var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
var form;

function emptyBox(theBox) {
	if ((theBox.value == null) || (theBox.value.length == 0))
		return true
	else
		return false
}

function emailSelect(theForm) {

	if (theForm.submissiontype[0].checked == false && theForm.submissiontype[1].checked == false) {
		alert('Please select subscribe or unsubscribe');
		return false;
	}

	if (theForm.submissiontype[0].checked == true) {
		return emailSignup(theForm);
		}
	else if (theForm.submissiontype[1].checked == true) { 
		return emailSignupRemove(theForm);
	}

}

function emailSignup(theForm) {
	
	if (emptyBox(theForm.emailAddress)) {
		alert('Please enter your email address');
		return false;
	}
	
	if (emailFilter.test(theForm.emailAddress.value) == false) {
		alert('Your email address is invalid, please re-enter');
		return false;
	}
	
	if (emptyBox(theForm.Store)) {
		alert('Process setup incorrectly');
		return false;
	}
		
	var parms = new Array();
	parms[parms.length] = theForm.emailAddress.value;
	parms[parms.length] = theForm.Store.value;
	parms[parms.length] = window.location.hostname;
			
	jsrsExecute("/common/comm/emailSignup/server.asp", emailSignupCallBack, "emailSignup", parms, false);
	
	form = theForm;
	
	return false;
}

function emailSignupCallBack(str) {
	
	if (str.substr(0, 5) != 'ERROR')
		form.reset();
		
	alert(str);		
}

function emailSignupRemove(theForm) {
		
	if (emptyBox(theForm.emailAddress)) {
		alert('Please enter your email address');
		return false;
	}
	
	if (emailFilter.test(theForm.emailAddress.value) == false) {
		alert('Your email address is invalid, please re-enter');
		return false;
	}
	
	if (emptyBox(theForm.Store)) {
		alert('Process setup incorrectly');
		return false;
	}
		
	var parms = new Array();
	parms[parms.length] = theForm.emailAddress.value;
	parms[parms.length] = theForm.Store.value;
	parms[parms.length] = window.location.hostname;
			
	jsrsExecute("/common/comm/emailSignup/server.asp", emailSignupCallBack, "emailRemove", parms, false);
	
	form = theForm;
	
	return false;
}
