// JavaScript Document

function invalid() {
		var emailFilter = /^[^@]+@[^@.]+\.[^@]*\W\w$/ ;
		var illegalChars = /\W/; // allow letters, numbers, and underscores
		if (document.Login.username.value == "") {
			document.Login.username.style.borderColor = "#f00";
			alert("You did not enter a username.");
			return false;
			}
		 if ((document.Login.username.value.length < 5) || (document.Login.username.value.length > 15)) {
			document.Login.username.style.borderColor = "#f00";
			alert("The username is the wrong length.\n Please enter 5 or more charaters.");
			return false;
			}
		 if (illegalChars.test(document.Login.username.value)) {
			document.Login.username.style.borderColor = "#f00";
			alert("The username contains illegal characters.\n Please use only Alphanumeric Characters.\n Acceptable Charaters: \"A-Z\", \"0-9\", and \"_\".");
			return false;
			}
		else {
			document.Login.username.style.borderColor = "#DFDFDF";
			}
			var minLength = 6; // Minimum length
			var invalid = " "; // Invalid character is a space
			var pw1 = document.Login.style.password;
			var pw2 = document.Login.style.password2;

			// check for a value in both fields.
		if (document.Login.password.value == '' || document.Login.password2.value == '') {
			alert('Please enter a password and then retype it in the second field. ');
			document.Login.password.focus();
			document.Login.password.style.borderColor = "#f00";
			document.Login.password2.focus();
			document.Login.password2.style.borderColor = "#f00";

			return false;
			}
			// check for minimum length
		if (document.Login.password.value.length < minLength) {
			alert('Your password must be at least ' + minLength + ' characters long. Please Try again.');
			document.Login.password.focus();
			document.Login.password.style.borderColor = "#f00";
			return false;
			}
			// check for spaces
		if (document.Login.password.value.indexOf(invalid) > -1) {
			alert("Sorry, spaces are not allowed in your password.");
			document.Login.password.focus();
			document.Login.password.style.borderColor = "#f00";
			return false;
			}
		if (document.Login.password.value != document.Login.password2.value) {
			alert ("You did not enter the same new password twice. Please re-enter your password.");
			document.Login.password.focus();
			document.Login.password.style.borderColor = "#f00";
			document.Login.password2.focus();
			document.Login.password2.style.borderColor = "#f00";
			return false;
			}
			
		else {
			document.Login.password.style.borderColor = "#DFDFDF";
			document.Login.password2.style.borderColor = "#DFDFDF";
			}

		 if (emailFilter.test(document.Login.company.value)) {
			document.Login.company.style.borderColor = "#f00";
			alert("The Company Field contains illegal characters.\n Please use only Alphanumeric Characters.\n Acceptable Charaters: \"A-Z\", \"0-9\", \"@\", \".\" and \"_\".");
			document.Login.company.focus();
			document.Login.company.style.borderColor = "#f00";
			return false;
			}			
		else {
			document.Login.company.style.borderColor = '#DFDFDF';
			}


		if(document.Login.first_name.value == "") {
			alert("You Must Enter Your First Name.");
			document.Login.first_name.focus();
			document.Login.first_name.style.borderColor = '#f00';
			return false;
			}
		 if (illegalChars.test(document.Login.first_name.value)) {
			document.Login.first_name.style.borderColor = "#f00";
			alert("The First Name contains illegal characters.\n Please use only Alphanumeric Characters.\n Acceptable Charaters: \"A-Z\", \"0-9\", and \"_\".");
			document.Login.first_name.focus();
			document.Login.first_name.style.borderColor = "#f00";
			return false;
			}			
		else {
			document.Login.first_name.style.borderColor = '#DFDFDF';
			}
		
		if(document.Login.last_name.value == "") {
			alert("You Must Enter Your Last Name.");
			document.Login.last_name.focus();
			document.Login.last_name.style.borderColor = '#f00';
			return false;
			}
		 if (illegalChars.test(document.Login.last_name.value)) {
			document.Login.last_name.style.borderColor = "#f00";
			alert("The Last Name contains illegal characters.\n Please use only Alphanumeric Characters.\n Acceptable Charaters: \"A-Z\", \"0-9\", and \"_\".");
			document.Login.last_name.focus();
			document.Login.last_name.style.borderColor = "#f00";
			return false;
			}			
		else {
			document.Login.last_name.style.borderColor = '#DFDFDF';
			}



	// Check From Address	
		var AtPos = document.Login.email.value.indexOf("@")
		var StopPos = document.Login.email.value.lastIndexOf(".")
		 
		 if (emailFilter.test(document.Login.email.value)) {
			document.Login.email.style.borderColor = "#f00";
			alert("The Email contains illegal characters.\n Please use only Alphanumeric Characters.\n Acceptable Charaters: \"A-Z\", \"0-9\", \"@\", \".\" and \"_\".");
			document.Login.email.focus();
			document.Login.email.style.borderColor = "#f00";
			return false;
			}			

		if (AtPos == -1 || StopPos == -1) {
				alert("Please Enter a Valid Email Address")
				document.Login.email.focus();
				document.Login.email.style.borderColor = '#f00';
				return false;
			}
		else {
			document.Login.email.style.borderColor = '#DFDFDF';
			}

		if (StopPos < AtPos) {
				alert("Please Enter a Valid Email Address")
				document.Login.email.focus();
				document.Login.email.style.borderColor = '#f00';
				return false;
			}
		else {
			document.Login.email.style.borderColor = '#DFDFDF';
			}
			
		if (StopPos - AtPos == 1) {
				alert("Please Enter a Valid Email Address")
				document.Login.email.focus();
				document.Login.email.style.borderColor = '#f00';
				return false;
			} 
		else {
			document.Login.email.style.borderColor = '#DFDFDF';
			}
			
			
	return true;
}


function VerifyData()
{
	var AtPos = document.sendmail.email.value.indexOf("@")
	var StopPos = document.sendmail.email.value.lastIndexOf(".")

	
		//Check Name
		if(document.sendmail.name.value == "") {
			emailsendH();
			alert("Please Enter Your Name.");
			document.sendmail.name.focus();
			document.sendmail.name.style.borderColor = '#f00';
			return false;
			}
		else {
			document.sendmail.name.style.borderColor = '#DFDFDF';
			}
		if(document.sendmail.email.value == "") {
			emailsendH();
			alert("You Must Enter Your Email Address.");
			document.sendmail.email.focus();
			document.sendmail.email.style.borderColor = '#f00';
			return false;
			}	
		else {
			document.sendmail.email.style.borderColor = '#DFDFDF';
			}
	
		
		// Check From Address	
		if (AtPos == -1 || StopPos == -1) {
				emailsendH();
				alert("Please Enter a Valid Email Address")
				document.sendmail.email.focus();
				document.sendmail.email.style.borderColor = '#f00';
				return false;
			}
		else {
			document.sendmail.email.style.borderColor = '#DFDFDF';
			}

		if (StopPos < AtPos) {
				emailsendH();
				alert("Please Enter a Valid Email Address")
				document.sendmail.email.focus();
				document.sendmail.email.style.borderColor = '#f00';
				return false;
			}
		else {
			document.sendmail.email.style.borderColor = '#DFDFDF';
			}
			
		if (StopPos - AtPos == 1) {
				emailsendH();
				alert("Please Enter a Valid Email Address")
				document.sendmail.email.focus();
				document.sendmail.email.style.borderColor = '#f00';
				return false;
			} 
		else {
			document.sendmail.email.style.borderColor = '#DFDFDF';
			}

		// Check Phone	
	   if(document.sendmail.phone.value.search(/\d{3}\-\d{3}\-\d{4}/)==-1){
		   	emailsendH();
     	 	alert("The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.");
			document.sendmail.phone.focus();
			document.sendmail.phone.style.borderColor = '#f00';
			return false;
			}
		else {
			document.sendmail.phone.style.borderColor = '#DFDFDF';
			}
			
		// Check Subject	
		if(document.sendmail.subject.value == "") {
			emailsendH();
			alert("You Must Enter A Subject.");
			document.sendmail.subject.focus();
			document.sendmail.subject.style.borderColor = '#f00';
			return false;
			}
		else {
			document.sendmail.subject.style.borderColor = '#DFDFDF';
			}

		// Check Body	
		if(document.sendmail.message.value == "") {
			emailsendH();
			alert("Please enter the message.");
			document.sendmail.message.focus();
			document.sendmail.message.style.borderColor = '#f00';
			return false;
			}
		else {
			document.sendmail.message.style.borderColor = '#DFDFDF';
			}
	return true;
	
}

function validateemail(){
		// Check From Address	
		var AtPos = document.addemail.emailaddress.value.indexOf("@")
		var StopPos = document.addemail.emailaddress.value.lastIndexOf(".")
		
		if (AtPos == -1 || StopPos == -1) {
				alert("Please Enter a Valid Email Address")
				document.addemail.emailaddress.focus();
				document.addemail.emailaddress.style.borderColor = '#f00';
				return false;
			}
		else {
			document.addemail.emailaddress.style.borderColor = '#DFDFDF';
			}

		if (StopPos < AtPos) {
				alert("Please Enter a Valid Email Address")
				document.addemail.emailaddress.focus();
				document.addemail.emailaddress.style.borderColor = '#f00';
				return false;
			}
		else {
			document.addemail.emailaddress.style.borderColor = '#DFDFDF';
			}
			
		if (StopPos - AtPos == 1) {
				alert("Please Enter a Valid Email Address")
				document.addemail.emailaddress.focus();
				document.addemail.emailaddress.style.borderColor = '#f00';
				return false;
			} 
		else {
			document.addemail.emailaddress.style.borderColor = '#DFDFDF';
			}
			
	return true;
}

