function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

$(function() { 
		   
	
	$('#content').columnize({ width: 300 });
	$('.first.column').css('margin-right', '20px');
	$('.last.column').css('margin-left', '20px');
	$('hr').wrap('<div class="hrReplacement clearfix" />');
	equalHeight($(".matchArticleHeight"));
	$("#popupMap_E107QT_map").gMap({ markers: [{ latitude: 51.56563, longitude: -0.03598, popup: false }],zoom: 13 });
	$("#popupMap_E179DN_map").gMap({ markers: [{ latitude: 51.57901, longitude: -0.00529, popup: false }],zoom: 13 });
	$('#header_imgs').cycle();
});


$.validator.methods.equal = function(value, element, param) {
		return value == param;
	};
	
	//$("input[name=formSubmit]").click(function () {
	$().ready(function() {
		var validator = $("#regForm").bind("invalid-form.validate", function() {
			$("#summary").html("Your form contains " + validator.numberOfInvalids() + " errors, see details below.");
		}).validate({
			debug: true,
			errorElement: "em",
			errorContainer: $("#warning"),
			errorPlacement: function(error, element) {
				error.appendTo( element.parent("div").next("div") );
			},
			success: function(label) {
				label.addClass("success");
			},
			submitHandler:function(form) {
			$("#submitbutton").hide();
			$("#waiting").fadeIn(400);
					submitregform();
				},
			rules: {
					cstFirstName: "required",
					cstLastName: "required",
					cstEmail: {				// compound rule
						required: true,
						email: true
					},
					cstAddress1: "required",
					cstTown: "required",
					cstCounty: "required",
					cstPostcode: "required"
			}
		});
		
	});



function submitregform(){
	
	var cstFirstName = jQuery("#cstFirstName").val();
var cstLastName = jQuery("#cstLastName").val();
	var cstEmail = jQuery("#cstEmail").val();
	var cstAddress1 = jQuery("#cstAddress1").val();
	var cstAddress2 = jQuery("#cstAddress2").val();
	var cstTown = jQuery("#cstTown").val();
	var cstCounty = jQuery("#cstCounty").val();
	var cstPostcode = jQuery("#cstPostcode").val();
	
	var encodedFirstName = encodeURIComponent(cstFirstName);
var encodedLastName = encodeURIComponent(cstLastName);  
	var encodedEmail = encodeURIComponent(cstEmail); 
	var encodedAddress1 = encodeURIComponent(cstAddress1);
	var encodedAddress2 = encodeURIComponent(cstAddress2); 
	var encodedTown = encodeURIComponent(cstTown);
	var encodedCounty = encodeURIComponent(cstCounty);
	var encodedPostcode = encodeURIComponent(cstPostcode);
	
	var dataString = 'cstFirstName='+ encodedFirstName + '&cstLastName='+ encodedLastName + '&cstEmail='+ encodedEmail + '&cstAddress1='+ encodedAddress1 + '&cstAddress2='+ encodedAddress2 + '&cstTown='+ encodedTown + '&cstCounty='+ encodedCounty + '&cstPostcode='+ encodedPostcode + '';

	
	$.ajax({
		type:"POST",
		url: "includes/voucherForm.asp",
		dataType: "application/x-www-form-urlencoded",
		data: dataString,
		async: false,
		success: function(){
			
			window.setTimeout(function() {
			 $(".formfield").hide();
$("#waiting").hide();
			$("#thanks").fadeIn(400);
			
			}, 2000);
			
			
	}
	
	})
}

