document.write('<div style="z-index: 3000;" style="hidden" class="jqmWindow jqmID1" id="dialog"></div>');
                                                                                    
//var is_ie = (navigator.userAgent.toLowerCase().indexOf("msie") != -1);

$().ready(function() {

	/**
	 *	The default Modal Box where all Ajax request loads
	 */
	$('#dialog').jqm({modal: true});

	/**
	 *	Post Ajax stuff
	 */
	$('.ajaxForm').submit(function () {
		ajaxPostUpdate (this.id, this.action + (this.action.indexOf("?") == -1 ? "?" : "&") , "dialog", true);
		return false;
	});

});

function ajaxSuccess(elementId, msg, tickbox) {
    $("#"+elementId).html(msg);

	if (tickbox == false) {
		if ($("#"+elementId).hasClass("jqmID1")) {
			$("#"+elementId).jqmShow();
		} else {
			$("#"+elementId).css("display", "");
		}
	}
}

function ajaxBefore(elementId, tickbox, url) {
	if (tickbox) {
		$("#"+elementId).html($("#waitModal").html());

		if ($("#"+elementId).hasClass("jqmID1")) {
			$("#"+elementId).jqmShow();
		} else {
			$("#"+elementId).css("display", "");
		}
	}
}

function ajaxPostUpdate (formId, postUrl, elementId, tickbox)
{

	if (elementId == null) {
		var elementId = 'dialog';
	}

    var params = $("#"+formId).serialize();

	var myAjax = $.ajax({
		type: "POST",
		url: postUrl,
		data: params,
		before: ajaxBefore(elementId, tickbox, postUrl),
		success: function(msg){
    		ajaxSuccess(elementId, msg, tickbox);
  		}
	 });
};
