/* ########################################################
** #
** # Name:		Validate.js
** #
** # Last modified:	20th January, 2003 by John Gaffney
** #
** # Purpose:		collection of validation functionss.
** #
** ########################################################
*/
// Regular expression declarations used by the validation functions.
var regValidEmailFormat = /^.+@.+..+$/;

// General purpose function that removes whitespace from within passed in string.
function stripWhitespace (str) { 
	var whitespace = " \t\n\r";
	var returnString = "";
	for (var i = 0; i < str.length; i++) { 
		var c = str.charAt(i);
		if (whitespace.indexOf(c) == -1) returnString += c;
	};
	return returnString;
};

// Function to validate an email string
function isValid(email,name,message) {
	if ( stripWhitespace(email).length == 0 ) {
		alert ("You need to enter a Name, Message and a valid Email address!");
		return false;
	};
	valid = regValidEmailFormat.test(email);
	if(valid) {
		//var istrue = 1;
	}
	else
	{
		alert ("You need to enter a Name, Message and a valid Email address!");
		return false;
	}
	
	if ( stripWhitespace(name).length == 0 ) {
		alert ("You need to enter a Name, Message and a valid Email address!");
		return false;
	}

	if ( stripWhitespace(message).length == 0 ) {
		alert ("You need to enter a Name, Message and a valid Email address!");
		return false;
	}else
	{
		return true;
	}
};

function isValid2(email,email2,name,name2,message) {
	if ( stripWhitespace(email).length == 0 ) {
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	};
	valid = regValidEmailFormat.test(email);
	if(valid) {
	}
	if ( stripWhitespace(email2).length == 0 ) {
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	};
	valid = regValidEmailFormat.test(email);
	if(valid) {
	}
	else
	{
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	}
	
	if ( stripWhitespace(name).length == 0 ) {
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	}
	if ( stripWhitespace(name2).length == 0 ) {
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	}

	if ( stripWhitespace(message).length == 0 ) {
		alert ("You need to enter a all fields and two valid Email addresses");
		return false;
	}else
	{
		return true;
	}
};

