String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};

var isSpam = true;
var words = "no spam,spam free,not spam,i am human,isnt spam,spam free,no spam here".split(",");
var word = getRandom(words);

$(function() {
	
	$("#Country").load("countries.htm");
	
	$("#SpamWord").bind("keypress", function() {
		isSpam = false;
	});

	$("#spam-word").html("Type '"+ word +"' in the box below");
	
	$("#RegisterForm").bind("submit", function() {
	
		$(this).attr("action", "http://holylandphotos.createsend.com/t/1/s/otrll/");
		var name = $("#Name").val();
		var email = $("#Email").val();
		var spamWord = $("#SpamWord").val();
		
		var e = [];
		if (name.trim() == "")
			e.push("Name is required");
			
		if (email.trim() == "")
			e.push("Email is required");
			
		if (spamWord.trim().toLowerCase() != word || isSpam)
			e.push("Please type '"+ word +"' into the box specified");
			
		if (e.length > 0)
		{
			alert("Oops. Please fix the following\n - "+ e.join("\n - "));
			return false;
		}
		return true;
	});
});

function getRandom(a) {
	return a[Math.floor(Math.random()*a.length)];
}
