function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value ="";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}

function isValidEmail(str) {

   return (str.indexOf("@") > 0);

}
function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
function alltrim(str) 
{
                return str.replace(/^\s+|\s+$/g, '');
 }

 function removeSpaces(string)
    {
        return string.split(' ').join('');
    }

function validContactForm()
{
	if(alltrim(document.form1.fname.value) == "First Name" || alltrim(document.form1.fname.value) == ""  )
	{
		alert("Please enter your first name");
		document.form1.fname.focus();
		return false;
	}
	
	if(alltrim(document.form1.lname.value) == "Last Name" || alltrim(document.form1.lname.value) == ""  )
	{
		alert("Please enter your last name");
		document.form1.lname.focus();
		return false;
	}
	
	if (alltrim(document.form1.email.value)=="Email Address" || alltrim(document.form1.email.value)=="")
    {
        alert ("please enter your email.")
        document.form1.email.focus();
        return false;
    }



    emailExp= /^\w+(\-\w+)*(\.\w+(\-\w+)*)*@\w+(\-\w+)*(\.\w+(\-\w+)*)+$/;
	if (!(emailExp.test(document.form1.email.value)))
	{ 
		alert("Invalid email address");
		document.form1.email.focus();
		return false;  
	} 
	
    if(alltrim(document.form1.phone.value) == "Phone Number" || alltrim(document.form1.phone.value) == ""  )
	{
		alert("Please enter your phone number in full, including area code and no spaces.");
		document.form1.phone.focus();
		return false;
	}


	
   if (!IsNumeric(document.form1.phone.value))
   {

       alert ("Please enter your phone number numeric , including area code and no spaces.");
       document.form1.phone.focus();
       return false;
   }
//alert(document.form1.phone.value.length);	 
   if ((document.form1.phone.value.length < 8))
   {
       alert ("Phone no. should be minimum 8 characters.");
       document.form1.phone.focus();
       return false;
   }

   if(alltrim(document.form1.loan_type.value) == "Type of Loan" || alltrim(document.form1.loan_type.value) == ""  )
	{
		alert("Please select Loan Type");
		document.form1.loan_type.focus();
		return false;
	}
	
	if(alltrim(document.form1.credit_history.value) == "Credit History" || alltrim(document.form1.credit_history.value) == ""  )
	{
		alert("Please select credit history");
		document.form1.credit_history.focus();
		return false;
	}
	if(alltrim(document.form1.propertyvalue.value) == "Property Value" || alltrim(document.form1.propertyvalue.value) == ""  )
	{
		alert("Please enter property value");
		document.form1.propertyvalue.focus();
		return false;
	}
	
	if(alltrim(document.form1.loanamount.value) == "Loan Amount" || alltrim(document.form1.loanamount.value) == ""  )
	{
		alert("Please enter loan amount");
		document.form1.loanamount.focus();
		return false;
	}

        var str1 = removeSpaces(document.getElementById('txtCaptcha').value);
        var str2 = removeSpaces(document.getElementById('txtInput').value);
        if (str1 == str2)
		{ return true;  }
		else
		{
		alert("Do not match Captcha code;");       
        return false;
		}
	
       return true;	
}



