jQuery.fn.center = function () {
    this.css("position","absolute");
    this.css("top", (($(window).height() - this.outerHeight()) / 2) + $(window).scrollTop() + "px");
    this.css("left", (($(window).width() - this.outerWidth()) / 2) + $(window).scrollLeft() + "px");
    return this;
}

function sendEmail(){
	
}

function contact(){
	$("#feedback").show();
	$("#feedback").center();
	
	var params = "&name=" + encodeURIComponent($("#txtName").val());
	params += "&email=" + encodeURIComponent($("#txtEmail").val());
	params += "&phone=" + encodeURIComponent($("#txtPhone").val());
	params += "&msg=" + encodeURIComponent($("#txtMsg").val());
	
	var interests = "";
	if($("#chkKickboxing").is(':checked')){
		interests += "kickboxing,";
	}
	if($("#chkKungFu").is(':checked')){
		interests += "kungfu,";
	}
	if($("#chkTaiChi").is(':checked')){
		interests += "taichi,";
	}
	if($("#chkSelfDefense").is(':checked')){
		interests += "selfdefense,";
	}
	if($("#chkDvd").is(':checked')){
		interests += "dvd,";
	}

	params += "&interests=" + encodeURIComponent(interests);
	
	$.ajax({
		type: "POST",
		url: "index.php?id=31",
		data: params,
		async: false,
		success: function(response) {
			if(response == "") {
				alert("Error ocurred while attempting to send message.");
				return;
			}
			
			//For some weird reason, the production site is html-ifying our json response.
			response = response.replace("<p>", "");
			response = response.replace("</p>", "");
			
			var result = eval("(" + response + ")");
			if(result["error"] != undefined){
				alert(result['error']);
			} else {
				//Clear form contents...
				$("#txtName").val("");
				$("#txtEmail").val("");
				$("#txtPhone").val("");
				$("#txtMsg").val("");
				$("#chkKickboxing").attr("checked", false);
				$("#chkKungFu").attr("checked", false);
				$("#chkTaiChi").attr("checked", false);
				$("#chkSelfDefense").attr("checked", false);
				$("#chkDvd").attr("checked", false);
				
		    	$("#thankYouDlg").dialog({
		    		autoOpen: true,
					width : 500,
					height : 350,
					resizable : false,
					scrollable: false,
					title: "Thank You!",
					buttons : {
						Close : function() {
							$(this).dialog('close');
						}
					},
					modal : true
		    	});
			}
		},
        error: function(xhr, errorStatus, err) { handleAjaxError(xhr) }
	});
	
	$("#feedback").hide();
}

