function zipCheck(){
	var zipcode = document.regForm.zip.value;
	var state = document.regForm.state.value;
	if(zipcode != ''){
		if(state == 'IL'){
				if(zipcode >= 60001 && zipcode <= 62999 && zipcode.length == 5){
					return true;
				} else {
					alert("Please enter a valid 5-digit Illinois ZIP code.")
					event.returnValue = false;
				}
			} else {
				if(zipcode >= 00000 && zipcode <= 99999 && zipcode != '' && zipcode.length == 5){
					return true;
				} else {
					alert('Please enter a valid 5-digit '+state+' ZIP code.')
					event.returnValue = false;
				}
			}
		}
	}
	
function reg_verify() {
if (document.regform.firstName.value=="") {
alert("Please fill out your first name in the form to proceed.");
return false;
}
else if (document.regform.lastName.value=="") {
alert("Please fill out your last name in the form to proceed.");
return false;
}
else if (document.regform.email.value=="") {
alert("Please fill out your email address in the form to proceed.");
return false;
}
else if (!isEmail(document.regform.email.value)) {
alert("Please fill out a valid email address.");
return false;
}
else if (document.regform.password.value=="") {
alert("Please fill out your password in the form to proceed.");
return false;
}
else if (document.regform.password2.value=="") {
alert("Please retype your password in the second field to proceed.");
return false;
}
else if (document.regform.password.value != document.regform.password2.value){
alert("The passwords you entered do not match.");
return false;
}
else if (document.regform.agree.checked==false) {
alert("Please agree to our Terms of Service.");
return false;
}
else {
return true;
}
}

function reg_verify_mod() {
if (document.regform.firstName.value=="") {
alert("Please fill out your first name in the form to proceed.");
return false;
}
else if (document.regform.email.value=="") {
alert("Please fill out your email address in the form to proceed.");
return false;
}
else if (!isEmail(document.regform.email.value)) {
alert("Please fill out a valid email address.");
return false;
}
else if (document.regform.password.value=="") {
alert("Please fill out your password in the form to proceed.");
return false;
}
else if (document.regform.password2.value=="") {
alert("Please retype your password in the second field to proceed.");
return false;
}
else if (document.regform.password.value != document.regform.password2.value){
alert("The passwords you entered do not match.");
return false;
}
else if (document.regform.agree.checked==false) {
alert("Please agree to our Terms of Service.");
return false;
}
else {
return true;
}
}

function open_email() {
OpenWin = this.open('','Title',"width=340,height=315");
page = "<html><head></head><body style=\"font-family:Arial,sans-serif;font-size:.9em\"><form action=\"http://www.bestchicagocondos.com/send_email.php\" method=\"post\"><strong>Your Email:</strong> <input type=\"text\" size=\"18\" name=\"email\" /><br /><br /><strong>Subject:</strong> I'm interested in advertising on BestChicagoCondos.com<br /><br /><strong>Your Information:</strong><br /><textarea name=\"body\" rows=\"3\" cols=\"30\"></textarea><br /><input style=\"color:#FFFFFF;background-color:#339900\" type=\"submit\" value=\"Send Email\" /></form><img src=\"http://www.bestchicagocondos.com/templates/3_col_standards/images/email_logo.jpg\" style=\"float:left\" /><small>Privacy Policy: We hate spam as much as you do. Your email address will not be shared or sold to any unauthorized third party. Period.<br /><br />&copy;2007 BestChicagoCondos.com</small></body></html>";
OpenWin.document.write(page);
OpenWin.document.close();
}

function open_terms() {
OpenWin = this.open('','Title',"width=715,height=500,scrollbars=yes");
page = "<html><head></head><body><img src=\"http://www.bestchicagocondos.com/images/terms.gif\" /></body></html>";
OpenWin.document.write(page);
OpenWin.document.close();
}

function open_privacy() {
OpenWin2 = this.open('','Title',"width=320,height=200");
page = "<html><head></head><body style=\"font-family:Arial,sans-serif\"><img style=\"width:300px;height:200px\" src=\"http://www.bestchicagocondos.com/templates/new/images/privacy2.gif\" /></body></html>";
OpenWin2.document.write(page);
OpenWin2.document.close();
}

function isZIPCode(value) {
   zip = new RegExp(/^\d{5}$|^\d{5}-\d{4}$/);
   if (!zip.test(value)){
   return false;
   }
   else {
   return true;
   }
}
function isEmail(value) {
   return (value.indexOf(".") > 2) && (value.indexOf("@") > 0);
}

function verify() {
if (document.zip_form.zip_code.value=="") {
alert("Please fill out your zip code in the form to proceed.");
return false;
}
else if (isZIPCode(document.zip_form.zip_code.value)) {
document.zip_form.submit();
}
else {
alert("Please fill out a valid Chicago area zip code to proceed.");
return false;
}
}
function verify2() {
if (document.zip_form.name.value=="") {
alert("Please fill out your name in the form to proceed.");
return false;
}
else if (document.zip_form.address.value=="") {
alert("Please fill out your current address in the form to proceed.");
return false;
}
else if (document.zip_form.city.value=="") {
alert("Please fill out your current address in the form to proceed.");
return false;
}
else if (document.zip_form.state.value=="") {
alert("Please fill out your state in the form to proceed.");
return false;
}
else if (document.zip_form.email.value=="") {
alert("Please fill out your primary email address in the form to proceed.");
return false;
}
else if (!isEmail(document.zip_form.email.value)){
alert("Please enter a valid email address.");
return false;
}
else if (document.zip_form.number_bedrooms.value=="") {
alert("Please fill out the number of bedrooms to proceed.");
return false;
}
else if (document.zip_form.number_bathrooms.value=="") {
alert("Please fill out the number of bathrooms to proceed.");
return false;
}
else if (document.zip_form.footage.value=="") {
alert("Please fill out the square footage of your condo to proceed.");
return false;
}
else {
document.zip_form.submit();
}
}
function verify3() {
if (document.moreinfo.email.value=="") {
alert("Please fill out your email in the form to proceed.");
return false;
}
if (!isEmail(document.moreinfo.email.value)) {
alert("Please fill out a valid email to proceed.");
return false;
}
if(document.moreinfo.name.value==""){
alert("Please enter your name to proceed.");
return false;
}
if(document.moreinfo.phone.value==""){
alert("Please enter your primary phone number to proceed.");
return false;
}
else{
return true;
}
}

//MLS Validation
function validateSearchTerms() {

var msg = "The following information is required\r to submit your Search:\r";
var msgflag = "false";

	selectAll(document.searchForm.selectedVersion);

	var count = numberOfSelectedEntries(document.searchForm.selectedVersion);
	if (count == 0) {
		msg+="\r- Neighborhood(s)";
		msgflag="true";
	}

         var str = validatePrice(document.searchForm.minPrice.value, document.searchForm.maxPrice.value);
        if (str != null){
                msg += "\n - " + str;
                msgflag = "true";
        }
	
	if (document.searchForm.propertyTypes[0].checked == false && document.searchForm.propertyTypes[1].checked == false && document.searchForm.propertyTypes[2].checked == false && document.searchForm.propertyTypes[3].checked == false && document.searchForm.propertyTypes[4].checked == false && document.searchForm.propertyTypes[5].checked == false && document.searchForm.propertyTypes[6].checked == false) {
		msg+="\r- Type of Property";
		msgflag="true";
	}

	if (msgflag == "true") {
		alert(msg);
		return false;
	}

	if (msgflag == "false") {
//		set('search');
	}
}

function validateminiSearchTerms() {

var msg = "The following information is required\r to submit your Search:\r";
var msgflag = "false";

	var count = numberOfSelectedEntries(document.minisearchForm.selectedVersion);
	if (count == 0) {
		msg+="\r- Neighborhood(s)";
		msgflag="true";
	}

         var str = validatePrice(document.minisearchForm.minPrice.value, document.minisearchForm.maxPrice.value);
        if (str != null){
                msg += "\n - " + str;
                msgflag = "true";
        }
	
	var count2 = numberOfSelectedEntries(document.minisearchForm.propertyTypes);
	if (count2 == 0) {
		msg+="\r- Property Type(s)";
		msgflag="true";
	}

	if (msgflag == "true") {
		alert(msg);
		return false;
	}

	if (msgflag == "false") {
//		set('search');
	}
}

// VALIDATE //
function validate() {
var msg;
var msgflag;

msg = "Please select a saved search.";
msgflag = "false";

	if (document.test.savedSearches.value == "") {
		msgflag="true";
	}

	if (msgflag == "true") {
		alert(msg);
		return false;
	}

	if (msgflag == "false") {
		document.test.submit();
	}
}
