function categorysearch() {
	var catid = document.getElementById("ddcategory").value;
	catname = document.getElementById("ddcategory").options[document.getElementById("ddcategory").selectedIndex].text;
	catname = catname.replace(/ /gi,"-").replace("&","").replace("#","").replace(/---/gi,"-").replace("/","|");
	location.href="/category-properties/"+catid+"/"+catname;
}

function pricesearch() {
	var pricerangeid = document.getElementById("ddprice").value;
	rangename = document.getElementById("ddprice").options[document.getElementById("ddprice").selectedIndex].text;
	rangename = rangename.replace(" - ","-").replace("&","").replace("#","").replace(" ","-");
	location.href="/price-search/"+pricerangeid+"/"+rangename;
}

function quicksearch() {
	var cat = document.getElementById("ddquickcategory").value;
	var bedrooms = document.getElementById("ddquickbedrooms").value;
	var bathrooms = document.getElementById("ddquickbathrooms").value;
	var pricerange = document.getElementById("ddquickprice").value;
	var params = cat+"|"+bedrooms+"|"+bathrooms+"|"+pricerange;
	
	var ajax = new sack();
	ajax.requestFile = "/components/mod_properties/save-search-ajax.php?params="+params;
	ajax.onCompletion = function(){ redirecttosearch(ajax); };	// Specify function that will be executed after file has been found
	ajax.runAJAX();		// Execute AJAX function
	
}

function keywordsearch() {
	var searchterm = document.getElementById("txtkeyword").value;
	searchterm = trim(searchterm);
	if(searchterm!="") {
		var params = searchterm;
		var ajax = new sack();
		ajax.requestFile = "/components/mod_properties/save-search-ajax.php?params="+params;
		ajax.onCompletion = function(){ redirecttokeywordsearch(ajax); };	// Specify function that will be executed after file has been found
		ajax.runAJAX();		// Execute AJAX function
	}
}


function displayagentlistings() {
	var catid = document.getElementById("ddagent").value;
	catname = document.getElementById("ddagent").options[document.getElementById("ddagent").selectedIndex].text;
	catname = catname.replace(/ /gi,"-").replace("&","").replace("#","").replace(/---/gi,"-").replace("/","|");
	location.href="/agent-properties/"+catid+"/"+catname;
}


function redirecttosearch(ajax)
{
	location.href="/property-search";
}

function redirecttokeywordsearch(ajax)
{
	location.href="/search";
}

$(document).ready(function() {
	$("a.zoom").fancybox({
		'width': 550, 
		'height': 250, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});
	
	$("a.refertofriend").fancybox({
		'width': 550, 
		'height': 350, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});
	
	$("a.propertyimage").fancybox({
		'autoDimensions' : false,
		'frameWidth'  : 600, 
           'frameHeight' : 500 
	});
	
	$("a.single_image").fancybox({
		'width'  : 720, 
           'height' : 450, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});

	$("a.map").fancybox({
	 	'width': 505, 
		'height': 505, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});

	$("a.specsheet").fancybox({
	 	'width': 695, 
		'height': 600, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});
	
	$("a.schoolpopup").fancybox({
		'width': 570, 
		'height': 350, 
		'autoScale': false, 
		'type': 'iframe',
		'titleShow': true
	});
});


function trim(str) { 
	str.replace(/^\s*/, '').replace(/\s*$/, ''); 
   	return str;
} 

