
// JavaScript funciones ajax

var txtIndica="";
var ano_mat ="2000"; //Variable usada en el proceso de generar matricula.
// creando objeto XMLHttpRequest de Ajax
var obXHR;
try {
	obXHR=new XMLHttpRequest();
} catch(err) {
	try {
		obXHR=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(err) {
		try {
			obXHR=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(err) {
			obXHR=false;
		}
	}
}

// INICIO ENVIO DE UN CHECKBOX

function cargarPOST(url,urlreturn,divinfo,divreload, foco) {
		
	url=url+"&q=getinfo"+GetInfoString();
	
	mostrar(divreload);
		
	obXHR.open("GET", url, true);
	
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			alert(obXHR.responseText);
			ocultar(divreload);
			cargarFocus(urlreturn,divinfo,divreload, foco);
		}
	}
	obXHR.send(null);
}

	function GetInfoString(){
		
	    var sData="";
        var iCount =0;

        iCount = myform.elements.namedItem("idAsA").length;
        if(iCount>>0){
	        for(i=0;i<iCount;i++){
	            //===========================================================================
	            // This Logic Is Compatible With IE browser but most not compatible for Other 
	            //===========================================================================
	            //if (myform.elements.namedItem("chkinfo[]","")(i).checked){
	            //sData += "&chkinfo[]=" +  myform.elements.namedItem("chkinfo[]","")(i).value;
	            //}
	            
	            //==============================================================
	            //Replace With This New Logic:  has been Tested In IE And Chrome
	            //==============================================================
	            if (myform.idAsA[i].checked) {
	                sData += "&idAsA[]=" + myform.idAsA[i].value;
	            }
	        }
	    }         
	    
		return sData;
	}
	
	
	function cargarVentanaReport(url, divinfo, divreload, ventana, divtitulo, txttitulo, idRedimencion, width, height, foco) {
	
		var obDiv = document.getElementById(divinfo);
	
		mostrar(divreload);
		
		url=url+GetInfoString2();
		
		//alert(url);
	
		obXHR.open("GET", url);
		obXHR.onreadystatechange = function() {
			if (obXHR.readyState == 4 && obXHR.status == 200) {
			
				obDiv.innerHTML=obXHR.responseText;
			
				ocultar(divreload);
				
				ubicoVentana(ventana, idRedimencion, width, height);
			
				divMsg(divtitulo,txttitulo);
						
				mostrar(ventana);
			
				document.getElementById(foco).focus();
			}
		}
		obXHR.send(null);
	}


	function GetInfoString2(){
		
	    var sData="";
        var iCount =0;

        iCount = myform.elements.namedItem("idAsA").length;
        if(iCount>>0){
	        for(i=0;i<iCount;i++){
	            //===========================================================================
	            // This Logic Is Compatible With IE browser but most not compatible for Other 
	            //===========================================================================
	            //if (myform.elements.namedItem("chkinfo[]","")(i).checked){
	            //sData += "&chkinfo[]=" +  myform.elements.namedItem("chkinfo[]","")(i).value;
	            //}
	            
	            //==============================================================
	            //Replace With This New Logic:  has been Tested In IE And Chrome
	            //==============================================================
	            if (myform.idAsA[i].checked) {
					if(sData==''){
	                	sData += "idAsA=" + myform.idAsA[i].value;
					}else{
						sData += '-' + myform.idAsA[i].value;
					}
	            }
	        }
	    }         
	    
		return sData;
	}
	
//FINAL ENVIO DE UN CHECKBOX


//INICIO ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT

function EnviarLista(url,idform, nlib, idcheck, divreload,idsocio, urlreturn ,divinfo,divreload,foco){
	if( ! confirm('Seguro desea validar el(los) aspirante(s) selecciondo(s) ?') ){
		return false;
	}
	val=0;
	
	codlibr=0;
	libranzas ='';
	soccios ='';
	num=0;
	obj = document.getElementById(idcheck);
	
	 document.getElementById(idcheck);
	
	for (i=0; ele=obj.form.elements[i]; i++){
	  if (ele.checked){
		  
			if(libranzas==''){
				libranzas = ele.value;
				socios = document.getElementById(idsocio+ele.value).value;
				if(document.getElementById(idsocio+ele.value).value == ''){val++ ; codlibr=ele.value;} 
				
			}else{
				libranzas += '-'+ele.value;
				socios += '-'+document.getElementById(idsocio+ele.value).value;  
				if(document.getElementById(idsocio+ele.value).value == '') {val++ ; codlibr=ele.value;} 
			}
				
			num++;
	  }
	}
	
	if( num==0 ){
		alert('Usted no ha seleccionado aspirantes.');
		return false;
	}
	
	if( val != 0 ){
		alert('En el aspirante de id= '+codlibr+', digite el codigo correspondiente.');
		document.getElementById(idsocio+codlibr).focus();
		return false;
	}
	
	mostrar(divreload);
	cadenaFormulario= 'idAsA='+libranzas+'&id_alumno='+socios+'&num='+num;
	
	obXHR.open("POST", url, true);
	obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	obXHR.onreadystatechange = function () {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				
				alert(obXHR.responseText);
				ocultar(divreload);
				cargarFocus(urlreturn,divinfo,divreload,foco);
				
		}
	}
	obXHR.send(cadenaFormulario);
}


//FINAL ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT
////////////////////////////////////////////////añadi/////////////////////////////////////

function EnviarListaCarga(url, idform, nlib, idcheck, divreload, nhoras, urlreturn, divinfo, divreload, foco){
	if( ! confirm('Seguro desea asignar la carga seleccionda ?') ){
		return false;
	}
	val=0;
	codasig=0;
	asignatura ='';
	numhoras='';
	num=0;
	obj = document.getElementById(idcheck);
	      //document.getElementById(idcheck);
		  
	
	for (i=0; ele=obj.form.elements[i]; i++){
	  if (ele.checked){
		  
			if(asignatura==''){
				asignatura = ele.value;
				
				//socios = document.getElementById(idsocio+ele.value).value;
				numhoras=document.getElementById(nhoras+ele.value).value;
				
				if(document.getElementById(nhoras+ele.value).value == ''){val++ ; codasig=ele.value;} 
				
			}else{
				
				asignatura += '-'+ele.value;
				numhoras += '-'+document.getElementById(nhoras+ele.value).value;  
				
				if(document.getElementById(nhoras+ele.value).value == '') {val++ ; codasig=ele.value;} 
			}
				
			num++;
	  }
	}
	
	if( num==0 ){
		alert('Usted no ha seleccionado asignaturas.');
		return false;
	}
	
	if( val != 0 ){
		alert('En la asignatura de Codigo= '+codasig+', digite el numero de horas correspondiente.');
		document.getElementById(nhoras+codasig).focus();
		return false;
	}
	
	mostrar(divreload);
	cadenaFormulario= 'idAsA='+asignatura+'&nhoras='+numhoras+'&num='+num;
	
	obXHR.open("POST", url, true);
	obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	obXHR.onreadystatechange = function () {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				
				alert(obXHR.responseText);
				ocultar(divreload);
				cargarFocus(urlreturn,divinfo,divreload,foco);
				
		}
	}
	obXHR.send(cadenaFormulario);
}


//FINAL ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT

//////////////////////////////////////////////////////////////////////////////////////////
//INICIO ENVIO varios OBJETOs  INPUT

function EnviarListaCalifica(url,idform, nlib, idcheck, divreload, idcheck, idconcepto, idnotanum, idasistencia, urlreturn ,divinfo,divreload,foco){
	if( ! confirm('Seguro desea procesar el conjunto de datos ?') ){
		return false;
	}
	val=0;
	val2=0;
	val3=0;
	
	codlibr=0;
	notlibr=0;
	asilibr=0;
	libranzas ='';
	concepto ='';
	notanum='';
	asistencia='';
	
	num=0;
	obj = document.getElementById(idcheck);
	
	 document.getElementById(idcheck);
	 
	 //alert('Libranza='+ idcheck);
	 
	
	for (i=0; ele=obj.form.elements[i]; i++){
	  if (ele.checked){
		  
			if(libranzas==''){
				libranzas = ele.value;
				concepto = document.getElementById(idconcepto+ele.value).value;
				if(document.getElementById(idconcepto+ele.value).value == ''){val++ ; codlibr=ele.value;} 
				
				notanum = document.getElementById(idnotanum+ele.value).value;
				if(document.getElementById(idnotanum+ele.value).value == '') {val2++ ; notlibr=ele.value;} 

				asistencia = document.getElementById(idasistencia+ele.value).value;
				if(document.getElementById(idasistencia+ele.value).value == '') {val3++ ; asilibr=ele.value;} 


								//alert('Libranza='+libranzas+', Concepto= '+concepto+', NotaNum= '+notanum+', asistencia= '+asistencia);
				
			}else{
				
				libranzas += '-'+ele.value;
				
				concepto += '-'+document.getElementById(idconcepto+ele.value).value;  
				if(document.getElementById(idconcepto+ele.value).value == '') {val++ ; codlibr=ele.value;}
				
				notanum += '-'+document.getElementById(idnotanum+ele.value).value;  
				if(document.getElementById(idnotanum+ele.value).value == '') {val2++ ; notlibr=ele.value;} 


				asistencia += '-'+document.getElementById(idasistencia+ele.value).value;  
				if(document.getElementById(idasistencia+ele.value).value == '') {val3++ ; asilibr=ele.value;} 
				
								//alert('Libranza='+libranzas+', Concepto= '+concepto+', NotaNum= '+notanum+', asistencia= '+asistencia);

			}
				
			num++;
	  }
	}
	
	
	//alert('Paso 0');
	
	if( num==0 ){
		alert('Usted no ha seleccionado aspirantes.');
		return false;
	}
	
	
	if( val != 0 ){
		alert('En el estudiante de id= '+codlibr+', digite el concepto correspondiente.');
		document.getElementById(idconcepto+codlibr).focus();
		return false;
	}else{
		
			if( val2 != 0 ){
				alert('En el estudiante de id= '+notlibr+', digite la nota correspondiente.');
				document.getElementById(idnotanum+notlibr).focus();
				return false;
			}else{
	
					if( val3 != 0 ){
						alert('En el estudiante de id= '+asilibr+', digite la asistencia correspondiente.');
						document.getElementById(idasistencia+asilibr).focus();
						return false;
					}			
		
				}

		}

	//alert('Paso 1');
	mostrar(divreload);
	//alert('Paso 2');
	cadenaFormulario= 'idAsA='+libranzas+'&idconcepto='+concepto+'&notanum='+notanum+'&asistencia='+asistencia+'&num='+num;
	
	obXHR.open("POST", url, true);
	obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	obXHR.onreadystatechange = function () {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				
				alert(obXHR.responseText);
				ocultar(divreload);
				cargarFocus(urlreturn,divinfo,divreload,foco);
				
		}
	}
	obXHR.send(cadenaFormulario);
}


//FINAL ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT

function cargarLink(url,urlreturn,divinfo,divreload, foco) {
		
	
	mostrar(divreload);
		
	obXHR.open("GET", url, true);
	
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			alert(obXHR.responseText);
			ocultar(divreload);
			cargarFocus(urlreturn,divinfo,divreload, foco);
		}
	}
	obXHR.send(null);
}


function cargarB(url,divinfo) {
	
	var obDiv = document.getElementById(divinfo);
	
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.innerHTML=obXHR.responseText;
		}
	}
	obXHR.send(null);
}

function cargarFocus(url,divinfo,divreload, foco) {
	
	var obDiv = document.getElementById(divinfo);
	
	mostrar(divreload);
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.innerHTML=obXHR.responseText;
			ocultar(divreload);
			document.getElementById(foco).focus();
		}
	}
	obXHR.send(null);
}

function cargarFocusIFrame(url,divinfo,divreload, foco) {
	
	var obDiv = document.getElementById(divinfo);
	
	parent.document.getElementById(divreload).style.visibility='visible';//mostrar(divreload);
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.innerHTML=obXHR.responseText;
			parent.document.getElementById(divreload).style.visibility='hidden';//ocultar(divreload);
			document.getElementById(foco).focus();
		}
	}
	obXHR.send(null);
}


function cargar(url,divinfo,divreload) {
	
	var obDiv = document.getElementById(divinfo);
	
	mostrar(divreload);
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.innerHTML=obXHR.responseText;
			ocultar(divreload);
		}
	}
	obXHR.send(null);
}

function cargarVentana(url, divinfo, divreload, ventana, divtitulo, txttitulo, idRedimencion, width, height, foco) {
	
	var obDiv = document.getElementById(divinfo);
	
	mostrar(divreload);
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			
			obDiv.innerHTML=obXHR.responseText;
			
			ocultar(divreload);
			
			ubicoVentana(ventana, idRedimencion, width, height);
			
			divMsg(divtitulo,txttitulo);
						
			mostrar(ventana);
			
			document.getElementById(foco).focus();
		}
	}
	obXHR.send(null);
}


function ubicoVentana(ventana, idRedimencion, width, height){		
	
	document.getElementById(idRedimencion).style.width = ((width))+'px';
	document.getElementById(idRedimencion).style.height = ((height))+'px';

	document.getElementById(ventana).style.left = ((document.width-width)/2)+'px';
	document.getElementById(ventana).style.top = ((document.height-height)/2)+'px';
	
}


function cargarS(url,dato,divinfo,divreload) {
	
	var obDiv = document.getElementById(divinfo);
	
	mostrar(divreload);
	
	obXHR.open("GET", url+dato);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.innerHTML=obXHR.responseText;
			ocultar(divreload);
		}
	}
	obXHR.send(null);
}

function cargarInput(url,divinfo,divreload) {
	
	var obDiv = document.getElementById(divinfo);
	
	mostrar(divreload);
	
	obXHR.open("GET", url);
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
			obDiv.value=obXHR.responseText;
			ocultar(divreload);
		}
	}
	obXHR.send(null);
}


function mostrar(div){
document.getElementById(div).style.visibility="visible";
}
function ocultar(div){
document.getElementById(div).style.visibility="hidden";
} 

function divMsg(div,msg){
document.getElementById(div).innerHTML=msg;
} 

function divIco(div,url){
document.getElementById(div).innerHTML=url;
} 

function eventIgualar(idObjetoD,dato){
document.getElementById(idObjetoD).value=dato;
}

// En uso de checkbox
 function mostrar_obj(obj1, obj2){
 	//var cambiapsw = document.getElementsByName(obj1);
 	var ObjActivo = document.getElementById(obj2);
 	if(obj1.checked){
		ObjActivo.disabled = false;
		ObjActivo.focus();
	}else{
		ObjActivo.disabled= true;
	}
 }


//****************************************************************//
// Funcion para seleccionar todos los checkbox.					  //
//****************************************************************//
function seleccionar_todo(form){
	var Formulario = document.getElementById(form);
	for (i=0;i<Formulario.elements.length;i++)
		if(Formulario.elements[i].type == "checkbox")	
			Formulario.elements[i].checked=1
}
function deseleccionar_todo(form){
	var Formulario = document.getElementById(form);
	for (i=0;i<Formulario.elements.length;i++)
		if(Formulario.elements[i].type == "checkbox")	
			Formulario.elements[i].checked=0
}


//****************************************************************//
// Funcion para enviar la informacion de un formulario completo.
//****************************************************************//

function enviarFormulario(url, formid, redir, url_redir, loading, divContent, foco){
		
		//ocultar('apDivVentana');
		mostrar(loading);
        
		 var Formulario = document.getElementById(formid);
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
}
  obXHR.open("POST", url, true);
  obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  obXHR.onreadystatechange = function () {
  if (obXHR.readyState == 4) {
		ocultar(loading);
		//document.getElementById('apDivCuerpo').innerHTML=obXHR.responseText;
		alert(obXHR.responseText);
		Formulario.reset();
		
		if(redir==1){
			
			cargarFocus(url_redir,divContent,loading, foco);
		
		}
		
		//cargar(recarga);
	}
}
obXHR.send(cadenaFormulario);
}


function enviarFormularioIFrame(url, formid, redir, url_redir, loading, divContent, foco){
		
		//ocultar('apDivVentana');
		parent.document.getElementById(loading).style.visibility='visible';//mostrar(loading);
        
		 var Formulario = document.getElementById(formid);
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
}
  obXHR.open("POST", url, true);
  obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  obXHR.onreadystatechange = function () {
  if (obXHR.readyState == 4) {
		parent.document.getElementById(loading).style.visibility='hidden';//ocultar(loading);
		//document.getElementById('apDivCuerpo').innerHTML=obXHR.responseText;
		alert(obXHR.responseText);
		Formulario.reset();
		
		if(redir==1){
			
			cargarFocusIFrame(url_redir,divContent,loading, foco);
		
		}
		
		//cargar(recarga);
	}
}
obXHR.send(cadenaFormulario);
}


function enviarFormularioPOST(url, formid, redir, url_redir, loading, divContent, foco){
		
		//ocultar('apDivVentana');
		mostrar(loading);
        
		 var Formulario = document.getElementById(formid);
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
}

	url=url+"&q=getinfo"+GetInfoString();

  obXHR.open("POST", url, true);
  obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  obXHR.onreadystatechange = function () {
  if (obXHR.readyState == 4) {
		ocultar(loading);
		//document.getElementById('apDivCuerpo').innerHTML=obXHR.responseText;
		alert(obXHR.responseText);
		Formulario.reset();
		
		if(redir==1){
			
			cargarFocus(url_redir,divContent,loading, foco);
		
		}
		
		//cargar(recarga);
	}
}
obXHR.send(cadenaFormulario);
}


function enviarFormularioR(url, formid, urlrecarga, divinfo){
		
		//ocultar('apDivVentana');
		mostrar('apDiv2');
        
		 var Formulario = document.getElementById(formid);
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         sepCampos="&";
}
  obXHR.open("POST", url, true);
  obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  obXHR.onreadystatechange = function () {
  if (obXHR.readyState == 4) {
		ocultar('apDiv2');
		//document.getElementById('apDivCuerpo').innerHTML=obXHR.responseText;
		alert(obXHR.responseText);
		cargar(urlrecarga,divinfo,'apDiv2');
	}
}
obXHR.send(cadenaFormulario);
}


function login(url, formid, recarga){
		
		var obDivmsg = document.getElementById('apDivMsg');
		//ocultarVent();
		mostrar("apDiv2");
        
		 var Formulario = document.getElementById(formid);
         var longitudFormulario = Formulario.elements.length;
         var cadenaFormulario = ""
         var sepCampos
         sepCampos = ""
         for (var i=0; i <= Formulario.elements.length-1;i++) {
         	cadenaFormulario += sepCampos+Formulario.elements[i].name+'='+encodeURI(Formulario.elements[i].value);
         	sepCampos="&";
		 }
  obXHR.open("POST", url, true);
  obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
  obXHR.onreadystatechange = function () {
  if (obXHR.readyState == 4) {
	  
		ocultar("apDiv2");
		
		if(obXHR.responseText!="1"){
			
			obDivmsg.innerHTML=obXHR.responseText;
			
		}else{
			
			document.location.href="app/";
			
		}
		
		//alert(obXHR.responseText);
		//cargar(recarga);

	}
}
obXHR.send(cadenaFormulario);
}


function logearse(){
	user=document.getElementById("user").value;
	psw=document.getElementById("pass").value;
	token=document.getElementById("ident").value;
	
	if(user==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar el Usuario.";
		document.getElementById("user").focus();
	}else if(psw==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar la Contrase&ntilde;a.";
		document.getElementById("pass").focus();
	}else if(token==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar la Identificaci&oacute;n.";
		document.getElementById("ident").focus();
	}else{
	
			document.getElementById("apDiv2").style.visibility="visible";
			obXHR.open("GET","login/login.php?user="+user+"&psw="+psw+"&token="+token);
			
		
			obXHR.onreadystatechange = function() {
				
				if (obXHR.readyState == 4 && obXHR.status == 200) {
				//obDiv.innerHTML=obXHR.responseText;
					document.getElementById("apDiv2").style.visibility="hidden";
					//alert(obXHR.responseText.length+" / "+obXHR.responseText);
					if(parseInt(obXHR.responseText)==1){//en el servidor mandar 114
						location.href='index.php';
					}else{
						document.getElementById("apDivMsg").innerHTML=obXHR.responseText;
						document.getElementById("user").select();
					}
					//;
					
				}
			}
			obXHR.send(null);
	}//fin else;
}
function logearse_marco(){
	user=document.getElementById("user").value;
	psw=document.getElementById("pass").value;
	token=document.getElementById("ident").value;
	
	if(user==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar el Usuario.";
		document.getElementById("user").focus();
	}else if(psw==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar la Contrase&ntilde;a.";
		document.getElementById("pass").focus();
	}else if(token==""){
		document.getElementById("apDivMsg").innerHTML="Favor Digitar la Identificaci&oacute;n.";
		document.getElementById("ident").focus();
	}else{
	
			
			document.getElementById("apDiv2").style.visibility="visible";
			obXHR.open("GET","http://www.feyalegria.comunidadwebschool.com/login/login.php?user="+user+"&psw="+psw+"&token="+token);
			//parent.location.href="http://www.feyalegria.comunidadwebschool.com/login/login.php?user="+user+"&psw="+psw+"&token="+token;
		
			obXHR.onreadystatechange = function() {
				
				if (obXHR.readyState == 4 && obXHR.status == 200) {
				//obDiv.innerHTML=obXHR.responseText;
					document.getElementById("apDiv2").style.visibility="hidden";
					//alert(obXHR.responseText.length+" / "+obXHR.responseText);
					if(parseInt(obXHR.responseText)==1){//en el servidor mandar 114
						location.href='index.php';
					}else{
						document.getElementById("apDivMsg").innerHTML=obXHR.responseText;
						document.getElementById("user").select();
					}
					//;
					
				}
			}
			obXHR.send(null);
	}//fin else;
}

function cerrarsesion(){
	
	obXHR.open("GET","../login/cerrarsesion.php");
	obXHR.onreadystatechange = function() {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				location.href='../';
		}
	}
	obXHR.send(null);
}


function isWebKit(){
	return RegExp(" AppleWebKit/").test(navigator.userAgent);
}
function ajaxUpload(form,url_action,id_element,html_show_loading,html_error_http){
	var detectWebKit = isWebKit();
	form = typeof(form)=="string"?$m(form):form;
	var erro="";
	if(form==null || typeof(form)=="undefined"){
		erro += "The form of 1st parameter does not exists.\n";
	}else if(form.nodeName.toLowerCase()!="form"){
		erro += "The form of 1st parameter its not a form.\n";
	}
	if($m(id_element)==null){
		erro += "The element of 3rd parameter does not exists.\n";
	}
	if(erro.length>0){
		alert("Error in call ajaxUpload:\n" + erro);
		return;
	}
	var iframe = document.createElement("iframe");
	iframe.setAttribute("id","ajax-temp");
	iframe.setAttribute("name","ajax-temp");
	iframe.setAttribute("width","0");
	iframe.setAttribute("height","0");
	iframe.setAttribute("border","0");
	iframe.setAttribute("style","width: 0; height: 0; border: none;");
	form.parentNode.appendChild(iframe);
	window.frames['ajax-temp'].name="ajax-temp";
	var doUpload = function(){
		removeEvent($m('ajax-temp'),"load", doUpload);
		var cross = "javascript: ";
		cross += "window.parent.$m('"+id_element+"').innerHTML = document.body.innerHTML; void(0);";
		$m(id_element).innerHTML = html_error_http;
		$m('ajax-temp').src = cross;
		if(detectWebKit){
        	remove($m('ajax-temp'));
        }else{
        	setTimeout(function(){ remove($m('ajax-temp'))}, 250);
        }
    }
	addEvent($m('ajax-temp'),"load", doUpload);
	form.setAttribute("target","ajax-temp");
	form.setAttribute("action",url_action);
	form.setAttribute("method","post");
	form.setAttribute("enctype","multipart/form-data");
	form.setAttribute("encoding","multipart/form-data");
	if(html_show_loading.length > 0){
		$m(id_element).innerHTML = html_show_loading;
	}
	form.submit();
}

//**************************************************************************//

 //Mas en: http://javascript.espaciolatino.com/

      //Objeto oNumero

function oNumero(numero)
{
	
	//Propiedades 
	
	this.valor = numero || 0
	
	this.dec = -1;
	
	//Métodos 
	
	this.formato = numFormat;
	
	this.ponValor = ponValor;
	
	//Definición de los métodos


	function ponValor(cad)
	
	{
	
		if (cad =='-' || cad=='+') return
		
		if (cad.length ==0) return
		
		if (cad.indexOf('.') >=0)
		
			this.valor = parseFloat(cad);
		
		else 
		
			this.valor = parseInt(cad);
		
	} 

function numFormat(dec, miles)

{

var num = this.valor, signo=3, expr;

var cad = ""+this.valor;

var ceros = "", pos, pdec, i;

for (i=0; i < dec; i++)

ceros += '0';

pos = cad.indexOf('.')

if (pos < 0)

    cad = cad+"."+ceros;

else

    {

    pdec = cad.length - pos -1;

    if (pdec <= dec)

        {

        for (i=0; i< (dec-pdec); i++)

            cad += '0';

        }

    else

        {

        num = num*Math.pow(10, dec);

        num = Math.round(num);

        num = num/Math.pow(10, dec);

        cad = new String(num);

        }

    }

pos = cad.indexOf('.')

if (pos < 0) pos = cad.lentgh

if (cad.substr(0,1)=='-' || cad.substr(0,1) == '+') 

       signo = 4;

if (miles && pos > signo)

    do{

        expr = /([+-]?\d)(\d{3}[\.\,]\d*)/

        cad.match(expr)

        cad=cad.replace(expr, RegExp.$1+','+RegExp.$2)

        }

while (cad.indexOf(',') > signo)

    if (dec<0) cad = cad.replace(/\./,'')

        return cad;

}

}//Fin del objeto oNumero:

//////////////////////////////////////////////////////////////////////////////////////////
//Funcion para moverse entre cajas de texto en el formulario enviando al punto donde quieras
function focusNext(form, elemName, evt) {
evt = (evt) ? evt : event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if (charCode == 13 || charCode == 3) {
form.elements[elemName].focus( );
return false;
}
return true;
}

//Funcion que solo permite inclusion de numeros.
function SoloNum(evt) {

 evt = (evt) ? evt : event;

 var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);

	if (charCode == 13 || charCode == 3) {

		//form.elements[elemName].focus( );
	
		return false;
		
	}else{
		
		// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
		var nav4 = window.Event ? true : false;
		var key = nav4 ? evt.which : evt.keyCode;	
		return (key <= 13 || (key >= 48 && key <= 57));
		
	}
	
return true;

}

//Funcion que solo permite inclusion de numeros y caracter.
function SoloNumChar(evt,caracter) {

 evt = (evt) ? evt : event;

 var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);

	if (charCode == 13 || charCode == 3) {

		//form.elements[elemName].focus( );
	
		return false;
		
	}else{
		
		// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
		var nav4 = window.Event ? true : false;
		var key = nav4 ? evt.which : evt.keyCode;	
		return (key <= 13 || (key >= 48 && key <= 57) || key==130 );
		
	}
	
return true;

}


//Funcion para moverse entre cajas de texto en el formulario enviando al punto donde quieras
function focusNextNum(form, elemName, evt) {

 evt = (evt) ? evt : event;

 var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);

	if (charCode == 13 || charCode == 3) {

		form.elements[elemName].focus( );
	
		return false;
		
	}else{
		
		// NOTA: Backspace = 8, Enter = 13, '0' = 48, '9' = 57	
		var nav4 = window.Event ? true : false;
		var key = nav4 ? evt.which : evt.keyCode;	
		return (key <= 13 || (key >= 48 && key <= 57)|| key==46 || key==44);
		
	}
	
return true;

}
	

////////////////////////////////////////////////
//Funcion para validar direccion de correo
function validarEmail(valor) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3,4})+$/.test(valor)){
   alert("La dirección de email " + valor + " es correcta.");
  } else {
   alert("La dirección de email es incorrecta.");
  }
}

///script para mover entre list
function verficarIguales(emisor1, receptor1){
	// Accedemos a los 2 selects
emisor1 = document.getElementById(emisor1);
receptor1 = document.getElementById(receptor1);
cantidad = receptor1.options.length;
selecionados = emisor1.selectedIndex;
texto = emisor1.options[selecionados].text;
//texto2=receptor.options[0].text;
i=0;
x2=0;
// INICIO DEL CICLO PARA RECORRER LAS ASIGNATURAS DE LA LISTA

for(i=0; i<cantidad; i++ )
	{
		texto2=receptor1.options[i].text;
        if(texto==texto2){
			x2=0;
			alert('La selecion hace parte del conjunto de elementos contenidos, verifiquelo');
			break;
		}else{
			x2=1;
			}
	}
	
   if (x2!=0 || cantidad==0){
	 posicion = receptor1.options.length;
     selecionado = emisor1.selectedIndex;

     if(selecionado != -1) {

         volcado = emisor1.options[selecionado];

         // Volcamos la opcion al select receptor y lo eliminamos del emisor
              receptor1.options[posicion] = new Option(volcado.text, volcado.value);
              emisor1.options[selecionado] = null;
              emisor1.selectedIndex=selecionado;
       if(selecionado>emisor1.length-1){emisor1.selectedIndex=emisor1.length-1;}

        }
     }
 }

function volcarSelects(emisor, receptor){

// Accedemos a los 2 selects
emisor = document.getElementById(emisor);
receptor = document.getElementById(receptor);

// Obtenemos algunos datos necesarios
posicion = receptor.options.length;
selecionado = emisor.selectedIndex;

if(selecionado != -1) {

volcado = emisor.options[selecionado];

// Volcamos la opcion al select receptor y lo eliminamos del emisor
receptor.options[posicion] = new Option(volcado.text, volcado.value);
emisor.options[selecionado] = null;
emisor.selectedIndex=selecionado;
if(selecionado>emisor.length-1){emisor.selectedIndex=emisor.length-1;}

}

}

function ArmaCadenaSelect(obj){
	
	IdSelect = document.getElementById(obj);
	CantId = IdSelect.length;
	
	cadenaSelect='';
	
	for(j=0; j<CantId ; j++){
	
		//alert(IdSelect[j].value + IdSelect[j].text);
		if(cadenaSelect==''){
			cadenaSelect += IdSelect[j].value;
		}else{
			cadenaSelect += ',' + IdSelect[j].value;
		}
	
	}
	return cadenaSelect;
	//alert(cadenaSelect);
	
}

///////////////////////////////////////////////////////////
function EnviarLista_Desc(url,idform, nlib, idcheck, divreload,idsocio,idsocio2, urlreturn ,divinfo,divreload,foco){
	if( ! confirm('Seguro desea aplicar los descuentos a el(los) estudiante(s) selecciondo(s) ?') ){
		return false;
	}
	val=0;
	
	codlibr=0;
	libranzas ='';
	soccios ='';
	soccios2 ='';
	num=0;
	obj = document.getElementById(idcheck);
	
	 document.getElementById(idcheck);
	
	for (i=0; ele=obj.form.elements[i]; i++){
	  if (ele.checked){
		  
			if(libranzas==''){
				libranzas = ele.value;
				socios = document.getElementById(idsocio+ele.value).value;
				socios2= document.getElementById(idsocio2+ele.value).value;
				if(document.getElementById(idsocio+ele.value).value == ''){val++ ; codlibr=ele.value;} 
				
			}else{
				libranzas += '-'+ele.value;
				socios += '-'+document.getElementById(idsocio+ele.value).value; 
				socios2 += '-'+document.getElementById(idsocio2+ele.value).value;
				if(document.getElementById(idsocio+ele.value).value == '') {val++ ; codlibr=ele.value;} 
			}
				
			num++;
	  }
	}
	
	if( num==0 ){
		alert('Usted no ha seleccionado estudiante.');
		return false;
	}
	
	if( val != 0 ){
		alert('En el estudiante de id= '+codlibr+', digite el codigo correspondiente.');
		document.getElementById(idsocio+codlibr).focus();
		return false;
	}
	
	mostrar(divreload);
	cadenaFormulario= 'idAsA='+libranzas+'&des_mat='+socios+'&des_pen='+socios2+'&num='+num;
	
	obXHR.open("POST", url, true);
	obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	obXHR.onreadystatechange = function () {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				
				alert(obXHR.responseText);
				ocultar(divreload);
				cargarFocus(urlreturn,divinfo,divreload,foco);
				
		}
	}
	obXHR.send(cadenaFormulario);
}


//FINAL ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT

function EnviarListaAtributo(url, idform, nlib, idcheck, divreload, nhoras, urlreturn, divinfo, divreload, foco){
	if( ! confirm('Seguro desea asignar los atributos seleccionados ?') ){
		return false;
	}
	val=0;
	codasig=0;
	asignatura ='';
	numhoras='';
	num=0;
	obj = document.getElementById(idcheck);
	      document.getElementById(idcheck);
		  
	
	for (i=0; ele=obj.form.elements[i]; i++){
	  if (ele.checked){
		  
			if(asignatura==''){
				asignatura = ele.value;
				
				//socios = document.getElementById(idsocio+ele.value).value;
				numhoras=document.getElementById(nhoras+ele.value).value;
				
				if(document.getElementById(nhoras+ele.value).value == ''){val++ ; codasig=ele.value;} 
				
			}else{
				
				asignatura += '-'+ele.value;
				numhoras += '-'+document.getElementById(nhoras+ele.value).value;  
				
				if(document.getElementById(nhoras+ele.value).value == '') {val++ ; codasig=ele.value;} 
			}
				
			num++;
	  }
	}
	
	if( num==0 ){
		alert('Usted no ha seleccionado atributos.');
		return false;
	}
	
	if( val != 0 ){
		alert('En el atributo de id= '+codasig+', digite el codigo correspondiente.');
		document.getElementById(nhoras+codasig).focus();
		return false;
	}
	
	mostrar(divreload);
	cadenaFormulario= 'idAsA='+asignatura+'&nhoras='+numhoras+'&num='+num;
	
	obXHR.open("POST", url, true);
	obXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
	obXHR.onreadystatechange = function () {
		if (obXHR.readyState == 4 && obXHR.status == 200) {
				
				alert(obXHR.responseText);
				ocultar(divreload);
				cargarFocus(urlreturn,divinfo,divreload,foco);
				
		}
	}
	obXHR.send(cadenaFormulario);
}


//FINAL ENVIO CHECK + OTRO OBJETO EJEMPLO: UN INPUT
