function JobSimpleEval( e ) {
	if (typeof e.error!="undefined") alert( e.error );
	if (typeof e.evaluate!="undefined") eval( e.evaluate );
}


function JobSubmitDialog() {
	var d = $("#dlg_job_action").data( "submitparams" );
	JobSendRequest( d , JobSimpleEval );
}

function JobCancelDialog() {
	$("#dlg_job_action").dialog( "close" );
	$("#dlg_job_action").dialog( "destroy" );
}

function JobDialogCallback( d ) {
	// error van
	if (typeof d.error!="undefined") {
		alert( d.error );
		if (typeof d.evaluate != "undefined") JobSimpleEval( d );
		return;
	}
	if (typeof d.evaluate != "undefined") JobSimpleEval( d );
	// van dialog
	if (typeof d.dlg=="undefined") return;

	$("#dlg_job_action").html( d.dlg );
	var dlg = {};
	if (typeof d.dlg_ttl!="undefined") dlg.title = d.dlg_ttl;
	dlg.modal = true;
	dlg.width = 600;
	dlg.height = 400;
	if (typeof d.buttons!="undefined") {
		var btns = {};
		for (var i in d.buttons) {
			if (d.buttons[i]!=false) {
				$("#dlg_job_action").data( "submitparams" , d.buttons[i] );
				btns[i] = function() { JobSubmitDialog( ); }
			} else {
				btns[i] = function() { JobCancelDialog(); }
			}
			dlg.buttons = btns;
		}
	}
	$("#dlg_job_action").dialog( dlg );
}


function JobSendRequest( d , cb ) {
	d["inajax"]=1;
	$.ajax(
		{
			type: "POST",
			cache: false,
			data: d,
			success: cb
		}
	);
}

function ActivateJob( hash ) {
	var d = {
		"ajaxevent" : "dlg_activate_job",
		"hash" : hash
	};
	JobSendRequest( d , JobDialogCallback );
}

function CloseJob( job_id ) {
	var d = {
		"ajaxevent" : "dlg_close_job",
		"job_id" : job_id
	};
	JobSendRequest( d , JobDialogCallback );
}

function RevokeJob( job_id ) {
	var d = {
		"ajaxevent" : "dlg_revoke_job",
		"job_id" : job_id
	};
	JobSendRequest( d , JobDialogCallback );
}

