function checkEmail (strng) 
{
	var error="";
    var emailFilter=/^.+@.+\..{2,3}$/;
	if (strng == "") 
	{
		error = "You didn't enter an email address.\n";
	}
	else if (!(emailFilter.test(strng))) 
    { 
       error = "Please enter a valid email address.\n";
    }
    else 
    {
	//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
	return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    if (stripped.length < 10) {
	error = "The phone number is the wrong length. Make sure you included a country and an area code.\n";
    } 
return error;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function checkDate(strng)
{
	var error = "" ;
	if ( strng == "")
	{
		error = "Please enter a date" ;
		return error ;
	}
	var daysInMonth = DaysArray(12)
	var s = strng.split("-");
	if (s.length != 3 || (s.length == 3 && (!isInteger(s[0]) || !isInteger(s[1]) || !isInteger(s[2]))))
	{
		error = "Please enter a valid date in the form [YYYY-MM-DD]" ;
	}
	else
	{	
		year = parseInt(s[0],10);
		month = parseInt(s[1],10);
		day = parseInt(s[2],10);
		if (month < 1 || month > 12 || day < 1 || day > 31 || year < 2007 || year > 2010 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month])
		{
			error = "Please enter a valid date in the form [YYYY-MM-DD]" ;
		}
	}
	return error;    
}
