/**
 * @method acabarCargaPais
 * Asigna el pais 
 */
function acabarCargaPais()
{
    document.CarSearchForm.paisIn.value = document.CarSearchForm.paisOut.value
    //Primero borramos el anterior.
    for (i=0; i < document.CarSearchForm.localidadOut.length; i++)
    {
        document.CarSearchForm.localidadIn.options[i] = null;
    }       
    //Pintamos el combo.
    for (i=0; i < document.CarSearchForm.localidadOut.length; i++)
    {
        var texto = document.CarSearchForm.localidadOut[i].text
        var valor = document.CarSearchForm.localidadOut[i].value    
        document.CarSearchForm.localidadIn.options[i] = new Option(texto,valor);
    }
}

/**
 * @method cargaLocalidades
 * @param {Object} key
 * @param {Object} tipo
 * @param {Object} pais
 * @param {Object} cual
 * Envía la peticion para obtener las localidades y cargarlos en los combos. 
 */
function cargaLocalidades(key,tipo,pais,cual)
{
    document.cochesCombos.key.value = key;
    document.cochesCombos.tipo.value = tipo;
    document.cochesCombos.pais.value = pais;
    document.cochesCombos.cual.value = cual;
    document.cochesCombos.target = "frameCarga";
    document.cochesCombos.submit();
    muestraCapaCargando();
}

/**
 * @method acabarCargaLocalidadRegreso
 */
function acabarCargaLocalidadRegreso()
{
    //Pintamos el combo.
    for (i=0; i<document.CarSearchForm.stationOut.length; i++){
        var texto = document.CarSearchForm.stationOut[i].text
        var valor = document.CarSearchForm.stationOut[i].value
    }
}

/**
 * @method muestraCapaCargando
 * Muestra el gif animado de espera mientras se cargan los combos de la home.
 */ 
function muestraCapaCargando(){
    var capaCargando = document.getElementById("capaCargando");
    var IfrCarga = document.getElementById('DivCarga');
    IfrCarga.style.width    = capaCargando.offsetWidth;
    IfrCarga.style.height   = capaCargando.offsetHeight;
    IfrCarga.style.top      = capaCargando.style.top;
    IfrCarga.style.left     = capaCargando.style.left;
    IfrCarga.style.zIndex   = capaCargando.style.zIndex - 1;
    IfrCarga.style.display  = "block";
    document.getElementById("capaCargando").style.display="block";
    document.getElementById("capaCargando").style.visibility="visible";
}

/**
 * @method ocultaCapaCargando
 * Oculta el gif animado que se muestra mientras se cargan los combos.
 */
function ocultaCapaCargando()
{
    document.getElementById("capaCargando").style.visibility="hidden";
    var IfrCarga = document.getElementById('DivCarga');
    IfrCarga.style.display  = "none";
}

/**
 * @method acabarCargaPais
 * Asigna el pais 
 */
function acabarCargaPais()
{
	document.CarSearchForm.paisIn.value = document.CarSearchForm.paisOut.value
	//Primero borramos el anterior.
	for (i=0; i < document.CarSearchForm.localidadOut.length; i++)
	{
		document.CarSearchForm.localidadIn.options[i] = null;
	}		
	//Pintamos el combo.
	for (i=0; i < document.CarSearchForm.localidadOut.length; i++)
	{
		var texto = document.CarSearchForm.localidadOut[i].text
		var valor = document.CarSearchForm.localidadOut[i].value	
		document.CarSearchForm.localidadIn.options[i] = new Option(texto,valor);
	}
}

/**
 * @method acabarCargaLocalidad
 */
function acabarCargaLocalidad()
{
	document.CarSearchForm.localidadIn.value = document.CarSearchForm.localidadOut.value
	//Primero borramos
	for (i=0; i<document.CarSearchForm.stationOut.length; i++)
	{
		document.CarSearchForm.stationIn.options[i] = null;
	}
	//Pintamos el combo.
	for (i=0; i<document.CarSearchForm.stationOut.length; i++)
	{
		var texto = document.CarSearchForm.stationOut[i].text
		var valor = document.CarSearchForm.stationOut[i].value
		document.CarSearchForm.stationIn.options[i] = new Option(texto,valor);
	}
}

/**
 * @method borraLocalidadesOut
 */
function borraLocalidadesOut(){	
	for (var x=document.CarSearchForm.localidadOut.length-1;x>0;x--){
		document.CarSearchForm.localidadOut.options[x] = null;
	}		
}

/**
 * @method borraLocalidadesIn
 */
function borraLocalidadesIn(){
	for (var x=document.CarSearchForm.localidadIn.length-1;x>0;x--){
		document.CarSearchForm.localidadIn.options[x] = null;
	}
}

/**
 * @method borraStationsOut
 */
function borraStationsOut(){
	for (var x=document.CarSearchForm.stationOut.length-1;x>0;x--){
		document.CarSearchForm.stationOut.options[x] = null;
	}
}

/**
 * @method borraStationsIn
 */
function borraStationsIn(){
    for (var x = document.CarSearchForm.stationIn.length - 1; x > 0; x--) {
		document.CarSearchForm.stationIn.options[x] = null;
	}
}

/**
 * @method cargaSucursal 
 * @param {Object} valor
 * Carga por defecto en el combo de sucursal de devolucion, la misma
 * que hay en la sucursal de recogida en caso de que sea la misma localidad.
 */
function cargaSucursal(valor){
	//Miramos si las localidades son iguales.
	if (document.CarSearchForm.localidadIn.value == document.CarSearchForm.localidadOut.value) {
		document.CarSearchForm.stationIn.value = valor;
	}
}