$(document).ready(function() {
    // Initialise the table
    $("table.dndtable").tableDnD({
    	onDrop: function(table, row) {
		    var object = $("table.dndtable").get(0).id;
    		ajaxCall="";
    		for(i=1;i<table.tBodies[0].rows.length;i++){
    			ajaxCall+="'"+i+"':"+table.tBodies[0].rows[i].id+", ";
    		}
			showAjaxNotice(translation["savingOrderLabel"]);
			$.post("indexAjax.php?object0="+object+"&action0=saveNewOrder",
				{newOrder: ajaxCall},
				function(data){
	    			if(data.status==1){
		    			showSuccessNotice(translation["orderSavedLabel"]);
		    			if(object == "SessionToPapersTable"){
		    				location.reload();
		    			}
		    		}
		    		else{
		    			showFailureNotice(translation["orderNotSavedLabel"]);
	    			}
	  			},
	  		"json");        }
    });
});

function showAjaxNotice(notice){	
	showPermanentNotice("<img src='ajax.gif'>"+notice);
}

function showSuccessNotice(notice){
	$("div#notice").html(notice);
	$("div#notice").show();
	$("div#notice").wait(2000);
	$("div#notice").fadeOut("slow",hideElement);
}

function showFailureNotice(notice){
	showPermanentNotice(notice);
}

function showPermanentNotice(notice){
	$("div#notice").html(notice);
	$("div#notice").show();	
}

