function validateData()
{var txtFirstName=getElementById("FIRST_NAME");var txtLastName=getElementById("LAST_NAME");var txtEmail=getElementById("EMAIL");var txtPhoneAreaCode=getElementById("PHONE_AREA_CODE");var txtPhoneLocalCode=getElementById("PHONE_LOCAL_CODE");var txtPhoneNumber=getElementById("PHONE_NUMBER");var txtComments=getElementById("COMMENTS");var sPhoneValue=txtPhoneAreaCode.value+txtPhoneLocalCode.value+txtPhoneNumber.value;var bRequirementsMet=true;var txtFocusField;if(txtFirstName.value.length==0&&txtLastName.value.length==0){txtFocusField=txtFirstName;bRequirementsMet=false;}
if(bRequirementsMet&&(txtEmail.value.length==0&&sPhoneValue.length==0)){txtFocusField=txtEmail;bRequirementsMet=false;}
var txtZip=getElementById("ZIP");txtZip.value=txtZip.value.toUpperCase();txtZip=getElementById("SELLER_ZIP");txtZip.value=txtZip.value.toUpperCase();if(!bRequirementsMet){window.alert("\nPlease enter your FIRST NAME or LAST NAME\nand\nPHONE NUMBER or EMAIL ADDRESS.\n");txtFocusField.focus();}else{if(sPhoneValue.length>0&&(txtPhoneAreaCode.value.length!=3||txtPhoneLocalCode.value.length!=3||txtPhoneNumber.value.length!=4)){bRequirementsMet=false;window.alert("\nYou have entered an invalid phone number. Please enter a correct phone number.\n");txtPhoneAreaCode.focus();}
if(bRequirementsMet&&txtEmail.value.length>0){var nAtSymbolIndex=txtEmail.value.indexOf("@");var sUserName="";var sServerName="";if(nAtSymbolIndex>0&&nAtSymbolIndex<txtEmail.value.length-1){sUserName=txtEmail.value.substring(0,nAtSymbolIndex);sServerName=txtEmail.value.substring(nAtSymbolIndex+1);nAtSymbolIndex=sServerName.indexOf(".");}
if(nAtSymbolIndex==-1||sUserName.length==0||sServerName.length==0){window.alert("You have entered an invalid email address. Please enter a correct email address.");txtEmail.focus();bRequirementsMet=false;}}
if(bRequirementsMet&&typeof(txtComments)!="undefined"&&txtComments.value.length>2900){bRequirementsMet=false;window.alert("\nYour comments are too long.  Please try to limit the length of your comments to 2900 characters.\n");txtComments.focus();}}
if(bRequirementsMet){var txtMinPrice=getElementById("SELLER_MIN_PRICE");var txtMaxPrice=getElementById("SELLER_MAX_PRICE");if(typeof(txtMinPrice)!="undefined"&&typeof(txtMaxPrice)!="undefined"){var sMinPrice=txtMinPrice.value;var sMaxPrice=txtMaxPrice.value;sMinPrice=sMinPrice.replace(/\$|\+|,/g,"");sMaxPrice=sMaxPrice.replace(/\$|\+|,/g,"");var nMinPrice=new Number(sMinPrice);var nMaxPrice=new Number(sMaxPrice);if(sMinPrice.length!=0&&sMaxPrice.length!=0){if(nMinPrice!=Number.NaN&&nMaxPrice!=Number.NaN&&nMinPrice>nMaxPrice){window.alert("\nYou have specified an invalid minimum or maximum price.  Please\nensure that the minimum price is not greater than the maximum price\nin the price range section.\n")
txtMaxPrice.focus();bRequirementsMet=false;}}}}
if(bRequirementsMet){var txtMinPrice=getElementById("BUYER_MIN_PRICE");var txtMaxPrice=getElementById("BUYER_MAX_PRICE");if(typeof(txtMinPrice)!="undefined"&&typeof(txtMaxPrice)!="undefined"){var sMinPrice=txtMinPrice.value;var sMaxPrice=txtMaxPrice.value;sMinPrice=sMinPrice.replace(/\$|\+|,/g,"");sMaxPrice=sMaxPrice.replace(/\$|\+|,/g,"");var nMinPrice=new Number(sMinPrice);var nMaxPrice=new Number(sMaxPrice);if(nMinPrice!=Number.NaN&&nMaxPrice!=Number.NaN&&nMinPrice>nMaxPrice){window.alert("\nYou have specified an invalid minimum or maximum price.  Please\nensure that the minimum price is not greater than the maximum price\nin the price range section.\n")
txtMaxPrice.focus();bRequirementsMet=false;}}}
return bRequirementsMet;}
function getElementById(id){if(typeof(document.getElementById)=="undefined"){for(var i=0;i<document.all.length;i++){var el=document.all(i);if(el.id==id){return el;}}}
else{return document.getElementById(id);}}
function initForm(){if(document.getElementById('frmMain')&&document.getElementById('STATUS_SELLER')){var statusSeller=getElementById("STATUS_SELLER");var statusBuyer=getElementById("STATUS_BUYER");var statusBoth=getElementById("STATUS_BOTH");var statusNeither=getElementById("STATUS_NEITHER");if(statusSeller.checked){status="Seller";}else if(statusBoth.checked){status="Both";}else if(statusBuyer.checked){status="Buyer"}else if(statusNeither.checked){status="Neither";}else{status="Neither";statusNeither.checked="checked";}
enableSection("Neither");enableAddressFields(false);}}
function fixFields(){getElementById("SELLER_HOUSE_NO").style.width="95%";getElementById("SELLER_STREET_NAME").style.width="95%";getElementById("SELLER_SUITE_NO").style.width="95%";getElementById("SELLER_CITY").style.width="95%";getElementById("SELLER_STATE").style.width="95%";getElementById("SELLER_ZIP").style.width="95%";}
function enableSection(section){setControl(getElementById("SELLER_MIN_PRICE"),section=="Buyer");setControl(getElementById("SELLER_MAX_PRICE"),section=="Buyer");setControl(getElementById("SELLER_SQUAREFEET"),section=="Buyer");setControl(getElementById("SELLER_BEDROOMS"),section=="Buyer");setControl(getElementById("SELLER_BATHROOMS"),section=="Buyer");setControl(getElementById("SELLER_AGE"),section=="Buyer");setControl(getElementById("SELLER_LOCATION_SAME_ADDRESS"),section=="Buyer");setControl(getElementById("SELLER_HOUSE_NO"),section=="Buyer");setControl(getElementById("SELLER_STREET_NAME"),section=="Buyer");setControl(getElementById("SELLER_SUITE_NO"),section=="Buyer");setControl(getElementById("SELLER_CITY"),section=="Buyer");setControl(getElementById("SELLER_STATE"),section=="Buyer");setControl(getElementById("SELLER_ZIP"),section=="Buyer");if(section=="Buyer"){getElementById("buyer_table").style.display="block";getElementById("seller_table").style.display="none";}else if(section=="Seller"){getElementById("seller_table").style.display="block";getElementById("buyer_table").style.display="none";fixFields();}else if(section=="Both"){getElementById("seller_table").style.display="block";getElementById("buyer_table").style.display="block";fixFields();}else if(section=="Neither"){getElementById("seller_table").style.display="none";getElementById("buyer_table").style.display="none";}
setControl(getElementById("BUYER_MIN_PRICE"),section=="Seller","$0");setControl(getElementById("BUYER_MAX_PRICE"),section=="Seller","no maximum");setControl(getElementById("BUYER_SQUAREFEET"),section=="Seller","0-999");setControl(getElementById("BUYER_BEDROOMS"),section=="Seller","1");setControl(getElementById("BUYER_BATHROOMS"),section=="Seller","1");setControl(getElementById("BUYER_AGE"),section=="Seller","0-9");setControl(getElementById("BUYER_CITY"),section=="Seller");setControl(getElementById("BUYER_STATE"),section=="Seller");enableAddressFields(false);}
function enableAddressFields(clearValues){var disable=getElementById("STATUS_BUYER").checked||getElementById("SELLER_LOCATION_SAME_ADDRESS").checked;var ctrlHouseNo=getElementById("SELLER_HOUSE_NO");var ctrlStreetName=getElementById("SELLER_STREET_NAME");var ctrlSuiteNo=getElementById("SELLER_SUITE_NO");var ctrlCity=getElementById("SELLER_CITY");var ctrlState=getElementById("SELLER_STATE");var ctrlZip=getElementById("SELLER_ZIP");setControl(ctrlHouseNo,disable);setControl(ctrlStreetName,disable);setControl(ctrlSuiteNo,disable);setControl(ctrlCity,disable);setControl(ctrlState,disable);setControl(ctrlZip,disable);if(disable){setValue(ctrlHouseNo,"HOUSE_NO");setValue(ctrlStreetName,"STREET_NAME");setValue(ctrlSuiteNo,"SUITE_NO");setValue(ctrlCity,"CITY");setValue(ctrlState,"STATE");setValue(ctrlZip,"ZIP");}
else if(typeof(clearValues)=="undefined"){clearValue(ctrlHouseNo);clearValue(ctrlStreetName);clearValue(ctrlSuiteNo);clearValue(ctrlCity);clearValue(ctrlState);clearValue(ctrlZip);}}
function clearValue(obj){if(typeof(obj)!="undefined"){obj.value="";}}
function setValue(obj,name){var obj2=getElementById(name);if(typeof(obj)!="undefined"&&typeof(obj2)!="undefined"){var width=obj.offsetWidth;obj.value=obj2.value;obj.style.width=width;}}
function setControl(control,disable,value){if(typeof(control)!="undefined"){control.disabled=disable;if(disable){control.value=typeof(value)=="undefined"?"":value;if(control.checked){control.checked=false;}}}}
function moveToNextField(obj,keys,e){var id=obj.id;var bAllowKey=false;var code;if(!e)var e=window.event;if(e.keyCode)code=e.keyCode;else if(e.which)code=e.which;if((code-48>=0)){for(var i=0;i<keys.length;i++){if((keys.charCodeAt(i)==code)||(keys.charCodeAt(i)==code-48)){bAllowKey=true;break;}}
if(!bAllowKey){obj.value=obj.value.substring(0,obj.value.length-1);}
if(code!=9){if(getElementById(id).value.length==3){if(id=="PHONE_AREA_CODE"){getElementById("PHONE_LOCAL_CODE").focus();}
else if(id=="PHONE_LOCAL_CODE"){getElementById("PHONE_NUMBER").focus();}}}}}
function enableBestTime(){var txtPhoneArea=getElementById("PHONE_AREA_CODE");var txtPhoneLocal=getElementById("PHONE_LOCAL_CODE");var txtPhoneNumber=getElementById("PHONE_NUMBER");var obgBestTime=getElementById("BEST_TIME");if(typeof(txtPhoneArea)!="undefined"&&txtPhoneArea!=null&&typeof(obgBestTime)!="undefined"&&obgBestTime!=null){obgBestTime.disabled=!(txtPhoneArea.value.length==3&&txtPhoneLocal.value.length==3&&txtPhoneNumber.value.length==4);}}
function Capitalize(obj)
{if(obj.value.length==1){obj.value=obj.value.toUpperCase();}}
function Submit()
{if(validateData()){getElementById("SUBMIT").disabled=true;var pForm=getElementById("frmMain");pForm.submit();}}
function addLoadEvent(func){var oldonload=window.onload;if(typeof(window.onload)!='function'){window.onload=func;}else{window.onload=function(){oldonload();func();}}}
addLoadEvent(initForm);