function objetoAjax(){
var xmlhttp=false;
var idAX = ["Msxml2.XMLHTTP.5.0","Msxml2.XMLHTTP.4.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"];
for(var i=0; !xmlhttp && i<idAX.length; i++){
	try{ xmlhttp = new ActiveXObject(idAX[i]);
	}catch(ex) {
		xmlhttp = false; 
	}
}
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
		}   
		if (!xmlhttp){
			alert('Falla :( No es posible crear una instancia XMLHTTP');
			}
	return xmlhttp;
}

var Spry;
if (!Spry) Spry = {};
if (!Spry.Widget) Spry.Widget = {};

Spry.Widget.TabbedPanels = function(element, opts)
{
	this.element = this.getElement(element);
	this.defaultTab = 0; // Show the first panel by default.
	this.bindings = [];
	this.tabSelectedClass = "TabbedPanelsTabSelected";
	this.tabHoverClass = "TabbedPanelsTabHover";
	this.tabFocusedClass = "TabbedPanelsTabFocused";
	this.panelVisibleClass = "TabbedPanelsContentVisible";
	this.focusElement = null;
	this.hasFocus = false;
	this.currentTabIndex = 0;
	this.enableKeyboardNavigation = true;

	Spry.Widget.TabbedPanels.setOptions(this, opts);

	// If the defaultTab is expressed as a number/index, convert
	// it to an element.

	if (typeof (this.defaultTab) == "number")
	{
		if (this.defaultTab < 0)
			this.defaultTab = 0;
		else
		{
			var count = this.getTabbedPanelCount();
			if (this.defaultTab >= count)
				this.defaultTab = (count > 1) ? (count - 1) : 0;
		}

		this.defaultTab = this.getTabs()[this.defaultTab];
	}

	// The defaultTab property is supposed to be the tab element for the tab content
	// to show by default. The caller is allowed to pass in the element itself or the
	// element's id, so we need to convert the current value to an element if necessary.

	if (this.defaultTab)
		this.defaultTab = this.getElement(this.defaultTab);

	this.attachBehaviors();
};

Spry.Widget.TabbedPanels.prototype.getElement = function(ele)
{
	if (ele && typeof ele == "string")
		return document.getElementById(ele);
	return ele;
}

Spry.Widget.TabbedPanels.prototype.getElementChildren = function(element)
{
	var children = [];
	var child = element.firstChild;
	while (child)
	{
		if (child.nodeType == 1 /* Node.ELEMENT_NODE */)
			children.push(child);
		child = child.nextSibling;
	}
	return children;
};

Spry.Widget.TabbedPanels.prototype.addClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) != -1))
		return;
	ele.className += (ele.className ? " " : "") + className;
};

Spry.Widget.TabbedPanels.prototype.removeClassName = function(ele, className)
{
	if (!ele || !className || (ele.className && ele.className.search(new RegExp("\\b" + className + "\\b")) == -1))
		return;
	ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), "");
};

Spry.Widget.TabbedPanels.setOptions = function(obj, optionsObj, ignoreUndefinedProps)
{
	if (!optionsObj)
		return;
	for (var optionName in optionsObj)
	{
		if (ignoreUndefinedProps && optionsObj[optionName] == undefined)
			continue;
		obj[optionName] = optionsObj[optionName];
	}
};

Spry.Widget.TabbedPanels.prototype.getTabGroup = function()
{
	if (this.element)
	{
		var children = this.getElementChildren(this.element);
		if (children.length)
			return children[0];
	}
	return null;
};

Spry.Widget.TabbedPanels.prototype.getTabs = function()
{
	var tabs = [];
	var tg = this.getTabGroup();
	if (tg)
		tabs = this.getElementChildren(tg);
	return tabs;
};

Spry.Widget.TabbedPanels.prototype.getContentPanelGroup = function()
{
	if (this.element)
	{
		var children = this.getElementChildren(this.element);
		if (children.length > 1)
			return children[1];
	}
	return null;
};

Spry.Widget.TabbedPanels.prototype.getContentPanels = function()
{
	var panels = [];
	var pg = this.getContentPanelGroup();
	if (pg)
		panels = this.getElementChildren(pg);
	return panels;
};

Spry.Widget.TabbedPanels.prototype.getIndex = function(ele, arr)
{
	ele = this.getElement(ele);
	if (ele && arr && arr.length)
	{
		for (var i = 0; i < arr.length; i++)
		{
			if (ele == arr[i])
				return i;
		}
	}
	return -1;
};

Spry.Widget.TabbedPanels.prototype.getTabIndex = function(ele)
{
	var i = this.getIndex(ele, this.getTabs());
	if (i < 0)
		i = this.getIndex(ele, this.getContentPanels());
	return i;
};

Spry.Widget.TabbedPanels.prototype.getCurrentTabIndex = function()
{
	return this.currentTabIndex;
};

Spry.Widget.TabbedPanels.prototype.getTabbedPanelCount = function(ele)
{
	return Math.min(this.getTabs().length, this.getContentPanels().length);
};

Spry.Widget.TabbedPanels.addEventListener = function(element, eventType, handler, capture)
{
	try
	{
		if (element.addEventListener)
			element.addEventListener(eventType, handler, capture);
		else if (element.attachEvent)
			element.attachEvent("on" + eventType, handler);
	}
	catch (e) {}
};

Spry.Widget.TabbedPanels.prototype.onTabClick = function(e, tab)
{
	this.showPanel(tab);
};

Spry.Widget.TabbedPanels.prototype.onTabMouseOver = function(e, tab)
{
	this.addClassName(tab, this.tabHoverClass);
};

Spry.Widget.TabbedPanels.prototype.onTabMouseOut = function(e, tab)
{
	this.removeClassName(tab, this.tabHoverClass);
};

Spry.Widget.TabbedPanels.prototype.onTabFocus = function(e, tab)
{
	this.hasFocus = true;
	this.addClassName(this.element, this.tabFocusedClass);
};

Spry.Widget.TabbedPanels.prototype.onTabBlur = function(e, tab)
{
	this.hasFocus = false;
	this.removeClassName(this.element, this.tabFocusedClass);
};

Spry.Widget.TabbedPanels.ENTER_KEY = 13;
Spry.Widget.TabbedPanels.SPACE_KEY = 32;

Spry.Widget.TabbedPanels.prototype.onTabKeyDown = function(e, tab)
{
	var key = e.keyCode;
	if (!this.hasFocus || (key != Spry.Widget.TabbedPanels.ENTER_KEY && key != Spry.Widget.TabbedPanels.SPACE_KEY))
		return true;

	this.showPanel(tab);

	if (e.stopPropagation)
		e.stopPropagation();
	if (e.preventDefault)
		e.preventDefault();

	return false;
};

Spry.Widget.TabbedPanels.prototype.preorderTraversal = function(root, func)
{
	var stopTraversal = false;
	if (root)
	{
		stopTraversal = func(root);
		if (root.hasChildNodes())
		{
			var child = root.firstChild;
			while (!stopTraversal && child)
			{
				stopTraversal = this.preorderTraversal(child, func);
				try { child = child.nextSibling; } catch (e) { child = null; }
			}
		}
	}
	return stopTraversal;
};

Spry.Widget.TabbedPanels.prototype.addPanelEventListeners = function(tab, panel)
{
	var self = this;
	Spry.Widget.TabbedPanels.addEventListener(tab, "click", function(e) { return self.onTabClick(e, tab); }, false);
	Spry.Widget.TabbedPanels.addEventListener(tab, "mouseover", function(e) { return self.onTabMouseOver(e, tab); }, false);
	Spry.Widget.TabbedPanels.addEventListener(tab, "mouseout", function(e) { return self.onTabMouseOut(e, tab); }, false);

	if (this.enableKeyboardNavigation)
	{
		// XXX: IE doesn't allow the setting of tabindex dynamically. This means we can't
		// rely on adding the tabindex attribute if it is missing to enable keyboard navigation
		// by default.

		// Find the first element within the tab container that has a tabindex or the first
		// anchor tag.
		
		var tabIndexEle = null;
		var tabAnchorEle = null;

		this.preorderTraversal(tab, function(node) {
			if (node.nodeType == 1 /* NODE.ELEMENT_NODE */)
			{
				var tabIndexAttr = tab.attributes.getNamedItem("tabindex");
				if (tabIndexAttr)
				{
					tabIndexEle = node;
					return true;
				}
				if (!tabAnchorEle && node.nodeName.toLowerCase() == "a")
					tabAnchorEle = node;
			}
			return false;
		});

		if (tabIndexEle)
			this.focusElement = tabIndexEle;
		else if (tabAnchorEle)
			this.focusElement = tabAnchorEle;

		if (this.focusElement)
		{
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "focus", function(e) { return self.onTabFocus(e, tab); }, false);
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "blur", function(e) { return self.onTabBlur(e, tab); }, false);
			Spry.Widget.TabbedPanels.addEventListener(this.focusElement, "keydown", function(e) { return self.onTabKeyDown(e, tab); }, false);
		}
	}
};

Spry.Widget.TabbedPanels.prototype.showPanel = function(elementOrIndex)
{
	var tpIndex = -1;
	
	if (typeof elementOrIndex == "number")
		tpIndex = elementOrIndex;
	else // Must be the element for the tab or content panel.
		tpIndex = this.getTabIndex(elementOrIndex);
	
	if (!tpIndex < 0 || tpIndex >= this.getTabbedPanelCount())
		return;

	var tabs = this.getTabs();
	var panels = this.getContentPanels();

	var numTabbedPanels = Math.max(tabs.length, panels.length);

	for (var i = 0; i < numTabbedPanels; i++)
	{
		if (i != tpIndex)
		{
			if (tabs[i])
				this.removeClassName(tabs[i], this.tabSelectedClass);
			if (panels[i])
			{
				this.removeClassName(panels[i], this.panelVisibleClass);
				panels[i].style.display = "none";
			}
		}
	}

	this.addClassName(tabs[tpIndex], this.tabSelectedClass);
	this.addClassName(panels[tpIndex], this.panelVisibleClass);
	panels[tpIndex].style.display = "block";

	this.currentTabIndex = tpIndex;
};

Spry.Widget.TabbedPanels.prototype.attachBehaviors = function(element)
{
	var tabs = this.getTabs();
	var panels = this.getContentPanels();
	var panelCount = this.getTabbedPanelCount();

	for (var i = 0; i < panelCount; i++)
		this.addPanelEventListeners(tabs[i], panels[i]);

	this.showPanel(this.defaultTab);
};

/*function muestra(){
document.getElementById('permisos').style.display= "block";
}*/

function muestra1(){
document.getElementById('alta_empresa').style.display= "block";
document.getElementById('seleccion_empresa').value=0;
document.getElementById('alta_empresa_edicion').style.display= "none";
}


function muestra_nuevo_edicion(){
document.getElementById('alta_empresa_edicion').style.display= "block";
document.getElementById('alta_empresa').style.display= "none";
document.getElementById('seleccion_empresa').value=0;
document.getElementById('nueva_empresa_edicion').value=1;
document.getElementById('nuevo_contacto_edicion').value=1;
document.getElementById('alta_contacto_empresa_edicion').style.display= "block";
document.getElementById('alta_contacto_empresa').style.display= "none";
document.getElementById('select_contact').style.display= "none";
}

function muestra_icel_1(){
document.getElementById('alta_contacto_ui_edicion').style.display= "block";
document.getElementById('alta_contacto_ui').style.display= "none";
document.getElementById('seleccion_contacto_ui').value=0;
document.getElementById('nuevo_contacto_ui_edicion').value=1;
}

function muestra_icel(){
document.getElementById('alta_contacto_ui').style.display= "block";
document.getElementById('seleccion_contacto_ui').value=0;
}

function checa_valor(){
var ui=document.getElementById('seleccion_contacto_ui').value;
if(ui.value!=0){
document.getElementById('alta_contacto_ui').style.display= "none";	
	}
else{
document.getElementById('alta_contacto_ui').style.display= "block";		
	}
}


function muestra_contacto(){
document.getElementById('alta_contacto_empresa').style.display= "block";
document.getElementById('seleccion_contacto').value=0;
document.getElementById('alta_contacto_empresa_edicion').style.display= "none";
}

function muestra_contacto1(){
document.getElementById('nuevo_contacto_edicion').value=1;
document.getElementById('alta_contacto_empresa_edicion').style.display= "block";
document.getElementById('seleccion_contacto').value=0;
document.getElementById('alta_contacto_empresa').style.display= "none";
}

function muestra_contacto_alta(){
	var val=document.getElementById('seleccion_contacto').value;
	if (val==0){
	document.getElementById('alta_contacto_empresa').style.display= "block";
	}
	else
	{
	
	document.getElementById('alta_contacto_empresa').style.display= "none";		
	}
}

function validar() {
	missinginfo=""; //variable para mensaje en la ventana confirm o alert

		if (document.getElementById('actualizacion').value=="") {
			missinginfo += "\n    - Generales - \u00daltima actualizaci\u00f3n";
		}
		if (document.getElementById('nombre_programa').value=="") {
			missinginfo += "\n    - Generales - Nombre del Programa";
		}
		if (document.getElementById('vigencia').value=="") {
			missinginfo += "\n    - Generales - Vigencia";
		}
		if (missinginfo!=""){
			missinginfo+="\n _____________________________\n";
			}
	/****************************Empresa*****************************************/
	if(document.getElementById('seleccion_empresa').value==0){
	
		if (document.getElementById('nombre_empresa').value=="") {
			missinginfo += "\n    - Empresa - Nombre de la empresa";
		}
		if (document.getElementById('calle').value=="") {
			missinginfo += "\n    - Empresa - Calle";
		}
		if (document.getElementById('numero').value=="") {
			missinginfo += "\n    - Empresa - N\u00famero";
		}
		if (document.getElementById('colonia').value=="") {
			missinginfo += "\n    - Empresa - Colonia";
		}
		if (document.getElementById('delegacion_municipio').value=="") {
			missinginfo += "\n    - Empresa - Delegaci\u00f3n/Municipio";
		}
		if (document.getElementById('estado').value=="") {
			missinginfo += "\n    - Empresa - Estado";
		}
		if (document.getElementById('ciudad').value=="") {
			missinginfo += "\n    - Empresa - Ciudad";
		}
		if (document.getElementById('cp').value=="") {
			missinginfo += "\n    - Empresa - C\u00f3digo Postal";
		}
		
		if (missinginfo!=""){
			missinginfo+="\n _____________________________\n";
			}
		
		if (document.getElementById('nombre_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Nombre";
		}
		if (document.getElementById('cargo_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Cargo";
		}
		if (document.getElementById('tel_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Tel\u00e9fono";
		}

	}
		if (missinginfo!=""){
			missinginfo+="\n _____________________________\n";
			}
		/********************Termina Empresa********************************/
		/********************Contacto Empresa*******************************/
else{
	if(document.getElementById('seleccion_contacto').value==0){
		
		if (document.getElementById('nombre_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Nombre";
		}
		if (document.getElementById('cargo_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Cargo";
		}
		if (document.getElementById('tel_contacto_emp').value=="") {
			missinginfo += "\n    - Contacto Empresa - Tel\u00e9fono";
		}
	}
}
		if (missinginfo!=""){
			missinginfo+="\n _____________________________\n";
			}
	/******************Termina Contacto Empresa**************************/
	/*********************Contacto UI************************************/
if(document.getElementById('seleccion_contacto_ui').value==0){
		if (document.getElementById('nombre_contacto_ui').value=="") {
			missinginfo += "\n    - Contacto UI - Nombre";
		}
		if (document.getElementById('cargo_contacto_ui').value=="") {
			missinginfo += "\n    - Contacto UI - Cargo";
		}
		if (document.getElementById('tel_contacto_ui').value=="") {
			missinginfo += "\n    - Contacto UI - Tel\u00e9fono";
		}
}
		if (missinginfo!=""){
			missinginfo+="\n _____________________________\n";
			}
/*********************************Termina Contacto UI********************/
		if (document.getElementById('descripcion_gral').value=="") {
			missinginfo += "\n    - Descripci\u00f3n - Descripci\u00f3n General del Programa";
		}

		if (missinginfo!="") {
			missinginfo ="No se insertaron correctamente\nlos datos en:\n" +
			"_____________________________\n" +
			missinginfo + "\n_____________________________";
			//opcion=confirm(missinginfo);
			alert(missinginfo);
			//return !(opcion);
			return false;
		}
		else return true;
}

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thecolor, thewidth){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
ajax=objetoAjax();
ajax.open("GET", "globo.php?matricula="+thetext);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4 && ajax.status == 200) {
		tipobj.innerHTML=ajax.responseText;
		}        
	}        
	ajax.send(null);
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var curX=(ns6)?e.pageX : event.x+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.y+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20

var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
else if (curX<leftedge)
tipobj.style.left="5px"
else
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetxpoint+"px"

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight)
tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px"
else
tipobj.style.top=curY+offsetypoint+"px"
tipobj.style.visibility="visible"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

function muestra(matricula) {
	ajax=objetoAjax();
	ajax.open("GET", "permisos.php?matricula="+matricula+"&opc=1");
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4 && ajax.status == 200) {
		document.getElementById('permisos').style.display="block";
		document.getElementById('permisos').innerHTML=ajax.responseText	
		}        
	}        
	ajax.send(null);
}

function agrega_permisos(check,matricula,sistema) {
	ajax=objetoAjax();
		if (document.getElementById(check).checked==true) {
	ajax.open("GET", "permisos.php?matricula="+matricula+"&opc=2&accion=1&sistema="+sistema);
		}
		else
		{
	ajax.open("GET", "permisos.php?matricula="+matricula+"&opc=2&accion=2&sistema="+sistema);
		}
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4 && ajax.status == 200) {
		ajax.responseText;	
		document.getElementById('permisos').style.display="block";
		document.getElementById('permisos').innerHTML=ajax.responseText	
		document.getElementById('permisos').innerHTML=ajax.responseText	
		}        
	}        
	ajax.send(null);
}

function ValidarAlta() {
	missinginfo=""; //variable para mensaje en la ventana confirm o alert

		if (document.registro.usuario.value=="") {
			missinginfo += "\n    - Usuario";
		}
		if (document.registro.contrasenia.value=="") {
			missinginfo += "\n    - Contraseña";
		}
		else if (document.registro.contrasenia.value!=document.registro.contraseniac.value){
			document.registro.contrasenia.value="";
			document.registro.contraseniac.value="";
			//document.registro.contrasenia.focus();
			missinginfo += "\n    - Las contraseñas no coinciden";
		}
		if (document.registro.tcarrera.value=="0") {
			missinginfo += "\n    - Carrera";
		}
		if (document.registro.email.value=="") {
			missinginfo += "\n    - E-Mail";
		}
/*		else{
			var mail = document.registro.email.value;
			var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
			if (!filter.test(mail))
			missinginfo += "\n    - Dirección de correo no válida";
		}*/

		
		if (missinginfo!="") {
			missinginfo ="No se insertaron correctamente\nlos datos en:\n" +
			"_____________________________\n" +
			missinginfo + "\n_____________________________";
			//opcion=confirm(missinginfo);
			alert(missinginfo);
			//return !(opcion);
			return false;
		}
		

			
		else return true;
}

function validarRecupera() {
	missinginfo=""; //variable para mensaje en la ventana confirm o alert

		if (document.logeo.matricula.value=="") {
			missinginfo += "\n    - Matricula";
		}
		if (document.logeo.correo.value=="") {
			missinginfo += "\n    - Correo Electronico";
		}
		
		if (missinginfo!="") {
			missinginfo ="No se insertaron correctamente\nlos datos en:\n" +
			"_____________________________\n" +
			missinginfo + "\n_____________________________";
			//opcion=confirm(missinginfo);
			alert(missinginfo);
			//return !(opcion);
			return false;
		}
		else return true;
}

