document.onclick = function (e) {
e = e || event;
var target = e.target || e.srcElement;
var select_suburb = document.getElementById("select_suburb");
var suburb_list = document.getElementById("suburb_list");
var select_property_type = document.getElementById("select_property_type");
var property_type_list = document.getElementById("property_type_list");

do {
	if (select_suburb == target || suburb_list == target || select_property_type == target || property_type_list == target ) {
		// Click occured inside the box, do nothing.
		return;
	}
	target = target.parentNode;
} while (target);

// Click was outside the box, hide it.
select_suburb.style.display = "none";
select_property_type.style.display = "none";
}

function submit_form(){
if(jQuery("#keywords").val()=='Enter keyword, ID, suburb, or street')document.getElementById('keywords').value='';
return true;
}

function showtab(type) {
var list=jQuery('#select_type').val();	
var siteurl=jQuery('#siteurl').val();	
var status=jQuery('#status').val();	
var url2 = siteurl + "/wp-content/plugins/Realty/display/pages/js/quick_search_ajax.php?list="+escape( list )+"&type="+escape( type )+"&status="+escape( status )+"&cat=property_type";	
jQuery('#select_property_type').load(url2);

var url = siteurl + "/wp-content/plugins/Realty/display/pages/js/quick_search_ajax.php?type="+escape( type )+"&cat=price";
jQuery('#price_for_sale').load(url);

var url1 = siteurl + "/wp-content/plugins/Realty/display/pages/js/quick_search_ajax.php?list="+escape( list )+"&type="+escape( type )+"&status="+escape( status )+"&cat=suburb";
jQuery('#select_suburb').load(url1);	
	
return false; 
}

function expand_propertyType(){
jQuery("#select_suburb").hide(); 
if(jQuery("#select_property_type").is(":visible") == true )  jQuery("#select_property_type").hide(); 
else  jQuery("#select_property_type").show(); 
}

function check_all_type(){		
if(eval("document.getElementById('all_type').checked") == true)
var max = document.getElementsByName('property_type[]').length;				
for(var idx = 0; idx < max; idx++){document.getElementsByName('property_type[]')[idx].checked = false;}
document.getElementById('propertyType').value="All";
}

function check_type(value){		
var flag='0';
var count='0';
var temp='';
if(eval("document.getElementById('all_type').checked") == true)flag='1';	
var max = document.getElementsByName('property_type[]').length;			
if(flag=='1'){
	document.getElementById('all_type').checked = false;
	for(var idx = 0; idx < max; idx++){
		if(document.getElementsByName('property_type[]')[idx].value!=value)document.getElementsByName('property_type[]')[idx].checked = false;
		else document.getElementsByName('property_type[]')[idx].checked = true;
	}
}
for(var idx = 0; idx < max; idx++){
	if(document.getElementsByName('property_type[]')[idx].checked == true){ count++; temp=document.getElementsByName('property_type[]')[idx].value; }
}
if(count=='0') { document.getElementById('propertyType').value="All";document.getElementsByName('all_type').checked = true; }
if(count=='1')document.getElementById('propertyType').value=temp;
if(count > 1)document.getElementById('propertyType').value="Multiple";
}

function expand_suburb(){
jQuery("#select_property_type").hide(); 
if(jQuery("#select_suburb").is(":visible") == true )  jQuery("#select_suburb").hide(); 
else  jQuery("#select_suburb").show(); 
}

function check_all_suburb(){		
if(eval("document.getElementById('all_suburb').checked") == true)
var max = document.getElementsByName('suburb[]').length;		
for(var idx = 0; idx < max; idx++){document.getElementsByName('suburb[]')[idx].checked = false;}
document.getElementById('suburb').value="All";
} 

function check_suburb(value){		
var flag='0';
var count='0';
var temp='';
var max = document.getElementsByName('suburb[]').length;
if(eval("document.getElementById('all_suburb').checked") == true)flag='1';					
if(flag=='1'){
	document.getElementById('all_suburb').checked = false;
	for(var idx = 0; idx < max; idx++){
		if(document.getElementsByName('suburb[]')[idx].value!=value)document.getElementsByName('suburb[]')[idx].checked = false;
		else document.getElementsByName('suburb[]')[idx].checked = true;
	}
}
for(var idx = 0; idx < max; idx++){
	if(document.getElementsByName('suburb[]')[idx].checked == true){ count++; temp=document.getElementsByName('suburb[]')[idx].value; }
}
if(count=='0') { document.getElementById('suburb').value="All";document.getElementsByName('all_suburb').checked = true; }
if(count=='1')document.getElementById('suburb').value=temp;
if(count > 1)document.getElementById('suburb').value="Multiple";
}

jQuery("#type select").change(function(){
if(this.value=='commercial')showtab('sale');
else if(this.value=='residential_lease')showtab('lease');
else if(this.value=='holiday_lease')showtab('lease');
else if(this.value=='residential_sale')showtab('sale');
else if(this.value=='project_sale')showtab('sale');
else if(this.value=='business_sale')showtab('sale');
});
