
function checkEmail (value) 
{
	var error="";
	if (value.replace(/\s/g,"") == "") 
	{
		error = "You didn't enter an email address.\n";
	}

    var emailFilter=/^.+@.+\.[a-z]{2,6}$/;
    if (!(emailFilter.test(value))) 
	{ 
       error = "Please enter a valid email address.\n";
    }
    else 
	{
		//test email for illegal characters
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
        if (value.match(illegalChars)) 
		{
          error = "Please enter a valid email address. The email address you provided contains illegal characters.\n";
       }
    }
	return error;    
}


// phone number - strip out delimiters and check for 10 digits
function checkPhone (value) 
{
	var error = "";
	if (value == "") 
	{
		error = "You didn't enter a phone number.\n";
	}

	var stripped = value.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) 
	{
       error = "Please enter a valid phone number. The phone number you provided contains illegal characters.\n";  
    }
    if (!(stripped.length == 10)) 
	{
		error = "Please enter a valid phone number. The phone number you provided is the wrong length. Make sure you included an area code.\n";
    } 
	return error;
}



// firstname and lastname - should be provided.

function checkNames (firstName, lastName) 
{
	var error = "";
	if (firstName.replace(/\s/g,"") == "") 
	{
	   error = "Please enter a first name.\n";
	}

	if (lastName.replace(/\s/g,"") == "") 
	{
	   error += "Please enter a last name.\n";
	}

	return error;
}       

// DOB - should be provided and a valid date.

function checkBirthDay (value) 
{
	var error = "";
	if (value == "") 
	{
	   error = "Please enter a date of birth.\n";
	}

	return error;
} 

//validate whole form
function checkVolunteerForm(theForm) {
    var why = "";
    why += checkNames(theForm.firstName.value,theForm.lastName.value);
    why += checkEmail(theForm.email.value);
	if (why != "") 
	{
       alert(why);
       return false;
    }
	return true;
}
