//funciones que estaban en validations.js
function containNumeric(chaine) {
    var i = 0;
    var contain = false;
    var character_NoAuthorized = "0123456789";

    if (chaine.length != 0) {
        while (!contain && (i <= (chaine.length - 1))) {
            if (character_NoAuthorized.indexOf(chaine.charAt(i)) > -1) {
                contain = true;
            }
            i = i + 1;
        }
    }
    else {
        contain = false;
    }

    return contain;
}

function trim(strIn)
{

  blnBeginning = true;
  blnInSpace = false;
  strOut = "";
  strSpace = "";
  
  for(iPos = 0; iPos < strIn.length; iPos++)
  {
    chr = strIn.charAt(iPos);
    
    if(chr == ' ' || chr == '\t' || chr == '\n') {
    	if(!blnBeginning) {
            blnInSpace = true;
    	    strSpace += chr;
    	}
    }
    else {
    	if(blnBeginning) {
    	    blnBeginning = false;
        }
	else if(blnInSpace) {
	    blnInSpace = false;
	    strOut += strSpace;
	    strSpace = "";
	}
	
	strOut += chr;
    }
  }

  return strOut;
}

function checkTextNotEmpty(strIn)
{
  strTrimmed = trim(strIn);

  if(strTrimmed.length == 0) {
    return false;
  }
  else {
    return true;
  }
}
function checkNumber(strIn)
{
	return !(isNaN(strIn));
}

function checkNumberPositive(strIn)
{
	var intValue = parseInt(strIn);
	if (checkNumber(intValue))
	{
		return (intValue >= 0);
	}
	else
	{	return false;
    }
}


function checkNIF(strNIF)
{
	var nif, temp, number, letter, position;
	var character = "TRWAGMYFPDXBNJZSQVHLCKE";

	if(trim(strNIF).length < 4 || trim(strNIF).length > 9)
	{	
		return 	false;
	}
	nif = trim(strNIF).toUpperCase();
	temp = trim(nif).substring(0,1);
	//Se eliminan los ceros de la izda.
	if (temp == "0")
	{
		while (temp == "0")
		{
			nif = trim(nif).substring(1, trim(nif).length);
			temp = trim(nif).substring(0,1);
		}
	}
	if (trim(nif).length < 4 || trim(nif).length > 9)
	{
		return false;
	}
	
	number = trim(nif).substring(0, trim(nif).length - 1);
	if (!checkNumber(number)) 
		return false;
		
	letter = trim(nif).substring(trim(nif).length - 1, trim(nif).length);
	if (!IsAlphaAnd(letter, false, ""))
		return false;

	position = number % 23;
	if (letter != character.substring(position, position + 1))
		return false;
		
	return true;

}

function checkNIE(strNIE)
{
	var firstLetter, nif;

	firstLetter = trim(strNIE).substring(0,1).toUpperCase();
	if (firstLetter != "X")
		return false;
	
	nif = trim(strNIE).substring(1, trim(strNIE).length);
	
	return checkNIF(nif);
}

function checkCIF(strCIF)
{
	var number, firstLetter;
	var character = "ABCDEFGHLPQS";
	
	firstLetter = trim(strCIF).substring(0,1).toUpperCase();
	if (character.indexOf(firstLetter) == -1)
		return false;

	number = trim(strCIF).substring(1).toUpperCase();
	if (trim(number).length <=8 && trim(number).length > 1 && checkNumber(trim(number)))
		return true;
	
	return false;
}

function checkBankCode(strBankCode)
{
	if (checkNumber(trim(strBankCode)) && trim(strBankCode).length == 4)
		return true;
	
	return false;
}

function checkOfficeCode(strOfficeCode)
{
	if (checkNumber(trim(strOfficeCode)) && trim(strOfficeCode).length == 4)
		return true;
	
	return false;
}

function IsAlphaAnd(chaine, numeric, specialChars, blank)
{
	var i = 0;
	var validate = true;
	var character_authorized="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	
	character_authorized += specialChars;

	if (blank) 
		character_authorized += " ";

	if (numeric) 
		character_authorized += "0123456789";
				
	chaine = trim(chaine);
	
	if (chaine.length != 0) 
	{
		while (validate && (i <= (chaine.length - 1)))	
		{					
			if (character_authorized.indexOf(chaine.charAt(i))== -1) 
			{	
				validate = false;
			}
			i = i + 1;
		}
	}
	else
	{	
		validate = false;
	}
		
	return validate;
}
//end funciones de validations.js


/******************************************************/
/* Validación de campos codigo postal segun provincia */
/******************************************************/

//El array "PostalCodeInitInit" contiene los primeros digitos del codigo postal de una provincia
var PostalCodeInit = new Array();
PostalCodeInit[0] = '01'; //Primeros digitos del codigo postal de Álava
PostalCodeInit[1] = '02'; //Primeros digitos del codigo postal de Albacete
PostalCodeInit[2] = '03'; //Primeros digitos del codigo postal de Alicante
PostalCodeInit[3] = '04'; //Primeros digitos del codigo postal de Almería
PostalCodeInit[4] = '33';//Primeros digitos del codigo postal de Asturias
PostalCodeInit[5] = '05'; //Primeros digitos del codigo postal de Ávila
PostalCodeInit[6] = '06'; //Primeros digitos del codigo postal de Badajoz
PostalCodeInit[7] = '08'; //Primeros digitos del codigo postal de Barcelona
PostalCodeInit[8] = '09'; //Primeros digitos del codigo postal de Burgos
PostalCodeInit[9] = '10'; //Primeros digitos del codigo postal de Cáceres
PostalCodeInit[10] = '11'; //Primeros digitos del codigo postal de Cádiz
PostalCodeInit[11] = '39'; //Primeros digitos del codigo postal de Cantabria
PostalCodeInit[12] = '12'; //Primeros digitos del codigo postal de Castellón de la Plana
PostalCodeInit[13] = '51'; //Primeros digitos del codigo postal de Ceuta
PostalCodeInit[14] = '13'; //Primeros digitos del codigo postal de Ciudad Real
PostalCodeInit[15] = '14'; //Primeros digitos del codigo postal de Córdoba
PostalCodeInit[16] = '15'; //Primeros digitos del codigo postal de Coruña, A
PostalCodeInit[17] = '16'; //Primeros digitos del codigo postal de Cuenca
PostalCodeInit[18] = '17'; //Primeros digitos del codigo postal de Girona
PostalCodeInit[19] = '18'; //Primeros digitos del codigo postal de Granada
PostalCodeInit[20] = '19'; //Primeros digitos del codigo postal de Guadalajara
PostalCodeInit[21] = '20'; //Primeros digitos del codigo postal de Guipúzcoa
PostalCodeInit[22] = '21'; //Primeros digitos del codigo postal de Huelva
PostalCodeInit[23] = '22'; //Primeros digitos del codigo postal de Huesca
PostalCodeInit[24] = '07'; //Primeros digitos del codigo postal de Illes Balears
PostalCodeInit[25] = '23'; //Primeros digitos del codigo postal de Jaén
PostalCodeInit[26] = '24'; //Primeros digitos del codigo postal de León
PostalCodeInit[27] = '25'; //Primeros digitos del codigo postal de Lleida
PostalCodeInit[28] = '27'; //Primeros digitos del codigo postal de Lugo
PostalCodeInit[29] = '28'; //Primeros digitos del codigo postal de Madrid
PostalCodeInit[30] = '29'; //Primeros digitos del codigo postal de Málaga
PostalCodeInit[31] = '52'; //Primeros digitos del codigo postal de Melilla
PostalCodeInit[32] = '30'; //Primeros digitos del codigo postal de Murcia
PostalCodeInit[33] = '31'; //Primeros digitos del codigo postal de Navarra
PostalCodeInit[34] = '32'; //Primeros digitos del codigo postal de Ourense
PostalCodeInit[35] = '34'; //Primeros digitos del codigo postal de Palencia
PostalCodeInit[36] = '35'; //Primeros digitos del codigo postal de Palmas, Las
PostalCodeInit[37] = '36'; //Primeros digitos del codigo postal de Pontevedra
PostalCodeInit[38] = '26'; //Primeros digitos del codigo postal de Rioja, La
PostalCodeInit[39] = '37'; //Primeros digitos del codigo postal de Salamanca
PostalCodeInit[40] = '38'; //Primeros digitos del codigo postal de Santa Cruz de Tenerife
PostalCodeInit[41] = '40'; //Primeros digitos del codigo postal de Segovia
PostalCodeInit[42] = '41'; //Primeros digitos del codigo postal de Sevilla
PostalCodeInit[43] = '42'; //Primeros digitos del codigo postal de Soria
PostalCodeInit[44] = '43'; //Primeros digitos del codigo postal de Tarragona
PostalCodeInit[45] = '44'; //Primeros digitos del codigo postal de Teruel
PostalCodeInit[46] = '45'; //Primeros digitos del codigo postal de Toledo
PostalCodeInit[47] = '46'; //Primeros digitos del codigo postal de Valencia
PostalCodeInit[48] = '47'; //Primeros digitos del codigo postal de Valladolid
PostalCodeInit[49] = '48'; //Primeros digitos del codigo postal de Vizcaya
PostalCodeInit[50] = '49'; //Primeros digitos del codigo postal de Zamora
PostalCodeInit[51] = '50'; //Primeros digitos del codigo postal de Zaragoza

function IsPostalCode(YourPostalCode)
{
    if (YourPostalCode.length != 5) return false; 
    
    for (i=0; i<=51; i++)
    {
        if (PostalCodeInit[i] == YourPostalCode.substring(0, 2)) return true;    
    }
    
    return false;
}

function validatecombo(src, arg) {
    var chkControlId = src.id.replace("Validator_", "");
    arg.IsValid = arg.Value != 0;
    if (!arg.IsValid) error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
    if (arg.IsValid) ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
}

function error(eOK, eContenedor, eError, eFocus) {
    document.getElementById(eOK).style.display = 'none';
    document.getElementById(eContenedor).style.background = '#F7E0E0'
    document.getElementById(eError).style.display = '';

    if (!((eFocus != null) && (eFocus == "nofocus"))) {
        var fd = null;

        if (document.getElementById(eFocus) != null)
            fd = document.getElementById(eFocus);
        else
            if (document.getElementById(eContenedor.replace("_cont", "")) != null)
            fd = document.getElementById(eContenedor.replace("_cont", ""));
        else
            fd = document.getElementById(eContenedor);

        if (fd != null)
            if ((fd.style.display != 'none') && (fd.disabled != true))
            if (fd.parentNode != null)
            if ((fd.parentNode.style.display != 'none') && (fd.parentNode.disabled != true))
            fd.focus();
    }
}

function ok(eOK, eContenedor, eError, abrir) {
    document.getElementById(eOK).style.display = '';
    document.getElementById(eContenedor).style.background = '#F7F7F7'
    document.getElementById(eError).style.display = 'none';
}

function Vfecha() {
    var esValidado = true;

    if (document.getElementById('VHExpirationPreviousPolicyDateYear').value != 0 && document.getElementById('VHExpirationPreviousPolicyDateMonth').value != 0 && document.getElementById('VHExpirationPreviousPolicyDateDay').value != 0) {

        if ((document.getElementById('VHExpirationPreviousPolicyDateYear').value % 4 == 0) && ((document.getElementById('VHExpirationPreviousPolicyDateYear').value % 100 != 0) || (document.getElementById('VHExpirationPreviousPolicyDateYear').value % 400 == 0))) {
            if (document.getElementById('VHExpirationPreviousPolicyDateMonth').value == 2 && document.getElementById('VHExpirationPreviousPolicyDateDay').value > 29) {
                esValidado = false;
            } else {
                esValidado = true;
            }
        } else {
            if (document.getElementById('VHExpirationPreviousPolicyDateMonth').value == 2 && document.getElementById('VHExpirationPreviousPolicyDateDay').value > 28) {
                esValidado = false;
            } else {
                esValidado = true;
            }
        }

    } else {
        esValidado = false;
    }

    if (arg == null)
        ValidatorEnable(document.getElementById('Validator_fecha'), esValidado);

    if (esValidado)
        ok('ok_fecha', 'fecha_cont', 'error_fecha');
    else
        error('ok_fecha', 'fecha_cont', 'error_fecha');
}

function validateMesMatriculacion(src, arg) {
    ValMesMatriculacion();
    arg.IsValid = document.getElementById('ok_fechaMatriculacion').style.display == '';
}

function ValMesMatriculacion() {
    if ((document.getElementById('anioMatriculacion').value != 'AAAA') && (document.getElementById('diaMatriculacion').value != 0)) {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();

        if (document.getElementById('diaMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('mesMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.length != 4) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        //El año no puede ser mayor al actual.
        if (document.getElementById('anioMatriculacion').value > ano) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.substring(0, 2) != "19" && document.getElementById('anioMatriculacion').value.substring(0, 2) != "20") {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if ((document.getElementById('anioMatriculacion').value % 4 == 0) && ((document.getElementById('anioMatriculacion').value % 100 != 0) || (document.getElementById('anioMatriculacion').value % 400 == 0))) {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 29) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        } 
        else {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 28) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        }

        ok('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');    
    }        
}

function ValDiaMatriculacion() {
    if ((document.getElementById('anioMatriculacion').value != 'AAAA') && (document.getElementById('mesMatriculacion').value != 0)) {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();

        if (document.getElementById('diaMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('mesMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.length != 4) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        //El año no puede ser mayor al actual.
        if (document.getElementById('anioMatriculacion').value > ano) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.substring(0, 2) != "19" && document.getElementById('anioMatriculacion').value.substring(0, 2) != "20") {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if ((document.getElementById('anioMatriculacion').value % 4 == 0) && ((document.getElementById('anioMatriculacion').value % 100 != 0) || (document.getElementById('anioMatriculacion').value % 400 == 0))) {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 29) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        }
        else {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 28) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        }    

        ok('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
    }
}

function validateDiaMatriculacion(src, arg) {
    ValDiaMatriculacion();
    arg.IsValid = document.getElementById('ok_fechaMatriculacion').style.display == '';
}


function validateMatriculacion(src, arg) {
    Vmatriculacion();
    arg.IsValid = document.getElementById('ok_fechaMatriculacion').style.display == '';
}

function Vmatriculacion() {
    if ((document.getElementById('anioMatriculacion').value != 'AAAA')) {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();

        if (document.getElementById('diaMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('mesMatriculacion').value == 0) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.length != 4) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        //El año no puede ser mayor al actual.
        if (document.getElementById('anioMatriculacion').value > ano) {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if (document.getElementById('anioMatriculacion').value.substring(0, 2) != "19" && document.getElementById('anioMatriculacion').value.substring(0, 2) != "20") {
            error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
            return;
        }

        if ((document.getElementById('anioMatriculacion').value % 4 == 0) && ((document.getElementById('anioMatriculacion').value % 100 != 0) || (document.getElementById('anioMatriculacion').value % 400 == 0))) {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 29) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        }
        else {
            if (document.getElementById('mesMatriculacion').value == 2 && document.getElementById('diaMatriculacion').value > 28) {
                error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
                return;
            }
        }       

        ok('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');

    }
    else {
        error('ok_fechaMatriculacion', 'fechaMatriculacion_cont', 'error_fechaMatriculacion');
        return;
    }
}

function validateFechaCarnetA(src, arg) {
    if (document.getElementById('ok_fechaCarnetB').style.display == '') {
        if ((document.getElementById('anioCarnetA').value == 'AAAA') && (document.getElementById('mesCarnetA').value == 0) && (document.getElementById('diaCarnetA').value == 0)) {
            VCarnet();
            arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
        }
        else arg.IsValid = true;
    }
    else {
        VCarnet();
        arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
    }
}

function validateFechaCarnetB(src, arg) {

    if (document.getElementById('ok_fechaCarnetA').style.display == '') {

        if ((document.getElementById('diacarB').value != 0) && (document.getElementById('mescarB').value != 0) && (document.getElementById('anocarB').value != 'AAAA')) {
            VCarnetB();
            arg.IsValid = document.getElementById('ok_fechaCarnetB').style.display == '';    
        }
        else arg.IsValid = true; 
    }
    else {
        VCarnetB();
        arg.IsValid = document.getElementById('ok_fechaCarnetB').style.display == '';
    }
}

function VCarnet() {

    Validator_fechaCarnetA.innerHTML = '';
    
    if ((document.getElementById('anioCarnetA').value == 'AAAA') && (document.getElementById('mesCarnetA').value == 0) &&
        (document.getElementById('diaCarnetA').value == 0) && (document.getElementById('anocarB').value == 'AAAA') &&
        (document.getElementById('diacarB').value == 0) && (document.getElementById('mescarB').value == 0)) {

        error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
    }
    else {
        if (document.getElementById('anioCarnetA').value != 'AAAA') {
            if (document.getElementById('anonaci').value != 'AAAA' && document.getElementById('mesnac').value != 0 && document.getElementById('dianac').value != 0) {
                var fecha = new Date();
                var diames = fecha.getDate();
                var mes = fecha.getMonth() + 1;
                var ano = fecha.getFullYear();

                if (document.getElementById('diaCarnetA').value == 0) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }

                if (document.getElementById('mesCarnetA').value == 0) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }

                if (document.getElementById('anioCarnetA').value.length != 4) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }

                //El año no puede ser mayor al actual.
                if (document.getElementById('anioCarnetA').value > ano) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }

                if (document.getElementById('anioCarnetA').value.substring(0, 2) != "19" && document.getElementById('anioCarnetA').value.substring(0, 2) != "20") {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }

                //Le sumamos 18 años a la fecha de nacimiento.
                var aux = parseInt(document.getElementById('anonaci').value) + 18;

                if (parseInt(document.getElementById('anioCarnetA').value) < parseInt(aux)) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    Validator_fechaCarnetA.innerHTML = 'el valor introducido debe ser al menos 18 a' + String.fromCharCode(241) + 'os superior al de la fecha de nacimiento';
                    return;
                }

                ok('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            }
            else {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                error('ok_fechan', 'fechan_cont', 'error_fechan');
                Validator_fechaCarnetA.innerHTML = 'debes completar el valor de la fecha de nacimiento';
            }
        }
        else {
            error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            return;
        }
    }       
}

function VCarnetB() {

    anocarB_Validator.innerHTML = '';

    if ((document.getElementById('anioCarnetA').value == 'AAAA') && (document.getElementById('mesCarnetA').value == 0) &&
        (document.getElementById('diaCarnetA').value == 0) && (document.getElementById('anocarB').value == 'AAAA') &&
        (document.getElementById('diacarB').value == 0) && (document.getElementById('mescarB').value == 0)) {

        error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
    }
    else {
        if ((document.getElementById('diacarB').value != 0) && (document.getElementById('mescarB').value != 0) && (document.getElementById('anocarB').value != 'AAAA')) {
            if (document.getElementById('anocarB').value != 'AAAA') {
                if (document.getElementById('anonaci').value != 'AAAA' && document.getElementById('mesnac').value != 0 && document.getElementById('dianac').value != 0) {
                    var fecha = new Date();
                    var diames = fecha.getDate();
                    var mes = fecha.getMonth() + 1;
                    var ano = fecha.getFullYear();

                    if (document.getElementById('diacarB').value == 0) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        return;
                    }

                    if (document.getElementById('mescarB').value == 0) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        return;
                    }

                    if (document.getElementById('anocarB').value.length != 4) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        return;
                    }

                    //El año no puede ser mayor al actual.
                    if (document.getElementById('anocarB').value > ano) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        return;
                    }

                    if (document.getElementById('anocarB').value.substring(0, 2) != "19" && document.getElementById('anocarB').value.substring(0, 2) != "20") {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        return;
                    }

                    //Le sumamos 18 años a la fecha de nacimiento.
                    if (document.getElementById('anonaci').value != 'AAAA') {
                        var aux = parseInt(document.getElementById('anonaci').value) + 18;

                        if (parseInt(document.getElementById('anocarB').value) < parseInt(aux)) {
                            error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                            anocarB_Validator.innerHTML = 'el valor introducido debe ser al menos 18 a' + String.fromCharCode(241) + 'os superior al de la fecha de nacimiento';
                            return;
                        }

                        ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    }
                    else {
                        ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    }
                }
                else {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    error('ok_fechan', 'fechan_cont', 'error_fechan');
                    anocarB_Validator.innerHTML = 'debes completar el valor de la fecha de nacimiento';
                }
            }
            else {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }
        }
    }        
}

function validateMesNaci(src, arg) {
    ValMesNacimiento();
    arg.IsValid = document.getElementById('ok_fechan').style.display == '';
}

function validateDiaNaci(src, arg) {
    ValDiaNacimiento();
    arg.IsValid = document.getElementById('ok_fechan').style.display == '';
}

function validateDiaNaci() {
    if ((document.getElementById('anonaci').value != 'AAAA') && (document.getElementById('mesnac').value != 0)) {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();
        if (document.getElementById('anonaci').value.length == 4) {
            if ((ano - document.getElementById('anonaci').value) > 18 && document.getElementById('anonaci').value != 0) {
                if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                } else {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                }

            } else if ((ano - document.getElementById('anonaci').value) == 18) {
                if (mes > document.getElementById('mesnac').value && document.getElementById('mesnac').value != 0) {

                    if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    } else {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    }

                } else if (mes > document.getElementById('mesnac').value) {
                    if (dia >= document.getElementById('dianac').value && document.getElementById('dianac').value != 0) {

                        if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        } else {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        }


                    } else {

                        error('ok_fechan', 'fechan_cont', 'error_fechan');

                    }
                } else {

                    error('ok_fechan', 'fechan_cont', 'error_fechan');

                }
            } else {
                error('ok_fechan', 'fechan_cont', 'error_fechan');
            }

        }
        else
            error('ok_fechan', 'fechan_cont', 'error_fechan');
    }
}

function ValMesNacimiento() {
    if ((document.getElementById('anonaci').value != 'AAAA') && (document.getElementById('dianac').value != 0)) {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();
        if (document.getElementById('anonaci').value.length == 4) {
            if ((ano - document.getElementById('anonaci').value) > 18 && document.getElementById('anonaci').value != 0) {
                if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                } else {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                }

            } else if ((ano - document.getElementById('anonaci').value) == 18) {
                if (mes > document.getElementById('mesnac').value && document.getElementById('mesnac').value != 0) {

                    if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    } else {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    }

                } else if (mes > document.getElementById('mesnac').value) {
                    if (dia >= document.getElementById('dianac').value && document.getElementById('dianac').value != 0) {

                        if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        } else {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        }


                    } else {

                        error('ok_fechan', 'fechan_cont', 'error_fechan');

                    }
                } else {

                    error('ok_fechan', 'fechan_cont', 'error_fechan');

                }
            } else {
                error('ok_fechan', 'fechan_cont', 'error_fechan');
            }

        }
        else
            error('ok_fechan', 'fechan_cont', 'error_fechan');
    }
}

function validatenaci(src, arg) {
    Vnacimiento();
    arg.IsValid = document.getElementById('ok_fechan').style.display == '';
}

function Vnacimiento() {
    if (document.getElementById('anonaci').value != 'AAAA') {
        var fecha = new Date();
        var diames = fecha.getDate();
        var mes = fecha.getMonth() + 1;
        var ano = fecha.getFullYear();
        if (document.getElementById('anonaci').value.length == 4) {
            if ((ano - document.getElementById('anonaci').value) > 18 && document.getElementById('anonaci').value != 0) {
                if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                } else {
                    if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                        error('ok_fechan', 'fechan_cont', 'error_fechan');
                    } else {
                        ok('ok_fechan', 'fechan_cont', 'error_fechan');
                    }
                }

            } else if ((ano - document.getElementById('anonaci').value) == 18) {
                if (mes > document.getElementById('mesnac').value && document.getElementById('mesnac').value != 0) {

                    if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    } else {
                        if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                            error('ok_fechan', 'fechan_cont', 'error_fechan');
                        } else {
                            ok('ok_fechan', 'fechan_cont', 'error_fechan');
                        }
                    }

                } else if (mes > document.getElementById('mesnac').value) {
                    if (dia >= document.getElementById('dianac').value && document.getElementById('dianac').value != 0) {

                        if ((document.getElementById('anonaci').value % 4 == 0) && ((document.getElementById('anonaci').value % 100 != 0) || (document.getElementById('anonaci').value % 400 == 0))) {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 29) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        } else {
                            if (document.getElementById('mesnac').value == 2 && document.getElementById('dianac').value > 28) {
                                error('ok_fechan', 'fechan_cont', 'error_fechan');
                            } else {
                                ok('ok_fechan', 'fechan_cont', 'error_fechan');
                            }
                        }


                    } else {

                        error('ok_fechan', 'fechan_cont', 'error_fechan');

                    }
                } else {

                    error('ok_fechan', 'fechan_cont', 'error_fechan');

                }
            } else {
                error('ok_fechan', 'fechan_cont', 'error_fechan');
            }

        }
        else
            error('ok_fechan', 'fechan_cont', 'error_fechan');
    }
    else
        error('ok_fechan', 'fechan_cont', 'error_fechan');
}

function validateradio(src, arg) {
    var chkControlId = src.id.replace("Validator_", "");
    if (document.getElementById(chkControlId + '1').checked == false && document.getElementById(chkControlId + '2').checked == false) {
        arg.IsValid = false;
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
    }
    else {
        arg.IsValid = true;
    }
}

function greenRadio(elemento) {
    document.getElementById(elemento).style.display = "";
    ok('ok_' + elemento, elemento + '_cont', 'error_' + elemento);
}





function greenRadio(elementoRaiz,elemento) {
    document.getElementById(elementoRaiz).style.display = "";
    ok('ok_' + elemento, elemento + '_cont', 'error_' + elemento);
}

function validateTextCaracter(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (containNumeric(arg.Value) || (arg.Value == "")) {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true; 
    }
}

function validateTextCaracterNoOblig(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (arg.Value != "") {
        if (containNumeric(arg.Value)) {
            error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
            arg.IsValid = false;
        }
        else {
            ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
            arg.IsValid = true;
        }
    }
}


function validateTextNumericNoOblig(src, arg) {
    var chkControlId = src.id.replace("Validator_", "");

    if (arg.Value != "") {
        if (!(isNaN(arg.Value))) {
            ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
            arg.IsValid = true;
        }
        else {
            error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
            arg.IsValid = false;
        }
    }       
}

function validateTextNumeric(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (arg.Value == "") {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
    else {
        if (!(isNaN(arg.Value))) {
            ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
            arg.IsValid = true;
        }
        else {
            error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
            arg.IsValid = false;
        }
    }      
}

function validateCaracterYNumerosNoOblig(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (arg.Value != "") {
        if (!IsAlphaAnd(arg.Value, true, '', true)) {
            error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
            arg.IsValid = false;
        }
        else {
            ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
            arg.IsValid = true;
        }
    }
}

function validateCaracterYNumeros(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (!IsAlphaAnd(arg.Value, true, '', true) || (arg.Value == "")) {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true; 
    }
}

function validateTextNif(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (checkCIF(arg.Value) || checkNIE(arg.Value) || checkNIF(arg.Value)) {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true; 
    }
    else {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
}

function validateNotEmpty(src, arg) {
    var chkControlId = src.id.replace("Validator_", "");

    if (arg.Value == "") {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true;
    }
}

function validateCaracterSpecial(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (!IsAlphaAnd(arg.Value, true, "_-@.", false) || (arg.Value == "")) {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true;
    }
}

function validateCP(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (!IsPostalCode(arg.Value) || (arg.Value == "")) {
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
        arg.IsValid = false;        
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true;
    }
}

function validateCheckTrue(src, arg) {

    var chkControlId = src.id.replace("Validator_", "");

    if (document.getElementById(chkControlId).checked == false) {
        arg.IsValid = false;
        error('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId);
    }
    else {
        ok('ok_' + chkControlId, chkControlId + '_cont', 'error_' + chkControlId, 1);
        arg.IsValid = true; 
    }
}

function OtraMotoOptions(enable) {

    document.getElementById('otramoto_cont').style.display = '';
    ok('ok_otramoto', 'otramoto_cont', 'error_otramoto');

    if (enable) {
        document.getElementById('datos_anterior').style.display = '';
        
        //Habilitamos la validaciones.
        ValidatorEnable(document.getElementById('Validator_matricula'), true);
        ValidatorEnable(document.getElementById('Validator_idpolant'), true);
        ValidatorEnable(document.getElementById('Validator_ciaant'), true);
        ValidatorEnable(document.getElementById('Validator_aniosCiaAnt'), true);
        ValidatorEnable(document.getElementById('Validator_marca2'), true);
        ValidatorEnable(document.getElementById('Validator_modelo2'), true);
        ValidatorEnable(document.getElementById('Validator_version2'), true);
    }
    else
    {
        document.getElementById('datos_anterior').style.display = 'none';
        
        //Deshabilitamos la validaciones.
        ValidatorEnable(document.getElementById('Validator_matricula'), false);
        ValidatorEnable(document.getElementById('Validator_idpolant'), false);
        ValidatorEnable(document.getElementById('Validator_ciaant'), false);
        ValidatorEnable(document.getElementById('Validator_aniosCiaAnt'), false);
        ValidatorEnable(document.getElementById('Validator_marca2'), false);
        ValidatorEnable(document.getElementById('Validator_modelo2'), false);
        ValidatorEnable(document.getElementById('Validator_version2'), false);
    }
}

function ValidaFechaCarnetB() {

    var valido = true;

    if (document.getElementById('anocarB').value != 'AAAA') {
        
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {
            
            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diacarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }

            if (document.getElementById('mescarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }

            if (document.getElementById('anocarB').value.length != 4) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anocarB').value > ano) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }

            if (document.getElementById('anocarB').value.substring(0, 2) != "19" && document.getElementById('anocarB').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            if (document.getElementById('anonaci').value != 'AAAA') {
                var aux = parseInt(document.getElementById('anonaci').value) + 18;

                if (parseInt(document.getElementById('anocarB').value) < parseInt(aux)) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido = false;
                }
            }

            if ((document.getElementById('anocarB').value % 4 == 0) && ((document.getElementById('anocarB').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 29) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido = false;
                }
            } else {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 28) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido = false;
                }
            }
        }
        else {
            error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            valido = false;
        }
    }
    else {

        if ((document.getElementById('diacarB').value != 0) || (document.getElementById('mescarB').value != 0)) {
            error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
            valido = false;
        }
        else {
            
            if (!document.getElementById('ok_fechaCarnetA').style.display == '') {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                valido = false;
            }
            else {
                document.getElementById('ok_fechaCarnetB').style.display = 'none';
                document.getElementById('fechaCarnetB_cont').style.background = ''
                document.getElementById('error_fechaCarnetB').style.display = 'none';
            }
        }
    }

    if (valido) ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
}

function ValDiaFCarnetA(src, arg) {
    ValidaDiaCarnetA();
    arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
}

function ValMesFCarnetA(src, arg) {
    ValidaMesCarnetA();
    arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
}

function ValidaDiaCarnetA() {
    if ((document.getElementById('anioCarnetA').value != 'AAAA') && (document.getElementById('mesCarnetA').value != 0)) {
        //Si se ha informado la fecha de nacimiento validamos la fecha del carnet A.
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {

            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diaCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('mesCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('anioCarnetA').value.length != 4) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anioCarnetA').value > ano) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('anioCarnetA').value.substring(0, 2) != "19" && document.getElementById('anioCarnetA').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            var aux = parseInt(document.getElementById('anonaci').value) + 18;

            if (parseInt(document.getElementById('anioCarnetA').value) < parseInt(aux)) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if ((document.getElementById('anioCarnetA').value % 4 == 0) && ((document.getElementById('anioCarnetA').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 29) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }
            } else {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 28) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }
            }
        }
        //Si no se ha informado la fecha de nacimiento damos error.
        else {
            error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            return;
        }

        ok('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');  
    }
}

function ValidaMesCarnetA() {

    if ((document.getElementById('anioCarnetA').value != 'AAAA') && (document.getElementById('diaCarnetA').value != 0)) {
        //Si se ha informado la fecha de nacimiento validamos la fecha del carnet A.
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {

            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diaCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('mesCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('anioCarnetA').value.length != 4) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anioCarnetA').value > ano) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if (document.getElementById('anioCarnetA').value.substring(0, 2) != "19" && document.getElementById('anioCarnetA').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            var aux = parseInt(document.getElementById('anonaci').value) + 18;

            if (parseInt(document.getElementById('anioCarnetA').value) < parseInt(aux)) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                return;
            }

            if ((document.getElementById('anioCarnetA').value % 4 == 0) && ((document.getElementById('anioCarnetA').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 29) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                } 
            } else {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 28) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                } 
            }
        }
        //Si no se ha informado la fecha de nacimiento damos error.
        else {
            error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            return;
        }

        ok('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
    }
 }

function ValDiaFCarnetB(src, arg) {
    ValidaDiaCarnetB();
    arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
}

function ValMesFCarnetB(src, arg) {
    ValidaMesCarnetB();
    arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
}

function ValidaDiaCarnetB() {
    if ((document.getElementById('anocarB').value != 'AAAA') && (document.getElementById('mescarB').value != 0)) {
        
        //Si se ha informado la fecha de nacimiento validamos la fecha del carnet A.
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {
        
            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diacarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('mescarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('anocarB').value.length != 4) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anocarB').value > ano) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('anocarB').value.substring(0, 2) != "19" && document.getElementById('anocarB').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            if (document.getElementById('anonaci').value != 'AAAA') {
                var aux = parseInt(document.getElementById('anonaci').value) + 18;

                if (parseInt(document.getElementById('anocarB').value) < parseInt(aux)) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            }

            if ((document.getElementById('anocarB').value % 4 == 0) && ((document.getElementById('anocarB').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 29) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            } else {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 28) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            }

            ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');            
        }
        else {
            error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            return;
        }
    }       
}

function ValidaMesCarnetB() {
    if ((document.getElementById('anocarB').value != 'AAAA') && (document.getElementById('diacarB').value != 0)) {
        
        //Si se ha informado la fecha de nacimiento validamos la fecha del carnet A.
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {
            
            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diacarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('mescarB').value == 0) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('anocarB').value.length != 4) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anocarB').value > ano) {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            if (document.getElementById('anocarB').value.substring(0, 2) != "19" && document.getElementById('anocarB').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                return;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            if (document.getElementById('anonaci').value != 'AAAA') {
                var aux = parseInt(document.getElementById('anonaci').value) + 18;

                if (parseInt(document.getElementById('anocarB').value) < parseInt(aux)) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            }

            if ((document.getElementById('anocarB').value % 4 == 0) && ((document.getElementById('anocarB').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 29) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            } else {
                if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 28) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    return;
                }
            }

            ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
        }
        else {
            error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            return;
        }
    }       
}

function ValFCarnetA(src, arg) {
    ValidaFechaCarnetA();
    arg.IsValid = document.getElementById('ok_fechaCarnetA').style.display == '';
}

function ValFCarnetB(src, arg) {
    ValidaFechaCarnetB();
    arg.IsValid = document.getElementById('ok_fechaCarnetB').style.display == '';
}

function ValidaFechaCarnetA() {
    
    var valido = true;
    
    if (document.getElementById('anioCarnetA').value != 'AAAA') {
        //Si se ha informado la fecha de nacimiento validamos la fecha del carnet A.
        if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {

            var fecha = new Date();
            var diames = fecha.getDate();
            var mes = fecha.getMonth() + 1;
            var ano = fecha.getFullYear();

            if (document.getElementById('diaCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            if (document.getElementById('mesCarnetA').value == 0) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            if (document.getElementById('anioCarnetA').value.length != 4) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            //El año no puede ser mayor al actual.
            if (document.getElementById('anioCarnetA').value > ano) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            if (document.getElementById('anioCarnetA').value.substring(0, 2) != "19" && document.getElementById('anioCarnetA').value.substring(0, 2) != "20") {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            //Le sumamos 18 años a la fecha de nacimiento.
            var aux = parseInt(document.getElementById('anonaci').value) + 18;

            if (parseInt(document.getElementById('anioCarnetA').value) < parseInt(aux)) {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }

            if ((document.getElementById('anioCarnetA').value % 4 == 0) && ((document.getElementById('anioCarnetA').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 29) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }
            } else {
                if (document.getElementById('mesCarnetA').value == 2 && document.getElementById('diaCarnetA').value > 28) {
                    error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                    return;
                }
            }
        }
        //Si no se ha informado la fecha de nacimiento damos error.
        else {
            error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            error('ok_fechan', 'fechan_cont', 'error_fechan');
            valido = false;
        }
    }
    else {

        //*********************************** Validacion fecha B ********************************************//

        if ((document.getElementById('diacarB').value != 0) &&
            (document.getElementById('mescarB').value != 0) &&
            (document.getElementById('anocarB').value != 'AAAA')) {

            if (document.getElementById('anonaci').value != 'AAAA' &&
            document.getElementById('mesnac').value != 0 &&
            document.getElementById('dianac').value != 0) {

                var fecha = new Date();
                var diames = fecha.getDate();
                var mes = fecha.getMonth() + 1;
                var ano = fecha.getFullYear();
                var valido1 = true;

                if (document.getElementById('diacarB').value == 0) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido1 = false;
                }

                if (document.getElementById('mescarB').value == 0) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido1 = false;
                }

                if (document.getElementById('anocarB').value.length != 4) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido1 = false;
                }

                //El año no puede ser mayor al actual.
                if (document.getElementById('anocarB').value > ano) {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido1 = false;
                }

                if (document.getElementById('anocarB').value.substring(0, 2) != "19" && document.getElementById('anocarB').value.substring(0, 2) != "20") {
                    error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                    valido1 = false;
                }

                //Le sumamos 18 años a la fecha de nacimiento.
                if (document.getElementById('anonaci').value != 'AAAA') {
                    var aux = parseInt(document.getElementById('anonaci').value) + 18;

                    if (parseInt(document.getElementById('anocarB').value) < parseInt(aux)) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        valido1 = false;
                    }
                }

                if ((document.getElementById('anocarB').value % 4 == 0) && ((document.getElementById('anocarB').value % 100 != 0) || (document.getElementById('anioCarnetA').value % 400 == 0))) {
                    if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 29) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        valido1 = false;
                    }
                } else {
                    if (document.getElementById('mescarB').value == 2 && document.getElementById('diacarB').value > 28) {
                        error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                        valido1 = false;
                    }
                }
            }
            else {
                error('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
                error('ok_fechan', 'fechan_cont', 'error_fechan');
                valido1 = false;
            }

            if (valido1) ok('ok_fechaCarnetB', 'fechaCarnetB_cont', 'error_fechaCarnetB');
        }
        
        //**************************** Fin Validacion fecha B ********************************************//
        
        if ((document.getElementById('diaCarnetA').value != 0) || (document.getElementById('mesCarnetA').value != 0)) {
            error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
            valido = false;
        }
        else {
            if (!document.getElementById('ok_fechaCarnetB').style.display == '') {
                error('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
                valido = false;
            }
            else {
                document.getElementById('ok_fechaCarnetA').style.display = 'none';
                document.getElementById('fechaCarnetA_cont').style.background = ''
                document.getElementById('error_fechaCarnetA').style.display = 'none';
            }
        }
    }

    if (valido) ok('ok_fechaCarnetA', 'fechaCarnetA_cont', 'error_fechaCarnetA');
}


