function insertSearch(loc,searchString) {
	place = loc.indexOf("£");
	if (place>=0) {
		loc = loc.substring(0,place)
			+searchString
			+loc.substring(place+1,loc.length);
	}
return loc;
}
function makePropertySearch(loc,city,minPrice,maxPrice,minBeds) {
	var newString=replaceString(loc,'£City£',city);
	newString=replaceString(newString,'£MinPrice£',minPrice);
	newString=replaceString(newString,'£MaxPrice£',maxPrice);
	newString=replaceString(newString,'£MinBeds£',minBeds);
return newString;
}
function getParameter(paramName) {
	var query=this.location.search.substring(1);
	if (query.length > 0){
		var params=query.split("&");
		for (var i=0;i<params.length;i++){
			var pos = params[i].indexOf("=");
			var name = params[i].substring(0,pos);
			if (name == paramName) {
				var value = params[i].substring(pos+1);
			}
		}
	}
return value;
}
function getParentParameter(paramName) {
	var query=parent.location.search.substring(1);
	var value = "";
	if (query.length > 0){
		var params=query.split("&");
		for (var i=0;i<params.length;i++){
			var pos = params[i].indexOf("=");
			var name = params[i].substring(0,pos);
			if (name == paramName) {
				value = params[i].substring(pos+1);
			}
		}
	}
return value;
}
function replaceString(bigString,subString,replaceString) {
	newString=bigString;
	place = newString.indexOf(subString);
	
	while (place>=0) {
		newString = newString.substring(0,place)+replaceString
			+newString.substring(place+subString.length,newString.length);
		place = newString.indexOf(subString);
	}
return newString;
}
function cleanSearch(searchString) {
	place = searchString.indexOf(" ");
	while (place>=0) {
		searchString = searchString.substring(0,place)+"+"
			+searchString.substring(place+1,searchString.length);
		place = searchString.indexOf(" ");
	}
return searchString;
}
function doReturn() {
	if (event.keyCode==13) {
		goSearch();
	}
}
function settd() {
	var td = "http://trac";
	td += "ker.";
	td += "trad";
	td += "edoub";
	td += "ler.com";
return td;
}
function setLocations() {
	td = settd();
	var any = [
	["http://www.home.co.uk/search/results.htm?location=£City£&TOWN_SEARCH=1&MAP_SEARCH=&high=£MaxPrice£&low=£MinPrice£&minbeds=£MinBeds£&maxbeds=&radius=4","Home.co.uk",false],
	["http://www.propertyfinder.com/cgi-bin/rsearch?a=s&cu=fn-pfc&s=&ss=&ag=&t=res&snf=rbs&chk=0&lead=&ty=&tb=£City£&u=£City£&pm=£MinPrice£&px=£MaxPrice£&minbed=£MinBeds£&maxbed=&cat=&o=def","Property Finder",false],
	["http://www.findaproperty.com/searchresults.aspx?loc=£City£&minprice=£MinPrice£&maxprice=£MaxPrice£&bedrooms=£MinBeds£&res=0&salerent=0&edid=0&f.x=0&f.y=0","Find a Property",false],
	["http://www.homemarketeer.com/homes/homes.htm","HomeMarketeer",false]
	];
	locs = [any];
return locs;
}
function getName(selected,defaultValue) {
	var names=["1","2","3","4","5","6","7","8","9"];
	if ((selected>=0) && (selected<names.length)) {
		selected=names[selected];
	} else {
		selected = defaultValue;
	}
	return selected;
}
function getSearchString(searchString) {
	if (searchString == "") {
		searchString="";
	} else {
		searchString=cleanSearch(searchString);
	}
	return searchString;
}
function search(city,minPrice,maxPrice,minBeds) {
	var isNav, isIE;
	if(parseInt(navigator.appVersion)>=4) {
		if (navigator.appName == "Netscape") {
			isNav = true;
		} else {
			isNav = false;
		}
	}
	
	locs=setLocations();
	
	selected = 0;
	if (isNav) {
		thisHeight = window.innerHeight;
		thisWidth = window.innerWidth;
	} else {
		thisHeight = document.body.clientHeight;
		thisWidth = document.body.clientWidth;
	}
	urls = new Array(locs[selected].length);
	for (var i=0;i<locs[selected].length;i++) {
		urls[i] = makePropertySearch(locs[choice][i][0],city,minPrice,maxPrice,minBeds);
	}
return urls;
}
function goSearch() {
	location.href="../property_search/search.htm?City="
	+ document.frmPS.elements.City.value
	+ "&MinPrice="
	+ document.frmPS.elements.MinPrice.value
	+ "&MaxPrice="
	+ document.frmPS.elements.MaxPrice.value
	+ "&MinBeds="
	+ getName(document.frmPS.MinBeds.selectedIndex,0);
}
function goSearchRoot() {
	location.href="property_search/search.htm?City="
	+ document.frmPS.elements.City.value
	+ "&MinPrice="
	+ document.frmPS.elements.MinPrice.value
	+ "&MaxPrice="
	+ document.frmPS.elements.MaxPrice.value
	+ "&MinBeds="
	+ getName(document.frmPS.MinBeds.selectedIndex,0);
}
function goSearchFor(searchString,searchType) {
	location.href="../property_search/search.htm?City="
	+ document.frmPS.elements.City.value
	+ "&MinPrice="
	+ document.frmPS.elements.MinPrice.value
	+ "&MaxPrice="
	+ document.frmPS.elements.MaxPrice.value
	+ "&MinBeds="
	+ getName(document.frmPS.MinBeds.selectedIndex,0);
}
function setGoogle(city,minPrice,maxPrice,minBeds) {
	if (minBeds) {
		beds=" with "+getName(minBeds,2)+" bedrooms";
	} else {
		beds=" with 2 bedrooms";
	}
	document.google.q.value = 'house for sale in '+city.value+beds;
}
