<!--
//=========================================================================
// Zip Code Validator
//=========================================================================
function validateZIP(field) {
var valid = "0123456789-";
var hyphencount = 0;

if (field.length!=5 && field.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code.");
return false;
}
for (var i=0; i < field.length; i++) {
temp = "" + field.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
return false;
}
if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
return false;
   }
}
return true;
}

//=========================================================================
// general purpose function to check date format.
//=========================================================================
function checkdate(invalue) {
	var err=0
	var b = 0
	var c = 0
	var d = 0
	var e = 0
	var f = 0
	var psj=0;
	
	a=invalue

	if (!isNaN(a)) err=1
	else
	{
	x = a.substring(1, 2)
	y = a.substring(2, 3)
	}
	
    if (a.length == 10)
	{
	
		b = a.substring(0, 2)// month
		c = a.substring(2, 3)// '/'
		e = a.substring(5, 6)// '/'
		d = a.substring(3, 5)// day
		f = a.substring(8, 10)// year
	}
	else if ((a.length == 9)&&(x == "/"))
	{
	
		b = a.substring(0, 1)// month
		c = a.substring(1, 2)// '/'
		d = a.substring(2, 4)// day
		e = a.substring(4, 5)// '/'
		f = a.substring(5, 9)// year
	}
	else if ((a.length == 9)&&(y == "/"))
	{
	
		b = a.substring(0, 2)// month
		c = a.substring(2, 3)// '/'
		d = a.substring(3, 4)// day
		e = a.substring(4, 5)// '/'
		f = a.substring(5, 9)// year
	}
	else if ((a.length == 8)&&(x == "/"))
	{
	
		b = a.substring(0, 1)// month
		c = a.substring(1, 2)// '/'
		d = a.substring(2, 3)// day
		e = a.substring(3, 4)// '/'
		f = a.substring(4, 8)// year
	}
	else if ((a.length == 8)&&(y == "/"))
	{
		b = a.substring(0, 2)// month
		c = a.substring(2, 3)// '/'
		d = a.substring(3, 5)// day
		e = a.substring(5, 6)// '/'
		f = a.substring(6, 8)// year
	}
	else if ((a.length == 7)&&(x == "/"))
		
	{
		
		b = a.substring(0, 1)// month
		c = a.substring(1, 2)// '/'
		d = a.substring(2, 4)// day
		e = a.substring(4, 5)// '/'
		f = a.substring(5, 7)// year
	}	
		
	else if ((a.length == 7)&&(y == "/"))
	
	{
		b = a.substring(0, 2)// month
		c = a.substring(2, 3)// '/'
		d = a.substring(3, 4)// day
		e = a.substring(4, 5)// '/'
		f = a.substring(5, 7)// year
	}
	
	else if (a.length == 6)
	
	{
		
		b = a.substring(0, 1)// month
		c = a.substring(1, 2)// '/'
		d = a.substring(2, 3)// day
		e = a.substring(3, 4)// '/'
		f = a.substring(4, 6)// year
	}

	//basic error checking
	if (b<1 || b>12) err = 1
	if (c != '/') err = 1
	if (d<1 || d>31) err = 1
	if (e != '/') err = 1
	if (parseInt(f.length) == 2) {
	  if (f<0 || f>99) {
	    err = 1;
	  }
	} else {
	  if (f<1900 || f>2027) {
	    err = 1;
	  }
	}
	
	//advanced error checking

	// months with 30 days
	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1
	}

	// february, leap year
	if (b==2){
		// feb
		var g=parseInt(f/4)
		if (isNaN(g)) {
			err=1
		}

		if (d>29) err=1
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1
	}

	if (err==1){
	    return false;
	} else {
	    return true;
	}
}

//=========================================================================
// general purpose function to see if a value is numeric
//=========================================================================
function isNumber(inputVal) {
  oneDecimal = false
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	if (i == 0 && oneChar == "-") {
	  continue
	}
	if (oneChar == "." && !oneDecimal) {
	  oneDecimal = true
	  continue
	}
	if (oneChar < "0" || oneChar > "9") {
	  return false
	}
  }
  return true
}

//=========================================================================
// general purpose function to see if a numeric input is a positive number
//=========================================================================
function isPosNumber(inputVal) {
  oneDecimal = false
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
	if (oneChar == "-") {
	  return false
	}
	if (oneChar == "." && !oneDecimal) {
	  oneDecimal = true
	  continue
	}
	if (oneChar < "0" || oneChar > "9") {
	  return false
	}
  }
  return true
}

//=========================================================================
// general purpose function to see if a numeric input is a positive integer
//=========================================================================
function isPosInteger(inputVal) {
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
    if (oneChar < "0" || oneChar > "9") {
      return false
    }
  }
  return true
}

//=========================================================================
// general purpose function to see if a field is empty
//=========================================================================
function isFieldEmpty(inputVal) {
  if (inputVal == null || inputVal == "") {
    return true
  }
  return false
}

//=========================================================================
// general purpose function to check for a valid email address
//=========================================================================
function emailCheck(emailStr) {
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    alert("The username doesn't seem to be valid.")
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
	        alert("Destination IP address is invalid!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="This address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

//-->
