



// new version using array.
function check4HTML(thisField)  {
   //checks for HTML content.
   var ext = thisField.value.toLowerCase()
   var okimg = true
   var imgExtArray = new Array("http://", "<p>", "<p", "<table", "<table>", "<tr", "<tr>", "<td",  "<td>", "javascript.", "alert(", "<body", "<html>", "<meta", "mailto:");
   
   //check for string patters in the field
   for (var i=0; i<imgExtArray.length; i++)
    if (ext == imgExtArray[i]){
    okimg = false
    }
    
    if (okimg == false) {
    alert("For security purposes, we do not permit HTML embedding. Please remove the HTML syntax from: " + thisField.name.toUpperCase() + ".");
    thisField.focus()
    return false;
    }

  return true;
}


//checks for required fields, returns friendly error message based on what errormsg
function reqFieldName(thisField, errorMsg) {

	 fieldLen = thisField.value.length
	 if (fieldLen == 0) {
	 	if (thisField.name == "FILE1") {
	   alert("Please select file to upload.")
	  }else{
	   if (errorMsg == '') {
    	     alert("Please enter " + thisField.name.toUpperCase() + " for this record.");
    	     }else{
	   alert(errorMsg);
	   }
	  }
    thisField.focus();
    return false;
	 }
 return true;
}


function checkSpecialChar(thisField)   {
   t = thisField.value;           //whole string
   filteredValues = ",~!@#$%^&*+|\=`{}'><";        // Characters stripped out
   var j;
   for (j = 0; j < t.length; j++) {  // Search through string and append to unfiltered values to returnString.
    var d = t.charAt(j);
    if (filteredValues.indexOf(d) != -1)  {
     alert("You are not permitted to use the special character(s)>> " + d + " in the field: " + thisField.name.toUpperCase() + "\nPlease remove them to continue.");
     return false;
    }
   }
  return true;
}


function isEmail(email) {
    var x = email.value.indexOf("@")
    var y = email.value.indexOf(".")
    var z = x * y
    if (z < 2) {
      alert("You must enter a valid Email Address.")
      email.focus()
      return false
   }
  return true;
}



function isPostalCode(thisField)
{
   var digits = "0123456789";
   var letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var postalCodeObject = thisField;
   var postalCode = thisField.value.toUpperCase();

   if (postalCode.length == 0)
   {
      //postal code may not be required so just ok it. Can use reqField function to ensure it is entered elsewhere.
      return true;
   }
 
   if (postalCode.length == 7)
   {
      if ((postalCode.substr(3,1) != " ") && (postalCode.substr(3,1) != "-"))
      {
         alert("You have entered an invalid Postal Code. Please use the following format for the postal code Z9Z9Z9. (TIP: do not use spaces or a dash.)");
	 return false;
      }
      else
      {
         postalCode = postalCode.substr(0,3) + postalCode.substr(4,3);
      }
   }

   if (postalCode.length != 6)
   {
      alert("You have entered an invalid Postal Code. Please use the following format for the postal code Z9Z9Z9. (TIP: do not use spaces or a dash.)");
      return false;
   }


   if ((letters.indexOf(postalCode.charAt(0)) < 0) || (letters.indexOf(postalCode.charAt(2)) < 0) ||
       (letters.indexOf(postalCode.charAt(4)) < 0))
   {
      alert("You have entered an invalid Postal Code. Please use the following format for the postal code Z9Z 9Z9.");
      return false;
   }
		
   if ((digits.indexOf(postalCode.charAt(1)) < 0) || (digits.indexOf(postalCode.charAt(3)) < 0) ||
       (digits.indexOf(postalCode.charAt(5)) < 0))
   {
      alert("You have entered an invalid Postal Code. Please use the following format for the postal code Z9Z 9Z9.");
      return false;
   }

   return true; 
}


