function ContainsCharacter(inputStr, beginChar, endChar)
{
var charFound
charFound = false
   for (var i = 0; i < inputStr.length; i++)
   {
      var oneChar = inputStr.substring(i, i+1)
      if (oneChar >= beginChar && oneChar <= endChar)
      {
         charFound = true
         break
      }
   }
   return charFound
}

function inValidCharSet(str,charset)
{
	var result = true;

	// Note: doesn't use regular expressions to avoid early Mac browser bugs	
	for (var i=0;i<str.length;i++)
	{
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	}
	return result;
}

function checkemail(email, fieldtitle, showalert)
{

   var valid, reason
   reason = "Invalid e-mail format."
   valid = emailFormatCheck(email.value)
   if ((!valid) && (showalert))
      alert("The \"" + fieldtitle + "\" specified is invalid.\n" + reason + "\nPlease update this value.")
   
   if (showalert)
      return valid
   else
      return reason
/*
   var position
   var currentint
   var currentposition
   var errnum
   var iLastInt
   valid = true
   currentchar= " "
   currentint = 0
   currentposition = 0
   currentint = email.value.charCodeAt(0)

   //Email address must be at least 6 characters x@x.xx
   if (email.value.length > 5)
   {
      //Make sure the first character is alpha
      if (((currentint > 64) && (currentint < 91)) || ((currentint > 96) && (currentint < 123)))
      {
         //Find the position of the @
         position = email.value.indexOf("@", 0)
         if (position < 0)
         {
            valid = false
            errnum = 6
         }
         else
         {
            currentposition++
            for (;currentposition < position ; currentposition++)
            {
               currentint = email.value.charCodeAt(currentposition)
               if (((currentint > 64) && (currentint < 91)) || ((currentint > 96) && (currentint < 123)) || ((currentint > 47) && (currentint < 58))  || (currentint = 45) || (currentint = 46) || (currentint = 95))
               {
                  //Check to make sure the character is an alpha-numberic, period, hyphen, or underscore
                  //do nothing
               }
               else
               {
                  valid = false
                  errnum = 3
                  break
               }
            }
            if (valid)
            {
               currentposition = ++position
               position = email.value.indexOf(".", currentposition)
               if (position > currentposition)
               {
                  for (;currentposition <= email.value.length - 3; currentposition++)
                  {
                     currentint = email.value.charCodeAt(currentposition)
                     if (((currentint > 64) && (currentint < 91)) || ((currentint > 96) && (currentint < 123)) || ((currentint > 47) && (currentint < 58))  || (currentint == 45) || (currentint == 46) || (currentint == 95))
                     {
                        //Check to make sure the character is an alpha-numberic, period, hyphen, or underscore
                        //do nothing

                     }
                     else
                     {
                        valid = false
                        errnum = 3
                        break
                     }
                  }
                  if (valid)
                  {
                     iLastInt = email.value.charCodeAt(email.value.length-2)
                     if (((iLastInt > 64) && (iLastInt < 91)) || ((iLastInt > 96) && (iLastInt < 123)))
                     {
                        //Make sure the next to last character is alpha
                        iLastInt = email.value.charCodeAt(email.value.length-1)
                        if (((iLastInt > 64) && (iLastInt < 91)) || ((iLastInt > 96) && (iLastInt < 123)))
                        {
                           //Make sure the next to last character is alpha
                           //do nothing
                        }
                        else
                        {
                           valid = false
                           errnum = 5
                        }
                     }
                     else
                     {
                        valid = false
                        errnum = 5
                     }
                  }
               }
               else
               {
                 valid = false
                 errnum = 4
               }
            }
         }
      }
      else
      {
         valid = false
         errnum = 2
      }
   }
   else
   {
      valid = false
      errnum = 1
   }
   
   if (errnum == 1)
   {
      reason = "E-Mail addresses must be a minimum of 6 characters in length (i.e. a@b.ca)."
   }
   else 
   {
      if (errnum == 2)
      {
         reason = "The first character of your e-mail address must be an alpha (ie. a-z or A-Z)."
      }
      else 
      {
         if (errnum == 3)
         {
            reason = "The characters before or after the \"@\" can only be alpha-numberic(ie. a-z, A-Z, 0-9), dot (i.e. \".\"), hyphen (i.e. \"-\"), or underscore (i.e. \"_\")."
         }
         else 
         {
            if (errnum == 4)
            {
               reason = "There must be at least one character between the \"@\" and the first dot (\".\") after the \"@\" (i.e. a@b.ca)."
            }
            else
            { 
               if (errnum == 5)
               {
                  reason = "The last two characters of your e-mail address must be alpha (ie. a-z or A-Z)."
               }
               else 
               {
                  if (errnum == 6)
                  {
                     reason = "E-Mail address must contain an \"@\"."
                  }
               }
            }
         }
      }
   }
   if ((!valid) && (showalert))
      alert("The \"" + fieldtitle + "\" specified is invalid.\n" + reason + "\nPlease update this value.")
   
   if (showalert)
      return valid
   else
      return reason
*/
}

function emailFormatCheck (emailStr) {

<!--This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- V1.1.3: Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Original:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->
<!-- Changes:
/* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
international characters) were allowed.

1.1.3: Added the restriction to only accept addresses ending in two
letters (interpreted to be a country code) or one of the known
TLDs (com, net, org, edu, int, mil, gov, arpa), including the
new ones (biz, aero, name, coop, info, pro, museum).  One can
easily update the list (if ICANN adds even more TLDs in the
future) by updating the knownDomsPat variable near the
top of the function.  Also, I added a variable at the top
of the function that determines whether or not TLDs should be
checked at all.  This is good if you are using this function
internally (i.e. intranet site) where hostnames don't have to 
conform to W3C standards and thus internal organization e-mail
addresses don't have to either.
Changed some of the logic so that the function will work properly
with Netscape 6.

1.1.2: Fixed a bug where trailing . in e-mail address was passing
(the bug is actually in the weak regexp engine of the browser; I
simplified the regexps to make it work).

1.1.1: Removed restriction that countries must be preceded by a domain,
so abc@host.uk is now legal.  However, there's still the 
restriction that an address must end in a two or three letter
word.

1.1: Rewrote most of the function to conform more closely to RFC 822.

1.0: Original  */
// -->

/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */

var checkTLD=0;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* 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];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
//alert("Ths username contains invalid characters.");
return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
//alert("Ths domain name contains invalid characters.");
return false;
   }
}

// 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.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
//alert("The domain name does not seem to be valid.");
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
//alert("The address must end in a well-known domain or two letter " + "country.");
return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
//alert("This address is missing a hostname!");
return false;
}

// If we've gotten this far, everything's valid!
return true;
}



function isDate(month, day, year)
{
   var yeardt
   yeardt = year

   if (!isNumeric(year))
   {return false}
   if (!isNumeric(day))
   {return false}
   if (!isNumeric(month))
   {return false}
   
   if (!(year.length == 1 || year.length == 2 || year.length == 4))
   {return false}
   
   if (yeardt.length == 1)
   {
      yeardt = 0 + yeardt
   }
   
   if (yeardt.length == 2)
   {
      if (yeardt >= 50)
      {
         yeardt = 19 + yeardt
      }
      else
      {
         yeardt = 20 + yeardt
      }
   }
   else
   {
      if (yeardt < 1950 || yeardt > 2049)
      {return false}
   }
   
   if (month < 1 || month > 12)
   {return false}

   if (day < 1 || day > 31)
   {return false}

   if ((month == 4 || month == 6 || month == 9 || month == 11) && day > 30)
   {return false}

   if (month == 2 && day > 29)
   {return false}
   else
   {
      if (!LeapYear(yeardt) && day > 28)
      {return false}
   }
   return true
}

function LeapYear(intYear) 
{
   if (intYear % 100 == 0) 
   {
      if (intYear % 400 == 0) 
      { return true; }
   }
   else 
   {
      if ((intYear % 4) == 0) 
      { return true; }
   }
   return false;
}

function isNumeric(sText)
{
   var ValidChars = "0123456789";
   var valid = true;
   var CurrentChar;

   for (var i = 0; i < sText.length && valid == true; i++) 
   { 
      CurrentChar = sText.charAt(i); 
      if (ValidChars.indexOf(CurrentChar) == -1) 
      {
         valid = false;
      }
   }
   return valid;
   
}

function ValidCharSet()
{
   var i, j
   var invalidChars = "^&*.(@"
   var CharSet = ""

   for (var i=32;i<=126;i++)
   {
      while (invalidChars.indexOf(String.fromCharCode(i)) >= 0)
      {
         i++;
      }
      CharSet += String.fromCharCode(i)
   }
   return CharSet
}


function checkpasswords(newpassword, newpassword2)
{
var msg
   msg = ""

      if (newpassword.value.length > 7 && newpassword.value.length < 33)
      {
         if (!(inValidCharSet(newpassword.value, ValidCharSet())))
         {
            msg = "Your Password contains invalid characters."
         }
         else 
         {
            if (!ContainsCharacter(newpassword.value, "0", "9"))
            {
               msg = "Your Password must contain at least 1 numeric character."
            }
            else
            {
               if (!(ContainsCharacter(newpassword.value, " ", "/") || ContainsCharacter(newpassword.value, ":", "~")))
               {
                   msg = "Your Password must contain at least 1 alpha character."
               }
               else
               {
                  if (newpassword.value != newpassword2.value)
                  {
                     msg = "Your New Password does not match your Confirm Password."
                  }
               }
            }
         }
      }
      else
      {
         msg = "Your password must be between 8 and 32 characters."
      }
   if (msg.length > 0)
   {
      alert(msg)
      return false
   }
   else
   {
      return true;
   }
}

function checkDLselected(fieldname)
{
   var valueselected
   valueselected = true
   if (fieldname.options[fieldname.selectedIndex].value.length == 0)
   {
      valueselected = false
   }
   return valueselected
}
