/*
	Change county popup in form "searchForm" when mouse over map
	Set county popup in form "searchForm" when mouse clicks on map
*/
var intPopup = 0;
changePopupMouseOver = function (intItem) {
	document.forms[0].County.selectedIndex = intItem;
	}
changePopupMouseOut = function () {
	document.forms[0].County.selectedIndex = intPopup;
	}
changePopupVar = function (intItem) {
	intPopup = intItem;
	document.forms[0].County.selectedIndex = intItem;
	return false;
	}

/*
	Return delimited "integer"
		Accepts: String or integer in form "1000" or 1000
		Returns: String in form "1,000"
*/	
thousands = function (expr, separator) {
	var i, j = 0, s = String(expr), formatted = '';
	
	if( s.indexOf('.') > -1 || s.indexOf(',') > -1 || s.length < 4)
		return s;
	
	for( i = s.length; i >= 0; i--) {
		j++;
		if (j % 3 == 0 && i > 0 && formatted.length < s.length ) 
			formatted = separator + s.substring(i-1, i) + formatted; 
		else
			formatted = s.substring(i-1, i) + formatted;
	}

	return formatted;
}

/*
	Change Price_From popup in form "searchForm"
	Change Price_To popup in form "searchForm"
	Depending on whether the search is for rent or sales
	Accepts: Boolean
	Returns: <nothing>
*/
listBuildPrice = function ( sales ) {
	if ( sales )
		var arrPrice = [ 'no minimum', 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000, 170000, 180000, 190000, 200000, 210000, 220000, 230000, 240000, 250000, 260000, 270000, 280000, 290000, 300000, 310000, 320000, 330000, 340000, 350000, 360000, 370000, 380000, 390000, 400000, 410000, 420000, 430000, 440000, 450000, 460000, 470000, 480000, 490000, 500000, 550000, 600000, 650000, 700000, 750000, 800000, 850000, 900000, 950000, 1000000, 1250000, 1500000, 2000000, 2500000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000, 12000000, 15000000, 'no maximum' ];
	else
		var arrPrice = [ 'no minimum', 50, 75, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 3500, 4500, 5500, 7500, 'no maximum' ];
	for( var i = 0; i < arrPrice.length; i++) {
		if( i == 0 ) {
			document.forms['searchForm']['Price_From'].options[i] = new Option( arrPrice[i], '' );
		} else if ( i < arrPrice.length - 1 ) {
			document.forms['searchForm']['Price_From'].options[i] = new Option( '\u00A3 ' + thousands( arrPrice[i], ',' ), arrPrice[i] );
			document.forms['searchForm']['Price_To'].options[i - 1] = new Option( '\u00A3 ' + thousands( arrPrice[i], ',' ), arrPrice[i] );			
			document.forms['searchForm']['Price_From'].options.length = i + 1;
		} else {
			document.forms['searchForm']['Price_To'].options[i - 1] = new Option( arrPrice[i], '' );
		}
		document.forms['searchForm']['Price_To'].options.length = i;
	}
	document.forms['searchForm']['Price_From'].selectedIndex = 0;
	document.forms['searchForm']['Price_To'].selectedIndex = document.forms['searchForm']['Price_To'].options.length - 1;
}