function validaFieldValue(campo, tipo) {
    var valoresInvalidosRE;
    if (tipo == 'alf'){
        valoresInvalidosRE = /[^\w\dÃ±\.,\s-]/ig;
    }
    else if (tipo == 'num'){
        valoresInvalidosRE = /[^\d\.-]/ig;
    }
    else if (tipo == 'mail'){
        valoresInvalidosRE = /[^\w\dÃ±\.\s@-]/ig;
    }
    if (campo.value.match(valoresInvalidosRE)){
        campo.value = campo.value.replace(valoresInvalidosRE, '');
    }
}

function validaField(e,tipo)
{
    funcion = true;
    if (navigator.appName == 'Microsoft Internet Explorer')
        key = window.event.keyCode;
    else
        key = e.which;
    if(key != 0){
    	if(tipo == 'alf'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 44
			)
			{funcion =  false; }
    	 }

    	else if(tipo == 'log'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			//&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			//&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0 && key != 8
			)
			{funcion =  false; }
    	 }
    	else if(tipo == 'txt'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
			)
			{funcion =  false; }
    	 }
    	else if(tipo == 'mail'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 45
            && key != 95
            && key != 64
			)
			{funcion =  false; }
    	 }
    	 else if(tipo == 'mailMINUS'){
    		if ((key < 96 || key > 122)
			&& key != 8
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 95
            && key != 64
			)
			{funcion =  false; }
    	 }
    	else if (tipo == 'num'){
	    	if ((key < 48 || key > 57) && key != 0 && key != 8)
	    	{ funcion = false  }
    	}
	    else if (tipo == 'fch'){
	 		if ((key < 47 || key > 57) && key != 0 && key != 8)
	 		{funcion = false}
	    }
	    else if (tipo == 'tel'){
		    if (key ==39)
		    {	 funcion = false }
	    }
	    else if (tipo == 'calif'){
		    if ((key < 45 || key > 57 ) && key != 47 )
		    { funcion = false	}
	    }
	    else if (tipo == 'hora'){
		    if ((key < 48 || key > 57) && key != 0 && key != 8 && key!=58)
		    {	 funcion = false }
	    }
	    if(tipo == 'conoc'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
            && (key < 48 || key > 57)
            && key != 0
            && key != 46
            && key != 44
            && key != 40
            && key != 41
            && key != 37
			)
			{funcion =  false; }
    	 }
    	 else if(tipo == 'txt2'){
    		if ((key < 65 || key > 122 || (key > 90 && key < 97))
			&& key != 32 && key != 8
			&& key != 44 && key != 46
			&& key != 225 && key != 233 && key != 237 && key != 243 && key != 250 //minisculas
			&& key != 193 && key != 201 && key != 205 && key != 211 && key != 218 //mayusuculas
			&& key != 209 && key != 241
			)
			{funcion =  false; }
    	 }
    }
    return funcion;
}



function isEmail(pEmail)
{
    var swOK=2;
	pCaracter=pEmail.value.replace(" ","\0");
	if(validaField(pEmail,"mail") == true)
    {
	    if (pEmail.value != "")
        {
		    for (var i = 0; i < pCaracter.length; i++)
            {
			    var sByte = pCaracter.substring(i, i + 1);
				if (sByte=="@" || sByte==".") { swOK = swOK - 1; }
            }
			if (swOK > 0 || pCaracter.length < 5 || pCaracter.charAt(0) == "@" || pCaracter.charAt(0) == "." || pCaracter.charAt(pCaracter.length-1)=="@" || pCaracter.charAt(pCaracter.length-1)=="." || pCaracter.charAt(pCaracter.indexOf("@")+1)==".")
			{
			    pEmail.focus();
				alert("DEBES CAPTURAR UN CORREO ELECTRONICO VALIDO");
				return false;
            }
        }
    }
    return true;
}


function chkidioma(_tipo_idioma, _tipo_dominio )
{
    if(_tipo_idioma.value == "0" || _tipo_idioma.value == "5" || _tipo_idioma.value == "6")
	{
	    _tipo_dominio[0].checked = false;
	    _tipo_dominio[1].checked = false;
	    _tipo_dominio[2].checked = false;
	 }
}


function discapacidad(_tipo_discapacidad2, _tipo_discapacidad)
{
    var valor = _tipo_discapacidad2.value;
    if( valor == "1")
    {
        _tipo_discapacidad[0].checked = false;
        _tipo_discapacidad[1].checked = false;
        _tipo_discapacidad[2].checked = false;
        _tipo_discapacidad[3].checked = false;
    }
}

function chkdiscapacidad(_tipo_discapacidad2, _tipo_discapacidad)
{
    valor = _tipo_discapacidad.value;
    if(!_tipo_discapacidad2[1].checked)
    {
        _tipo_discapacidad.checked = false;
	}
}

function validaInsLogin(_vlogin, _vpass, _vconfirma)
{
    var max = 9;

    if (_vlogin.value == "")
    {
        alert("Debe capturar el Usuario de Acceso al Sistema");
        _vlogin.focus();
        v = "false";
        return false;
    }

    if(_vlogin.value.length < max)
    {
        alert("El Usuario debe ser exactamente de 9 caracteres");
        _vlogin.focus()
        return false;
    }

  
    if(!validateLogin(_vlogin)){
          return false;
      }

    if (_vpass.value == "")
    {
        _vpass.focus();
        alert("Debe capturar la Clave de Acceso al Sistema");
        return false;
    }
    if(_vpass.value.length < max)
    {
        _vpass.focus();
        alert("La Clave debe ser exactamente de 9 caracteres");
        return false;
    }

 if(!validateLogin(_vpass)){
          return false;
      }
   

    if (_vconfirma.value == "")
    {
        _vconfirma.focus();
        alert("Debe capturar la confirmación de su Clave de Acceso al Sistema");
        return false;
    }

    if(_vconfirma.value.length < max)
    {
        _vconfirma.focus();
        alert("La Confirmación Clave debe ser exactamente de 9 caracteres");
        return false;
    }

   if(!validateLogin(_vconfirma)){
          return false;
      }

    if (!(_vpass.value == _vconfirma.value))
    {
        _vconfirma.focus();
        alert("La confirmación de password es incorrecta, favor de confirmar nuevamente");
        return false;
    }




    return true;
}

function cambiaMotivo(_tipo_trabaja,_motivob)
{
    if(_tipo_trabaja.value=="1")
    {
        _motivob.options.length=0;
	    _motivob.options[0] = new Option("SELECCIONE UNA OPCION",1,false,false);
	    _motivob.options[1] = new Option("PARA CAMBIARSE DE TRABAJO",2,false,false);
	    _motivob.options[2] = new Option("PARA TENER MAS DE UN EMPLEO",3,false,false);
	 }
	 if(_tipo_trabaja.value=="2")
	 {
	    _motivob.options.length=0;
	    _motivob.options[0] = new Option("SELECCIONE UNA OPCION",1,false,false);
        _motivob.options[1] = new Option("EX?TRABAJADOR DE LyFC",11,false,false);
        _motivob.options[2] = new Option("NUNCA HA TRABAJADO",12,false,false);
        _motivob.options[3] = new Option("CERRO / QUEBRO SU FUENTE DE TRABAJO",13,false,false);
        _motivob.options[4] = new Option("AJUSTE DE PERSONAL",14,false,false);
        _motivob.options[5] = new Option("FUE DESPEDIDO SIN CAUSA",15,false,false);
        _motivob.options[6] = new Option("SE TERMINO SU CONTRATO",16,false,false);
        _motivob.options[7] = new Option("SE RETIRO VOLUNTARIAMENTE",17,false,false);
        _motivob.options[8] = new Option("OTRO",18,false,false);
	 }
}

function calculaedad(fecha) {
	var fecha;
	var hoy=new Date();
	var ano = ""+hoy.getYear()+"";
	var mes = "" + hoy.getMonth() + "";
	var dia=hoy.getDate()

	var longdia = document.solicitante.vfecnac.value.length;
	var buscadiagdia = document.solicitante.vfecnac.value.indexOf("/");
	var logfinaldia = document.solicitante.vfecnac.value.indexOf("/");
	var loginiciodia = 0;
	var dd = 0;
    for (var i=loginiciodia; i<logfinaldia; i++)
    {
	    dd = dd + document.solicitante.vfecnac.value.substring(i, i+1);
	}
	var mescadena = document.solicitante.vfecnac.value.substring(logfinaldia+1,longdia);
	var longmes = longdia;
	var loginiciomes = 0;
	var logfinalmes = mescadena.indexOf("/");
	var mm = 0;
	for (var i=loginiciomes; i<logfinalmes; i++)
	{
	    mm = mm+mescadena.substring(i, i+1);
	}
	var longit = document.solicitante.vfecnac.value.length;
	var logfinal = longit -4;
	var yy = "";
	for (var i=logfinal; i<document.solicitante.vfecnac.value.length; i++)
	{
	    yy = yy + document.solicitante.vfecnac.value.substring(i, i+1);
	}
	if (mm.length == 3)
	{
	    var montharray=new Array("001","002","003","004","005","006","007","008","009","010","011","012")
	}
	else
	{
		var montharray=new Array("01","02","03","04","05","06","07","08","09","10","11","12")
	}
	var fecha = ano -yy
	if (mm == montharray[mes])
	{
		if (dd <= dia)
		{
			document.solicitante.vedad.value = fecha;
		}
		else
			document.solicitante.vedad.value = fecha - 1;
	}
	else if (mm > montharray[mes])
	{
		document.solicitante.vedad.value = fecha - 1;
	}
	else
	{
		document.solicitante.vedad.value = fecha;
	}
}

function validaDate(_fecha) {
  var funcion = false
  var fecha = _fecha.value;
  var err = 0;
  if (fecha.length > 0) {
  	var fstSep = fecha.indexOf('/');
  	var lstSep = fecha.lastIndexOf('/');

  	if(fstSep > 0 &&
  	   ((lstSep+1) != fecha.length)
  	   ){
  		var dia = fecha.substring(0,fstSep);
  		var mes = fecha.substring(fstSep + 1,lstSep);
  		var anio = fecha.substring(lstSep+1,fecha.length);

  		var test = new Date(anio,mes-1,dia);

  		 if (anio == y2k(test.getYear()) && (mes-1 == test.getMonth()) && (dia == test.getDate())) {
  		 	funcion = true
  		 }else{
  		 	err = 2;
                }

  	}else{
  	    err= 1
  	}
  }
  if (!funcion){

  	if(err==1){
  		alert('Formato de fecha no valido');
  	}else if(err==2){
  		alert('Fecha No válida');
  	}
  	_fecha.focus();
  }
  return funcion;
}

function esFechaValida2 (_fecha2, sep) {
  var funcion = false
  var fecha = _fecha2.value;
  var err = 0;

  if (fecha.length > 0) {
  	var fstSep = fecha.indexOf('/');
  	var lstSep = fecha.lastIndexOf('/');

  	if(fstSep > 0 &&
  	   ((lstSep+1) != fecha.length)
  	   ){
  		var dia = fecha.substring(0,fstSep);
  		var mes = fecha.substring(fstSep + 1,lstSep);
  		var anio = fecha.substring(lstSep+1,fecha.length);

  		var test = new Date(anio,mes-1,dia);

  		 if (anio == y2k(test.getYear()) && (mes-1 == test.getMonth()) && (dia == test.getDate())) {
  		 	funcion = true
  		 }else{
  		 	err = 2;
                }

  	}else{
  	    err= 1
  	}
  }
  if (!funcion){

  	if(err==1){
  		alert('Formato incorrecto');
  	}else if(err==2){
  		alert('Fecha No válida');
  	}
  	//_fecha2.focus();
  }
  return funcion;
}

function trim(strText) {

    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);

    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
}


function EsEspacioVacio(strText) {
    var vacio = false;
    var espacio = 0
    if (strText.length > 0 ){
    	    while (strText.substring(0,1) == ' ') {
		strText = strText.substring(1, strText.length);
		espacio ++;
	    }

	    while (strText.substring(strText.length-1,strText.length) == ' '){
		strText = strText.substring(0, strText.length-1);
		espacio ++;

	    }
	if((espacio>0) && strText.length==0){
		vacio = true;
	}

    }
    return vacio;
}


function ValidaEspacioVacio(_valor) {
	if(EsEspacioVacio(_valor.value)){
		alert('El campo no debe contener espacios');
		_valor.focus();
		_valor.value='';
	}
}



function y2k(number) { return (number < 1000) ? number + 1900 : number; }


function calculaedadC(fecha) {
	var fecha;
	var hoy=new Date();
	var ano = ""+hoy.getYear()+"";
	var mes = "" + hoy.getMonth() + "";
	var dia=hoy.getDate()

	var longdia = document.solicitanteC.vfecnac.value.length;
	var buscadiagdia = document.solicitanteC.vfecnac.value.indexOf("/");
	var logfinaldia = document.solicitanteC.vfecnac.value.indexOf("/");
	var loginiciodia = 0;
	var dd = 0;
    for (var i=loginiciodia; i<logfinaldia; i++)
    {
	    dd = dd + document.solicitanteC.vfecnac.value.substring(i, i+1);
	}
	var mescadena = document.solicitanteC.vfecnac.value.substring(logfinaldia+1,longdia);
	var longmes = longdia;
	var loginiciomes = 0;
	var logfinalmes = mescadena.indexOf("/");
	var mm = 0;
	for (var i=loginiciomes; i<logfinalmes; i++)
	{
	    mm = mm+mescadena.substring(i, i+1);
	}
	var longit = document.solicitanteC.vfecnac.value.length;
	var logfinal = longit -4;
	var yy = "";
	for (var i=logfinal; i<document.solicitanteC.vfecnac.value.length; i++)
	{
	    yy = yy + document.solicitanteC.vfecnac.value.substring(i, i+1);
	}
	if (mm.length == 3)
	{
	    var montharray=new Array("001","002","003","004","005","006","007","008","009","010","011","012")
	}
	else
	{
		var montharray=new Array("01","02","03","04","05","06","07","08","09","10","11","12")
	}
	var fecha = ano -yy
	if (mm == montharray[mes])
	{
		if (dd <= dia)
		{
			document.solicitanteC.vedad.value = fecha;
		}
		else
			document.solicitanteC.vedad.value = fecha - 1;
	}
	else if (mm > montharray[mes])
	{
		document.solicitanteC.vedad.value = fecha - 1;
	}
	else
	{
		document.solicitanteC.vedad.value = fecha;
	}
}


function validate(field) {
  var valid = "ABCDEFGHIJKLMN?OPQRSTUVWXYZabcdefghijklmn?opqrstuvwxyz0123456789 "
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    alert("Caracter Invalido!  Solamente letras (A-Z) y numeros (0-9) son aceptados!");
    field.focus();
    field.select();
   }
}


function replaceChars(entry) // reemplazar la letra Ã± por "_"
{
    entry = Trim(entry.toUpperCase());
    out = "Ã‘";
    add = "_";
    temp = "" + entry;
    while (temp.indexOf(out)>-1)
    {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add +
        temp.substring((pos + out.length), temp.length));
    }

    return temp;
}

function replaceArroba(entry) // reemplazar la letra Ã± por "_"
{
    //entry = Trim(entry.toUpperCase());
    out = "@";
    add = "$";
    temp = "" + entry;
    while (temp.indexOf(out)>-1)
    {
        pos= temp.indexOf(out);
        temp = "" + (temp.substring(0, pos) + add +
        temp.substring((pos + out.length), temp.length));
    }

    return temp;
}


function Trim(TRIM_VALUE)
    {
        if(TRIM_VALUE.length < 1)
        {
            return"";
        }

        TRIM_VALUE = RTrim(TRIM_VALUE);
        TRIM_VALUE = LTrim(TRIM_VALUE);
        if(TRIM_VALUE=="")
        {
            return "";
        }
        else
        {
            return TRIM_VALUE;
        }
    }

    function RTrim(VALUE)
    {
        var w_space = String.fromCharCode(32);
        var v_length = VALUE.length;
        var strTemp = "";
        if(v_length < 0)
        {
            return"";
        }
        var iTemp = v_length -1;
        while(iTemp > -1)
        {
            if(VALUE.charAt(iTemp) == w_space)
            {
            }
            else
            {
                strTemp = VALUE.substring(0,iTemp +1);
                break;
            }
            iTemp = iTemp-1;
        }
        return strTemp;
    }

    function LTrim(VALUE)
    {
        var w_space = String.fromCharCode(32);
        if(v_length < 1)
        {
            return"";
        }
        var v_length = VALUE.length;
        var strTemp = "";
        var iTemp = 0;
        while(iTemp < v_length)
        {
            if(VALUE.charAt(iTemp) == w_space)
            {
            }
            else
            {
                strTemp = VALUE.substring(iTemp,v_length);
                break;
            }
            iTemp = iTemp + 1;
        }
        return strTemp;
    }

function validateName(field) {
  var valid = "ABCDEFGHIJKLMNÃ‘OPQRSTUVWXYZabcdefghijklmnÃ±opqrstuvwxyz0123456789 "
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1") ok = "no";
  }
  if (ok == "no") {
    alert("Caracter Invalido!  Solamente letras (A-Z) y numeros (0-9) son aceptados!");
    field.focus();
    field.select();
   }
}
function validateCP(field) {
	if(field.value.length!=5)
	{
		alert("El código postal debe estar formado por 5 números!");
		field.value = "";
		field.focus();
	}
}


function isvalidateAcentos(campo) {
    var RegExPattern = /[áéíóúÁÉÍÓÚ]/;
   
    if ((campo.value.match(RegExPattern)) && (campo.value!='')) {
        return false;
     }

     return true;
}


function validateLogin(field) {
  var valid = "ABCDEFGHIJKLMNÃ‘OPQRSTUVWXYZabcdefghijklmnÃ±opqrstuvwxyz0123456789 "
  var ok = "yes";
  var temp;
  for (var i=0; i<field.value.length; i++) {
    temp = "" + field.value.substring(i, i+1);
    if (valid.indexOf(temp) == "-1"){
        ok = "no";

    }
  }
  if (ok == "no") {
    alert("Caracter Invalido!  Solamente letras (A-Z) y numeros (0-9) son aceptados!");
    field.focus();
    field.select();
    return false;
   }
   return true;
}

