function saleLetChange() {
	var frm = document.leftform;
	var mi = frm.lop;
	var ma = frm.hip;
	var ar = frm.area;
	var pct = 0.05;

	mi.length = 0;
	ma.length = 0;
	ar.length = 0;

	if (frm.salelet.selectedIndex == 0) {
		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);
		ar.options[0] = new Option("All Areas","all",true,true);
		ar.options[1] = new Option("Baldock","bal",false,false);
		ar.options[2] = new Option("Harpenden","har",false,false);
		ar.options[3] = new Option("Hitchin","hit",false,false);
		ar.options[4] = new Option("Knebworth","kne",false,false);
		//ar.options[5] = new Option("Royston","roy",false,false);
		ar.options[5] = new Option("St Albans","sta",false,false);
		ar.options[6] = new Option("Stevenage","ste",false,false);
		ar.options[7] = new Option("W.G.C.","wgc",false,false);
		//ar.options[8] = new Option("Wheathampstead","whe",false,false);
		frm.action = "http://www.vebra.com/home/solex/refine.asp";
		//frm.fid.value = "11002";
		//frm.dbt.value = "1";
		frm.nba.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);
		ar.options[0] = new Option("All Areas","all",true,true);
		ar.options[1] = new Option("Baldock","bal",false,false);
		ar.options[2] = new Option("Harpenden","har",false,false);
		ar.options[3] = new Option("Hitchin","hit",false,false);
		ar.options[4] = new Option("Knebworth","kne",false,false);
		//ar.options[5] = new Option("Radlett","rad",false,false);
		//ar.options[6] = new Option("Royston","roy",false,false);
		ar.options[5] = new Option("St Albans","sta",false,false);
		ar.options[6] = new Option("Stevenage","ste",false,false);
		ar.options[7] = new Option("W.G.C.","wgc",false,false);
		//ar.options[9] = new Option("Wheathampstead","whe",false,false);
		frm.action = "http://www.cfpsoftwarehosting02.co.uk/putterills/";
		//frm.fid.value = "17002";
		//frm.dbt.value = "2";
		frm.nba.value = "Baldock,Letchworth,Royston,Ashwell,Steeple Morden,Rushden,Harpenden,Sandridge,Wheathampstead,Gustard Wood,Redbourn,Flamstead,Markyate,Caddington,Kimpton,Whitwell,Hitchin,Letchworth,Hexton,Shillington,Pirton,Weston,Lilley,Gosmore,Preston,Stotfold,Arlesey,Knebworth,Codicote,Oaklands,Datchworth,Aston,Stevenage,St Albans,Graveley,Walkern,Sacombe,Benington,Welwyn Garden City,WGC,Hertford,Tewin,Digswell,Welwyn,Hatfield,Essendon";
	}
}

function areaChange(area) {
	var val = area.value;
	var el = area.form.elements;
	if (document.leftform.salelet.selectedIndex == 0) {
		//sales
		var bal = (val == "bal");
		var har = (val == "har");
		var hit = (val == "hit");
		var kne = (val == "kne");
		var rad = (val == "rad");
		var roy = (val == "roy");
		var sta = (val == "sta");
		var ste = (val == "ste");
		var wgc = (val == "wgc");
		var whe = (val == "whe");
		el['aloWest Side'].checked = wgc;
		el['aloWelwyn Garden City Others'].checked = wgc;
		el['aloWelwyn Village and Oaklands'].checked = wgc;
		el['aloWGC Surrounding Villages'].checked = wgc;
		el['aloHatfield'].checked = wgc;
		el['aloHatfield Surrounding Villages'].checked = wgc;
		el['aloHertford and Surrounding Villages'].checked = wgc;
		el['aloWare and Surrounding Villages'].checked = wgc;
		el['aloWheathampstead'].checked = har;
		el['aloWheathampstead Surrounding Villages'].checked = har;
		el['aloHarpenden'].checked = har;
		el['aloHarpenden Surrounding Villages'].checked = har;
		el['aloRedbourn and Markyate'].checked = har;
		el['aloKnebworth'].checked = kne;
		el['aloKnebworth Surrounding Villages'].checked = kne;
		el['aloWelwyn Village and Oaklands'].checked = kne;
		el['aloSt Albans'].checked = sta;
		el['aloStevenage Old Town'].checked = ste;
		el['aloStevenage'].checked = ste;
		el['aloStevenage Surrounding Villages'].checked = ste;
		el['aloHitchin'].checked = hit;
		el['aloHitchin Surrounding Villages South'].checked = hit;
		el['aloHitchin Surrounding Villages North'].checked = hit;
		el['aloLetchworth'].checked = bal || hit;
		el['aloBaldock'].checked = bal;
		el['aloBaldock Surrounding Villages'].checked = bal;
		el['aloBiggleswade Surrounding Villages'].checked = bal;
		el['aloRoyston'].checked = hit;
		el['aloRoyston Surrounding Villages South'].checked = hit;
		el['aloRoyston Villages North and Cambs'].checked = hit;
		el['aloRoyston Surrounding Villages West'].checked = hit;
	}
	else {
		//lettings
		var el2 = area.form.nba;
		switch(val) {
			case "all":
				el2.value = "Baldock,Letchworth,Royston,Ashwell,Steeple Morden,Rushden,Harpenden,Sandridge,Wheathampstead,Gustard Wood,Redbourn,Flamstead,Markyate,Caddington,Kimpton,Whitwell,Hitchin,Letchworth,Hexton,Shillington,Pirton,Weston,Lilley,Gosmore,Preston,Stotfold,Arlesey,Knebworth,Codicote,Oaklands,Datchworth,Aston,St Albans,Stevenage,Graveley,Walkern,Sacombe,Benington,Welwyn Garden City,WGC,Hertford,Tewin,Digswell,Welwyn,Hatfield,Essendon";
				break;
			case "bal":
				el2.value = "Baldock,Letchworth,Royston,Ashwell,Steeple Morden,Rushden";
				break;
			case "har":
				el2.value = "Harpenden,Sandridge,Wheathampstead,Gustard Wood,Redbourn,Flamstead,Markyate,Caddington,Kimpton,Whitwell";
				break;
			case "hit":
				el2.value = "Hitchin,Letchworth,Hexton,Shillington,Pirton,Weston,Lilley,Gosmore,Preston,Stotfold,Arlesey";
				break;
			case "kne":
				el2.value = "Knebworth,Codicote,Oaklands,Datchworth,Aston";
				break;
			case "sta":
				el2.value = "St Albans";
				break;
			case "ste":
				el2.value = "Stevenage,Graveley,Walkern,Sacombe,Benington";
				break;
			case "wgc":
				el2.value = "Welwyn Garden City,WGC,Hertford,Tewin,Digswell,Welwyn,Hatfield,Essendon";
				break;
		}
	}
}

function loadLeftForm() {
	c_value = getCookie("left");
	document.leftform.reset();
	if (c_value == null) {
		saleLetChange();
	} else {
		c_array = c_value.split(";");
		document.leftform.salelet.selectedIndex = c_array[0];
		saleLetChange();
		document.leftform.area.selectedIndex = c_array[1];
		areaChange(document.leftform.area);
		document.leftform.lop.selectedIndex = c_array[2];
		document.leftform.hip.selectedIndex = c_array[3];
		document.leftform.salelet.selectedIndex = c_array[4];
	}
}

function quickClick() {
	c_value = document.leftform.salelet.selectedIndex.toString()+";"+document.leftform.area.selectedIndex.toString()+";"+document.leftform.lop.selectedIndex.toString()+";"+document.leftform.hip.selectedIndex.toString()+";"+document.leftform.salelet.selectedIndex.toString();
	setCookie("left",c_value);
	document.leftform.submit();
}

function advancedClick() {
	var s = document.leftform.salelet;

	if (s.options[s.selectedIndex].value == "sale") {
		window.location = "http://www.putterills.co.uk/sales/sales.html";
	}
	else {
		window.location = "http://www.putterills.co.uk/lettings/lettings.html";
	}
}

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) {
		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;
}
