//**** jv 08/11/2010
function ActivarValidarParaCamposLogin(valor){
    if (valor=="4"){ //campos autenticacion
	    ValidatorField('AU_DNI', true, "", "", "");
        ValidatorField('Mensaje_Autenticacion', true, "", "", 1000);				
	}else{
	    ValidatorField('AU_DNI', false, "", "", "");
        ValidatorField('Mensaje_Autenticacion', false, "", "", "");	
	}

}
function ValidatorField(nombre, obligatorio, formato, minimo, maximo){
	if (nombre != ""){		
		if (obligatorio != null || obligatorio != "")
			a_fields[nombre]['r'] = obligatorio;
		if (formato != "")
			a_fields[nombre]['f'] = formato;
		if (minimo != "")
			a_fields[nombre]['mn'] = minimo;
		if (maximo != "")
			a_fields[nombre]['mx'] = maximo;
	}
}
//******************************************************
// solo texto y número
function valida_ingreso2()
{
  var key=window.event.keyCode;//codigo de tecla. 
  if (key < 48 || key > 57) //si no es numero en rango ascii
  {  
    //window.event.keyCode=0;//anula la entrada de texto. 
    event.returnValue = false;//anula la entrada de otros signos. 
  }
}

function valida_solo_texto_y_numero()
{
	//verify for netscape/mozilla
	var key1=window.event.keyCode;
	var key2=event.which;
	
	var isNS4 = (navigator.appName=="Netscape")?1:0;	
	
	if(!isNS4){
		if ((key1 > 32 && key1 < 48) || (key1 > 57 && key1 < 65) || (key1 > 90 && key1 < 97) || (key1 > 122 && key1 < 129) || (key1 > 165 && key1 < 192))
			event.returnValue = false;
	}
	else{
		if ((key2 > 32 && key2 < 48) || (key2 > 57 && key2 < 65) || (key2 > 90 && key2 < 97) || (key2 > 122 && key2 < 129) || (key2 > 165 && key2 < 192)) 
			return false;
	}
}
 
function DivDisplaySexo(sexo){
  var theForm = document.frmFormulario;
  //theForm.hddCargo_Sexo.value = sexo;
  theForm.hddCargo.value = "";
  theForm.hddGrabar.value = "";
  //-- jv --16/11/2010
  theForm.hdd_Viene_Documento.value = "1";
  //-----------------------------------
  theForm.method = "POST";
  theForm.action = "formulario.asp";
  theForm.submit();
}

function ReemplazarLaboralporDomicilio()
{  
  var theForm = document.frmFormulario; 
  theForm.hddGrabar.value = "";
  theForm.Cambiar_Seccion.value = 1;
  theForm.hdd_Viene_Cambiar_Seccion.value = 1;
  theForm.method = "POST";
  theForm.action = "formulario.asp";
  theForm.submit();
}
//********* JV 23/10/2010
function EnvioLogin()
{  
  var theForm = document.frmLogin; 
  theForm.method = "POST";
  theForm.action = "ProcesoLogin.asp";
  theForm.submit();
}

//******* jv 18/10/2010
function ActualizarFechaLogin()
{
  var theForm = document.frmLogin; 
  theForm.hdd_Fecha_Nacimiento_Login.value = theForm.dia_login.value + "/" + theForm.mes_login.value + "/" + theForm.anio_login.value;  
}
//******* jv 18/10/2010
function VisualizarAsterisco(Campo, Tipo)
{  
  var nodeList = document.getElementsByTagName("EM");
  if (Tipo != 1)
  {    
    Campo.value = LTrim(Campo.value);
	if (Campo.value != "" && Campo.value != " ")
	{	  
	  for (var i = 0; i < nodeList.length; i++)
		  nodeList[i].style.display = '';
	}
	else
	  for (var i = 0; i < nodeList.length; i++)
		  nodeList[i].style.display = 'none';
  }
  else
	for (var i = 0; i < nodeList.length; i++)
	  nodeList[i].style.display = '';
}

function VisualizarAsteriscoInfLab(Campo, Tipo)
{   
  if (Tipo != 1)
  {    
    Campo.value = Trim(Campo.value);
	if (Campo.value != "")
	{	  
		O_Razon_Social_Empresa.style.display = '';
		O_Direccion_Sede.style.display = '';
		O_Pais_Sede.style.display = '';
		O_Departamento_Sede.style.display = '';
		O_Provincia_Sede.style.display = '';
		O_Distrito_Sede.style.display = '';
		O_Ciudad_Sede.style.display = '';
		O_Telefono_Central_Sede.style.display = '';
	}
	else{
		O_Razon_Social_Empresa.style.display = 'none';
		O_Direccion_Sede.style.display = 'none';
		O_Pais_Sede.style.display = 'none';
		O_Departamento_Sede.style.display = 'none';
		O_Provincia_Sede.style.display = 'none';
		O_Distrito_Sede.style.display = 'none';
		O_Ciudad_Sede.style.display = 'none';
		O_Telefono_Central_Sede.style.display = 'none';
	}
  }
  else{
	O_Razon_Social_Empresa.style.display = '';
	O_Direccion_Sede.style.display = '';
	O_Pais_Sede.style.display = '';
	O_Departamento_Sede.style.display = '';
	O_Provincia_Sede.style.display = '';
	O_Distrito_Sede.style.display = '';
	O_Ciudad_Sede.style.display = '';
	O_Telefono_Central_Sede.style.display = '';
  }
	
}

function VisualizarAsteriscoEMailLab()
{ 		
	var theForm = document.frmFormulario;
	
	O_E_mail_Laboral.style.display = 'none';
	if (theForm.OptInEMailLaboral.checked == true)
	  O_E_mail_Laboral.style.display = '';
}

function LTrim(s){
	// Devuelve una cadena sin los espacios del principio
	var i=0;
	var j=0;
	
	// Busca el primer caracter <> de un espacio
	for(i=0; i<=s.length-1; i++){
	    j=i;
		if(s.substring(i,i+1) != ' ')		
			break;
	}	
	return s.substring(j, s.length);
}

function RTrim(s){
	// Quita los espacios en blanco del final de la cadena
	var j=0;
	
	// Busca el último caracter <> de un espacio
	for(var i=s.length-1; i>-1; i--)
		if(s.substring(i,i+1) != ' '){
			j=i;
			break;
		}
	return s.substring(0, j+1);
}
function Trim(s){
	// Quita los espacios del principio y del final
	return LTrim(RTrim(s));
}

function ActualizarFechaForm()
{
  var theForm = document.frmFormulario; 
  theForm.hdd_Fecha_Nacimiento.value = theForm.Dia.value + "/" + theForm.Mes.value + "/" + theForm.Anio.value;  
}

function LlenarCampoHdd(Obj1,Obj2)
{  
  var theForm = document.frmFormulario;
  if (Obj1[Obj1.selectedIndex].value != '')
    Obj2.value = Obj1[Obj1.selectedIndex].text;
  else
    Obj2.value = '';
}

function LlenarCampoParaHddSincronizar_Eventos(Obj1,Obj2)
{  
  var theForm = document.frmFormulario;
  if (Obj1.checked == true)
    Obj2.value = "1";
  else
    Obj2.value = '';
}

function consisfec(xdia,xmes,xano) 
{
  if (parseInt(xdia)==0 || parseInt(xmes)==0 || parseInt(xano)==0) return false;
  var meses=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  meses[1]=((xano % 4)==0) ? 29 : 28;
  return ((xdia<=meses[xmes-1]) ? true : false );  // true -> OK     false -> KO
}

function GrabarForm(){
  var theForm = document.frmFormulario;  
  if (v.exec()){    
    if (validaDireccion()){
      theForm.hddGrabar.value = theForm.btnGrabar.value;
      theForm.method = "POST";
      theForm.action = "formulario.asp";
      theForm.submit();
    }
  }
}

//------- JV 11/11--  QUITÉ validaCaracterLogin()
function GrabarFormLogin(){
  //alert("voy a verificar");
  
  var theForm = document.frmLogin;      

	    if (v_login.exec()){ 
         theForm.hdd_Enviar_Login.value = theForm.btnEnviarLogin.value;
         theForm.method = "POST";
         //theForm.action = "ProcesoLogin.asp";
		 theForm.action = "Formulario.asp";
         theForm.submit();
		}
}
//===========================================
function validaDireccion(){
	var theForm = document.frmFormulario;
	var msg = ''
	for(var i=0; i<theForm.length; i++)
	{	    
		if (theForm[i].name=='Direccion'){
		  if (NoTieneNumero(theForm.Direccion) && Trim(theForm.Direccion.value) != "")
			msg = msg + "El campo \"Dirección de Domicilio\" no tiene número.\n";
		}
		if (theForm[i].name=='Direccion_Sede'){
		  if (NoTieneNumero(theForm.Direccion_Sede) && Trim(theForm.Direccion_Sede.value) != "")
			msg = msg + "El campo \"Dirección de Sede\" no tiene número.\n";
		}
	}
	if (msg!='')
		return confirm(msg + "¿Está seguro de continuar?.");
	else
		return true;
}

function NoTieneNumero(obj){
  var checkOK = "1234567890";
  var checkStr = obj.value;
  var allValid = true;
  for (var i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (var j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j)){
        allValid = false;
        break;
      }
  }
  return allValid;  
}

function NuevaAsignacion()
{
  var theForm = document.frmFormulario; 
  theForm.method = "POST";
  theForm.action = "Editar_Asignacion.asp";
  theForm.submit();
}

function EliminarAsignacion()
{
  var theForm = document.frmFormulario;
  var variable;
  
  if (ChequearEliminar())
  {
    if (!(confirm("Está seguro que desea eliminar la(las) Asignación(es) seleccionada(s)?")))
    {     
      return false;
    }
    theForm._hidNuevaConsulta.value = "FALSE";  //Esto es para la tablaDinamica
    theForm.method = "POST";
    theForm.action = "Adm_Asignacion.asp?Accion=Eliminar";
    theForm.submit();
  }
  else
	alert("No ha seleccionado ninguna Asignación de formulario para eliminar"); 
}


function NuevoFormulario()
{
  var theForm = document.frmFormulario; 
  theForm.method = "POST";
  theForm.action = "Editar_Formulario.asp";
  theForm.submit();
}

function EliminarFormulario()
{
  var theForm = document.frmFormulario;
  var variable;
  
  if (ChequearEliminar())
  {
    if (!(confirm("Está seguro que desea eliminar el(los) Formulario(s) seleccionado(s)?")))
    {     
      return false;
    }
     theForm._hidNuevaConsulta.value = "FALSE";  //Esto es para la tablaDinamica
    theForm.method = "POST";
    theForm.action = "Adm_Formularios.asp?Accion=Eliminar";
    theForm.submit();
  }
  else
	alert("No ha seleccionado ningún formulario para eliminar"); 
}
//******************************************************************************
// jv 16/11/2011
function GrabarProductoXFormulario()
{
  var theForm = document.frmFormulario;
  
  if (ChequearProductoXFormulario()) //chequea si hay elementos para grabar
  {
    if(ChequearTextoAlternoParaProductoXFormulario()){
		theForm.method = "POST";
		theForm.action = "Adm_Asignar_Productos.asp?Accion=Grabar";
		theForm.submit();
	}	
  }
  else
	alert("No ha seleccionado ningún producto para grabar"); 
}
//*************************************************
function VerificarDisabled()
{
  var theForm = document.frmFormulario;
  if (ChequearEliminar()) 
    theForm.btnEliminar.disabled = false;  
  else
    theForm.btnEliminar.disabled = true;
}
//***JV 20/11/2011
function VerificarDisabledGrabar()
{
  var theForm = document.frmFormulario;
  if (ChequearProductoXFormulario()) 
    theForm.btnGrabar.disabled = false;  
  else
    theForm.btnGrabar.disabled = true;
}
//************************************
function ChequearEliminar()
{
  var theForm = document.frmFormulario;
  var Longitud = theForm.chkEliminar.length;
  var Cont=0;
  if (Longitud > 1)
  {
    for(var i=0; i<Longitud; i++)
    {      
      if (theForm.chkEliminar[i].checked == true)
        Cont=Cont+1;
    }
    if (Cont>0)
      return true;
    else
      return false;
  }
  else
  {
    if (theForm.chkEliminar.checked == true)
      return true;
    else
      return false;
  }
}

// jv 20/11/2011
function ChequearProductoXFormulario()
{
  var theForm = document.frmFormulario;
  var LongitudString = theForm.Cantidad_Productos.value;
  var Longitud;

	if(LongitudString != ""){
		  Longitud = parseInt(LongitudString);
		  
		  if(!isNaN(Longitud)){
			
			    var Cont=0;
			    var chk;
				for(var i=1; i<=Longitud; i++)
				{      
				   //alert("chkGrabar"+i);
				  
				  chk = document.getElementById("chkGrabar"+i);
				  if (chk.checked == true)
					Cont=Cont+1;
				}
				if (Cont>0)
				  return true;
				else
				  return false;
			
		   }else{
			   return false;
		   }
		   
	}else{
	    return false;
	}
	
}
//***  jv 20/11/2011   ******************************
function ChequearTextoAlternoParaProductoXFormulario()
{
  var theForm = document.frmFormulario;
  var LongitudString = theForm.Cantidad_Productos.value;
  var Longitud;
  var mensaje = "";
  
  if(LongitudString != ""){
      Longitud = parseInt(LongitudString);
	  if(!isNaN(Longitud)){
	     var chk;
		 var txtAlterno;
		 for(var i=1; i<=Longitud; i++)
		 {      
		     //verificamos solo si está chequeado
			 chk = document.getElementById("chkGrabar"+i);
		     if (chk.checked == true){
			      //chequeamos el texto
				  // si es vacio, mandamos mensaje
				  txtAlterno = document.getElementById("txtNombreAlterno"+i);
				  if (txtAlterno.value == ""){
					  mensaje = "Debe colocar el nombre alternativo en los campos de texto a grabar";
					  alert(mensaje);
					  return false;
					  break;
				  }
			 
			 }
	     }
		 //si revisa y todo está bien
		 return true;
      }else{
	     return false;
	  }
  }else{
      return false;
  }
}
//************************************************************
 function soloAlfanumericos(e){
	tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla==8) return true; // 3
    patron =/[A-Za-zñÑáéíóúÁÉÍÓÚ0-9\(\)\-\s]/; // 4
    te = String.fromCharCode(tecla); // 5
    return patron.test(te); // 6
   }

//************************************************************

//PARA BÚSQUEDA DE EMPRESAS
var codEmpresa;
var codSede;

    
function getValue (codEmpresa, codSede, tipo) 
{
	this.codEmpresa = codEmpresa;
	this.codSede = codSede;
	if (tipo == 1)
	  open ('searchEmpresa/index.asp','popup','width=521,height=330,toolbar=no,menubar=no,scrollbars=yes');
	else
	  open ('searchEmpresa/index.asp?PARAM=' + codEmpresa.value,'popup','width=521,height=330,toolbar=no,menubar=no,scrollbars=yes');
}
    
function configura() {
	var theForm = document.frmFormulario;
	theForm.hddGrabar.value = "";
	theForm.method = "POST";
	theForm.action = "formulario.asp";
	theForm.submit(); 
} 
//*** jv 14/11/2010*************
function validaVieneEmpresa() {
	var theForm = document.frmFormulario;
	theForm.hdd_Viene_Empresa.value = "1";
} 

function EmpresaSedeDisabled(){
	var theForm = document.frmFormulario;
	if(theForm.hddCodigo_Empresa.value != -1 && theForm.hddCodigo_Empresa.value != ""){
	    theForm.E_mail_Laboral.focus();
		theForm.Razon_Social_Empresa.disabled = true;
		theForm.RUC_Empresa.disabled = true;
		if(theForm.hddCodigo_Sede.value != -1 && theForm.hddCodigo_Sede.value != ""){		  
		  theForm.Via_Sede.disabled = true;		  
		  theForm.Direccion_Sede.disabled = true;
		  theForm.Urbanizacion_Sede.disabled = true;
		  theForm.Pais_Sede.disabled = true;
		  theForm.Departamento_Sede.disabled = true;
		  theForm.Provincia_Sede.disabled = true;
		  theForm.Distrito_Sede.disabled = true;
		  theForm.Telefono_Central_Sede.disabled = true;
		  
		  theForm.hddVia_Sede.disabled = true;
		  theForm.hddPais_Sede.disabled = true;
		  theForm.hddDepartamento_Sede.disabled = true;
		  theForm.hddProvincia_Sede.disabled = true;
		  theForm.hddDistrito_Sede.disabled = true;
		}
	}
} 


