﻿/**************************************************************

result.php by Milfson (milf@milfcz.com) 17.04.2004

Milfson added preselect(parameters...) to pre-populate dropdowns with default values.

Thanks for the code! - Brent.

***************************************************************/

//alert ("Carga fichero");

// constants

var noValue = '-99';
// default values
var IDComarca = noValue;
var IDProvincia = noValue;
var IDLocalidad = noValue;
var IDTipoAlojamiento = noValue;
var IDIdioma = noValue;


//selects disabled true/false

var boolEnabled = true;



// globals

var curOption = new Array();

var isLoaded = new Array();



//Lo llama gestion/tablas.php

//Lo llama index.php

function BuscarAlojamientoIndex(provincia,localidad,idioma){
	IDProvincia = provincia;
	IDLocalidad = localidad;
	IDIdioma = idioma;

	jsrsExecute( '/index_rs.php', crearprovincia, 'Provincia');
}

function crearprovincia ( cadenac ){
	window.status = 'Creando Provincias...';
	fillList( 'provincia',cadenac );
	var val=document.getElementById('provincia').value;
	jsrsExecute( '/index_rs.php', crearlocalidad, 'Localidad', val);
}

function provincia_onChange(){
	var val = this.options[this.selectedIndex].value;
	IDComarca = val;
	if(val == noValue){
		selectOption( this.name, curOption[this.name] )
	} else {
		curOption[this.name] = val;
		emptyList('localidad');
		window.status = 'Cargando Localidades...';
		jsrsExecute( '/index_rs.php', crearlocalidad, 'Localidad',val);
	}
}

function crearlocalidad ( cadenal ){
	window.status = 'Creando Localidades...';
	fillList( 'localidad',cadenal );
}

/*
function creartipoalojamiento ( cadenata ){ 

	window.status = 'Creando Tipos de Alojamiento...';

	fillList( 'tipoalojamiento',cadenata );

}



//OFERTAS inicio

function BuscarOfertas(comarca,localidad,idioma){

	IDComarca = comarca;

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearcomarcao, 'Comarcao');

}



function crearcomarcao ( cadenac ){ 

	window.status = 'Creando Comarcas...';

	fillList( 'comarcao',cadenac );

	var val=document.getElementById('comarcao').value;

	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidado, 'Localidado', val);

}



function comarcao_onChange(){

	var val = this.options[this.selectedIndex].value;

	IDComarca = val;

	if(val == noValue){

		selectOption( this.name, curOption[this.name] )

	} else {

		curOption[this.name] = val;

		emptyList('localidado');

		window.status = 'Cargando Localidades...';

		jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidado, 'Localidado',val);

	}	

}



function crearlocalidado ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidado',cadenal );

}

//OFERTAS fin



//Lo llama quevisitar.php

function BuscarQueVisitar(localidad,idioma){

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadqv, 'Localidadqv' );

}



function crearlocalidadqv ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidadqv',cadenal );

}



//Artesania inicio

function BuscarArtesania(comarca,localidad,idioma){

	IDComarca = comarca;

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearcomarcaa, 'Comarcaa');

}



function crearcomarcaa ( cadenac ){ 

	window.status = 'Creando Comarcas...';

	fillList( 'comarcaa',cadenac );

	var val=document.getElementById('comarcaa').value;

	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidada, 'Localidada', val);

}



function comarcaa_onChange(){

	var val = this.options[this.selectedIndex].value;

	IDComarca = val;

	if(val == noValue){

		selectOption( this.name, curOption[this.name] )

	} else {

		curOption[this.name] = val;

		emptyList('localidada');

		window.status = 'Cargando Localidades...';

		jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidada, 'Localidada',val);

	}	

}



function crearlocalidada ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidada',cadenal );

}

//ARTESANIA fin



//TURISMO ACTIVO inicio

function BuscarTurismoActivo(comarca,localidad,idioma){

	IDComarca = comarca;

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearcomarcata, 'Comarcata');

}



function crearcomarcata ( cadenac ){ 

	window.status = 'Creando Comarcas...';

	fillList( 'comarcata',cadenac );

	var val=document.getElementById('comarcata').value;

	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadta, 'Localidadta', val);

}



function comarcata_onChange(){

	var val = this.options[this.selectedIndex].value;

	IDComarca = val;

	if(val == noValue){

		selectOption( this.name, curOption[this.name] )

	} else {

		curOption[this.name] = val;

		emptyList('localidadta');

		window.status = 'Cargando Localidades...';

		jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadta, 'Localidadta',val);

	}	

}



function crearlocalidadta ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidadta',cadenal );

}

//TURISMO ACTIVO fin



//BARES DE TAPEO inicio

function BuscarBaresTapas(comarca,localidad,idioma){

	IDComarca = comarca;

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearcomarcabt, 'Comarcabt');

}



function crearcomarcabt ( cadenac ){ 

	window.status = 'Creando Comarcas...';

	fillList( 'comarcabt',cadenac );

	var val=document.getElementById('comarcabt').value;

	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadbt, 'Localidadbt', val);

}



function comarcabt_onChange(){

	var val = this.options[this.selectedIndex].value;

	IDComarca = val;

	if(val == noValue){

		selectOption( this.name, curOption[this.name] )

	} else {

		curOption[this.name] = val;

		emptyList('localidadbt');

		window.status = 'Cargando Localidades...';

		jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadbt, 'Localidadbt',val);

	}	

}



function crearlocalidadbt ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidadbt',cadenal );

}

//BARES DE TAPEO fin



//PRODUCTOS TIPICOS inicio

function BuscarProductosTipicos(comarca,localidad,idioma){

	IDComarca = comarca;

	IDLocalidad = localidad;

	IDIdioma = idioma;



	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearcomarcapt, 'Comarcapt');

}



function crearcomarcapt ( cadenac ){ 

	window.status = 'Creando Comarcas...';

	fillList( 'comarcapt',cadenac );

	var val=document.getElementById('comarcapt').value;

	jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadpt, 'Localidadpt', val);

}



function comarcapt_onChange(){

	var val = this.options[this.selectedIndex].value;

	IDComarca = val;

	if(val == noValue){

		selectOption( this.name, curOption[this.name] )

	} else {

		curOption[this.name] = val;

		emptyList('localidadpt');

		window.status = 'Cargando Localidades...';

		jsrsExecute( 'http://www.CasaCuevaRural.com/index_rs.php', crearlocalidadpt, 'Localidadpt',val);

	}	

}



function crearlocalidadpt ( cadenal ){ 

	window.status = 'Creando Localidades...';

	fillList( 'localidadpt',cadenal );

}

//PRODUCTOS TIPICOS fin


*/
function fillList( NombreLista, strOptions ){

	emptyList( NombreLista );

//	var lst = document.forms['formulario'][NombreLista];

	var lst = document.getElementById(NombreLista);

	lst.disabled = true;



	switch(NombreLista){

		case 'comarca':
			switch(IDIdioma){
				case '0':
					lst.options[0] = new Option("Comarca",0);
					break;
				case '1':
					lst.options[0] = new Option("Area",0);
					break;
				default:
					lst.options[0] = new Option("Comarca",0);
					break;
			}
			break;
		case 'provincia':
			switch(IDIdioma){
				case '0':
					lst.options[0] = new Option("Provincia",0);
					break;
				case '1':
					lst.options[0] = new Option("Town",0);
					break;
				default:
					lst.options[0] = new Option("Provincia",0);
					break;
			}
			break;
		case 'localidad':
			switch(IDIdioma){
				case '0':
					lst.options[0] = new Option("Localidad",0);
					break;
				case '1':
					lst.options[0] = new Option("Town",0);
					break;
				default:
					lst.options[0] = new Option("Localidad",0);
					break;
			}
			break;
	}



	var aOptionPairs = strOptions.split('|');

	for( var i = 0; i < aOptionPairs.length; i++ ){

		if (aOptionPairs[i].indexOf('~') != -1) {

			var aOptions = aOptionPairs[i].split('~');

			if ( NombreLista != 'localidadqv')

				lst.options[i+1] = new Option(aOptions[1], aOptions[0]);

			else

				lst.options[i] = new Option(aOptions[1], aOptions[0]);

		}	

	}

	var ID;

	switch(NombreLista){

		case 'comarca':
			ID = IDComarca;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			lst.onchange = eval( NombreLista + "_onChange" );
			break;
		case 'provincia':
			ID = IDProvincia;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			lst.onchange = eval( NombreLista + "_onChange" );
			break;
		case 'localidad':
			ID = IDLocalidad;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			break;
		case 'tipoalojamiento':
			ID = IDTipoAlojamiento;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			break;
		case 'tiposervicios':
			ID = IDTipoServicios;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			lst.onchange = eval( NombreLista + "_onChange" );
			break;
		case 'servicios':
			ID = IDServicios;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			break;
		case 'tipoquevisitar':
			ID = IDTipoQueVisitar;
			selectOption( NombreLista, ID );
			isLoaded[NombreLista] = true;
			lst.disabled = !boolEnabled;
			break;
	}

	window.status = 'Altipla Rural';

}



function emptyList( NombreLista ){

//alert ("Limpia la lista: "+NombreLista);

//	var lst = document.forms['formulario'][NombreLista];
	var lst = document.getElementById(NombreLista);
	lst.options.length = 0;
	lst.onchange = null;
	lst.disabled = !boolEnabled;
	isLoaded[NombreLista] = false;
	curOption[NombreLista] = noValue;
}



function selectOption( NombreLista, optionVal ){

// set list selection to option based on value

//	var lst = document.forms['formulario'][NombreLista];

	var lst = document.getElementById(NombreLista);

	for( var i = 0; i< lst.options.length; i++ ){

		if( lst.options[i].value == optionVal ){

			lst.selectedIndex = i;

			curOption[NombreLista] = optionVal;

			return;

		}

	}

}

