// //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// ///////////////////////////////// VARIABLES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
 
/*
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<< VALIDACIÓN DE MATRÍCULAS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*/
// FUNCIONES COMUNES:
// Determina si un caracter es numérico.
function ldaComunEsNumerico(num){
   return (/^[0-9]$/.test(num));
}
// Determina si un caracter es letra.
function ldaComunEsLetra(valor){
   return (/^[a-zA-Z]$/.test(valor));
}
// Determina si un caracter es vocal.
function ldaComunEsVocal(caracter){
   return (/^[a,A,e,E,i,I,o,O,u,U]$/.test(caracter));
}
// Determina si un caracter es letra no vocal.
function ldaComunEsLetraNoVocal(valor){
	return  (ldaComunEsLetra(valor)&&(!ldaComunEsVocal(valor)));
}
// Limpia una cadena de caracteres de todo lo que no sean numeros o letras.
function ldaComunLimpiaCadena(matricula){
	var aux = "";
	var tamanyo = matricula.length;
   	for (var i = 0;i < tamanyo; i++){
		if( (ldaComunEsNumerico(matricula.charAt(i) )) || ( ldaComunEsLetra(matricula.charAt(i) )) ) {   
	   		aux = aux + matricula.charAt(i).toUpperCase();
		}
	}
   	matricula = aux;
   	return matricula;
}
// FUNCIONES ESPECÍFICAS:
/*
	Función de validación de matrículas.
	Entrada : formateado y toUpperCase().
	Retorno : correcto -> La matrícula formateada.
			  incorrecto -> "".
*/
function validateLicensePlate(codigo,mat){
	if ((codigo != "02") && (codigo != "08")){
    	mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
    } else {
		mat = mat.toUpperCase();
	}
    var matRetorno = "";
    var result = false;	
    switch (codigo){
		// ACTUAL ORDINARIA
		case '01':
			result = ldaComunValidacionActualOrdinaria(mat);
			if (result) matRetorno = ldaComunFormateaActualOrdinaria(mat);
			break;
		// ANTIGUA ORDINARIA
    	case '02': 
			result = ldaComunValidacionAntiguaOrdinaria(mat);
			if (result) matRetorno = ldaComunFormateaAntiguaOrdinaria(mat);
			break;
		// REMOLQUE Y SEMIRREMOLQUE FORMATO ANTIGUO
		case '03': 
			result = ldaComunValidacionRemolqueAntiguo(mat);
			if (result) matRetorno = ldaComunFormateaRemolqueAntiguo(mat);
			break;
		// VEHICULOS ESPECIALES Y TRACTORES FORMATO ANTIGUO
		case '04':
			result = ldaComunValidacionVehiculoEspecialAntiguo(mat);
			if (result) matRetorno = ldaComunFormateaVehiculoEspecialAntiguo(mat);
			break;
		// CICLOMOTORES
		case '07':
			result = ldaComunValidacionCiclomotor(mat);
			if (result) matRetorno = mat;
			break;
		//
    	case '08': 
			if (ldaComunIsValidFormat("XXNNNNXNNXXX",mat)){
				result = true;
				matRetorno = mat;
			}
			break;
		// Copiado de parte no hace validación de matrícula
        case '13':
            result = true;
            matRetorno = mat;
            break;
		// TEMPORAL 
		case '15': 
			result = ldaComunValidacionTemporal(mat); 			
            if (result) matRetorno = ldaComunFormateaTemporal(mat); 			
            break; 			
		// EUROPEA
		case '16':
			result = ldaComunValidacionEuropea(mat);
			if (result) matRetorno = ldaComunFormateaEuropea(mat);
			break;
		// VEHÍCULOS ESPECIALES FORMATO NUEVO
		case '17':
			result = ldaComunValidacionVehiculoEspecialNuevo(mat);
			if (result) matRetorno = ldaComunFormateaVehiculoEspecialNuevo(mat);
			break;
		// REMOLQUES CON PLACAS FORMATO NUEVO
		case '18':
			result = ldaComunValidacionRemolqueNuevo(mat);
			if (result) matRetorno = (ldaComunLimpiaCadena(mat)).toUpperCase();
			break;
		// MATRÍCULA HISTÓRICA
		case '20': 
			result = ldaComunValidacionHistorica(mat);
			if (result) matRetorno = ldaComunFormateaHistorica(mat);
			break;
    }
	if (result == false){
    	matRetorno = "";  
	}
	return matRetorno;
}

/*
	Descripción: validación de las matriculas actuales ordinarias
		entrada:---> SIGLA PROVINCIAL (1 o 2 letras) - 4 números - 1 o 2 letras
		salida  :---> TRUE, si pasa las validaciones especiales de matrícula 
				:---> FALSE: c.c.
*/
function ldaComunValidacionActualOrdinaria(mat){
	var mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
	var result= false;
	/*
		Patrones válidos:
		CXNNNNC -------------> MU3443V
		CXNNNNXC ------------> MU3456PV
		CNNNNC --------------> M1234W
		CNNNNXC -------------> M2234ZV
		CXNNNNNNC -----------> MU003456V
		CXNNNNNNXC ----------> MU003456PV
		CNNNNNNC ------------> M003456V
		CNNNNNNXC -----------> M003456PV
	*/
 	if ((ldaComunIsValidFormat("CXNNNNXC",mat))||(ldaComunIsValidFormat("CNNNNXC",mat))||
 	    (ldaComunIsValidFormat("CXNNNNC",mat)) ||(ldaComunIsValidFormat("CNNNNC",mat))||
 	    (ldaComunIsValidFormat("CXNNNNNNXC",mat)) || (ldaComunIsValidFormat("CNNNNNNXC",mat)) ||
		(ldaComunIsValidFormat("CNNNNNNC", mat)) || (ldaComunIsValidFormat("CXNNNNNNC",mat)))	{
 	    result = true;
 	}
	return result;
}

/*
	Descripción: formatea la matrícula con el formato
	MATRICULA ACTUAL ORDINARIA   ----> CX00NNNNXC
	entrada: matricula actual ordinaria.
	salida:  matricula actual ordinaria formateada.
*/
function ldaComunFormateaActualOrdinaria(mat){
	var provincia = "";
	var numAux = "";
	for (var i=0;i<mat.length;i++){
   		if (ldaComunEsNumerico(mat.charAt(i))){
	    	numAux = numAux + mat.charAt(i);
   		}
	}
	var numeros   = "";
	if (numAux.length <= 4){
    	numeros = "00";
	}
	var letras    = "";
	if (ldaComunEsLetra(mat.charAt(0))){
		provincia = provincia  + mat.charAt(0);
	}
	if (ldaComunEsLetra(mat.charAt(1))){
   		provincia = provincia  + mat.charAt(1);
		numeros = numeros + numAux;//mat.substr(2,4);
		if(ldaComunEsLetra(mat.substring(mat.length - 2, mat.length-1))){
			letras = letras + mat.substring(mat.length-2);
		}else{
			letras = letras + mat.substring(mat.length-1);
		}
	}else{
   		provincia = provincia  + " ";
		numeros = numeros + numAux; //amat.substr(1,4);
		if(ldaComunEsLetra(mat.substring(mat.length - 2, mat.length-1))){
			letras = letras + mat.substring(mat.length-2);
		}else{
			letras = letras + mat.substring(mat.length-1);
		}
	}
	if (letras.length == 1){
    	letras = " " + letras; 
	}
	return (provincia + numeros + letras);
}

/*
	Descripción: validación de las matriculas antiguas ordinarias
		entrada:---> SIGLA PROVINCIAL - 6 NUMEROS desaparecen en 1.971	  
		salida  :---> TRUE, si pasa las validaciones especiales de matrícula 
				:---> FALSE: c.c.
*/
function ldaComunValidacionAntiguaOrdinaria(mat){
	var result= false;
	if (ldaComunIsValidFormat("XXNNNNNNXXXX",mat) 
		||ldaComunIsValidFormat("XNNNNNN",mat) 
		||ldaComunIsValidFormat("XXNNNNNN",mat) 
		||ldaComunIsValidFormat("XNNNNNNXXXX",mat) 
		||ldaComunIsValidFormat("XXNNNNN",mat) 
		||ldaComunIsValidFormat("XXNNNNNN",mat) 
		||ldaComunIsValidFormat("XNNNNN",mat) 
		||ldaComunIsValidFormat("XNNNNNN",mat) 
		||ldaComunIsValidFormat("XNNNNX",mat) 
		||ldaComunIsValidFormat("XXNNNNX",mat)){
		result = true;
	}	
	return result;
}

/*
	Descripción: formatea la matrícula con el formato
	MATRICULA ANTIGUA ORDINARIA ----> CXNNNNNNXXXX
	entrada: matricula antigua ordinaria.
	salida:  matricula antigua ordinaria formateada.
*/
function ldaComunFormateaAntiguaOrdinaria(mat){
	var cadena = "";
	// Letras de pronvincia, si hay una se le añade un espacio
	var reLetPrin = /^[A-Z]{1,2}/i;
	cadena += reLetPrin.exec(mat)[0];
	if (cadena.length < 2) cadena += " ";
	// Números, si son menos de 6 se completan con ceros
	var reNum = /\d{4,6}/i;
	var num = reNum.exec(mat)[0];
	for (var i=0; i < (6 - num.length) ; i++){
		cadena += "0";
	}
	cadena += num;
	// Letras finales pueden ser hasta 4
	var reLetFin = /[A-Z]{0,4}$/i;
	cadena += reLetFin.exec(mat)[0];
	//
	return cadena;
}

/*
	Formatear la matrícula ordinaria antigua de un remolque 
	Salida --> CXNNNNNNR
*/
function ldaComunFormateaRemolqueAntiguo(mat){
	var provincia = "";
	var numeros = "";
	for (var i=0;i<mat.length;i++){
   		if (ldaComunEsNumerico(mat.charAt(i))){
	    	numeros = numeros + mat.charAt(i);
   		}
	}
	var letras    = "";
	if (ldaComunEsLetra(mat.charAt(0))){
		provincia = provincia  + mat.charAt(0);
	}
	if (ldaComunEsLetra(mat.charAt(1))){
   	provincia = provincia  + mat.charAt(1);
	}else{
    provincia = provincia  + " ";		
	}
	letras = letras + mat.substring(mat.length-1);
	return (provincia + numeros + letras);	
}


/*
	Descripción: validación de las matriculas de ciclomotores
		entrada:---> SIGLA C - 4 NUMEROS - 3 LETRAS	  
		salida  :---> TRUE, si pasa las validaciones especiales de matrícula 
				:---> FALSE: c.c.
*/
function ldaComunValidacionCiclomotor(mat){
	var result = false;
	if (ldaComunIsValidFormat("CNNNNCCC",mat)){
		var expresion = /^[c]\d{4}[bcdfghjklmnprstvwxyz]{3}/i;
		result = expresion.test(mat);
	}
	return result;
}

/*
	Descripción: validación de las matrículas europeas
		entrada:---> SIGLA E - 4 NÚMEROS - 3 LETRAS
		salida :---> TRUE, si pasa las validaciones especiales de matrícula europea.
		       :---> FALSE: c.c.
*/
function ldaComunValidacionEuropea(mat){
	var result = false;	
	if ((ldaComunIsValidFormat("NNNNCCC",mat))||
		(ldaComunIsValidFormat("CNNNNCCC",mat))||
		(ldaComunIsValidFormat("CXNNNNCCC",mat))
		){

		mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
		var longitud = mat.length;
		if ( (ldaComunEsLetraNoVocal(mat.charAt(longitud -1)))&& (ldaComunEsLetraNoVocal(mat.charAt(longitud -2)))&&
			(ldaComunEsLetraNoVocal(mat.charAt(longitud -3))) ){
			result = true;
		}
		// se puede dar el caso siguiente:
		if ((!ldaComunEsNumerico(mat.charAt(0))) && (mat.charAt(0).toUpperCase() != "E")){
			result = false;
		}
		if ((!ldaComunEsNumerico(mat.charAt(1))) && (mat.charAt(1) != "")){
			result = false;
		}
		if ( (mat.charAt(longitud - 1).toUpperCase() == "Q")  || (mat.charAt(longitud - 2).toUpperCase() == "Q") || 
			 (mat.charAt(longitud - 3).toUpperCase() == "Q")) {
			result = false;
		}
	}
	return result;
}

/*
	Descripción: formatea la matrícula con el formato
	MATRICULA EUROPEA -----> E NNNNCCC
	entrada: matricula europea.
	salida: matricula europea formateada.
*/
function ldaComunFormateaEuropea(mat){
	var aux = "";
   	if(mat.charAt(0) != "E"){
   		aux = "E " + mat;
   	}else{
    	aux = mat.charAt(0) + " " + mat.substr(1,mat.length -1);
   	}
	return aux;
}	

/*
	Descripción: validación de las matrículas históricas
		entrada:---> SIGLA H - 4 NUMEROS - 3 LETRAS
		salida :---> TRUE, si pasa las validaciones especiales de matrícula histórica
		       :---> FALSE: c.c.
*/
function ldaComunValidacionHistorica(mat){
	/*
		Patrones válidos:
		XNNNNXXX  -------->H1234BBB
		XNNNNXXX  -------->H1234 BBB			
		XNNNNXXX  -------->H 1234BBB
		XNNNNXXX  -------->H 1234 BBB
		XNNNNXXX  -------->H 1234 BBB
	*/
	var result = false;
	if (ldaComunIsValidFormat("XNNNNXXX",mat)){
		var expresion = /^[h]\d{4}[bcdfghjklmnprstvwxyz]{3}/i;
		result = expresion.test(mat);
	}
	return result;
}

/* 
Descripción: validación de las matrículas temporales 
        entrada:---> SIGLA P/S/V - 4 NUMEROS - 3 LETRAS 
        salida :---> TRUE, si pasa las validaciones especiales de matrícula temporal 
              :---> FALSE: c.c. 
*/ 
function ldaComunValidacionTemporal(mat){ 
        /* 
        Patrones válidos: 
        XNNNNXXX  -------->P1234BBB 
        XNNNNXXX  -------->P1234 BBB                         
        XNNNNXXX  -------->P 1234BBB 
        XNNNNXXX  -------->P 1234 BBB 
        XNNNNXXX  -------->P 1234 BBB 
        */
        var result = false; 
        if (ldaComunIsValidFormat("XNNNNXXX",mat)){ 
                var expresion = /^[psv]\d{4}[bcdfghjklmnprstvwxyz]{3}/i; 
                result = expresion.test(mat); 
        } 
        return result; 
} 

/* 
Descripción: formatea la matrícula con el formato PNNNNXXX 
        entrada: matricula temporal. 
        salida: matricula formateada. 
*/ 
function ldaComunFormateaTemporal(cadena){ 
        var let = /[bcdfghjklmnprstvwxyz]{3}/i; 
        var letras = let.exec(cadena); 
        var num = /\d{4}/; 
        var numeros = num.exec(cadena); 		
        cadena = cadena.charAt(0).toUpperCase() + numeros[0] + letras[0].toUpperCase(); 
        return cadena; 
}

/*
	Descripción: formatea la matrícula con el formato H NNNNXXX
		entrada: matricula europea.
		salida: matricula formateada.
*/
function ldaComunFormateaHistorica(cadena){
	var let = /[bcdfghjklmnprstvwxyz]{3}/i;
	var letras =  let.exec(cadena);
	var num = /\d{4}/;
	var numeros = num.exec(cadena);
	cadena = "H" + numeros[0] + letras[0].toUpperCase();
	return cadena;
}

/*
	Descripción: valicadion de las matrículas de vehículos especiales conformato nuevo

*/
function ldaComunValidacionVehiculoEspecialNuevo(mat){
	var result = false;
	/*
		Patrones válidos:
		E12345VFG
	*/
	var expresion = /^E\d{4}[BCDFGHJKLMNPRSTVWXYZ]{3}$/i;
	result = expresion.test(mat);
	return result;
}
/*
	Descripción: validación de las matrículas de vehículos especiales y tractores formato antiguo
*/
function ldaComunValidacionVehiculoEspecialAntiguo(mat){
	mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
//	return result;
	var result = false;
	/*
		Patrones válidos:
		CXNNNNNXX ----------> AL12345VE
	*/
	//if (ldaComunIsValidFormat("CXNNNNNXX",mat)){
		var expresion = /^[A-Z]{1,2}\d{5,6}VE$/i;
		result = expresion.test(mat);
	//}
	return result;
}

/*
	Descripción: formatea la matrícula con el formato
	MATRICULA VEHÍCULOS ESPECIALES Y TRACTORES FORMATO ANTIGUO----> CXNNNNNXX
	entrada: matricula vehículo especial.
	salida:  matricula vehículo especial formateada.
*/
function ldaComunFormateaVehiculoEspecialAntiguo(mat){
	var cadena = "";
	// Letras de pronvincia, si hay una se le añade un espacio
	var reLetPrin = /^[A-Z]{1,2}/i;
	cadena += reLetPrin.exec(mat)[0];
	if (cadena.length < 2) cadena += " ";
	// Cinco números
	var reNum = /\d{5,6}/i;
	var num = reNum.exec(mat)[0];
	for (var i=0; i < (6 - num.length) ; i++){
		cadena += "0";
	}
	cadena += num;
	// Letras finales (será siempre VE)
	var reLetFin = /[A-Z]{2}$/i;
	cadena += reLetFin.exec(mat)[0];
	//
	return cadena;
}

/*
	Formatea las matriculas de quads
*/
function ldaComunFormateaVehiculoEspecialNuevo(mat){
	mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
	return mat;
}

/*
	Validación de matrícula para remolques con placas (cod2mat = '03')
*/
function ldaComunValidacionRemolqueNuevo(mat){
	mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
	var result = false;
	/*
		Patrones válidos:
		R1234VFG
	*/
	var expresion = /^R\d{4}[BCDFGHJKLMNPRSTVWXYZ]{3}$/i;
	result = expresion.test(mat);
	return result;
}

/*
	Validación de matrícula para remolques y semirremolques anteriores a matriculas europeas (cod2mat = '18')
*/

function ldaComunValidacionRemolqueAntiguo(mat){
	var result = false;
	mat = (ldaComunLimpiaCadena(mat)).toUpperCase();
	/*
		Patrones válidos:
		CNNNNNNR ---------->  M123456R
		CXNNNNNNR ----------> AL123456R		
	*/
	if ((ldaComunIsValidFormat("CNNNNNNC",mat)) || (ldaComunIsValidFormat("CXNNNNNNC",mat))){
			var longitud = mat.length;			
		// La letra final debe ser R
		if (ldaComunEsLetraNoVocal(mat.charAt(longitud -1)) && mat.charAt(longitud - 1) == "R"){
			result = true;
		}		
	}
	return result;
}

/*
	Descripción: esta función determina si el string pasado
			 como parámetro se ajusta a un determinado 
			 patrón, también pasado como parámetro.
	Entrada:     PATRON, STRING.
	Salida:      TRUE ---> se ajusta al patrón.
			 FALSE --> c.c.
*/
function ldaComunIsValidFormat(pat,str) {
	if (pat.length != str.length){ 
	    return false;
	} else {
		for (i=0;i<pat.length;i++) {
			c = str.charAt(i);
	   		h = pat.charAt(i);
	   		switch(h) {
	      		case 'X': 
	      			if ((c.toUpperCase()<'A' || c.toUpperCase()>'Z') && c.toUpperCase() != ' ') {
	      				return false;
	      			}
	      		break;
	      		case 'C': 
					if (c.toUpperCase()<'A' || c.toUpperCase()>'Z') {
			      		return false;
	      			}
	      		break;
	      		case 'N': 
					if (isNaN(parseInt(c)))  {
	      				return false;
		      		}
	      		break;
				default: break;
	   		}
		}
    	return true;
   	}
}

//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<<<<<<<< FIN. VALIDACION MATRICULAS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


// funciones típicas /////////////////////////////////////////////////////////////////
// abrir ventana navegador
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

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() { //v6.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_showHideTables() { //v6.0
  var i,p,v,obj,args=MM_showHideTables.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')?'block':(v=='hide')?'none':v; }
    obj.display=v; }
}


function moveLayerTop(layer,top){
  if(document.layers){//  If Netscape 4
    document.layers[layer].top = top;
  }else if(document.all){//  If IE4
    document.all[layer].style.pixelTop = top;
  }
}

//////////////////////////////////////////////////////////
/////////////  SCRIPT PARA REALIZAR EL SCROLL //////////
window.onerror = null; 
 var bName = navigator.appName;
 var bVer = parseInt(navigator.appVersion);
 var NS4 = (bName == "Netscape" && bVer >= 4);
 var IE4 = (bName == "Microsoft Internet Explorer" && bVer >= 4);
 var NS3 = (bName == "Netscape" && bVer < 4);
 var IE3 = (bName == "Microsoft Internet Explorer" && bVer < 4);
//-----------------------------------------------------------
 var scroll_length = 384;// The scroll length
 var time_length =10;// Scroll delay in milliseconds
 var begin_pos = 0;// Start position of scroll hint
 var i=begin_pos;
 var j=i;
 var scroll_dir="left";//  To scroll left use "left"
//                            To scroll right use "right"
//-----------------------------------------------------------
if (NS4 || IE4) {
 if (navigator.appName == "Netscape") {
 layerStyleRef="layer.";
 layerRef="document.layers";
 styleSwitch="";
 }else{
 layerStyleRef="layer.style.";
 layerRef="document.all";
 styleSwitch=".style";
 }
}
//SCROLL
function Scroll(layerName)
{
document.forms["datos02Form"].nombre.value= '    begin_pos:'+begin_pos+'    i:'+i+'    j:'+j+'   '+eval(layerRef+'["'+layerName+'"]'+ styleSwitch+'.left="'+(i)+'"');
 if (NS4 || IE4)
 { 
  if(scroll_dir=="left")
  {
   if(i<(begin_pos+scroll_length))
   {  
   	if (i<=0) { 
    	eval(layerRef+'["'+layerName+'"]'+ styleSwitch+'.left="'+(i)+'"');
    	i++;
    	j++;
	 }	
   }
  }
  if(scroll_dir=="right")
  {
   if(i>(begin_pos-scroll_length))
   {
  	 
    	eval(layerRef+'["'+layerName+'"]'+ styleSwitch+'.right="'+(-i)+'"');
    	i--;
    	j--;
	 
   }
  }  
  	if(i==j)
  	{	
   	setTimeout("Scroll('"+layerName+"')",time_length);  	
  }
 }
}
//STOP SCROLLING
function StopScroll(layerName,entra)
{
  if(scroll_dir=="right")
 {
 	j=j-1;
    eval(layerRef+'["'+layerName+'"]'+ styleSwitch+'.left="'+(i)+'"');
 }
 if(scroll_dir=="left")
 {
    j=j-1;
    eval(layerRef+'["'+layerName+'"]'+ styleSwitch+'.right="'+(-i)+'"');
 }
}
//////////// FIN DE CODIGO DE SCROLL ////////////
///////////////////////////////////////////////// 
////////////////////////////////////////////////////////////////////////////////////
// --------------------------- Browser Netscape? ------------------------------------
var NN = (navigator.appName=="Netscape" ? true : false);

// //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// ///////////////////////////////// FUNCIONES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// //////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// ------------------------- Para saber si un campo esta vacio ----------------------
function esVacio(campo){
if (campo.value=="")
      return true;
 else return false;
}
// ----------------------------------------------------------------------------------

// -------------------- Para obtener el valor de una select -------------------------
function valorLista(combo) {
  var indice = combo.selectedIndex;
  var valor = combo.options[indice].value;
  return valor;
}
// ----------------------------------------------------------------------------------
// -------------------- Para obtener el valor de un radioButton -------------------------
function valorRadio(radio) {
		// Si solo hay un radiobutton, se trata el campo como un input, y no como un array.
    if (isNaN(radio.length)){
			if (radio.checked)
				return (radio.value);
			else
				return "";
		}else{
			// Si hay varios radiobuttons, se busca el que está marcado.
			for (var i = 0; i < radio.length; i++) {
        if (radio[i].checked) {
            return (radio[i].value);
        }
			}
			return "";
    }
}
// ----------------------------------------------------------------------------------
// -------------------- Comprobacion de datos correctos para una fecha --------------
function fechaValida(anio,mes,dia){ 
  fTest = new Date(anio,mes-1,dia); 
  return ((fTest.getDate()==dia)? true : false);
}
// ----------------------------------------------------------------------------------


// --------------- Comprobacion de datos correctos para un número (enteros)----------
function numeroValido(pCaracter){
  for (var i=0;i<pCaracter.length;i++) {
    var sByte=pCaracter.substring(i,i+1);
    if (sByte<"0" || sByte>"9") return false;
  }
  return true;
}
// ----------------------------------------------------------------------------------


// ----------- Comprobacion de datos correctos para un número decimal ---------------
function numeroDecimalValido(pCaracter){
  var j = 0;
  var i = 0;
  var sByte = "";
  for (i=0;i<pCaracter.length;i++) {
    sByte=pCaracter.substring(i,i+1);
	if ((sByte<"0")|| (sByte>"9")) {
       if ((sByte==".") || (sByte==",")) {
         if (i==0) {
		 	return false;
		 }
         j = i+1;
         break;
       } else {
	   	 return false;
	   }
    }
  }
  for (j=j;j<pCaracter.length;j++) {
    sByte=pCaracter.charAt(j);
    if (sByte<'0' || sByte>'9') {
	   return false;
	}
  }
  return true;
}
// ----------------------------------------------------------------------------------
// ----------- Quita los espacios en blanco de la derecha de una cadena ---------------	
function rightTrim(strValue) {
	var objRegExp = /^([\w\W]*)(\b\s*)$/;
    if(objRegExp.test(strValue)) {
    	//remove trailing a whitespace characters
       	strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}
// ----------------------------------------------------------------------------------	
// ----------- Quita los espacion en blanco de la izquierda de una cadena ---------------	
function leftTrim(strValue) {
	var objRegExp = /^(\s*)(\b[\w\W]*)$/;
    if(objRegExp.test(strValue)) {
		//remove leading a whitespace characters
    	strValue = strValue.replace(objRegExp, '$2');
    }
	return strValue;
}
// ----------------------------------------------------------------------------------	
// ----------- Quita los espacion en blanco a la izquierda y a la derecha de una cadena ---------------	
function trim(str) {
	var resultStr = "";
	var objRegExp = /^(\s*)$/;
    //check for all spaces
    if(objRegExp.test(str)) {
    	str = str.replace(objRegExp, '');
       	if( str.length == 0)
	    	return str;
    }
	resultStr = leftTrim(str);
	resultStr = rightTrim(resultStr);
	return resultStr;
}

// -------------------------------------------------------------------------- //
// -- Selecciona en un objeto de formulario "select" el mes por su número  -- //
// -------------------------------------------------------------------------- //
function seleccionaMes(comboMes) {
	// Capturo la tecla pulsada
	var enterKey = event.keyCode - 48;
	// Si es un número entre 1 y 9
	if ((enterKey>0 && enterKey<10) || (enterKey>48 && enterKey<58)) {
		if (enterKey > 48) enterKey -= 48;
		// Selecciono el mes que corresponde al número
		var indice = comboMes.selectedIndex;
		if (enterKey == 1) {
			if (indice == 1) enterKey = 10;
			if (indice > 9 && indice < 12) enterKey = indice + 1;
			if (indice == 12) enterKey = 1;
		}
		comboMes.selectedIndex = enterKey;
	}
}

//                                    VALIDACIONES DE CAMPOS
// los siguientes métodos comprueban que se han informado los campos de texto, selects, radios, checks...
// Valida que está relleno un campo de texto
function validaInputText(campo){
	if(campo){
		var campoValue = campo.value;
		campoValue = trim(campoValue);
		if(campoValue != ""){
			return true;
		}
	}
	return false;
}
// igual que el anterior pero comprobando que no se tome como texto el texto inicial (si lo tuviera)
function validaInputText(campo, textoInicial){
	if(campo){
		var campoValue = campo.value;
		campoValue = trim(campoValue);
		if((campoValue != "") && (campoValue != textoInicial)){
			return true;
		}
	}
	return false;
}
// valida que está relleno un área de texto
function validaTextArea(campo){
	if(campo){
		var campoValue = campo.value;
		campoValue = trim(campoValue);
		if(campoValue != ""){
			return true;
		}
	}
	return false;
}
// valida que está relleno al menos una casilla de un checkbox
function validaCheck(campo){
	if(campo && campo.length >= 1){
		for(i = 0; i < campo.length; i++){
			if(campo[i].checked){
				return(true);
			}
		}
	}
	return false;
}
// valida que un radiobuton está seleccionado
function validaRadio(campo){
	if(campo && campo.length > 1){
		for(i=0; i<campo.length; i++){
			if(campo[i].checked){
				return true;
			}
		}
	}else{
		if(campo && campo.checked){
			return true;
		}
	}
	return false;
}
// valida que en una select (tanto normal como múltiple) está seleccionado alguna opción
function validaSelect(campo){
	if(campo){
		var campoValue = campo.value;
		campoValue = trim(campoValue);
		if(campoValue != ""){
			return true;
		}
	}
	return false;
}
// FIN      de       VALIDACIONES DE CAMPOS
// 
// ----------- Cambio dinámico propiedades de un td  ---------------
//
function cambiaTextoTD(idTD,nuevoTexto){
	document.getElementById(idTD).innerHTML = nuevoTexto;
}
// 
function cambiaClassTD(idTD,nuevoClass){
	if(document.getElementById(idTD)){
		document.getElementById(idTD).className = nuevoClass;
	}
}
// ------------ Métodos para la gestión de errores  ----------------
function muestraError(){
	muestraCapaError();
}
//
function marcaError(idTD){
	cambiaClassTD(idTD, 'td00_formulariosRed');
}
//
function desmarcaError(idTD){
	cambiaClassTD(idTD, 'td00_formularios');
}

function marcaError2(idTD){
	cambiaClassTD(idTD, 'lk_arial10_rojo');
}
//
function desmarcaError2(idTD){
	cambiaClassTD(idTD, '');
}

// ------------ Validación de dirección de e-mail -----------------
/**
 * Reference: Sandeep V. Tamhankar (stamhankar@hotmail.com),
 * http://javascript.internet.com
 */
function verificaMail (email){
	var expresion =  /^\w+([-_\.]\w+)*@\w+([-_\.]\w+)*(\.\w{2,6})+$/;
  return expresion.test(email);
}

// ------------ Validación de teléfono fijo/fax -----------------
function validaTelefonoFax(campo){
	// Puede ser Fijo o Fax
	var numTelefono = document.getElementById(campo).value;
	var uno = numTelefono.substring(0,1); 
	if(!numeroValido(numTelefono) || numTelefono.length != 9 || (uno != '9' && uno != '8')){
		return false;
	}else{
	  return true;
		/*
	  var prefijo = parseInt((numTelefono.substring(0,3)), 10); 
		if ((prefijo >= 910 && prefijo <= 939) ||
		    (prefijo >= 941 && prefijo <= 989) ||
		    (prefijo >= 810 && prefijo <= 899)) {
			return true;
		}else{		     
			return false;
		}
		*/
	}
}
// ------------ Validación de teléfono móvil -----------------
function validaTelefonoMovil(campo){
	// Puede ser Movil
	var numTelefono = document.getElementById(campo).value;
	var uno = numTelefono.substring(0,1); 
	if(!numeroValido(numTelefono) || numTelefono.length != 9 || (uno != '6' && uno != '7')){
		return false;
	}else{
		return true;
	}
}

// ------------ Validación de nombre y apellidos -----------------
function validaNombreApellido(campo, validoVacio){
	if (validaInputText(campo)) {
		var campoValue = campo.value;
		campoValue = trim(campoValue);
		// Longitud mínima = 2
		if(campoValue.length >= 2){
			return true;
		}
	}else{
		if (validoVacio){
			return true;
		}
	}
	return false;
}

function validarTarjetaResidente(documento) {
	var cadena="TRWAGMYFPDXBNJZSQVHLCKE";
	var vlongitudNif = documento.length;// Calculamos la longitud de la tarjeta
	var primeraletra = documento.substring(0, 1); //  Extraemos la primera letra
	var numero = documento.substring(1, vlongitudNif - 1); //  Extraemos el numero de la tarjeta
	var letra = documento.substring(vlongitudNif - 1, vlongitudNif); //  Extraemos la letra de la tarjeta

	//Validar longitud
	if (vlongitudNif != 9) {
		return false;
	}
	
	//Validar numero (distinguir entre si se tienen 9 o 10 digitos)
	if ((numero<0000000) || (numero>9999999)) {
		return false;
	}

	//Validar letra inicio
	if ((primeraletra.toUpperCase()!='X') && (primeraletra.toUpperCase()!='Y') && (primeraletra.toUpperCase()!='Z')) {
		return false;
	}

	//Validar letra fin
	
	// Si la letra es Y aniadimos un 1 delante del numero
	if (primeraletra.toUpperCase() =='Y')
		numero = '1' + numero; 
	// Si la letra es Z aniadimos un 2 delante del numero
	else if (primeraletra.toUpperCase() =='Z')
		numero = "2" + numero; 
		
	var posicion = numero % 23;
	var letraCalculada = cadena.charAt(posicion);


	if (letra.toUpperCase() != letraCalculada) {
		return false;
	}
	return true;
}


function validarPasaporte(documento) {
	var _documentoAux = documento;
	if (_documentoAux == '') {
		return false;
	} else {
		var primeraletra = _documentoAux.substring(0, 1);
		if ((_documentoAux.length < 9) || (primeraletra.toUpperCase() == 'X') || (primeraletra.toUpperCase() == 'Y') 
			 || (primeraletra.toUpperCase() == 'Z') ||(!numeroValido(_documentoAux.substring(8, 9)))) {
			return false;
		} else {
			return true;
		}
	}
}

// Validación de C.I.F.
function validarCIF(cif){
	var resul = false;
	var cifTemp = trim(cif.toUpperCase()); // pasamos a mayúsculas
	if(!/^[A-Za-z0-9]{9}$/.test(cifTemp)) {		// son 9 caracteres?
		resul = false;
	}else
	if(!/^[ABCDEFGHJNPQRSUVW]/.test(cifTemp)){ //  el primer carácter es una letra admitida?
		resul = false;
	}else{
		var v1 = new Array(0,2,4,6,8,1,3,5,7,9);
		var v2 = new Array('J','A','B','C','D','E','F','G','H','I'); // equivalencia entre digito de control y número
		var temp = 0;
		var temp1;
		var fc = cifTemp.substring(0,1); // primera letra del CIF
		var dc = cifTemp.substring(cifTemp.length-1); // dígito de control del CIF
		for(i=2;i<=6;i+=2){
			temp = temp + v1[parseInt(cifTemp.substr(i-1,1))];
			temp = temp + parseInt(cifTemp.substr(i,1));
		};
		temp = temp + v1[parseInt(cifTemp.substr(7,1))];
		temp = (10 - (temp % 10));
		if(temp == 10)
			temp = 0;
		
		if ( (dc == v2[temp]) || (dc == temp) ) {
			resul = true;
		} 
		else {
			resul = false;
		}
		/*
		// Comentado por modificación 11/05/2005 para que sea válido tanto letra como número en el dígito
		// de control en todo caso
		//
		// Si empieza por estas letras se permite que el dígito de control sea letra o numero
		if (fc == 'N' || fc == 'P' || fc == 'Q' || fc == 'R' || fc == 'S' || fc == 'W')
		{
			if ( (dc == v2[temp]) || (dc == temp) ) {
				resul = true;
			} 
			else {
				resul = false;
			}
		}
		// Sino, el dígito de control ha de ser numérico
		else
		{
			if (dc == temp) {
				resul = true;
			} 
			else {
				resul = false;
			}
		}*/		
	}
	return resul;
}

function validaNif(tipoDocumento, documento){
	documento = trim(documento);
	if(tipoDocumento == 'N'){
		// NIF
		if (documento.indexOf(" ") != -1 || documento.indexOf("-") != -1){
		  	return false; 
      	}	
		var cadena = 'TRWAGMYFPDXBNJZSQVHLCKET';//  Letras válidas para el NIF
		var longitudNif    = documento.length;
		if (longitudNif > 9){
			return false;
		}
		var numeroExtraido = documento.substring(0, longitudNif - 1);
		if (isNaN(parseInt(numeroExtraido))) {
			return false;
		}
		
	  	var letraExtraida  = documento.substring(longitudNif - 1, longitudNif);
		var posicion = numeroExtraido % 23;
		var letraCalculada = cadena.charAt(posicion);
		if(letraExtraida.toUpperCase() != letraCalculada){
			return false;
		}
	}else
	if(tipoDocumento == 'T'){
		// Tarjeta de Residente
		return validarTarjetaResidente(documento);
	}else
	if(tipoDocumento == 'P'){
        return validarPasaporte(documento);
	}else
	if(tipoDocumento == 'C'){
		return validarCIF(documento);
	}
    return true;
}
//  método que calcula la letra de un nif que se ha introducido en una caja de texto. 
// 	el mísmo método además vuelve a poner el número seguido de la letra correspondiente.
function calculaLetraNif(nombreCampo){
	var campo = document.getElementById(nombreCampo);
	var value = campo.value;
	if(!isNaN(value) && value != '' && value.length <= 8){
		var resto = value % 23;
		var cadena = 'TRWAGMYFPDXBNJZSQVHLCKE';
		var letra = cadena.charAt(resto);
		campo.value = value + letra;
	}
}
// ------------------------------ CAPA DE ERROR ------------------------------------
// funciones javascript para la aparicion de una capa flotante que muestra error. LDA
function muestraCapa(id, div){
	document.getElementById(id).innerHTML = div;
}
function muestraCapaError(){
	var textoError = 'Los campos que se han marcado en rojo no est\xe1n informados o no se admiten como correctos';
	if(arguments[0]){
		textoError = arguments[0];		
	}
	var idDiv = "capaError";
	var capaError = "<div id='subCapaError' style='position:absolute;'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td><div align='center'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='215' height='220'><param name='movie' value='/ZZRecursos/recursos/ES/animacion/error.swf?textoError="+textoError+"'><param name='quality' value='high'><embed src='/ZZRecursos/recursos/ES/animacion/error.swf?textoError="+textoError+"' quality='high' type='application/x-shockwave-flash' width='215' height='220'></embed></object></div></td></tr></table></div>";
	MM_showHideLayers('capaError','','show');
	muestraCapa(idDiv, capaError);
	positionit();
}
function muestraMensajes(titulo,mensaje,icono){
	var idDiv = "capaError";
	var capaError = "<div id='subCapaError' style='position:absolute;'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td><div align='center'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  width='538' height='356'><param name='movie' value='/ZZRecursos/recursos/ES/animacion/mensaje.swf?titulo="+titulo+"&mensaje="+mensaje+"&icono="+icono+"'><param name='quality' value='high'><embed src='/ZZRecursos/recursos/ES/animacion/mensaje.swf?titulo="+titulo+"&mensaje="+mensaje+"&icono="+icono+"' quality='high'  type='application/x-shockwave-flash' width='538' height='356'></embed></object></div></td></tr></table></div>";
	MM_showHideLayers('capaError','','show');
	muestraCapa(idDiv, capaError);
	positionit();
}

function recalculando(){
	var idDiv = "recalcular";
	var capaRecalculo = "<div id='subCapaError' style='position:absolute;'><table width='100%' height='100%' border='0' cellpadding='0' cellspacing='0'><tr><td><div align='center'><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'  width='200' height='200'><param name='movie' value='/ZZRecursos/recursos/ES/animacion/recalculando.swf'><param name='quality' value='high'><embed src='/ZZRecursos/recursos/ES/animacion/recalculando.swf' quality='high'  type='application/x-shockwave-flash' width='200' height='200'></embed></object></div></td></tr></table></div>";
	MM_showHideLayers('capaRecalculo ','','show');
	muestraCapa(idDiv, capaRecalculo );
	positionit();
}

function positionit(){
	var crossobj = "";
	if (document.all){
		crossobj =document.all.subCapaError;
	}else if (document.getElementById){
	
		crossobj =document.getElementById("subCapaError");
	} else {
	
		crossobj =document.subCapaError;
	}
	//define universal dsoc top point
	var dsoctop=document.all? document.body.scrollTop : pageYOffset
	//if the user is using IE 4+ or NS6+
	if (document.all||document.getElementById){
		if (document.body.scrollHeight < 400 && document.body.scrollHeight > 300) {
			crossobj.style.top=dsoctop+75;
		} else {
			if (document.body.scrollHeight <= 300) {
				crossobj.style.top=dsoctop+25;
			} else {
				crossobj.style.top=dsoctop+175;
			}
		}
	}
	//else if the user is using NS 4
	else if (document.layers){
	
		crossobj.top=dsoctop+175
	}
}
//setInterval("positionit()",200)
//positionit();
// Fin capa error.
// 
function diferenciaFechasEnDias(fechaDespues,fechaAntes) {
	var fechaD = new Date(fechaDespues.substring(0,4), fechaDespues.substring(5,7)-1, fechaDespues.substring(8));
    var fechaA = new Date(fechaAntes.substring(0,4), fechaAntes.substring(5,7)-1, fechaAntes.substring(8));
    var diferencia = fechaD.getTime() - fechaA.getTime();
    if (diferencia == 0) 
		return 0;
	else{
      var diferenciaDias = Math.floor(diferencia/1000/60/60/24);
	  return diferenciaDias;
	}
}
// ------------------------------- Variable _entorno -----------------------------
var _entorno = (window.location.href).toLowerCase();
if (_entorno.indexOf("desarrollo") != -1) {
    _entorno = "D";
} else
    if (_entorno.indexOf("training") != -1) {
        _entorno = "T";
    } else _entorno = "P";
// --------------------imprimir página------------------------------------
function imprimir() {
  if (window.print) {
    window.print();
  }
}
function irACotizacionCoches() {
	var x = screen.width;
	var y = screen.height;
	if (x>799) {
		x = screen.width-10;
		y = screen.height-80;
	}
	var _properties = new String("width="+x+",height="+y+",scrollbars=yes,menubar=visible,statusbar=yes,status=yes,location=no,toolbar=no,history=no,resizable=yes,screenX=0,screenY=0,top=0,left=0");
	//
	if ((window.location.href.indexOf("nldamdes") != -1) || (window.location.href.indexOf("nldamtra") != -1) || (window.location.href.indexOf("www2.lineadirecta.es") != -1)) {
		var _cadenaEntorno = "https://www.lineadirecta.com";
		if (window.location.href.indexOf("nldamdes") != -1) {
			_cadenaEntorno = "https://www.desarrollo.lda";
		} else {
			if (window.location.href.indexOf("nldamtra") != -1) {
				_cadenaEntorno = "https://www.training.lda";
			}
		}
		window.open(_cadenaEntorno+'/ventas/ControlFlujo?idEstado=HOME&idTransicion=ldacoti', 'cotizacionCoches', _properties);
	} else {
		if (_entorno == "D") {
			window.open('https://www.desarrollo.lda/ventas/ControlFlujo?idEstado=HOME&idTransicion=ldacoti', 'cotizacionCoches', _properties);
		} else { 
			if (_entorno == "T") {
				window.open('https://www.training.lda/ventas/ControlFlujo?idEstado=HOME&idTransicion=ldacoti', 'cotizacionCoches', _properties);
			} else {
				window.open('https://www.lineadirecta.com/ventas/ControlFlujo?idEstado=HOME&idTransicion=ldacoti', 'cotizacionCoches', _properties);			
			}			
		}
	}
}
/* ir a cotización de motos*/

function irACotizacionMotos() {
	var x = screen.width;
	var y = screen.height;
	if (x>799) {
		x = screen.width-10;
		y = screen.height-80;
	}
	var _properties = new String("width="+x+",height="+y+",scrollbars=yes,menubar=visible,statusbar=yes,status=yes,location=yes,toolbar=yes,history=no,resizable=yes,screenX=0,screenY=0,top=0,left=0");
	//
	if ((window.location.href.indexOf("nldamdes") != -1) || (window.location.href.indexOf("nldamtra") != -1) || (window.location.href.indexOf("www2.lineadirecta.es") != -1)) {
		var _cadenaEntorno = "https://www.lineadirecta.com";
		if (window.location.href.indexOf("nldamdes") != -1) {
			_cadenaEntorno = "https://www.desarrollo.lda";
		} else {
			if (window.location.href.indexOf("nldamtra") != -1) {
				_cadenaEntorno = "https://www.training.lda";
			}
		}
		window.open(_cadenaEntorno+'/MOVE/LDA?idEstado=MOVEHOME&idTransicion=cotizar&idioma=ES', 'cotizacionMotos', _properties);
	} else {
		if (_entorno == "D") {
			window.open('https://www.desarrollo.lda/MOVE/LDA?idEstado=MOVEHOME&idTransicion=cotizar&idioma=ES', 'cotizacionMotos', _properties);
		} else { 
			if (_entorno == "T") {
				window.open('https://www.training.lda/MOVE/LDA?idEstado=MOVEHOME&idTransicion=cotizar&idioma=ES', 'cotizacionMotos', _properties);
			} else {
				window.open('https://www.lineadirecta.com/MOVE/LDA?idEstado=MOVEHOME&idTransicion=cotizar&idioma=ES', 'cotizacionMotos', _properties);			
			}			
		}
	} 
}



function irALunasChapas(codOpcion){
  var x       = screen.width;
  var y       = screen.height;
  if(x > 799) {
    x = screen.width - 10;
    y = screen.height - 80;
  }
  var _properties = new String("width=" + x + ",height=" + y + ",scrollbars=yes,menubar=visible,statusbar=yes,status=yes,location=no,toolbar=no,history=no,resizable=yes,screenX=0,screenY=0,top=0,left=0");
  window.open('/ventas/ControlFlujo?idEstado=pgZZLOGI53&amp;idTransicion=accesoAppl&codOpcion='+codOpcion,'cotizacionCoches',_properties);
}

function abrirVentana(_params){
  var x       = screen.width;
  var y       = screen.height;
  if(x > 799) {
    x = screen.width - 10;
    y = screen.height - 80;
  }
  var _properties = new String("width=" + x + ",height=" + y + ",scrollbars=yes,menubar=visible,statusbar=yes,status=yes,location=no,toolbar=no,history=no,resizable=yes,screenX=0,screenY=0,top=0,left=0");
  //
  window.open(_params,'cotizacionCoches',_properties);
}


