/////////////////// CLASE PARA AJAX ////////////////////////////////
	function createRequestObject() {
		var ro;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			ro = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			ro = new XMLHttpRequest();
		}
		return ro;
	}
	
	var http = createRequestObject();
////////////////////////////////////////////////////////////////////////
function Envia_form(e){
    var key = window.event ? e.keyCode : e.which;
    if(key==13)
	    {
		  Valida_form(1)
		  return(key!=13);  
		}
   }
////////////////////////////////////////////////////////////////////////

function Valida_form(x)
          { 
		     
			 
            if(x==1)
			  {
			f=document.getElementById('forma');
			 if(f.email.value=="")
			    {alert("Llene el campo email"); 
				document.forma.email.focus(); 
				return false;}
			 if(f.contra.value=="")
			    {alert("Llene el canpo contraseña");
				document.forma.contra.focus();
				return false;}	
			 
			 http.open('get','validaec.php?email='+f.email.value+'&contra='+f.contra.value);
			 http.onreadystatechange = respuesta_validaec;
			 http.send(null);
			 
			}
			else if(x==2)
			     {
			   f=document.getElementById('formaoc');
				  if(f.correooc.value=="")
			    {alert("Llene el campo correo"); 
				f.correooc.focus(); 
				return false;}
			 if(f.nssoc.value=="")
			    {alert("Llene el canpo nss");
				f.nssoc.focus();
				return false;}	
			 
			 	http.open('get','reolvidocontra.php?correo='+f.correooc.value+'&nss='+f.nssoc.value);
			 http.onreadystatechange = respuesta_enviacorreo;
			 http.send(null);
				 }
			}
			
function respuesta_validaec()
          {
		    if (http.readyState==4)   
		       {       
				if(http.status==200){  
				   var resp = http.responseText;
				   if(resp==0){
					alert('Usuario y/o contraseña incorrectos.');
					document.forma.email.value="";
					document.forma.contra.value="";
					document.forma.email.focus();
					}
					else if(resp==-1){
					alert('Usted no confirmo su registro.');
					document.forma.email.value="";
					document.forma.contra.value="";
					document.forma.email.focus();
					}
					else
					{
					//location.replace('bienvenidoec.php');
					window.open('bienvenidoec.php');
					document.forma.email.value="";
					document.forma.contra.value="";
					 }
			 	} // ajax ==200
		    } // ajax == 4 
		  }
		  
		  function respuesta_enviacorreo()
          {
		    if (http.readyState==4)   
		       {       
				if(http.status==200){  
				   var resp = http.responseText;
				   
				  if(resp==1)
					{
					alert('Listo, usted recibira la información por correo.');
					document.formaoc.correooc.value="";
					document.formaoc.nssoc.value="";
					document.formaoc.correooc.focus();
					
					 }
				  else{
					alert('Ha ocurrido un error.');
					document.formaoc.correo.value="";
					document.formaoc.nss.value="";
					document.formaoc.correo.focus();
					}
					
			 	} // ajax ==200
		    } // ajax == 4 
		  }
////////////////////////////////////////////////////////////
function Genera_buscador(tb,tper,tecta)
          {
			 // alert('...');
		   
		   if(tb==1)
		       {
		         var tit="Escriba el NSS o la CURP del cliente.";
				 document.getElementById('tipo_s').value='SA'; 
				 document.getElementById('tipo_periodo').value=tper;
				 document.getElementById('tipoecta').value=tecta;	
				 var func='Envia_form';
				/* document.getElementById('buscador').innerHTML='<b>Temporalmente  fuera de servicio,<br>generando informaci&oacute;n.</b>';
				 return false;*/
			   }
		else if(tb==2)
		       {
			     var tit="Escriba el NSS o la CURP del cliente.";
				 document.getElementById('tipo_s').value='SS';	
				 document.getElementById('tipo_periodo').value=tper;	
				 document.getElementById('tipoecta').value=tecta;	
				 var func='Envia_form';	
				 	   
			   }
		else if(tb==3)
		       {
			     var tit="Escriba el NSS o la CURP del cliente.";
				 document.getElementById('tipo_s').value='SC';	
				 document.getElementById('tipo_periodo').value=tper;	
				 document.getElementById('tipoecta').value=tecta;	
				 var func='Envia_form';	
				 	   
			   }	   	   	 
		    Genera_ec();
		  }

////////////////////////////////////////////////////////////
function Genera_ec(){
        
		var f = document.getElementById('forma2');
        var n_param='nss';
        var url='edocta/exec_system.php?n_parametro='+n_param+'&v_parametro='+f.nss.value+'&tipo_saldo='+f.tipo_s.value+'&tipo_periodo='+f.tipo_periodo.value+'&tipoecta='+f.tipoecta.value;		  
        //alert(url); 
             http.open('get',url);
			 http.onreadystatechange = respuesta_Genera_ec;
			 http.send(null);

}	
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////

function Genera_ec_men(tipo_s,tper,tecta){
    var f = document.getElementById('forma2');
    var n_param='nss';
	var url='ecuenta/exec_system.php?n_parametro='+n_param+'&v_parametro='+f.nss.value+'&tipo_saldo='+tipo_s+'&tipo_periodo='+tper+'&tipoecta='+tecta;
		//alert(url);  
http.open('get',url);
		// http.open('get','ejsystem.php?nss='+f.nss.value+'&tipo_saldo='+tipo_s+'&tipo_periodo='+tper);

			 http.onreadystatechange = respuesta_Genera_ec;
			 http.send(null);

}	
/////////////////////////////////////////////////////////////////////
function trim(cadena)
          {
		    var rcadena=cadena.replace(/^\s+|\s+$/g,"");
			//alert(rcadena+'--'+rcadena.length);
			return rcadena;
		  }
//////////////////////////////////////////////////////////////////////
function respuesta_Genera_ec(){

 if (http.readyState==4)   
		       {  
			   
				if(http.status==200)
				{  
				
				   var resp = http.responseText;
				   var arr_resp=resp.split('|');
				  var fo = 33;
				   //alert(resp+'--'+resp[2]);
				   if(parseInt(arr_resp[2])>0)
				     {
					 
					arr_resp[1]=trim(arr_resp[1]);
					  //alert(arr_resp[1]+'--'+arr_resp[1].length);
					  if(arr_resp[1]=='SC'){arr_resp[1]='SA';}
					
					window.open('ecuenta/cta_ind_sb_ses_'+arr_resp[1]+'.php?sesion='+arr_resp[0],'Estado_de_Cuenta','width=750,height=600,scrollbars=yes,resizable=no,location=no,directoeries=no');
					document.getElementById('resultado').innerHTML=' ';
					 }
					else
					 {
						
					alert(arr_resp[4]);
					document.getElementById('resultado').innerHTML='';
					 
					 }
			 		} // ajax ==200
		    } // ajax == 4 
	 else{
		     document.getElementById('resultado').innerHTML='<img src="images/edocta/cargando200x18.gif" width="200" height="18">';
		 }   	
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
function limpia(x)
 {
  
  f=document.forma;
   if(x==1){
   f.email.value="";
   f.contra.value="";
   f.email.focus();
   }
   else if(x==2)
   {
    f.correo.value="";
   f.nss.value="";
   f.correo.focus();
   }
}
function Salir()
   {
       //f=document.forma;
	 http.open('get','cierre.php');
			 http.onreadystatechange = respuesta_salir;
			 http.send(null);
   } 	
   function respuesta_salir()
   {
   if (http.readyState==4)   
		       {       
				if(http.status==200)
				{  
				   var resp = http.responseText;
				  
				   if(resp == 1)
				     {
					//alert(resp);
					location.replace('index.php');					
					 }
					
			 	} // ajax ==200
		    } // aja
   } 	  	
