


//Funcion: validar_logeo()
//Descripcion: Validación del formulario de logeo
//Origen: Formularios/General/f_logeo.php 
//Implementado en: Documentos/General/logeo.php

function validar_logeo()	    
{
      var ok=1;//si la validacion es correcta ok=1 de lo contrario ok=0									      	
   	  if( window.document.Logeo.usuario.value == "" )
        {
      	 alert("Debe ingresar su nombre de usuario");
         window.document.Logeo.usuario.focus();
   	     ok=0;											   
		 return false;
        }
      
      
   	  if( window.document.Logeo.clave.value == "" )
        {
      	 alert("Debe ingresar una clave");
         window.document.Logeo.clave.focus();
  	     ok=0;											   
		 return false;
        }

      if(ok=1)//validacion correcta
        {
	     window.document.Logeo.submit();
	     return true;
	    }
 }
 
 //fin de la funcion validar_logeo();
 
 
//Funcion: validar_logeo()
//Descripcion: Validación del formulario de logeo
//Origen: Formularios/General/f_logeo.php 
//Implementado en: Documentos/General/logeo.php

function validar_cambiar_clave()	    
{
      var ok=1;//si la validacion es correcta ok=1 de lo contrario ok=0									      	
	  
	  //usuario y clave actuales
   	  if( window.document.cambiar_clave.usuario_actual.value == "" )
        {
      	 alert("Debe ingresar su nombre de usuario actual");
         window.document.cambiar_clave.usuario_actual.focus();
   	     ok=0;											   
		 return false;
        }
      
      
   	  if( window.document.cambiar_clave.clave_actual.value == "" )
        {
      	 alert("Debe ingresar su clave actual");
         window.document.cambiar_clave.clave_actual.focus();
  	     ok=0;											   
		 return false;
        }
		
      
      
   	  if( window.document.cambiar_clave.nueva_clave.value == "" )
        {
      	 alert("Debe ingresar su nueva clave");
         window.document.cambiar_clave.nueva_clave.focus();
  	     ok=0;											   
		 return false;
        }

		
		//envio del formulario

      if(ok=1)//validacion correcta
        {
	     window.document.cambiar_clave.submit();
	     return true;
	    }
 }
 
//Funcion: validar_menu_cr()
//Descripcion:  Validación del formulario cr
//Origen: Ordenes de Servicio\Formularios\
//Implementado en: donde se requiera
  function validar_menu_cr() 
{ 
 clv=window.document.m_cr.clave.value;
 usu=window.document.m_cr.usuario.value;
 operac=window.document.m_cr.operacion.value;
 window.document.m_cr.submit();
 window.document.m_cr.clave.value=clv;
 window.document.m_cr.usuario.value=usu;
 window.document.m_cr.operacion.value=operac;
 return true;
} 


//Funcion: max(txarea)longitud=1000
//Descripcion: limita la cantidad de caracteres que se deben digitar en un textarea
//Origen: Ordenes de Servicio\Formularios\General
//Implementado en: donde se requiera
  function max(txarea) 
{ 
    total = 1000; 
    tam = txarea.value.length; 
    str=""; 
    str=str+tam;   
	/*
    Digitado.innerHTML = str; 
    Restante.innerHTML = total - str; 
	  */
    if (tam > total){ 
        aux = txarea.value; 
        txarea.value = aux.substring(0,total); 
       /* Digitado.innerHTML = total 
        Restante.innerHTML = 0 */
    } 	   
	
	
} 
//fin de la funcion max(txarea)

//Funcion: max2(txarea) lonfitud=100
//Descripcion: limita la cantidad de caracteres que se deben digitar en un textarea
//Origen: Ordenes de Servicio\Formularios\General
//Implementado en: donde se requiera
  function max2(txarea) 
{ 
    total = 100; 
    tam = txarea.value.length; 
    str=""; 
    str=str+tam; 
    Digitado.innerHTML = str; 
    Restante.innerHTML = total - str; 

    if (tam > total){ 
        aux = txarea.value; 
        txarea.value = aux.substring(0,total); 
        Digitado.innerHTML = total 
        Restante.innerHTML = 0 
    } 
} 
//fin de la funcion max2(txarea)

//Funcion: validar_vacio()
//Descripcion: valida si el area de texto solicitud esta vacia antes del envio
//Origen: Ordenes de Servicio\Formularios\General
//Implementado en: donde se requiera
  function validar_vacio() 
{ 
    campo= window.document.solicitud.orden.value; 
    if(campo=="")
	  { 
	   alert("Debe digitar una Solicitud");
	   window.document.solicitud.orden.focus();
	   return false;
      } 
	 else
	  {
       window.document.solicitud.submit();   	  
	   return true;
	  } 
} 


//Funcion: NoAtras()
//Descripcion: Evitar navegacion
//Origen: Ordenes de Servicio\Formularios\General
//Implementado en: donde se requiera
function NoAtras()
{			   

 history.go(1);
} 

//Funcion: NoAtras()
//Descripcion: Evitar navegacion y clocar el foco en el campo usuario
//Implementado en: Ordenes de Servicio\Formularios\General\logeo.php
function NoAtras_focus()
{
 history.go(1);
 window.document.Logeo.usuario.focus();
} 

//Funcion: borrar_txt(solucion)
//Descripcion: borrar un campo y ubicar el foco
//Implementado en: donde se requiera

function borrar_txt(campo)
{
 campo.value="";
 campo.focus();
}
	   
 function muestraReloj()
{
 history.go(1);			
// Compruebo si se puede ejecutar el script en el navegador del usuario
if (!document.layers && !document.all && !document.getElementById) return;
// Obtengo la hora actual y la divido en sus partes
var fechacompleta = new Date();
var horas = fechacompleta.getHours();
var minutos = fechacompleta.getMinutes();
var segundos = fechacompleta.getSeconds();
var ano=fechacompleta.getYear();
var mes=fechacompleta.getMonth()+1;
var dia=fechacompleta.getDate();

//window.document.sesion.info_sesion.value="Sesión: Admin - Ingreso: "+ano+"/"+mes+"/"+dia+" "+horas+":"+minutos+":"+segundos;
var mt = "AM";
// Pongo el formato 12 horas
if (horas > 12) {
mt = "PM";
horas = horas - 12;
}
if (horas == 0) horas = 12;
// Pongo minutos y segundos con dos dígitos
if (minutos <= 9) minutos = "0" + minutos;
if (segundos <= 9) segundos = "0" + segundos;
// En la variable 'cadenareloj' puedes cambiar los colores y el tipo de fuente
cadenareloj = " "+dia+"/"+mes+"/"+ano+" "+ horas + ":" + minutos + ":" + segundos + " " + mt;
// Escribo el reloj de una manera u otra, según el navegador del usuario
if (document.layers) {
document.layers.spanreloj.document.write(cadenareloj);
document.layers.spanreloj.document.close();
}
else if (document.all) spanreloj.innerHTML = cadenareloj;
else if (document.getElementById) document.getElementById("spanreloj").innerHTML = cadenareloj;
// Ejecuto la función con un intervalo de un segundo
setTimeout("muestraReloj()", 1000);
}


//Funcion: validar_elim()
//Descripcion: valida si el un registro antes de eliminarlo
//Implementado en: donde se requiera
function validar_elim(frm) 
{    
 if(confirm("Seguro que desea eliminar este registro?"))
   {
    frm.submit(); 	   
    return true;
   }else return false; 
} 

//Funcion: validar_info()
//Descripcion: valida si el area de texto de vigencia em los info es vacio
//Origen: Contratacion/Frm\General
//Implementado en: donde se requiera
function validar_info(frm) 
{
  	  var ok=1;//si la validacion es correcta ok=1 de lo contrario ok=0									      	
      if(frm.vigencia.value=="")
	  { 
	   alert("Debe ingresar una vigencia");
	   frm.vigencia.focus();
	   ok=0;
	   return false;
      } 
	 if(ok==1)
	  {
       frm.submit();   	  
	   return true;
	  } 
} 
  //salir de una ventana
  function salir()
  {		  
   if(confirm("¿Salir de la aplicación?"))
   {
    window.opener = top;
    top.window.close();
   }	
  }

 ///funcion para validar un campo numerico
 
 function val_num(texto)
 { 
  if(isNaN(texto.value))
  {    		
    alert("Este campo requiere un valor numerico");
	texto.value='';								   
	texto.focus();
  }	
 }
   
 
 /*********************VALIDACION DE FECHAS****************************************/
 function esDigito(sChr){
var sCod = sChr.charCodeAt(0);
return ((sCod > 47) && (sCod < 58));
}
function valSep(oTxt){
var bOk = false;
bOk = bOk || ((oTxt.value.charAt(4) == "-") && (oTxt.value.charAt(7) == "-"));
bOk = bOk || ((oTxt.value.charAt(4) == "/") && (oTxt.value.charAt(7) == "/"));
return bOk;
}
function finMes(oTxt){
var nMes = parseInt(oTxt.value.substr(5, 2), 10);	 
var Ano = oTxt.value.substr(0,4);
var nRes = 0;
switch (nMes){
case 1: nRes = 31; break;
case 2:
 if(Ano % 4 ==0)
  nRes = 29;
 else 		
  nRes = 28;
break;
case 3: nRes = 31; break;
case 4: nRes = 30; break;
case 5: nRes = 31; break;
case 6: nRes = 30; break;
case 7: nRes = 31; break;
case 8: nRes = 31; break;
case 9: nRes = 30; break;
case 10: nRes = 31; break;
case 11: nRes = 30; break;
case 12: nRes = 31; break;
}
return nRes;
}
function valDia(oTxt){
var bOk = false;
var nDia = parseInt(oTxt.value.substr(8,2), 10);
bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
return bOk;
}
function valMes(oTxt){
var bOk = false;
var nMes = parseInt(oTxt.value.substr(5,2), 10);
bOk = bOk || ((nMes >= 1) && (nMes <= 12));
return bOk;
}
function valAno(oTxt){
var bOk = true;
var nAno = oTxt.value.substr(0,4);
bOk = bOk && ((nAno.length == 2) || (nAno.length == 4));
if (bOk){
for (var i = 0; i < nAno.length; i++){
bOk = bOk && esDigito(nAno.charAt(i));
}
}
return bOk;
}

function valAnoVig(oTxt,vig)
{
 var bOk = true;
 var nAno = oTxt.value.substr(0,4);
 if(nAno!=vig)
 {
  bOk=false; 
 }
 return bOk;
}



function valFecha(oTxt){
var bOk = true;
if (oTxt.value != ""){
bOk = bOk && (valAno(oTxt));
bOk = bOk && (valMes(oTxt));
bOk = bOk && (valDia(oTxt));
bOk = bOk && (valSep(oTxt));
if (!bOk){
alert("Fecha inválida. Ej: 2007-01-31");
//oTxt.value = "";	 
oTxt.select();
oTxt.focus();
} 

}
}	   

//validar fecha y vigencia
function valFechaVig(oTxt,vig){
var bOk = true;
var bvig = true;
if (oTxt.value != ""){
bOk = bOk && (valAno(oTxt));
bOk = bOk && (valMes(oTxt));
bOk = bOk && (valDia(oTxt));
bOk = bOk && (valSep(oTxt));
bvig = bvig && (valAnoVig(oTxt,vig));
if (!bOk||!bvig){
alert("Fecha inválida");
//oTxt.value = "";	  
oTxt.select();
oTxt.focus();
}


}
}
 
 /********************************************************************************/

//FUNCIONES  PARA VALIDAR CARACTERES ACEPTADOS EN UN CAMPO DE TEXTO

function ValTxt(txt)
{				   
 var str=txt.value.substr(0);
 // Return immediately if an invalid value was passed in
 if (str+"" == "undefined" || str+"" == "null")	
 return false;
 var Valido = true;
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {
  if(!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
       ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
       ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))||	    
	    (str.charAt(i) == ".") || (str.charAt(i) == "-")||
		(str.charAt(i) == " ") ||
		(str.charAt(i) == "ñ") || (str.charAt(i) == "Ñ")
	  )
	)
	{
	 Valido = false;
	 break;
	}	
  } // END for   
    
 if(!Valido) 
 {			  
  alert("El texto contiene caracteres no válidos");
 // txt.value="";
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 

//FUNCIONES  PARA VALIDAR CARACTERES ACEPTADOS EN UN CAMPO DE TEXTO DE BUSQUEDA
function ValTxtBuscar(txt)
{				   
 var str=txt.value.substr(0);
 var Valido = true;
 // Return immediately if an invalid value was passed in

 
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {
  if(!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
       ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
       ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))||	    
	    (str.charAt(i) == ".") || (str.charAt(i) == "-")||
		(str.charAt(i) == "*") || (str.charAt(i) == " ")||
		(str.charAt(i) == "ñ") || (str.charAt(i) == "Ñ")		
	  )
	)
	{
	 Valido = false;
	 break;
	}	
  } // END for   
    
 if(!Valido) 
 {			  
  alert("El texto contiene caracteres no válidos");
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 
  
//FUNCIONES  PARA VALIDAR CARACTERES ALFANUMERICOS

function esAlfaNum(txt)
{				   
 var str=txt.value.substr(0);
 // Return immediately if an invalid value was passed in
 if (str+"" == "undefined" || str+"" == "null")	
 return false;
 var Valido = true;
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {
  if(!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9")) || 
       ((str.charAt(i) >= "a") && (str.charAt(i) <= "z")) ||
       ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))||
		(str.charAt(i) == "ñ") || (str.charAt(i) == "Ñ")||
		(str.charAt(i) == " ")	   	    
	  )
	)
	{
	 Valido = false;
	 break;
	}	
  } // END for   
    
 if(!Valido) 
 {			  
  alert("El texto contiene caracteres no alfanuméricos");
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 

//FUNCIONES  PARA VALIDAR CARACTERES ALFABETICOS

function esAlfa(txt)
{				   
 var str=txt.value.substr(0);
 // Return immediately if an invalid value was passed in
 if (str+"" == "undefined" || str+"" == "null")	
 return false;
 var Valido = true;
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {
  if(!(((str.charAt(i) >= "a") && (str.charAt(i) <= "z"))||
       ((str.charAt(i) >= "A") && (str.charAt(i) <= "Z"))||    
		(str.charAt(i) == "ñ") || (str.charAt(i) == "Ñ")	   
	  )
	)
	{
	 Valido = false;
	 break;
	}	
  } // END for   
    
 if(!Valido) 
 {			  
  alert("El texto contiene caracteres no alfanuméricos");
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 

//FUNCIONES  PARA VALIDAR CARACTERES NUMERICOS

function esNum(txt)
{				   
 var str=txt.value.substr(0);
 // Return immediately if an invalid value was passed in
 if (str+"" == "undefined" || str+"" == "null")	
 return false;
 var Valido = true;
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {
  if(!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9"))))
	{
	 Valido = false;
	 break;
	}	
  } // END for   
    
 if(!Valido) 
 {			  
  alert("Este campo requiere un valor numérico");
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 

function esDec(txt)
{				   
 var str=txt.value.substr(0);
 // Return immediately if an invalid value was passed in
 if (str+"" == "undefined" || str+"" == "null")	
 return false;
 var Valido = true;
// convert to a string for performing string comparisons.
 str += "";	
 for (i = 0; i < str.length; i++)
 {	
  if(!(((str.charAt(i) >= "0") && (str.charAt(i) <= "9"))||
        (str.charAt(i) == ",") || (str.charAt(i) <= ".")
      )
    )
	{
	 Valido = false;
	 break;
	}	 
	if(isNaN(str.charAt(i))&&isNaN(str.charAt(i+1)))
	{
	 Valido = false;
	 break;	
	}
  } // END for   
    
 if(!Valido) 
 {			  
  alert("Este campo requiere un valor numérico");
  txt.select();
  txt.focus(); 
  return false;
 }else return true;					 
	   
} 		  
  
// s es vacio
function isEmpty(s)			   
{ 
  return ((s == null) || (s.length == 0))
}
		 
//funcion para recortar espacios en blanmco al inicio y final de una cadena
function recortar(txt)
{
 if(txt.value=="")
 {
  return "";
 }			
 else
 {
    var cadena=txt.value.substr(0);	
	//recortar espacios a la izquierda
    for(i=0; i<cadena.length;)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	//recortar espacios a la derecha
	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}  
	   return cadena;	
  }  
}
// s es vacio o solo caracteres de espacio
function hayEspacios(s)
{  

    var i;	 
    var vacios=false;		      
	var str=recortar(s).substr(0);
//    var str=s.value.substr(0);
	
    
    if (s+"" == "undefined" || s+"" == "null")	
     vacios=true;

    for (i = 0; i < str.length; i++)
    {    
        var c = str.charAt(i);
		
        if (c==" ") vacios=true;
    }
    return vacios;
} 

// s es una direccion de correo valida
function esEmail (txt)
{	   	 
 var correo=recortar(txt).substr(0);	  
	
 if(correo=="")
 {
	return true;
 }	
 else
 {	
    regx = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
    return regx.test(correo);
  }
   	
}

   //lamar a lafuncion isEmail
function valEmail(txt)   
{	   
 	 if(!esEmail(txt)) 
	 {			  
	  alert("Este Correo Electronico no es valido");
	  txt.select();
	  txt.focus(); 
	  return false;
	 }else return true;	
}

function enviar_frm(frm,op)
{			  
 frm.operacion.value=op;
 frm.submit();
}
				
function enviar_frm_fechas(frm)
{
    ok=1;
   	if (frm.fecha1.value == "" )
      {	
      	 alert("Por Favor Diligencie la Fecha 1");
		  frm.fecha1.focus();
		 ok=0;		
      	 return false;
      }

  
  if ( frm.fecha2.value == "" )
      {	
      	alert("Por Favor Diligencie la Fecha 2");
		frm.fecha2.focus();
		ok=0;		
      	return false;
      }		
	   
   if(ok==1)
   {
    frm.submit();
	return true;
   }
}
	  
//Funcion que agrega un <br> en un salto de linea

function InsertarSaltoLinea(campo)
{					 
 var tecla=event.keyCode;
 if(tecla==13)
 {
 // campo.value=campo.value+"<br>";
 } 
}							

//Descripcion: Cerrar Ventana

function cerrar_ventana() 
{    
 if(confirm("¿Seguro que desea salir?"))
   {
    window.close();    
   }
} 

function detectar_navegador()
{
 if(navigator.appName=="Netscape")
 {
   alert("Para mejor visualización de esta página, se recomienda usar El Navegador Internet Explorer");
 }
}	  

//chequear y deschequear los checkbox de un formulario
function chequear_cb(frm,val)
{
 //val =1: chequeado
 //val=0: deschequeado    
   for (i=0;i<frm.elements.length;i++)
   {
      if(frm.elements[i].type == "checkbox")
         frm.elements[i].checked=val
   }      
}
