
function LimpiarCombo(combo){
	for(i=combo.options.length;i>1;i--)
		combo.remove(1);
}

function CargarProductos(){
	buscador.CargarProductos(hddBuscador.value, hddIdEc.value, hddIdioma.value, CallBackProductos);
}
function CargarProvincias(){
	cbA = document.getElementById("cmbProducto");
	buscador.CargarProvincias(hddBuscador.value, hddIdEc.value, cbA.value, hddIdioma.value, CallBackProvincias);
}
function CargarLocalidades(){
	cbA = document.getElementById("cmbProducto");
	cbB = document.getElementById("cmbProvincia");
	buscador.CargarLocalidades(cbA.value, cbB.value, CallBackLocalidades);
}
function CargarZonas(){
	cbA = document.getElementById("cmbProducto");
	cbB = document.getElementById("cmbLocalidad");
	buscador.CargarProvincias(cbA.value, cbB.value, CallBackZonas);
}


function CallBackProductos(response){
	cbZ = document.getElementById("cmbProducto");
	cbC = document.getElementById("cmbProvincia");
	cbA = document.getElementById("cmbLocalidad");
	cbB = document.getElementById("cmbZona");
	LimpiarCombo(cbZ);
	LimpiarCombo(cbC);
	LimpiarCombo(cbA);
	LimpiarCombo(cbB);
	rows = response.value;
	if (rows != null){		
		for (i = 0; i < rows.length; i++){
			cbZ.options[i] = new Option(rows[i]["sDescripcion"], rows[i]["IdComboProducto"]);
		}
	}
	fn_OnchangeCmbProducto();
	UpdateContador();
}


function CallBackProvincias(response){
	cbZ = document.getElementById("cmbProvincia");
	cbA = document.getElementById("cmbLocalidad");
	cbB = document.getElementById("cmbZona");
	LimpiarCombo(cbZ);
	LimpiarCombo(cbA);
	LimpiarCombo(cbB);
	rows = response.value;
	if (rows != null){		
		for (i = 0; i < rows.length; i++){
			cbZ.options[i + 1] = new Option(rows[i]["sDescripcion"], rows[i]["idProvincia"]);
		}
	}	
	UpdateContador();
}

function CallBackLocalidades(response){
	cbZ = document.getElementById("cmbLocalidad");
	cbB = document.getElementById("cmbZona");
	cbP = document.getElementById("cmbProvincia");
	
	indice = cbP.options.selectedIndex;
	document.all.hddsProvincia.value = cbP.options[indice].text;
	
	
	LimpiarCombo(cbZ);
	LimpiarCombo(cbB);
	rows = response.value;
	if (rows != null){		
		for (i = 0; i < rows.length; i++){
			cbZ.options[i + 1] = new Option(rows[i]["sDescripcion"], rows[i]["idLocalidad"]);
			if(cbP.options[indice].text == rows[i]["sDescripcion"])
			{
				cbZ.options[i + 1].selected = true;
				fn_OnChangeCmbLocalidad();
			}
		}
	}	
	UpdateContador();
		
}


function CallBackZonas(response){
	cbZ = document.getElementById("cmbZona");
	cbL = document.getElementById("cmbLocalidad");
	
	indice = cbL.options.selectedIndex;
	document.all.hddsLocalidad.value = cbL.options[indice].text;
	
	LimpiarCombo(cbZ);
	rows = response.value;
	if (rows != null){		
		for (i = 0; i < rows.length; i++){
			cbZ.options[i + 1] = new Option(rows[i]["sDescripcion"], rows[i]["idZona"]);
		}
	}	
	UpdateContador();
}

function UpdateContador(){
	////alert("UpdateContador()");
	////string idRegion, idTipo, areas, zonas, precio, beds, life
	//AreasZonasSeleccionadas();
	/*idRegion =	document.getElementById("HdRegion").value; 
	idTipo	 =	document.getElementById("CbTipos").value;
	areas    =	document.getElementById("HdAreas").value;
	zonas    =  document.getElementById("HdZonas").value;
	precio   =	document.getElementById("CbPrecios").value;
	beds	 =	document.getElementById("CbBeds").value;
	life	 =	document.getElementById("CbLifes").value;*/
	////alert("idRegion: " + idRegion + "\nidTipo: " + idTipo + "\nareas: " + areas + "\nzonas: " + zonas + "\nprecio: " + precio + "\nbeds: " + beds + "\nlife: " + life );
	//buscador.ActualizarContador(idRegion, idTipo, areas, zonas, precio, beds, life, CallBackContador);	
}