$(document).ready(function(){
	//init
	if($("#s_location").val() == ""){
		$("#s_district_khan").val('');
		$("#p-district-khan").hide();
	}
	c_type();
	var tt_b = $("#s_type").val();
	
	var pt = $("#s_type").val();
	if(pt == undefined) pt = "";
	var pm = $("#s_price_unit").val();
	if(pm == undefined) pm = "";
	var pf = $("#s_sale_rent").val();
	if(pf == undefined) pf = "";
	$("#p-price").load('inc/property-price.php',{'type': pt,'ms': pm,'sr': pf},function(){
		$("#p-price select").val($("#p-price").attr('rel'));
	});

	
	//on change
	$("#s_location").change( function() {
		if($("#s_location").val() == ""){
			$("#s_district_khan").val('');
			$("#p-district-khan").hide();
		}else {
			var pc = $("#s_location").val();
			$("#p-district-khan").show();
			load_location('inc/property-location.php','#p-district-khan',pc,'1');
		}							 
	});
	
	$("#s_type").change( function() {
		c_type();
		var pt = $("#s_type").val();
		if(pt == undefined) pt = "";
		if(pt == '14' ^ tt_b == '14'){
			var pm = $("#s_price_unit").val();
			if(pm == undefined) pm = "";
			var pf = $("#s_sale_rent").val();
			if(pf == undefined) pf = "";
			load_f('inc/property-price.php','#p-price',pf,pm,pt);
		}
		tt_b = $("#s_type").val();
	});	
	
	$("#s_sale_rent").change( function() {c_price();});
	$("#s_price_unit").change( function() {c_price();});

	$('#features').innerfade({speed: 1000,timeout: 5000,type: 'sequence',containerheight: '220px'});
	$("#print").click(function(){window.print();});
	
});

function c_type(){
	if($("#s_type").val() == "14"){
		$("#p-area").show();
		$("#p-price-unit").show();			
	}else{
		$("#s_area").val('');
		$("#p-area").hide();		
		$("#s_price_unit").val('');
		$("#p-price-unit").hide();
	}
}

// change price range
function c_price(){
	c_type();
	var pt = $("#s_type").val();
	if(pt == undefined) pt = "";
	var pm = $("#s_price_unit").val();
	if(pm == undefined) pm = "";
	var pf = $("#s_sale_rent").val();
	if(pf == undefined) pf = "";
	load_f('inc/property-price.php','#p-price',pt,pm,pf);
}
//load price ragne
function load_f(path,DID,type,ms,sr){
	$(DID).empty().html('<img src="images/busy.gif" />');
	$(DID).load(path,{'type': type,'ms': ms,'sr': sr});
}

// load property location
function load_location(path,DID,RID,type){
	$(DID).empty().html('<img src="images/busy.gif" />');
	$(DID).load(path,{'id': RID, 'type': type});
}
