// JavaScript Document

	// define the error message area
	var errMsg = "";

// ! check if field is empty
/*   The isEmpty and isWhitespace functions were taken straight from Netscape's JavaScript development site, http://developer.netscape.com.*/

      // whitespace characters
      var whitespace = " \t\n\r";
      /****************************************************************/
      // Check whether string s is empty.
      function isEmpty(s)
      { return ((s == null) || (s.length == 0)) }
      /****************************************************************/
      function isWhitespace (s)
      {
           var i;
           // Is s empty?
           if (isEmpty(s)) return true;
           // Search through string's characters one by one
           // until we find a non-whitespace character.
           // When we do, return false; if we don't, return true.
           for (i = 0; i < s.length; i++)
           {
                // Check that current character isn't whitespace.
                var c = s.charAt(i);
                if (whitespace.indexOf(c) == -1) return false;
           }
           // All characters are whitespace.
           return true;
      }

// ! if whitespace check field empty, display error message
	// function to display error message
      function ForceEntry(val, str) {
           var strInput = new String(val.value);

           if (isWhitespace(strInput)) {
                //alert(str);
			    errMsg += ("<li>" + str + "</li>");
				/*val.style.backgroundColor ="#fa7acd";*/
                return false;
           } else
		   		val.style.backgroundColor ="white";
                return true;

      }
	
	// function to check email
	function echeck(val, msg) {
		/*if(val.value!=document.getElementById('email2').value){
			errMsg += ("* Email addresses do not match." + "<br>");
			return false;
		} */    
		
        var str = new String(val.value);
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   errMsg += ("<li>" + msg + "</li>");
		   /*val.style.backgroundColor ="#fa7acd";*/
		   return false;
		}
		else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   errMsg += ("<li>" + msg + "</li>");
		   /*val.style.backgroundColor ="#fa7acd";*/
		   return false;
		}
		else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    errMsg += ("<li>" + msg + "</li>");
			/*val.style.backgroundColor ="#fa7acd";*/
		    return false;
		}
		else if (str.indexOf(at,(lat+1))!=-1){
		    errMsg += ("<li>" + msg + "</li>");
			/*val.style.backgroundColor ="#fa7acd";*/
		    return false;
		 }
		 else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    errMsg += ("<li>" + msg + "</li>");
			/*val.style.backgroundColor ="#fa7acd";*/
		    return false;
		 }
		 else if (str.indexOf(dot,(lat+2))==-1){
		    errMsg += ("<li>" + msg + "</li>");
			/*val.style.backgroundColor ="#fa7acd";*/
		    return false;
		 }
		 else if (str.indexOf(" ")!=-1){
		    errMsg += ("<li>" + msg + "</li>");
			/*val.style.backgroundColor ="#fa7acd";*/
		    return false;
		 }else{ 
		 	 val.style.backgroundColor ="white";
     		 return true;					
		}	 
	}
	
	
	//-- form check for enquiry form START --//
	function checkEnquiry() {
	
	   	errMsg = "";
	   
		var messages = false;
		var name = false;
		var contact = false;
   		var email = false;		
		
		//can be any name = ForceEntry will return (document.form name.field name),";
        messages = ForceEntry(document.forms[0].messages,"<span>Please type in your message.</span>");
        name = ForceEntry(document.forms[0].name,"<span>Please supply your name.</span>");
   		contact = ForceEntry(document.forms[0].contact,"<span>Please supply your contact number.</span>");	
        email = echeck(document.forms[0].email,"<span>Please supply your email.</span>");		

			if(messages&&name&&contact&&email) {
		   	   //alert 'test';
			   return true;		
			   
		   } else {
		   	   document.getElementById('errArea').innerHTML = "<br><b>Errors</b><br>" + "<ul>" + errMsg + "</ul>";
			   window.scrollTo(0,0);
			   return false;
		   }
	}	
	//-- form check for enquiry form END --//	