// JavaScript Document
function validateEmail(email) {
/*	new version by Laurence 2004 Nov 26
	revised 2005 Nov 04 by Laurence: allow hyphens before @ symbol; rename 'verifyEmail' to 'validateEmail'

	RegExp is a Javascript1.2 feature; tested successfully in WinIE 5.0+, MacIE 5.1, Safari 1.0, WinNN 4.7, WinNN 6.2, WinMoz 1.7
	The pattern matches: 
	- at least one word character ( a-zA-Z0-9_ )
	- followed by any number more including periods and hyphens
	- then a single @
	- then at least one alphanumeric character plus any number more including hyphens and periods
	- plus an ending of an alphanumeric char, a single period, and at least 2 more letters. 
	There can be nothing before or after the pattern; all whitespace, punctuation, etc. not explicitly allowed is forbidden.
*/
	var myRegExp = /^[\w][\w\.\-]*@[a-zA-Z0-9]+[\w\.\-]*[a-zA-Z0-9]\.[a-zA-Z]{2,}$/;
	var sPos = email.search(myRegExp);
	if (sPos >= 0) {
		return true;
	} else {
		return false;
	}
}
$(document).ready(function() { 
	$("#form1").submit(function () { 
	
		var emptyFields = "";
	
		if ($("#first").val() == ""){
			emptyFields += "The first name cannot be blank." + "\n" ;
		}
		
		if ($("#last").val() == ""){
			emptyFields += "The last name cannot be blank." + "\n" ;
		}	
		if ($("#email").val() == ""){
			emptyFields += "The email cannot be blank." + "\n" ;
		}			
			
		if ($("#phonenumber").val() == ""){
			emptyFields += "The phone number cannot be blank." + "\n" ;
		}	
		
	
	
		if (emptyFields.length >= 1) {
			alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
			return false;
		}else{
			return true;	
		}
	})

 })

function validateFeedback(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.firstName.value == ""){
		emptyFields += "The first name cannot be blank." + "\n" ;
	}
		
	if (theForm.lastName.value == ""){
		emptyFields += "The last name cannot be blank." + "\n" ;
	}
	
	if (theForm.email.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.email.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.comments.value == ""){
		emptyFields += "The comments cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateRequest(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	if (theForm.firstName.value == ""){
		emptyFields += "The first name cannot be blank." + "\n" ;
	}
		
	if (theForm.lastName.value == ""){
		emptyFields += "The last name cannot be blank." + "\n" ;
	}
	
	if (theForm.email.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.email.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	if (theForm.phone.value == ""){
		emptyFields += "The telephone number cannot be blank." + "\n" ;
	}
	
	if (theForm.description.value == ""){
		emptyFields += "The description cannot be blank." + "\n" ;
	}
	
	if (theForm.requestName.value == ""){
		emptyFields += "The tenant service request name cannot be blank." + "\n" ;
	}
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}

function validateSignup(thisForm) {
	var theForm = thisForm;
	var emptyFields = "";
	
	
	if (theForm.email.value == ""){
		emptyFields += "The email address cannot be blank." + "\n" ;
	} else if (!validateEmail(theForm.email.value)) {
		emptyFields += "The email address must be correctly formatted." + "\n" ;
	}
	
	
	if (emptyFields.length >= 1) {
		alert("Please ensure that the following fields are completed correctly:" + "\n" + emptyFields);
		return false;
	} else {
		return true;
	}
}