function loader() {

	var searchString = document.location.search;



	// strip off the leading '?'

	searchString = searchString.substring(1);



	var nvPairs = searchString.split("&");



	for (i = 0; i < nvPairs.length; i++)

	{

		 var nvPair = nvPairs[i].split("=");

		 var name = nvPair[0];

		 var value = nvPair[1];

	}

	//document.write(value);

	if (value) {

		makerequest('guestbook/thank.php', 'content');

	}

}

	
function key(number) {
	return Math.floor(Math.random() * number);
}

function echeck(str) {

	var at = "@";
	var dot = ".";
	var lat = str.indexOf(at);
	var lstr = str.length;
	var ldot = str.indexOf(dot);
	
	if (str.indexOf(at) ==- 1) { return false; }
	if (str.indexOf(at) ==- 1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) { return false; }
	if (str.indexOf(dot) ==- 1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) { return false; }
	if (str.indexOf(at, (lat + 1)) !=- 1) { return false; }
	if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) { return false; }
	if (str.indexOf(dot, (lat + 2)) ==- 1) { return false; }
	if (str.indexOf(" ") !=- 1 ) { return false; }
	 
	return true;
}
	

function validate() {

	

	// first_name

	if (document.getElementById("first_name").value.length < 1) {

		alert("Please enter a valid first name.");

		document.getElementById("first_name_label").style.color = "red";

		document.getElementById("first_name").focus();

		return false;

	} else {

		document.getElementById("first_name_label").style.color = "black";

	}

	

	// last_name

	if (document.getElementById("last_name").value.length < 1) {

		alert("Please enter a valid last name.");

		document.getElementById("last_name_label").style.color = "red";

		document.getElementById("last_name").focus();

		return false;

	} else {

		document.getElementById("last_name_label").style.color = "black";

	}

	

	// email_address_1 (validate)

	if (echeck(document.getElementById("email_address_1").value) == false) {

		alert("Please enter a valid email address.");

		document.getElementById("email_address_1_label").style.color = "red";

		document.getElementById("email_address_1").focus();

		return false;

	} else {

		document.getElementById("email_address_1_label").style.color = "black";

	}

	

	// email_address_2 (match)

	if (document.getElementById("email_address_2").value != document.getElementById("email_address_1").value) {

		alert("Your email addresses do not match.");

		document.getElementById("email_address_2_label").style.color = "red";

		document.getElementById("email_address_2").focus();

		return false;

	} else {

		document.getElementById("email_address_2_label").style.color = "black";

	}

	

	/*if (!document.getElementById("agree").checked) {

		alert("Please read our terms and conditions and tick the checkbox if you agree with them.");

		return false;

	}*/

			

	// comment

	if (document.getElementById("comment").value.length < 1) {

		alert("Please enter a valid comment.");

		document.getElementById("comment_label").style.color = "red";

		document.getElementById("comment").focus();

		return false;

	} else {

		document.getElementById("comment_label").style.color = "black";

	}

	

	/*if (document.getElementById("txtCaptcha").value.length == 5) {
		$.ajax({
			type	: "POST",
			url		: "/guestbook/captcha/captcha.php",
			data	: "txtCaptcha=" + document.getElementById("txtCaptcha").value + "&key=" + key(10000),
			success	: function(html){
				$("#result").empty();
				$("#result").append(html);
				
				if (html == "FAIL") {
					alert("The code you entered was incorrect. Please try again.");
					$("#imgCaptcha").attr("src", "/guestbook/captcha/image.php?key=" + key(10000));
				} else {
					document.register.submit();
				}
			}
		});
		return false;
	} else {
		alert("Please enter the exact code on the image into the text box and try again.");
		document.getElementById("txtCaptcha").focus();
		return false;
	}*/

	

}