// JavaScript Document

 //on submit this function is called

function submitEmail() {
	var field = document.emailcapture.EM;     
	var str = field.value;        
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; 
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; 

	//check if the email is valid
	if (!reg1.test(str) && reg2.test(str)) {                     
		//post the lead info to the formpost page in poptionaloffers which writes to the database
		document.subImage.src='http://www.poptionaloffers.com/learningemail/emailcapture.jsp?CLK='+document.emailcapture.CLK.value+ '&EM=' + document.emailcapture.EM.value +'&A1=' + document.emailcapture.A1.value + '&A2=' + document.emailcapture.A2.value + '&submit=submit';                   
		document.getElementById('optinemail').className = 'optinthide'; 
		document.getElementById('optinthankyou').className = 'optintshow'; 
		document.getElementById('asgtext').value = '';
	} else {
		//throw an error message
		alert("Please enter a valid e-mail address.");
		document.getElementById('asgtext').select();
	}
}

function clearField(){
	document.forms.emailcapture.EM.value='';
}

function pressKey (e) {
	var code;
	
	if (!e) 
		var e = window.event;

	if (e.keyCode) 
		code = e.keyCode;
	
	else if (e.which) 
		code = e.which;
	
	if (code != 13) {
		return true;
	} else {
		submitEmail ();
		return false;
	}
}