
/* ---- 
set defaults for Counties if RegionData fails to load
 ---- */

var _ServerPath = "http://realestate.sfgate.com/RealEstate";
//var _ServerPath = "http://re.gabriels.net/Newspapers/sfgate/realestate";

 
if (!RegionData) {
  alert("!regiondata");
	var RegionData = new Array();
	
	RegionData[0] = new Array(6001,10,10,"All Alameda County",0,0,0,0,0,0);
	RegionData[1] = new Array(6013,11,11,"All Contra Costa County",0,0,0,0,0,0);
	RegionData[2] = new Array(6041,12,12,"All Marin County",0,0,0,0,0,0);
	RegionData[3] = new Array(6055,13,13,"All Napa County",0,0,0,0,0,0);
	RegionData[4] = new Array(6075,14,14,"All San Francisco City/County",0,0,0,0,0,0);
	RegionData[5] = new Array(6081,15,15,"All San Mateo County",0,0,0,0,0,0);
	RegionData[6] = new Array(6085,16,16,"All Santa Clara County",0,0,0,0,0,0);
	RegionData[7] = new Array(6095,17,17,"All Solano County",0,0,0,0,0,0);
	RegionData[8] = new Array(6095,18,18,"All Sonoma County",0,0,0,0,0,0);
}


function loadCountiesNewCon(theForm) {

	var C = theForm.PCounties;
	var L = MarketData;
	var thisCNT = 0;
	var allCountyCNT = 0;	
	var typeIndex = 0;
	var tempCount = 1;
	
	C.className = 'enabled';
	C.disabled = false;
	C.selectedIndex = 0;
	C.length = 200;

	for (x=0;x<L.length;x++) {
	
		switch(L[x][1]) {
		case "Oakland-Alameda":
			L[x][1] = "Alameda-Contra Costa County";
			break;
		case "San Jose":
			L[x][1] = "Santa Clara County";
			break;
		case "Vallejo-Napa":
			L[x][1] = "Solano-Napa County";
			break;
		}
		
		// no duplicate entries
		if (x==0) {
			C[tempCount].value = L[x][0];
			C[tempCount].text = L[x][1];
			tempCount++;
		}
		else 
			if (L[x][1] != L[x-1][1]) {
				C[tempCount].value = L[x][0];
				C[tempCount].text = L[x][1];
				tempCount++;
		}
	}
	
	C.length = tempCount;
	
}


function loadRegionsNewCon(theForm,pickedSubCounty) {

	var R = theForm.RegionIds;
	var C = theForm.PCounties;
	var L = MarketData;
	var thisCNT = 0;
	var allCountyCNT = 0;	

	var typeIndex = 0;
	
	R.className = 'enabled';
	R.disabled = false;
	R.selectedIndex = 0;
	R.length = 200;	
	var tempCount;
	tempCount = 1;

	if (pickedSubCounty != "27,35,39,41")  // TODO: un-hardcode
	{
	pickedSubCounty = Math.round(pickedSubCounty); /* ----  we convert the passed sub-county to a number dropping the leading zero  ---- */
	var tempRegions = new Array();
	var loopSubCounty;	

//	RegionData[0] = new Array(6001,10,10,"All Alameda County",0,0,0,0,0,0);
//	                         (27,"vallejo","city",11211,CA);
	
	for (x=0;x<L.length;x++) {
	
		if (L[x][0] == pickedSubCounty) { 
			
			// no duplicate entries
			if (L[x][2] != R[tempCount - 1].text) {
				R[tempCount].value = L[x][3]; 
				R[tempCount].text = L[x][2]; // + " (" + L[x][3] + ")";
				tempCount++;
			}
		}
	}
	
} else {
	//alert ("Selected all counties");
	tempCount = 1;
	R[0].value = ""; 
	R[0].text = "";
	R[0].selectedIndex=0;
	//alert (allCountyCNT);
	
	///////////////////////////////////////////////PH

	//alert ("here:" + allCountyCNT + "x:" + x);
		
	R[0].value = pickedSubCounty;
	R[0].text = "All Counties";
				
	/////////////////////////////////////////////////////////PH

	//alert (allCountyCNT);
}

 	if (pickedSubCounty == "19") {   //quick fix to handle out of bay areas
		R.length = tempCount-1;		
	}
	else {
		R.length = tempCount;		
	}
}




function loadRegions(theForm,pickedSubCounty) {

//alert('Error #256');

	var R = theForm.RegionIds;
	var C = theForm.PCounties;
	var L = RegionData;
	var thisCNT = 0;
	var allCountyCNT = 0;	

	var typeIndex = 0;
	
	R.className = 'enabled';
	R.disabled = false;
	R.selectedIndex = 0;
	R.length = 200;	
	var tempCount;
	tempCount = 1;
	
	
	if (pickedSubCounty.indexOf(",") < 0)
	{
	pickedSubCounty = Math.round(pickedSubCounty); /* ----  we convert the passed sub-county to a number dropping the leading zero  ---- */
	var tempRegions = new Array();
	var loopSubCounty;
	for (x=0;x<L.length;x++) {

		if (L[x][2] == pickedSubCounty) { /* ----  Get All County Count  ---- */
			if (L[x][1] == L[x][2]) { 
		
		/* ----		
		'RegionData[x][4] = (Broker) Rentals Listings
		'RegionData[x][5] = (Broker) Sales Listings
		'RegionData[x][6] = (Broker) Open House Listings
		
		'RegionData[x][7] = (Classified) Rentals Listings
		'RegionData[x][8] = (Classified) Sales Listings
		'RegionData[x][9] = (Classified) Open House Listings
		---- */
		
			if (theForm.passROS.value == "S") {
				
				if (theForm.chrononly.checked) {
					if (theForm.OHOnly.checked) {
						allCountyCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
						//alert('Chronicle Open House ' + allCountyCNT);
					} else {
						allCountyCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
						//alert('Chronicle Sales All ' + allCountyCNT);
					}
				} else {
					if (theForm.OHOnly.checked) {
						allCountyCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						//alert('Both - Sales - Open House ' + allCountyCNT);
					} else {
						allCountyCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						//alert('Both - Sales - All ' + allCountyCNT);
					}
				}
			}
			}
			//alert (theForm.passROS.value);
			if (theForm.passROS.value == "R") {
				if (theForm.chrononly.checked) {
					allCountyCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
				} else {
					allCountyCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
				}
			}
			
			
			//allCountyCNT = addCommas(allCountyCNT);
			
				//PH
				//alert(allCountyCNT);

				if (allCountyCNT > 0) 
				{
				allCountyCNT = addCommas(allCountyCNT);
					R[0].value = L[x][1];
					R[0].text = "*" + L[x][3] + " (" + allCountyCNT + ")";
				
				} else {
				//allCountyCNT = addCommas(allCountyCNT);
					//R[0].value = L[x][1];
					//R[0].text = "*0*" + L[x][3] + " (" + allCountyCNT + ")";
							R[0].text = "No Available Listings";
							R[0].value = 0;
							R.className = 'disabled';
							//alert("1");
							R.disabled = true;
						
				} //PH
			
		} else { /* ----  get regions, push into tempRegions  ---- */
		
			loopSubCounty = L[x][1];  
			
			if (pickedSubCounty == loopSubCounty) {
				if (theForm.passROS.value == "S") {
					if (theForm.chrononly.checked) {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
						} else {
							thisCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
						}
					} else {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						} else {
							thisCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						}
					}
				}
				
				if (theForm.passROS.value == "R") {
					if (theForm.chrononly.checked) {
						thisCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
					} else {
						thisCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
					}
				}

			
		   
					R[tempCount].value = L[x][2]; 
					R[tempCount].text = L[x][3] + " (" + addCommas(thisCNT) + ")" ;
					tempCount = tempCount + 1;
				}
				

		}
	}
} else {
	tempCount = 1;
	R[0].value = ""; 
	R[0].text = "";
	R[0].selectedIndex=0;
	
	///////////////////////////////////////////////PH
	
	//alert("pickedSubCounty - " + pickedSubCounty);
	
	var	pickedSubCountyArray = pickedSubCounty.split(",");
	var pickedSubCountyNoArea = "";
	for (x=1;x<pickedSubCountyArray.length;x++)
		var pickedSubCountyNoArea = pickedSubCountyNoArea + "," + pickedSubCountyArray[x];
	var pickedArea;
	
	for (x=0;x<L.length;x++) 
	{
		for (y=1;y<pickedSubCountyArray.length;y++)
		{
			if ((L[x][2] == pickedSubCountyArray[y]) && (L[x][10] == pickedSubCountyArray[0])) {
				pickedArea = L[x][11];
				//alert(x + " - " + L[x][2] + " - " + L[x][11]);
				if (theForm.passROS.value == "S") {
					
					if (theForm.chrononly.checked) {
						if (theForm.OHOnly.checked) {
							allCountyCNT = allCountyCNT + L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
							//alert('Chronicle Open House ' + allCountyCNT);
						} else {
							allCountyCNT = allCountyCNT + L[x][8];  /* ---- Chronicle - Sales - All ---- */
							//alert('Chronicle Sales All ' + allCountyCNT);
						}
					} else {
						if (theForm.OHOnly.checked) {
							allCountyCNT = allCountyCNT + L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
							//alert('Both - Sales - Open House ' + allCountyCNT);
						} else {
							allCountyCNT = allCountyCNT + L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
							//alert('Both - Sales - All ' + allCountyCNT);
						}
					}
				}
	
				if (theForm.passROS.value == "R") {
					if (theForm.chrononly.checked) {
						allCountyCNT =  allCountyCNT + L[x][7];  /* ---- Chronicle - Rentals - All ---- */
					} else {
						allCountyCNT = allCountyCNT + L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
					}
				}			
			}
		}
	}
		
	//alert ("allCountyCNT:" + allCountyCNT + "  x:" + x);
	if (allCountyCNT > 0) 
				{
				allCountyCNT = addCommas(allCountyCNT);
					R[0].value = pickedSubCountyNoArea;
					R[0].text = "All " + pickedArea + " (" + allCountyCNT + ")";
				
				} else {
				//allCountyCNT = addCommas(allCountyCNT);
					//R[0].value = L[x][1];
					//R[0].text = "*0*" + L[x][3] + " (" + allCountyCNT + ")";
							R[0].text = "No Available Listings";
							R[0].value = 0;
							R.className = 'disabled';
							R.disabled = true;
						
				}
				
	

	/////////////////////////////////////////////////////////PH

	//alert (allCountyCNT);
}

 
 	if (pickedSubCounty == "") {   //quick fix to handle out of bay areas
		R.length = tempCount-1;
		//	alert("19!!");
	}
	else {
		R.length = tempCount;	
		//alert("tempcount - " + tempCount);	
	}

}



function loadRegions_olf(theForm,pickedSubCounty) {

	
	var R = theForm.RegionIds;
	var C = theForm.PCounties;
	var L = RegionData;
	var thisCNT = 0;
	var allCountyCNT = 0;	

	var typeIndex = 0;
	
	R.className = 'enabled';
	R.disabled = false;
	R.selectedIndex = 0;
	R.length = 200;	
	var tempCount;
	tempCount = 1;
	//alert (pickedSubCounty);
	if (pickedSubCounty != "10,11,12,13,14,15,16,17,18")
	{
		pickedSubCounty = Math.round(pickedSubCounty); /* ----  we convert the passed sub-county to a number dropping the leading zero  ---- */
		var tempRegions = new Array();
		var loopSubCounty;
		for (x=0;x<L.length;x++) {

			if (L[x][2] == pickedSubCounty) { /* ----  Get All County Count  ---- */
				if (L[x][1] == L[x][2]) { 
		
			/* ----		
			'RegionData[x][4] = (Broker) Rentals Listings
			'RegionData[x][5] = (Broker) Sales Listings
			'RegionData[x][6] = (Broker) Open House Listings
		
			'RegionData[x][7] = (Classified) Rentals Listings
			'RegionData[x][8] = (Classified) Sales Listings
			'RegionData[x][9] = (Classified) Open House Listings
			---- */
		
					if (theForm.passROS.value == "S") {
				
						if (theForm.chrononly.checked) {
							if (theForm.OHOnly.checked) {
								allCountyCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
								//alert('Chronicle Open House ' + allCountyCNT);
						} else {
							allCountyCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
							//alert('Chronicle Sales All ' + allCountyCNT);
						}
					} else {
						if (theForm.OHOnly.checked) {
							allCountyCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						//alert('Both - Sales - Open House ' + allCountyCNT);
					} else {
						allCountyCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						//alert('Both - Sales - All ' + allCountyCNT);
					}
				}
			}
			}
	
			if (theForm.passROS.value == "R") {
				if (theForm.chrononly.checked) {
					allCountyCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
				} else {
					allCountyCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
				}
			}
			
			
			allCountyCNT = addCommas(allCountyCNT);
			
				//PH
				if (allCountyCNT > 0) 
				{
				allCountyCNT = addCommas(allCountyCNT);
					R[0].value = L[x][1];
					R[0].text = "*" + L[x][3] + " (" + allCountyCNT + ")";
				
				} else {
				//allCountyCNT = addCommas(allCountyCNT);
					//R[0].value = L[x][1];
					//R[0].text = "*0*" + L[x][3] + " (" + allCountyCNT + ")";
							R[0].text = "No Available Listings";
							R[0].value = 0;
							R.className = 'disabled';
							R.disabled = true;
						
				} //PH
			
		} else { /* ----  get regions, push into tempRegions  ---- */
		
			loopSubCounty = L[x][1];  
			
			if (pickedSubCounty == loopSubCounty) {
				if (theForm.passROS.value == "S") {
					if (theForm.chrononly.checked) {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
						} else {
							thisCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
						}
					} else {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						} else {
							thisCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						}
					}
				}
				
				if (theForm.passROS.value == "R") {
					if (theForm.chrononly.checked) {
						thisCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
					} else {
						thisCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
					}
				}

			
		   
					R[tempCount].value = L[x][2]; 
					R[tempCount].text = L[x][3] + " (" + addCommas(thisCNT) + ")" ;
					tempCount = tempCount + 1;
				}
				
				//PH
					if (allCountyCNT > 0) 
				{
				allCountyCNT = addCommas(allCountyCNT);
					R[0].value = L[x][0];
					R[0].text = "*" + L[x][3] + " (" + allCountyCNT + ")";
				
				} else {
				//allCountyCNT = addCommas(allCountyCNT);
					//R[0].value = L[x][1];
					//R[0].text = "*0*" + L[x][3] + " (" + allCountyCNT + ")";
							R[0].text = "No Available Listings";
							R[0].value = 0;
							R.className = 'disabled';
							//R.disabled = true;
						
				}
			//PH
		}
	}


} else {
	//alert ("Selected all counties");
}


R.length = tempCount;	
}

function loadRegions_tmpold(theForm,pickedSubCounty) {

	
	var R = theForm.RegionIds;
	var C = theForm.PCounties;
	var L = RegionData;
	var thisCNT = 0;
	var allCountyCNT = 0;	

	var typeIndex = 0;
	
	R.className = 'enabled';
	R.disabled = false;
	
	
	pickedSubCounty = Math.round(pickedSubCounty); /* ----  we convert the passed sub-county to a number dropping the leading zero  ---- */
	var tempRegions = new Array();
	var loopSubCounty;
	for (x=0;x<L.length;x++) {

		if (L[x][2] == pickedSubCounty) { /* ----  Get All County Count  ---- */
		
		/* ----		
		'RegionData[x][4] = (Broker) Rentals Listings
		'RegionData[x][5] = (Broker) Sales Listings
		'RegionData[x][6] = (Broker) Open House Listings
		
		'RegionData[x][7] = (Classified) Rentals Listings
		'RegionData[x][8] = (Classified) Sales Listings
		'RegionData[x][9] = (Classified) Open House Listings
		---- */
		
			if (theForm.passROS.value == "S") {
				if (theForm.chrononly.checked) {
					if (theForm.OHOnly.checked) {
						allCountyCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
						//alert('Chronicle Open House ' + allCountyCNT);
					} else {
						allCountyCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
						//alert('Chronicle Sales All ' + allCountyCNT);
					}
				} else {
					if (theForm.OHOnly.checked) {
						allCountyCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						//alert('Both - Sales - Open House ' + allCountyCNT);
					} else {
						allCountyCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						//alert('Both - Sales - All ' + allCountyCNT);
					}
				}
			}
			
			if (theForm.passROS.value == "R") {
				if (theForm.chrononly.checked) {
					allCountyCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
				} else {
					allCountyCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
				}
			}
			
			
			allCountyCNT = addCommas(allCountyCNT);
			
			
		} else { /* ----  get regions, push into tempRegions  ---- */
		
			loopSubCounty = L[x][1];  
			
			if (pickedSubCounty == loopSubCounty) {
				if (theForm.passROS.value == "S") {
					if (theForm.chrononly.checked) {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9];   /* ---- Chronicle - Sales - Open House ---- */
						} else {
							thisCNT = L[x][8];  /* ---- Chronicle - Sales - All ---- */
						}
					} else {
						if (theForm.OHOnly.checked) {
							thisCNT = L[x][9] + L[x][6]; /* ---- Both - Sales - Open House ---- */
						} else {
							thisCNT = L[x][5] + L[x][8]; /* ---- Both - Sales - All ---- */
						}
					}
				}
				
				if (theForm.passROS.value == "R") {
					if (theForm.chrononly.checked) {
						thisCNT = L[x][7];  /* ---- Chronicle - Rentals - All ---- */
					} else {
						thisCNT = L[x][7] + L[x][4]; /* ---- Both - Rentals - All ---- */
					}
				}
			}
			
			if (thisCNT > 0) {
				tempRegions.push(new Array(L[x][2],L[x][3],addCommas(thisCNT)));		
			}
		}
	}
	
	var T = tempRegions;
		
	R.disabled = false;
	R.className = 'enabled';
	R.selectedIndex = 0;
	R.length = tempRegions.length+1;
						//alert('allCountyCNT: ' + allCountyCNT);	
	if (allCountyCNT > 0) {
		R[0].text = "All " + C.options[C.selectedIndex].text + " (" + allCountyCNT + ") ";
		R[0].value = pickedSubCounty;
	} else {
		if (C.selectedIndex == 1) { // All Counties
			R[0].text = "All Coverage Area";
			R[0].value = C.options[C.selectedIndex].value;
			R.className = 'disabled';
			R.disabled = true;
		} else {
			R[0].text = "No Available Listings";
			R[0].value = 0;
			R.className = 'disabled';
			R.disabled = true;
		}
	}
	
	for (x=0;x<T.length;x++) {
		R[x+1].value = T[x][0]; 
		R[x+1].text = T[x][1] + " (" + T[x][2] + ") ";
	}

}

function doSearch2(theForm) {

	var R = theForm.RegionIds;
	var mid = theForm.PCounties.value;
	//var zip = theForm.RegionIds.value;
	
	var	city = theForm.RegionIds[R.selectedIndex].text
	var cty = city.split(" (");
	var pl = theForm.pl.value;
	var ph = theForm.ph.value;
	var cityname = cty[0];
	if (cityname == "Please select a city")
		cityname = "";
	var cityname = cityname.replace(" ","+");
	
	
	if (pl == "undefined")
		pl = "";
	if (ph == "undefined")
		ph = "";
		
	theForm.action = "http://www.newhomesource.com/sfchroniclenewcon/communityresults/pid-86/market-" + mid + "/city-" + cityname + "/pricelow-" + pl + "/pricehigh-" + ph + "/searchtype-qscr";
	//alert(theForm.action);
}




function doSearch(theForm) {

	var R = theForm.RegionIds;
	var C = theForm.PCounties;
	var LP = theForm.LPrice;
	var HP = theForm.HPrice;
	var L = RegionData;
	
	
	if (C.selectedIndex == 0) {
		window.alert("Please select a county to begin your search.");
		C.focus();
		return;
	}
	if (R.options[R.selectedIndex].value == 0) {
		window.alert("Sorry, there are no listings available in your selection at this time. \n\nPlease choose another area to begin your search.");
		C.focus();
		return;
	}
  	if (parseInt(LP.options[LP.selectedIndex].value) > parseInt(HP.options[HP.selectedIndex].value)) {
		alert("The \"TO\" Price should be Higher or equal to the \"FROM\" Price.");
    	document.sales.HPrice.focus();
		return;
  	}
	if (C.selectedIndex > 0 || C.length == 1) {
	
		C.disabled = false;
		R.disabled = false;
		theForm.PC.value = C.selectedIndex-1;
		checkFilters(theForm);
		theForm.submit();
		
	} else {
		/* ---- 	to search in an entire county, the sub-county IDS need to be gathered.  ---- */
		var tempSubCounties = '';
		var theCounty = C.options[C.selectedIndex].value;
		theCounty = Math.round(theCounty); /* ----  we convert the county to a number dropping the leading zero  ---- */
		for (x=0;L[x][2]<100;x++) { /* ----  we only need counties, so we only loop until the countyID threshhold has been reached in RegionID  ---- */
			loopCounty = L[x][0];
			if (theCounty == loopCounty) {
				tempSubCounties += L[x][1] + ',';
			}
		}

		R.options[0].value = tempSubCounties;
		R.selectedIndex = 0;
		R.disabled = false;
		
		theForm.PC.value = C.selectedIndex-1;
		checkFilters(theForm);
		theForm.submit();
	}
}
 
 
function checkFilters(theForm) {
	if (theForm.chrononly.checked) {
		theForm.cid.value = '20';
	} else {
		theForm.cid.value = '999';
	}
	if (theForm.OHOnly.checked) {
		theForm.action = _ServerPath + "/OpenHouses/SearchResults.asp";
	} else {
		if (theForm.passROS.value == 'R') {
			theForm.action = _ServerPath + "/rentals/searchresults.asp";
		} else {
			theForm.action = _ServerPath + "/sales/searchresults.asp";
		}
	}
}

function addCommas(theNumber) {
	theNumber = '' + theNumber;
	if (theNumber.length > 3) {
		var mod = theNumber.length % 3;
		var formattedNumber = (mod > 0 ? (theNumber.substring(0,mod)) : '');
		for (i=0;i<Math.floor(theNumber.length/3);i++) {
			if ((mod == 0) && (i == 0)) {
				formattedNumber += theNumber.substring(mod+ 3 * i, mod + 3 * i + 3);
			} else {
				formattedNumber+= ',' + theNumber.substring(mod + 3 * i, mod + 3 * i + 3);
			}
		}
		return (formattedNumber);
	} else {
		return theNumber;
	}
}

function resetRegions(theForm) {
	var R = theForm.RegionIds;
	var P = theForm.PCounties;
	
		
		R.length = 1;
		R.options[0].value = '';
		R.options[0].text = '';
		R.selectedIndex = 0;
		R.disabled = true;
		R.className = 'disabled';
		
		theForm.PCounties.selectedIndex = 0;
		
}


function searchType(searchType) {
	hideAllSearchType();
	eval("document.getElementById('" + searchType + "').className = 'Search-Live';");
}

function hideAllSearchType() {
	var mySearches = new Array('ByCounty','ByCity','ByAddress');
	for (x=0;x<mySearches.length;x++) {
		document.getElementById(mySearches[x]).className = 'Search-Dead';
	}
}

function trim(str){ 
	return str.replace(/^\s+|\s+$/gm,''); 
}

function doCitySearch() {
	
	var theForm = document.citysearch;
	
	if (trim(theForm.searchby.value).length < 1) {
		window.alert("Please enter a search term for your city search");
		theForm.searchby.value = trim(theForm.searchby.value);
		theForm.searchby.focus();
		return;
	}
	theForm.submit();
}

function doAddressSearch() {
	
	var theForm = document.searchAddress;
	
	if (trim(theForm.searchby.value).length < 1) {
		window.alert("Please enter a search term for your address search");
		theForm.searchby.value = trim(theForm.searchby.value);
		theForm.searchby.focus();
		return;
	}
	theForm.submit();
}

/*function reset() {
document.sales.PCounties.selectedIndex = 0;
document.sales.RegionIds.selectedIndex = 0;
document.sales.BRooms.selectedIndex = 0;
document.sales.HPrice.selectedIndex = 0;
document.sales.OHOnly.checked = false;
}*/


