var emfForm;
var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function EMF(theForm) {
	emfForm = theForm;
			
	if ((theForm.to.value == null) || (theForm.to.value.length == 0)) {
		alert('Please enter the recipient\'s name');
		theForm.to.focus();
		return false;
	}
	
	if ((theForm.toaddress.value == null) || (theForm.toaddress.value.length == 0)) {
		alert('Please enter the recipient\'s email address');
		theForm.toaddress.focus();
		return false;
	}
	
	if (emailFilter.test(theForm.toaddress.value) == false){
		alert('Recipient\'s email address is invalid, please re-enter');
		theForm.toaddress.focus();
		return false;
	}

	if ((theForm.from.value == null) || (theForm.from.value.length == 0)) {
		alert('Please enter your name');
		theForm.from.focus();
		return false;
	}
	
	if ((theForm.fromaddress.value == null) || (theForm.fromaddress.value.length == 0)) {
		alert('Please enter your email address');
		theForm.fromaddress.focus();
		return false;
	}

	if (emailFilter.test(theForm.fromaddress.value) == false){
		alert('Your email address is invalid, please re-enter');
		theForm.fromaddress.focus();
		return false;
	}
	
	if ((theForm.message.value == null) || (theForm.message.value.length == 0)) {
		alert('Please enter your message');
		theForm.message.focus();
		return false;
	}
	
	// error checking done
	
	var parms = new Array();
	parms[parms.length] = theForm.codiv.value;
	parms[parms.length] = theForm.from.value;
	parms[parms.length] = theForm.fromaddress.value;
	parms[parms.length] = theForm.to.value;
	parms[parms.length] = theForm.toaddress.value;
	parms[parms.length] = theForm.itemdesc.value;
	parms[parms.length] = theForm.link.value;
	parms[parms.length] = theForm.message.value;
		
	jsrsExecute("/common/comm/emailAFriend/server.asp", EMFCallBack, "EMF", parms, false);
	
	return false;
}

function EMFCallBack(str) {
	alert(str);
	if (str.substr(0, 5) != 'ERROR') {
		emfForm.reset();
		EMFToggle('layer_EMF');
	}
}
