$(document).ready(function(){
	$("#submit").click(function(){
		$("#submit").hide();
		$("#submitLoader").show();
		$("#response").hide();
		
		if (jQuery.trim($("#password").val()) != jQuery.trim($("#password2").val()))
		{
			$("#response").html("Your passwords do not match. Please try again.");
			$("#response").attr("class", "error_message");
			$("#response").fadeIn("slow");
			$("#submit").show();
			$("#submitLoader").hide();
		}
		else
		{
			var args = $("#signup").serialize();
			$.ajax({
				url: "../data/insert.php",
				type: "POST",
				data: args,
				dataType: "json",
				error: function(html)
				{
					$("#response").html("Oops! Something horrible happened. Please refresh your page and try again.");
					$("#response").attr("class", "error_message");
					$("#response").fadeIn("slow");
					$("#submit").show();
					$("#submitLoader").hide();
				},
				success: function(html)
				{
					$("#submit").show();
					$("#submitLoader").hide();
					if (html.result == "success")
					{
						$("#response").html("Thanks for signing up with TasteLive! Your account has been created. Please login by clicking <a href='login'>here</a> or the link on the top right of the page.");
						$(".subwrap_profile").hide();
						$("#response").attr("class", "success_message");
						$("#response").fadeIn("slow");
						$("#password").val('');
						$("#username").val('');
						$("#full_name").val('');
						$("#email_addr").val('');
					}
					else
					{
						$("#response").html(html.msg);
						$("#response").attr("class", "error_message");
						$("#response").fadeIn("slow");
						/*$("#password").val('');
						$("#username").val('');
						$("#full_name").val('');
						$("#email_addr").val('');*/
					}
				}
			});
		}

		return false;
	});
});