﻿
function SeleccionaAnioVehiculo( anio )
{
	oDate = new Date();
	if( oDate.getFullYear() == anio )
	{
		document.getElementById("divCeroKM").style.display = 'inline' ;
	}
	else
	{
		document.getElementById("divCeroKM").style.display = 'none' ;
	}
	
}

function SeleccionaTipoCombustible( tipoCombustible )
{
	if( tipoCombustible == "GNC" )
	{
		document.getElementById("divValorGNC").style.display = 'inline' ;
	}
	else
	{
		document.getElementById("divValorGNC").style.display = 'none' ;
	}
	
}

function evaluaGetLocalidades( resultado )
{
	var i = document.getElementById("cmbLocalidades").options.length ;
	for ( x in resultado )
	{
		document.getElementById("cmbLocalidades").options[i] = new Option( resultado[x][1],resultado[x][0],false) ;
		i++ ;
	}	

	document.getElementById("cmbProvincias").disabled = "" ;
	document.getElementById("divLocalidades").innerHTML = '' ;
}

function GetMascasxTipoVehiculo( idTipoVehiculo )
{
	LimpiarCombo( "cmbMarcas" , new Option("--Seleccione--","",true) ) ;
	LimpiarCombo( "cmbModelos" , new Option("--Seleccione--","",true) ) ;
	LimpiarCombo( "cmbAnios" , new Option("--Seleccione--","",true) ) ;

	if( idTipoVehiculo != 0 )
	{
	
		document.getElementById("cmbTiposVehiculo").disabled = "true" ;
		document.getElementById("divMarcas").innerHTML += '<img src="images/procesando.gif" width="16" height="16">' ;
	
		xajax_GetMascasxTipoVehiculo( idTipoVehiculo );
	}
}

function evaluaGetMascasxTipoVehiculo( resultado )
{
	var i = document.getElementById("cmbMarcas").options.length ;
	for ( x in resultado )
	{
		document.getElementById("cmbMarcas").options[i] = new Option( resultado[x][1],resultado[x][0],false) ;
		i++ ;
	}	

	document.getElementById("cmbTiposVehiculo").disabled = "" ;
	document.getElementById("divMarcas").innerHTML = '' ;
}

function GetModelos( )
{
	var idTipoVehiculo = document.getElementById("cmbTiposVehiculo").value ;
	var idMarca = document.getElementById("cmbMarcas").value ;
	
	LimpiarCombo( "cmbModelos" , new Option("--Seleccione--","",true) ) ;
	LimpiarCombo( "cmbAnios" , new Option("--Seleccione--","",true) ) ;
	
	
	if( idTipoVehiculo != 0  && idMarca != 0 )
	{
	
		document.getElementById("cmbMarcas").disabled = "true" ;
		document.getElementById("divModelos").innerHTML += '<img src="images/procesando.gif" width="16" height="16">' ;
	
		xajax_GetModelos( idTipoVehiculo , idMarca );
	}

}

function evaluaGetModelos( resultado )
{
	var i = document.getElementById("cmbModelos").options.length ;
	for ( x in resultado )
	{
		document.getElementById("cmbModelos").options[i] = new Option( resultado[x][1],resultado[x][0],false) ;
		i++ ;
	}	

	document.getElementById("cmbMarcas").disabled = "" ;
	document.getElementById("divModelos").innerHTML = '' ;
}


function GetAniosModelo( idModelo )
{
	
	LimpiarCombo( "cmbAnios" , new Option("--Seleccione--","",true) ) ;
	
	if( idModelo != 0 )
	{
	
		document.getElementById("cmbModelos").disabled = "true" ;
		document.getElementById("divAnios").innerHTML += '<img src="images/procesando.gif" width="16" height="16">' ;
	
		xajax_GetAniosModelo( idModelo );
	}

}

function evaluaGetAniosModelo( resultado )
{
	var i = document.getElementById("cmbAnios").options.length ;
	for ( x in resultado )
	{
		document.getElementById("cmbAnios").options[i] = new Option( resultado[x][1],resultado[x][0],false) ;
		i++ ;
	}	

	document.getElementById("cmbModelos").disabled = "" ;
	document.getElementById("divAnios").innerHTML = '' ;
}


function CotizarAuto(  )
{
	
	document.getElementById("divBtn").innerHTML = '<img src="images/loading.gif" width="86" height="19" border="0">' ;
	
	xajax_CotizarAuto(xajax.getFormValues('frmCotizarAuto'));
}

function evaluaCotizarAuto( resultado )
{
	if( resultado != "" )
	{
		Sexy.error('<h1>Error: </h1>'+resultado ) ;		
		document.getElementById("divBtn").innerHTML = '<a  onclick="CotizarAuto()" ><img  src="images/btn/btn_enviar.jpg" width="86" height="19" border="0"></a>' ;
	}
	else
	{
		window.location = "seguro-auto-gracias.php" ;
	}
	
}