var arrayPoblaciones = new Array();

function iniciar() {
	document.location.href="#resultados";

		var i=0;
		for(i=0;psector!=document.getElementById('formu').sector.options[i].value;i++) {}
		document.getElementById('formu').sector.selectedIndex=i;
		for(i=0;ppoblacion!=document.getElementById('formu').poblacion.options[i].value;i++) {}
		document.getElementById('formu').poblacion.selectedIndex=i;
}

function enviar() {
	if ((document.getElementById('formu').sector.selectedIndex==0)&&(document.getElementById('formu').poblacion.selectedIndex==0)) {
		if(document.getElementById('textodoblea')) document.getElementById('textodoblea').style.display='none';
		if(document.getElementById('textodoblea2')) document.getElementById('textodoblea2').style.display='block';
		if (document.getElementById('buscadoblea')) document.getElementById('buscadoblea').style.display='none';
	}
	else {
		document.getElementById('formu').submit();
	}
}
function pintaSelectPoblacion(){
	document.write('<select id="poblacion" name="poblacion" ><option value="">Todas las Localidades: </option>');
	document.write(poblacion);
	document.write('</select>');
}
function pintaSelectSector(){
	document.write('<label for="sector">Selecciona Sector</label>');
	document.write('<select id="sector" name="sector" ><option value="">Todos los Sectores: </option>	');
	document.write(sector);
	document.write('</select>');
}
function envia2(id){
	document.getElementById('formu').sector.options[0].selected=true;
	document.getElementById('formu').sector.options[0].value="";
	document.getElementById('formu').poblacion.value= valor(0,arrayPoblaciones[id]);
	document.getElementById('formu').submit();
}
function valor(num, cadena){
	var aux = cadena.split('#');
	return(aux[num]);
}	
function poblaciones(){
	for (i=1; i< document.getElementById('formu').poblacion.options.length ; i++)
	{
		arrayPoblaciones[i] = document.getElementById('formu').poblacion.options[i].value +'#'+ document.getElementById('formu').poblacion.options[i].text;
	}
}
function escribelocalidad(){
	document.write('<div id="textodoblea2" class="margen">');
		document.write('<p>Selecciona una localidad para ver los establecimientos asociados que puedes encontrar en ella :</p>');	
				poblaciones();
				document.write('<div class="listado">');
				for (i=1; i< arrayPoblaciones.length; i++ )
				{
					if (i== Math.round(arrayPoblaciones.length /2) ) 
					{
						document.write('</div>');
						document.write('<div class="separador"><img src="/images/sizer.gif" alt="" width="1" height="1" /></div>');
						document.write('<div class="listado" >');
					}
					(i%2)? aux= 'azulnegrita' : aux= 'naranja' ;
					document.write ('<a href="javascript:envia2('+ i +')" class="poblaciones"><strong class="'+ aux +'">'+ valor(1,arrayPoblaciones[i]) +'</strong></a><br />');
					
				}
				document.write('</div>');
	document.write('</div>');		
}

function escribe_combos()
	{document.write('<select name="sector" id="sectores" style="width:71%"><option value="">Todos los sectores:</option>'+sector+'</select><select name="poblacion" id="poblaciones"><option value="-1">Todas las poblaciones:</option>'+poblacion+'</select>');}