function emailCheck (emailStr) {
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s).");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	/*if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}*/

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid in your email address!");
			return false;
			}
		}
		return true;
	}
	
	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		alert("The domain name doesn't seem to be valid in your email address.");
		return false;
	}

	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) {
	   alert("The address must end in a three-letter domain, or two letter country.");
	   return false;
	}
	
	if (len<2) {
	   var errStr="This address is missing a hostname!";
	   alert(errStr);
	   return false;
	}

	return true;
}

function validateDate(s)
{
	//this function validates the date in the format mm-dd-yyyy
	//this function calls the following 2 functions: isNum() and own_split()
    var isNumber = 0;

    //Test for a string
   	if (s.length > 0)
   	{
    	//Create an array to split the date into mm/dd/yyyy
    	strarr = new Array ();

    	//Use own split function 
    	own_split(strarr, s, '/' );

	    //3 array elements means month,day and year
	   	if (strarr.length == 3)
	   	{
			if ((!isNum(strarr[0])) || (!isNum(strarr[1])) || (!isNum(strarr[2])))
			{
				alert("No characters (a-z) allowed in the date field.");
				return false;
			}			
			
			//Test that the value of each element falls in an acceptable range
			for (var i = 0; i < strarr.length; i++)
			{				
				if ((strarr[0] < 1) || (strarr[0] >12))
				{
					alert("Month must be between 1 and 12.");
					return false;
				}

				//check if month is February,whether it is a leap year and if day is valid for the year 
				if (strarr[0]==2)
				{		
					if ( ( (strarr[2] % 4 == 0) && (strarr[2] % 100!= 0)) || (strarr[2] % 400 == 0) ) 
					{
						if ((strarr[1] < 1) || (strarr[1] >29))
						{
							alert("Invalid number of days for this month.");
							return false;								
						}
					}
					else
					{
						if ((strarr[1] < 1) || (strarr[1] >28))
						{
							alert("Invalid number of days for this month.");
							return false;
						}
					}
				}
				//check if month is a 31 day month, and see if day is valid
				if ((strarr[0]==1)||(strarr[0]==3)||(strarr[0]==5)||(strarr[0]==7)||(strarr[0]==8)||(strarr[0]==10)||(strarr[0]==12))
				{
					if ((strarr[1] < 1) || (strarr[1] >31))
					{
						alert("Invalid number of days for this month.");
						return false;					
					}
				}
				//check if month is a 30 day month, and see if day is valid
				if ((strarr[0]==4)||(strarr[0]==6)||(strarr[0]==9)||(strarr[0]==11))
				{
					if ((strarr[1] < 1) || (strarr[1] >30))
					{
						alert("Invalid number of days for this month.");
						return false;		
					}
				}
				//check if year is a valid four digit year	
				if ((strarr[2] <1900) || (strarr[2] >3000))
				{
					alert("Invalid year. The year must have 4 digits.");
					return false;					
				}
			}
			return true;
		}
		alert("Please enter the date in the format of mm/dd/yyyy.\nPlease include dashes (/).");
		return false;
	}	
	return true;	
}
	
function own_split(arr, str, delim)
{//called by validateDate function
	//Initialize local variables
	var pos = 0;
	var num = 0;
	var start = 0;

	//Loop while there are characters in the string
	while (pos < str.length)
	{
		//Loop while there are delimiters in the string
		while((str.substring (pos, pos+1) != delim) && (pos < str.length))
		{
			pos++;
		}
		//Add the new characters to the output array
		arr[num] = str.substring(start,pos);
		num++;
		start = pos+1;
		pos++;
	}
}

function isNum(CurrentValue)
{
	var Length = CurrentValue.length;

	for(var j = 0; j < Length; j++)
	{
		ch = CurrentValue.charAt(j);
		if(ch < "0" || ch > "9")
			return false;
	}
	return true;
}	

function checkCard(thecard){
	var Length = thecard.length;

	for(var j = 0; j < Length; j++)
 	{
		ch = thecard.charAt(j);
		if((ch < "0" || ch > "9") && ch != " ")
			return false;
	}
 	return true;
}

function Trim (theString)
{//removes spaces at the beginning and end of text
	if ((theString != null) && (theString.length > 0))
	{
		for (var cFirstCharacter = 0; (cFirstCharacter < theString.length) && (theString.charAt(cFirstCharacter) == ' '); cFirstCharacter++)
			;

		for (var cLastCharacter = theString.length-1; (cLastCharacter > 0) && (theString.charAt(cLastCharacter) == ' '); cLastCharacter--)
			;

		if (cFirstCharacter <= cLastCharacter)
			theString = theString.substring(cFirstCharacter, cLastCharacter+1);
		else
			theString = '';
		}

	return theString;
}