	
function ActualizarLocalidades(cbA, idBuscador, idEntidadCliente, idioma){ 
	index.CargarLocalidades(idBuscador, idEntidadCliente, cbA.value, -1, idioma, CallBackLocalidades);
}

function ActualizarZonas(cbA, idBuscador, idEntidadCliente, idioma){ 
	count = OptionsCounter(cbA);
	if (count > 0){
		if (cbA[count].text.substring(1,2) != " " && cbA[count+1].text.substring(1,2) != " " )
		{
			cbT = document.getElementById("LbType");	
			index.CargarZonas(idBuscador, idEntidadCliente, cbT.value, cbA.value, idioma, CallBackZonas);
		}
	}			
}
		
function CallBackLocalidades(response){
	cbA = document.getElementById("LbGrupoArea");
	LimpiarCombo(cbA);
	rows = response.value;
	if (rows != null){		
		for (i = 0; i < rows.length; i++){
			cbA.options[i + 1] = new Option(rows[i]["sDescripcion"], rows[i]["idLocalidad"]); //TODO:revisar los nombres de campos. Dependen del SP que manden
		}
	}	
}

function CallBackZonas(response){

	cbA = document.getElementById("LbGrupoArea");
	rows = response.value;
	if (rows != null){		
		var total=cbA.options.length;
		var j=0;
		for (i = count+1; i < total; i++){
			j++;
			cbA.options[count + j + rows.length] = new Option(cbA.options[i].text, cbA.options[i].value); //TODO:revisar los nombres de campos. Dependen del SP que manden
		}
	
		for (i = 0; i < rows.length; i++){
			cbA.options[count + i + 1] = new Option("   " + rows[i]["sDescripcion"], rows[i]["idZona"]); //TODO:revisar los nombres de campos. Dependen del SP que manden
		}
		cbA.options[count].selected = true;
	}	
}

function OptionsCounter(cbA){	
	count = 0;
	for (i = 0; i < cbA.length; i++){
			if (cbA[i].selected) {
				count = i;
			}
		}
	return count;
}

function LimpiarCombo(combo){
	for(i=combo.options.length;i>1;i--)
		combo.remove(1);
}

function AreasZonasSeleccionadas()
{
    document.getElementById("validar").value = "false";
    cbA  = document.getElementById("LbGrupoArea");
	hdZ1 = document.getElementById("HdidAreas");
	hdZ2 = document.getElementById("HdAreas");
	hdZ1.value="";
	hdZ2.value="";
	hdB1 = document.getElementById("HdidZonas");
	hdB2 = document.getElementById("HdZonas");
	hdB1.value="";
	hdB2.value="";
    for (i = 1; i < cbA.length; i++)
    {
		if (cbA[i].selected) 
		{
			document.getElementById("validar").value = "true";
			if (cbA[i].text.substring(1,2)!= " ")
			{
				hdZ1.value += cbA[i].value + ",";
				hdZ2.value += cbA[i].text + ",";
				//hdA1.value += cbA[i].value + ",";
				//hdA2.value += cbA[i].text + ",";
			}
			else
			{
				hdB1.value += cbA[i].value + ",";
				hdB2.value += cbA[i].text + ",";
			}
		}
    }
}
		
function Selecciones(mensaje){
	ref = document.getElementById("TbRef");
	if (ref != null)
		{
			if (ref.value != "")
				return true;
		}

	AreasZonasSeleccionadas();
	if ((document.getElementById("validar").value == "false")) 
	{
		alert(mensaje);
		return false;
	}
	else
		return true;
}