var formulario;
var onload;

// FUNCION QUE VALIDA LOS CAMPOS OBLIGATORIOS ANTES DE REALIZAR EL SUBMIT
function enviar()
{
	document.forms[0].h1c034.disabled = false;
 	document.forms[0].h1c132.disabled = false;
 	document.forms[0].h1c043.disabled = false;
 	document.forms[0].h1c134.disabled = false;
		 	
	habilitarCampo();
    document.forms[0].submit();
}

function onLoadEnBody(esPlataforma){
	
	onload = true;
	formulario = document.forms[0];
	
	if(esPlataforma == 'true'){
		setTimeout("window.focus(); alert('Su sesión va a expirar.\\nPor favor, grabe el documento para no perder los cambios.')", 1200000);
	}
	
	autocompletarMunicipioVuelta('h1c016',formulario.h1c017[formulario.h1c017.selectedIndex].text);
	autocompletarMunicipioVuelta('h1c029',formulario.h1c030[formulario.h1c030.selectedIndex].text);
	autocompletarMunicipioVuelta('h1c042',formulario.h1c043[formulario.h1c043.selectedIndex].text);
	
	controlBloqueoPresentador();
	
	onload = false;
}

// FUNCION QUE CAMBIA EL ESTADO DE LA VARIABLE correcto a ERRONEO
function cambiarEstado ()
{
	document.forms[0].estado.value = 'validacion';
}

/*
FUNCION QUE REALIZA CAMBIOS DIN?MICOS EN EL SELECT DE EMBARCACIONES.
*/

function cambiarContenidoSelect (selectCtrl,seleccion)
{
	var i, j;
	var k = seleccion.selectedIndex;
	for (i = selectCtrl.options.length; i >= 0; i--)
	{
		selectCtrl.options[i] = null;
	}
	var array;
	if ( k == 2 )
	{
		array = embarcacionVela;
		for (i = 0; i < array.length; i++)
			selectCtrl.options[i] = new Option(array[i]);
	}
	else
		if ( k == 1)
		{
			array = embarcacionMotor;
			for (i = 0; i < array.length; i++) {
			selectCtrl.options[i] = new Option(array[i]);
		}
	}
}

function longitudMatricula (matricula,tipo)
{
	if (( matricula.length) <  6 )
	{
//		arrayErrores [i] = "La matr?cula de "+ tipo +" debe tener una longitud m?nima de 6 caracteres";
//		i++;
//		error = true;
		// alert ( "La matr?cula de "+ tipo +" debe tener una longitud m?nima de 6 caracteres");
	}
}
// FUNCION QUE ENLAZA DE FORMA DIN?MICA UN ANCLA DE UNA VENTANA EN OTRA.
/**
function irA(ancla)
{
  document.location.hash=ancla ;
}
*/


/*
 * Función que devuelve la primera palabra de una cadena
 */
function primeraPalabra(cadena) {

  var array = cadena.split(" ");
 
  return array[0];
}



/*
 * Función que devuelve el año de la fecha de primera matriculación del vehículo
 */
function dameAnyoPrimeraMatriculacion(){
	
	var fechaPM = $('h1c066_1').value;

	if(fechaPM != ""){
		return fechaPM.substring(fechaPM.length-4);
	}else{
		return "";
	}
	
}

/*
 * Función que devuelve "D" si el motor es Diesel y "G" si es Gasolina
 * 
 * 
 */
function dameTipoMotor(){
	
	var tipMot = $('h1c049').value;
	
	if(tipMot=="DIESEL")
		return "D";
	else if(tipMot=="GASOLINA")
		return "G";
	else
		return "";
}

 
//Transforma las imagenes de borrar formulario y la de enviar por imagenes blancas
function quitarImagenes(){
	//parent.arriba.document.enviar.width = '0';
}
<!-- FUNCI?N QUE LIMITA EL TAMA?O DE CARACTERES DE ENTRADA DE UN TEXTAREA -->

function cambiarEstadoEnviar(){
	document.forms[0].estado.value='validacion';
}

function cargarDatosMatriculacionVehiculo(campoMatricula , nifVendedor, claveCaptcha)
{
	$('indicadorVehiculo').style.visibility="visible";
	$('mensajeErrorModelo').style.visibility="hidden";
	
	if(claveCaptcha != ""){
		if(campoMatricula != ""){
			if(tieneEspaciosEnBlanco(campoMatricula) == false){
				if(nifVendedor != ""){
					ProxyDWR.invocarPorReflexion('dgt.AjaxDGT.devolverDatosMatriculacion', [campoMatricula, nifVendedor.toUpperCase(), claveCaptcha], function(data) {
						if (data!=null) { // Si devuelve datos
							if (data.matriculaIncorrecta)
							{
								// Mensaje matricula incorrecta
								$('mensajeErrorVehiculo').innerHTML="La matrícula introducida no es correcta.";
								$('mensajeErrorVehiculo').style.visibility="visible";
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').value = "";
								}
							}
							else if (data.matriculaInexistente)
							{
								// Mensaje matricula inexistente
								$('mensajeErrorVehiculo').innerHTML="Matrícula inexistente."
								$('mensajeErrorVehiculo').style.visibility="visible";
								limpiarDatosVehiculo();
								protegerCamposVehiculo(false);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').value = "";
								}
							}
							else if (data.errorConexion)
							{
								$('mensajeErrorVehiculo').innerHTML="No ha sido posible obtener los datos automáticamente, por favor, insértelos manualmente."
								$('mensajeErrorVehiculo').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(false);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').removeAttribute("readonly");
									$('claveCaptcha').readOnly = true;
								}
							}
							else if (data.nifNoCorrespondiente)
							{
								$('mensajeErrorVehiculo').innerHTML="El nif " + nifVendedor.toUpperCase() + " del vendedor/a o transmitente no coincide con el propietario del vehículo."
								$('mensajeErrorVehiculo').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									recargaImagenCaptcha(data.captchaId);
								}
							}
							else if (data.errorToken)
							{
								$('mensajeErrorVehiculo').innerHTML="Número máximo de intentos excedido.<br/> Por motivos de seguridad, por favor, pulse el botón [limpiar] para recargar el formulario."
								$('mensajeErrorVehiculo').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').removeAttribute("readonly");
									$('claveCaptcha').readOnly = true;
								}
							}
							else if (data.errorValidCaptcha)
							{
								$('mensajeErrorVehiculo').innerHTML="No ha sido posible verificar el código de la imagen.<br/> Por motivos de seguridad, por favor, pulse el botón [limpiar] para recargar el formulario."
								$('mensajeErrorVehiculo').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').removeAttribute("readonly");
									$('claveCaptcha').readOnly = true;
								}
							}
							else if (data.errorCaptcha)
							{
								$('mensajeErrorVehiculo').innerHTML="El código de la imagen introducido no coincide con el texto de la imagen. Por favor, inténtelo de nuevo con un nuevo código."
								$('mensajeErrorVehiculo').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								if (claveCaptcha != 'null'){
									recargaImagenCaptcha(data.captchaId);
								}
							}
							else if (data.activarCaptcha)
							{
								//Desproteger todos los campos
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								//CAPTCHA
								//if (claveCaptcha != 'null'){
									//recargaImagenCaptcha(data.captchaId);
								//}
								document.getElementById('captcha').style.display = '';
								document.getElementById('captchaEnlace').style.display = '';
								document.getElementById('enlaceSinCaptcha').style.display = 'none';
								$('mensajeErrorVehiculo').innerHTML="Por motivos de seguridad debe consignar el campo de texto asociado a la imagen.";
								$('mensajeErrorVehiculo').style.visibility="visible";
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								$('indicadorVehiculo').style.visibility="hidden";

								
							}
							else // Si no hay error
							{	
								$('mensajeErrorVehiculo').innerHTML="";
								$('mensajeErrorVehiculo').style.visibility="hidden";
								limpiarDatosVehiculo();
								protegerCamposVehiculo(true);
								
								// Cargamos los datos en los campos
								$('h1c045_1').value=data.tipoVehiculo;
								$('h1c049').value=data.tipoMotor;
								$('h1c046_1').value=data.marca;
								$('h1c047_1').value=data.modelo;
								$('h1c052_1').value=data.bastidor;
								$('h1c066_1').value=data.fechaMatriculacion;
								$('h1c051_1').value=data.cilindrada;
								$('h1c048_1').value=data.potencia;
								
								cargarFiltroVehiculo();						
																					
								//Comprobar si se ha seleccionado una opción
								if ($('h1c045_1').selectedIndex==0) // Combo tipo vehículo
									$('h1c045_1').readonly=false;
								
								if ($('h1c049').selectedIndex==0) // Combo tipo motor
									$('h1c049').readonly=false;
	
								if ($('h1c046_1').selectedIndex==0) // Combo marca
									$('h1c046_1').readonly=false;
					
								//Campos a deshabilitar seguro
								$('h1c047_1').readonly=false;		// modelo
								$('h1c065_1').readonly=false;		// año fabricación
								//CAPTCHA
								if (claveCaptcha != 'null'){
									$('claveCaptcha').removeAttribute("readonly");
									$('claveCaptcha').readOnly = true;
								}
								$('mensajeErrorModelo').innerHTML="Modelo orientativo, por favor seleccione uno de la lista pulsando el icono 'Desplegar'.";
								$('mensajeErrorModelo').style.visibility="visible";
							
							}
						}
					
						$('indicadorVehiculo').style.visibility="hidden";	
					});
				}else{
					// El nif del vendedor es nulo
					$('mensajeErrorVehiculo').innerHTML="Debe consignar el nif del Vendedor/a o Transmitente para realizar esta búsqueda.";
					$('mensajeErrorVehiculo').style.visibility="visible";
					limpiarDatosVehiculo();
					protegerCamposVehiculo(true);
					$('indicadorVehiculo').style.visibility="hidden";	
					//CAPTCHA
					if (claveCaptcha != 'null'){
						$('claveCaptcha').value=claveCaptcha;
					}
				}
			}else{
				// La matricula tiene espacios en blanco
				$('mensajeErrorVehiculo').innerHTML="La Matricula no debe contener espacios en blanco.";
				$('mensajeErrorVehiculo').style.visibility="visible";
				limpiarDatosVehiculo();
				protegerCamposVehiculo(true);
				$('indicadorVehiculo').style.visibility="hidden";
				//CAPTCHA
				if (claveCaptcha != 'null'){
					$('claveCaptcha').value=claveCaptcha;
				}
			}	
		}else{
			// La matricula es nula
				$('mensajeErrorVehiculo').innerHTML="Debe consignar la matrícula del vehículo para realizar esta búsqueda.";
				$('mensajeErrorVehiculo').style.visibility="visible";
				limpiarDatosVehiculo();
				protegerCamposVehiculo(true);
				$('indicadorVehiculo').style.visibility="hidden";	
		}
	}else{
		//La claveCaptcha es nula
		$('mensajeErrorVehiculo').innerHTML="Debe consignar el campo de texto asociado a la imagen para realizar esta búsqueda.";
		$('mensajeErrorVehiculo').style.visibility="visible";
		limpiarDatosVehiculo();
		protegerCamposVehiculo(true);
		$('indicadorVehiculo').style.visibility="hidden";
	}
	
}

function limpiarDatosVehiculo()
{
	$('h1c045_1').setAttribute("selectedIndex","0");
	$('h1c049').setAttribute("selectedIndex","0");	
	$('h1c046_1').setAttribute("selectedIndex","0");	
	
	$('h1c047_1').value="";
	$('h1c065_1').value=""; // año fabricación
	$('h1c052_1').value="";
	$('h1c066_1').value="";
	$('h1c051_1').value="";
	$('h1c048_1').value="";
}

function protegerCamposVehiculo(proteger)
{	
	if (proteger==true){
		$('h1c049').setAttribute("disabled","disabled");
		$('h1c046_1').setAttribute("disabled","disabled");
		
	}else{
		$('h1c045_1').removeAttribute("readonly");
		$('h1c045_1').readOnly = false;
		$('h1c047_1').removeAttribute("readonly");
		$('h1c047_1').readOnly = false;
		$('h1c065_1').removeAttribute("readonly");
		$('h1c065_1').readOnly = false;
		$('h1c052_1').removeAttribute("readonly");
		$('h1c052_1').readOnly = false;		
		$('h1c051_1').removeAttribute("readonly");
		$('h1c051_1').readOnly = false;
		$('h1c048_1').removeAttribute("readonly");
		$('h1c048_1').readOnly = false;
		habilitarCampo()
	}
}


function cargarDatosMatriculacionMotocicleta(campoMatricula, nifVendedor, tokenTrafico)
{
	$('indicadorMotocicleta').style.visibility="visible";
	if(tokenTrafico != ""){
		if(campoMatricula != ""){ 
			if(tieneEspaciosEnBlanco(campoMatricula) == false){
				if(nifVendedor != ""){
					ProxyDWR.invocarPorReflexion('dgt.AjaxDGT.devolverDatosMatriculacionMotocicletas', [campoMatricula, nifVendedor.toUpperCase(), tokenTrafico], function(data) {
						if (data!=null) {
							if (data.matriculaIncorrecta){
								// Mensaje matricula incorrecta
								$('mensajeErrorMotocicleta').innerHTML="La matrícula introducida no es correcta.";
								$('mensajeErrorMotocicleta').style.visibility="visible";
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(true);
							}	else if (data.matriculaInexistente)	{
								// Mensaje matricula inexistente
								$('mensajeErrorMotocicleta').innerHTML="Matrícula inexistente."
								$('mensajeErrorMotocicleta').style.visibility="visible";
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(false);
							} else if (data.errorConexion) {
								$('mensajeErrorMotocicleta').innerHTML="No ha sido posible obtener los datos automáticamente, por favor, insértelos manualmente."
								$('mensajeErrorMotocicleta').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(false);
							}
							else if (data.nifNoCorrespondiente)
							{
								$('mensajeErrorMotocicleta').innerHTML="El nif " + nifVendedor.toUpperCase() + " del vendedor/a o transmitente no coincide con el propietario de la motocicleta."
								$('mensajeErrorMotocicleta').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(true);
							}
							else if (data.errorToken)
							{
								$('mensajeErrorMotocicleta').innerHTML="Número máximo de intentos excedido.<br/> Por motivos de seguridad, por favor, pulse el botón [limpiar] para recargar el formulario."
								$('mensajeErrorMotocicleta').style.visibility="visible";
								//Desproteger todos los campos
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(true);
							}
							else // Si no hay error
							{	
								
								$('mensajeErrorMotocicleta').innerHTML="";
								$('mensajeErrorMotocicleta').style.visibility="hidden";
								limpiarDatosMotocicleta();
								protegerCamposMotocicleta(true);
								
								// Cargamos los datos en los campos			
								if (data.cilindrada>50)
									$('h1c045_2').value="MOTOCICLETA";
								else
									$('h1c045_2').value="SCOOTER";								
									
								$('h1c051_2').value=data.cilindrada;		
								$('h1c046_2').value=data.marca;
								$('h1c052_2').value=data.bastidor;
								$('h1c047_2').value=data.modelo;
								$('h1c066_2').value=data.fechaMatriculacion;
								$('h1c048_2').value=data.potencia;						
									
								//Campos a deshabilitar seguro
								$('h1c065_2').readonly=false;		// tipo de motor		
							//Campos a deshabilitar seguro
								$('h1c047_1').readonly=false;		// modelo
								$('h1c065_1').readonly=false;		// año fabricación	
							}		
						}	
						$('indicadorMotocicleta').style.visibility="hidden";	
					});
				}else{
					// El nif del vendedor es nulo
					$('mensajeErrorMotocicleta').innerHTML="Debe consignar el nif del Vendedor/a o Transmitente para realizar esta búsqueda.";
					$('mensajeErrorMotocicleta').style.visibility="visible";
					limpiarDatosMotocicleta();
					protegerCamposMotocicleta(true);
					$('indicadorMotocicleta').style.visibility="hidden";
				}
			}else{
				// La matricula tiene espacios en blanco
				$('mensajeErrorMotocicleta').innerHTML="La Matricula no debe contener espacios en blanco.";
				$('mensajeErrorMotocicleta').style.visibility="visible";
				limpiarDatosMotocicleta();
				protegerCamposMotocicleta(true);
				$('indicadorMotocicleta').style.visibility="hidden";	
			}	
		}else{
			// La matricula es nula
				$('mensajeErrorMotocicleta').innerHTML="Debe consignar la matrícula de la motocicleta para realizar esta búsqueda.";
				$('mensajeErrorMotocicleta').style.visibility="visible";
				limpiarDatosMotocicleta();
				protegerCamposMotocicleta(true);
				$('indicadorMotocicleta').style.visibility="hidden";	
		}
	}else{
		// El token de session es nulo
			$('mensajeErrorMotocicleta').innerHTML="Por motivos de seguridad, por favor, pulse el botón [limpiar] para recargar los datos del formulario.";
			$('mensajeErrorMotocicleta').style.visibility="visible";
			limpiarDatosMotocicleta();
			protegerCamposMotocicleta(true);
			$('indicadorMotocicleta').style.visibility="hidden";	
	}
}

function limpiarDatosMotocicleta()
{
	$('h1c045_2').setAttribute("selectedIndex","0");	
	$('h1c051_2').value="";
	$('h1c046_2').value="";
	$('h1c052_2').value="";	
	$('h1c047_2').value="";
	$('h1c065_2').value=""; // año fabricación
	$('h1c066_2').value="";
	$('h1c048_2').value="";
}

function protegerCamposMotocicleta(proteger)
{	
	if (proteger==true){
		proteger="readonly";		
	}else{
	$('h1c045_2').removeAttribute("readonly");
	$('h1c045_2').readOnly = false;
	$('h1c051_2').removeAttribute("readonly");
	$('h1c051_2').readOnly = false;
	$('h1c046_2').removeAttribute("readonly");
	$('h1c046_2').readOnly = false;
	$('h1c052_2').removeAttribute("readonly");
	$('h1c052_2').readOnly = false;
	$('h1c047_2').removeAttribute("readonly");
	$('h1c047_2').readOnly = false;
	$('h1c065_2').removeAttribute("readonly");
	$('h1c065_2').readOnly = false;	
	$('h1c048_2').removeAttribute("readonly");
	$('h1c048_2').readOnly = false;
	}
}

function habilitarCampo(){
	$('h1c049').removeAttribute("disabled");
	$('h1c046_1').removeAttribute("disabled");
}

function actualizarCampoCaptcha(campo){
		document.formulario.claveCaptcha.value = campo.value;
}

function manejadorEventosMatricula(campo, event, tipo, nifVendedor, token) {
	
		
         var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
         if (keyCode == 13 || keyCode == 9) //Tecla Intro
         {
         	if (tipo=="Vehiculo")
         		cargarDatosMatriculacionVehiculo(campo.value,nifVendedor.value,token);
         	else
         		cargarDatosMatriculacionMotocicleta(campo.value,nifVendedor.value,token);
         
         }
         else {
         	if (tipo=="Vehiculo")         
			{
				limpiarDatosVehiculo();
	         	protegerCamposVehiculo(true);
			}
			else
			{
				limpiarDatosMotocicleta();
	         	protegerCamposMotocicleta(true);
			}         	
         }
}

/*
	Función que carga la base imponible en la casilla correspondiente utilizando Ajax.	
*/
function cargarBaseImponibleAjax(campoFechaDevengo){	
		
	if($('h1c002')){
		dwr.util.setValue('h1c071', "");  // Inicialmente lo vacío, por si hay erro no se quede el anterior
		ProxyDWR.invocarPorReflexion('modelos.modelo621.Modelo621Ajax.cargarBaseImponible', ['document.forms[0].h1c002.value', $('h1c002').value, $('h1c045_1').value, $('h1c049').value,$('h1c046_1').value,$('h1c047_1').value,$('h1c052_1').value,$('h1c065_1').value,$('h1c066_1').value,$('h1c067_1').value,$('h1c045_2').value,$('h1c046_2').value,$('h1c047_2').value,$('h1c051_2').value,$('h1c052_2').value,$('h1c065_2').value,$('h1c066_2').value,$('h1c067_2').value,$('h1c056').value,$('h1c053').value,$('h1c054').value,$('h1c058').value,$('h1c059').value,$('h1c065_3').value,$('h1c066_3').value,$('h1c067_3').value], function(data) {
			// Esto sólo se ejecuta si NO se lanza excepción, es decir, ej: si el DNI es correcto
			dwr.util.setValue('h1c071', data); 
			if (data == 0){
				$('mensajeErrorBaseImponible').innerHTML="No se ha podido calcular correctamente el valor de la base imponible, ya que existe algún error en el formulario.";
				$('mensajeErrorBaseImponible2').innerHTML="Pulse el boton -Enviar- y se le mostrará la lista de errores.";
				$('mensajeErrorBaseImponible').style.visibility="visible";	
				$('mensajeErrorBaseImponible2').style.visibility="visible";	
			} 
		});	
	}
	else{
		eval('document.forms[0].h1c071.value="0"');
	}		
}

function manejadorEventosBaseImponible(campo, event) {
	
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 13 || keyCode == 9) //Tecla Intro
    	cargarBaseImponibleAjax(campo.value);       	                  
}

function cargarComboMarcaEmbarcaciones()
{   
	if($('h1c056').value !=""){
		recargarCombos(['h1c053'], 'modelos.modelo621.Modelo621Ajax.cargarMarcaEmbarcaciones', [$('h1c056').value]);
	}
	else{
		limpiarSelect('h1c053');
	}
}  
/*
 * Funcion que cambia la marca de un vehiculo mercedes segun el tipo de vehiculo
 * */
function cambiarMarca(casTipoVeh, casMarca, casModelo){
	
	//Si viene la marca
	if($(casMarca).options.selectedIndex>-1){
		var tipoVeh = ($(casTipoVeh).options[$(casTipoVeh).options.selectedIndex].text).toUpperCase();
		var marca = ($(casMarca).options[$(casMarca).options.selectedIndex].text).toUpperCase();
		var modelo = ($(casModelo).value).toUpperCase();
		
		var seleccionar = "";
		if("MERCEDES"==(marca.match("MERCEDES")))	{
			
			//Si se selecciona TURISMO O TODOTERRENO y la marca es MERCEDES se pone MERCEDES
			if(tipoVeh=="TURISMO" || tipoVeh=="TODOTERRENO"){
				$(casMarca).value = "MERCEDES"
			}else if(tipoVeh=="COMERCIAL"){//Si se selecciona COMERCIAL y la marca es MERCEDES se pone MERCEDES BENZ
				$(casMarca).value = "MERCEDES-BENZ"
			}
			
		}
		
		if("GALLOPER"==(modelo.match("GALLOPER")) && "MITSUBISHI"==(marca.match("MITSUBISHI")))	{
			
			// GALLOPER en nuestra BBDD es la marca del vehiculo, para trafico es un modelo de la marca MITSUBISHI
			$(casMarca).value = "GALLOPER";
			
		}
	}
	
}  

function controlDivVehiculo(div){

	title = eval('document.forms[0].imagen'+div+'.title');
	
	if( title == "desplegar"){
		
		if($('h1c046_1').value != ""){
			desplegar(div);
			cargarFiltroVehiculo();
			$('mensajeErrorModelo').style.visibility="hidden";
		}
		else{
			alert("Debe consignar la matrícula del vehículo y obtener los datos automáticamente o seleccionar los datos del vehículo");
		}
	}else{
		plegar(div);
	}
}

function controlDivBarco(div){

	title = eval('document.forms[0].imagen'+div+'.title');
	
	if( title == "desplegar"){
		
		if($('h1c053').value != ""){
			desplegar(div);
			cargarDivBarco();
		}
		else{
			alert("Primero debe seleccionar la marca de la embarcación");
		}
	}else{
		plegar(div);		
	}
}

function plegar(div){
	
	document.getElementById(div).style.display="none";
	eval('document.imagen'+div+'.src="../../comun/images/desplegar.png"');
	eval('document.imagen'+div+'.alt="muestra los datos"');
	eval('document.imagen'+div+'.title="desplegar"');
}

function desplegar(div){
	
	document.getElementById(div).style.display="block"; 			
	eval('document.imagen'+div+'.src="../../comun/images/plegar.png"');
	eval('document.imagen'+div+'.alt="oculta los datos"');
	eval('document.imagen'+div+'.title="plegar"');
}


function copiarVehiculo(texto){
	 document.forms[0].h1c047_1.value = texto;
	 cambiarEstado();
 }
 
function copiarBarco(texto){
	 document.forms[0].h1c054.value = texto;
	 cambiarEstado();
 }
 
 function cargarFiltroVehiculo(){
 	
 	if($('h1c049').value == 'DIESEL'){
 		$('h1c047_1_3').value='D';
 	}
 	else{
 		$('h1c047_1_3').value='G';	
 	}
	$('h1c047_1_4').value=$('h1c051_1').value;
	$('h1c047_1_5').value=$('h1c048_1').value;
	
	$('h1c047_1_2').value=dameAnyoPrimeraMatriculacion();
	$('h1c047_1_1').value=primeraPalabra($('h1c047_1').value);
	
	cargarDivVehiculo();
	
}
 
 
 function cargarDivVehiculo(){
 	incluirFragmento('fragmentoParametrosVehiculo','/modelos/modelo621/modelosVehiculos.jsp?&marca='+$('h1c046_1').value+'&fechaDevengo='+$('h1c002').value+'&tipoVehiculo='+$('h1c045_1').value+'&tipoMotor='+$('h1c047_1_3').value+'&anyoMatricula='+$('h1c047_1_2').value+'&potencia='+$('h1c047_1_5').value+'&cilindrada='+$('h1c047_1_4').value+'&modelo='+$('h1c047_1_1').value);
 }
 
 function cargarDivBarco(){
 	incluirFragmento('Barco','/modelos/modelo621/modelosBarcos.jsp?&marca='+document.forms[0].h1c053.options[document.forms[0].h1c053.options.selectedIndex].text+'&fechaDevengo='+$('h1c002').value+'&tipoEmbarcacion='+$('h1c056').value);
 }
 
 function borrarCamposMotocicleta(){

	formulario.h1c045_2.selectedIndex = 0;
	limpiarDatosMotocicleta();

 	
 }
 
 function borrarCamposVehiculo(){
 	
 	formulario.h1c045_1.selectedIndex = 0;
	formulario.h1c049.selectedIndex = 0;
	formulario.h1c046_1.selectedIndex = 0;
	limpiarDatosVehiculo();
 	
 	
 }
 
 function controlBloqueoPresentador(){
	
	if (document.forms[0].h1c130.checked == true ){
		desBloquearPresentador();
		document.getElementById('DatosPresentador').style.display="none"; 
	}else {
		//desBloquearPresentador();
		recargaTipoNumeracionPresentador();
		document.getElementById('DatosPresentador').style.display="block"; 
	}
 }
 
 
 function bloquearPresentador(){

	 if(!onload){
	 	
	 	document.forms[0].h1c032_1.value = document.forms[0].h1c005_1.value;
	 	document.forms[0].h1c033_1.value = document.forms[0].h1c006_1.value;
	 	document.forms[0].h1c033_2.value = document.forms[0].h1c006_2.value;
	 	document.forms[0].h1c033_3.value = document.forms[0].h1c006_3.value;
	 	document.forms[0].h1c033_4.value = document.forms[0].h1c006_4.value;
	 	document.forms[0].h1c034.value = document.forms[0].h1c007.value;
	 	document.forms[0].h1c035.value = document.forms[0].h1c008.value;
	 	document.forms[0].h1c132.value = document.forms[0].h1c112.value;
	 	document.forms[0].h1c135.value = document.forms[0].h1c115.value;
	 	document.forms[0].h1c036.value = document.forms[0].h1c009.value;
	 	document.forms[0].h1c133.value = document.forms[0].h1c113.value;
	 	document.forms[0].h1c037.value = document.forms[0].h1c010.value;
	 	document.forms[0].h1c038.value = document.forms[0].h1c011.value;
	 	document.forms[0].h1c039.value = document.forms[0].h1c012.value;
	 	document.forms[0].h1c040.value = document.forms[0].h1c013.value;
	 	document.forms[0].h1c136.value = document.forms[0].h1c116.value;
	 	document.forms[0].h1c134.value = document.forms[0].h1c042.value;
	 	document.forms[0].h1c044.value = document.forms[0].h1c018.value;
	 	document.forms[0].h1c041.value = document.forms[0].h1c014.value;
	 	document.forms[0].h1c042.value = document.forms[0].h1c016.value;
	 	document.forms[0].h1c043.value = document.forms[0].h1c017.value;
	 	
	 	$('h1c134').options[0]=new Option($('h1c114')[$('h1c114').selectedIndex].value, $('h1c114')[$('h1c114').selectedIndex].text);
	 	
	 }

	 	document.forms[0].h1c032_1.readOnly = true;
	 	document.forms[0].h1c033_1.readOnly = true;
	 	document.forms[0].h1c033_2.readOnly = true;
	 	document.forms[0].h1c033_3.readOnly = true;
	 	document.forms[0].h1c033_4.readOnly = true;
	 	document.forms[0].h1c035.readOnly = true;
	 	document.forms[0].h1c036.readOnly = true;
	 	document.forms[0].h1c135.readOnly = true;
	 	document.forms[0].h1c037.readOnly = true;
	 	document.forms[0].h1c133.readOnly = true;
	 	document.forms[0].h1c038.readOnly = true;
	 	document.forms[0].h1c039.readOnly = true;
	 	document.forms[0].h1c040.readOnly = true;
	 	document.forms[0].h1c136.readOnly = true;
	 	document.forms[0].h1c042.readOnly = true;
	 	document.forms[0].h1c044.readOnly = true;
	 	document.forms[0].h1c041.readOnly = true;	 	
	 	
	 	document.forms[0].h1c034.disabled = true;
	 	document.forms[0].h1c132.disabled = true;
	 	document.forms[0].h1c043.disabled = true;
	 	document.forms[0].h1c134.disabled = true;
	 	
	 	document.forms[0].h1c032_1.style.background='#DDDDDD';
	 	document.forms[0].h1c033_1.style.background='#DDDDDD';
	 	document.forms[0].h1c033_2.style.background='#DDDDDD';
	 	document.forms[0].h1c033_3.style.background='#DDDDDD';
	 	document.forms[0].h1c033_4.style.background='#DDDDDD';
	 	document.forms[0].h1c034.style.background='#DDDDDD';
	 	document.forms[0].h1c035.style.background='#DDDDDD';
	 	document.forms[0].h1c132.style.background='#DDDDDD';
	 	document.forms[0].h1c036.style.background='#DDDDDD';
	 	document.forms[0].h1c135.style.background='#DDDDDD';
	 	document.forms[0].h1c037.style.background='#DDDDDD';
	 	document.forms[0].h1c133.style.background='#DDDDDD';
	 	document.forms[0].h1c038.style.background='#DDDDDD';
	 	document.forms[0].h1c039.style.background='#DDDDDD';
	 	document.forms[0].h1c040.style.background='#DDDDDD';
	 	document.forms[0].h1c136.style.background='#DDDDDD';
	 	document.forms[0].h1c042.style.background='#DDDDDD';
	 	document.forms[0].h1c134.style.background='#DDDDDD';
	 	document.forms[0].h1c044.style.background='#DDDDDD';
	 	document.forms[0].h1c041.style.background='#DDDDDD';
	 	document.forms[0].h1c043.style.background='#DDDDDD';

	 }
 	
 	 function recargaTipoNumeracionPresentador(){
		
		// Se selecciona la primera opción del combo de tipo de numeración
 		if ("" == document.forms[0].h1c132.value)
 		 document.forms[0].h1c132.selectedIndex = 0;
 	 }

	 function desBloquearPresentador(){
	 	
	 		document.forms[0].h1c032_1.value = "";
		 	document.forms[0].h1c033_1.value = "";
		 	document.forms[0].h1c033_2.value = "";
		 	document.forms[0].h1c033_3.value = "";
		 	document.forms[0].h1c033_4.value = "";
		 	document.forms[0].h1c034.value = "";
		 	document.forms[0].h1c035.value = "";		 	
		 	document.forms[0].h1c132.value = "";
		 	document.forms[0].h1c135.value = "";
		 	document.forms[0].h1c036.value = "";
		 	document.forms[0].h1c133.value = "";
		 	document.forms[0].h1c037.value = "";
		 	document.forms[0].h1c038.value = "";
		 	document.forms[0].h1c039.value = "";
		 	document.forms[0].h1c040.value = "";
		 	document.forms[0].h1c136.value = "";
		 	document.forms[0].h1c134.value = "";
		 	document.forms[0].h1c044.value = "";
		 	document.forms[0].h1c041.value = "";
		 	document.forms[0].h1c042.value = "";
		 	document.forms[0].h1c043.value = "";
	 	
	 }
function cambiarDesglose(nombreDIV,nombreA){
	if($(nombreA).innerHTML=="(detalle del cálculo)"){	
		$(nombreA).innerHTML="(ocultar)"
		mostrarDesglose(nombreDIV);
	}else{
		$(nombreA).innerHTML="(detalle del cálculo)"
		ocultarDesglose(nombreDIV);
	}

}

function mostrarDesglose(nombreDIV){
	
	$(nombreDIV).style.visibility = "visible";
	$(nombreDIV).style.display = "block";
	
	
}

function ocultarDesglose(nombreDIV){

	$(nombreDIV).style.visibility = "hidden";
	$(nombreDIV).style.display = "none";
	
}

function tieneEspaciosEnBlanco(cadena) { 
	for (var i=0; i < cadena.length; i++) 
	{
		if ((cadena.charAt(i) == ' ')){
			return true; 
		}
	}
	return false;
}
