// JavaScript Document
var SearchString = "";

function gotosearch() {
	if (document.SearchForm.PriceFrom.value.length > 0) {
		BuildString("pf=" + filterNum(document.SearchForm.PriceFrom.value))
	}
	if (document.SearchForm.PriceTo.value.length > 0) {
		BuildString("pt=" + filterNum(document.SearchForm.PriceTo.value))
	}
	if (document.SearchForm.Bedrooms.value != 0) {
		BuildString("br=" + document.SearchForm.Bedrooms.value)
	}
	if (document.SearchForm.Baths.value != 0) {
		BuildString("bt=" + document.SearchForm.Baths.value)
	}
	if (document.SearchForm.SquareFootage.value.length > 0) {
		BuildString("sf=" + filterNum(document.SearchForm.SquareFootage.value))
	}
	SearchString = "/residential.asp" + SearchString
	// alert(SearchString)
	window.location.href = SearchString
}

function BuildString(StringtoAdd) {
	if (SearchString.length == 0) {
		SearchString = "?" + StringtoAdd
	} else {
		SearchString = SearchString + "&" + StringtoAdd
	}
}

function filterNum(InValue) {
// Convert the value to a string
InValue = InValue + ""
// define a temp string value for resultant number
var FormattedInValue = ""

	for (var i = 0; i <= InValue.length; i = i + 1) {
		//If numeric, Put the number in the work string
		if (isNaN(InValue.charAt(i))) {
			//discard the non numeric
		} else {
			FormattedInValue = FormattedInValue + InValue.charAt(i)
		}
		if (InValue.charAt(i) == '.') {
			return parseFloat(FormattedInValue)	
		}
	}
	if (FormattedInValue.length == 0) {
		return ""
	} else {
		return parseFloat(FormattedInValue)
	}
}

// Event object processor for NN4, IE4+, NN6
function isEnterKey(evt) {
	if (!evt) {
		// grab IE event object
		evt = window.event	
	} else if (!evt.keyCode) {
		// grab NN4 event info
		evt.keyCode = evt.which
	}
	return (evt.keyCode == 13)
}

function processOnEnter(fld, evt) {
	if (isEnterKey(evt)) {
		// alert("Ready to do some work with the form.")
		gotosearch()
		return false
	}
	return true
}
