
function save_state(){
	
	country_select = document.getElementById('country');	
	region_select = document.getElementById('region');
	currency_select = document.getElementById('currency');
	minPrice_select = document.getElementById('minPrice');
	maxPrice_select = document.getElementById('maxPrice');
	propertyType_select = document.getElementById('propertyType');
	buylet_select = document.getElementById('buylet');

	//bedrooms_select = document.getElementById('bedrooms');
	
	SetCookie('country',country_select.options[country_select.selectedIndex].value);
	SetCookie('region', region_select.options[region_select.selectedIndex].value);
	SetCookie('currency',currency_select.options[currency_select.selectedIndex].value);
	SetCookie('minprice',minPrice_select.options[minPrice_select.selectedIndex].value);
	SetCookie('maxprice',maxPrice_select.options[maxPrice_select.selectedIndex].value);
	SetCookie('property',propertyType_select.options[propertyType_select.selectedIndex].value);
	SetCookie('buylet',buylet_select.options[buylet_select.selectedIndex].value);
	//SetCookie('bedrooms',bedrooms_select.options[bedrooms_select.selectedIndex].value);
	$('searchForm').submit();
	
}

function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
return null;
}

function SetCookie (name, value) {
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	document.cookie = name + "=" + escape (value) +
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	((path == null) ? "" : ("; path=" + path)) +
	((domain == null) ? "" : ("; domain=" + domain)) +
	((secure == true) ? "; secure" : "");
}

function InitialiseCountries() {

var country_select = document.getElementById('country');
	country_select.options[0] = new Option("Any");
	country_select.options[0].value = 0;
var region_select = document.getElementById('region');
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = "0";
	country_select.options[0] = new Option("United Kingdom");
	country_select.options[0].value = 32;
	country_select.options[1] = new Option("Canada");
	country_select.options[1].value = 85;
	country_select.options[2] = new Option("Germany");
	country_select.options[2].value = 130;
	country_select.options[3] = new Option("Malaysia");
	country_select.options[3].value = 177;
	country_select.options[4] = new Option("Morocco");
	country_select.options[4].value = 192;
	country_select.options[5] = new Option("Portugal");
	country_select.options[5].value = 220;
	country_select.options[6] = new Option("Spain");
	country_select.options[6].value = 248;
	country_select.options[7] = new Option("Turkey");
	country_select.options[7].value = 267;
	country_select.options[8] = new Option("America");
	country_select.options[8].value = 292;
	country_select.options[9] = new Option("Caribbean");
	country_select.options[9].value = 293;
}

//--------------------------------------- End of InitialiseCountires Function 

function FillRegions() {

	var country_select = document.searchForm.country;
	var region_select = document.searchForm.region;
	// check to see if the user has selected All
	// If not, populate the region select box else clear it out.
	if( country_select.options[country_select.selectedIndex].value == 0 ) {
		region_select.length = 0;
		region_select.options[0] = new Option("Any");
		region_select.options[0].value = 0;
	region_select.style.display='block';
document.getElementById('bregion').style.display='block';

		} else {
if( country_select.options[country_select.selectedIndex].value == "32" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='none';
	document.getElementById('bregion').style.display='none';
	region_select.options[1] = new Option("Bristol");
	region_select.options[1].value = 89;
	region_select.options[2] = new Option("Murcia");
	region_select.options[2].value = 96;
}

if( country_select.options[country_select.selectedIndex].value == "85" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Quebec");
	region_select.options[1].value = 174;
}

if( country_select.options[country_select.selectedIndex].value == "130" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Berlin");
	region_select.options[1].value = 661;
}

if( country_select.options[country_select.selectedIndex].value == "177" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Port Dickson");
	region_select.options[1].value = 167;
	region_select.options[2] = new Option("Straits of Malacca");
	region_select.options[2].value = 663;
}

if( country_select.options[country_select.selectedIndex].value == "192" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Saïdia");
	region_select.options[1].value = 157;
	region_select.options[2] = new Option("Mediterranean Sea");
	region_select.options[2].value = 380;
	region_select.options[3] = new Option("Atlantic Coast");
	region_select.options[3].value = 390;
}

if( country_select.options[country_select.selectedIndex].value == "220" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Olhao");
	region_select.options[1].value = 577;
	region_select.options[2] = new Option("The Silver Coast");
	region_select.options[2].value = 664;
}

if( country_select.options[country_select.selectedIndex].value == "248" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Costa Blanca");
	region_select.options[1].value = 147;
	region_select.options[2] = new Option("Costa de la Luz");
	region_select.options[2].value = 155;
	region_select.options[3] = new Option("Costa Blanca North");
	region_select.options[3].value = 156;
	region_select.options[4] = new Option("Costa de Almeria");
	region_select.options[4].value = 159;
	region_select.options[5] = new Option("Costa del Sol");
	region_select.options[5].value = 165;
	region_select.options[6] = new Option("Murcia");
	region_select.options[6].value = 175;
	region_select.options[7] = new Option("Corvera");
	region_select.options[7].value = 205;
	region_select.options[8] = new Option("Sevilla");
	region_select.options[8].value = 378;
	region_select.options[9] = new Option("Canary Islands");
	region_select.options[9].value = 372;
	region_select.options[10] = new Option("Cordoba");
	region_select.options[10].value = 370;
	region_select.options[11] = new Option("Costa Calida");
	region_select.options[11].value = 367;
	region_select.options[12] = new Option("Jaen");
	region_select.options[12].value = 361;
	region_select.options[13] = new Option("Granada");
	region_select.options[13].value = 360;
	region_select.options[14] = new Option("Balearic Islands");
	region_select.options[14].value = 386;
	region_select.options[15] = new Option("Costa Dorada");
	region_select.options[15].value = 397;
}

if( country_select.options[country_select.selectedIndex].value == "267" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Didim");
	region_select.options[1].value = 148;
	region_select.options[2] = new Option("Akbuk");
	region_select.options[2].value = 152;
	region_select.options[3] = new Option("Bodrum");
	region_select.options[3].value = 161;
	region_select.options[4] = new Option("Kusadasi");
	region_select.options[4].value = 662;
}

if( country_select.options[country_select.selectedIndex].value == "292" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("Orlando Florida");
	region_select.options[1].value = 154;
	region_select.options[2] = new Option("Florida");
	region_select.options[2].value = 383;
	region_select.options[3] = new Option("South Carolina");
	region_select.options[3].value = 400;
}

if( country_select.options[country_select.selectedIndex].value == "293" ) {
	region_select.length = 0;
	region_select.options[0] = new Option("Any");
	region_select.options[0].value = 0;
	region_select.style.display='block';
	document.getElementById('bregion').style.display='block';
	region_select.options[1] = new Option("St. Lucia");
	region_select.options[1].value = 190;
	region_select.options[2] = new Option("Barbados");
	region_select.options[2].value = 404;
}

}

}

//--------------------------------------- End of InitialiseRegion Function 

function InitialiseMinMaxPrices() {
	var currency_select = document.getElementById('currency');
	var minPrice_select = document.getElementById('minPrice');
	var maxPrice_select = document.getElementById('maxPrice');
	if( currency_select.options[currency_select.selectedIndex].value == "0" ) {
	minPrice_select.length = 0;
	minPrice_select.options[0] = new Option("No minimum");
	minPrice_select.options[0].value = 0;
	maxPrice_select.length = 0;
	maxPrice_select.options[0] = new Option("No maximum");
	maxPrice_select.options[0].value = 0;
}	currency_select.length=0;
	currency_select.options[0] = new Option("GBP United Kingdom Pounds");
	currency_select.options[0].value = 1;
	currency_select.options[1] = new Option("USD United States Dollars");
	currency_select.options[1].value = 2;
	currency_select.options[2] = new Option("EUR Euros");
	currency_select.options[2].value = 3;
if(document.getElementById('buylet').value == 1){
maxPrice_select.length = 0;
minPrice_select.length = 0;

	minPrice_select.options["0"] = new Option("No Minimum");
	minPrice_select.options[0].value = 0;
	
	maxPrice_select.options["0"] = new Option("No Maximum");
	maxPrice_select.options[0].value = 0;
	
	minPrice_select.options[1] = new Option("50,000");
	minPrice_select.options[1].value = 50000;
	
	maxPrice_select.options[1] = new Option("50,000");
	maxPrice_select.options[1].value = 50000;
	
	minPrice_select.options[2] = new Option("100,000");
	minPrice_select.options[2].value = 100000;
	
	maxPrice_select.options[2] = new Option("100,000");
	maxPrice_select.options[2].value = 100000;
	
	minPrice_select.options[3] = new Option("150,000");
	minPrice_select.options[3].value = 150000;
	
	maxPrice_select.options[3] = new Option("150,000");
	maxPrice_select.options[3].value = 150000;
	
	minPrice_select.options[4] = new Option("200,000");
	minPrice_select.options[4].value = 200000;
	
	maxPrice_select.options[4] = new Option("200,000");
	maxPrice_select.options[4].value = 200000;
	
	minPrice_select.options[5] = new Option("250,000");
	minPrice_select.options[5].value = 250000;
	
	maxPrice_select.options[5] = new Option("250,000");
	maxPrice_select.options[5].value = 250000;
	
	minPrice_select.options[6] = new Option("300,000");
	minPrice_select.options[6].value = 300000;
	
	maxPrice_select.options[6] = new Option("300,000");
	maxPrice_select.options[6].value = 300000;
	
	minPrice_select.options[7] = new Option("350,000");
	minPrice_select.options[7].value = 350000;
	
	maxPrice_select.options[7] = new Option("350,000");
	maxPrice_select.options[7].value = 350000;
	
	minPrice_select.options[8] = new Option("350,000");
	minPrice_select.options[8].value = 350000;
	
	maxPrice_select.options[8] = new Option("350,000");
	maxPrice_select.options[8].value = 350000;
	
	minPrice_select.options[9] = new Option("400,000");
	minPrice_select.options[9].value = 400000;
	
	maxPrice_select.options[9] = new Option("400,000");
	maxPrice_select.options[9].value = 400000;
	
	minPrice_select.options[10] = new Option("450,000");
	minPrice_select.options[10].value = 450000;
	
	maxPrice_select.options[10] = new Option("450,000");
	maxPrice_select.options[10].value = 450000;
	
	minPrice_select.options[11] = new Option("500,000");
	minPrice_select.options[11].value = 500000;
	
	maxPrice_select.options[11] = new Option("500,000");
	maxPrice_select.options[11].value = 500000;
	
	minPrice_select.options[12] = new Option("600,000");
	minPrice_select.options[12].value = 600000;
	
	maxPrice_select.options[12] = new Option("600,000");
	maxPrice_select.options[12].value = 600000;
	
	minPrice_select.options[13] = new Option("650,000");
	minPrice_select.options[13].value = 650000;
	
	maxPrice_select.options[13] = new Option("650,000");
	maxPrice_select.options[13].value = 650000;
	
	minPrice_select.options[14] = new Option("700,000");
	minPrice_select.options[14].value = 700000;
	
	maxPrice_select.options[14] = new Option("700,000");
	maxPrice_select.options[14].value = 700000;
	
	minPrice_select.options[15] = new Option("750,000");
	minPrice_select.options[15].value = 750000;
	
	maxPrice_select.options[15] = new Option("750,000");
	maxPrice_select.options[15].value = 750000;
	
	minPrice_select.options[16] = new Option("800,000");
	minPrice_select.options[16].value = 800000;
	
	maxPrice_select.options[16] = new Option("800,000");
	maxPrice_select.options[16].value = 800000;
	}
if(document.getElementById('buylet').value == 2){
maxPrice_select.length = 0;
minPrice_select.length = 0;

	minPrice_select.options["0"] = new Option("No Minimum");
	minPrice_select.options[0].value = 0;
	
	maxPrice_select.options["0"] = new Option("No Maximum");
	maxPrice_select.options[0].value = 0;
	
	minPrice_select.options[1] = new Option("250");
	minPrice_select.options[1].value = 250;
	
	maxPrice_select.options[1] = new Option("250");
	maxPrice_select.options[1].value = 250;
	
	minPrice_select.options[2] = new Option("500");
	minPrice_select.options[2].value = 500;
	
	maxPrice_select.options[2] = new Option("500");
	maxPrice_select.options[2].value = 500;
	
	minPrice_select.options[3] = new Option("750");
	minPrice_select.options[3].value = 750;
	
	maxPrice_select.options[3] = new Option("750");
	maxPrice_select.options[3].value = 750;
	
	minPrice_select.options[4] = new Option("1,000");
	minPrice_select.options[4].value = 1000;
	
	maxPrice_select.options[4] = new Option("1,000");
	maxPrice_select.options[4].value = 1000;
	
	minPrice_select.options[5] = new Option("1,500");
	minPrice_select.options[5].value = 1500;
	
	maxPrice_select.options[5] = new Option("1,500");
	maxPrice_select.options[5].value = 1500;
	
	minPrice_select.options[6] = new Option("2,000");
	minPrice_select.options[6].value = 2000;
	
	maxPrice_select.options[6] = new Option("2,000");
	maxPrice_select.options[6].value = 2000;
	}
if(document.getElementById('buylet').value == 0){
maxPrice_select.length = 0;
minPrice_select.length = 0;

	minPrice_select.options["0"] = new Option("No Minimum");
	minPrice_select.options[0].value = 0;
	
	maxPrice_select.options["0"] = new Option("No Maximum");
	maxPrice_select.options[0].value = 0;
	
	minPrice_select.options[1] = new Option("500");
	minPrice_select.options[1].value = 500;
	
	maxPrice_select.options[1] = new Option("500");
	maxPrice_select.options[1].value = 500;
	
	minPrice_select.options[2] = new Option("750");
	minPrice_select.options[2].value = 750;
	
	maxPrice_select.options[2] = new Option("750");
	maxPrice_select.options[2].value = 750;
	
	minPrice_select.options[3] = new Option("1,000");
	minPrice_select.options[3].value = 1000;
	
	maxPrice_select.options[3] = new Option("1,000");
	maxPrice_select.options[3].value = 1000;
	
	minPrice_select.options[4] = new Option("10,000");
	minPrice_select.options[4].value = 10000;
	
	maxPrice_select.options[4] = new Option("10,000");
	maxPrice_select.options[4].value = 10000;
	
	minPrice_select.options[5] = new Option("50,000");
	minPrice_select.options[5].value = 50000;
	
	maxPrice_select.options[5] = new Option("50,000");
	maxPrice_select.options[5].value = 50000;
	
	minPrice_select.options[6] = new Option("100,000");
	minPrice_select.options[6].value = 100000;
	
	maxPrice_select.options[6] = new Option("100,000");
	maxPrice_select.options[6].value = 100000;
	
	minPrice_select.options[7] = new Option("150,000");
	minPrice_select.options[7].value = 150000;
	
	maxPrice_select.options[7] = new Option("150,000");
	maxPrice_select.options[7].value = 150000;
	
	minPrice_select.options[8] = new Option("200,000");
	minPrice_select.options[8].value = 200000;
	
	maxPrice_select.options[8] = new Option("200,000");
	maxPrice_select.options[8].value = 200000;
	
	minPrice_select.options[9] = new Option("250,000");
	minPrice_select.options[9].value = 250000;
	
	maxPrice_select.options[9] = new Option("250,000");
	maxPrice_select.options[9].value = 250000;
	
	minPrice_select.options[10] = new Option("300,000");
	minPrice_select.options[10].value = 300000;
	
	maxPrice_select.options[10] = new Option("300,000");
	maxPrice_select.options[10].value = 300000;
	
	minPrice_select.options[11] = new Option("350,000");
	minPrice_select.options[11].value = 350000;
	
	maxPrice_select.options[11] = new Option("350,000");
	maxPrice_select.options[11].value = 350000;
	
	minPrice_select.options[12] = new Option("350,000");
	minPrice_select.options[12].value = 350000;
	
	maxPrice_select.options[12] = new Option("350,000");
	maxPrice_select.options[12].value = 350000;
	
	minPrice_select.options[13] = new Option("400,000");
	minPrice_select.options[13].value = 400000;
	
	maxPrice_select.options[13] = new Option("400,000");
	maxPrice_select.options[13].value = 400000;
	
	minPrice_select.options[14] = new Option("450,000");
	minPrice_select.options[14].value = 450000;
	
	maxPrice_select.options[14] = new Option("450,000");
	maxPrice_select.options[14].value = 450000;
	
	minPrice_select.options[15] = new Option("500,000");
	minPrice_select.options[15].value = 500000;
	
	maxPrice_select.options[15] = new Option("500,000");
	maxPrice_select.options[15].value = 500000;
	
	minPrice_select.options[16] = new Option("600,000");
	minPrice_select.options[16].value = 600000;
	
	maxPrice_select.options[16] = new Option("600,000");
	maxPrice_select.options[16].value = 600000;
	
	minPrice_select.options[17] = new Option("650,000");
	minPrice_select.options[17].value = 650000;
	
	maxPrice_select.options[17] = new Option("650,000");
	maxPrice_select.options[17].value = 650000;
	
	minPrice_select.options[18] = new Option("700,000");
	minPrice_select.options[18].value = 700000;
	
	maxPrice_select.options[18] = new Option("700,000");
	maxPrice_select.options[18].value = 700000;
	
	minPrice_select.options[19] = new Option("750,000");
	minPrice_select.options[19].value = 750000;
	
	maxPrice_select.options[19] = new Option("750,000");
	maxPrice_select.options[19].value = 750000;
	
	minPrice_select.options[20] = new Option("800,000");
	minPrice_select.options[20].value = 800000;
	
	maxPrice_select.options[20] = new Option("800,000");
	maxPrice_select.options[20].value = 800000;
	}
}function propertyInitialise(){

	var property_select = document.getElementById('propertyType');
	property_select.options[1] = new Option("Apartment/Condo");
	property_select.options[1].value = 1;
	property_select.options[2] = new Option("Town Home");
	property_select.options[2].value = 3;
	property_select.options[3] = new Option("Bungalow");
	property_select.options[3].value = 8;
	property_select.options[4] = new Option("Plot/Land");
	property_select.options[4].value = 10;
	property_select.options[5] = new Option("Finca");
	property_select.options[5].value = 13;
	property_select.options[6] = new Option("Cottage");
	property_select.options[6].value = 21;
	property_select.options[7] = new Option("Annexe");
	property_select.options[7].value = 24;
	property_select.options[8] = new Option("Garage");
	property_select.options[8].value = 37;
	property_select.options[9] = new Option("New Type");
	property_select.options[9].value = 38;
	property_select.options[10] = new Option("Coach House");
	property_select.options[10].value = 39;
	property_select.options[11] = new Option("Detached");
	property_select.options[11].value = 40;
	property_select.options[12] = new Option("Semi-Detached");
	property_select.options[12].value = 42;
	property_select.options[13] = new Option("End Terraced");
	property_select.options[13].value = 43;
	property_select.options[14] = new Option("Terraced");
	property_select.options[14].value = 44;
	property_select.options[15] = new Option("Back To Back");
	property_select.options[15].value = 45;
	property_select.options[16] = new Option("Link Detached");
	property_select.options[16].value = 47;

}

var status = "ok";
