function validateForm(thisForm) {
	if ((thisForm.Neighborhoods.value !== '') || (thisForm.Subdivisions.value !== '')) {
		// Make sure the user didn't populate the Neighborhood/Subdivision AND the STR.
		if ((thisForm.section.value !== '') || (thisForm.township.value !== '') || (thisForm.range.value !== '')) {
			if (confirm('Do not use a Neighborhood/Subdivision AND Section/Township/Range.  Would you like to clear the Section/Township/Range?')) {
				// Clear the ParcelID.
				thisForm.section.value = '';
				thisForm.township.value = '';
				thisForm.range.value = '';
				return false;
			} else {
				// Didn't want to clear the STR.
				return false;
			}
		}
	}

	// Check the data integrity of the optional fields.

	// Date Check (FORMAT: MM-YYYY or MM/YYYY)
	var datePattern = /^[01]?\d[-\/][12]\d{3}$/;
	if (thisForm.SalesDateBegin.value != '') {
		// Verify that this is a valid date.
		if (thisForm.SalesDateBegin.value.search(datePattern) != 0) {
			alert('Please enter a valid start date, using format MM-YYYY');
			return false;
		}
	}
	if (thisForm.SalesDateEnd.value != '') {
		if (thisForm.SalesDateEnd.value.search(datePattern) != 0) {
			alert('Please enter a valid end date, using format MM-YYYY');
			return false;
		}
	}
	
	// Sales Price Check (FORMAT: ?,??? OR ????) (basically, group 3 number by commas or don't have commas; you can have 0-3 digits as the first group).
	// Dollar signs are accepted.  A decimal point is accepted as long as there are two or more numbers after it (it will be ignored on the server)
	var currencyPattern = /^\$?\d{1,3}(\,?\d{3})*(\.?\d{2,})?$/;
	if (thisForm.SalesPriceBegin.value != '') {
		if (thisForm.SalesPriceBegin.value.search(currencyPattern) != 0) {
		alert('Please enter a valid start price, using format ###,### or only numbers');
			return false;
		}
	}
	if (thisForm.SalesPriceEnd.value != '') {
		if (thisForm.SalesPriceEnd.value.search(currencyPattern) != 0) {
		alert('Please enter a valid end price, using format ###,### or only numbers');
			return false;
		}
	}
	// Make sure the SalesPriceBegin is less than the SalesPriceEnd
	if (parseInt(thisForm.SalesPriceEnd.value.replace(/\$/,'').replace(/\,/g,'')) < parseInt(thisForm.SalesPriceBegin.value.replace(/\$/,'').replace(/\,/g,''))) {
		// Swap them (we will check this on the server as well.
		var temp = thisForm.SalesPriceBegin.value;
		thisForm.SalesPriceBegin.value = thisForm.SalesPriceEnd.value;
		thisForm.SalesPriceEnd.value = temp;
		temp = 0;
	}
	
	// Square Footage Check.  Same as sales price check except for dollar signs.
	var numberPattern = /^\d{1,3}(\,?\d{3})*(\.?\d{2,})?$/;
	if (thisForm.SquareFootageBegin.value != '') {
		if (thisForm.SquareFootageBegin.value.search(numberPattern) != 0) {
		alert('Please enter a valid start square footage, using format ###,### or only numbers');
			return false;
		}
	}
	if (thisForm.SquareFootageEnd.value != '') {
		if (thisForm.SquareFootageEnd.value.search(numberPattern) != 0) {
		alert('Please enter a valid end square footage, using format ###,### or only numbers');
			return false;
		}
	}
	// Make sure the SquareFootageBegin is less than the SquareFootageEnd
	if (parseInt(thisForm.SquareFootageEnd.value.replace(/\,/g,'')) < parseInt(thisForm.SquareFootageBegin.value.replace(/\,/g,''))) {
		// Swap them (we will check this on the server as well.
		var temp = thisForm.SquareFootageBegin.value;
		thisForm.SquareFootageBegin.value = thisForm.SquareFootageEnd.value;
		thisForm.SquareFootageEnd.value = temp;
		temp = 0;
	}
	
	// Acreage Check.  Same as square footage.
	var numberPattern = /^\d{1,3}(\,?\d{3})*(\.?\d{2,})?$/;
	if (thisForm.AcreageBegin.value != '') {
		if (thisForm.AcreageBegin.value.search(numberPattern) != 0) {
		alert('Please enter a valid start acreage, using format ###,### or only numbers');
			return false;
		}
	}
	if (thisForm.AcreageEnd.value != '') {
		if (thisForm.AcreageEnd.value.search(numberPattern) != 0) {
		alert('Please enter a valid end acreage, using format ###,### or only numbers');
			return false;
		}
	}
	// Make sure the AcreageBegin is less than the AcreageEnd
	if (parseInt(thisForm.AcreageEnd.value.replace(/\,/g,'')) < parseInt(thisForm.AcreageBegin.value.replace(/\,/g,''))) {
		// Swap them (we will check this on the server as well.
		var temp = thisForm.AcreageBegin.value;
		thisForm.AcreageBegin.value = thisForm.AcreageEnd.value;
		thisForm.AcreageEnd.value = temp;
		temp = 0;
	}

	// Everything checked out
	return true;
}

var onloadEvent = function() {
	// Sets the subdivsion or neighborhood code.
	var optionList;
	var firstList;

	// Set the initial values from the querystring.
	var qs = new Querystring();
	var initNh_cd = qs.get_value('neighborhood', null);
	var initSub = qs.get_value('subdivision', null);
	var initStartDate = qs.get_value('startDate', null);
	var i=0;
	if (initNh_cd) {
		optionList = document.getElementsByName('Neighborhoods');
		if (optionList.length === 1) {
			var firstList = optionList[0];
			for (i=0;i<firstList.options.length;i++) {
				if (firstList.options[i].value === initNh_cd) {
					firstList.options[i].selected = true;
					break;
				}
			}
		}
	}
	if (initSub) {
		optionList = document.getElementsByName('Subdivisions');
		if (optionList.length === 1) {
			var firstList = optionList[0];
			for (i=0;i<firstList.options.length;i++) {
				if (firstList.options[i].value === initSub) {
					firstList.options[i].selected = true;
					break;
				}
			}
		}
	}
	
	// If there is an initNh_cd or init_Sub then we are coming from an 18 month search link, if the
	// startDate isn't already set then set it to 18 months ago.
	var tmpDate;
	var month;
	if (((initNh_cd) || (initSub)) && (!initStartDate)) {
		tmpDate = new Date();
		tmpDate.setDate(tmpDate.getDate() - (18 * 30));
		month = tmpDate.getMonth() + 1;
		if (month < 10) {month = '0' + month;}
		initStartDate = (month + '-' + (tmpDate.getFullYear()));
	}
	
	if (initStartDate) {
		optionList = document.getElementsByName('SalesDateBegin');
		if (optionList.length === 1) {
			var firstList = optionList[0];
			firstList.value = initStartDate;
		}
	}
	
	// Always have an endDate of Today.
	optionList = document.getElementsByName('SalesDateEnd');
	if (optionList.length === 1) {
		var firstList = optionList[0];
		tmpDate = new Date();
		month = tmpDate.getMonth() + 1;
		if (month < 10) {month = '0' + month;}
		firstList.value = month + '-' + (tmpDate.getFullYear());
	}
};

if (window.onload) {
	var tmpFunction = window.onload;
	window.onload = function() {
		if (tmpFunction) {
			tmpFunction();
		}
		onloadEvent();	
	}
} else {
	window.onload = onloadEvent;
}
