$(document).ready(function() {
	
	$("#AlertMsgWrap").hide();
	$("#Contact_LoadingTxt").hide();
	
	$("form#ContactForm").livequery('submit', function() {
		
		var loadingTxt = "Loading, Please Wait...";
		$("#Contact_SubmitBtn").hide();
		$("#Contact_LoadingTxt").empty()
															.append(loadingTxt)
															.show();
		var errorMsg = "";
		
		var valid = false;
		
		if ($("input#name").val() == "") {
			errorMsg = "Please provide your name.";
		} else if ($("input#email").val() == "") {
			errorMsg = "Please provide your email address.";
		} else if ($("#message").val() == "") {
			errorMsg = "You didn't provide a message to send!";
		} else {
			valid = true;
		}
		
		if (valid) {
			var FormData = $("form#ContactForm").serialize();

			$.ajax({
				type: "POST",
				url: "/index/contact",
				data: FormData,
				success: function(html){
					var pos = html.indexOf("yes");
					if (pos >= 0) {

						var msg = "<div style='color:black; font-weight:bold;'>Your message has been successfully sent. Thank You!</div>";
						$("#AlertMsgWrap").hide();
						$("#alertMsg_public").empty()
																 .append(msg);

						$("#ContactFormWrap").slideUp(1000, function() {
							$("#AlertMsgWrap").slideDown(1000);
						});


					} else {

						$("#AlertMsgWrap").show();
						$("#alertMsg_public").empty()
																 .append(html);	

						$("#Contact_LoadingTxt").empty()
																			.hide();
						$("#Contact_SubmitBtn").show();												
					}

				}
			});
		} else {
			
			$("#AlertMsgWrap").show();
			$("#alertMsg_public").empty()
													 .append(errorMsg);

			$("#Contact_LoadingTxt").empty()
																.hide();
			$("#Contact_SubmitBtn").show();
			
		}
		
		
		return false;
		
	});
	
});

