function validateAjaxEmail(emailid,statusid) {
	status=document.getElementById(statusid).value;
	if(status==3 || status=='') {
		return true;
	} else if(status==-1) {
		alert("Please wait for the email to be validated.");
	} else if(status==2 || status==1 || status==0) {
		alert("Please enter a valid email.");
	}
	document.getElementById(emailid).select();
	return false;
}
/*
emailid - email address to validate (form field)
emailbackgroundcolor - backgroundcolor for emailid
emailvalidrating (hidden field)
emailvalidmessage (hidden field)
emaildatevalidated (hidden field)
emailmsg - same as emailvalidmessage, but in visible DIV
*/
function ajaxUpdateStatus(emailid,emailbackgroundcolor,rating,message,messagehtml) {
	document.getElementById(emailid+'validrating').value=rating;
	document.getElementById(emailid+'validmessage').value=message;
	document.getElementById(emailid).style.backgroundColor=emailbackgroundcolor;
	document.getElementById(emailid+'msg').innerHTML=messagehtml;
	//if(datevalidated && datevalidated !='') {
		//document.getElementById(emailid+'datevalidated').value=datevalidated;
	//}
}
function ajaxEmail(ajaxemail,emailid,baseurl) {
	if(!baseurl) {
		baseurl='/';
	}
	//Refresh link that comes after the validation message
	if(baseurl=='') {
		refreshtext=' <span class="smalltext">(<a href="javascript:ajaxEmail(\''+ajaxemail+'\',\''+emailid+'\')">Refresh</a>)</span>'
		
	} else {
		refreshtext=' <span class="smalltext">(<a href="javascript:ajaxEmail(\''+ajaxemail+'\',\''+emailid+'\',\''+baseurl+'\')">Refresh</a>)</span>'	
	}
	//Compare ajaxemail with trim version
	ajaxemailtemp=ajaxemail;
	ajaxemail=trimVar(ajaxemail);
	//If email field is blank, remove color and message
	if(ajaxemail=='') {
		ajaxUpdateStatus(emailid,'#FFFFFF','','','','');
		return;
	} else {
		//Check if valid email format - if not valid, mark with invalid color
		if(!validEmailFormat(ajaxemail)) {
			ajaxUpdateStatus(emailid,'#FFCCFF','','','','');
		} else {
			//if valid format, update email with trimmed email, if different, then proceed to validate live email account
			if(ajaxemailtemp!=ajaxemail) {
				document.getElementById(emailid).value=ajaxemail;
			}
			//Set message to Validating..
			ajaxUpdateStatus(emailid,'#FFCCFF',-1,'Validating..','<img src="/images/emailvalidating.gif" width="10" height="10" border="0" style="padding-right:.5em"> Validating..'+refreshtext,'');
			try{
		   		xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
		  		new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				//Cannot validate. Browser does not support AJAX.
				ajaxUpdateStatus(emailid,'#FFFFFF','','','','');
		 	}
		 	xmlhttp.onreadystatechange = function() {
				//If get valid http response
				if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
					results=xmlhttp.responseText.split('|');
					if(!results.length || results.length !=2 || results[0].length !=1) {
						//Unable to validate (because error with .cfm page)
						ajaxUpdateStatus(emailid,'#FFFFFF','','','','');
					} else {
						if(results[0]==3) {
							// Valid
							ajaxUpdateStatus(emailid,'#CCFFCC',results[0],results[1],'<img src="/images/emailvalid.gif" width="10" height="10" border="0" style="padding-right:.5em"> '+results[1]+refreshtext);
						} else {
							// Invalid
							ajaxUpdateStatus(emailid,'#FFCCFF',results[0],results[1],'<img src="/images/emailnotvalid.gif" width="10" height="10" border="0" style="padding-right:.5em"> Invalid: '+results[1]+refreshtext);
						}
					}
				} else {
					//valid request not returned (yet)
			   }
			}
			//Add random number to query string to prevent cached results
		 	xmlhttp.open("GET",baseurl+'ajaxemail.cfm?email='+escape(ajaxemail)+'&random='+Math.random(),true);
		 	xmlhttp.send(null);
		}
	}
}
function ajaxEmail2(ajaxemail2,emailid2,baseurl2) {
	if(!baseurl2) {
		baseurl2='/';
	}
		
	//Refresh link that comes after the validation message
	if(baseurl2=='') {
		refreshtext2=' <span class="smalltext">(<a href="javascript:ajaxEmail(\''+ajaxemail2+'\',\''+emailid2+'\')">Refresh</a>)</span>'
		
	} else {
		refreshtext2=' <span class="smalltext">(<a href="javascript:ajaxEmail(\''+ajaxemail2+'\',\''+emailid2+'\',\''+baseurl2+'\')">Refresh</a>)</span>'	
	}
	//Compare ajaxemail with trim version
	ajaxemailtemp2=ajaxemail2;
	ajaxemail2=trimVar(ajaxemail2);
	//If email field is blank, remove color and message
	if(ajaxemail2=='') {
		ajaxUpdateStatus(emailid2,'#FFFFFF','','','','');
		return;
	} else {
		//Check if valid email format - if not valid, mark with invalid color
		if(!validEmailFormat(ajaxemail2)) {
			ajaxUpdateStatus(emailid2,'#FFCCFF','','','','');
		} else {
			//if valid format, update email with trimmed email, if different, then proceed to validate live email account
			if(ajaxemailtemp2!=ajaxemail2) {
				document.getElementById(emailid2).value=ajaxemail2;
			}
			//Set message to Validating..
			ajaxUpdateStatus(emailid2,'#FFCCFF',-1,'Validating..','<img src="/images/emailvalidating.gif" width="10" height="10" border="0" style="padding-right:.5em"> Validating..'+refreshtext2,'');
			try{
		   		xmlhttp2 = window.XMLHttpRequest?new XMLHttpRequest():
		  		new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				//Cannot validate. Browser does not support AJAX.
				ajaxUpdateStatus(emailid2,'#FFFFFF','','','','');
		 	}
		 	xmlhttp2.onreadystatechange = function() {
				//If get valid http response
				if ((xmlhttp2.readyState == 4) && (xmlhttp2.status == 200)) {
					results2=xmlhttp2.responseText.split('|');
					if(!results2.length || results2.length !=2 || results2[0].length !=1) {
						//Unable to validate (because error with .cfm page)
						ajaxUpdateStatus(emailid2,'#FFFFFF','','','','');
					} else {
						if(results2[0]==3) {
							// Valid
							ajaxUpdateStatus(emailid2,'#CCFFCC',results2[0],results2[1],'<img src="/images/emailvalid.gif" width="10" height="10" border="0" style="padding-right:.5em"> '+results2[1]+refreshtext2);
						} else {
							// Invalid
							ajaxUpdateStatus(emailid2,'#FFCCFF',results2[0],results2[1],'<img src="/images/emailnotvalid.gif" width="10" height="10" border="0" style="padding-right:.5em"> Invalid: '+results2[1]+refreshtext2);
						}
					}
				} else {
					//valid request not returned (yet)
			   }
			}
			//Add random number to query string to prevent cached results
		 	xmlhttp2.open("GET",baseurl2+'ajaxemail.cfm?email='+escape(ajaxemail2)+'&random='+Math.random(),true);
		 	xmlhttp2.send(null);
		}
	}
}
function validEmailFormat(rawemail) {
	filter = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-_0-9]+\.)+[a-zA-Z]{2,}))$/
	return (filter.test(rawemail) && rawemail.substring(rawemail.length,rawemail.length-3) !='.co')
}
function trimVar(cleaned) {
	//remove beginning and ending spaces and white space characters
	return cleaned.replace(/^[ ]*([^ ]*)[ ]*$/, "$1").replace(/\s*/, "");
}