function searchButton(valFunction) {
	href = "href=JavaScript:if("+ valFunction +"(document.forms[\'townlist\']))void(document.forms[\'townlist\'].submit())"
	if (document.all)
		document.write('<A '+ href +' style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; FONT-WEIGHT: bold; FONT-SIZE: 11px; FILTER: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=\'#A0ffd406\', EndColorStr=\'#00000000\'); BORDER-LEFT: silver 1px solid; WIDTH: 58px; BACKGROUND-COLOR: #ffffff; COLOR: #000000; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: Arial; HEIGHT: 20px; TEXT-ALIGN: center; TEXT-DECORATION: none">Search</A>');
	else 
		document.write('<A '+ href +' style="BORDER-RIGHT: silver 1px solid; BORDER-TOP: silver 1px solid; FONT-WEIGHT: bold; FONT-SIZE: 11px; BORDER-LEFT: silver 1px solid; WIDTH: 58px; BACKGROUND-COLOR: #ffd406; COLOR: #000000; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: Arial; HEIGHT: 20px; TEXT-ALIGN: center; TEXT-DECORATION: none">&nbsp;&nbsp;Search&nbsp;&nbsp;</A>');
	document.write('<input type="image" src="img/t.gif">');
}
function searchTips() {
	parent.location.href = "tips.html";
	return true;
}
function userProfile() {
	parent.location.href = "/UserProfile";
	return true;
}
function addressFormCheck(formname) {
	if ((formname.town.options.selectedIndex < 0 || formname.town.options[formname.town.options.selectedIndex].text == "select a town/city") && formname.zip.value.replace(/ /g, "") == "") {
		alert("You must choose a town or zip to begin the search.");
		return false;
	}
	// Check for Street Name Input
	if ((formname.stname.value.replace(/ /g, "") == "") || (formname.stname.value == null)) {
		alert("You must provide a street name to begin the search.");
		return false;
	}
	// Now does Street Number Check...
	if (StreetNumberCheck(formname.stnum_lo.value,formname.stnum_hi.value) == false) {
		return false;
	}
	popUpNew();
	return true;
}
function nameFormCheck(formname) {
	// Only need this if looking for multiple selection list...
	// Check for Town Selection (need at least 1)

	// Check for Last Name Input
	if ((formname.lname.value.replace(/ /g, "") == "") || (formname.lname.value == null)) {
		alert("You must provide a last name to begin the search.");
		return false;
	}
	if ((formname.town.options.selectedIndex < 0 || formname.town.options[formname.town.options.selectedIndex].text == "select a town/city") && formname.zip.value.replace(/ /g, "") == "") {
		alert("You must choose a town or zip to begin the search.");
		return false;
	}
	popUpNew();
	return true;
}
function comparableFormCheck(formname) {

	if ((formname.town.options.selectedIndex < 0 || formname.town.options[formname.town.options.selectedIndex].text == "select a town/city")) {
		alert("You must choose a town to begin the search.");
		return false;
	}
	
	// Now does Street Number Check...
	if (StreetNumberCheck(formname.stnum_lo.value,formname.stnum_hi.value) == false) {
		return false;
	}
	
	// Now does Zipcode Check...
	if (ZipCheck(formname.zip_lo.value,formname.zip_hi.value) == false) {
		return false;
	}
	
	// Now does Census Track Check...
	if (CensusCheck(formname.tract_lo.value,formname.tract_hi.value) == false) {
		return false;
	}
	
	// Now does the Sale Price Check...
	if (SalePriceCheck(formname.price_lo.value,formname.price_hi.value) == false) {
		return false;
	}
	
	// Now does the Sale Date Check...
	if (SaleDateCheck(formname.sale_lo.value,formname.sale_hi.value) == false) {
		return false;
	}

	// Now does the Assessed Value Check...
	if (AssessedValueCheck(formname.tav_lo.value,formname.tav_hi.value) == false) {
		return false;
	}

	if (MortPriceCheck(formname.amount_lo.value,formname.amount_hi.value) == false) {
		return false;
	}

	if (MortDateCheck(formname.mortgage_lo.value,formname.mortgage_hi.value) == false) {
		return false;
	}

	// Now does the Living Area Check...
	if (LivingAreaCheck(formname.live_lo.value,formname.live_hi.value) == false) {
		return false;
	}
	
	// Now does the Lot Size Check...
	if (LotSizeCheck(formname.lot_lo.value,formname.lot_hi.value) == false) {
		return false;
	}
	
	// Now does the Year Built Check...
	if (YearCheck(formname.yr_lo.value,formname.yr_hi.value) == false) {
		return false;
	}
	
	// Now does the Total Rooms Check...
	if (TotalRoomsCheck(formname.totrm_lo.value,formname.totrm_hi.value) == false) {
		return false;
	}
	
	// Now does the Bedrooms Check...
	if (BedroomsCheck(formname.bed_lo.value,formname.bed_hi.value) == false) {
		return false;
	}
	
	// Now does the Bathrooms Check...
	if (BathroomsCheck(formname.bath_lo.value,formname.bath_hi.value) == false) {
		return false;
	}
	
	// The only way to get to here is if it passes all tests...
	popUpNew();			
	return true;
}
function radiusFormCheck(formname) {
	// Now does the Sale Price Check...
	if (SalePriceCheck(formname.price_lo.value,formname.price_hi.value) == false) {
		return false;
	}
	// Now does the Sale Date Check...
	if (SaleDateCheck(formname.sale_lo.value,formname.sale_hi.value) == false) {
		return false;
	}
	// Now does the Assessed Value Check...
	if (AssessedValueCheck(formname.tav_lo.value,formname.tav_hi.value) == false) {
		return false;
	}
	if (false){//(MortPriceCheck(formname.amount_lo.value,formname.amount_hi.value) == false) {
		return false;
	}
	if (false){//(MortDateCheck(formname.mortgage_lo.value,formname.mortgage_hi.value) == false) {
		return false;
	}
	// Now does the Living Area Check...
	if (LivingAreaCheck(formname.live_lo.value,formname.live_hi.value) == false) {
		return false;
	}
	// Now does the Lot Size Check...
	if (LotSizeCheck(formname.lot_lo.value,formname.lot_hi.value) == false) {
		return false;
	}
	// Now does the Year Built Check...
	if (YearCheck(formname.yr_lo.value,formname.yr_hi.value) == false) {
		return false;
	}
	// Now does the Total Rooms Check...
	if (TotalRoomsCheck(formname.totrm_lo.value,formname.totrm_hi.value) == false) {
		return false;
	}
	// Now does the Bedrooms Check...
	if (BedroomsCheck(formname.bed_lo.value,formname.bed_hi.value) == false) {
		return false;
	}
	// Now does the Bathrooms Check...
	if (BathroomsCheck(formname.bath_lo.value,formname.bath_hi.value) == false) {
		return false;
	}
	popUpNew();			
	return true;
}
function mortgageFormCheck(formname) {

	var townsel = false;
	for (var i=0;i<formname.town.length;i++) {
		if (formname.town.options[i].selected && formname.town.options[formname.town.options.selectedIndex].text != "select a town/city") {
			townsel = true;
			break;
		}
	}

	if (townsel == false) {
		alert("You must select a town to begin the search.");
		return false;
	}

	var m0, m1, m2, rv;
	// Assumed that all failed first...
	m0 = false;
	m1 = false;
	m2 = false;
	
	// Check at Lender...anything other than the default value would pass...
	if (formname.lender.value != "Any") {
		m0 = true;
	}
	
	// Mortgage Date Range Format check...return true if Blanked or if format okay...
	if (MortDateCheck(formname.mortgage_lo.value,formname.mortgage_hi.value) == true) {
		// If any are blanked, then failed it...
		if ((formname.mortgage_lo.value.replace(/ /g, "") == "" || formname.mortgage_lo.value == null) && (formname.mortgage_hi.value.replace(/ /g, "") == "" || formname.mortgage_hi.value == null)) {
			m1 = false;
		} else {
			m1 = true;
		}
	}
	else
		return false;

	// Now does the Mortgage Price Check...using SalePriceCheck routine
	if (MortPriceCheck(formname.amount_lo.value,formname.amount_hi.value) == true) {
		// If any are blanked, then failed it...
		if ((formname.amount_lo.value.replace(/ /g, "") == "" || formname.amount_lo.value == null) && (formname.amount_hi.value.replace(/ /g, "") == "" || formname.amount_hi.value == null)) {
			m2 = false;
		} else {
			m2 = true;
		}
	}
	else
		return false;

	// If any one of the 3 elements are set, then it's okay to proceed otherwise, don't.
	rv = m0 || m1 || m2;
	if (rv == false) {
		alert("You must select at least one of the following fields to continue this search: Lender, Mortgage Amount (Low and/or High), or Mortgage Date (Low and/or High).");
		return false;
	} else {
		// The only way to get to here is if it passes all tests...
		popUpNew();			
		return true;
	}
}
////////////////////////////////////////////////////////////////////////////////
function popUpNew() {
	apopup = window.open('wait.html','wait','height=480,width=640,resizable=1,scrollbars=1,status=1,toolbar=0,location=0,directories=0,menubar=0')
	parent.pwin = apopup;
}
////////////////////////////////////////////////////////////////////////////////
// Followings all return true if okay otherwise false
//
// 1. SaleDateCheck(lo,hi)
// 2. SalePriceCheck(lo,hi)
// 3. AssessedValueCheck(lo,hi)
// 4. BedroomsCheck(lo,hi)
// 5. BathroomsCheck(lo,hi)
// 6. LivingAreaCheck(lo,hi)
// 7. LotSizeCheck(lo,hi)
// 8. TotalRoomsCheck(lo,hi)
// 9. StreetNumberCheck(lo,hi)
// 10. ZipCheck(lo,hi)
// 11. YearCheck(lo,hi)
//
function SaleDateCheck(dlo,dhi) {
	var sdt = sDateCheck(dlo,"Sale Date Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sDateCheck(dhi,"Sale Date Hi Range");
	if (sdt == false) {
		return false;
	}
	if (!dateOrderCheck(dlo,dhi)) {
		return false;
	}
	return true;
}
//
function SalePriceCheck(plo,phi) {
	// Now does the Sale Price Check...
	var sdt = sCheckDollar(plo,"Sale Price Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckDollar(phi,"Sale Price Hi Range");
	if (sdt == false) {
		return false;
	}
	return true
}
//
function MortDateCheck(dlo,dhi) {
	var sdt = sDateCheck(dlo,"Mortgage Date Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sDateCheck(dhi,"Mortgage Date Hi Range");
	if (sdt == false) {
		return false;
	}
	if (!dateOrderCheck(dlo,dhi)) {
		return false;
	}
	return true;
}
//
function MortPriceCheck(plo,phi) {
	// Now does the Sale Price Check...
	var sdt = sCheckDollar(plo,"Mortgage Price Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckDollar(phi,"Mortgage Price Hi Range");
	if (sdt == false) {
		return false;
	}
	return true
}
//
function AssessedValueCheck(alo,ahi) {
	// Now does the Assessed Value Check...
	var sdt = sCheckDollar(alo,"Assessed Value Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckDollar(ahi,"Assessed Value Hi Range");
	if (sdt == false) {
		return false;
	}
	
	return true
}
//
function BedroomsCheck(blo,bhi) {
	var sdt = sCheckNumeric(blo,"Bedroom Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(bhi,"Bedroom Hi Range");
	if (sdt == false) {
		return false;
	}

	return true;
}
//
function BathroomsCheck(dlo,dhi) {
	var sdt = sCheckNumeric(dlo,"Bathroom Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(dhi,"Bathroom Hi Range");
	if (sdt == false) {
		return false;
	}

	return true;
}
//
function LivingAreaCheck(llo,lhi) {
	var sdt = sCheckNumeric(llo,"Living Area Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(lhi,"Living Area Hi Range");
	if (sdt == false) {
		return false;
	}

	return true;
}
//
function LotSizeCheck(tlo,thi) {
	var sdt = sCheckNumeric(tlo,"Lot Size Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(thi,"Lot Size Hi Range");
	if (sdt == false) {
		return false;
	}

	return true;
}
//
function TotalRoomsCheck(olo,ohi) {
	var sdt = sCheckNumeric(olo,"Total Rooms Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(ohi,"Total Rooms Hi Range");
	if (sdt == false) {
		return false;
	}
	
	return true;
}
//
function StreetNumberCheck(slo,shi) {
	var sdt = sCheckNumeric(slo,"Street Number Lo Range");
	if (sdt == false) {
		return false;
	}
	sdt = sCheckNumeric(shi,"Street Number Hi Range");
	if (sdt == false) {
		return false;
	}
	
	return true;
}
//
function ZipCheck(zlo,zhi) {
	// Only check if zip code is 5 characters/digits in length
	if (zlo.length == 5) {
		var sdt = sCheckNumeric(zlo,"Zipcode Lo Range");
		if (sdt == false) {
			return false;
		} else {
			// Check to make sure that the zipcode is within 00001 and 10000
			if ((parseInt(zlo) < 0) || (parseInt(zlo) > 10000)) {
				alert("Sorry, Zipcode (Low) must be within 00001 and 10000 range.  Please try again.");
				return false;
			}
		}
	} else {
		// otherwise, if blank, then it's also okay
		if (zlo.length != 0) {
			alert("Invalid Zipcode in the Lo Range");
			return false;
		}
	}

	// Only check if zip code is 5 characters/digits in length
	if (zhi.length == 5) {
		var sdt = sCheckNumeric(zhi,"Zipcode High Range");
		if (sdt == false) {
			return false;
		} else {
			// Check to make sure that the zipcode is within 00001 and 10000
			if ((parseInt(zhi) < 0) || (parseInt(zhi) > 10000)) {
				alert("Sorry, Zipcode (High) must be within 00001 and 10000 range.  Please try again.");
				return false;
			}
		}
	} else {
		// otherwise, if blank, then it's also okay
		if (zhi.length != 0) {
			alert("Invalid Zipcode in the High Range");
			return false;
		}
	}
	
	return true;
}
//
function CensusCheck(clo, chi) {
	if (!sCheckNumeric(clo,"Census Track Lo Range") || !sCheckNumeric(chi,"Census Track Hi Range"))
		return false;
	return true;
}
//
function YearCheck(ylo,yhi) {
	// Only check if Year Built is 4 characters/digits in length
	var sdt = sCheckNumeric(ylo,"Year Built Lo Range");
	if (sdt == false) {
		return false;
	} else {
		// Check if it is not blank
		if (ylo.length != 0) {
			// If it is a number, make sure that it is within range (1600 - 2050)
			if ((parseInt(ylo) < 1600) || (parseInt(ylo) > 2050)) {
				alert("Sorry, Year Built Lo Range is out of the allowed years range (1600-2050).  Please try again.");
				return false;
			}
		}
	}

	// Only check if zip code is 5 characters/digits in length
	var sdt = sCheckNumeric(yhi,"Year Built High Range");
	if (sdt == false) {
		return false;
	} else {
		// Check if it is not blank
		if (yhi.length != 0) {
			// If it is a number, make sure that it is within range (1600 - 2050)
			if ((parseInt(yhi) < 1600) || (parseInt(yhi) > 2050)) {
				alert("Sorry, Year Built High Range is out of the allowed years range (1600-2050).  Please try again.");
				return false;
			}
		}
	}
	
	return true
}
//
////////////////////////////////////////////////////////////////////////////////
//
function dateOrderCheck(dlo,dhi) {
	if (!dlo || !dhi)
		return true;
	//if ((new Date(dlo)).getVarDate() <= (new Date(dhi)).getVarDate())
	if (Date.parse(dlo) <= Date.parse(dhi))
		return true;
	alert("The To Date must be the same or later than the From Date.");
	return false;
}
function sDateCheck(val,hdr) {
	//  If blank, then it's okay...otherwise, go through with the checking
	if (val.length == 0)
		return true;
	else if (val.replace(/ /g, "").length == 0) {
		alert(hdr + " is not in the correct format.  Please try again.");
		return false;
	}
	else {
		var retv = checkDate(val);
		if (retv[0] == true) {
			return true;
		} else {
			if (retv[1] == -1) {
				alert(hdr + " is not in the correct format.  Please try again.");
			}
			if (retv[1] == 0) {
				alert(hdr + " is not in the correct format.  Month is outside the proper range (1-12).  Please try again.");
			}
			if (retv[1] == 1) {
				alert(hdr + " is not in the correct format.  Day is outside the proper range for the specified month.  Please try again.");
			}
			if (retv[1] == 2) {
				alert(hdr + " is not in the correct format.  Year is outside the proper range (1900 - 2100).  Please try again.");
			}
			return false;
		}
	}
}
//
function sCheckNumeric(val,hdr) {
	// If blank, then it's okay...otherwise, go through with the checking
	if (val.length == 0)
		return true;
	else if (val.replace(/ /g, "").length == 0) {
		alert(hdr + " is not in the correct format.  Please try again.");
		return false;
	}
	else {
		// If error, then error out		
		re = /,/g;
		var ival = val.replace(re,"");
		if (isNumeric(ival) == false) {
			alert(hdr + " is not in the correct format.  Please try again.");
			return false;
		} else {
			return true;
		}
	}
}
//
function sCheckDollar(val,hdr) {
	// If blank, then it's okay...otherwise, go through with the checking
	if (val.length == 0)
		return true;
	else if (val.replace(/ /g, "").length == 0) {
		alert(hdr + " is not in the correct format.  Please try again.");
		return false;
	}
	else {
		// If error, then error out
		if (isDollar(val) == false) {
			alert(hdr + " is not in the correct format.  Please try again.");
			return false;
		} else {
			return true;
		}
	}
}
// Check to make sure that the input string is a valid date
// Return a 2 elements array
function checkDate(dt) {

	// Return value will contain 2 elements.  First will be true or false.  
	// If true, then 2nd element would be the date value in mm/dd/yyyy format
	// If false, then 2nd element would contain one of the followings:
	// -1 = invalid date (not equal to 3 elements)
	// 0 = month part is invalid
	// 1 = day part is invalid
	// 2 = year part is invalid
	//

	// First, change delimiter to / from -, if any
	// don't use unless going to replace the form value; pdw - 6/23/2004
	//dt = dt.replace(/-|\\/g, "/");

	var retvar = new Array(isDate(dt), dt); // isDate E smartwebby.js
	
	if (retvar[0] == 0)
		retvar[0] = true;
	else {
		if (retvar[0] > 0)
			retvar[1] = retvar[0] - 1;
		else
			retvar[1] = retvar[0];
		retvar[0] = false;
	}
	return retvar;
}
//
// determine whether or not the input is a number or not
function isNumeric(nbr) {
	if (isNaN(nbr) == true) {
		return false;
	} else {
		return true;
	}
}
//
// check for Dollar...(ignore $ and ,) <--- can't have multiple $ though
function isDollar(nbr) {
	// Just 1 occurrence of "$"
	re = /\$/;
	var tbr = nbr.replace(re,"");

	// Multiple occurrence of ","
	re = /,/g;
	var vbr = tbr.replace(re,"");
	
	if (isNaN(vbr) == true) {
		return false;
	} else {
		return true;
	}
}