$(function() {
	var formHeight = $("#regForm").height();
	var messageHeight = $("#importantMessage").height();
	$("#loading").css("height",formHeight - messageHeight - 20);
		   
	$("#regForm").submit(function(){
									  									  									  	
		var str = $(this).serialize();
		
		$("#loading").fadeIn(500);
						
		$.ajax({
			type: "POST",
			url: "public/inc/regProcess.php",
			data: str,
			success: function(data){
			
				$("#contactAlert").ajaxComplete(function(event, request, settings)
				{
					
					if(data == 'OK') // Message Sent? Show the 'Thank You' message and hide the form
					{
						result = '<h5>Thank you for your registration. You will receive a confirmation email shortly.</h5><div class="success"><p>If you wish to register another Tribal Extreme Rod, please <a href="index.php">click here</a></p></div>';
						$("#regForm").hide();
					}
					else if(data == 'DUPE')
					{
						result = '<h6>Thank you for attempting to register your Shimano product. Unfortunately a rod with this number has already been registered. Please check your Rod Number and retry, or contact support at Shimano at <a href=\"mailto:fishinginfo@shimano-eu.com?subject=Tribal%20Extreme%20Rod%20Registration%20Error%20-%20Duplicate%20Rod\">fishinginfo@shimano-eu.com</a>.</h6>';
					}
					else
					{
						result = data;
					}
				
					$(this).html(result);
					$("#loading").fadeOut(500);
				
				});
			
			}
		
		});
		
		return false;
	
	});

});
