function BGAction( n , action , params ) {
	t = $("#"+n );
	ids = t.data( "selecteds" );

	var d = {};
	d["inajax"] = 1;
	d["ajaxevent"] = "table_event";
	d["tbl"] = n;
	d["action"] = action;
	d["ids[]"] = ids;

	if (typeof params != "undefined") {
		var i;
		for (i in params) d[i] = params[i];
	}

	$.ajax(
		{
			type: "POST",
			cache: false,
			data: d,
			success: function(ret) {
				a = eval(ret);
			}
		}
	);
}

function BGCustom( n , action , d ) {
	t = $("#"+n );
	if (typeof d == "undefined") d = new Object();
	d["inajax"] = 1;
	d["ajaxevent"]="table_event_custom";
	d["tbl"]=n;
	d["action"]=action;
	$.ajax(
		{
			type: "POST",
			cache: false,
			data: d,
			success: function(ret) {
				a = eval(ret);
			}
		}
	);
}

function BGAddToArray( arr , id ) {
	retval = arr;
	retval[retval.length]=id;
	return retval;
}


function BGIsInArray( arr , id ) {
	for (i in arr) {
		if (arr[i] == id) return true;
	}
	return false;
}

function BGRemoveFromArray( arr , id ) {
	retval = new Array();
	x = 0;
	for (i in arr) {
		if (arr[i]==id) continue;
		retval[x]=arr[i];
		x++;
	}
	return retval;
}

function BGSelectionChanged( tbl , chk , id ) {
	var t = $( "#" + tbl );
	var c = $( chk );
	var a = t.data( "selecteds" );if (a==undefined) a = new Array();

	if (chk.attr( "checked" )) {
		if (!BGIsInArray( a , id ))
			a = BGAddToArray( a , id );
	} else {
		if (BGIsInArray( a , id ))
			a = BGRemoveFromArray( a , id );
	}
	t.data( "selecteds" , a );
}

function BGInitSelection( tbl , ids ) {
	var t = $( "#" + tbl );
	t.data( "selecteds" , ids );
}

function BGSelectAll( tblid , val ) {
	FNTHSuperGridSelectAll( tblid , val );
	var t = $( "#" + tblid );
	var sels = new Array();
	$("input.FNTHSuperGridRowCheck").each( function( index , elem ) {
		if (!($(elem).attr("checked"))) return;
		var id = $(elem).attr("id");
		var pos = id.indexOf( "_row" );
		while (pos>=0) {
			id = id.substring( pos + 4 );
			pos = id.indexOf( "_row" );
		}
		id = id.replace( "_chk_check" , "" );
		BGAddToArray( sels , id );
	} );
	t.data( "selecteds" , sels );
	BGSelectionChangedDefaultAMD( tblid );
}

function BGSelectionChangedDefaultAMD( tblid ) {
	var t = $("#"+tblid );
	var a = t.data( "selecteds" );
	if (a.length==0) {
		// egy se
		$("#"+tblid+"_tbrbutton_modify").addClass( "dsb" );	// nincs modify
		$("#"+tblid+"_tbrbutton_delete").addClass( "dsb" ); // nincs delete
	} else if (a.length==1) {
		// szigoruan egy
		$("#"+tblid+"_tbrbutton_modify").removeClass( "dsb" ); // van modify
		$("#"+tblid+"_tbrbutton_delete").removeClass( "dsb" ); // van delete
	} else {
		// tobb van kijelolve
		$("#"+tblid+"_tbrbutton_modify").addClass( "dsb" );	// nincs modify
		$("#"+tblid+"_tbrbutton_delete").removeClass( "dsb" );	// van delete
	}
}
