
$(document).ready(function(){
  $('#country').bind('change',getStates);
  $('#state').bind('change',getCities);
  $('#savenow').bind('click',getProperties);
});

function getStates(e){
	$('#city').html("<option value=''>City/Area</option>");
	$('#city').attr("disabled","disabled");
	var country = $('#country').val();
	var allProperty= $('#allProperty').val();
	$.ajax({
		   type: "POST",
		   url: "index.php",
		   data: "do=get-state&country="+country+"&allProperty="+allProperty,
		   success: function(responseText){
			   if(responseText != ''){
			     $('#state').html(responseText);
				 $('#state').removeAttr("disabled");
			   }else{
				 $('#state').html("<option value=''>State/Province</option>");
				 $('#state').attr("disabled","disabled");
				 getCities();
			   }			   
		   }
   });
}

function getCities(){
	var country = $('#country').val();
	var state = $('#state').val();
	if(state == null){
		state = '';
	}
	var allProperty= $('#allProperty').val();
	$.ajax({
		   type: "POST",
		   url: "index.php",
		   data: "do=get-city&country="+country+"&state="+state+"&allProperty="+allProperty,
		   success: function(responseText){
			   $('#city').html(responseText);
			   $('#city').removeAttr("disabled");
		   }
   });
}

function getProperties(){
	var country = $('#country').val();	
	var state = $('#state').val();
	if(state == '')
	  state = country;
	var city = $('#city').val();	
	if(city != ''){
	  $.ajax({
		     type: "POST",
		     url: "index.php",
		     data: "do=get-content&country="+country+"&state="+state+"&city="+city,
		     success: function(responseText){
			     $('#result_city_name').html(city);
			     $('#results_content').html(responseText);
			     $('#results').show("slow");
		     }
      });
	}
	return false;
}

function hideResults()
{
	$('#results').hide("slow");
	return false;
}

function photoPopup(address) {
	window.open(address,'photosPopUp','width=600,height=416,resizable=no,scrollbars=no,status=no');
}

