// Funcion que quita los caracteres en blanco de un campo
function quitaBlancos(campo) {
   if(campo.value)
	{
		var contenido = campo.value;
		campo.value = (contenido.replace(/^\s+/,'')).replace(/\s+$/,'');
		return(campo)
	}
	return(campo)
}
// Fin de Funcion que quita los caracteres en blanco de un campo


// Funcion que comprueba el numero de tarjeta de credito en funcion de la tarjeta seleccionada
function checkCardNumWithMod10(cardNum) { 
        var i; 
        var cc = new Array(16); 
        var checksum = 0; 
        var validcc; 

        // assign each digit of the card number to a space in the array         
        for (i = 0; i < cardNum.length; i++) { 
                cc[i] = Math.floor(cardNum.substring(i, i+1)); 
        } 

        // walk through every other digit doing our magic 
        // if the card number is sixteen digits then start at the 
        // first digit (position 0), otherwise start from the 
        // second (position 1) 
        for (i = (cardNum.length % 2); i < cardNum.length; i+=2) { 
                var a = cc[i] * 2; 
                if (a >= 10) { 
                        var aStr = a.toString(); 
                        var b = aStr.substring(0,1); 
                        var c = aStr.substring(1,2); 
                        cc[i] = Math.floor(b) + Math.floor(c); 
                } else { 
                        cc[i] = a; 
                } 
        } 

        // add up all of the digits in the array 
        for (i = 0; i < cardNum.length; i++) { 
                checksum += Math.floor(cc[i]); 
        } 

        // if the checksum is evenly divisble by 10 
        // then this is a valid card number 
        validcc = ((checksum % 10) == 0); 

        return validcc; 
} 

function cleanCardNum(cardNum) { 
        var i; 
        var ch; 
        var newCard = ""; 

        // walk through the string character by character to build 
        // a new string with numbers only 
        i = 0; 
        while (i < cardNum.length) { 
                // get the current character 
                ch = cardNum.substring(i, i+1); 
                if ((ch >= "0") && (ch <= "9")) { 
                        // if the current character is a digit then add it 
                        // to the numbers-only string we're building 
                        newCard += ch; 
                } else { 
                        // not a digit, so check if its a dash or a space 
                        if ((ch != " ") && (ch != "-")) { 
                                // not a dash or a space so fail 
                                return ""; 
                        } 
                } 
                i++; 
        } 

        // we got here if we didn't fail, so return what we built 
        return newCard; 
} 

function checkCard(cardType, cardNum) { 
        var validCard; 
        var cardLength; 
        var cardLengthOK; 
        var cardStart; 
        var cardStartOK; 
        
        // check if the card type is valid 
        if ((cardType != "V") && (cardType != "M") && (cardType != "A") && (cardType != "D")) { 
                return false; 
        } 

        // clean up any spaces or dashes in the card number 
        validCard = cleanCardNum(cardNum); 
        if (validCard != "") { 
                // check the first digit to see if it matches the card type 
                cardStart = validCard.substring(0,1); 
                cardStartOK = ( ((cardType == "V") && (cardStart == "4")) || 
                                ((cardType == "M") && (cardStart == "5")) || 
                                ((cardType == "A") && (cardStart == "3")) || 
                                ((cardType == "D") && (cardStart == "6")) ); 
                if (!(cardStartOK)) { 
                        // card number's first digit doesn't match card type 
                        return false; 
                } 

                // the card number is good now, so check to make sure 
                // it's a the right length 
                cardLength = validCard.length;                 
                cardLengthOK = ( ((cardType == "V") && ((cardLength == 13) || (cardLength == 16))) || 
                                 ((cardType == "M") && (cardLength == 16)) || 
                                 ((cardType == "A") && (cardLength == 15)) || 
                                 ((cardType == "D") && (cardLength == 16)) ); 
                if (!(cardLengthOK)) { 
                        // not the right length 
                        return false; 
                } 

                // card number seems OK so do the Mod10 
                if (checkCardNumWithMod10(validCard)) { 
                        return true; 
                } else { 
                        return false; 
                } 
        } else { 
                return false; 
        } 
}
// Fin de Funcion que comprueba el numero de tarjeta de credito en funcion de la tarjeta seleccionada


// Funcion que fija la atencion en un campo dado
function fijarAtencion(campo){
	campo.focus();
	campo.style.backgroundColor = 'lightsteelblue';
	                        
}
// Fin de Funcion que fija la atencion en un campo dado


// Funcion que retira la atencion de un campo dado
function ponBlanco(campo){
	campo.style.backgroundColor = '';
}
// Fin de Funcion que retira la atencion de un campo dado


// Funcion que comprueba que un campo no es nulo o vacio
function validaNoNulo(theFormtxtNombre){
		if (theFormtxtNombre.value == "") {
			return (false);
		}//fin del if
	 	else{
			return(true);
		}
}//fin del validaNoNulo
// Fin de Funcion que comprueba que un campo no es nulo o vacio


// Funcion que comprueba que un valor dado es numerico positivo
function validaNumeroValor(valor)
{
  var todoBien;
  
  todoBien = !isNaN(valor) && (valor >= 0);

  return (todoBien);
}
// Fin de Funcion que comprueba que un valor dado es numerico y positivo


// Funcion que comprueba el digito de control en un numero de cuenta
function validaDG(entidad,sucursal,DG,cuenta)
{
	banco=entidad+sucursal;

 	pesos1= new Object(8);
 	pesos1[0]='6';
 	pesos1[1]='3';
 	pesos1[2]='7';
 	pesos1[3]='9';
 	pesos1[4]='10';
 	pesos1[5]='5';
 	pesos1[6]='8';
 	pesos1[7]='4';

 	pesos2= new Object(10);  
 	pesos2[0]='6';
 	pesos2[1]='3';
 	pesos2[2]='7';
 	pesos2[3]='9';
 	pesos2[4]='10';
 	pesos2[5]='5';
 	pesos2[6]='8';
 	pesos2[7]='4';
 	pesos2[8]='2';
 	pesos2[9]='1';

 	result=0;
 	cont=0;
 
 	for (i=7;i>=0;i--)  
  	{
   		result=result+banco.charAt(i)*pesos1[cont];
   		cont++;
  	}             

 	resta=11-(result%11);
 	digito='';
	if (resta==11)
     		digito=digito+0;
	else if (resta==10)
        	digito=digito+1;
    	else 
          	digito=digito+resta;

 	corriente=cuenta;
 	cont2=0;
 	result2=0;

 	for (j=9;j>=0;j--)
  	{
   		result2=result2+corriente.charAt(j)*pesos2[cont2];
   		cont2++;
  	}

 	resta2=11-(result2%11);

	if (resta2==11)
     		digito=digito+0;

	else if (resta2==10)
        	digito=digito+1;
     	else 
          	digito=digito+resta2;

	if (digito==DG)
    		return(true);
	else
    		return(false);
}
// Fin de Funcion que comprueba el digito de control en un numero de cuenta


// Funcion que comprueba que un campo no contiene numeros, aunque puede contener otros caracteres especiales
function validaAlfanumerico2(theFormtxtNombre)
{
  var checkOK = "ABCDEFGHIJKLMN\xd1OPQRSTUVWXYZ\xc1\xc9\xcd\xd3\xdaabcdefghijklmn\xf1opqrstuvwxyz\xe1\xe9\xed\xf3\xfa\xfc\xdc\xba\xaa-. \t\r\n\f";
  var checkStr = theFormtxtNombre.value;
  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++) if (ch == checkOK.charAt(j)) break;
    if (j == checkOK.length)
    {
      allValid = false;

      break;
    }
  }
  if (!allValid)
  {
    theFormtxtNombre.focus();
    return (false);
  }
  return (true);
}
// Fin de Funcion que comprueba que un campo no contiene numeros, aunque puede contener otros caracteres especiales


// Obtener el valor de un input select
function GetSelectValue(selectObject) {
	// Validate parameter value
	if (selectObject == null)
		return null;
	
	if (selectObject.selectedIndex+"" == "undefined" || 
				selectObject.selectedIndex == null ||
				selectObject.selectedIndex < 0)
		return null;

	return selectObject.options[selectObject.selectedIndex].value;
}
// Fin de Obtener el valor de un input select


// Obtener el valor de un input radio
function GetRadioValue(radioObject) { 
	var value = null;

	// Validate parameter value
	if (radioObject+"" == "undefined" || radioObject == null)
		return null;

	for (var i=0; i < radioObject.length; i++) { 
		if (radioObject[i].checked) { 
			value = radioObject[i].value;
			break;
		} 
	} // end for loop 
	
	return value;
}
// Fin de Obtener el valor de un input radio

// Comprobar fechas
function check_date(dia, mes, anio){
var checkstr = "0123456789";
var Datevalue = "";
var DateTemp = "";
var seperator = ".";
var day;
var month;
var year;
var leap = 0;
var err = 0;
var i;
   err = 0;
   DateValue = dia.value + "/" + mes.value + "/" + anio.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   DateValue = DateTemp;
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(2,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(0,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      return(true)
   }
   /* Error-message if err != 0 */
   else {
     return(false)
   }
}
// Fin de Comprobar fechas


// Calcula la edad
function getAge(dateString,dateType) {
 /*
    function getAge
    parameters: dateString dateType
    returns: boolean

    dateString is a date passed as a string in the following
    formats:

    type 1 : 19970529
    type 2 : 970529
    type 3 : 29/05/1997
    type 4 : 29/05/97

    dateType is a numeric integer from 1 to 4, representing
    the type of dateString passed, as defined above.

    Returns string containing the age in years, months and days
    in the format yyy years mm months dd days.
    Returns empty string if dateType is not one of the expected
    values.
 */

     var now = new Date();
     var today = new Date(now.getYear(),now.getMonth(),now.getDate());

     var yearNow = now.getYear();

     if (yearNow.toString().length==4){
	yearNow=yearNow-1900;
     }

     var monthNow = now.getMonth();

     var dateNow = now.getDate();


     if (dateType == 1)
         var dob = new Date(dateString.substring(0,4),
                             dateString.substring(4,6)-1,
                             dateString.substring(6,8));
     else if (dateType == 2)
         var dob = new Date(dateString.substring(0,2),
                             dateString.substring(2,4)-1,
                             dateString.substring(4,6));
     else if (dateType == 3)
         var dob = new Date(dateString.substring(6,10),
                             dateString.substring(3,5)-1,
                             dateString.substring(0,2));
     else if (dateType == 4)
         var dob = new Date(dateString.substring(6,8),
                             dateString.substring(3,5)-1,
                             dateString.substring(0,2));
     else
         return '';

     var yearDob = dob.getYear();

     var monthDob = dob.getMonth();

     var dateDob = dob.getDate();


     yearAge = yearNow - yearDob;

     if (monthNow >= monthDob)
         var monthAge = monthNow - monthDob;
     else {
         yearAge--;
         var monthAge = 12 + monthNow -monthDob;
     }

     if (dateNow >= dateDob)
         var dateAge = dateNow - dateDob;
     else {
         monthAge--;
         var dateAge = 31 + dateNow - dateDob;

         if (monthAge < 0) {
             monthAge = 11;

             yearAge--; 
         }
     }
        return yearAge;
}

// Función que  valida si el e-mail es correcto 
function checkEmail(checkString1){
	var newstr = "";
	var at = false;
	var dot = false;
	checkString = checkString1.value;
    // Vemos si tiene '@'
    if (checkString.indexOf("@") != -1) {
		at = true;
    // Vemos si tiene '.'
	}
    else if (checkString.indexOf(".") != -1) {
		dot = true;
	}
    //
    for (var i = 0; i < checkString.length; i++) {
		ch = checkString.substring(i, i + 1)
		if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
			|| (ch == "@") || (ch == ".") || (ch == "_")
            || (ch == "-") || (ch >= "0" && ch <= "9")) {
            newstr += ch;
            if (ch == "@") {
				at=true;
			}
			if (ch == ".") {
                dot=true;
			}
		}
	}
	if ((at == true) && (dot == true)) {
        return true;
    }
    else {
       // Error
       alert ("La direcci\xf3n de correo no tiene el formato adecuado");
       //checkString1.focus();
       //return checkString;
       return false;
    }
}
// Fin de validar email
/***********************************************************************************/
/******************             Función que me valida si la/s  letra/s             ********************/
/******************      del principio una matricula nueva es correcta        ********************/
/***********************************************************************************/

function validaLetrasIniMat(letras)
{
  var inicialProv = new Array("A","AB","AL","AV","B","BA","BI","BU","C","CA","CC","CE","CO","CR","CS","CU","GC","GI","GE","GR","GU","H","HU","J","L","LE","LO","LU","M","MA","ML","MU","NA","O","OU","OR","P","IB","PM","PO","S","SA","SE","SG","SO","SS","T","TE","TF","TO","V","VA","VI","Z","ZA");
  var checkStr = letras;
  var allValid = true;
  for (y = 0;  y < inicialProv.length;  y++){
  	if (checkStr == inicialProv[y]) break;
  }
  if (y == inicialProv.length){
      allValid = false;
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/********************      es un vehículo especial tipo E o R  o TE      ***********************/
/***********************************************************************************/

function vehiculoEspecial(matr)
{
	if (matr.length==4){
		// vehiculos del tipo E
 		if (validaNumero2(matr.substring(0,2))){
			if(matr.substring(2)=="VE"){
				return(true);
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}else{
		if (matr.length==3){
			// vehiculos del tipo R
 			if (validaNumero2(matr.substring(0,2))){
				if(matr.substring(2)=="R"){
					return(true);
				}else{
					return(false);
				}
			}else{
				if ( ( matr.substring(0,1) == "T" ) || ( matr.substring(0,1) == "R" ) ){
					if ( validaNumero2(matr.substring(1,3)) ){
						return(true);
					}else{
						return(false);
					}
				}else{
					return(false);
				}
			}
		}else{
			return(false);
		}
	}
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/******************      es un vehículo especial tipo E1 o R1 o C o T1          ******************/
/***********************************************************************************/

function vehiculoEspecial2(matr)
{
	if (matr.length==8){
		if ( (matr.substring(0,1)=="E") ||  (matr.substring(0,1)=="R")  ||  (matr.substring(0,1)=="C")  ||  (matr.substring(0,1)=="T")  ||  (matr.substring(0,1)=="H")  ||  (matr.substring(0,1)=="P") ||  (matr.substring(0,1)=="V") ||  (matr.substring(0,1)=="S") ) {
			if (validaNumero2(matr.substring(1,5))){
				if ( validaLetraNueva(matr.substring(5)) ){			
					return(true);
				}else{
					return(false);
				}
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}else{
		return(false);
	}
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/******************      es un vehículo del estado (tipo M o M1)         ******************/
/***********************************************************************************/

function vehiculoEstado(matr)
{
	var matEstado = new Array("A","DGP","EA","ET","FN","MF","MMA","MOP","PGC","PME","PMM");	
	var mat1 = matr.substring(0,1);
	var mat2 = matr.substring(0,2);
	var mat3 = matr.substring(0,3);
	var rest = "";
	for (var q = 0;  q <matEstado.length;  q++){
		if (mat1 == matEstado[q]) break;
	}
	for (var y = 0;  y <matEstado.length;  y++){
		if (mat2 == matEstado[y]) break;
	}
	for (var t = 0;  t <matEstado.length;  t++){
		if (mat3 == matEstado[t]) break;
	}
	if (q != matEstado.length){
		rest = matr.substring(1);
	}else{
		if (y != matEstado.length){
			rest = matr.substring(2);
		}else{
			if (t != matEstado.length){
				rest = matr.substring(3);
			}else{
				return(false);
			}
		}
	}
	if (validaNumero2(rest.substring(0,4))){
		if (rest.substring(4).length==2){
			if (validaNumero2(rest.substring(4,6))){
				return(true);
			}
			if (validaLetras(rest.substring(4,6))){
				return(true);
			}
			return(false);
		}else{
			return(false);
		}
	}else{
		if (rest.substring(0,2) == "VE"){
			if (rest.substring(2).length==6){	
				if (validaNumero2(rest.substring(2,8))){
					return(true);
				}else{
					return(false);
				}
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/**************      es un vehículo de pruebas (tipo P) o de la ITV (tipo I)          ***************/
/***********************************************************************************/

function vehiculoPruebasITV(matr)
{
	if ( validaNumero2(matr.substring(0,2))){
		if ( (matr.substring(2,3) == "P") || (matr.substring(2,3) == "T")){
			if ( validaNumero2(matr.substring(3,7)) ){
				if ( (matr.substring(7,8) =="1") || (matr.substring(7,8) =="2") ){
					if ( (matr.substring(8).length == "0") || (matr.substring(8).length == "2") ){
						if (matr.substring(8).length =="2") {
							if ( validaNumero2(matr.substring(8,10)) ){
								return(true);
							}else{
								return(false);
							}
						}else{
							return(true);
						}
					}else{
						return(false);
					}
				}else{
					return(false);
				}
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}else{
		if (matr.substring(0,3) == "ITV"){
			if (matr.substring(3).length == 4){
				if ( validaNumero2(matr.substring(3,7)) ){
					return(true);
				}else{
					return(false);
				}
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/***********************      es una matrícula de tipo turística T         ***********************/
/***********************************************************************************/

function vehiculoTuristico(matr)
{
  var mesRomano= new Array("I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII");
	if (matr.length>=7){
		if ( validaNumero2(matr.substring(0,2)) ){
			if ( validaLetras(matr.substring(2,3)) ){
				if ( validaLetras(matr.substring(3,4)) ){
					//es una posible provincia de 2 letras
					if (validaLetrasIniMat(matr.substring(2,4))){
						if (validaNumero2(matr.substring(4,8))){
							if ( (matr.substring(8).length == 4) || (matr.substring(8).length==0) ){
								if ( matr.substring(8).length==4){
									for (var y = 0;  y <mesRomano.length;  y++){
  										if (matr.substring(8,10) == mesRomano[y]) break;
									}
									if (y == mesRomano.length){
										return(false);
									}
									if (validaNumero2(matr.substring(10,12))){
										return(true);
									}else{
										return(false);
									}
								}
							}
						}
					}else{
						return(false);
					}
				}else{
					//es una posible provincia de 1 letra
					if (validaLetrasIniMat(matr.substring(2,3))){
						if (validaNumero2(matr.substring(3,7))){
							if ( (matr.substring(7).length==4) || (matr.substring(7).length==0) ){
								if ( matr.substring(7).length==4){
									for (y = 0;  y <mesRomano.length;  y++){
  										if (matr.substring(7,9) == mesRomano[y]) break;
									}
									if (y == mesRomano.length){
										return(false);
									}
									if (validaNumero2(matr.substring(9,11))){
										return(true);
									}else{
										return(false);
									}
								}							
							}
						}						
					}else{
						return(false);
					}
				}
			}else{
				return(false);
			}
		}else{
			return(false);
		}
	}else{
		return(false);
	}
}
/************************************************************************************/
/******************             Función que me valida si la matrícula             ********************/
/************************      es un vehículo de regimen diplomático           ************************/
/***********************************************************************************/

function regimenDiplomatico(matr)
{
	if ( (matr.substring(0,2)=="CD") ||  (matr.substring(0,2)=="OI")  ||  (matr.substring(0,2)=="TA") ||  (matr.substring(0,2)=="CC") ) {
		if (matr.length==8){
			if (validaNumero2(matr.substring(2,8))){
				return(1);
			}else{
				return(0);
			}
		}else{
			return(0);
		}
	}else{
		return(2);
	}
}
/*******************************************************************************/
/**********************        Función que me valida si la          ************************/
/**********************  	  matrícula es correcta                ************************/
/*******************************************************************************/
function validaMatricula(txtMatricula){
 	txtMatricula.value = txtMatricula.value.toUpperCase();
	trim(txtMatricula);
	var valor = txtMatricula.value;
	var auxMat = "";
	
	//No se debe introducir una E al principio. DMFVIRE 24/08/2004.
	if (valor.substring(0, 1) =="E"){
		alert("La matr\xedcula introducida no es correcta");
		return(false);
	}
	
	
	axMod = valor.split("-");
	if (axMod.length > 1){
		alert("La matr\xedcula debe ser introducida sin guiones.");
		return(false);
//		valor="";
//		for (var x=0; x < axMod.length;x++) {
//			auxMat = axMod[x];
//			axMod[x] = (auxMat.replace(/^\s+/,'')).replace(/\s+$/,'');
//			valor = valor + axMod[x];
//		}//end del for
	}
	auxMat = "";
	for (x=0; x< valor.length;x++){
		if (valor.charAt(x) != " ") auxMat += valor.charAt(x);
	}
	valor = auxMat;
	txtMatricula.value = valor;
	if ( validaNumero2(valor.substring(0,4)) ){
		if (valor.substring(4).length ==3){
			if ( !validaLetraNueva(valor.substring(4)) ){
				alert("La matr\xedcula introducida no es correcta.");
				return(false);
			}
		}else{
			alert("La matr\xedcula introducida no es correcta.");
			return(false);
		}
	}else{
		if ( vehiculoTuristico(valor)){
			return(true);
		}
		if ( validaLetras(valor.substring(0,1)) ){
			if ( validaLetras(valor.substring(1,2)) ){
				if (vehiculoEstado(valor)) {
					return(true);
				}
				var auxRD="";
				auxRD = auxRD+regimenDiplomatico(valor);
				//se valida que la matricula sea del tipo D (regimen diplomático)
				if (auxRD == 1){
					return(true);
				}else{
					if(auxRD == 0){
						if (valor.substring(0,2)!= "CC"){
							alert("El formato de una matr\xedcula en R\xe9gimen Diplom\xe1tico debe tener el formato: "+valor.substring(0,2)+"-000000. Completando con ceros cada bloque de tres cifras.");	
							return(false);
						}
					}
				}	
				//las dos primeras posiciones son letras	
				if (!validaLetrasIniMat(valor.substring(0,2))){
					//Se comprueba si seguido de la 1ª letra esta el literal ITV
					if (valor.substring(1,4) == "ITV"){
						if (vehiculoPruebasITV(valor.substring(1))){
							return(true);
						}
					}
					alert("La matr\xedcula introducida no es correcta, la provincia no es correcta.");
					return(false);
				}else{
					if (valor.substring(2,5) == "ITV"){
						if (vehiculoPruebasITV(valor.substring(2))){
							return(true);
						}
					}
					if (validaLetrasIniMat(valor.substring(0,1))){
						if (vehiculoPruebasITV(valor.substring(1))){
							return(true);
						}
					}
				}	
				if ( validaNumero2(valor.substring(2,6))){
					if (valor.substring(6).length > 2){
						// a las 2 primeras posiciones, que son letras, les siguen 4 números, 
						//pero hay más de 2 posiciones despues, es decir, ni tiene 6 números
						//despues de las 2 letras, ni tiene 4 numeros y como máximo 2 letras.
						if (vehiculoEspecial(valor.substring(6))){
							return(true);
						}
						alert("La matr\xedcula introducida no es correcta.");
						return(false);
					}else{
						//se compruba el valor de las 2 últimas posiciones
						if (!validaNumero2(valor.substring(6)) ){
							//si estas 2 ultimas no son números.
							if (!validaLetras(valor.substring(6))){
								alert("La matr\xedcula introducida no es correcta.");
								return(false);							
							}
						}else{
							//si estas 2 ultimas son números.
							if (valor.substring(6).length != 2){
								alert("La matr\xedcula introducida no es correcta.");
								return(false);
							}
						}
					}
				}else{
					// a las 2 primeras posiciones, que son letras, no les siguen 4 números.
					alert("La matr\xedcula introducida no es correcta.");
					return(false);
				}
			}else{
				//la primera posicion es una letra
				if (!validaLetrasIniMat(valor.substring(0,1))){
					if (vehiculoEspecial2(valor)){
						return(true);
					}
					alert("La matr\xedcula introducida no es correcta, la provincia no es correcta.");
					return(false);
				}	
				if ( validaNumero2(valor.substring(1,5))){
					if (valor.substring(5).length > 2){
						// a la primera posicion, que es una letra, le sigue 4 números, 
						//pero hay más de 2 posiciones despues, es decir, ni tiene 6 números
						//despues de la letra, ni tiene 4 numeros y como máximo 2 letras.
						if (vehiculoEspecial(valor.substring(5))){
							return(true);
						}
						if (vehiculoEspecial2(valor)){
							//se valida que la matricula sea del tipo E1 ó R1 ó C (ciclomotores) ó T1 (turística) ó TT .
							return(true);
						}
						alert("La matr\xedcula introducida no es correcta.");
						return(false);
					}else{
						//se comprueba el valor de las 2 últimas posiciones
						if (!validaNumero2(valor.substring(5)) ){
							//si estas 2 ultimas no son números.
							if (!validaLetras(valor.substring(5))){
								alert("La matr\xedcula introducida no es correcta.");
								return(false);							
							}
						}else{
							if (valor.substring(5).length != 2){
								alert("La matr\xedcula introducida no es correcta.");
								return(false);
							}
						}
					}
				}else{
					// a la primera posicion, que es una letra, no le sigue 4 números.
					alert("La matrí\xedcula introducida no es correcta.");
					return(false);
				}
			}		
		}else{
			alert("La matr\xedcula introducida no es correcta.");
			return(false);
		}
	}
	return(true);
}
//fin del validaMatricula

/**********************************************************************************/
/******************  Función que me limpia los espacios          ******************/
/******************  en blanco del comienzo y fin de la cadena.	 ******************/
/**********************************************************************************/
function trim(theFormtxtDsNombre) {
    if(theFormtxtDsNombre.value)
	{
		var x = theFormtxtDsNombre.value;
		theFormtxtDsNombre.value = (x.replace(/^\s+/,'')).replace(/\s+$/,'');
	}
}


/**********************************************************************************/
/******************                      Función que me valida si un              ********************/
/******************                           valor es numerico                        ********************/
/**********************************************************************************/

function validaNumero2(theFormtxtNombre)
{
  var checkOK = "0123456789 \t\r\n\f";
  var checkStr = theFormtxtNombre;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

/*********************************************************************************/
/******************                Función que me valida que el                 ********************/
/******************                      dato sea sólo letras                          ********************/
/*********************************************************************************/
function validaLetras(theFormtxtNombre)
{
  var checkOK = "ABCDEFGHIJKLMN\xd1OPQRSTUVWXYZabcdefghijklmn\xf1opqrstuvwxyz";
  var checkStr = theFormtxtNombre;

  var allValid = true;

  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);

    for (j = 0;  j < checkOK.length;  j++) if (ch == checkOK.charAt(j)) break;
    if (j == checkOK.length)
    {
      allValid = false;

      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}
/*********************************************************************************/
/******************             Función que me valida si la  letra              ********************/
/******************           de una matricula nueva es correcta             ********************/
/*********************************************************************************/

function validaLetraNueva(letras)
{
  var checkOK = "BCDFGHJKLMNPRSTVWXYZbcdfghjklmnprstvwxyz";
  var checkStr = letras;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    return (false);
  }
  return (true);
}

/*********************************************************************************/
/******************             Función que introduce un cero      ********************/
/******************                al principio del NIF            ********************/
/*********************************************************************************/

function rellenaCeros (numeroDoc){
	if((numeroDoc.value.length < 10) ){
		var re = "";
		for(i=0;i<10-numeroDoc.value.length;i++){
			re="0"+re;
		}
		numeroDoc.value=re+numeroDoc.value.toUpperCase(); 
		 		
	}
	return (numeroDoc);
}


function rellenaCeros2 (numeroDoc, numeroBien){
	if((numeroDoc.value.length < 10)){
		if (parseInt(numeroBien)==1){
			numeroDoc.value = " "+numeroDoc.value.toUpperCase();
		} 
		else if (parseInt(numeroBien)==3) {
			var primerCaracter = numeroDoc.value.substring (0,1);
			numeroDoc.value = primerCaracter+"0"+numeroDoc.value.substring(1,numeroDoc.value.length).toUpperCase();
		}	
		 		
	}
	else {
		if (parseInt(numeroBien)==1){
			var primerCaracter = numeroDoc.value.substring (0,1);
			if (primerCaracter == "0"){
				numeroDoc = numeroDoc.value.substring(1,numeroDoc.value.length); 
				numeroDoc.value = " "+numeroDoc.value.toUpperCase();
			}
		} 		
	}
	return (numeroDoc);
}


function quitarCeros (numero){
	if (numero.length == 10){
		var primerCaracter = numero.substring (0,1);
		if (primerCaracter == "0"){
			numero = numero.substring(1,numero.length); 
		}
		else {
			var segundoCaracter = numero.substring (1,2);
			if (segundoCaracter == "0"){
				numero = primerCaracter+numero.substring(2,numero.length); 	
			}
		}
	}
	return (numero);
}