
// no comment

function trim(text){
	text = text.replace(/^\s+/, "");
	text = text.replace(/\s+$/, "");
	text = text.replace(/\s+/g, " ");
	return text;
}

function saveSubscriber(){		

	var objForm = document.getElementById("itlForm");
	
	if (trim(objForm.n.value).length < 2 || objForm.n.value == "Name"){
		alert("Please enter your first name.");
		objForm.n.value = trim(objForm.n.value);
		objForm.n.focus();
		return false;
	}
	
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(trim(objForm.e.value)))){
		alert("Please enter a valid email address for yourself.");
		objForm.e.value = trim(objForm.e.value);
		objForm.e.focus();
		return false;
	}
	
	new Ajax.Request('code/includes/save_subscriber.asp?_r=' + Math.random(), {method: 'post', parameters: $('itlForm').serialize(true), evalScripts: true, onComplete: completeSaveEmail});
	
}
		
function completeSaveEmail(transport){
	response = transport.responseText;
	
	$('itlForm').reset();
	
	if (response == "ok"){
		$('alertContents').innerHTML = 'Thank you - you will receive the next edition of In The Loop.';
	}else{
		$('alertContents').innerHTML = 'An error occurred trying to subscribe you to the newsletter.';
	}
	
}

