
function Form_Validator(theForm)
{

  if (theForm.Name.value == "")
  {
    alert("Please enter your \"Name\".");
    theForm.Name.focus();
    return (false);
  }
  
  if (theForm.HomePhone.value == "")
  {
    alert("Please enter your \"Home Phone\".");
    theForm.HomePhone.focus();
    return (false);
  }
  
  if (theForm.Address1.value == "")
  {
    alert("Please enter your \"Address 1\".");
    theForm.Address1.focus();
    return (false);
  }
  
  if (theForm.City.value == "")
  {
    alert("Please enter your \"City\".");
    theForm.City.focus();
    return (false);
  }
  
  if (theForm.State.value == "")
  {
    alert("Please select your \"State\".");
    theForm.State.focus();
    return (false);
  }
  
  if (theForm.Email.value == "")
  {
    alert("Please enter your \"personal email address\".");
    theForm.Email.focus();
    return (false);
   }
  else
  {
    //  Validate Personal Email Address
  	    var email = theForm.Email
		var name = "personal e-mail address"
		var fncReturn = Email_Validator(email , name)
		if (fncReturn == false)
		{
		theForm.Email.focus();
        return (false);
		}
   }
  
   if (theForm.BestTimeToReach.value == "") 
  		{
    		alert("Please enter the \"Best Time To Reach You\".");
   			theForm.BestTimeToReach.focus();
    		return (false);
  		}
  
   if (theForm.AnnualIncome.value == "") 
 		{
    		alert("Please enter your \"Annual House Hold Income\".");
   			theForm.AnnualIncome.focus();
    		return (false);
  		}
// Check Credit History Radio Buttons to make sure one is selected
	if (!CheckCreditHistory(theForm))
		{
			return(false);
		}
	
  if (theForm.CCMinPayment.value == "")
  	{
		   	alert("Please enter your \"Minimum Credit Card Payment\". If you do not have a credit card payment then enter 0.");
   			theForm.CCMinPayment.focus();
    		return (false);
	}
  if (theForm.CarPayment.value == "")
  	{
		   	alert("Please enter the amount of your \"Car Payment\". If you do not have a car payment then enter 0.");
   			theForm.CarPayment.focus();
    		return (false);
	}
  if (theForm.StudentLoan.value == "")
  	{
		   	alert("Please enter the amount of your \"Student Loan\". If you do not have a student loan then enter 0.");
   			theForm.StudentLoan.focus();
    		return (false);
	}
  if (theForm.OtherExpenses.value == "")
  	{
		   	alert("Please enter the amount of \"Other Expenses\" that you might have. If you do not have any other expenses then enter 0.");
   			theForm.OtherExpenses.focus();
    		return (false);
	}
	
// Check Time Frame Radio Buttons to make sure one is selected
	if (!CheckTimeFrame(theForm))
		{
			return(false);
		}

// Check Realtor Info Radio Buttons to make sure one is selected
	if (!CheckRealtorInfo(theForm))
		{
			return(false);
		}
		
  if (theForm.Price1.value == "")
  	{
		   	alert("Please enter your \"Minimum Price\".");
   			theForm.Price1.focus();
    		return (false);
	}
   if (theForm.Price2.value == "")
  	{
		   	alert("Please enter your \"Max Price\".");
   			theForm.Price2.focus();
    		return (false);
	}
   
    if (theForm.DownPayment1.value == "")
  	{
		   	alert("Please enter your \"Min Down Payment\".");
   			theForm.DownPayment1.focus();
    		return (false);
	}
    if (theForm.DownPayment2.value == "")
  	{
		   	alert("Please enter your \"Max Down Payment\".");
   			theForm.DownPayment2.focus();
    		return (false);
	}
  
 
  return (true);
  //return (false);
}


//***************************************************************************************

// Checks to see if the Price is numeric and a valid whole number
// Dependent functions "isInteger(), getFront(), stripCharsInBag(),"
// "Commafy()"
function isPrice(inputStr){

	//var Price = document.forms["BlankForm"].Price.value;
	var Price = inputStr.value;
	
	Price = getFront(Price, ".")
	Price = stripCharsInBag(Price, ",$ ")	
	
		if (isInteger(Price))
		{		
			Price = Commafy(Price);
			//thisPrice.value = Price
			inputStr.value = "$" + Price + ".00";
		    return (true);
		}
		else
		{
			//thisPrice.select
			//thisPrice.focus
			inputStr.select;
			inputStr.focus;
			alert("The \"Price\" is not a valid \"Currency\".");
			return(false);   
		}
}
//*************************************************************************************

// Checks to see if the value is an Integer
// Dependent functions are "isEmpty, isDigit"
function isInteger(s){
   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}






//**************************************************************************************
function getFront(mainStr, searchStr){
	foundOffset = mainStr.indexOf(searchStr)
	if (foundOffset == -1){
		return mainStr
	}
	return mainStr.substring(0, foundOffset)
}

//**************************************************************************************
// Removes all characters which appear in string bag from string s.
// Example stripCharsInBag(s, ",.- ") this would remove a comma, period,
// hyphen and a space
function stripCharsInBag (s, bag){   
	var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}
//*************************************************************************************

function Commafy(Price){
	var re = /(-?\d+)(\d{3})/
	var num = Price
	while (re.test(num)) {
		num = num.replace(re, "$1,$2")
		}
		return(num)
}

//***************************************************************************************

// Check whether string s is empty.
function isEmpty(s){   
	return ((s == null) || (s.length == 0))
}

//**************************************************************************************

// Returns true if character c is a digit 
// (0 .. 9).
function isDigit(c){ 
	 return ((c >= "0") && (c <= "9"))
}

//*************************************************************************************
// general purpose function to see
// if a suspected numeric input is a Number
function isNumber(inputStr) {
	for (var i = 0; i < inputStr.length; i++) {
		var oneChar = input.substring(i, i + 1)
		if (oneChar < "0"  || oneChar > "9") {
			alert("Please make sure Entries are numbers only.")
			return false
		}
	}
	return true
}


   
// Checks to make sure that a credit history was selected
function CheckCreditHistory(form) {

	//var form = theForm
	var bCheck = 0
	for (var i = 0; i < form.rbCredit.length; i++) {
		if (form.rbCredit[i].checked) {
			bCheck = 1
			break
		}
	}
			
	if(bCheck) {
		return (true);
	}else{
		alert("Please select your \"Credit History\".");
   		form.rbCredit[0].focus();
		return (false);
	}
}

// Checks to make sure that a time frame was selected
function CheckTimeFrame(form) {

	//var form = theForm
	var bCheck = 0
	for (var i = 0; i < form.rbTimeFrame.length; i++) {
		if (form.rbTimeFrame[i].checked) {
			bCheck = 1
			break
		}
	}
			
	if(bCheck) {
		return (true);
	}else{
		alert("Please select a \"Time Frame\".");
   		form.rbTimeFrame[0].focus();
		return (false);
	}
}

// Checks to make sure that a time frame was selected
function CheckRealtorInfo(form) {

	//var form = theForm
	var bCheck = 0
	for (var i = 0; i < form.rbRealtorInfo.length; i++) {
		if (form.rbRealtorInfo[i].checked) {
			bCheck = 1
			break
		}
	}
	
	if (form.rbRealtorInfo[0].checked){
		if (form.RealtorsName.value == ""){
			alert("Please provied the \"Realtors Name\".");
			bCheck = 0
			form.RealtorsName.focus();
			return (false);
		}
	}
			
	if(bCheck) {
		return (true);
	}else{
		alert("Please select if your are \"Working With a Realtor\".");
   		form.rbRealtorInfo[0].focus();
		return (false);
	}
}
//-->
