/* Author: Albert Sun
 */

/*jslint devel: true, bitwise: true, browser: true, confusion: true, undef: true, unparam: true, eqeq: true, vars: true, white: true, nomen: true, plusplus: true */
/*global jQuery: false, $: false, log: false, window: false, _: false, google: false, localStorage: false */

// Necessary functions
if (!window.typeOf) { window.typeOf = function(b){var a=typeof b;if(a==="object")if(b){if(b instanceof Array)a="array"}else a="null";return a}; }

// ***************************************
// Just in case there's a console.log hanging around....
// ***************************************
if (!window.console) { window.console = { "log": jQuery.noop }; }


$(document).ready(function() {
    function handleForm(responsetext, statustext, xhrobj) {
	console.log("submit success");
	$("#comments_wrapper form").remove();
	$("#comments_wrapper").append($(responsetext));
    }
    $("#comments_wrapper form .submit-preview").live("click", function(e) {
	e.preventDefault();
	console.log("click preview");
	var formdata = $("#comments_wrapper form").formSerialize();
	formdata += "&preview=Preview";
	console.log(formdata);
	var action = $("#comments_wrapper form").attr("action");
	$.post(action, formdata, handleForm);
    });
    $("#comments_wrapper form").live("submit", function(e) {
	console.log("submit");
	$(this).ajaxSubmit({
	    "success": handleForm
	});
	return false;
    });
});
