function emailSubmit(form) {
	var formName = form.name;
	//alert('In validation.js'+formName);
	document.getElementById("reqName").style.color = "#585858";
	document.getElementById("reqEmail").style.color = "#585858";
	/*document.getElementById("reqstate").style.color = "#585858";*/
	document.getElementById("checkfriends").style.color = "#585858";
	var urlParam = window.location;
	//alert(urlParam);
	//document.getElement+ById("commas").style.color = "#585858";
	if(formName == "tellafriend") {
		var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		var currentDate = new Date();
		var errors = "";
		var eligibilityFlag = true;
		var yourName = form.yourname.value;
		var yourEmail = form.youremail.value;
		var state = form.state.value;
		var date = form.dob.value;
		var sendCopy = form.sendCopy.checked;
		var friendsNames1 = form.friendsNames1.value;
		var friendsNames2 = form.friendsNames2.value;
		var friendsNames3 = form.friendsNames3.value;
		var subject = 'Check this out';
		var message = form.message.value;
		/*var charRemain = form.charRemain.checked;*/
		var status = true;
		var i = 0;
		var field = document.getElementById("message").value;
		var firstspace = /^ /
		var lastspace = / $/
		var middlespace = /[ ]+/g 
		var field = field.replace(firstspace,"");
		var field = field.replace(lastspace,"");
		var field = field.replace(middlespace," ");
		var fieldDiv = field.split(" ");
		var words = fieldDiv.length;
		//alert(words);
		//$(document).ready(function(){
		//	var thewords = $('#message').val().split(/\b[\s,\.-:;]*/).length;
		//	alert($('#message').val().split(/\b[\s,\.-:;]*/));
		//	alert(thewords);
		//});
		function validate(email) {
			return emailFilter.test(email);
		}
		function trim(str) {
			var	str = str.replace(/^\s\s*/,''),
					ws = /\s/,
					i = str.length;
			while (ws.test(str.charAt(--i)));
			return str.slice(0, i + 1);
		}
		/** Validate a date with the format mm/dd/yyyy */
		function validateDate(strValue) {
			var objRegExp = /^\d{1,2}(\/)\d{1,2}\1\d{4}$/
			//check to see if in correct format
			if(!objRegExp.test(strValue)){
				return false; //doesn't match pattern, bad date
			} else {
				var strSeparator = strValue.substring(2,3) 
				var arrayDate = strValue.split(strSeparator); 
				//create a lookup for months not equal to Feb.
				var arrayLookup = { '01' : 31,'03' : 31, 
														'04' : 30,'05' : 31,
														'06' : 30,'07' : 31,
														'08' : 31,'09' : 30,
														'10' : 31,'11' : 30,
														'12' : 31}
				var intDay = parseInt(arrayDate[1],10);
				//check if month value and day value agree
				if(arrayLookup[arrayDate[0]] != null) {
					if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
						return true; //found in lookup table, good date
				}
				
				//check for February
				var intMonth = parseInt(arrayDate[0],10);
				if (intMonth == 2) { 
					 var intYear = parseInt(arrayDate[2]);
					 if (intDay > 0 && intDay < 29) {
							 return true;
					 }
					 else if (intDay == 29) {
						 if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
								 (intYear % 400 == 0)) {
									// year div by 4 and ((not div by 100) or div by 400) ->ok
								 return true;
						 }   
					 }
				}
			}  
			return false; //any other values, bad date
		}

		if(yourName == "Your Name") {
			errors += "- Your name is required\n";
			/*document.getElementById("reqName").style.color = "#ca2221";*/
		}
		if(yourEmail == "Your Email Address") {
			errors += "- Your email is required\n";
			/*document.getElementById("reqEmail").style.color = "#ca2221";*/
		} else {
			if(!emailFilter.test(yourEmail)) {
				errors += "- A valid email is required\n";
				/*document.getElementById("reqEmail").style.color = "#ca2221";*/
			}
		}
		if(state == "") {
			errors += "- A state is required\n";
			/*document.getElementById("reqstate").style.color = "#ca2221";*/
		}
		if(date == "mm/dd/yyyy"){
			errors += "- A date of birth is required\n";
		} else {
			if(!validateDate(date)){
				errors += "- A valid date of birth is required\n";
			}
		}
		if(friendsNames1 == "email address" && friendsNames2 == "email address" && friendsNames3 == "email address") {
			errors += "- Your friend's email is required\n";
			/*document.getElementById("checkfriends").style.color = "#ca2221";*/
		} else {
			var emailArray = new Array();
			var emailCounter = 0;
			var validStatus = true;
			if (friendsNames1 != "email address") {
				emailArray[emailCounter] = friendsNames1;
				emailCounter++;
			}
			if (friendsNames2 != "email address") {
				emailArray[emailCounter] = friendsNames2;
				emailCounter++;
			}
			if (friendsNames3 != "email address") {
				emailArray[emailCounter] = friendsNames3;
			}
			for (i=0; i<emailArray.length; i++) {
				if(!validate(trim(emailArray[i]))) {
					validStatus = false;
				}
			}
			if(!validStatus) {
				errors += "- Valid friend's email is required\n";
			}
		}
		if(words > 150) {
			errors += "- 150-word limit.\n";
			document.getElementById("wordlimit").style.color = "#ca2221";
		}
		if (errors) {
			alert('The following error(s) occurred:\n'+errors);
		} else {
			// If state is Maine, then validate that age is not under 18 years old
			if(state == "ME"){
				var birthDate = new Date(date);
				var birthDay = birthDate.getDate();
				var birthMonth = birthDate.getMonth();
				var birthYear = birthDate.getFullYear();
				var age;
				currentDay = currentDate.getDate();
				currentMonth = currentDate.getMonth();
				currentYear = currentDate.getFullYear();
				if((currentMonth > birthMonth)||(currentMonth==birthMonth & currentDay>=birthDay)) {
					age = birthYear
				} else {
					age = birthYear + 1;
				}
				age = currentYear - age;
				if(age < 18) {
					eligibilityFlag = false;
				}
			} 
			if(eligibilityFlag) {
				if (window.XMLHttpRequest) {
					req = new XMLHttpRequest();
				} else if (window.ActiveXObject) {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				}
				if (req) {
					pageTracker._trackPageview('www.olayprofessional.com/emailThankYou/');
					req.onreadystatechange = handleResponse;
					URL_OLAY = '/sendemail.jsp?yourName='+yourName+'&email='+yourEmail+'&sendCopy='+sendCopy+'&subject='+subject+'&friendsNames1='+friendsNames1+'&friendsNames2='+friendsNames2+'&friendsNames3='+friendsNames3+'&message='+message+'&urlParam='+urlParam;
					//alert(URL_OLAY);
					req.open('GET',URL_OLAY, true);
					req.send(null);
				}
				
			} else {
				hidePop();
				SetCookie();
				showPop("files/friendmailerror.html");
			}
		}
	}
	function handleResponse() {
		if(req.readyState == 4) {
			//alert('req.readyState = '+req.readyState);
			var response = req.responseText;
			//document.forms["tellafriend"].yourName.value = "";
			//document.forms["tellafriend"].email.value = "";
			//document.forms["tellafriend"].sendCopy.value = "";
			//showPopup('/en-US/geton_filled.jsp');
			//alert(response);
			hidePop();
		}
	}
}
//end checkForm