// filename: form_validation_applets.js
// design by: www.ernestconill.com
// date: 24 November 2008

//////////////////////////////////////////////////////
// This function tests for the punctuation characters
// (. and @) found in a valid e-mail address.
// And then because we use re-confirm email field
// it checks if both emails are the same
//////////////////////////////////////////////////////

function bothValidEmail(inputValue) {
// designates the variable "emailPattern" as a RegExp object.
var emailPattern = /^\w+@\w+\.+\w/
// test() is a built-in method of the RegExp object.
// If both an @ symbol and a dot were found, and
// in the correct order (@ must come first) and it fits with the RegExp object initialized
// beffore /^\w+@\w+(\.\w{3})$/  (start with caracter have @ have a . and tree letters
if (emailPattern.test(inputValue)) {
// It’s a valid e-mail address. Then we check if they are the same emails 
	with (document.forms.friends)
		{
			if (email_2.value.length <=0) {return true}  		//to let the two be filled
			if (email_1.value.length <=0) {return true}			//to let the two be filled
			if (email_1.value == email_2.value) {return true}
			else {alert('Sorry, the emails addresses are not the same'); return false}
		}
}
else {
// The e-mail address is invalid.
alert('Sorry, you entered an invalid e-mail address. Please try again.')
return false
}
}



//////////////////////////////////////////////////////////
// This function tests the name field to not be left blank
//////////////////////////////////////////////////////////
function ValidateName(name)
{
with (document.forms.friends)
	{
		if (name.value.length <=0) {alert ('no name ??'); return false}
		return true;
	}
}



//////////////////////////////////////////////////////////////
// This function tests the textarea field to not be left blank
//////////////////////////////////////////////////////////////

function ValidateText(textarea)
{
with (document.forms.friends)
	{
		if (textarea.value.length <=0) {alert ('no message ??'); return false}
		return true;
	}
}


