var flash=0;

igualar= function(){
	    col1 = jQuery("#menuSec").height()
		col2 = jQuery("#nivelPri").height()

		if (col1 >= col2 )
		{
			jQuery(".contNivel").height(col1-(jQuery("h2.title").height()+jQuery(".bottom").height()))
		}
		else
		{
			jQuery(".contCleanSup").height(col2 -  jQuery("#banner_lateral_izquierda_secciones").height())
		}
    };

prepararDatos = function(datos){
dat = '<ul>';
for (var i = 0; i < datos.length; i++)
{
	dat += '<li><span class="dtitle">'+decodeURIComponent(datos[i].nombre)+'</span>';
	if (datos[i].oficial == 1)
		dat += '<span style="position:absolute;top:0px;right:0px;"><img class="dlogo" src="'+rp+'img/logo_distribuidor_oficial_'+lang+'.png" width="50px" height="33px" alt="Distribuidor oficial" title="Distribuidor oficial" /></span>';
	dat += '<span class="direccion">'+decodeURIComponent(datos[i].direccion)+'</span><span class="telemail">'
	if (datos[i].telefono != '')
		dat += '<span class="tel">Telf: </span>'+decodeURIComponent(datos[i].telefono);
	if (datos[i].email != '')
		dat += '&nbsp;&middot;&nbsp;<span class="email">email: </span><a href="mailto:'+decodeURIComponent(datos[i].email)+'">'+decodeURIComponent(datos[i].email)+'</a>';
	if (datos[i].website != '')	
		dat += '<br /><span class="email">Web: </span><a target="_blank" href="http://'+decodeURIComponent(datos[i].website)+'">'+decodeURIComponent(datos[i].website)+'</a>';
	dat += '</span><span class="borde"> </span></li>';
}
dat +='</ul>';
return dat;
}




function cambiarPais(v)
{
	flash=1;
	jQuery("#paises").val(v);
	jQuery("#paises").change();
// 	var currentHref = window.location.href;
// 	window.location.href = currentHref.substr(0, currentHref.lastIndexOf("#")) + "#map";
	//location.href=location.href+"#map";
}

jQuery(document).ready(function(){




jQuery(".zonas").hide();
jQuery("#distribuidores").hide();
document.fdist.idp.selectedIndex=0;
jQuery("#paises").change(function(){

if (flash == 0)
flashProxy.call('zoomTo', jQuery("#paises").val());
else
flash=0;

jQuery(".arrow").show();

jQuery.post(rp+"distribuidores.php", { idp: jQuery('#paises').val(), lang: lang },
  function(data){
  	if (data.zonas.length > 0)
	{
		jQuery('#zonas').html('<option selected>loading</option>');
		jQuery(".zonas").show();
		var options = olddata;
		for (var i = 0; i < data.zonas.length; i++)
			options += '<option value="' + data.zonas[i].id + '">' + decodeURIComponent(data.zonas[i].nombre) + '</option>';
		jQuery('#zonas').html(options);	
		
	}
	else
	{
		jQuery(".zonas").hide();
	}
	
	if (data.distribuidores.length > 0)
	{
		jQuery('.lugar').html(document.fdist.idp.options[document.fdist.idp.selectedIndex].text);
		dist = prepararDatos(data.distribuidores);
		jQuery('#distribuidores').hide();
		jQuery('.listado').html(dist);
		jQuery('#distribuidores').fadeIn('slow');
		jQuery(".zonas").hide();
    	jQuery('.dlogo').hoverpulse();
// 		igualar();
		
	}
	else
	{
		jQuery('#distribuidores').hide();
	}
  },"json");
        });
		
jQuery("#zonas").change(function(){

jQuery(".arrow").hide();
jQuery.post(rp+"distribuidores.php", { idp: jQuery('#paises').val(), idz:jQuery('#zonas').val(), lang: lang },
  function(data){
  	if (data.distribuidores.length > 0)
	{
		jQuery('.lugar').html(document.fdist.idp.options[document.fdist.idp.selectedIndex].text+' | '+document.fdist.idz.options[document.fdist.idz.selectedIndex].text);
		dist = prepararDatos(data.distribuidores);
		jQuery('#distribuidores').hide();
		jQuery('.listado').html(dist);
		jQuery('#distribuidores').fadeIn('slow');
		jQuery('.dlogo').hoverpulse();
		/*$(".contNivel").height($(".contNivel").height()+($('#distribuidores').height()))*/
// 		igualar();
	}
	else
	{
		jQuery('#distribuidores').hide();
	}
	
  },"json");
        });


});

