//
//*Version Control
//****************************************************************************************************
//*                                                                                                  *
//*  Source: formcheck.js                                                                            *
//'*                                                                                                 *
//'*  Rev     Inits   Date    Description                                                            *
//'* -----    -----  -------  -----------                                                            *
//'*                                                                                                 *
//'*  0.0            27/02/06 Initial                                                                *
//'*                                                                                                 *
//'***************************************************************************************************
//
//
//
// Includes the following:
// checkContactInfo() 			checks contact info on the form has been supplied


// this function validates an email address
function checkEmail(f) {
	var str = f.value;
 	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
     	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	if (!(!reg1.test(str) && reg2.test(str))) { //   syntax is invalid
		alert('Please enter a valid email address');
 	   	f.focus();
 		f.select();
 	 	return (false);
	}
	return (true);
}


// This script checks if a telephone number or email address have been supplied. If an email address
// has been supplied then it validates it. The switch parameter determines whether two separate forename
// and surname boxes were used or just one
function checkContactInfo() 
{
	if(document.emailForm.Name.value == "") {
        alert("Please enter your name");
        document.emailForm.Name.focus();
		return false;
	} 
	if(document.emailForm.Email.value == "" && document.emailForm.Telephone.value == "" )	{
		alert("Please enter either a valid telephone number or a valid email address");
	        document.emailForm.Email.focus();
			
		return false;
	} else {
		if(document.emailForm.Email.value != "")	{
			if (!checkEmail(document.emailForm.Email))
				return(false);
		}
	} 
	return true;
	
}


