$(document).ready(
function()
{
 function adjustRegion()
 {
  var regionValue = $('#region').val();
  var tmpSelect = $('#countrysel');
  if(regionValue == 0)
  {
   tmpSelect.attr('disabled','disabled');
   tmpSelect.clearSelect();
   adjustCountry();
   $('#countrydiv').css('display','none');
   $('#citydiv').css('display','none');
   $('#typediv').html($('#tmpnavi').html());
  }
  else
  {
   $('#countrydiv').css('display','');
   if($('#langdiv').html()==1 || $('#langdiv').html()==2)
   {
    $.getJSON('/cascadeselectcountry_new.php',{region:regionValue,l:$('#langdiv').html()},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); adjustCountry(); });
    $('#typediv').load('/cascadeselecttype_new.php?region='+regionValue+'&l='+$('#langdiv').html()).show();
   }
  }
 }
 function adjustCountry()
 {
  var regionValue  = $('#region').val();
  var countryValue = $('#countrysel').val();
  var tmpSelect    = $('#citysel');
  	if(countryValue == 0||regionValue==0) {
  		tmpSelect.attr('disabled','disabled');
  		tmpSelect.clearSelect();
        document.getElementById('citydiv').style.display='none';
  	} else {
                $('#citydiv').css('display','');
                var countrytxt=" <a href=\"\searchbox.php?c="+countryValue+"\" class=\"searchlink\">"+$('#countrysel :selected').html()+"</a>&raquo;";
                $.getJSON('/cascadeselectcity_new.php',{country:countryValue,l:$('#langdiv').html()},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); });
  	}
    $('#typediv').load('/cascadeselecttype_new.php?country='+countryValue+'&region='+regionValue+'&l='+$('#langdiv').html()).show();
  };
  function adjustCity()
  {
   var regionValue 	=$('#region').val();
   var countryValue 	=$('#countrysel').val();
   var cityValue 	=$('#citysel').val();
   $('#typediv').load('/cascadeselecttype_new.php?city='+cityValue+'&country='+countryValue+'&region='+regionValue+'&l='+$('#langdiv').html()).show();
  };
  $('#tmpnavi').html($('#typediv').html());
  $('#region').change(function(){adjustRegion();});
  $('#countrysel').change(adjustCountry);
  $('#citysel').change(adjustCity);
});

