function loadScript(table) {
	var editButton = "<a class='btn btn-success edit'  ><i class='icon-edit icon-white'></i>"
			+ $.i18n.prop('script-edit') + "</a>";
	var deleteButton = "<a class='btn btn-info delete'><i class='icon-trash icon-white'></i>"
			+ $.i18n.prop('delete') + "</a>";
	table.clear();
	$.post("loadScripts", {}, function(data) {
		if (data.success) {
			var scripts = data.scripts;
			if (scripts == null) {
				return;
			}
			for ( var i = 0; i < scripts.length; i++) {
				var tr = table.row.add(
						[ i + 1, scripts[i].name,
								new Date(scripts[i].createDateTime),
								editButton + deleteButton ]).draw().node();
				$(tr).attr("id", scripts[i].id);

			}

		} else {
			information(data.failedMessage);
		}

	}, "json");

}
function addEvent(table) {
	var tbody = table.table().body();
	$(tbody).on("click", "td a.delete", function(e) {
		e.preventDefault();
		var row = $(this).closest("tr");
		var scriptId = $(row).attr("id");
		deleteScript(scriptId, table.row(row));

	});
	$(tbody).on("click", "td a.edit", function(e) {
		e.preventDefault();
		var row = $(this).closest("tr");
		var scriptId = $(row).attr("id");
		var scriptId = $(row).attr("id");
		var scriptName = table.row(row).data()[1];
		editScript(scriptId, scriptName);
	});
}

function deleteScript(scriptId, row) {
	$.post("deleteScript", {
		scriptId : scriptId
	}, function(data) {
		if (data.success) {

			information($.i18n.prop("script-deleteSuc"));
			row.remove().draw();
		} else {
			information(data.failedMessage);
			// error message
		}
	}, "json");
}
function editScript(scriptId, scriptName) {
	window.open("editScript.jsp?name=" + scriptName + "&scriptId=" + scriptId);// need
}