// JavaScript Document
function setFormAllowCookie() {
        var cookieName = "f_a";
        var cookieValue = "true";
        document.cookie= cookieName + "=" + escape(cookieValue) + "; domain=mosaicproject.org; path=/";
        return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		//no @
		if (lat==-1){
		   return false
		}

		//@ can't be first, last or one from last
		if (lat==0 || lat==lstr || lat==lstr-1 ){
		   return false
		}

		//dot can't be not found, first, last, or one from last, or two from last
		if (ldot==-1 || ldot==0 || ldot==lstr || ldot==lstr-1 || ldot==lstr-2 ){
		    return false
		}
		
		//more than one @	
		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 //dot is right before or after @
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }
		
		 //dot must be at least two chars after @
		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		//must not have spaces
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}


function mailinglist_form_validator(theForm) {
	if (theForm.firstname.value == "") { 
	 	alert("Please enter a value for the \"First Name\" field."); 
		theForm.firstname.focus();
		return (false); 
	}   
	if (theForm.lastname.value == "") { 
		alert("Please enter a value for the \"Last Name\" field.");
		theForm.lastname.focus(); 
		return (false); 
	}   
	if (echeck(theForm.email.value)==false){
		alert('Please enter a valid email address');
		theForm.email.focus()
		return false
	}
	return (true); 
} 