﻿function EmailAddress(sMessage)
{
	var string1 = "Support";
	var string2 = "@";
	var string3 = "Ezee-PC.com";
	var string4 = "?subject=Enquiry_for_Ezee-PC";
	document.write("<a href=" + "mail" + "to:" + string1 + string2 + string3 + string4 + ">" + sMessage + "</a>");
}


function IsEmpty(sText)
/** Test to see if string is empty **/
{
   if ((sText.length==0) ||
   (sText==null)) {
      return true;
   }
   else { return false; }
}


function IsNumeric(sText)
/** Test to see if string is not empty and contains numbers**/
{
   var ValidChars = "0123456789+ -.()";
   var IsNumber=true;
   var Char;

 
   if (sText.length == 0) return false;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
}


function IsValidEmail(sText)
/** Simple email format check: ensures string is not empty and there is a dot and @ sign **/
{
   return (sText.indexOf(".") > 0) && (sText.indexOf("@") > 0) && (sText.length > 0); 
}


function validateForm()
{
	var sMessage = "";
    	
    /** Get data from form **/
    formObj = document.Enquiry;
        
    /** Check name is not empty **/
    if(IsEmpty(formObj.Name.value)) 
    { 
		sMessage = sMessage + "Please enter your Name.\r\n"; 
    } 
    
    /** Check phone number **/
 	if (!IsNumeric(formObj.Phone.value)) 
	{ 
		sMessage = sMessage + "Please enter a valid Phone Number.\r\n";
    } 
 
    /** Check email address is valid **/
    if(!IsValidEmail(formObj.EMAddress.value)) 
    { 
		sMessage = sMessage + "Please enter a valid Email Address.\r\n"; 
    } 
     
    /** Check address is not empty **/
    if(IsEmpty(formObj.Address.value)) 
    { 
		sMessage = sMessage + "Please fill in an address.\r\n"; 
    } 
    
    /** Check the Message is not empty **/
    if(IsEmpty(formObj.Question.value)) 
    { 
		sMessage = sMessage + "Please complete your enquiry in the enquiry field.\r\n"; 
    } 
    
	if (sMessage != "")
		{
		/* Display alert window if one or more fields are not valid */
		sMessage = "You have not filled out the form correctly:\r\n\r\n" + sMessage;
		alert (sMessage);
		return false;
		}
	else
		return true; 
} 
