var areas = ['Colnbrook','Cowley','Denham','Harlington','Harmondsworth','Harmondsworth Village','Hayes','Hillingdon','Hounslow','Ickenham','Langley','Longford','Northolt','Ruislip','Sipson','Slough','Uxbridge','West Drayton','Yeading','Yiewsley'];

function writeAreaInputs() {
	for(var num = 0;num < areas.length;num++) {
		document.write('<input type="checkbox" name="alo');
		document.write(areas[num]);
		document.write('" value="');
		document.write(areas[num]);
		document.write('" class="displaynone" />');
	}
}

function writeAreaOptions() {
	var sel = document.quickform.area;
	
	for(var num = 0;num < areas.length;num++) {
		sel.options[num+1] = new Option(areas[num],num,false,false);
	}
}

function areaChange(val) {
	var sel = document.quickform.area;
	var el = sel.form.elements;

	for(var num = 0;num < areas.length;num++) {
		el[num+5].checked = (val==num+1);
	}
}

function saleLetChange(buy) {
	var frm = document.quickform;
	var mi = frm.lop;
	var ma = frm.hip;
	var pct = 0.05;

	mi.length = 0;
	ma.length = 0;

	if (buy) {
		mi.options[0] = new Option("£0",0,true,true);
		mi.options[1] = new Option("£100,000",100000*(1-pct),false,false);
		mi.options[2] = new Option("£150,000",150000*(1-pct),false,false);
		mi.options[3] = new Option("£200,000",200000*(1-pct),false,false);
		mi.options[4] = new Option("£250,000",250000*(1-pct),false,false);
		mi.options[5] = new Option("£300,000",300000*(1-pct),false,false);
		mi.options[6] = new Option("£400,000",400000*(1-pct),false,false);
		mi.options[7] = new Option("£500,000",500000*(1-pct),false,false);
		mi.options[8] = new Option("£600,000",600000*(1-pct),false,false);
		mi.options[9] = new Option("£700,000",700000*(1-pct),false,false);
		mi.options[10] = new Option("£800,000",800000*(1-pct),false,false);
		mi.options[11] = new Option("£900,000",900000*(1-pct),false,false);
		mi.options[12] = new Option("£1000,000",1000000*(1-pct),false,false);
		mi.options[13] = new Option("£1,250,000",1250000*(1-pct),false,false);
		mi.options[14] = new Option("£1,500,000",1500000*(1-pct),false,false);
		mi.options[15] = new Option("£1,750,000",1750000*(1-pct),false,false);
		mi.options[16] = new Option("£2,000,000",2000000*(1-pct),false,false);
		mi.options[17] = new Option("£2,500,000",2500000*(1-pct),false,false);
		ma.options[0] = new Option("£100,000",100000*(1+pct),false,false);
		ma.options[1] = new Option("£150,000",150000*(1+pct),false,false);
		ma.options[2] = new Option("£200,000",200000*(1+pct),false,false);
		ma.options[3] = new Option("£250,000",250000*(1+pct),false,false);
		ma.options[4] = new Option("£300,000",300000*(1+pct),false,false);
		ma.options[5] = new Option("£400,000",400000*(1+pct),false,false);
		ma.options[6] = new Option("£500,000",500000*(1+pct),false,false);
		ma.options[7] = new Option("£600,000",600000*(1+pct),false,false);
		ma.options[8] = new Option("£700,000",700000*(1+pct),false,false);
		ma.options[9] = new Option("£800,000",800000*(1+pct),false,false);
		ma.options[10] = new Option("£900,000",900000*(1+pct),false,false);
		ma.options[11] = new Option("£1000,000",1000000*(1+pct),false,false);
		ma.options[12] = new Option("£1,250,000",1250000*(1+pct),false,false);
		ma.options[13] = new Option("£1,500,000",1500000*(1+pct),false,false);
		ma.options[14] = new Option("£1,750,000",1750000*(1+pct),false,false);
		ma.options[15] = new Option("£2,000,000",2000000*(1+pct),false,false);
		ma.options[16] = new Option("£2,500,000",2500000*(1+pct),false,false);
		ma.options[17] = new Option("£3,000,000+",1000000000,true,true);
		frm.dbt.value = "1";
	}
	else {
		mi.options[0] = new Option("£0 pcm",0,true,true);
		mi.options[1] = new Option("£400 pcm",400,false,false);
		mi.options[2] = new Option("£500 pcm",500,false,false);
		mi.options[3] = new Option("£600 pcm",600,false,false);
		mi.options[4] = new Option("£700 pcm",700,false,false);
		mi.options[5] = new Option("£800 pcm",800,false,false);
		mi.options[6] = new Option("£900 pcm",900,false,false);
		mi.options[7] = new Option("£1000 pcm",1000,false,false);
		mi.options[8] = new Option("£1250 pcm",1250,false,false);
		mi.options[9] = new Option("£1500 pcm",1500,false,false);
		mi.options[10] = new Option("£2000 pcm",2000,false,false);
		mi.options[11] = new Option("£2500 pcm",2500,false,false);
		ma.options[0] = new Option("£400 pcm",400,false,false);
		ma.options[1] = new Option("£500 pcm",500,false,false);
		ma.options[2] = new Option("£600 pcm",600,false,false);
		ma.options[3] = new Option("£700 pcm",700,false,false);
		ma.options[4] = new Option("£800 pcm",800,false,false);
		ma.options[5] = new Option("£900 pcm",900,false,false);
		ma.options[6] = new Option("£1000 pcm",1000,false,false);
		ma.options[7] = new Option("£1250 pcm",1250,false,false);
		ma.options[8] = new Option("£1500 pcm",1500,false,false);
		ma.options[9] = new Option("£2000 pcm",2000,false,false);
		ma.options[10] = new Option("£2500 pcm",2500,false,false);
		ma.options[11] = new Option("£3000+ pcm",300000,true,true);
		frm.dbt.value = "2";
	}
}

function loadQuickForm() {
	var c_value = getCookie("quick");
	if (c_value == null) {
		saleLetChange(true);
	} else {
		c_array = c_value.split(";");
		if (c_array[0] == 'true') {
			document.getElementById("buy").checked = true;
			saleLetChange(true);
		} else {
			document.getElementById("rent").checked = true;
			saleLetChange(false);
		}
		document.quickform.area.selectedIndex = c_array[1];
		document.quickform.lop.selectedIndex = c_array[2];
		document.quickform.hip.selectedIndex = c_array[3];
	}
	areaChange(document.quickform.area.selectedIndex);
}

function unloadQuickForm() {
	var c_value = document.getElementById("buy").checked.toString()+";"+document.quickform.area.selectedIndex.toString()+";"+document.quickform.lop.selectedIndex.toString()+";"+document.quickform.hip.selectedIndex.toString();
	setCookie("quick",c_value);
}

function quickClick() {
	document.quickform.action = "http://www.vebra.com/home/quick/PFrefine.asp?swdat="+(document.getElementById("buy").checked==true?0:1)+"%3B"+document.getElementById("buy").checked.toString()+"%3B"+document.quickform.area.selectedIndex.toString()+"%3B"+document.quickform.lop.selectedIndex.toString()+"%3B"+document.quickform.hip.selectedIndex.toString();
	document.quickform.submit();
}

function advancedClick() {
	if (document.getElementById("buy").checked) {
		window.location = "http://www.cameron-estateagents.co.uk/index.php?pid=1";
	}
	else {
		window.location = "http://www.cameron-estateagents.co.uk/index.php?pid=2";
	}
}

function minChange(lop, hip) {
	if (lop.selectedIndex > hip.selectedIndex) {
		window.alert("Minimum price must be lower than maximum price");
		lop.selectedIndex = 0;
	}
}

function maxChange(lop, hip) {
	if (lop.selectedIndex > hip.selectedIndex) {
		window.alert("Maximum price must be higher than minimum price");
		hip.selectedIndex = hip.length - 1;	
	}
}

function setCookie(c_name,c_value) {
	var exdate=new Date();
	exdate.setFullYear(exdate.getFullYear() + 1);
	document.cookie=c_name+ "="+escape(c_value)+";path=/"+";expires="+exdate;
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		var c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return null;
}