$(document).ready(function() {


$("#changeVerification").click(function() {
	// in the event the user has a prob this changes the image and refreshes the image validation string in the sessiobn
	// have to add a variable number to stop STUPID IE and FF using the cached image. STOOOPID.
	var randomnumber=Math.floor(Math.random()*10001);
//	alert($("#verficationImage").attr('src'));
	$("#verficationImage").attr('src', 'verification.php?'+randomnumber);
});


	$("#submit").click(function() {
		var verified;
		// I've made the ajax syncronous to wait for the validation result!
		$("#registerwarning").text("");
		
		$.ajax({
          url: 'hat_register_ajax.php',
		  async: false, 
          //data: 'action=check_capture&capture=' + $("#capture").val(),
		  data: $("form.#registerform").serialize(),
          dataType: 'json',
          type: 'post',
		  cache: false,
          success: function (j) {

			if (j.result == "true") {
				$("#registerwarning").text('Success!!').show();
				$("#signup").hide();
				
				if ($("#status").val() == 'wait') {
					$("#waitConfirm").show();
				}
				else {
					$("#payment").show();
				}
				
				// confirm values
				$("#totalcost").text(j.total);
				$("#discs").text(j.numberDiscs);
				
				// Google checkout values
				$("#item_name_1").val(j.leadID);
				$("#item_description_1").val("DUFFA Hat 2011 Registration Fee for " + $("#noPlayer").val() + " player(s)");
				$("#item_price_1").val(j.total);
				// Cheque values
				$("#cqreference").text(j.leadID);
				
				verified = 1;
				return true;
			}
			else {
			//	$("#registerwarning").text(j.msg).show();
				$("#registerwarning").html(j.msg).show();
				verified = 0;
				return false;
			}
          }
        });

//		if (verified==1) {
			//alert('I am true');
//			return true;
//		}

//		else {
		//	alert('I am false');
//			return false;
//		}
		});
	});
