        // VARIABLE DECLARATIONS

        var digits = "0123456789";
        var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
        var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        var whitespace = " \t\n\r";
        var pEntryPrompt = "Please enter the following information: "
 
        // CONSTANT STRING DECLARATIONS

        // m is an abbreviation for "missing"
		
        var mPrefix = "Invalid Response! "
        var mSuffix = "This is a required field. Please enter it now."
		
	// p is an abbreviation for "pulldown"

        var pPrefix = "This is a Required Field. "
        var pSuffix = "Please Make your Selection."

	// r is an abbreviation for "radio"
        var rPrefix = "Please answer the following question: "
        var rSuffix = "This is a required field. "
		
         // s is an abbreviation for "string"
    
	var s_name = "Please Enter Your Full Name" 
	var s_fname = "Please Enter Your First Name" 
    var s_lname = "Please Enter Your Last Name" 
    var s_Address = "Please Enter Your Address" 
    var s_City = "Please Enter Your City" 
    var s_State = "Please Select Your State"   
    var s_Zip = "Please Enter Your Zip Code"    
	var s_phone = "Please Enter Your Contact Phone Number"    
	var s_email = "Please Enter The Correct Email Address" 
	var s_email_confirm = "Please Confirm The Correct Email Address"
	var s_confirmEmail = "Your Email Address Does Not Match Please Re-Enter It Again" 
	var s_subject = "Please Enter A Subject"  
	 
	var iDigits = "Please Enter A Valid Number.\n\nPlease re-enter it now.\n\n(This Field May Only Be Numbers)"
	var iZip = "Please Enter The Correct Zip Code.\n\nPlease re-enter it now.\n\n(Field Must Contain 5 Digits)" 
	var iNoWhitespace = "Your Username and Password selections cannot contain whitespace characters (i.e. space, tab, new-line).\n lease re-enter a correct value." 
    var iwarn = "Sorry The Advance Amount You Entered Can Not Exceed $300\n Please Enter The Advance Amount Again."
	var iPhone = "Please Enter The Correct Format.\n\nPlease re-enter it now.\n\n(Field Must Contain 3-digit area code)"
	var iPhone2 = "Please Enter The Correct Format.\n\nPlease re-enter it now.\n\n(Field Must Contain 3-digit prefix phone number)"
	var iPhone3 = "Please Enter The Correct Format.\n\nPlease re-enter it now.\n\n(Field Must Contain 4-digit suffix phone number)"
	    
        // Determines if empty fields are acceptable

        var defaultEmptyOK = false
 
        // Check whether string s is empty.

        function isEmpty(s) {
            return ((s == null) || (s.length == 0));
        }

        // Returns true if string s is empty or
        // whitespace characters only.

        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;
        }

  // Returns true if string s is all digits 
        function isDigits (s) {
                var i;
                // Is s empty?
                if (isEmpty(s)) return false;
                // Search through string's characters one by one
                // until we find a non-digits.
                // When we do, return false; if we don't, return true.
                for (i = 0; i < s.length; i++)
                {
                        var c = s.charAt(i);
                        if (digits.indexOf(c) == -1) return false;
                }
                // All characters are digit.
                return true;
        }
		
        // Removes all characters which appear in string bag from string s.

        function stripCharsInBag (s, bag) {
                var i;
                var returnString = "";
                // Search through string's characters one by one.
                // If character is not 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) returnString += c;
                }
                return returnString;
        }

        // Removes all whitespace characters from s.
        // Global variable whitespace (see above)
        // defines which characters are considered whitespace.
        function stripWhitespace (s) {
            return stripCharsInBag (s, whitespace);
        }

        // Workaround for bug in Navigator 2.02
        function charInString (c, s)
        {   for (i = 0; i < s.length; i++)
                {   if (s.charAt(i) == c) return true;
                }
                return false
        }
        // Removes initial (leading) whitespace characters from s.
        // Global variable whitespace (see above)
        // defines which characters are considered whitespace.
        function stripInitialWhitespace (s)
        {   var i = 0;
                while ((i < s.length) && charInString (s.charAt(i), whitespace))
                   i++;
                return s.substring (i, s.length);
        }

		var badchar = new Array ('!','#','$','%','^','&','*','(',')','[',']','{','}',':',';','\'','"','\\','/','>','<',',','?','`','~','+','=',' ','|');
		
        function checkEmail (theField) {
		
   //check length is less than 128 chars in length
 	 if (theField.value.length > 128) {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }
    
  //check for at least 1 '@' and 1 '.'
  if (theField.value.indexOf('@') <= 0 || theField.value.indexOf('.') <= 0) {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check for more than one '@'
  newval = theField.value.split('@');
  if (newval.length > 2) {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check first part of email string before the '@' for bad characters
  first = newval[0];
  for (x=0; x<badchar.length; x++) {
    newchar = badchar[x];
    if (first.indexOf(newchar) >= 0) {
      alert("Please enter a valid email address so you can receive your confirmation email");
      theField.focus();
      return false;
    }
  }

  //check for '_' and '-' as the first character
  newindex = 0;
  if (first.charAt(newindex) == "_" || first.charAt(newindex) == "-") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check for '_' and '-' and '.' right before the '@'
  newindex = first.length - 1;
  if (first.charAt(newindex) == "_" || first.charAt(newindex) == "-" || first.charAt(newindex) == ".") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check second part of email string after the '@' for bad characters
  second = newval[1];
  for (x=0; x<badchar.length; x++) {
    newchar = badchar[x];
    if (second.indexOf(newchar) >=0) {
      alert("Please enter a valid email address so you can receive your confirmation email");
      theField.focus();
      return false;
    }
  } 

  //check for '_' and '-' and '.' right after the '@'
  newindex = 0;
  if (second.charAt(newindex) == "_" || second.charAt(newindex) == "-" || second.charAt(newindex) == ".") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check for '_' and '-' as the last character
  newindex = second.length - 1;
  if (second.charAt(newindex) == "_" || second.charAt(newindex) == "-") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check for some extension after last '.' in email address
  second1 = second.split('.');
  newindex = second1.length - 1;
  if (second1[newindex].length <= 1) {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }

  //check for '_' and '-' and '.' before and after the last '.'
  newlen = second.length;
  newstr = new Array(newlen);
  for (x=0; x<newlen + 1; x++) {
    newstr[newlen-x] = second.substring(x,x+1);
  }
  laststr = "";
  for (x=0; x<newstr.length; x++) {
    laststr += newstr[x];
  }
  newindex = laststr.indexOf('.');
  if (laststr.charAt(newindex + 1) == "_" || laststr.charAt(newindex + 1) == "-") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }
  if (laststr.charAt(newindex - 1) == "_" || laststr.charAt(newindex - 1) == "-") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }
  if (laststr.charAt(newindex + 1) == ".") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }
  if (laststr.charAt(newindex - 1) == ".") {
    alert("Please enter a valid email address so you can receive your confirmation email");
    theField.focus();
    return false;
  }
  
    return true;
}

        // Display prompt string s in status bar.
        function prompt (s)
        {   window.status = s

        }

        // Display data entry prompt string s in status bar.
        function promptEntry (s)
        {   window.status = pEntryPrompt + s

        }

		function warnRadio (theField, s)
        {   theField[0].focus()
                alert(rPrefix + "\n\n" + s + "\n\n" + rSuffix)
                return false
        }
		
        function warnEmpty (theField, s)
        {   theField.focus()
                alert(mPrefix + "\n\n" + s + "\n\n" + mSuffix)
                return false
        }

        function warnInvalid (theField, s)
        {   theField.focus()
                theField.select()
                alert(s)
                return false
        }
        
        // Check that string theField.value is not all whitespace.
        function checkString (theField, s, emptyOK)
        {   // Make sure the field exists before completing the test
                if (theField == null) return true;
                // Next line is needed on NN3 to avoid "undefined is not a number" error
                // in equality comparison below.
                if (checkString.arguments.length == 2) emptyOK = defaultEmptyOK;
                if ((emptyOK == true) && (isEmpty(theField.value))) return true;
                if (isWhitespace(theField.value))
                   return warnEmpty (theField, s);
                else return true;
        }
		
		
	function checkAllDigits (theField, warn, emptyOK)
        {   
                if (theField == null) return true;
		if (checkAllDigits.arguments.length == 2) emptyOK = defaultEmptyOK;
                if ((emptyOK == true) && (isEmpty(theField.value))) return true;
		else if (!isDigits(theField.value)) return warnInvalid (theField, warn);
                else return true;
        }
		
	function checkDigits (theField, max_length, warn, emptyOK)
        {    
                if (theField == null) return true;
		if (checkDigits.arguments.length == 4) emptyOK = defaultEmptyOK;
                if ((emptyOK == true) && (isEmpty(theField.value))) return true;
		if (!isDigits(theField.value)) return warnInvalid (theField, warn);
		else if (!isCertainLength(theField,max_length, warn)) return false;
                else return true;
        }
		
		
		
	function isCertainLength(theField, max_length, warn)
        {
		if (theField.value.length == max_length)
    		  return true;
		else 
    		  return warnInvalid (theField, warn)
	}

		
 	function checkPulldown (theField, s, emptyOK)
        { 
                if (theField == null) return true;
   		if ((emptyOK == true) && (isEmpty(theField.value))) return true;
                txt=theField.options[theField.selectedIndex].value;
                if (txt == "")
                   return warnPulldown (theField, s);
                else
                   return true;
        }


 	function warnPulldown (theField, s)
        {   
		theField.focus()
                alert(pPrefix + "\n\n" + s + "\n\n"  + pSuffix)
                return false;
        }  
		 
	function AddString(first_num, second_num, third_num, f_num, deli)
	{
                if (first_num == null) return true;
 		f_num.value = first_num.value + deli + second_num.value + deli + third_num.value;
		return true;
	}
	
	function AddString2(first_num, second_num, f_num)
	{
                if (first_num == null) return true;
 		f_num.value = first_num.value + " " + second_num.value;
		return true;
	}
	  
	  
     function check_count(form, num_limit, current_field, next_field)
	{  
		current_length = eval("form." + current_field + ".value.length");
	    next = eval("form." + next_field);
		if (current_length == num_limit)
		{
		   next.focus();
		}
		return true;
	
	} 
	
		function checkConfirmEmail(theField, theField2, s) 
		{   
		    theFieldValue  = theField.value;
			theField2Value = theField2.value; 
			if (theField == null) return true;
			if (theField2 == null) return true; 
            if (theFieldValue == theField2Value) return true;  
            else
		        return warnEmail (theField, theField2, s);
   		}
		
		function warnEmail (theField,theField2, s)
        {   theField2.focus()
                alert("Sorry Please Check This Field Again !" + "\n\n" + s + "\n\n" + "( Your Email Addresses Does Not Match )");
                return false
        }
		 
        function checkCatalog(form)  {
        var selectType = form.catalog.checked; 
		if(selectType == true)
		{   return (
		 checkString(form.elements["address"],s_Address) &&
		 checkString(form.elements["city"], s_City) &&
	 	 checkString(form.elements["state"], s_State) 
			 )
        }
		else return true;
		}
		
		function checkCatalogF(form)  {
        var selectType = form.fcatalog.checked;
		if(selectType == true)
		{   return ( 
		 checkEmail(form.elements["femail"]) && 
		 checkConfirmEmail(form.elements["femail"],form.elements["confemail"],s_confirmEmail) &&
		 checkString(form.elements["faddress"],s_Address) &&
		 checkString(form.elements["fcity"], s_City) &&
	 	 checkString(form.elements["fstate"], s_State) &&
		 checkDigits(form.elements["fzip"],5,iZip)  
			 )
        }
		else return true;
		}
		  
        function validateForm(form)
        {   return (  
        checkString(form.elements["fname"],s_fname) &&
        checkString(form.elements["lname"],s_lname) && 
		checkEmail(form.elements["email"]) && 
		checkEmail(form.elements["email_confirm"]) &&
		checkConfirmEmail(form.elements["email"],form.elements["email_confirm"],s_confirmEmail) &&
        checkString(form.elements["address"],s_Address) &&
        checkString(form.elements["city"],s_City) &&
        checkPulldown(form.elements["state"], s_State) &&  
		checkDigits(form.elements["zip"],5,iZip)  
		 )
        }
		function validateDir(form)
        {   return (   
		checkString(form.elements["1a"],s_Address) &&
        checkString(form.elements["1c"],s_City) &&
		checkPulldown(form.elements["1s"], s_State) &&  
		checkDigits(form.elements["1z"],5,iZip)  
		 )
        }
		function checkFormEmail(form)
        {   return (   
		checkString(form.elements["fname"],s_fname) &&
        checkString(form.elements["lname"],s_lname) &&  
		checkEmail(form.elements["email"]) && 
		checkConfirmEmail(form.elements["email"],form.elements["conemail"],s_confirmEmail) &&
		checkString(form.elements["phone"],s_phone) &&  
		checkDigits(form.elements["zip"],5,iZip) &&
		checkCatalog(form)
		 )
        }
		
		function checkFormTellEmail(form)
        {   return (   
		checkString(form.elements["name"],s_fname) && 
		checkEmail(form.elements["email"]) && 
		checkConfirmEmail(form.elements["email"],form.elements["conemail"],s_confirmEmail) &&
		checkCatalog(form) 
		 )
        }  
		
		function contactVal(form)
        {   return (  
		 checkString(form.elements["fname"],s_fname) &&
         checkString(form.elements["lname"],s_lname) && 
		 checkEmail(form.elements["email"]) && 
		 checkEmail(form.elements["email_confirm"]) && 
		 checkDigits(form.elements["Phone_h_area"],3,iPhone) &&
	 	 checkDigits(form.elements["Phone_h_prefix"],3,iPhone2) &&
		 checkDigits(form.elements["Phone_h_sufix"],4,iPhone3) &&  
		 AddString(form.elements["Phone_h_area"], form.elements["Phone_h_prefix"], form.elements["Phone_h_sufix"], form.elements["phone_hm"], "-") &&
		 checkString(form.elements["comment"], s_comment) 
		 )
        }
