// Script for email Validation
//**************************************************************************
var valid ="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_ '";

function validate()
{
	var email = document.emailform.email.value;
	//Reference Wev Sites\varification code
	


	//var reason = document.emailform.reason.value;
	var name = document.emailform.full_name.value;
	//var middle = document.emailform.middle.value;
	//var last = document.emailform.last.value;
	//var challenge = document.frmAllowMe.challenge.value;
	var regx = /^[A-Za-z0-9\@\+=%\\'\?\^!\$(\);\"&]+[\w\.\@\+=%\\'\?\^!\$(\);\"&-_]*@[A-Za-z0-9\@\+=%\\'\?\^!\$\(\);\"&]+[\w\.\@\+=%\\'\?\^!\$\(\);\"&-]*\.[\w\.\@\+=%\\'\?\^!\$\(\);\"&-]+$/;

	if (name.length ==0)
	{
		alert("Your Name is required.");
		document.emailform.full_name.focus();
		return false;
	}

	for (j = 0; j < name.length; j++) {
		if (valid.indexOf(name.charAt(j)) == -1)
		{
			alert("Your Name contains invalid characters (only A-Z, a-z, ', - and _ are supported.)");
			document.emailform.full_name.focus();
			return false;
		}
	}
//*********************************************************************************************
	if (email.length ==0)
	{
		alert("Your Email Address is Required.");
		document.emailform.email.focus();
		return false;
	}

	if ((email != "") && (!isValidEmailAddress(email, regx)))
	{
		alert("The email address you entered is not valid. Please re-enter a valid email address.");
		document.emailform.email.focus();
		return false;
	}

	alert("Your Message has been sent");
	return true;

}

//used by isValidEmailAddress function
function trim(inputString) {
   return inputString.replace(/^\s+/,'').replace(/\s+$/,'');
}
//Called by html page
function isValidEmailAddress(email, regx) {
	if(email == null)  
	{
		return false;
	} 
	else if((email = trim(email)).length == 0)
	{
		return false;
	} 
	else 
	{
		//Validate emailaddress character set and rules
		if(regx == null || regx == "" || regx == "null")
		{
			regx = /^[A-Za-z0-9]+\w*((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-|_)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		}
		return regx.test(email);
  	}
}
// called by html page but we will not be using so we can erase.
function isValidDomain(domain, regx) 
{	
	if(domain == null)
	{
		return false;
	} 
	else if((domain = trim(domain)).length == 0)
	{
		return false;
	}
	else if(domain.length > 250)
	{
		return false;
	}
	else 
	{	
		//Validate domain character and rules
		if(regx == null || regx == "" || regx == "null")
		{
			regx = /^[A-Za-z0-9](\.|-|\w)*[A-Za-z0-9]$/;
		}
  		return regx.test(domain);
  	}
}