function registerPlak() {
	if (document.getElementById('reg_name').value.length == 0) {
		alert("Please supply your name.");
	} else if (document.getElementById('reg_name').value.length > 40) {
		alert("Sorry, your name is limited to 40 characters.");
	} else if (document.getElementById('reg_email').value.length == 0) {
		alert("Please supply a valid email address.");
	} else if (document.getElementById('reg_email').value.length > 60) {
		alert("Sorry, the email address is limited to 60 characters.");
	} else if(!validate_email(document.getElementById('reg_email').value)) {
		alert("The supplied email address seems to be invalid.");
	} else if (document.getElementById('reg_password1').value.length == 0) {
		alert("Please supply a password.");
	} else if (document.getElementById('reg_password2').value.length == 0) {
		alert("Please supply your password again.");
	} else if (document.getElementById('reg_password1').value.length > 40) {
		alert("Sorry, the password is limited to 40 characters.");
	} else if(document.getElementById('reg_password1').value != document.getElementById('reg_password2').value) {
		alert("The two passwords do not match.");
	} else if (document.getElementById("captchaRegText").value.length == 0) {
		alert("Please enter the captcha text to prove that you are not a bot.");
	} else if (!document.getElementById("haveread").checked) {
		alert("If you have not read the information on this page, and/or do not agree with it, then you can't register on Plak.");
	} else {
		document.getElementById('register').disabled = true;
		AJAXCall('register', encodeURI("name=" + document.getElementById('reg_name').value + "&email=" + document.getElementById('reg_email').value + "&pword=" + document.getElementById('reg_password1').value + "&captcha=" + document.getElementById("captchaRegText").value), 'registered(rep)');
	}
}

function resendEmail() {
	if (document.getElementById('reg_email').value.length == 0) {
		alert("Please supply a valid email address.");
	} else if(!validate_email(document.getElementById('reg_email').value)) {
		alert("The supplied email address seems to be invalid.");
	} else if (document.getElementById("captchaRegText").value.length == 0) {
		alert("Please enter the captcha text to prove that you are not a bot.");
	} else {
		document.getElementById('resend').disabled = true;
		AJAXCall('resend', encodeURI("email=" + document.getElementById('reg_email').value + "&captcha=" + document.getElementById("captchaRegText").value), 'registered(rep)');
	}
}


function registered(object) {
	document.getElementById('register').disabled = false;
	document.getElementById('resend').disabled = false;
	if(object[0] == "ok") {
		document.getElementById('reg_name').value = "";
		document.getElementById('reg_email').value = "";
		document.getElementById('reg_password1').value = "";
		document.getElementById('reg_password2').value = "";
		document.getElementById('captchaRegText').value = "";
	}
	var reply = object[1];
	reply = reply.replace("++", "\r\n")
	alert(reply);
}

function validate_email(s) {
	var regexp  = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/
	return regexp.test(s);
}
