function libtest(){
	alert("lib function test");
}

// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. Instead,
// please just point to my URL to ensure the most up-to-date versions
// of the files. Thanks.
// ===================================================================
// 
// function LTrim(str)
// function RTrim(str)
// function Trim(str)
// function removeSpaces(string)
// function isNull(val)
// function isBlank(val)
// function isInteger(val)
// function isPosFloatVal(val)
// function isDigit(num)
// function isMonth(val)
// function isStateAbbr(val)
// function isUSStateAbbr(val)
// function isCanadianStateAbbr(val)
// function setNullIfBlank(obj)
// function setFieldsToUpperCase()
// function disallowBlank(obj)
// function disallowModify(obj)
// function isChanged(obj)
// function getInputValue(obj)
// function getInputDefaultValue(obj)
// function setInputValue(obj,val)
// function isFormModified(theform, hidden_fields, ignore_fields)
// function isValidLength(string, min, max)
// function isValidCreditCard(number)
// function isValidEmail(address)
// function isValidZipcode(zipcode)
// function isValidPostalcode(postalcode)
// function isAlphanumeric(string, ignoreWhiteSpace)
// function isAlphabetic(string, ignoreWhiteSpace)
// function isAlphaPlus(string, ignoreWhiteSpace)
// function isNumeric(string, ignoreWhiteSpace)
// function removeBadCharacters(string)
// function trimWhitespace(string)
// function getMod10(number)
//  
// function validateForm(theForm)
// 
//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str) {
  for (var i=0; str.charAt(i)==" "; i++);
  return str.substring(i,str.length);
}

function RTrim(str) {
  for (var i=str.length-1; str.charAt(i)==" "; i--);
  return str.substring(0,i+1);
}

function Trim(str) {
  return LTrim(RTrim(str));
}

// Remove all spaces from a string
function removeSpaces(string) {
  var newString = '';
  for (var i = 0; i < string.length; i++) 
    if (string.charAt(i) != ' ') newString += string.charAt(i);
  return newString;
}

// Remove likely characters used in phone numbers from a string
function removePhoneCharacters(phstring) {
  var newString = '';
  for (var i = 0; i < phstring.length; i++) 
    if (phstring.charAt(i) != '-') newString += phstring.charAt(i);
  // alert ("modifed phone string " + newString);
  return newString;
}

//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val) {
  if (val == null) return true;
  return false;
}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val) {
  if (val == null) return true;
  for (var i=0; i < val.length; i++) 
    if ((val.charAt(i) != ' ') && (val.charAt(i) != "\t") && (val.charAt(i) != "\n")) return false;
  return true;
}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val) {
//	alert ("ii1");
  for (var i=0; i < val.length; i++) 
    if (!isDigit(val.charAt(i))) {
			return false;
		}
  return true;
}

//-------------------------------------------------------------------
// isPosFloatVal(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isPosFloatVal(val) {
  var dp = false;
  for (var i=0; i < val.length; i++) { //  EXAMINE EACH CHAR IN STRING 'VAL'
    if (!isDigit(val.charAt(i))) { //  IF LEGAL CHAR
      if (val.charAt(i) == '.') {
        if (dp == true) { return false; } // already saw a decimal point
        else { dp = true; }
      }	else return false; 
  	} //  IF LEGAL CHAR
	}  //  FOR EACH CHAR
  return true;
}
  
//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
  var string="1234567890";
  if (string.indexOf(num) != -1) return true;
  return false;
}

//-------------------------------------------------------------------
// isMonth(string)
//   Returns true if string is either a full month name or a month
//   abbreviation.
//-------------------------------------------------------------------
function isMonth(val) {
  val = val+"";
  val = val.toLowerCase();
  if ((val=="jan") || (val=="feb") || (val=="mar") || (val=="apr") || (val=="may") || (val=="jun") ||
      (val=="jul") || (val=="aug") || (val=="sep") || (val=="oct") || (val=="nov") || (val=="dec")) {
      return true;
  }
  if ((val=="january") || (val=="february") || (val=="march") || (val=="april") || (val=="may") ||
      (val=="june") || (val=="july") || (val=="august") || (val=="september") || (val=="october") ||
      (val=="november") || (val=="december")) {
        return true;
  }
  return false;
}

//-------------------------------------------------------------------
// isStateAbbr(string)
//   Returns true if string is a US state abbreviation or one of 
//   the canadian provinces
//-------------------------------------------------------------------
function isStateAbbr(val) {
  if (val.length != 2) { return false; }
  val = val+"";
  if (val.charAt(0) == ' ' || val.charAt(1) == ' ') { return false; }
  if (isUSStateAbbr(val)) { return true; }
  if (isCanadianStateAbbr(val)) { return true; }
  return false;
}
  
//-------------------------------------------------------------------
// isUSStateAbbr(string)
//   Returns true if string is a US State Abbreviation
//-------------------------------------------------------------------
function isUSStateAbbr(val) {
  val = val+"";
        if (val.length != 2) { return false; }
        if (val.charAt(0) == ' ' || val.charAt(1) == ' ') { return false; }
  var string="AK AL AR AZ CA CO CT DC DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO MS MT NC ND NE NH NJ NM NV NY OH OK OR PA PR RI SC SD TN TX UT VA VI VT WA WI WV WY";
  if (string.indexOf(val.toUpperCase()) != -1) {
    return true;
  }
  return false;
}

//-------------------------------------------------------------------
// isCanadianStateAbbr(string)
//   Returns true if string is a Canadian State (Province) Abbreviation
//-------------------------------------------------------------------
function isCanadianStateAbbr(val) {
  val = val+"";
        if (val.length != 2) { return false; }
        if (val.charAt(0) == ' ' || val.charAt(1) == ' ') { return false; }
  var string="AB BC EI MB NB NF NS NT NU ON PQ SK YK";
  if (string.indexOf(val.toUpperCase()) != -1) {
    return true;
  }
  return false;
}

//-------------------------------------------------------------------
// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
//-------------------------------------------------------------------
function setNullIfBlank(obj) {
  if (isBlank(obj.value)) {
    obj.value = "";
}	}

//-------------------------------------------------------------------
// setFieldsToUpperCase(input_object)
//   Sets value of form field toUpperCase() for all fields passed
//-------------------------------------------------------------------
function setFieldsToUpperCase() {
  for (var i=0; i<arguments.length; i++) {
    var obj = arguments[i];
    obj.value = obj.value.toUpperCase();
}	}

//-------------------------------------------------------------------
// disallowBlank(input_object[,message[,true]])
//   Checks a form field for a blank value. Optionally alerts if 
//   blank and focuses
//-------------------------------------------------------------------
function disallowBlank(obj) {
  var msg;
  var dofocus;
  if (arguments.length>1) { msg = arguments[1]; }
  if (arguments.length>2) { dofocus = arguments[2]; } else { dofocus=false; }
  if (isBlank(obj.value)) {
    if (!isBlank(msg)) alert(msg);
    if (dofocus) {
      obj.select();
      obj.focus();
    }
    return true;
  }
  return false;
}

//-------------------------------------------------------------------
// disallowModify(input_object[,message[,true]])
//   Checks a form field for a value different than defaultValue. 
//   Optionally alerts and focuses
//-------------------------------------------------------------------
function disallowModify(obj) {
  var msg;
  var dofocus;
  if (arguments.length>1) { msg = arguments[1]; }
  if (arguments.length>2) { dofocus = arguments[2]; } else { dofocus=false; }
  if (getInputValue(obj) != getInputDefaultValue(obj)) {
    if (!isBlank(msg)) alert(msg);
    if (dofocus) {
      obj.select();
      obj.focus();
    }
    setInputValue(obj,getInputDefaultValue(obj));
    return true;
  }
  return false;
}

//-------------------------------------------------------------------
// isChanged(input_object)
//   Returns true if input object's state has changed since it was
//   created.
//-------------------------------------------------------------------
function isChanged(obj) {
	var i;
  if ((typeof obj.type != "string") && (obj.length > 0) && (obj[0] != null) && (obj[0].type=="radio")) {
    for (i=0; i<obj.length; i++) {
      if (obj[i].checked != obj[i].defaultChecked) { return true; }
    }
    return false;
  }
  if ((obj.type=="text") || (obj.type=="hidden") || (obj.type=="textarea"))
    return (obj.value != obj.defaultValue);
  if (obj.type=="checkbox")
    return (obj.checked != obj.defaultChecked);
  if (obj.type=="select-one") { 
    if (obj.options.length > 0) {
      var x=0;
      for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].defaultSelected) { x++; }
      }
      if (x==0 && obj.selectedIndex==0) return false;
      for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].selected != obj.options[i].defaultSelected) {
          return true;
    }	}	}
    return false;
  }
  if (obj.type=="select-multiple") {
    if (obj.options.length > 0) {
      for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].selected != obj.options[i].defaultSelected) {
          return true;
    }	}	}
    return false;
  }
  // return false for all other input types (button, image, etc)
  return false;
}

//-------------------------------------------------------------------
// getInputValue(input_object)
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj) {
	var i;
  if ((typeof obj.type != "string") && (obj.length > 0) && (obj[0] != null) && (obj[0].type=="radio")) {
    for (i=0; i<obj.length; i++) {
      if (obj[i].checked == true) { return obj[i].value; }
    }
    return "";
  }
  if (obj.type=="text") return obj.value;
  if (obj.type=="hidden") return obj.value;
  if (obj.type=="textarea") return obj.value;
  if (obj.type=="checkbox") {
    if (obj.checked == true) {
      return obj.value;
    }
    return "";
  }
  if (obj.type=="select-one") { 
    if (obj.options.length > 0) {
      return obj.options[obj.selectedIndex].value; 
    }
    else {
      return "";
  }	}
  if (obj.type=="select-multiple") { 
    var val = "";
    for (i=0; i<obj.options.length; i++) {
      if (obj.options[i].selected) {
        val = val + "" + obj.options[i].value + ",";
    }	}
    if (val.length > 0) {
      val = val.substring(0,val.length-1); // remove trailing comma
      }
    return val;
    }
  return "";
}

//-------------------------------------------------------------------
// getInputDefaultValue(input_object)
//   Get the default value of any form input field when it was created
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputDefaultValue(obj) {
	var i;
  if ((typeof obj.type != "string") && (obj.length > 0) && (obj[0] != null) && (obj[0].type=="radio")) {
    for (var i=0; i<obj.length; i++) {
      if (obj[i].defaultChecked == true) { return obj[i].value; }
    }
    return "";
  }
  if (obj.type=="text") return obj.defaultValue;
  if (obj.type=="hidden") return obj.defaultValue;
  if (obj.type=="textarea") return obj.defaultValue;
  if (obj.type=="checkbox") {
    if (obj.defaultChecked == true) {
      return obj.value;
    }
    return "";
  }
  if (obj.type=="select-one") {
    if (obj.options.length > 0) {
      for (i=0; i<obj.options.length; i++) {
        if (obj.options[i].defaultSelected) {
          return obj.options[i].value;
    }	}	}
    return "";
  }
  if (obj.type=="select-multiple") { 
    var val = "";
    for (i=0; i<obj.options.length; i++) {
      if (obj.options[i].defaultSelected) {
        val = val + "" + obj.options[i].value + ",";
    }	}
    if (val.length > 0) {
      val = val.substring(0,val.length-1); // remove trailing comma
    }
    return val;
  }
  return "";
}
  
//-------------------------------------------------------------------
// setInputValue()
//   Set the value of any form field. In cases where no matching value
//   is available (select, radio, etc) then no option will be selected
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function setInputValue(obj,val) {
	var i;
  if ((typeof obj.type != "string") && (obj.length > 0) && (obj[0] != null) && (obj[0].type=="radio")) {
    for (i=0; i<obj.length; i++) {
      if (obj[i].value == val) { 
        obj[i].checked = true;
      }
      else {
        obj[i].checked = false;
  }	}	}
  if (obj.type=="text") obj.value = val;
  if (obj.type=="hidden") obj.value = val;
  if (obj.type=="textarea") obj.value = val;
  if (obj.type=="checkbox") {
    if (obj.value == val) obj.checked = true;
    else obj.checked = false;
  }
  if ((obj.type=="select-one") || (obj.type=="select-multiple")) {
    for (i=0; i<obj.options.length; i++) {
      if (obj.options[i].value == val) {
        obj.options[i].selected = true;
      }
      else {
        obj.options[i].selected = false;
}	}	}	}
  
//-------------------------------------------------------------------
// isFormModified(form_object,hidden_fields,ignore_fields)
//   Check to see if anything in a form has been changed. By default
//   it will check all visible form elements and ignore all hidden 
//   fields. 
//   You can pass a comma-separated list of field names to check in
//   addition to visible fields (for hiddens, etc).
//   You can also pass a comma-separated list of field names to be
//   ignored in the check.
//-------------------------------------------------------------------
function isFormModified(theform, hidden_fields, ignore_fields) {
  if (hidden_fields == null) { hidden_fields = ""; }
  if (ignore_fields == null) { ignore_fields = ""; }
  
  var hiddenFields = new Object();
  var ignoreFields = new Object();
  var i,field;
  var hidden_fields_array = hidden_fields.split(',');

  for (i=0; i<hidden_fields_array.length; i++) {
    hiddenFields[Trim(hidden_fields_array[i])] = true;
    }
  var ignore_fields_array = ignore_fields.split(',');
  for (i=0; i<ignore_fields_array.length; i++) {
    ignoreFields[Trim(ignore_fields_array[i])] = true;
    }
  for (i=0; i<theform.elements.length; i++) {
    var changed = false;
    var name = theform.elements[i].name;
    if (!isBlank(name)) {
      var type = theform[name].type;
      if (!ignoreFields[name]) {
        if (type=="hidden" && hiddenFields[name]) {
          changed = isChanged(theform[name]);
        }
        else if (type=="hidden") {
          changed = false;
        }
        else {
          changed = isChanged(theform[name]);
    }}}
    if (changed) { 
      return true;
  }}
  return false;
}

// Form Validation Functions  v1.0
// http://www.dithered.com/javascript/form_validation/index.html
// code by Chris Nott (chris@dithered.com)

// Check that the number of characters in a string is between a max and a min
function isValidLength(string, min, max) {
  if (string.length < min || string.length > max) return false;
  else return true;
}

// Check that a credit card number is valid based using the LUHN formula (mod10 is 0)
function isValidCreditCard(number) {
  number = '' + number;
  if (number.length > 16 || number.length < 13 ) return false;
  else if (getMod10(number) != 0) return false;
  else if (arguments[1]) {
    var type = arguments[1];
    var first2digits = number.substring(0, 2);
    var first4digits = number.substring(0, 4);
    if (type.toLowerCase() == 'visa' && number.substring(0, 1) == 4 &&
      (number.length == 16 || number.length == 13 )) return true;
    else if (type.toLowerCase() == 'mastercard' && number.length == 16 &&
      (first2digits == '51' || first2digits == '52' || first2digits == '53' || first2digits == '54' || first2digits == '55')) return true;
    else if (type.toLowerCase() == 'american express' && number.length == 15 && 
      (first2digits == '34' || first2digits == '37')) return true;
    else if (type.toLowerCase() == 'diners club' && number.length == 14 && 
      (first2digits == '30' || first2digits == '36' || first2digits == '38')) return true;
    else if (type.toLowerCase() == 'discover' && number.length == 16 && first4digits == '6011') return true;
    else if (type.toLowerCase() == 'enroute' && number.length == 15 && 
      (first4digits == '2014' || first4digits == '2149')) return true;
    else if (type.toLowerCase() == 'jcb' && number.length == 16 &&
      (first4digits == '3088' || first4digits == '3096' || first4digits == '3112' || first4digits == '3158' || first4digits == '3337' || first4digits == '3528')) return true;
    else return true;
  }
  else return true;
}

// Check that an email address is valid based on RFC 821 (?)
function isValidEmail(address) {
  if (address.indexOf('@') < 3) return false;
  var name = address.substring(0, address.indexOf('@'));
  var domain = address.substring(address.indexOf('@') + 1);
  if (name.indexOf('(') != -1 || name.indexOf(')') != -1 || name.indexOf('<') != -1 || name.indexOf('>') != -1 || name.indexOf(',') != -1 || name.indexOf(';') != -1 || name.indexOf(':') != -1 || name.indexOf('\\') != -1 || name.indexOf('"') != -1 || name.indexOf('[') != -1 || name.indexOf(']') != -1 || name.indexOf(' ') != -1) return false;
  if (domain.indexOf('(') != -1 || domain.indexOf(')') != -1 || domain.indexOf('<') != -1 || domain.indexOf('>') != -1 || domain.indexOf(',') != -1 || domain.indexOf(';') != -1 || domain.indexOf(':') != -1 || domain.indexOf('\\') != -1 || domain.indexOf('"') != -1 || domain.indexOf('[') != -1 || domain.indexOf(']') != -1 || domain.indexOf(' ') != -1) return false;
  return true;
}


// Check that a US zip code is valid
function isValidZipcode(zipcode) {
  zipcode = removeSpaces(zipcode);
  if (!(zipcode.length == 5) || !isNumeric(zipcode)) return false;
  return true;
}


// Check that a Canadian postal code is valid
function isValidPostalcode(postalcode) {
  if (postalcode.search) {
    postalcode = removeSpaces(postalcode);
    if (postalcode.length == 6 && postalcode.search(/^\w\d\w\d\w\d$/) != -1) return true;
    else if (postalcode.length == 7 && postalcode.search(/^\w\d\w\-d\w\d$/) != -1) return true;
    else return false;
  }
  return true;
}

// Check that a valid US phone number was entered
function isValidPhone(areacode, phonenum) {
  phonenumTest = areacode + phonenum;
  phonenumTest = removeSpaces(phonenumTest);
  phonenumTest = removePhoneCharacters(phonenumTest);  
  if (!(phonenumTest.length == 10) || !isNumeric(phonenumTest)) return false;
  return true;
}

// Check that a string contains only letters and numbers
function isAlphanumeric(string, ignoreWhiteSpace) {
  if (string.search) {
    if ((ignoreWhiteSpace && string.search(/[^\w\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\W/) != -1)) return false;
  }
  return true;
}

// Check that a string contains only letters
function isAlphabetic(string, ignoreWhiteSpace) {
  if (string.search) {
    if ((ignoreWhiteSpace && string.search(/[^a-zA-Z\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z]/) != -1)) return false;
  }
  return true;
}

// Check that a string contains only letters, '.', ',' or '-'
function isAlphaPlus(string, ignoreWhiteSpace) {
  if (string.search) {
    if ((ignoreWhiteSpace && string.search(/[^a-zA-Z,\.\-\s]/) != -1) || (!ignoreWhiteSpace && string.search(/[^a-zA-Z,\.\-]/) != -1)) return false;
  }
  return true;
}

// Check that a string contains only numbers
function isNumeric(string, ignoreWhiteSpace) {
  if (string.search) {
    if ((ignoreWhiteSpace && string.search(/[^\d\s]/) != -1) || (!ignoreWhiteSpace && string.search(/\D/) != -1)) return false;
  }
  return true;
}

// Remove characters that might cause security problems from a string
// DOES NOT SEEM TO WORK AT ALL! 
function removeBadCharacters(string) {
// DOES NOT SEEM TO WORK AT ALL! 
  if (string.replace) {
    alert("String from badchars function " + string);
    string.replace(/[<>\"\'%;\)\(&\+]/g, '');
  }
  // alert("Debug: Modified String from badchars function " + string);
  return string;
}

// Remove leading and trailing whitespace from a string
function trimWhitespace(string) {
  var newString  = '';
  var substring  = '';
  beginningFound = false;
  // copy characters over to a new string
  // retain whitespace characters if they are between other characters
  for (var i = 0; i < string.length; i++) {
    // copy non-whitespace characters
    if (string.charAt(i) != ' ' && string.charCodeAt(i) != 9) {
      // if the temporary string contains some whitespace characters, copy them first
      if (substring != '') {
        newString += substring;
        substring = '';
      }
      newString += string.charAt(i);
      if (beginningFound == false) beginningFound = true;
    }
    // hold whitespace characters in a temporary string if they follow a non-whitespace character
    else if (beginningFound == true) substring += string.charAt(i);
  }
  return newString;
}

// Returns a checksum digit for a number using mod 10
function getMod10(number) {
  // convert number to a string and check that it contains only digits
  // return -1 for illegal input
  number = '' + number;
  number = removeSpaces(number);
  if (!isNumeric(number)) return -1;
  // calculate checksum using mod10
  var checksum = 0;
  for (var i = number.length - 1; i >= 0; i--) {
    var isOdd = ((number.length - i) % 2 != 0) ? true : false;
    digit = number.charAt(i);
    if (isOdd) checksum += parseInt(digit);
    else {
      var evenDigit = parseInt(digit) * 2;
      if (evenDigit >= 10) checksum += 1 + (evenDigit - 10);
      else checksum += evenDigit;
  }}
  return (checksum % 10);
}

//var PatDict = new Object();

//PatDict.zipPat      = /\d{5}(-\d{4})?/;             // matches zip codes
//PatDict.currencyPat = /\$\d{1,3}(,\d{3})*\.\d{2}/;  // matches $17.23 or $14,281,545.45 or ...
//PatDict.timePat     = /\d{2}:\d{2}/;                // matches 12:34 but also 75:83
//PatDict.timePat2    =/^([1-9]|1[0-2]):[0-5]\d$/;    // matches 5:04 or 12:34 but not 75:83

// V A L I D A T E F O R M
//
// Any Form Input field can have a 'validate' value.
//
// It 3 parts seperated by slashes '/'.
//
//    Part 1: required or not - 'req' = required 'not' or missing = NOT required
//
//    Part 2: field type validation:  'num' = numeric               'alpha' = alphabetic
//                                    'alphanum' = mixed alpnanumeric or numeric 
//                                    'CC' = Credit Card Number     'email' = legal email address  
//                                    'zip' = US Zip Code           'CPost' = Canadian Postal Code'
//                                    'zipost' = zip or postal
//
//    Part 3: string to be displayed in an alert box of validation fails
//
//
function validateForm(theForm){       // return true if all is well
  var elArr = theForm.elements;       // get all elements of the form into array
  for(var i = 0; i < elArr.length; i++) with(elArr[i]){ // for each element of the form...
    var v = elArr[i].validator;     // get validator, if any
    if(!v) continue;
    vFields = v.split('/');         // parse validator fields
    fReq = vFields[0]; fVal = vFields[1]; fErMsg = vFields[2];
    if((fReq == 'req') && (value == '0')) {
      alert("Please complete all required fields.");
      elArr[i].focus();
      return false;
    }                       
    if(!fVal) continue;             // no validator property, skip
    if(fVal == 'num') {
      if(!isInteger(value)) {
        if(!fErMsg) alert('Field can only contain numbers.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'alpha') {
      if(!isAlphabetic(value)) {
        if(!fErMsg) alert('Field can only contain letters.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'alphanum') {
      if(!isAlphanumeric(value)) {
        if(!fErMsg) alert('Field can only contain letters and numbers.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'CC') {
      if(!isValidCreditCard(value)) {
        if(!fErMsg) alert('Not Valid Credit Card Number.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'email') {
      if(!isValidEmail(value)) {
        if(!fErMsg) alert('Not Valid Email Address.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'zip') {
      if(!isValidZipcode(value)) {
        if(!fErMsg) alert('Not Valid Zip Code.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'CPost') {
      if(!isValidPostalcode(value)) {
        if(!fErMsg) alert('Not Valid Canadian Postal Code.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
    else if(fVal == 'zipost') {
      if(!isValidZipcode(value) && !isValidPostalcode(value)) {
        if(!fErMsg) alert('Not Valid Zip/Postal Code.');
        else alert(fErMsg);
        elArr[i].focus();
        return false;
      }  
    }   
  } // for  
  return true;
}
//=============================================================================
//=============================================================================
//=============================================================================

var days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

function date_comp_today(cdate, relation) {
//	DATE COMPARISON TO TODAY
//	PARAMETERS:
//		CDATE = (STRING) COMPARISON DATE (YYYY-MM-DD)
//		RELATION = (STRING)  ['LT' <= COMPARISON DATE IS LESS THAN TODAY (IN PAST)
//													'GT' <= COMPARISON DATE IS GREATER THAN TODAY (IN FUTURE)
//													'EQ' <= COMPARISON DATE IS EQUAL TO TODAY (CURRENT)
//													'LE' <= LESS THAN OR EQUAL
//													'GE' <= GREATER THA OR EQUAL
//													'NE' <= NOT EQUAL ]
//	RETURNS:
//		TRUE  <= SPECIFIED RELATIONSHIP BETWEEN COMPARISON DATE AND CURRENT DATE IS TRUE
//		FALSE <= RELATIONSHIP IS NOT TRUE
//
	var comparison_flag = 1								// 0 <= COMPARISON DATE IS LESS THAN TODAY
																				// 1 <= COMPARISON DATE IS EQUAL TO TODAY
																				// 2 <= COMPARISON DATE IS GREATER THAN TODAY
	var today = new Date();								// TODAY
 	var tyear  = today.getFullYear(); 		// TODAY - YEAR
	var tmonth = today.getMonth() + 1;		// TODAY - MONTH
 	var tday   = today.getDate();					// TODAY - DAY
	
	var cyear	 = cdate.slice(0, 4);				// COMPARISON - YEAR
 	var cmonth = cdate.slice(5, 7);				// COMPARISON - MONTH
	var cday   = cdate.slice(8);					// COMPARISON - DAY	
//	alert("cdate = |"+cdate+"|\n" +
//				"today ("+tyear+"|"+tmonth+"|"+tday+")\n"	+
//				"comparison ("+cyear+"|"+cmonth+"|"+cday+")\n");
	
	// SET COMPARISON_FLAG			
	if (cyear < tyear) {
		comparison_flag = 0;
	} else if (cyear > tyear) {
		comparison_flag = 2;
	} else {
		if (cmonth < tmonth) {
			comparison_flag = 0;
		} else if (cmonth > tmonth) {
			comparison_flag = 2;
		} else {
			if (cday < tday) {
				comparison_flag = 0;
			} else if (cday > tday) {
				comparison_flag = 2;
			} else {
				comparison_flag = 1;
	}	}	}
	// RETURN TRUE OR FALSE BASED UPON COMPARISON_FLAG AND RELATION PARAMETER
	switch (relation.toUpperCase()) {
		case 'LT': return ((comparison_flag == 0)? true: false);
		case 'GT': return ((comparison_flag == 2)? true: false);
		case 'EQ': return ((comparison_flag == 1)? true: false);
		case 'LE': return ((comparison_flag <= 1)? true: false);
		case 'GE': return ((comparison_flag >= 1)? true: false);
		case 'NE': return ((comparison_flag != 1)? true: false);
	} //CASE
	alert ("function date_comp_today: second parameter (relation) has illegal value.");
	return false;
}	

function standard_form_date(sf_year, sf_month, sf_day) {
	if (((sf_year.length < 1) || (sf_year == " ")) || 
			((sf_month.length < 1) || (sf_month == " ")) || 
			((sf_day.length < 1) || (sf_day == " "))) {
		return ("");
	} else {			
		return ((sf_year) + "-" + 
						(sf_month.length == 1? "0"+sf_month: sf_month) + "-" +
						(sf_day.length   == 1? "0"+sf_day:   sf_day));
	}
}

function valerr(control, errmsg) {
	var i = 0;
	alert(errmsg);
	// IS CONTROL AN ARRAY?  IF SO IT MUST BE EITHER A CHECKBOX OR A RADIOBUTTON
	if (control.type == null) {
		control[i].value = "";
		control[i].focus();
	}
	// IT ISN'T AN ARRAY BUT COULD STILL BE A CHECKBOX OF RADIOBUTTON
	else if ((control.type == "radio") || (control.type == "checkbox")) { 
		control.value = "";
		control.focus();
	}
	// MUST NOT BE EITHER A CHECKBOX NOR A RADIOBUTTON
	else {
		control.value = "";
		control.focus();
	}
	return false;
}

function notnull(field, errmsg) {
	if (isBlank(field.value)) {
		valerr(field, errmsg);
		return false;
	}
	return field.value;
}

function rb_numchecked(cb_object) {
	var total = 0;
	var max = cb_object.length;
	for (var idx = 0; idx < max; idx++) {
		if (eval("cb_object[" + idx + "].checked") == true) {
	    total += 1;
	}	}
	return total;
}

function rb_selection(rb_object) {
	var selection = null;
	for (var i = 0; i < rb_object.length; i++) {
		if (rb_object[i].checked) {
			selection = rb_object[i].value;
			return selection;
	}	}
	return selection;
} // end function returnSelection

function rb_checked(rb_name) {
	var rb_len = rb_name.length;
	for (i = 0; i < rb_len; i++) {
		if (rb_name[i].checked) {
			return true;
		}
	}
	return false;
}




