$(document).ready(
function()
{
 function adjustRegion()
 {
  var regionValue = $('#region').val();
  var tmpSelect = $('#countrysel');
  if(regionValue == 0)
  {
   tmpSelect.attr('disabled','disabled');
   tmpSelect.clearSelect();
   adjustCountry();
   document.getElementById('countrydiv').style.display='none';
   document.getElementById('citydiv').style.display='none';
   document.getElementById('submitdiv').style.display='none';
   $('#typediv').html($('#tmpnavi').html());
  }
  else
  {
   document.getElementById('countrydiv').style.display='';
   document.getElementById('submitdiv').style.display='';
   if($('#langdiv').html()==1) {$('#poptoursspan').html("Популярные туры: "+$('#region :selected').html()).show();}
   else {$('#poptoursspan').html("Popular Tours in "+$('#region :selected').html()).show();}
   if($('#langdiv').html()==1 || $('#langdiv').html()==2)
   {
    $.getJSON('/cascadeselectcountry.php',{region:regionValue,l:$('#langdiv').html()},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); adjustCountry(); });
    $('#typediv').load('/cascadeselecttype.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 {
                document.getElementById('citydiv').style.display='';
                var countrytxt=" <a href=\"\searchbox.php?c="+countryValue+"\" class=\"searchlink\">"+$('#countrysel :selected').html()+"</a>&raquo;";
                $('#poptoursspan').html("Popular Tours in "+$('#countrysel :selected').html()).show();
                $.getJSON('/cascadeselectcity.php',{country:countryValue,l:$('#langdiv').html()},function(data) { tmpSelect.fillSelect(data).attr('disabled',''); });
                $('#typediv').load('/cascadeselecttype.php?country='+countryValue+'&l='+$('#langdiv').html()).show();
  	}
  };
  function adjustCity()
  {
   var regionValue 	=$('#region').val();
   var countryValue 	=$('#countrysel').val();
   var cityValue 	=$('#citysel').val();
   $('#typediv').load('/cascadeselecttype.php?city='+cityValue+'&l='+$('#langdiv').html()).show();
   $('#poptoursspan').html("Popular Tours in "+$('#citysel :selected').html()).show();
  };
  $('#tmpnavi').html($('#typediv').html());
  $('#region').change(function(){adjustRegion();}).change();
  $('#countrysel').change(adjustCountry);
  $('#citysel').change(adjustCity);
});
