
     	function getDocObj(elem,parent) {
	      if (document.layers) {
		    if (parent) {
			  return "document."+parent+".document."+elem;
		    } else {
			  return "document."+elem;
		    }

	      } else if (document.all) {
		    return "document.all."+ elem;
	      } else if (document.getElementById) {
		    return "document.getElementById('"+elem+"')";
	      }
	}
	function getDocObj(elem,parent) {
      if (document.layers) {
            if (parent) {
                  return "document."+parent+".document."+elem;
            } else {
                  return "document."+elem;
            }

      } else if (document.all) {
            return "document.all."+ elem;
      } else if (document.getElementById) {
            return "document.getElementById('"+elem+"')";
      }
	}


	
	function displayIfFoundHome(flag) {
	if(flag){

				eval(getDocObj('haveSignedContract')).style.display="";
				eval(getDocObj('hidengap2')).style.display="";
				eval(getDocObj('homeCity')).style.display="";
				eval(getDocObj('hidengap3')).style.display="";
				eval(getDocObj('homeStreet')).style.display="";
				eval(getDocObj('homeZip')).style.display="";
				eval(getDocObj('hideziptxt')).style.display="none";
				eval(getDocObj('hidezipfields')).style.display="none";
				eval(getDocObj('hidengap5')).style.display="none";
				eval(getDocObj('hidengap6')).style.display="none";
				eval(getDocObj('hidengap7')).style.display="";
				eval(getDocObj('hidengap4')).style.display="";


	}
	else {
				
				eval(getDocObj('haveSignedContract')).style.display="none";
				eval(getDocObj('hidengap2')).style.display="none";
				eval(getDocObj('homeCity')).style.display="none";
				eval(getDocObj('hidengap3')).style.display="none";
				eval(getDocObj('homeStreet')).style.display="none";
				eval(getDocObj('homeZip')).style.display="none";
				eval(getDocObj('hideziptxt')).style.display="";
				eval(getDocObj('hidezipfields')).style.display="";
				eval(getDocObj('hidengap5')).style.display="";
				eval(getDocObj('hidengap6')).style.display="";
				eval(getDocObj('hidengap7')).style.display="none";
				eval(getDocObj('hidengap4')).style.display="none";
		}
	}
	
	function displayIfOwnHome(flag) {
	if(flag){

				eval(getDocObj('estValue')).style.display="";
				eval(getDocObj('hidengap1')).style.display="none";
				eval(getDocObj('hidengap5')).style.display="";
	}
	else {

				eval(getDocObj('estValue')).style.display="none";
				eval(getDocObj('hidengap1')).style.display="none";
				eval(getDocObj('hidengap5')).style.display="none";
				
		}
	}
	
function checkSubmit(form){

	if(document.getElementById("firstTimeBuyer").checked==false){
		selectedOption = -1;
		for (i=form.firstTimeBuyer.length-1; i > -1; i--) {
		if (form.firstTimeBuyer[i].checked) {
		selectedOption = i;
		}
		}
		if (selectedOption == -1) {
		alert("Please answer the question: Are You a First Time Buyer?");
		return false;
		}
	}
	
	
	if(document.getElementById("doOwnHome").checked==true){
	
		if(document.getElementById("willSellCurrentHome").checked==false){
		
				selectedOption = -1;
			for (i=form.willSellCurrentHome.length-1; i > -1; i--) {
			if (form.willSellCurrentHome[i].checked) {
				selectedOption = i;
			}
			}
			if (selectedOption == -1) {
				alert("Please answer the question: Selling Your Current Home?");
				return false;
			}
		}
		if(form.homeValue.value==""){
			alert("Please enter the Estimated Home Value for the current home you own.");
			return false;
		}
		if(isNaN(form.homeValue.value)){
			alert("Estimated Home Value must be numeric. No commas or Dollar Signs.");
			return false;	
		  }

		if(form.totalMortgageBalance.value==""){
			alert("Please enter the Amount Owed To Current Mortgage Balances.");
			return false;
		}
		if(isNaN(form.totalMortgageBalance.value)){
			alert("Amount Owed To Current Mortgage Balances Value must be numeric. No commas or Dollar Signs.");
			return false;	
		  }
	}
	
	
	if(document.getElementById("hasFoundHome").checked==true){
		if(document.getElementById("contractSigned").checked==false){
		
				selectedOption = -1;
				for (i=form.contractSigned.length-1; i > -1; i--) {
				if (form.contractSigned[i].checked) {
					selectedOption = i;
				}
				}
				if (selectedOption == -1) {
					alert("Please answer the question: Have You signed A Purchase Contract?");
					return false;
				}

		}

		if(form.newHomeStreet.value==""){
			alert("Please enter the Street of Your New Home.");
			return false;
		}

		if(form.newHomeCity.value==""){
			alert("Please enter the City of Your New Home.");
			return false;
		}

		if(form.newHomeState.value==""){
			alert("Please select the State of Your New Home.");
			return false;
		}

		if (form.newHomeZip.value==""){
		      alert("Please enter the Zip Code of Your New Home.");
		      return false;
		}
		if(isNaN(form.newHomeZip.value)){
		      alert("Zip code of Your New Home must be numeric.");
		      return false;	
		}

	}

	if(document.getElementById("hasFoundHome").checked==false){
		if(form.desiredZipCode1.value==""){
			alert("Please enter a Zip Code of where You Desire To Purchase Your New Home \n in the text field labled Zip Code1.");
			return false;
		}
		if(isNaN(form.desiredZipCode1.value)){
				      alert("The Zip Code of where You Desire To Purchase Your New Home \n Must Be Numeric.");
				      return false;	
		}
	}

	
	
	
	
	if(form.estimatedPurchaseMonth.value==""){
			alert("Please tell us the Month of when you estimate to purchase your home.");
			return false;
	}
	if(form.estimatedPurchaseYear.value==""){
			alert("Please tell us the Year of when you estimate to purchase your home.");
			return false;
	}
	if(form.homeType.value==""){
			alert("Please select the Home Type you plan to purchase.");
			return false;
	}
	if(form.homePurpose.value==""){
			alert("Please select the Home Purpose.");
			return false;
	}
	if(form.estdPurchasePrice.value==""){
			alert("Please select the Estimated Purchase Price.");
			return false;
	}
	if(form.downPaymentPercent.value==""){
			alert("Please select a Down Payment Percent.");
			return false;
	}
	if(form.downPaymentSource.value==""){
			alert("Please select a Down Payment Source.");
			return false;
	}
	

	if(form.desiredMortgageTerm.value==""){
		alert("Please select Desired Mortgage Term.");
		return false;
	}


				
	 if (form.householdIncome.value==""){
      alert("Please select your annual household income.");
      return false;
     }
         if (form.isSelfEmployed.value==""){
      alert("Are you self employed?");
      return false;
     }
	 if (form.workLength.value==""){
      alert("Please select the duration at the current job.");
      return false;
     }     
	 if (form.creditHistory.value==""){
      alert("Please select your credit history.");
      return false;
     }
	 if (form.bankruptcy.value==""){
      alert("Please select your bankruptcy status.");
      return false;
     }

	 if (form.firstName.value==""){
      alert("Please enter your first name.");
      return false;
     }
	 if (form.lastName.value==""){
      alert("Please enter your last name.");
      return false;
     }
     if (form.addressStreet.value==""){
      alert("Please enter your street address.");
      return false;
     }
     if (form.addressCity.value==""){
      alert("Please enter your city.");
      return false;
     }
     if (form.addressState.value==""){
      alert("Please enter your state.");
      return false;
     }
     if (form.addressZip.value==""){
      alert("Please enter your zip code.");
      return false;
     }
     if(isNaN(form.addressZip.value)){
     		alert("Zip code must be numeric.");
     		return false;	
     }
     if (form.phoneWork.value==""){
      alert("Please enter your Work Phone number.");
      return false;
     }
	 var stripped = form.phoneWork.value.replace(/[\(\)\.\-\ ]/g, '');
     if (isNaN(parseInt(stripped))) {
        alert("The Work Phone number contains illegal characters.");
        return false;
     }
     if (!(stripped.length == 10)) {
      alert("The Work Phone number is the wrong length.\nMake sure you included an area code.\n Example: 111-111-1111\n or 1210347897");
      return false;
     }
     if (form.phoneEvening.value==""){
      alert("Please enter your Evening Phone number.");
      return false;
     }
     var stripped = form.phoneEvening.value.replace(/[\(\)\.\-\ ]/g, '');
     if (isNaN(parseInt(stripped))) {
        alert("The Evening Phone number contains illegal characters.");
        return false;
     }
     if (!(stripped.length == 10)) {
      alert("The Evening Phone number is the wrong length.\nMake sure you included an area code.\n Example: 111-111-1111\n or 1210347897");
      return false;
     }
     if (form.contactTime.value==""){
      alert("When is the best time to contact you?");
      return false;
     }
	 if (form.email.value==""){
      alert("Please enter your email address.");
      return false;
     }
	 
	if (!emailCheck(form.email.value)) {
		return false;
	}
     return true;
}//
	 
	 function emailCheck (emailStr) {
	  			 var emailPat=/^(.+)@(.+)$/
	  			 var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	   			 var validChars="\[^\\s" + specialChars + "\]"
	   			 var quotedUser="(\"[^\"]*\")"
	  			 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	  			 var atom=validChars + '+'
	  			 var word="(" + atom + "|" + quotedUser + ")"
	  			 var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	  			 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	   			 var matchArray=emailStr.match(emailPat)
	  				 if (matchArray==null) {
	    				alert("Email address seems incorrect (check @ and .'s)")
	  				  return false
	   				}
	   			var user=matchArray[1]
	   			var domain=matchArray[2]
	  				 // See if "user" is valid
	  				 if (user.match(userPat)==null) {
	      			 // user is not valid
	       				alert("The username of the email address doesn't seem to be valid.")
	       				return false
	  				 }
	   			var IPArray=domain.match(ipDomainPat)
	  				 if (IPArray!=null) {
	       			// this is an IP address
	     				 for (var i=1;i<=4;i++) {
	       					 if (IPArray[i]>255) {
	           					 alert("Destination IP address is invalid!")
	    					 return false
	        				}
	      			 }
	       		return true
	     }
	   // Domain is symbolic name
	   var domainArray=domain.match(domainPat)
	   if (domainArray==null) {
	    alert("The domain name doesn't seem to be valid.")
	       return false
	   }
	   var atomPat=new RegExp(atom,"g")
	   var domArr=domain.match(atomPat)
	   var len=domArr.length
	   if (domArr[domArr.length-1].length<2 ||
	       domArr[domArr.length-1].length>3) {
	      // the address must end in a two letter or three letter word.
	      alert("The email address must end in a three-letter domain, or two letter country.")
	      return false
	   }
	   // Make sure there's a host name preceding the domain.
	   if (len<2) {
	      var errStr="This address is missing a hostname!"
	      alert(errStr)
	      return false;
	   }
	   // If we've gotten this far, everything's valid!
	   return true;
	}