/***************************************************************************************/
/******************* NOTA: ESTE JAVASCRIPT DEPENDE DE VALIDACIONESMUTUA.JS *************/
/******************* CON LO CUAL ANTES DE INCLUIR VALICACIONES.JS HAY QUE  *************/
/******************* INCLUIR VALIDACIONESMUTUA.JS						   *************/	

	function bisiesto(year) 
	{
		if ((year % 4 == 0) && (( year % 100 != 0) || (year % 400 ==0)))
	  		return true;
		else
	  		return false;
	}


	function isHoy( fechaComparar ){
	
		var fechaActual = new Date();
		
		var fecha = fechaComparar.split("/"); 
		
		var dia = fecha[0]; 
		var mes = fecha[1] - 1; 
		var ano = fecha[2]; 		
		
		// creamos la fecha a comparar con la hora 23:59:59 para que cubra todo el día
		var miFecha = new Date(ano,mes,dia,23,59,59); 
						
		if( miFecha == fechaActual ){
			return 0;
		} else if (miFecha < fechaActual){
			return -1;
		} else if (miFecha > fechaActual) {
			return 1;
		} else {
			// terminacion anormal
			return -2;
		}
	}
	
	
	function isNum( numstr ) {
	
		if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "")	
			return false;
	
		var isValid = true;
		var decCount = 0;		
	
		numstr += "";	
	
		for (i = 0; i < numstr.length; i++) {
			if (numstr.charAt(i) == ".")
				decCount++;
	
	    	if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || 
					(numstr.charAt(i) == "-") || (numstr.charAt(i) == "."))) {
	       	isValid = false;
	       	break;
			} else if ((numstr.charAt(i) == "-" && i != 0) ||
					(numstr.charAt(i) == "." && numstr.length == 1) ||
				  (numstr.charAt(i) == "." && decCount > 1)) {
	       	isValid = false;
	       	break;
	      }         	         	       
	
	   } 
	   
	   	return isValid;
	} 

	function validaDia(oTxt){
	
		var bOk = false;

		if( isNum(oTxt) ) {
			
			var nDia = parseInt(oTxt, 10);
	
			bOk = bOk || ((nDia >= 1) && (nDia <= 31));
		}

		return bOk;
	}
	
	function validaMes(oTxt){
	
		var bOk = false;

		if ( isNum(oTxt) ) {	
			
			var nMes = parseInt(oTxt, 10);
	
			bOk = bOk || ((nMes >= 1) && (nMes <= 12));
		}

		return bOk;
	}
	
	function validaAnyo(oTxt){
		
		var bOk = false;
		
		if( isNum(oTxt) ) {
				
			// Variables auxiliares
			var fecha = new Date();		
			
			var nAno = parseInt(oTxt, 10);
			
			bOk = nAno.length != 4;
						
		} else {
			bOk = false;
		}
			
		return bOk;
	}

	function isFechaCorrecta(fecha) { 
		
		try { 
			var fecha = fecha.split("/"); 
			
			var dia = fecha[0]; 
			var mes = fecha[1]; 
			var ano = fecha[2]; 
			
			var estado = true; 
			
   
  
		    if (isNaN(ano) || ano.length < 4 ){   
		        estado = false   
		    }   
		    if (isNaN(mes) || parseFloat(mes) < 1 || parseFloat(mes) > 12){   
		        estado = false   
		    }   
		    if (isNaN(dia) || parseInt(dia, 10) <1  || parseInt(dia, 10) > 31){   
		        estado = false   
		    }   
		    if (mes == 4 || mes == 6 || mes == 9 || mes == 11 || mes == 2) {   
		        if (mes == 2 && dia > 28 || dia > 30) {   
		            estado = false   
		        }   
		    }   

			
			return estado; 
		}catch(err){ 
			return false;
		}
	}


 function ponBlanco(campo){
	campo.style.backgroundColor = '';
}
/*********************************************************************************************/
/******************  Función que me limpia los espacios                               ********/
/******************  en blanco del comienzo y fin de la cadena y me devuelve la cadena********/
/*********************************************************************************************/

function quitaBlancos(theForm) {
    if(theForm.value)
	{
		var x = theForm.value;
		theForm = (x.replace(/^\s+/,'')).replace(/\s+$/,'');
		return(theForm);
	}
}


function compruebaNumero(value) {
	return UtilV.validaRegExp("^[0-9]+$",value);
}

function replaceAll( text, busca, reemplaza ){  
 
	while (text.toString().indexOf(busca) != -1){       
		text = text.toString().replace(busca,reemplaza);   
	}   
	
	return text;
}

/**************************************************************************/
/******************  Función que me valida los dígitos de          ******************/
/******************  control de una cuenta bancaria 	 ******************/
/**************************************************************************/

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);

}  
/**************************************************************************/
/********************      Funciones que pintan las páginas     ********************/
/*************************************************************************/
var pulsar=0;
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); 
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*******************************************************************************/
/********************** ESTE GRUPO DE FUNCIONES SE ************************/
/********************** ENCARGA DE HACER PARPADEAR *********************/
/********************** UN LITERAL EN LA PARTE DE  *************************/
/********************** ABAJO DEL NAVEGADOR ******************************/
/*******************************************************************************/
function pintaAbajo(arg1,arg2,arg3,tipo){
	startclock(tipo,0);
	MM_preloadImages(arg1,arg2,arg3);
}
var timerRunning = false;
var timerID = null;
function stopclock(){  
	 if(timerRunning)      
		clearTimeout(timerID);
	timerRunning = false;
}

function startclock(tip,i){   
	// Nos aseguramos de que el reloj está parado   
	stopclock();  
	showtime(tip,i);
}
/******************************************************************************/
/**********************  Funcion que se encarga de sacar    *************************/
/**********************  un mensaje en la parte de abajo del *************************/
/**********************  browser desplanzando el mensaje    *************************/
/******************************************************************************/
function showtime2(tip,i){
	i++;   
	if (i==tip.length) i=0;
	window.defaultStatus=tip.substring(i);
	timerID = setTimeout("showtime('"+tip+"','"+i+"')",150);   
	timerRunning = true;
}
/******************************************************************************/
/**********************  Funcion que se encarga de sacar    *************************/
/**********************  un mensaje en la parte de abajo del *************************/
/**********************  browser haciendo un parpadeo        *************************/
/******************************************************************************/
function showtime(tip,i){
	i++;   
	if(i%10==1){
		window.defaultStatus="                                                                                                                         ";
	}else{
		window.defaultStatus=tip;
	}
	timerID = setTimeout("showtime('"+tip+"','"+i+"')",75);   
	timerRunning = true;
}
function pintura(tip){
	window.defaultStatus=tip;
	window.clearTimeout
}

        
/**************************************************************************/
/*******                 VALIDACIÓN DE FECHAS                        ******/
/**************************************************************************/

function dameEdad (F1, dataType){
	var now = new Date();
	var fechaHoy = "";
    fechaHoy = getFechaHoy();
	
	var edadActual = DiferenciaAnios(fechaHoy,F1, 3);
	return edadActual;
}

function DiferenciaAnios(F2, F1, dateType) { 
/*
    function DiferenciaAnios
    parameters: F2(la mayor), F1(la menor) dateType
    returns: String

    F1 & F2 son dos fechas pasadas como string con los 
	siguientes formatos:
    type 1 : 19970529
    type 2 : 970529
    type 3 : 29/05/1997
    type 4 : 29/05/97

    dateType es un número entero de 1 a 4, que representa
    el tipo de fecha que se ha pasado por parámetro, 
	tal como se define mas arriba.

    Devuelve un String que contiene la diferencia de años en el formato YYYY.
    Devuelve una cadena vacia si uan de las fechas no tiene el formato indicado.
 */

	if (dateType == 1){
		var S1 = F1.substring(0,4) + "/" +
                F1.substring(4,6) + "/" +
				F1.substring(6,8);
		var S2 = F2.substring(0,4) + "/" +
                F2.substring(4,6) + "/" +
				F2.substring(6,8);		
	}else if (dateType == 2){
		var S1 = F1.substring(0,2) + "/" +
                 F1.substring(2,4) + "/" +
                 F1.substring(4,6);
		var S2 = F2.substring(0,2) + "/" +
                 F2.substring(2,4) + "/" +
                 F2.substring(4,6);
	}else if (dateType == 3){
		var S1 = F1.substring(6,10) + "/" +
                 F1.substring(3,5) + "/" +
                 F1.substring(0,2);
		var S2 = F2.substring(6,10) + "/" +
                 F2.substring(3,5) + "/" +
                 F2.substring(0,2);
				

	}else if (dateType == 4){
		var S1 = F1.substring(6,8) + "/" +
				 F1.substring(3,5) + "/" +
                 F1.substring(0,2);
		var S2 = F2.substring(6,8) + "/" +
				 F2.substring(3,5) + "/" +
                 F2.substring(0,2);
   	}else
		return '';
		
 var D2 = ReadISO8601date(S2) ; if (D2<0) return ""
 var D1 = ReadISO8601date(S1) ; if (D1<0) return ""
 D1 = new Date(D1[0], D1[1], D1[2])
 D2 = new Date(D2[0], D2[1], D2[2])

 var age = D2.getFullYear() - D1.getFullYear()
 D1.setFullYear(D2.getFullYear())
 if (D1>D2) age--
 return age  
}

function compareDates(dateA,dateB,dateType,returnType)
/*   
	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
    
    return value: difference B-A
    return  type 1: hours
    		type 2: days
    		type 3: years
    		default: millis
*/   
{
	var a,b;
	var yearLen, dayStart, monthStart, yearStart;
	if (dateType == 1){     
		yearLen = 4; dayStart = 6; monthStart = 4; yearStart = 0;
	} else if (dateType == 2) {
		yearLen = 2; dayStart = 4; monthStart = 2; yearStart = 0;
	} else if (dateType == 3) {
		yearLen = 4; dayStart = 0; monthStart = 3; yearStart = 6;
	} else if (dateType == 4) {
		yearLen = 2; dayStart = 0; monthStart = 3; yearStart = 6;
	} else
        return '';	
        
    var a = new Date(dateA.substr(yearStart,yearLen),
                      dateA.substr(monthStart,2),
                      dateA.substr(dayStart,2));
    var b = new Date(dateB.substr(yearStart,yearLen),
                      dateB.substr(monthStart,2),
                      dateB.substr(dayStart,2));

   	var millisA = a.getTime();
   	var millisB = b.getTime();

    var minutes = 1000 * 60;
	var hours = minutes * 60;
	var days = hours * 24;
	var years = days * 365.256363;
	var divisor;
	switch(returnType)
	{
		case 1: divisor = hours; break;
		case 2: divisor = days; break;
		case 3: divisor = years; break;
		default: divisor = 1;
	}
	return Math.floor((millisB-millisA)/divisor); 
}

		
function ValidDate(y, m, d) // m = 0..11
 { with (new Date(y, m, d)) return ((getDate()==d) && (getMonth()==m)) }

function ReadISO8601date(Q) { var T // adaptable for other layouts
	if ((T = /^(\d+)([-\/])(\d\d)(\2)(\d\d)$/.exec(Q)) == null)
	{ return -2 } // bad format
	for (var j=1; j<=5; j+=2) 
	{ T[j] = parseInt(T[j], 10) } // wanted ?
	if (!ValidDate(T[1], T[3]-1, T[5])) 
	{ return -1 } // bad value
	return [ T[1], T[3], T[5] ] 
}
 
function getFechaHoy(){
	var now = new Date();
	var fechaHoy = "";
	if (now.getDate() < 10)
    	fechaHoy = fechaHoy + 0 + now.getDate();
	else 
		fechaHoy = fechaHoy + now.getDate();
	var mes = now.getMonth()+1;
	if ( mes<10)
		fechaHoy = fechaHoy + "/0" + mes;
	else
		fechaHoy = fechaHoy + "/" + mes;

	fechaHoy = fechaHoy + "/" + now.getFullYear();
	return fechaHoy;	
}


function IsNumeric(valor){
	var log=valor.length; var sw="S";
	for (x=0; x<log; x++){
		v1=valor.substr(x,1);
		v2 = parseInt(v1, 10);
	//Compruebo si es un valor numérico
		if (isNaN(v2)) {
			sw= "N";
		}
	}
	if (sw=="S") {
		return true;
	}else {
		return false;
	}
} 

function isYear(anio){
	var now = new Date();
	var today = new Date(now.getYear(),now.getMonth(),now.getDate());
   	var anioAct = (UtilV.y2k(now.getYear()) );		
	var anioIni=1500;                   
	if( anio && IsNumeric(anio)){
		if(parseInt(anio, 10)>parseInt(anioAct, 10)) {
			return(false);
		}else if(parseInt(anio, 10)<parseInt(anioIni, 10)){
			return(false);
		}
		return(true);
	}else{
		return(false);
	}
}
		
function formateaCantidad(valor,numDecimales) {
// transforma un numero en formato "#####.##" al formato "##.###,##"
	if (valor==null) return false;
	var numero = (''+valor).split(".");
	if (numero.length>2) return false;
	if (!compruebaNumero(numero[0])) return false;

	var ceros = 3-(numero[0].length%3);
	if (ceros==3) ceros = 0;
	for (var i=0;i<ceros;i++) numero[0] = "0"+numero[0]; //rellenamos con ceros a la izquierda

	//parte entera
	var entera = "";
	var i = numero[0].length-1;
	while (i>3) {
		entera = "."+numero[0].charAt(i-2)+numero[0].charAt(i-1)+numero[0].charAt(i)+entera;
		i=i-3;
	}
	entera = numero[0].charAt(2)+entera;
	if (ceros <2) entera = numero[0].charAt(1)+entera;
	if (ceros <1) entera = numero[0].charAt(0)+entera;
	
	//parte decimal
	var decimal = "";
	
	for (var x=0;x<numDecimales;x++)
	{
		if (numero.length>1 && ((numero[1].length)>(x)) ) 	decimal += numero[1].charAt(x);
		else 					  							decimal += "0";
	}

	if ( decimal == "" ){
		return entera;
	} else { 
		return entera+","+decimal;
	}
}


//Antes de enviar los datos, debemos eliminar los millares de la parte entera de la cantidad,
//y sustituiremos la coma decimal por un punto.

function enviarDato(_campo){
var s1="",s2="";
  //eval("s1=document."+this.form+"."+_campo+".value.replace(/\s/g,'')");  
  s1=_campo.value.replace(/\s/g,'');

  
  //if(s1=="") return 0;
  
  for(var i=0;i<s1.length;i++){
    if(s1.charAt(i)!='.')
      if(s1.charAt(i)==',') s2+='.';
      else s2+=s1.charAt(i);
  }
  //if(s2=="") s2="0";
  
  return(s2);
  
}


/**********************************************************************************/
/******************  Función que me limpia los espacios          ******************/
/******************  en blanco del comienzo y fin de la cadena.	 ******************/
/**********************************************************************************/

// 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  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 newstr;
    }
    else {
       // Error
       alert ("La direccion de correo no tiene el formato adecuado.");
       //checkString1.focus();
       //return checkString;
       return false;
    }
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
	

	
// ************** HTML
	
		// *************************
	function cambiaFoco(campoInicial, campoFinal){
		//funcion utilizada para cambiar de un campo a otro en la introduccion de una  cuenta por ejemplo
		//si llegamos a la longitud del campo Inicial, nos pasamos a la siguiente
		//utilizar con evento KeyUp
		var campoInicialAux = document.getElementById(campoInicial);
		if (campoInicialAux.value.length == campoInicialAux.maxLength)
			document.getElementById(campoFinal).focus();
	}
		
	function setCombo(name,enabled,value) {
  		var select = eval("document.forms[0]."+name);
  		if (enabled) { 
 	 		var index;
 			for (var i=0;i<select.options.length;i++) {
  				if (select.options[i].value==value) { index = i; break; }
  			}
	  		select.selectedIndex = index;	
  		}
 		select.disabled = !enabled;
  	}
  	
/**********************************************************************************/
/******************                      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 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 me valida que el                 ********************/
/******************                      dato sea sólo letras                          ********************/
/*********************************************************************************/
function validaLetras(theFormtxtNombre)
{
  var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZabcdefghijklmnñopqrstuvwxyz";
  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/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)=="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 matricula introducida no es correcta");
		return(false);
	}
	axMod = valor.split("-");
	if (axMod.length > 1){
		alert("La matrícula 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ícula introducida no es correcta.");
				return(false);
			}
		}else{
			alert("La matrícula 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ícula en Régimen Diplomático 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ícula 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ícula 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ícula introducida no es correcta.");
								return(false);							
							}
						}else{
							//si estas 2 ultimas son números.
							if (valor.substring(6).length != 2){
								alert("La matrícula introducida no es correcta.");
								return(false);
							}
						}
					}
				}else{
					// a las 2 primeras posiciones, que son letras, no les siguen 4 números.
					alert("La matrícula 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ícula 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ícula 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ícula introducida no es correcta.");
								return(false);							
							}
						}else{
							if (valor.substring(5).length != 2){
								alert("La matrícula introducida no es correcta.");
								return(false);
							}
						}
					}
				}else{
					// a la primera posicion, que es una letra, no le sigue 4 números.
					alert("La matrícula introducida no es correcta.");
					return(false);
				}
			}		
		}else{
			alert("La matrícula introducida no es correcta.");
			return(false);
		}
	}
	return(true);
}//fin del validaMatricula

function validaCantidad(value) {
	var exp = "^([0-9]{1,3}){1}([/.][0-9]{3})*(,[0-9]+)?$";
	if (value.indexOf(".")<0) exp = "^[0-9]+(,[0-9]+)?$"; //si no hay puntos tb puede pasar
	return UtilV.validaRegExp(exp,value);
}

/*******************************************************************************/
/******************  Función que quita el formato decimal   ********************/
/******************  a un valor: cambia comas por puntos	********************/
/*******************************************************************************/
function desformateaCantidad(valor) {
	var result = valor.replace(".","");
	return result.replace(",","."); 
}

	// //////////////////////////////////////////////////////