  var whitespace = " \\t\\n\\r"  function MakeLowerCase(str)  {     return str.toLowerCase()  }  function isEmpty(s)  {    return ((s == null) || (s.length == 0))  }  //===================================================================  function isWhitespace (s)  { var i;    if (isEmpty(s)) return true;    for (i = 0; i < s.length; i++){      var c = s.charAt(i);      if (whitespace.indexOf(c) == -1) return false;    }    return true;  }  //===================================================================  function isCharsInBag (s, bag)  {    var i;    // Search through string's characters one by one.    // If character is 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) return false;    }    return true;  }  //===================================================================  function validate(theForm)  {// alert("STARTING VALIDATION - TESTING");      var errMesg = "";    // CHECK ALL THE REQUIRED INFORMATION FIELDS.    // FIRST_NAME, LAST_NAME AND E-MAIL ARE MANDATORY    { var Q = ""; // this block determines lifespan of Q		if (isWhitespace(theForm.chargeCard.value)) Q += "  Credit Card\n";      		if (isWhitespace(theForm.firstName.value)) Q += "  First Name\n";            		if (isWhitespace(theForm.lastName.value)) Q += "  Last Name\n";		if (isWhitespace(theForm.cardNumber.value)) Q += "  Card Number\n";		if (isWhitespace(theForm.ship_to_Name.value)) Q += "  Ship to Name\n";		if (isWhitespace(theForm.ship_to_Address.value)) Q += "  Ship to Address\n";		if (isWhitespace(theForm.ship_to_City.value)) Q += "  Ship to City\n";		if (isWhitespace(theForm.ship_to_State.value)) Q += "  Ship to State\n";		if (isWhitespace(theForm.ship_to_Zip.value)) Q += "  Ship to Zip\n";		if (isWhitespace(theForm.email.value)) Q += "  Email\n";		// ADD CHECKS FOR ADDITIONAL FIELDS HERE EXACTLY AS ABOVE		if ( Q.length> 0 )			{			errMesg += "Please provide valid values for: \n" + Q ;			}    }        	var loginName = theForm.email.value = theForm.email.value.toLowerCase();	var textareaCount;    // VALIDATION OF THE EMAIL (MANDATORY)    if ( !isCharsInBag( loginName, "abcdefghijklmnopqrstuvwxyz0123456789.-_@" ) || (!isCharsInBag( "@", loginName ))  )    	{    	errMesg += "Contact E-mail has invalid characters or missing \"@\".\n" ;    	} 	else if (! isCharsInBag( loginName.charAt(loginName.length - 1),"abcdefghijklmnopqrstuvwxyz"))    	{    	errMesg += "Contact E-mail must end in an alphabetic character.\n";    	}	 else if ( !isCharsInBag( loginName.charAt(0),"abcdefghijklmnopqrstuvwxyz0123456789"))		{     	errMesg += "Contact E-mail name must start with an alphanumeric character.\n";		} 	else if ( loginName.length < 7 )    	{      	errMesg += "Contact E-mail must be 7 or more characters.\n" ;    	}//===================================================================    // VALIDATION OF THE PHONE (MANDATORY)//    var phone = theForm.phone.value;//    if ( phone.length < 10 )//    {//      errMesg += "Phone must be 10 or more digits.\n" ;//    }	    if (errMesg != ""){      alert(errMesg);      return false;    }    theForm.submit();  }