var emfForm;
var emailFilter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function EMF() {
	emfForm = document.getElementById("emailafriend_block");
			
	if ((emfForm.to.value == null) || (emfForm.to.value.length == 0)) {
		alert('Please enter the recipient\'s name');
		emfForm.to.focus();
	}	
	
	else if ((emfForm.toaddress.value == null) || (emfForm.toaddress.value.length == 0)) {
		alert('Please enter the recipient\'s email address');
		emfForm.toaddress.focus();
	}
	
	else if (emailFilter.test(emfForm.toaddress.value) == false){
		alert('Recipient\'s email address is invalid, please re-enter');
		emfForm.toaddress.focus();
	}

	else if ((emfForm.from.value == null) || (emfForm.from.value.length == 0)) {
		alert('Please enter your name');
		emfForm.from.focus();
	}
	
	else if ((emfForm.fromaddress.value == null) || (emfForm.fromaddress.value.length == 0)) {
		alert('Please enter your email address');
		emfForm.fromaddress.focus();
	}

	else if (emailFilter.test(emfForm.fromaddress.value) == false){
		alert('Your email address is invalid, please re-enter');
		emfForm.fromaddress.focus();
	}
	
	else if ((emfForm.message.value == null) || (emfForm.message.value.length == 0)) {
		alert('Please enter your message');
		emfForm.message.focus();
	}
	
	else if (emfForm.message.value.length > 1000) {
		alert('Your message must not exceed 1000 characters');
		emfForm.message.focus();
	}
	
	else if ((emfForm.recaptcha_response_field.value == null) || (emfForm.recaptcha_response_field.value.length == 0)) {
	    alert("A 'Captcha' system is in place for security reasons.\nPlease enter the two words appearing about the Submit button");
		emfForm.recaptcha_response_field.focus();
	}
	
	else {    	
	    // error checking done
    	
	    var parms = new Array();
	    parms[0] = emfForm.recaptcha_challenge_field.value;
	    parms[parms.length] = emfForm.recaptcha_response_field.value;
    		
	    jsrsExecute("/common/comm/emailAFriend/v1/server.asp", EMFCallBack, "recaptcha_submit_challenge", parms, false);
	}
}

function EMFCallBack(str) {
    if(str != ""){
        alert("Words did not match the display. Please try again.\nUse the refresh button, on the right, to get two fresh Captcha words.");
        Recaptcha.reload();
    }
    else{
        if(typeof emfForm != "object"){
            emfForm = document.getElementById("emailafriend_block");
        }
        emfForm.submit();
    }
}