//vars to determine browser
bV=parseInt(navigator.appVersion);
NS4=(document.layers) ? true : false;
IE4=((document.all)&&(bV>=4))?true:false;

//used to pop up help window
  function help()
    {
    window.open("", "help", "width=600,height=600,resizable=yes,scrollbars=yes,status=no,directories=no,menubar=no,toolbar=no")
  }


  // doomSay drives the warning which pops up when an attempt is made to delete or unlink something
  function doomSay(VoiceOfDoom) {
    if (confirm(VoiceOfDoom)) {
      return true
    } else {
      return false
    }
  }

  // droplist is maintained only for reference for later when addressing the rogue lists
  function droplist(member) {
    if (confirm('You are about to remove the current address from this list.  Are you sure?')) {
      window.open('ListLink.asp?member=' + member + '&return=' + escape('address.asp?address=<% = URLaddress %>&process=<% = URLprocess %>&track=av'), '_self')
    }
  }



function stripEntry(newdata) {
	newdata=newdata.replace(/\(/g, "")
	newdata=newdata.replace(/\)/g, "")
	newdata=newdata.replace(/ /g, "")
	newdata=newdata.replace(/-/g, "")
	return newdata;
}


//checkspecific - this function can be used to check for specific character, number or combination sets.
//i.e. if you want to only check for alpha characters, use a type value of alpha.

function checkspecific(thisField, type) {
	var validchars;
	if (type == "int") {
     validchars = "0123456789+-";
  } else {
  	if (type == "absint") {
  		validchars = "0123456789";
  	} else {
  	  if (type == "abs") {
  	  	validchars = "0123456789.";
      } else {
  	    if (type == "dec") {
  	    	validchars = "0123456789.-+";
        } else {
    	    if (type == "char") {
  	      	validchars = "abcdefghijklmnopqrstuvwxyz";
          } else {
  	        if (type == "numchar") {
  	        	validchars = "abcdefghijklmnopqrstuvwxyz1234567890";
  	        } else {
  	        if (type == "nozero") {
  	        	validchars = "123456789";
              }
            }
          }
        }
      }
    }
  }
 newdata = thisField.value;
  x = true;
  for (var i=0; i < newdata.length; i++) {
    temp = "" + newdata.substring(i, i+1);
    if (validchars.indexOf(temp) == "-1") x = false;
  }
  if (!x) return false;
  return true;
}

function isdigit(thisField) {
 var validchars = "0123456789";
 newdata = thisField.value
  x = true
  for (var i=0; i < newdata.length; i++) {
    temp = "" + newdata.substring(i, i+1);
    if (validchars.indexOf(temp) == "-1") x = false;
  }
  //if (!x) return false;
  if (!x) {
    alert("This field can be a numeric value only. Please enter a number.")
    thisField.focus()
    return false;
  }
  return true;
}


function rightlength(thisField) {
	newdata = thisField.value
	if (newdata.length < 10) return false;
	return true;
}

function formatnum(thisField) {
  newdata = thisField.value
  len = newdata.length
  if (len == 11 && (newdata.substring(0,4) == "1800" || newdata.substring(0,4) == "1888" || newdata.substring(0,4) == "1900" || newdata.substring(0,4) == "1866" || newdata.substring(0,4) == "1877")) {
  newdata = '(' + newdata.substring(0,4) + ') ' + newdata.substring(4,7) +  '-'  + newdata.substring(7,len);
  }
  if (len == 10) {
   newdata = '(' + newdata.substring(0,3) + ') ' + newdata.substring(3,6) +  '-'  + newdata.substring(6,10);
  }
  thisField.value = newdata
}

function validatePhoneNumber(thisField) {
  var x = true
  thisField.value = stripEntry(thisField.value)
  if (!isdigit(thisField)) { x = false;}
  if (!rightlength(thisField)) { x = false;}
  if (!x) {
   alert("Your phone number is incorrect. Please check if it is in the right format (i.e. (###)###-####). Ref: " + thisField.name.toUpperCase())
   thisField.focus()
   x = true
   return false
  }
  formatnum(thisField)

  return true;
}

//checks to see if the user has entered more than the allowed field limit
function checkFieldLen(thisField,len) {
    fieldLen = thisField.value.length
    if (fieldLen > len) {
    //alert("Make sure that the " + thisField.name.toUpperCase() + " filed has been properly completed.")
    alert("The " + thisField.name.toUpperCase() + " field must be less than or equal to " + len + " characters (spaces and other special characters included).")
    thisField.focus()
    return false
  }
 return true;
}
//checks to ensure that the field has at least x characters in it
function checkFieldLenMin(thisField,len) {
    fieldLen = thisField.value.length
    if (fieldLen < len) {
    //alert("Make sure that the " + thisField.name.toUpperCase() + " filed has been properly completed.")
    alert("The " + thisField.name.toUpperCase() + " field must have at least  " + len + " characters (spaces and other special characters included).")
    thisField.focus()
    return false;
  }
 return true;
}



function reqField(thisField) {
	 fieldLen = thisField.value.length
	 if (fieldLen == 0) {
	 	if (thisField.name == "FILE1") {
	   alert("Please select file to upload.")
	  }else{
	   alert("Please enter " + thisField.name.toUpperCase() + " for this record.");
	  }
    thisField.focus();
    return false;
	 }
 return true;
}


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


// new version using array.
function checkFileXt(thisField)  {
   //check file extensions
   var filename = thisField.value.toLowerCase()
//   var okimg = false
  var okimg = true
   var imgExtArray = new Array(".exe", ".vbs", ".mpg", ".mpeg", ".vsd", ".vba", ".pif", ".ocx", ".ini", ".hta", ".dot", ".dll", ".bin", ".com", ".avi", ".bat", ".mp3");
   //alert(imgExtArray.length);

   var x = filename.lastIndexOf(".")
   var y = filename.length
   var ext = filename.substring(x,y)

   //check to make sure image is of the allowable type
   for (var i=0; i<imgExtArray.length; i++)
    //alert(imgExtArray[i]);
    if (ext == imgExtArray[i]){
    okimg = false
    }

    //alert(okimg)

    if (okimg == false) {
    //alert("You are not permitted to upload files of this extension: (" + ext + ") Please upload a file as permitted in the description of this page.");
    alert("For security concerns, we do not permit files of this type (" + ext + ") to be uploaded to our systems. Please choose another file.");
    thisField.focus()
    return false;
    }

  return true;
}

// improved version from checkFileXt. This one allows you to send in an array of values that you WANT the file you are uploading to be equal to
// if the file does not match, an error is returned.
// Sample:
//   var imgExtArray = new Array(".xls", ".doc", ".rtf", ".pdf");    -these are the file xt I am checking against
//   if (!checkFileXt2(uploadedfile, imgExtArray) return false;

function checkFileXtRev(thisField, extArray)  {
   //check file extensions
   var filename = thisField.value.toLowerCase()
   var okimg = false
   //var imgExtArray = new Array(".vbs", ".mpg", ".mpeg", ".vsd", ".vba", ".pif", ".ocx", ".ini", ".hta", ".dot", ".dll", ".bin", ".com", ".avi", ".bat", ".mp3");
   //alert(imgExtArray.length);

   var x = filename.lastIndexOf(".")
   var y = filename.length
   var ext = filename.substring(x,y)

   //check to make sure image is of the allowable type
   for (var i=0; i<extArray.length; i++)
    //alert(imgExtArray[i]);
    if (ext == extArray[i]){
    okimg = true
    }

    //alert(okimg)

    if (okimg == false) {
    alert("Files of this type (" + ext + ") are not permitted.");
    thisField.focus()
    return false;
    }

  return true;
}



function checkFileXtImage(thisField)  {
   //check file extensions
   var filename = thisField.value.toLowerCase()
   var okimg = false
   var imgExtArray = new Array(".gif", ".GIF", ".jpg", ".JPG");
   //alert(imgExtArray.length);

   var x = filename.lastIndexOf(".")
   var y = filename.length
   var ext = filename.substring(x,y)

   //check to make sure image is of the allowable type
   for (var i=0; i<imgExtArray.length; i++)
    //alert(imgExtArray[i]);
    if (ext == imgExtArray[i]){
    okimg = true
    }

    //alert(okimg)

    if (okimg == false) {
    alert("You are not permitted to upload files of this extension: (" + ext + ") Please upload a file as permitted in the description of this page.");
    thisField.focus()
    return false;
    }

  return true;
}

function checkFileName(thisField)   {
   s = thisField.value;           //whole string
   filteredValues = "~!@#$%^*+|\=`{}'><,";        // Characters stripped out
   var i;
   var period = 0;
   for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
    var c = s.charAt(i);
//    if (c == ".") period  = period + 1;
    if (filteredValues.indexOf(c) != -1)  {
     //alert("You are not permitted to use " + c + " in the filename. Please rename your file and upload again.");
     alert("You are not permitted to use " + c + " in the filename.\nPLEASE RENAME FILE ON YOUR COMPUTER FIRST, then choose BROWSE again and add it.");
     return false
    }
//    if (period > 1) {
//     alert("You are not allowed to use more than 1 period '.' in the filename. \nFor example, an allowed filename would look like this: filename.ext. \nPlease rename your file and upload again.");
//     return false
//    }
   }
  return true;
}
// checks if user entered any special characters - used in search submission boxes. Used in combination with CheckFieldLenMin() to ensure that
//user has both entered a min # of chars and not used special characters.
//sample:  checkSpecialCharFilter(Lname)
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;
}

// checks if user entered any special characters - used in search submission boxes. this one is different from CheckSpecialChar()
//in that it allows the user to pass in the characters to be checked against.
// sample:  checkSpecialCharFilter(Lname, "~!@#$%^&*+|\=`{}'><_")
function checkSpecialCharFilter(thisField, FilterVals)   {
   t = thisField.value;           //whole string
   filteredValues = FilterVals;
   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 + "\nPlease remove them to continue.");
     return false;
    }
   }
  return true;
}

function noCommas(thisField)   {
   s = thisField.value;           //whole string
   var i;
   x = true
   for (i = 0; i < s.length; i++) {  // Search through string and append to unfiltered values to returnString.
    var c = s.charAt(i);
    if (c == ",")  x = false;
   }
   if (!x)  {
    alert("Please do not use commas ',' in the field (Keyword) . A simple space between words is sufficient. (i.e. instead of 'water, sewage' use 'water sewage'");
    thisField.focus()
    return false
   }
  return true;
}

function reqSelectList(thisField) {
	fieldVal = thisField.options[0].selected
  if (fieldVal) {
  	var len = thisField.name.length
  	var fieldname = thisField.name.substring(0,len-2)
    alert("Please select " + fieldname.toUpperCase() + " for this record.")
    //alert("Please make a selection for this field.")
    thisField.focus()
    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 checkPostCode(thisField) {
  postalCode = stripEntry(thisField.value)
  postalCodelen = postalCode.length
  if (postalCodelen > 0){
    if (postalCodelen < 5){
  	  alert("Please make sure the Postal Code you have entered is valid.")
  	  thisField.focus()
  	  return false;
	  }else {
      if (postalCodelen == 6) {postalCode = postalCode.substring(0,3) + ' ' + postalCode.substring(3,6)}
      postalCode = postalCode.toUpperCase()
	  }
	  thisField.value = postalCode
	  return postalCode;
	}
else
	{
		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; 
}


 function checkDate(thisField)  {
 	dateVal = thisField.value

  // Checks for the following valid date formats:
  // MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
  // Also separates date into month, day, and year variables

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

  // To require a 4 digit year entry, use this line instead:
  // var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;


  var matchDate = dateVal.match(datePat); // is the format ok?
  if (matchDate == null) {
    alert("The field " + thisField.name.toUpperCase() + " is not in a valid format. Use MM/DD/YYYY")
    thisField.focus();
    return false;
  }


  month = matchDate[1]; // parse date into variables
  day = matchDate[3];
  year = matchDate[4];

  var message = "";

  if (month == 2) { // check for february 29th
   var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
   if (day>29 || (day==29 && !isleap))  message = "February " + year + " doesn't have " + day + " days!  Please make sure that the " + thisField.name.toUpperCase() + " is correct."
  }
  if ((month==4 || month==6 || month==9 || month==11) && day==31)  message = "Month "+month+" doesn't have 31 days!  Please Please make sure that the " + thisField.name.toUpperCase() + " is correct."
  if (day < 1 || day > 31) message = "Day must be between 1 and 31.  Please make sure that the " + thisField.name.toUpperCase() + " is correct."
  if (month < 1 || month > 12)  message = "Month must be between 1 and 12. Please make sure that the " + thisField.name.toUpperCase() + " is correct."  // check month range
  if (message !=0) {
    alert(message)
  	thisField.focus()
  	return false
  }

  return true;
 }

//textCounter - displays characters left while user is typing in a text/texarea field.
//SAMPLE - code from page:
//response.write("<textarea name=orgdesc rows=3 cols=45 wrap=virtual " & _
//               "onKeyDown=textCounter(this.form.orgdesc,this.form.remLen_1,255); " & _
//               "onKeyUp=textCounter(this.form.orgdesc,this.form.remLen_1,255);></textarea><br>")

//  response.write("Characters left:<input readonly type=text name=remLen_1 size=5 maxlength=4 value= class=tinytext>")
//  response.write("<script language=JavaScript>")
//  response.write("document.regform.remLen_1.value = (255 - document.regform.orgdesc.value.length);")
//  response.write("</script>")

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}


function returnDate(dateFormat)
{
	
//Style = 5; //pick a style from below
style = dateFormat;

/*------------------------------
Style 1: March 17, 2000
Style 2: Mar 17, 2000
Style 3: Saturday March 17, 2000
Style 4: Sat Mar 17, 2000
Style 5: Sat March 17, 2000
Style 6: 17 March 2000
Style 7: 17 Mar 2000
Style 8: 17 Mar 00
Style 9: 3/17/00
Style 10: 3-17-00
Style 11: Saturday March 17
--------------------------------*/

months = new Array();
months[1] = "January";  months[7] = "July";
months[2] = "February"; months[8] = "August";
months[3] = "March";    months[9] = "September";
months[4] = "April";    months[10] = "October";
months[5] = "May";      months[11] = "November";
months[6] = "June";     months[12] = "December";

months2 = new Array();
months2[1] = "Jan"; months2[7] = "Jul";
months2[2] = "Feb"; months2[8] = "Aug";
months2[3] = "Mar"; months2[9] = "Sep";
months2[4] = "Apr"; months2[10] = "Oct";
months2[5] = "May"; months2[11] = "Nov";
months2[6] = "Jun"; months2[12] = "Dec";

days = new Array();
days[1] = "Sunday";    days[5] = "Thursday";
days[2] = "Monday";    days[6] = "Friday";
days[3] = "Tuesday";   days[7] = "Saturday";
days[4] = "Wednesday";

days2 = new Array();
days2[1] = "Sun"; days2[5] = "Thu";
days2[2] = "Mon"; days2[6] = "Fri";
days2[3] = "Tue"; days2[7] = "Sat";
days2[4] = "Wed";

todaysdate = new Date();
date  = todaysdate.getDate();
day  = todaysdate.getDay() + 1;
month = todaysdate.getMonth() + 1;
yy = todaysdate.getYear();
year = (yy < 1000) ? yy + 1900 : yy;
year2 = 2000 - year; year2 = (year2 < 10) ? "0" + year2 : year2;

dateline = new Array();
dateline[1] = months[month] + " " + date + ", " + year;
dateline[2] = months2[month] + " " + date + ", " + year;
dateline[3] = days[day] + " " + months[month] + " " + date + ", " + year;
dateline[4] = days2[day] + " " + months2[month] + " " + date + ", " + year;
dateline[5] = days2[day] + " " + months[month] + " " + date + ", " + year;
dateline[6] = date + " " + months[month] + " " + year;
dateline[7] = date + " " + months2[month] + " " + year;
dateline[8] = date + " " + months2[month] + " " + year2;
dateline[9] = month + "/" + date + "/" + year2;
dateline[10] = month + "-" + date + "-" + year2;
dateline[11] = days[day] + " " + months[month] + " " + date;

return dateline[Style];
}


function isInteger (s)
// isInteger (STRING s [, BOOLEAN emptyOK])
//
// Returns true if all characters in string s are numbers.
//
// Accepts non-signed integers only. Does not accept floating
// point, exponential notation, etc.
//
// We don't use parseInt because that would accept a string
// with trailing non-numeric characters.
//
// By default, returns defaultEmptyOK if s is empty.
// There is an optional second argument called emptyOK.
// emptyOK is used to override for a single function call
//      the default behavior which is specified globally by
//      defaultEmptyOK.
// If emptyOK is false (or any value other than true),
//      the function will return false if s is empty.
// If emptyOK is true, the function will return true if s is empty.
//
// EXAMPLE FUNCTION CALL:     RESULT:
// isInteger ("5")            true
// isInteger ("")             defaultEmptyOK
// isInteger ("-5")           false
// isInteger ("", true)       true
// isInteger ("", false)      false
// isInteger ("5", false)     true

{
   var defaultEmptyOK = false
   var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


<!-- Dynamic Version by: Nannette Thacker -->
<!-- http://www.shiningstar.net -->
<!-- Original by :  Ronnie T. Moore -->
<!-- Web Site:  The JavaScript Source -->
<!-- Use one function for multiple text areas on a page -->
<!-- Limit the number of characters per textarea -->
<!-- Begin
function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
