// JavaScript Document

var EmailText;

//---------------------------------

function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = " 0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
//---------------------------------

function checkMail(EmailText)
{
        var x = EmailText;
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(x))
        {
                return true;
        }
        else {
                return false;
        }
}

function checkIfNumber(value) 
{
	var num = new Number();
	num = value;
	if(isNaN(num)) 
	{
		return true;
	}
	else
	{
		return false;
	}
}



function checkContactForm()
{
	
	 if(document.formFooter.selectoption.value==0 || document.formFooter.selectoption.value=='Please select your reason for contacting Housingnet' || !document.formFooter.selectoption.value)
	 {
		document.getElementById('contactErrorMessage').innerHTML = "Please select your reason for contacting Housingnet.";
		//alert("Please select your reason for contacting Housingnet.");
		document.formFooter.selectoption.focus();
		return false;
	 }
	else if(trim(document.formFooter.firstName.value)=="" || document.formFooter.firstName.value=="First Name ...")
	{
	   
	   
	   document.getElementById('contactErrorMessage').innerHTML = "Name should not be empty."
	   document.formFooter.firstName.focus();
	   return false;
	} else if ((trim(document.formFooter.phone.value)!="") &&  (trim(document.formFooter.phone.value)!="Phone ...") && (!IsNumeric(document.formFooter.phone.value))){
	   
	   document.getElementById('contactErrorMessage').innerHTML = "Only numeric characters allowed in the phone field."
	   return false;
		
	}
	else if((trim(document.formFooter.email.value) == '') || (trim(document.formFooter.email.value)=="Email ..."))	{		
		document.getElementById('contactErrorMessage').innerHTML = "Email should not be empty."
		return false;
		
	}  else if(!checkMail(document.formFooter.email.value)){
		document.getElementById('contactErrorMessage').innerHTML = "Invalid Email."
		return false;

	}	else if((trim(document.formFooter.comments.value) == '') || (trim(document.formFooter.comments.value)=="Message ..."))	{		
		document.getElementById('contactErrorMessage').innerHTML = "Message should not be empty."		
		return false;
		
	}  else  {
		 document.getElementById('contactErrorMessage').innerHTML="";
		 document.formFooter.chk_form.value="Submit";
		 
		 sendEmail();
		 //document.formFooter.submit();
	 }
}


