function validEmail(Email)
{
	invalidChars = " /:,;" ;
	if (Email == "") 
	{
		return false ;
	}
	for (i=0; i<invalidChars.length; i++)
	{
		badChar = invalidChars.charAt(i) ;
		if (Email.indexOf(badChar,0) > -1)
		{
			return false ;
		}
	}
	atPos = Email.indexOf("@",1) ;
	if (atPos == -1) 
	{
		return false ; 
	}
	if (Email.indexOf("@",atPos+1) > -1)
	{
		return false ; 
	}	
	periodPos = Email.indexOf(".",atPos) ;
	if (periodPos == -1)
	{
		return false ; 
	}	
	if (periodPos+3 > Email.length)
	{
		return false ;  
	}	
	return true ;
}
		
function chkNumber(valToCheck)
{
	// this function checks to see if a value is numeric.
	// the first character can be +, -, ., or a digit.
	// remaining characters can be . or a digit.
	// once a . is detected, all of the following characters can be a digit only

	numValid = 1 ;
	DecDetect = 0 ;	
	for (i=0; i < valToCheck.length && numValid == 1; i++)
	{

		// set comparison string based on which character we are checking
		if (i == 0)
		{
			CompareTo = "+-0123456789" ;
		}
		else
		{
			CompareTo = "0123456789" ;
		}
		
		// check this character against comparison string
		if (CompareTo.indexOf(valToCheck.charAt(i)) == -1)
		{
			// character is not in comparison
			if (valToCheck.charAt(i) == ".")
			{
				if (DecDetect == 1)
				{
					// this character is a decimal and there has already been one
					numValid = 0 ;
				}
				else
				{
					// this character is the first decimal
					DecDetect = 1 ;
				}
			}
			else
			{
				// this value is invalid
				numValid = 0 ;
			}
		}
	}
	if (numValid == 1)
	{
		return true ;
	}
	else
	{
		return false ;
	}
}

function chkInteger(valToCheck)
{
	// this function checks to see if a value is numeric.
	// the first character can be +, -, ., or a digit.
	// remaining characters can be . or a digit.
	// once a . is detected, all of the following characters can be a digit only

	intValid = 1 ;
	for (i=0; i < valToCheck.length && intValid == 1; i++)
	{

		// set comparison string based on which character we are checking
		if (i == 0)
		{
			CompareTo = "+-0123456789" ;
		}
		else
		{
			CompareTo = "0123456789" ;
		}
		
		// check this character against comparison string
		if (CompareTo.indexOf(valToCheck.charAt(i)) == -1)
		{
			intValid = 0 ;
		}
	}
	if (intValid == 1)
	{
		return true ;
	}
	else
	{
		return false ;
	}
}
function chkDate(valToCheck)
// this function checks to see if a value is a date in the form m/d/yyyy
{
	// check for slashes
	if (valToCheck.indexOf("/") == -1) return false ;
	// check for 3 parts (month, day, and year)
	splitDate = valToCheck.split("/") ;
	if (splitDate.length != 3) return false ;
	// check that all three parts are numeric
	if (chkInteger(splitDate[0])) monthPart = new Number(splitDate[0]) ;
	else return false ;
	if (chkInteger(splitDate[1])) dayPart = new Number(splitDate[1]) ;
	else return false ;
	if (chkInteger(splitDate[2])) yearPart = new Number(splitDate[2]) ;
	else return false ;
	// check for year between 1980 and 2100
	if (yearPart < 1980 || yearPart > 2100) return false ;
	// check for valid month and day
	if (monthPart == 1 || monthPart == 3 || monthPart == 5 || monthPart == 7 || monthPart == 8 || monthPart == 10 || monthPart == 12)   // day should be between 1 and 31
	{
		if (dayPart < 1 || dayPart > 31) return false ;
	}
	else if (monthPart == 4 || monthPart == 6 || monthPart == 9 || monthPart == 11)
	// day should be between 1 and 30
	{
		if (dayPart < 1 || dayPart > 30) return false ;
	}
	else if (monthPart == 2)     // February.  28 or 29 days depending on leap year
	{
		if (yearPart % 4 == 0)      // possibly a leap year
		{
			if (yearPart % 100 == 0)
			// year divisible by 100.  if also divisible by 400 it is a leap year.
			{
				if (yearPart % 400 == 0)
				{
					if (dayPart < 1 || dayPart > 29) return false ;  // leap year
				}
				else if (dayPart < 1 || dayPart > 28) return false ;  // not leap year
			}
			else if (dayPart < 1 || dayPart > 29) return false ;  // leap year
		}
		else if (dayPart < 1 || dayPart > 28) return false ;  // not leap year
	}
	else return false ;    // not a valid month
	// if we got this far, return true
	return true ;
}

function chkTime(valToCheck)
{
	// this function checks to see if a value is a time in the form hh:mm am/pm
	if (valToCheck.length != 8)
	{
		return false ;
	}
	if (chkNumber(valToCheck.substr(0,2)) == false || valToCheck.substr(0,2) < 1 || valToCheck.substr(0,2) > 12)
	{
		return false ;
	}
	if (valToCheck.substr(2,1) != ":")
	{
		return false ;
	}
	if (chkNumber(valToCheck.substr(3,2)) == false || valToCheck.substr(3,2) < 0 || valToCheck.substr(3,2) > 59)
	{
		return false ;
	}
	if (valToCheck.substr(5,1) != " ")
	{
		return false ;
	}
	if (valToCheck.substr(6,2) != "am" && valToCheck.substr(6,2) != "pm")
	{
		return false ;
	}
	return true ;
}

function confDelete()
{
	if (confirm("Are you sure you want to delete this record?"))
	{
		return true ;
	}
	else
	{
		return false ;
	}
}

function chkPassword(pwdToCheck, UserName)
{
	rightLength = 0 ;
	nothasUsername = 0 ;
	hasNumber = 0 ;
	hasLetter = 0 ;
	pwdToCheck = pwdToCheck.toUpperCase() ;
	UserName = UserName.toUpperCase() ;
	
	if (pwdToCheck.length >= 6 && pwdToCheck.length <= 12)
	{
		rightLength = 1 ;
	}
	if (pwdToCheck.indexOf(UserName) == -1)
	{
		nothasUsername = 1 ;
	}
	for (i=0; i < pwdToCheck.length && hasNumber == 0; i++)
	{
		CompareTo = "0123456789" ;
		if (CompareTo.indexOf(pwdToCheck.charAt(i)) > -1)
		{
			hasNumber = 1 ;
		}
	}
	for (j=0; j < pwdToCheck.length && hasLetter == 0; j++)
	{
		CompareTo = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
		if (CompareTo.indexOf(pwdToCheck.charAt(j)) > -1)
		{
			hasLetter = 1 ;
		}
	}
	if (rightLength == 1 && nothasUsername == 1 && hasNumber == 1 && hasLetter == 1)
	{
		return true ;
	}
	return false ;
}
function timeoutWarning()
{
	alert('Your session is about to expire due to inactivity.') ;
}

