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 of Email address 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 of Email address 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 Email 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 Email address is missing a hostname!"
   alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//**********************************************
//a very RICH date check format function
//reg exp to check for correct date format

function isValidDateCurrent(thisWay,str,myForm)
{
	var daYear;
	var match;
	var daField;
	var con;
	var isdate;

	isdate=true;
	
	daField=str.value;

	if (daField != '') {
		// find the number of element in the form to be able to focus it
		for (var i=0; i < myForm.length; i++) {
			if (myForm.elements[i] == str) {
				con = i;
			}
		}
			
		//split any system dates into an array and replace any whitespace with nuthin 
		//so we only test short date mm/dd/yy

		daString=daField.replace(/[^\/0-9]/g,"")
	
		if (!(thisWay.test(daString))) 
		{
			alert("Please enter dates using this format: mm/dd/yy or mm/dd/yyyy \nA two digit entry for year will default to between 1951 and 2050.");
			myForm.elements[con].focus();
			isdate=false;
		}
		else {
			match=daString.match(thisWay);
			//check year
			daYear=match[3];
							
			 //if a 3 or 4 digit yr just keep it within db boundaries
				
			daTest=/\d{3,4}/;
			
			if (daTest.test(daYear))
			{		
				if ((parseInt(daYear) <1951) || (parseInt(daYear)>2050))
				{
						alert ("Please enter a year between 1951 and 2050");
						myForm.elements[con].focus();
						isdate=false;
				}
			}			
			if ((match[1]<1) || (match[1]>12))
			{
				alert ("Please enter a valid month (1-12)");
				myForm.elements[con].focus();
				isdate=false;
			}
			if ((match[2]<1) || ((match[2]>leapDays(daYear)) && (match[1]==2)) ||
				((match[2]>30) && (match[1]==4||match[1]==6||match[1]==9||match[1]==11)) ||
				((match[2]>31) && (match[1]==1||match[1]==3||match[1]==5||match[1]==7||match[1]==8||match[1]==10||match[1]==12)))
			{
				alert ("Please enter a valid day.");
				myForm.elements[con].focus();
				isdate=false;
			}	
			if (isdate==true){
				var d=new Date(CleanDate(daString));
				var msecsInADay = 86400000;
				var dc=new Date();
				var ddc=new Date(dc.getTime() - msecsInADay);
				if (d<ddc){
					alert("Remind date can not be older than today.");
					myForm.elements[con].focus();
				}
			}
		}
	}
}

function ValidUserIDandPWD(sText)
{
	var ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var IsValidInput=true;
    var Char;

   for (i = 0; i < sText.length && IsValidInput == true; i++) 
	{ 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) 
		{
			IsValidInput = false;
		}
	}
   return IsValidInput;
}

function CompareDate(Obj1,Obj2)
{
	var IsValidInput=false;
	var Date1=new Date(Obj1.value);
	var Date2=new Date(Obj2.value);
	
	if (Date1>Date2){
		IsValidInput=true;
	}

   return IsValidInput;
}

function isValidDate(thisWay,str,myForm)
{
	var daYear;
	var match;
	var daField;
	var con;

    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();
    var f_year=curr_year+2;
	
	daField=str.value;

	if (daField != '') {
		// find the number of element in the form to be able to focus it
		for (var i=0; i < myForm.length; i++) {
			if (myForm.elements[i] == str) {
				con = i;
			}
		}
			
		//split any system dates into an array and replace any whitespace with nuthin 
		//so we only test short date mm/dd/yy

		daString=daField.replace(/[^\/0-9]/g,"")
	
		if (!(thisWay.test(daString))) 
		{
		alert("Please enter dates using this format: mm/dd/yy or mm/dd/yyyy \nA two digit entry for year will default to between 1951 and 2050.");
			myForm.elements[con].focus();
		}
		else {
			match=daString.match(thisWay);
			//check year
			daYear=match[3];
							
			 //if a 3 or 4 digit yr just keep it within db boundaries
				
			daTest=/\d{3,4}/;
			if (daTest.test(daYear))
				{		
				if ((parseInt(daYear) <curr_year) || (parseInt(daYear)>f_year))
					{
					alert ("Please enter a year between "+curr_year.toString()+" and "+f_year.toString());
						myForm.elements[con].focus();
					}
				}
				/*
				if ((parseInt(daYear) <1951) || (parseInt(daYear)>2050))
					{
					alert ("Please enter a year between 1951 and 2050");
						myForm.elements[con].focus();
					}
				}*/			
			if ((match[1]<1) || (match[1]>12))
			{
				alert ("Please enter a valid month (1-12)");
				myForm.elements[con].focus();
			}
			if ((match[2]<1) || ((match[2]>leapDays(daYear)) && (match[1]==2)) ||
				((match[2]>30) && (match[1]==4||match[1]==6||match[1]==9||match[1]==11)) ||
				((match[2]>31) && (match[1]==1||match[1]==3||match[1]==5||match[1]==7||match[1]==8||match[1]==10||match[1]==12)))
			{
				alert ("Please enter a valid day.");
			myForm.elements[con].focus();
			}	
		}
	}
}

// returns max number of days in February depending on the year
function leapDays(myYear) {
		myYear = parseInt(myYear);

		if (myYear < 100) {
			myYear = ((myYear < 50) ? (2000 + myYear) : (1900 + myYear));
		}
		if (((myYear % 4 == 0) && !(myYear % 100 == 0)) || (myYear % 400 == 0)) {
			return 29;
		}
		else {
			return 28;
		}
}

function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var Char;
   var vreturn=true;
   
   if (sText.length==0) return false;
   
   for (i = 0; i < sText.length; i++) {
       Char = sText.charAt(i);
       if (ValidChars.indexOf(Char) == -1) {
          vreturn=false;
       }
    }
   return vreturn;
}

// This takes a date string that MIGHT have a two digit year
// as the last two digits. If it does, this function replaces
// the two digit year with what it *assumes* is the proper
// four digit year.
function CleanDate( strDate ){
	// Return the cleaned date.
	return(
	strDate.replace(

		// This regular expression will search for a slash
		// followed by EXACTLY two digits at the end of
		// this date string. The two digits are being
		// grouped together for future referencing.
		new RegExp( "/(\\d{2})$", "" ),
 

		// We are going to pass the match made by the
		// regular expression off to this function literal.
		// Our arguments are as follows:
		// $0 : The entire match found.
		// $1 : The first group within the match.
		function( $0, $1 ){
		 

			// Check to see if our first group begins with
			// a zero or a one. If so, replace with 20 else
			// replace with 19.
			if ($1.match( new RegExp( "^[01]{1}", "" ) )){

				// Replace with 20.
				return( "/20" + $1 );
			}else {
				 

				// Replace with 19.
				return( "/19" + $1 );
				 

			}
		}
	)
);
 

}


