AdminTasksGridJsParams = "width=800,height=600";
AdminTasksGridInterval = null;

function AdminTasksGridModify( uid ) {
	window.open( 'edit.php?mode=modify&uid='+uid , '_blank' , AdminTasksGridJsParams );
}

function AdminTasksGridAction( n , action ) {
	if ($("#"+FNTHSuperGrid_ToolbarId( n , action )).hasClass( "dsb" )) return;
	switch (action) {
	case "new":
		window.open( 'edit.php?mode=new' , '_blank' , AdminTasksGridJsParams );break;
	case "modify":
		AdminTasksGridModify( $("#"+n).data( "selecteds" )[0] , AdminTasksGridJsParams );
		break;
	case "delete":
		if (!window.confirm( aJSLangDefs.taskspage_confirm_Delete_tasks )) return;
		BGAction( n , action );
		break;
	case "filter":
		$("#frm_AdminTasksGrid").append( "<input type=\"hidden\" name=\"task\" value=\"filter\" />" );
		document.frm_AdminTasksGrid.submit();
		break;
	}
}

function AdminTasksGridSelectionChanged( tblid , chk , id ) {
	BGSelectionChanged( tblid , chk , id );
	BGSelectionChangedDefaultAMD( tblid , chk, id );
}

function AdminTasksGridRefreshRowsCallback( datas ) {
	var i,tdid;
	var s = datas.clearscript;
	eval( s );
	for (i in datas.ids) {
		var job_id = datas.ids[i];
		var item = datas.datas[job_id];
		$("#"+datas.id + "_row"+job_id+"_task_name").html( item.task_name );
		$("#"+datas.id + "_row"+job_id+"_task_ctstamp").html( item.task_ctstamp );
		$("#"+datas.id + "_row"+job_id+"_task_ptstamp").html( item.task_ptstamp );	
		var mtstamp = $("#"+datas.id + "_row"+job_id+"_task_mtstamp");
		var changed = (mtstamp.html() != item.task_mtstamp );
		if (changed) {
			$("#"+datas.id + "_row"+job_id+"_task_status").html( item.task_status );
			var state = $("#"+datas.id + "_row"+job_id+"_task_state");
			state.html( item.task_state );
		}
	}
}

function AdminTasksGridRefreshRows( tblid , ids ) {
	$.ajax(
		{
			type: "POST",
			cache: false,
			data: (
				{
					inajax : 1,
					ajaxevent : "refresh_grid_rows",
					id : tblid,
					uids : ids
				}
			),
			success: function(ret) {
				AdminTasksGridRefreshRowsCallback( eval( ret ) );
			}
		}
	);
}

function AdminTasksGridTimer( tblid ) {
	var o = $("#"+tblid );
	var datas = o.data( "griddata" );
	AdminTasksGridRefreshRows( tblid , datas.ids );
}

function InitAdminTasksGrid( tblid , datas ) {
	var o = $("#"+tblid );
	o.data( "griddata" , datas );
	AdminTasksGridInterval = setInterval( "AdminTasksGridTimer('"+tblid+"');" , 3000 );
}

function AdminTaskOpen( o ) {
	o.css( "overflow" , "scroll" );
	o.animate(
		{ height: 500 } ,
		1000  ,
		function() {}
	);
}

function AdminTaskReissue( task_id ) {
	BGCustom("AdminTasksGrid","reissue", { "task_id" : task_id } );
}
