// JavaScript Document

function SendMail() // get the real email contact addess for use with mail clients
{	
	$.get("bin/fetchmail.php", function(data){
	   var str = data;
       var left = str.substr(0, str.indexOf("FECK OFF"));
       var right = str.substr(str.indexOf("@"));
	   window.location = "mailto:"+left+right;
	});
	return false;
}

function CaptchaSuccess() // using the email form, so validate inputs before proceeding
{
	// verify details first
	var b = $("textarea#body").val();
	var addy = $("input#addy").val();
	if (addy.length>0)
	{
		if (!IsValidEmail(addy))
		{
			alert("You have entered an invalid email address.  If you do not wish to receive a reply, please leave this field blank");
			return false;
		}
	}
	
	if (b.length<3)
	{
		alert("Your message does not appear to be a valid message.  Please rectify this before sending");
		return false;
	}
	if (IsSpam(b))
	{
		alert("You may not enter website addresses into your message.  If you are a spammer, please kill yourself immediately");
		return false;
	}
	
	$.ajax( {
		type: "POST",
		url: "bin/SendMail.php",
		data: $("form[name='contactForm']").serialize(),
		success: function(data)
				{
					if (data=="success")
						alert("Your message has been sent");
					else
					{
						alert("Unfortunately your message failed to send.  This is likely due to a server problem.  Please try again");
						//alert(data);
					}
				}
		} ); // end of ajax request
}

function CaptchaFail()
{
	alert("You have chosen the incorrect image.  You are human, aren't you?");
}
