/////////////////// 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_ec(tipo_s,tper){
   f=document.forma;
 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 respuesta_Genera_ec(){

 if (http.readyState==4)   
		       {       
				if(http.status==200)
				{  
				   var resp = http.responseText;
				   var arr_resp=resp.split('|');
				   var fo = 33;
				   if(resp != 0)
				     {
					//alert(resp);
					window.open('edo_cta_h1.2.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('No se encontro información.');
					 }
			 	} // ajax ==200
		    } // ajax == 4 
	 else{
		     document.getElementById('resultado').innerHTML='<img src="imagenes/edoctaafore/cargando200x18.gif" width="200" height="18">';
		 }   	
}
*/
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////

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_men;
			 http.send(null);

}	
/////////////////////////////////////////////////////////////////////
function trim(cadena)
          {
		    var rcadena=cadena.replace(/^\s+|\s+$/g,"");
			//alert(rcadena+'--'+rcadena.length);
			return rcadena;
		  }
//////////////////////////////////////////////////////////////////////
function respuesta_Genera_ec_men(){

 if (http.readyState==4)   
		       {  
			   
				if(http.status==200)
				{  
				
				   var resp = http.responseText;
				   var arr_resp=resp.split('|');
				  var fo = 33;
				   //alert(resp);
				   if(arr_resp[0]!=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
					 {
						  if(parseInt(trim(arr_resp[2]))==-30)
					       {
					        
					                  alert('Dentro de los primeros 5 dias hábiles del mes\n no se puede generar un estado de cuenta con corte al mes inmediato anterior');
					                  document.getElementById('resultado').innerHTML='';	               
						      
						    }
							else{
					alert('No se encontro informacion'+arr_resp[2]);
					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
   } 	  	