var CLASS_NAME_FILTER_SELECTED = "titlefilterselected";
var CLASS_NAME_FILTER_UNSELECTED = "titlefilter";
var iDivPagingNumber = 0;
var MAX_FILTER = 50;
var COUNT_RECORDS_LIMIT_FOR_ORDER = 500;
var INDEX_FOR_ORDER = 8;
var COUNT_RECORDS_BY_PAGE = 22;
var sNavigationMode = "Live";
var bItemSyle = true;

var iLastDataSetCharged = 0;
var aLastDataSetCharged = new Array();


/* Draw title table in the list */
function GetTitleTable( sFunctionOrder, sFunctionRenderFilter, sColNameOrder, sOrder, aTitles, ds, sIdDataGrid )
{
	//aArrayValuesOptions[1] = 0;
	if ( sNavigationMode != "Live" )
		if ( ds )
			if ( ds.Tables[0] )
			{
				aLastDataSetCharged[ iLastDataSetCharged ] = ds;
				//aArrayValuesOptions[2] = ds.Tables[0].Rows.length;
			}

	if ( sIdDataGrid == null )
		sIdDataGrid = "";
	else
		sIdDataGrid+="_";
	var sImgAsc = "";
	var sImgDesc = "";
	var bRequiredOrder = true;
	var bRequiredFilter = true;
	var sText = '<table cellSpacing="0" cellPadding="0" width="100%" border="0">' +
		'<tr class="listtitle" height="20">' +
			'<td width="10" align="left">&nbsp;</td>';
			//'<td width="10" align="left"><div id=divTesting class=hide><input type="checkbox" id="chkTesting"></div</td>';
//sTextPages+= "<input type='checkbox' id='chkTesting'>";
			for ( var i = 0; i < aTitles.length; i++ )
			{
				aData = aTitles[i].split( "," );
				if ( aData[ 0 ].indexOf( "[checkbox]" ) == 0 )
				{
					var sNameId = "";
					var aDataCheckbox = aData[ 0 ].split( ":" );
					if ( aDataCheckbox.length > 1 )
						sNameId = ' name="' + aDataCheckbox[ 1 ] + '" id="' + aDataCheckbox[ 1 ] + '" ';
					bRequiredOrder = false;
					bRequiredFilter = false;
					aData[ 0 ] = '<input ' + sNameId + ' type="checkbox" ' +
									'onClick="' + aData[ 1 ] + '( this );">';
				}
				else
{
				sImgAsc = "sort-asc-off.gif";
				sImgDesc = "sort-desc-off.gif";
							
				if ( sColNameOrder == aData[1] )
					if ( sOrder.toLowerCase() == "desc" )
						sImgDesc = "sort-desc-on.gif";
					else
						sImgAsc = "sort-asc-on.gif";
						
				bRequiredOrder = true;
				if ( aData.length > 3 )
					if ( aData[3].toLowerCase() == "noorder" )
						bRequiredOrder = false;
				bRequiredFilter = true;
				if ( aData.length > 4 )
					if ( aData[4].toLowerCase() == "nofilter" )
						bRequiredFilter = false;
				if ( sFunctionRenderFilter == "" )
					bRequiredFilter = false;
				if ( ( ds != null ) && ( ( bRequiredFilter ) || ( bRequiredOrder ) ) )
				{
					var iMaxFilter = MAX_FILTER;
					var sColName = aData[1];
					if ( bRequiredFilter )
					{
						if ( ds.Tables[1] )
							if ( ds.Tables[1].Rows.length > 0 )
								if ( parseInt( ds.Tables[1].Rows[0][ sColName ] ) > iMaxFilter )
									bRequiredFilter = false;
						if ( ds.Tables[0] )
						{
							if ( parseInt( ds.Tables[0].Rows.length ) <= 0 )
								bRequiredFilter = false;
						}else bRequiredFilter = false;
					}
					
					if ( ( ds.Tables[0] ) && ( ds.Tables[1] ) )
						if ( ds.Tables[0].Rows.length > COUNT_RECORDS_LIMIT_FOR_ORDER )
							if ( (ds.Tables[0].Rows.length / parseInt( ds.Tables[1].Rows[0][ sColName ] ) ) > INDEX_FOR_ORDER )
								bRequiredOrder = false;
				}
}
				var sTDAlign = "left";
				if ( aData.length > 5 )
					sTDAlign = aData[5];
				sTextColumn= '' + 
			'<td width="' + aData[2] + '" align="'+sTDAlign+'">' +
				'<table cellPadding="0" cellSpacing="0" border="0">' +
					'<tr height="20">' +
						'<td>';
						if ( bRequiredFilter )
							sTextColumn+='<a href="#" id="lbt_'+sIdDataGrid+aData[1]+'" class="'+CLASS_NAME_FILTER_UNSELECTED+'" onclick="javascript:' + sFunctionRenderFilter + '(\'' + aData[1] + '\', event);return false;">'+aData[0]+'</a>';
						else
							sTextColumn+= aData[0];
						sTextColumn+='</td>' +
						'<td width="5"></td>' +
						'<td>';
						if ( bRequiredOrder )
						{
							sTextColumn+='<table cellSpacing="0" cellPadding="0" border="0">' +
								'<tr>' +
									'<td>';
										if ( ( sOrder.toLowerCase() == "desc" ) || ( sColNameOrder != aData[1] ) )
											sTextColumn+='<a href="#" onClick="'+sFunctionOrder+'(\'' + aData[1] + '\', \'asc\' );return false;">';
										sTextColumn+='<img src="../Images/Icons/' + sImgAsc + '" border="0" width="10" height="9">';
										
										if ( ( sOrder.toLowerCase() == "desc" ) || ( sColNameOrder != aData[1] ) )
											sTextColumn+='</a>';
									sTextColumn+='</td>' +
								'</tr>' +
								'<tr>' +
									'<td>';
										if ( ( sOrder.toLowerCase() == "asc" ) || ( sColNameOrder != aData[1] ) )
											sTextColumn+='<a href="#" onClick="'+sFunctionOrder+'(\'' + aData[1] + '\', \'desc\' );return false;">';
										sTextColumn+='<img src="../Images/Icons/' + sImgDesc + '" border="0" width="10" height="9">';
										
										if ( ( sOrder.toLowerCase() == "asc" ) || ( sColNameOrder != aData[1] ) )
											sTextColumn+='</a>';
									sTextColumn+='</td>' +
								'</tr>' +
							'</table>';
						}
						sTextColumn+='</td>' +
					'</tr>' +
				'</table>'+
			'</td>';
				sText += sTextColumn;
			}
			if ( sNavigationMode == "Live" )
				sText+= '<td width="16">&nbsp;</td>';
			else
			{
				sText+= '<td width="16"><a href="#" class="titlefilter" onclick="';
				//sText+= 'openOptions_DropDownDataList( event );';
				sText+= 'DropDownDataList( aArrayNamesOptions, ' + iLastDataSetCharged + ', event, \'ViewDataSetInfo\' );';
				sText+= 'DoDropDownFilter( event );return false;'
				sText+= '">#</a></td>'
			}
		sText+= '</tr>' +
	'</table>';
	if ( sNavigationMode != "Live" )
	{
		iLastDataSetCharged++;
		if ( iLastDataSetCharged >= 10 ) iLastDataSetCharged = 0;
	}
	return sText;
}
function DecimalFormat( iItem, iCountDec_Param )
{
	var exItem = iItem;
	iItem = iItem * ( Math.pow( 10, iCountDec_Param ) );
	var iItemX10 = iItem;
	iItem = Math.round(iItem) / ( Math.pow( 10, iCountDec_Param ) );
	var sNumericItem = iItem + "";
	if ( sNumericItem.indexOf( "." ) == -1 )
		sNumericItem = iItem + ".";
	var sPartInt = sNumericItem.split(".")[0];
	sPartInt = CommaFormat( sPartInt );
	var sPartDec = sNumericItem.split(".")[1];
	var iCountDec = parseInt(iCountDec_Param) - sPartDec.length;
	for ( var hDec = 0; hDec < iCountDec; hDec++ )
		sPartDec+= "0";
	if ( parseInt(iCountDec_Param) > 0 )
		return sPartInt + "." + sPartDec;
	else
		return sPartInt;
}
function CommaFormat( x )
{
    var delimiter = ",";
    var rgx = /(\d+)(\d{3})/;
    while (rgx.test(x))
        x = x.replace(rgx, '$1' + delimiter + '$2');
    return x;
}
/*	Returns data table from ds dataSet showing only the columns of the array aColumns
	and builds the list of distinct words for the filter option in the aFilterList array for each 
	column indicated in aColumns (if not coming as "NoFilter") and if the amount of data of each
	column (indicated in Table[1] of ds dataSet) is smaller than iMaxFilter. */
function fnSetDiv( obj, iCountPages, iStartPageIndex, iCountPagesMaxByView, sfn_GoToPageNumber )
{
	var oDivPaging = null;
	if ( typeof( obj ) != "object" ) /*then is object id*/
	{
		oDivPaging = GetElementById( obj );
	}
	else
	{
		oDivPaging = obj.parentNode;
	}
	var sDivPagingId = oDivPaging.id;
	var sReturn = "";
	var a = iStartPageIndex + iCountPagesMaxByView;
	var b = a + iCountPagesMaxByView - 1;
	for ( var i = a; ( i <= b ) && ( i <= iCountPages ); i++ )
	{
		sReturn+= "<a class='linkpaging' href='#' onClick='"+sfn_GoToPageNumber+"("+i+");return false;'>" + i + "</a>-";
	}
	iStartPageIndex = a;
	var iTheLastPageInList = i - 1;
	if ( iTheLastPageInList < iCountPages ) 
		sReturn+= " - <a class='linkpaging' href='#' onclick='fnSetDiv(\""+sDivPagingId+"\","+iCountPages+","+iStartPageIndex+","+iCountPagesMaxByView+",\""+sfn_GoToPageNumber+"\");return false;'>"+"&gt;&gt;"+"</a>";
	oDivPaging.innerHTML = sReturn;
}
function SetPagingListTable( ds, aColumns, iMaxFilter, aFilterList, aRowFunctions, divListName, divPagingName, iPageNumber, iRowsShow, aGroupByKey, iHeightRow, sfn_GoToPageNumber, sNameDataGrid )
{
	if ( iPageNumber == null )
		iPageNumber = 1;
	if ( iRowsShow == null )
		iRowsShow = COUNT_RECORDS_BY_PAGE;
	var aText = GetTable( ds, aColumns, iMaxFilter, aFilterList, aRowFunctions, iPageNumber, iRowsShow, divListName, aGroupByKey, iHeightRow, sfn_GoToPageNumber, sNameDataGrid );
	//alert( "Start m1" );
	//var iT0 = (new Date()).getTime();
	GetElementById( divListName ).innerHTML = aText[ 0 ];
	//replaceHtml( divListName, aText[ 0 ] );
	//var iT1 = (new Date()).getTime();
	//var iT = iT1 - iT0;
	//alert( iT );
	GetElementById( divListName ).scrollTop = 0;
	GetElementById( divPagingName ).innerHTML = aText[ 1 ];
}/*var sClassNameBefore = "";*/
function replaceHtml( el, html ) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	return newEl;
}
function CollapseOF( iId, obj )
{
	var sTextKey = "tblCollpasedSection_";
	//var objToShowHide = GetElementById( sTextKey + iId );
	var objToShowHide = (obj.parentNode).parentNode.nextSibling;
	if ( ( objToShowHide.className=="show" ))
	{
		objToShowHide.className='hide';
		obj.title = OrderAndFilter.sTextClickToExpand;
	}
	else
	{
		objToShowHide.className="show";
		obj.title = OrderAndFilter.sTextClickToCollapse;
	}

}
var OrderAndFilter = {	};
OrderAndFilter.sTextClickToExpand = "Click to Expand";
OrderAndFilter.sTextClickToCollapse = "Click to Collapse";

OrderAndFilter.openAll = function( sIdDataSet )
{
	var sTextKey = "tblCollpasedSection_";
	var iId = 0;
	while ( document.getElementById( sTextKey + sIdDataSet + iId ) != null )
	{
	
		var obj = GetElementById( sTextKey + sIdDataSet + iId );
		obj = (obj.parentNode).parentNode.nextSibling;
		obj.title = OrderAndFilter.sTextClickToCollapse;

		GetElementById(  sTextKey + sIdDataSet + iId ).className="show";
		iId++;
	}
}
OrderAndFilter.closeAll = function( sIdDataSet )
{
	if ( sIdDataSet == null ) sIdDataSet = "";
	var sTextKey = "tblCollpasedSection_";
	var iId = 0;
	while ( document.getElementById( sTextKey + sIdDataSet + iId ) != null )
	{
		var obj = GetElementById( sTextKey + sIdDataSet + iId );
		obj = (obj.parentNode).parentNode.nextSibling;
		obj.title = OrderAndFilter.sTextClickToExpand;
		GetElementById(  sTextKey + sIdDataSet + iId ).className="hide";
		iId++;
	}
}
function GetTable( ds, aColumns, iMaxFilter, aFilterList, aRowFunctions , iPageNumber, iRowsShow, divListName, aGroupByKey, iHeightRow, sfn_GoToPageNumber, sNameDataGrid )/*//, sFilterColumn, sFilterText*/
{
	var tblGroupByKey = null;
	var bIsArrayGroupByKey = true;
	if ( aGroupByKey == null ){aGroupByKey = new Array();bIsArrayGroupByKey=false;}
	else
	{
		if ( typeof( aGroupByKey[0] ) == "object" )
		{
			tblGroupByKey = aGroupByKey[0].tbl;
			//alert( "object: " + tblGroupByKey.Rows.length );
			aGroupByKey = new Array();
			//alert( "object: " + tblGroupByKey.Rows.length );
			for ( var i = 0; i < tblGroupByKey.Rows.length; i++ )
			{
				//alert( tblGroupByKey.Rows[i][tblGroupByKey.Columns[1].Name] );
				aGroupByKey[tblGroupByKey.Rows[i][tblGroupByKey.Columns[0].Name]+""] = tblGroupByKey.Rows[i][tblGroupByKey.Columns[1].Name]+"";
			}
		}
	}
	var rows = ds.Tables[0].Rows.length;
	/** START PAGING **/
	var sTextPages = "";
	var sTextPagesDivCont = "";
	var iCountPagesMaxByView = 3;
	var bToEnd = true;
	var iStartPageIndex = 1;				
	var bShowPageNumbers = false;				
	var iStartIndex = 0;
	var iEndIndex = ds.Tables[0].Rows.length;
	var iCountPages = 0;
	if ( sfn_GoToPageNumber == null )
		sfn_GoToPageNumber = "GoToPageNumber";
	if ( sNameDataGrid == null )
		sNameDataGrid = "";
	if ( iRowsShow == null )
		iRowsShow = COUNT_RECORDS_BY_PAGE;
	if ( iHeightRow == null )
		iHeightRow = 20;
	rows = iRowsShow;
	iCountPages = parseInt( ds.Tables[0].Rows.length/iRowsShow );
	if ( iCountPages < ds.Tables[0].Rows.length/iRowsShow ) 
		iCountPages++;
	if ( ( iPageNumber != null )  )
	{
		bShowPageNumbers = true;
		iStartIndex = (iRowsShow*(iPageNumber-1));
		iEndIndex = ((iStartIndex + rows)>ds.Tables[0].Rows.length)?ds.Tables[0].Rows.length:(iStartIndex + rows);
		sTextPages+= "<table width='100%' cellspacing='0' cellpadding='0' border='0'><tr height='20' class='listtitle'>";
		sTextPages+= "<td width='10'>&nbsp;</td>";
		sTextPages+= "<td align='center'>";//iDivPagingNumber
		sTextPages+= "<div id='divListPageNumbers_" + divListName + "' width='100%' " + ">";
		sTextPages+= "Pages ";
		if ( iCountPages > 1 )
		{
			var iPagePrevious = iPageNumber - 1;
			if ( iPagePrevious > 0 )
				sTextPages+= "<a class='linkpaging' href='#' onClick='"+sfn_GoToPageNumber+"("+iPagePrevious+");return false;'>" + "&lt;" + "</a>-";
			else 
				sTextPages+= "<span style='color:white;font-weight:bold;'>&lt;-</span>";
		}
		for ( var pp = 1; ( pp <= iCountPages ) && ( (pp <= iCountPagesMaxByView)||(bToEnd) ); pp++ )
		{
			if ( pp != iPageNumber )
				sTextPages+= "<a class='linkpaging' href='#' onClick='"+sfn_GoToPageNumber+"("+pp+");return false;'>" + pp + "</a>-";
			else 
				sTextPages+="<span style='color:#000000;font-weight:bold;'>" + pp + "</span>-";
		}
		if ( iCountPages > 1 )
		{
			var iPageNext = iPageNumber + 1;
 			if ( iPageNext <= iCountPages )
				sTextPages+= "<a class='linkpaging' href='#' onClick='"+sfn_GoToPageNumber+"("+iPageNext+");return false;'>" + "&gt;" + "</a>";
			else 
				sTextPages+= "<span style='color:white;font-weight:bold;'>&gt;</span>";
		}
		var iTheLastPageInList = pp - 1;
		if ( (!(bToEnd)) && (iTheLastPageInList<iCountPages) ) //then show some page numbers; else show all page numbers
			sTextPages+= " - <a class='linkpaging' href='#' onclick='fnSetDiv(this,"+iCountPages+","+iStartPageIndex+","+iCountPagesMaxByView+",\""+sfn_GoToPageNumber+"\");return false;'>"+"&gt;&gt;"+"</a>";
		sTextPages+= "   Total: " + ds.Tables[0].Rows.length + " records.";
		sTextPages+= "</div>";// class='list'
		sTextPages+= "</td></tr></table>";
	}
	/** END PAGING **/
	if ( iMaxFilter == null )
		iMaxFilter = MAX_FILTER;
	var cols = ds.Tables[0].Columns.length;
	var sTable = "";
	var sRow = "";
	var sClassRow = "";
	var sItem = "";
	var sAddToItem = "";
	var sAddBeforeToItem = "";
	var bEvenRow = false;
	var sColName = "";
	var sColWidth = "";
	var sColFunction = "";
	var sColParam = "";
	var sColParam_2 = "";
	var sColParam_3 = "";
	var sColParam_4 = "";
	var sRowFunction = "";
	var sRowFunctionTitle = "";
	var sRowFunctionTooltip = "";
	var sRowParam = "";
	var sRowParam_2 = "";
	var sRowParam_3 = "";
	var sRowParamId_1 = "";
	var sRowParamId_2 = "";
	var sRowParamId_3 = "";
	var sClickTd = "";
	var sClickImage = "";
	var aItems;
	var bAddRow = true;
	var aText = new Array();
	if ( aColumns!= null )
		for ( var j = 0; j < aColumns.length; j++ )
		{
			aItems = (aColumns[ j ]+"").split( "," ); 
			sColName = aItems[0];
			aColumns[ sColName ] = 0;
		}
	aText.push('<table cellSpacing="0" cellPadding="0" width="100%" border="0">');
	var sColValueGroupBy_Before = "";/* code Group By */
	var sColValueGroupByTwo_Before = "";/* code Group By Two */
	var iCountCollapsedSections = 0;/* code Group By Two */
	//var sClassNameForCollapsedSection = "";/* code Group By and Group By Two */
	/* start code Group By */
		var sKeyToGroupBy = (aColumns[ 0 ]+"").split( "," )[0].toLowerCase();
		var bIsGroupBy = false;
		var bIsGroupByCollapsed = false;
		//Exception//var sCollapsedException = "";
		//Exception//if (sKeyToGroupBy.indexOf("groupbycollapsed|") == 0) sCollapsedException = sKeyToGroupBy.split("|")[1].split(":")[0];
	//Exception//alert( sKeyToGroupBy+"-"+  sCollapsedException );
	// * end code Group By * //
	var sColumnNameOfGroupBy = ((aColumns[ 0 ]+"").split( "," )[0]).split( ":" )[1];
	var aDataGroupBy = new Array();
	for ( var i = iStartIndex; i < iEndIndex; i++ )
	{
		var aRow = new Array();
		
		/************************* NEW GROUP BY X ******************************/
			sColumnValueOfGroupBy = ds.Tables[0].Rows[i][ sColumnNameOfGroupBy ]+"";
			if ( !bIsArrayGroupByKey )
				aGroupByKey[ sColumnValueOfGroupBy ] = sColumnValueOfGroupBy;
			if (aDataGroupBy[ sColumnValueOfGroupBy ] == null )
			{
				bEvenRow = false;
				aDataGroupBy[ sColumnValueOfGroupBy ] = new OrderAndFilter.ClassRowOrderFilter( bEvenRow );//new Array();
			}
			else
			{
				bEvenRow = !aDataGroupBy[ sColumnValueOfGroupBy ].bEvenRow;
				aDataGroupBy[ sColumnValueOfGroupBy ].bEvenRow = bEvenRow;
			}
			/////alert( sColumnValueOfGroupBy + " \n" + aDataGroupBy[ sColumnValueOfGroupBy ] );
		/*********************** END NEW GROUP BY X **************************/
		
		if(bItemSyle)
		    sClassRow = (bEvenRow)? "listitemeven": "listitemuneven";

		/* **** start code Group By **** */
		var iInitIndexColumns = 0;
		bIsGroupBy = (sKeyToGroupBy.indexOf( "groupby:" ) == 0);
		bIsGroupByCollapsed = ( (sKeyToGroupBy.indexOf("groupbycollapsed:") == 0) || (sKeyToGroupBy.indexOf("groupbycollapsed|") == 0) );
// ** //var iColCountGroupBy = -1;
/*
// ***************************************************************
// ***************************************************************
		if ( bIsGroupBy || bIsGroupByCollapsed )
		{
			iInitIndexColumns = 1;
			var sColNameGroupBy = ((aColumns[ 0 ]+"").split( "," )[0]).split( ":" )[1];
			//var sColValueGroupBy = ds.Tables[0].Rows[i][ sColNameGroupBy ]+""; // * old code * //
			var sColValueGroupBy = ds.Tables[0].Rows[i][ sColNameGroupBy ]+"";// **new line - more optimal** //
			if ( aGroupByKey != null )
			{
				sColValueGroupBy = aGroupByKey[ ds.Tables[0].Rows[i][ sColNameGroupBy ]+"" ];// **new line - more optimal** //
				if ( typeof( sColValueGroupBy ) == "object" )
				{
					sColValueGroupBy = aGroupByKey[ ds.Tables[0].Rows[i][ sColNameGroupBy ]+"" ][ 0 ];
					iColCountGroupBy = parseInt( aGroupByKey[ ds.Tables[0].Rows[i][ sColNameGroupBy ]+"" ][ 1 ] );
				}
			}
			//var sColValueGroupByToCompare = sColValueGroupBy.split( "-" )[0]; // **new line - more optimal** //
			var sColValueGroupByToCompare = ds.Tables[0].Rows[i][ sColNameGroupBy ]+"";
			//Exception//if (sKeyToGroupBy.indexOf("groupbycollapsed|") == 0)
			//Exception//if ( sColValueGroupBy.toLowerCase() == sCollapsedException ) {bIsGroupByCollapsed = false;}
			//if ( sColValueGroupBy_Before != sColValueGroupBy ) // **old line** //
			if ( sColValueGroupBy_Before != sColValueGroupByToCompare ) // **new line - more optimal** //
			{
				sColValueGroupByTwo_Before = "";
				bEvenRow = false;// *reset style of row* //
				sClassRow = (bEvenRow)? "listitemeven": "listitemuneven";// *reset style of row* //
				// * collapse section * //
				if ( i != iStartIndex )
				{
					aRow.push( '</table>' );
					aRow.push('<table cellSpacing="0" cellPadding="0" width="100%" border="0">');

				}// * end collapse section * //
				//sColValueGroupBy_Before = sColValueGroupBy+""; // **old line** //
				sColValueGroupBy_Before = sColValueGroupByToCompare+""; // **new line - more optimal** //
				//aRow.push( '<tr class="listsummarydivisor" valign="center" height="20">' );
				
				// * collapse section * //
				sClassNameForCollapsedSection = "listsummarydivisor";
				if ( (aColumns[ 1 ]+"").split( "," )[0].toLowerCase().indexOf( "groupby:" ) == 0 )
					sClassNameForCollapsedSection = "listitemuneven";

				var sClassNameByCollapse = "hide";
				var sTitleNameByCollapse = "Expand";
				var sTitleNameByCollapseWithoutItems = "Without items";
				if (!bIsGroupByCollapsed)
				{
					sClassNameByCollapse = "show";
					sTitleNameByCollapse = "Collapse";
				}
				aRow.push( '<tr class="'+ sClassNameForCollapsedSection +'" valign="center" height="20"');
				//aRow.push( ' onclick="GetElementById( \'tbl_' + i + '\' ).className=\'show\';">' );
				if ( iColCountGroupBy != 0 )
					aRow.push( ' title="'+sTitleNameByCollapse+'" onclick="CollapseOF(' + iCountCollapsedSections + ', this);" style="cursor:hand;cursor:pointer;">' );
				else
					aRow.push( ' title="'+ sTitleNameByCollapseWithoutItems + '" style="cursor:default;">' );
				///aRow.push( ' onclick="CollapseOF( \'tbl_' + i + '\' );" style="cursor:hand;cursor:pointer;">' );
				// * end collapse section * //
				
				aRow.push( "<td width=\"10\">&nbsp;</td>" );
				//colspan var iColSpanGroupBy = aColumns.length + aRowFunctions.length - 1;
				//colspan aRow.push( '<td align="left" colspan="' + iColSpanGroupBy + '"> ' + sColValueGroupBy + '</td>' );
				aRow.push( '<td align="left"> ' + sColValueGroupBy + '</td>' );
				aRow.push( '</tr>' );
				
				// * collapse section * //
				aRow.push('</table><table id="tblCollpasedSection_' + iCountCollapsedSections + '" cellSpacing="0" cellPadding="0" width="100%" border="0" class="'+sClassNameByCollapse+'">');
				iCountCollapsedSections++;
				//continue;
				// * end collapse section * //
			}
//sClassRow = "hide";



			// *
			//if ( document.getElementById("Header1_txSearch") )
			//	if (GetElementById( "Header1_txSearch" ).value != "@" )* //
					bIsGroupByCollapsed=false;
			//if ( !bIsGroupByCollapsed )
			//{

			// * **** start code Group By Two **** * //
			if ( (aColumns[ 1 ]+"").split( "," )[0].toLowerCase().indexOf( "groupby:" ) == 0 )
			{
				sClassRow = "listitemeven";
				iInitIndexColumns = 2;
				var sColNameGroupByTwo = ((aColumns[ 1 ]+"").split( "," )[0]).split( ":" )[1];
				var sColValueGroupByTwo = ds.Tables[0].Rows[i][ sColNameGroupByTwo ]+"";
				if ( sColValueGroupByTwo_Before != sColValueGroupByTwo )
				{
					sColValueGroupByTwo_Before = sColValueGroupByTwo+"";
					aRow.push( '<tr class="listsummarydivisor" valign="center" height="20">' );
					aRow.push( "<td width=\"10\">&nbsp;</td><td>&nbsp;</td>" );
					var iColSpanGroupByTwo = aColumns.length + aRowFunctions.length - 2;
					aRow.push( '<td align="left" colspan="' + iColSpanGroupByTwo + '"> ' + sColValueGroupByTwo + '</td>' );
					aRow.push( '</tr>' );
				}
			}
			// * **** end code Group By Two **** * //
			//}
		}
*/
// ******************************************************* //
// ******************************************************* //
		
		
		/* **** end code Group By **** */
		////if ( !bIsGroupBy ) //test
// ** //if ( iColCountGroupBy != 0 )
		{
// ** //if ( !bIsGroupByCollapsed )
{
		aRow.push( "<tr id='td_" + i + "' valign='center' class='" + sClassRow + "' height='" + iHeightRow + "' " );
		////aRow.push( "<tr valign='center' class='" + sClassRow + "' height='20' " );
		//aRow.push( " onmouseout='this.className=sClassNameBefore;'");
		//aRow.push( " onmouseover='sClassNameBefore=this.className;this.className=\"listitemevenover\"';" );
		if (( aRowFunctions != null )&&( aRowFunctions[0] != "" ))
			aRow.push( " style='cursor: pointer;'" )
		aRow.push( ">" );
		aRow.push( "<td width=\"10\">&nbsp;</td>" );
}
		for ( var j = iInitIndexColumns; j < aColumns.length; j++ )
		{
			aItems = (aColumns[ j ]+"").split( "," ); 
			sColName = aItems[0];
			sColWidth = aItems[1];
			/* In this id we get the function name to call (and the parameter)
			in the case of a click over text-element */
			if ( aItems.length > 2 )
			{							
				aItemsFunction = aItems[2].split( ";" );
				var sColClassLinkColumn = ""
				if ( aItemsFunction[0].indexOf( "class=" ) == 0 )
				{
					sColClassLinkColumn = 'class="'+aItemsFunction[0].split("-")[0].split("=")[1]+'"';
					aItemsFunction[0] = aItemsFunction[0].split("-")[1];
				}
				sColFunction = aItemsFunction[0];
				sColParam = ds.Tables[0].Rows[i][ aItemsFunction[1] ] + "";
				sColParam = sColParam.replace(/'/g, "&rsquo;");

				for ( var hh = 2; hh < aItemsFunction.length; hh++ )
				{
					eval( 'sColParam_' + hh + ' = ds.Tables[0].Rows[i][ aItemsFunction[' + hh + '] ]' );
					eval( "sColParam_" + hh + " = (sColParam_" + hh + " + '').replace(/'/g, '&rsquo;')" );
				}
			}
			else
			{
				sColFunction = "";
				sColParam = "";
				sColParam_2 = "";
				sColParam_3 = "";
				sColParam_4 = "";
			}
			sAddToItem = "";
			sAddBeforeToItem = "";
			if ( sColName != "" )
			{
				if ( sColName.indexOf( ";" ) == -1 )
					sItem = ds.Tables[0].Rows[i][ sColName ];
				else
				{
					sItem = ds.Tables[0].Rows[i][ sColName.split(";")[0] ];//sAddToItem new
					var sSepJoinCol = "";
					if ( ds.Tables[0].Rows[i][ sColName.split(";")[1] ] != "" )
					{
						sSepJoinCol = " - ";
						if ( sColName.split(";").length > 2 )
							sSepJoinCol = sColName.split(";")[2];
					}
					//sItem = ds.Tables[0].Rows[i][ sColName.split(";")[0] ] + sSepJoinCol + ds.Tables[0].Rows[i][ sColName.split(";")[1] ];
					sAddToItem = sSepJoinCol + ds.Tables[0].Rows[i][ sColName.split(";")[1] ];
					sColName = sColName.split(";")[0];
				}
			}
			else
				sItem = "&nbsp;";
			if ( sItem == "undefined" )
			{
				alert( "sColName:" + sColName + " is undefined." );
				return;
			}
			else if ( ( aItems.length > 5 ) && (( aItems[5].toLowerCase() == "imagestatic" )||( aItems[5].toLowerCase() == "textstatic" )) )
			{
				sItem = sColName;
			}
			else if ( sItem == null )
			{
				sItem = "";
			}
			sItem = trimR( sItem );
// ** //if ( !bIsGroupByCollapsed )
{
			var sItemShowTip = sItem;
			var sOver = "";/** setting tooltip **/
			var sClickByTooltip = ""
			if ( ( aItems.length > 4 ) && ( sItem != "" ) && ( sItem.length > parseInt( aItems[4] ) ) )
			{
				if ( aItems[4].toLowerCase().indexOf( "tooltip" ) > 0 )
				{
					if ( sItem.length > 600 ) sItem = sItem.substring( 0, 600 ) + "<br><br>(Continue...)</b>";
					sItem = sItem.replace(/'/g, "&rsquo;");
					sItem = sItem.replace(/"/g, "&rsquo;");
					sItem = sItem.replace(/\’/g, "&rsquo;");
					sItem = sItem.replace(/\r\n/g, "<br>");
					sItem = sItem.replace(/\r/g, "<br>");
					sItem = sItem.replace(/\n/g, "<br>");
					sItem = sItem.replace(String.fromCharCode(10), "<br>");
					//sOver = ' onmouseover="showHelpTip(event, \''+sItem+'\',true,-1);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'hidden\');" onmouseout="showHelpTip(event, \'\',true);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'\');"';
					sOver = ' onmouseover="showHelpTip(event, \''+sItem+'\',true,-1);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'hidden\');" onmouseout="closeHelpTip(event);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'\');"';
					//sClickByTooltip = "showHelpTip(event, \'\',true);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'\');";
					sItemShowTip = sItem.substring( 0, parseInt( aItems[4] ) )+"...";
				}
				else if ( aItems[4].toLowerCase().indexOf( "space" ) > 0 )
				{
					sOver = '';
					sItemShowTip = insertSpace( sItemShowTip, parseInt( aItems[4] ) );
				}
			}
			var sAlignTd = "left";
			var sTypeOfDataInCell = "";
			if ( ( aItems.length > 5 ) && ( (sItem+"") != "" ) )//
			{
				/***************************/
				/** Decimal determination **/
				if ( aItems[5].toLowerCase().indexOf( "numeric" ) != -1 )
				{
					if ( aColumns!= null )
						aColumns[ sColName ]+= sItem;
					sAlignTd = "right";
					sItemShowTip = DecimalFormat( sItem/*iItem*/, aItems[5].split(":")[1]/*iCountDec*/ );
					if ( aItems[5].split(":").length > 2 )/* *insert sign ($ by example)* */
						sItemShowTip = aItems[5].split(":")[2]+sItemShowTip;
				}
				else if ( aItems[5].toLowerCase().indexOf( "date" ) != -1 )
				{
					if ( sItem == "01-01-1900" )
						sItemShowTip = "";
				}
				else if ( aItems[5].toLowerCase() == "image" )
				{
					sItemShowTip = "<img src='../Images/icons/" + sItem + "'>";
					sAlignTd = "center";
				}
				else if ( aItems[5].toLowerCase().indexOf( "custom:" ) == 0 )
				{
					var sFunctionNameToInjectCode = "";
					if ( aItems[5].toLowerCase().indexOf( "custom:" ) == 0 )
						sFunctionNameToInjectCode = aItems[5].split( ":" )[1];

					if ( sFunctionNameToInjectCode != "" )
					{
						var sParamInCustomFunction = "";
						sParamInCustomFunction = '\''+sColParam+'\' ';
						for ( var hh = 2; hh < aItemsFunction.length; hh++ )
						{
							sParamInCustomFunction += ', \'' + eval( "sColParam_" + hh ) + '\' ';
						}
						sParamInCustomFunction += ', \'' +sColFunction +'\', i ';

						sItemShowTip = eval( sFunctionNameToInjectCode + "( " + sParamInCustomFunction + " );" );
						sTypeOfDataInCell = "custom";
					}
					else
						sItemShowTip = "";
				}
				else if ( aItems[5].toLowerCase() == "imagestatic" )
				{
					sItemShowTip = "<img src='../Images/icons/" + aItems[0] + "'>";
					sAlignTd = "center";
				}
				else if ( aItems[5].toLowerCase() == "textstatic" )
				{
					sItemShowTip = aItems[0]+"";
					sAlignTd = "center";
				}
				else if ( ( aItems[5].split(":")[0].toLowerCase() == "checkbox" ) || ( aItems[5].split(":")[0].toLowerCase() == "radio" ) )
				{
					var sTypeCheckboxOrRadio = aItems[5].split(":")[0].toLowerCase();
					var aCheckAttributes = aItems[5].split(":");
					var sCheckName = "";
					if ( aCheckAttributes.length > 1 )
					{
						sCheckName = aCheckAttributes[1];
						if ( sCheckName.indexOf( "=" ) != -1 )//sItem = ds.Tables[0].Rows[i][ sColName ];
						{
							var sChNameText = sCheckName.split( "=" )[1];
							if ( sCheckName.indexOf( "+" ) != -1 )
							{
								var aChNameText = sChNameText.split("+");
								sCheckName = aChNameText[0] + ds.Tables[0].Rows[i][ aChNameText[1] ];
							}
							else
								sCheckName = ds.Tables[0].Rows[i][ sChNameText ];
						}
					}
					var sCheckId = sCheckName + "_" + sItem;
					if ( aCheckAttributes.length > 2 )
						if ( aCheckAttributes[2] != "" )
						{
							/**/sCheckId = "";
							if ( aCheckAttributes[2].indexOf( "+" ) != -1 )
							{
								sCheckId = aCheckAttributes[2].split( "+" )[0];
								aCheckAttributes[2] = aCheckAttributes[2].split( "+" )[1];
							}/**/
							var aIdsCheckboxs = aCheckAttributes[2].split( "$" );
							if ( aIdsCheckboxs.length == 1 )
								sCheckId+= ds.Tables[0].Rows[i][ aCheckAttributes[2] ];
							else
							{
								if ( aIdsCheckboxs[0].indexOf( "@" ) == 0 )
									sCheckId+= aIdsCheckboxs[0].split("@")[1] + ds.Tables[0].Rows[i][ aIdsCheckboxs[1] ];
								else
									sCheckId+= ds.Tables[0].Rows[i][ aIdsCheckboxs[0] ] + "_" + ds.Tables[0].Rows[i][ aIdsCheckboxs[1] ];
							}
						}
					var sCheckValue = sItem;
					if ( aCheckAttributes.length > 3 )
						if ( aCheckAttributes[3] != "" )
							sCheckValue = ds.Tables[0].Rows[i][ aCheckAttributes[3] ];

					var sCheckChecked = "";
					if ( aCheckAttributes.length > 4 )
						if ( aCheckAttributes[4] != "" )
							sCheckChecked = ds.Tables[0].Rows[i][ aCheckAttributes[4] ]; // checked | ""
							//sCheckChecked = (ds.Tables[0].Rows[i][ aCheckAttributes[4] ]=="Stopped")?"checked":""; // checked | ""
					var sCheckFunction = "";
					if ( aCheckAttributes.length > 5 )
						if (aCheckAttributes[5] != "")
                            {
                                if (aCheckAttributes[5].indexOf(";") != -1)
                                {
                                    var aCChangeFunction = aCheckAttributes[5].split(";");
                                    sCheckFunction = aCChangeFunction[0] + "(";
                                    for (var ihi = 1; ihi < aCChangeFunction.length; ihi++)
                                        sCheckFunction += "\"" + ds.Tables[0].Rows[i][aCChangeFunction[ihi]] + "\","
                                        sCheckFunction += "this, " + i + " );";
                                    }
                                else
                                    sCheckFunction = aCheckAttributes[5] + "( this, " + i + " );";
                            }
					var sCheckLabel = "";
					if ( aCheckAttributes.length > 6 )
						sCheckLabel = "<label for='" + sCheckId + "' style='cursor:hand;cursor:pointer;'>"+ ds.Tables[0].Rows[i][ aCheckAttributes[6] ] + "</label>";
					sItemShowTip = "<input type='" + sTypeCheckboxOrRadio + "' value='" + sCheckValue + "' name='" + sCheckName + "' id='" + sCheckId + "' onclick='" + sCheckFunction + "StopEvent(event);' " + sCheckChecked + ">";//"<img src='../Styles/" + sDefaultSkinName + "/icons/" + sItem + "'>";
					if ( sCheckLabel != "" )
						sItemShowTip= "<div style='float:left;'>" + sItemShowTip +"</div><div style='float:left;padding-top:4px;'>" + sCheckLabel + "</div>";
					sAlignTd = "center";
				}
				else if ( ( aItems[5].split(":")[0].toLowerCase() == "textbox" ) || ( aItems[5].split(":")[0].toLowerCase() == "hidden" ) || ( aItems[5].split(":")[0].toLowerCase() == "password" ))
				{
					var sTypeTextboxOrHidden = aItems[5].split(":")[0].toLowerCase();
					var aTextboxAttributes = aItems[5].split(":");
					var sTextboxName = "";
					if ( aTextboxAttributes.length > 1 )
					{
						sTextboxName = aTextboxAttributes[1];
						if ( sTextboxName.indexOf( "=" ) != -1 )
						{
							sTextboxName = sTextboxName.split( "=" )[1];
							var sTextboxPrefixName = "";
							if ( sTextboxName.indexOf( "+" ) != -1 )
							{
								sTextboxPrefixName = sTextboxName.split( "+" )[0];
								sTextboxName = sTextboxName.split( "+" )[1];
							}
							sTextboxName = sTextboxPrefixName + ds.Tables[0].Rows[i][ sTextboxName ];
						}
					}
					var sTextboxId = sTextboxName + "_" + sItem;
					if ( aTextboxAttributes.length > 2 )
						if ( aTextboxAttributes[2] != "" )
						{
							sTextboxId = "";
							if ( aTextboxAttributes[2].indexOf( "+" ) != -1 )
							{
								sTextboxId = aTextboxAttributes[2].split( "+" )[0];
								aTextboxAttributes[2] = aTextboxAttributes[2].split( "+" )[1];
							}
							var aIdsTextboxs = aTextboxAttributes[2].split( "$" );
							if ( aIdsTextboxs.length == 1 )
								sTextboxId+= ds.Tables[0].Rows[i][ aTextboxAttributes[2] ];
							else
								sTextboxId+= ds.Tables[0].Rows[i][ aIdsTextboxs[0] ] + "_" + ds.Tables[0].Rows[i][ aIdsTextboxs[1] ];
						}
					var sTextboxValue = sItem;
					if ( sColName == "" )
						sTextboxValue = "";
					if ( aTextboxAttributes.length > 3 )
						if ( aTextboxAttributes[3] != "" )
							sTextboxValue = ds.Tables[0].Rows[i][ aTextboxAttributes[3] ];
					var sTextboxDisabled = "";
					if ( aTextboxAttributes.length > 4 )
						if ( aTextboxAttributes[4] != "" )
							sTextboxDisabled = ds.Tables[0].Rows[i][ aTextboxAttributes[4] ];
					var sTextboxClass = "";
					if ( aTextboxAttributes.length > 5 )
						if ( aTextboxAttributes[5] != "" )
							sTextboxClass = aTextboxAttributes[5];
					var sTextboxWidth = "";
					if ( aTextboxAttributes.length > 6 )
						if ( aTextboxAttributes[6] != "" )
							sTextboxWidth = aTextboxAttributes[6];	
												
					var sTextboxChangeFunction = "";
					if ( aTextboxAttributes.length > 7 )
						if ( aTextboxAttributes[7] != "" )
						{
							if ( aTextboxAttributes[7].indexOf( ";" ) != -1 )
							{
								var aTChangeFunction = aTextboxAttributes[7].split( ";" );
								sTextboxChangeFunction = "onChange='" + aTChangeFunction[0] + "(";
								for( var ihi = 1; ihi < aTChangeFunction.length; ihi++)
								    sTextboxChangeFunction += "\"" + ds.Tables[0].Rows[i][aTChangeFunction[ihi]] + "\","
							    sTextboxChangeFunction+="this, " + i + " );'";
							}
							else
								sTextboxChangeFunction = "onChange='" + aTextboxAttributes[7] + "( this, " + i + " );'";
						}

					sItemShowTip = "<input type='" + sTypeTextboxOrHidden + "' value='" + sTextboxValue + "' name='" + sTextboxName + "' id='" + sTextboxId + "' " + sTextboxDisabled + " class='" + sTextboxClass + "' style='width:" + sTextboxWidth + ";' onclick='StopEvent(event);' " + sTextboxChangeFunction + ">";
					if ( sTypeTextboxOrHidden == "hidden" ) sItemShowTip+= "&nbsp;";
				}
			}
			if ( ( aItems.length > 6 ) && ( (sItem+"") != "" ) )
			{
				sAlignTd = aItems[6].toLowerCase();
			}
			var bPermissionC = true;
			if ( ( aItems.length > 7 ) && ( (sItem+"") != "" ) )//
			{
			/************************************/
			/* ***** condition in columns ***** */
				var sConditionFieldC;
				var sConditionTypeC = "";
				var sConditionValueC;
				var sConditionOperatorC = "==";
				var aRowConditionC = new Array();
				aRowConditionC = aItems[7].split( ":" );
				//sConditionFieldC = ds.Tables[0].Rows[i][ aRowConditionC[0] ];

				var aRowConditionFieldAndType = aRowConditionC[0].split('@');
				sConditionFieldC = ds.Tables[0].Rows[i][ aRowConditionFieldAndType[0] ];
				if ( aRowConditionFieldAndType.length > 1 )
					sConditionTypeC = aRowConditionFieldAndType[1];

				sConditionValueC = aRowConditionC[1];
				if (aRowConditionC.length > 2 )
					if ( aRowConditionC[2] != "" )
						sConditionOperatorC = aRowConditionC[2];
				bPermissionC = (sConditionFieldC == sConditionValueC);
				sConditionFieldC = (sConditionFieldC+"").replace(/'/g, "&rsquo;");
				sConditionFieldC = (sConditionFieldC+"").replace(/\’/g, "&rsquo;");
				sConditionValueC = (sConditionValueC+"").replace(/'/g, "&rsquo;");
				sConditionValueC = (sConditionValueC+"").replace(/\’/g, "&rsquo;");
				sConditionFieldC = unescape(escape(sConditionFieldC).replace(/\%0D\%0A/g, ""));
				sConditionFieldC = unescape(escape(sConditionFieldC).replace(/\%0D/g, ""));
				bPermissionC = eval( "'"+sConditionFieldC+"'" + sConditionOperatorC + "'"+sConditionValueC+"'");
			/* *** end condition in columns *** */
			/************************************/
			}
			/* ************************ */
			/* ***** click on row ***** */
			if ( aRowFunctions != null )
			{
				if ( aRowFunctions[0] != "" )
				{
					var aItemsFunctionOnRow = aRowFunctions[0].split( ";" );
					//sRowFunction = aItemsFunctionOnRow[0];
					sRowFunction = aItemsFunctionOnRow[0].split( ":" )[0];
					if ( aItemsFunctionOnRow[0].split( ":" ).length > 1 )
					{
						if ( aItemsFunctionOnRow[0].split( ":" )[1].split( "=" )[ 0 ] == "title" )
							sRowFunctionTitle = "title='" + aItemsFunctionOnRow[0].split( ":" )[1].split( "=" )[ 1 ] + "'";
					}
					sRowParam = ds.Tables[0].Rows[i][ aItemsFunctionOnRow[1] ];
					sRowParam = (sRowParam+"").replace(/'/g, "&rsquo;");
					sRowParam = (sRowParam+"").replace(/\’/g, "&rsquo;");
					for ( var hh = 2; hh < aItemsFunctionOnRow.length; hh++ )
					{
						eval( 'sRowParam_' + hh + ' = ds.Tables[0].Rows[i][ aItemsFunctionOnRow[' + hh + '] ]' );
						eval( "sRowParam_" + hh + " = (sRowParam_" + hh + " + '').replace(/'/g, '&rsquo;')" );
					}
				}
				else
				{
					sRowFunction = "";
					sRowParam = "";
					sRowParam_2 = "";
					sRowParam_3 = "";
					sClickTd = "";
				}
			}
			/***************************/
			if ( sRowFunction != "" )
			{
				sClickTd = ' onclick="' + sClickByTooltip + '' +sRowFunction+'(\''+sRowParam+'\' );return false;"';
			}
			if ( sRowParam_2 != "" )
			{
				sClickTd = ' onclick="'+sRowFunction+'(\''+sRowParam+'\' ';
				for ( var hh = 2; hh < aItemsFunctionOnRow.length; hh++ )
				{
					sClickTd += ', \'' + eval( "sRowParam_" + hh ) + '\' ';
				}
				sClickTd += ' );return false;"';
			}
			sClickTd = sRowFunctionTitle + sClickTd;
			if ( bPermissionC )
			{
				var sLinkInCell = "";
				if ( sTypeOfDataInCell != "custom" )
				{
				
					if ( sColFunction != "" )
					{
						sLinkInCell = '<a href="#" id="lnkOrderAndFilter_'+i+'" '+sColClassLinkColumn+' onclick="'+sColFunction+'(\''+sColParam+'\' ';
						for ( var hh = 2; hh < aItemsFunction.length; hh++ )
						{
							sLinkInCell += ', \'' + eval( "sColParam_" + hh ) + '\' ';
						}
						sLinkInCell += ', event, this );StopEvent( event );return false;">'+sItemShowTip+'</a>';
					}
					else
						sLinkInCell = sItemShowTip;
					aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>" + sAddBeforeToItem + ((sItemShowTip != "")? ( sLinkInCell ) : "&nbsp;") + sAddToItem + "</td>" );

				
				
					/*if ( sColParam_3 != ""  ) // with 3 params
						aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>" + ((sItemShowTip != "")? ( (sColFunction!="")?'<a href="#" onclick="'+sColFunction+'(\''+sColParam+'\',\''+sColParam_2+'\',\''+sColParam_3+'\', event, this );StopEvent( event );return false;">'+sItemShowTip+'</a>': sItemShowTip ) : "&nbsp;") + "</td>" );
					else if ( sColParam_2 != ""  ) // with 2 params
						aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>" + ((sItemShowTip != "")? ( (sColFunction!="")?'<a href="#" onclick="'+sColFunction+'(\''+sColParam+'\',\''+sColParam_2+'\', event, this );StopEvent( event );return false;">'+sItemShowTip+'</a>': sItemShowTip ) : "&nbsp;") + "</td>" );
					else // with 1 param
					{
						aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>" + sAddBeforeToItem + ((sItemShowTip != "")? ( (sColFunction!="")?'<a href="#" onclick="'+sColFunction+'(\''+sColParam+'\', event, this );StopEvent( event );return false;">'+sItemShowTip+'</a>': sItemShowTip ) : "&nbsp;") + sAddToItem + "</td>" );
					}*/
				}
				else
				{
					aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>" + sAddBeforeToItem + ((sItemShowTip != "")? sItemShowTip : "&nbsp;") + sAddToItem + "</td>" );
				}
			}
			else
			{
				if ( sConditionTypeC.toLowerCase() != "onlylink" )
					aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>"+ "&nbsp;" + "</td>" );
				else
				{
					aRow.push( "<td "+sClickTd+sOver+" align='"+sAlignTd+"' width='" + sColWidth + "'>"+ (( (sItemShowTip + sAddToItem) != "")? (sItemShowTip + sAddToItem) : "&nbsp;" ) + "</td>" );
				}
				
				
			}
}
			var bDoFilter = true;
			if ( aItems.length > 3 )
			{
				if ( aItems[3].toLowerCase() == "nofilter" )
					bDoFilter = false;
			}
			if ( ds.Tables[1] )
				if ( parseInt( ds.Tables[1].Rows[0][ sColName ] ) > iMaxFilter )
					bDoFilter = false;
			/* *********** Make filter array *********** */
			if ( bDoFilter )
			{
				if ( typeof( aFilterList[ sColName ] ) == "undefined" )
					aFilterList[ sColName ] = new Array();
				var sChar = "&";
				var sText = sChar + aFilterList[ sColName ].join( sChar ) + sChar;
				if (( sText.toLowerCase().indexOf( sChar + (sItem+"").toLowerCase() + sChar ) == -1 ) && (sItem !=""))
				{
					aFilterList[ sColName ].push( sItem );
				}
			}
			/* End Make filter array */
		}
// ** //if ( !bIsGroupByCollapsed )
{

		/* ************************* */
		/* ******* ACTIONS ********* */
		/* ************************* */
		if ( aRowFunctions != null )
			if ( aRowFunctions.length>1 != "" )
			{
				for ( var hh = 1; hh < aRowFunctions.length; hh++ )
				{
					var aItemsFunction = aRowFunctions[hh].split( ";" );
					sRowFunction = aItemsFunction[0];
					/**************************/
					/******* Parameters *******/
					var sRowParamAll = aItemsFunction[1];
					if ( sRowParamAll.indexOf(":") != -1 )
					{
						sRowParamId_1 = aItemsFunction[1].split(":")[0];
						sRowParamId_2 = aItemsFunction[1].split(":")[1];
						if ( aItemsFunction[1].split(":").length > 2 )
							sRowParamId_3 = aItemsFunction[1].split(":")[2];
					}
					else
					{
						sRowParamId_1 = aItemsFunction[1];
						sRowParamId_2 = "";
						sRowParamId_3 = "";
					}
					sRowParam = ds.Tables[0].Rows[i][ sRowParamId_1 ];
					sRowParam = (sRowParam+"").replace(/'/g, "&rsquo;");
					sRowParam = (sRowParam+"").replace(/\’/g, "&rsquo;");
					if ( sRowParamAll.indexOf(":") != -1 )
					{
						sRowParam_2 = ds.Tables[0].Rows[i][ sRowParamId_2 ];
						sRowParam_2 = (sRowParam_2+"").replace(/'/g, "&rsquo;");
						sRowParam_2 = (sRowParam_2+"").replace(/\’/g, "&rsquo;");
						if ( aItemsFunction[1].split(":").length > 2 )
						{
							sRowParam_3 = ds.Tables[0].Rows[i][ sRowParamId_3 ];
							sRowParam_3 = (sRowParam_3+"").replace(/'/g, "&rsquo;").replace(/\’/g, "&rsquo;");
						}
					}
					/******* End Parameters *******/
					/******************************/
					var sRowTitle = aItemsFunction[2];
					var sRowSrcImage = aItemsFunction[3];
					var sRowWidth = aItemsFunction[4];
					var aRowCondition = null;
					/********************/
					/***** condition ****/
					var sConditionField;
					var sConditionValue;
					var sConditionOperator = "==";
					var sConditionImage = "";
					var sConditionImageTitle = "";
					var bPermission = true;
					if (aItemsFunction.length > 5 )
					{
						aRowCondition = aItemsFunction[5].split( ":" );
						sConditionField = ds.Tables[0].Rows[i][ aRowCondition[0] ];
						sConditionValue = aRowCondition[1];
						if (aRowCondition.length > 2 )
							if ( aRowCondition[2] != "" )
								sConditionOperator = aRowCondition[2];
						bPermission = (sConditionField == sConditionValue);
						sConditionField = (sConditionField+"").replace(/'/g, "&rsquo;");
						sConditionValue = (sConditionValue+"").replace(/'/g, "&rsquo;");
						sConditionValue = (sConditionValue+"").replace(/\’/g, "&rsquo;");
						sConditionField = unescape(escape(sConditionField).replace(/\%0D\%0A/g, ""));
						sConditionField = unescape(escape(sConditionField).replace(/\%0D/g, ""));
						bPermission = eval( "'"+sConditionField+"'" + sConditionOperator + "'"+sConditionValue+"'");
						if (aRowCondition.length > 3 )
						{
							var aConditionImageAndTitle = aRowCondition[3].split( "*" );
							sConditionImage = aConditionImageAndTitle[0];
							if (aConditionImageAndTitle.length > 1 )
								sConditionImageTitle = aConditionImageAndTitle[1];
						}
					}
					/***** end condition ****/
					/************************/
					aRow.push( '<td width="'+sRowWidth+'" ' );
					if ( sClickTd != "" )
						aRow.push( sClickTd ); 
					aRow.push( 'align="center">' );
					var sMouseOverImage = "";
					var sClickImageOnly = "";
					
					if ( bPermission )
					{
						if ( sRowSrcImage != "" )
						{
							if ( ( sRowFunction != "" ) && ( sRowFunction.toLowerCase() != "tooltip" ) )
							{
								sClickImage = 'onclick="'+sRowFunction+'(\''+sRowParam+'\' );StopEvent(event);"';//return false;
								if ( sRowParam_2 != "" )
									sClickImage = 'onclick="'+sRowFunction+'(\''+sRowParam+'\', \''+sRowParam_2+'\' );StopEvent(event);"';//return false;
								if ( sRowParam_3 != "" )
									sClickImage = 'onclick="'+sRowFunction+'(\''+sRowParam+'\', \''+sRowParam_2+'\', \''+sRowParam_3+'\' );StopEvent(event);"';//return false;
								//aRow.push( '<a href="#" '+sClickImage+' title="'+sRowTitle+'">' );
								if ( sRowSrcImage.toLowerCase() != "onlytext" )
									aRow.push( '<input type="button" '+sClickImage+' title="'+sRowTitle+'" style="background:url(../Images/icons/'+sRowSrcImage+') no-repeat" class="imagelist">' );
								else
									aRow.push( '<a href="#" '+ sClickImage  +'>'+sRowTitle + '</a>' );
								////aRow.push( '<input type="button" '+sClickImage+' title="'+sRowTitle+'" class="imagelist2">' );
								//aRow.push( '<img ' + sMouseOverImage + sClickImageOnly + ' title="'+sRowTitle+'" border="0" align="absmiddle" src="../styles/'+sDefaultSkinName+'/icons/'+sRowSrcImage+'"/>' );
							}
							else
							{
								if ( sRowFunction.toLowerCase() == "tooltip" )
								{
									sRowParam = sRowParam.replace(/'/g, "&rsquo;");
									sRowParam = sRowParam.replace(/"/g, "&rsquo;");
									sRowParam = sRowParam.replace(/\’/g, "&rsquo;");
									sRowParam = unescape(escape(sRowParam).replace(/\%0D\%0A/g, "<br>"));
									sRowParam = unescape(escape(sRowParam).replace(/\%0D/g, "<br>"));
									sMouseOverImage = ' onmouseover="showHelpTip(event, \''+sRowParam+'\',true,null,this);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'hidden\');" onmouseout="showHelpTip(event, \'\',true);HideShowElement(\'SELECT\', document.getElementById(\'boxHelpTip\'),\'\');"';
									sClickImageOnly = ' onClick="StopEvent(event);return false;" ';
								}
								else
								{	
									sMouseOverImage = ' onMouseOver="this.style.cursor=\'default\';" ';
									sClickImageOnly = ' onClick="StopEvent(event);return false;" ';
								}
								aRow.push( '<img ' + sMouseOverImage + sClickImageOnly + ' title="'+sRowTitle+'" border="0" align="absmiddle" src="../Images/icons/'+sRowSrcImage+'"/>' );
							}
							//if ( ( sRowFunction != "" ) && ( sRowFunction.toLowerCase() != "tooltip" ) )
								//aRow.push( '</a>' );
						}
						else 
							aRow.push( '&nbsp;' );
					}
					else if ( sConditionImage != "" )/*If it contains an image when the condition is not true...*/
					{
						sMouseOverImage = ' onMouseOver="this.style.cursor=\'default\';" ';
						sClickImageOnly = ' onClick="StopEvent(event);return false;" ';
						aRow.push( '<img ' + sMouseOverImage + sClickImageOnly + ' title="'+sConditionImageTitle+'" border="0" align="absmiddle" src="../Images/icons/'+sConditionImage+'"/>' );
					}
					else 
					{
					
						aRow.push( '&nbsp;' );
						}
					aRow.push( '</td>' );
				}
			}
		aRow.push( "</tr>" );
		}/******* test *******/
}
		//if ( bAddRow ) 
		//	aText.push( aRow.join("") );
		if ((bIsGroupBy) || (bIsGroupByCollapsed))
		{
/************************* NEW GROUP BY X ******************************/
			aDataGroupBy[ sColumnValueOfGroupBy ].arrayText.push( aRow.join("") );
/////alert( sColumnValueOfGroupBy + " \n" + aDataGroupBy[ sColumnValueOfGroupBy ] );
/*********************** END NEW GROUP BY X **************************/
		}
		else
		{
			if ( bAddRow ) 
				aText.push( aRow.join("") );
		}
		bEvenRow = !bEvenRow;
	}
	
	
	
	
	
/************************* NEW GROUP BY X ******************************/
	if((bIsGroupBy) || (bIsGroupByCollapsed))
	//for ( var i = 0; i < aGroupByKey.length; i++ )
//if ( aGroupByKey == null ) aGroupByKey = aDataGroupBy;
for ( var i in aGroupByKey )
{
//alert( " i: " + i + " data: " + aGroupByKey[ i ] );
	if  ( typeof( aGroupByKey[ i ] ) == "string" )// no function as property of Array()
//for ( var i in aDataGroupBy )
	{
		var sColumnValueOfGroupBy = aGroupByKey[ i ];
//alert( sColumnValueOfGroupBy );
		if (!(( aDataGroupBy[ i ] == null ) && ( iPageNumber != null ) ))
		{
/* --*-- */
var aRow = OrderAndFilter.getRowTitle( aColumns, bIsGroupByCollapsed, aDataGroupBy, i, sNameDataGrid, iCountCollapsedSections, sColumnValueOfGroupBy, tblGroupByKey )
				if ( aDataGroupBy[ i ] != null )
				aText.push( aRow.join("") + aDataGroupBy[ i ].arrayText.join("") );
				else aText.push( aRow.join("") );

				iCountCollapsedSections++;
		}
	}
}
/*********************** END NEW GROUP BY X **************************/
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	aText.push( "</table>" );
	if ( ( iPageNumber != null ) )
	{
		var aRet = new Array( aText.join(""), sTextPages );
		return aRet;
	}
	else
		return sTextPagesDivCont + aText.join("");
}
OrderAndFilter.getRowTitle = function( aColumns, bIsGroupByCollapsed, aDataGroupBy, i, sNameDataGrid, iCountCollapsedSections, sColumnValueOfGroupBy, tblGroupByKey )
{
	var sClassNameForCollapsedSection = "";/* code Group By and Group By Two */
			var aRow = new Array();
				if ( i != 0 )
				{
					aRow.push( '</table>' );
					aRow.push('<table cellSpacing="0" cellPadding="0" width="100%" border="0">');

				}// * end collapse section * //
				//sColValueGroupBy_Before = sColValueGroupBy+""; // **old line** //
///////////////sColValueGroupBy_Before = sColValueGroupByToCompare+""; // **new line - more optimal** //
				//aRow.push( '<tr class="listsummarydivisor" valign="center" height="20">' );
				
				// * collapse section * //
				sClassNameForCollapsedSection = "listsummarydivisor";
				if ( (aColumns[ 1 ]+"").split( "," )[0].toLowerCase().indexOf( "groupby:" ) == 0 )
					sClassNameForCollapsedSection = "listitemuneven";

				var sClassNameByCollapse = "hide";
				var sTitleNameByCollapse = OrderAndFilter.sTextClickToExpand;
				var sTitleNameByCollapseWithoutItems = "Without items";
				if (!bIsGroupByCollapsed)
				{
					sClassNameByCollapse = "show";
					sTitleNameByCollapse = OrderAndFilter.sTextClickToCollapse;
				}
				aRow.push( '<tr class="'+ sClassNameForCollapsedSection +'" valign="center" height="20"');
				//aRow.push( ' onclick="GetElementById( \'tbl_' + i + '\' ).className=\'show\';">' );
				//if ( iColCountGroupBy != 0 )
				if ( aDataGroupBy[ i ] != null )
					aRow.push( ' title="'+sTitleNameByCollapse+'" onclick="CollapseOF(\'' + sNameDataGrid + iCountCollapsedSections + '\', this);" style="cursor:hand;cursor:pointer;">' );
				else
					aRow.push( ' title="'+ sTitleNameByCollapseWithoutItems + '" style="cursor:default;">' );
				///aRow.push( ' onclick="CollapseOF( \'tbl_' + i + '\' );" style="cursor:hand;cursor:pointer;">' );
				// * end collapse section * //
				
				aRow.push( "<td width=\"10\">&nbsp;</td>" );
				if ( tblGroupByKey != null )
				{
					for ( var k = 0; k < aCols.length; k++ )
					{
						var aItems = aCols[k].split( "," );
						if ( ( aItems[5].split(":")[0].toLowerCase() == "checkbox" ) || ( aItems[5].split(":")[0].toLowerCase() == "radio" ) )
						{
							aRow.push( "<td width=\"22\"><input type=checkbox></td>" );
						}
					}
				}
				//colspan var iColSpanGroupBy = aColumns.length + aRowFunctions.length - 1;
				//colspan aRow.push( '<td align="left" colspan="' + iColSpanGroupBy + '"> ' + sColValueGroupBy + '</td>' );
				aRow.push( '<td align="left"> ' + sColumnValueOfGroupBy + '</td>' );
				aRow.push( '</tr>' );
				
				// * collapse section * //
				aRow.push('</table><table id="tblCollpasedSection_' + sNameDataGrid + iCountCollapsedSections + '" cellSpacing="0" cellPadding="0" width="100%" border="0" class="'+sClassNameByCollapse+'">');
				//continue;
	return aRow;
}
function fnCheckbox( aItems )
{
	
					var sTypeCheckboxOrRadio = aItems[5].split(":")[0].toLowerCase();
					var aCheckAttributes = aItems[5].split(":");
					var sCheckName = "";
					if ( aCheckAttributes.length > 1 )
					{
						sCheckName = aCheckAttributes[1];
						if ( sCheckName.indexOf( "=" ) != -1 )//sItem = ds.Tables[0].Rows[i][ sColName ];
							sCheckName = ds.Tables[0].Rows[i][ sCheckName.split( "=" )[1] ];
					}
					var sCheckId = sCheckName + "_" + sItem;
					if ( aCheckAttributes.length > 2 )
						if ( aCheckAttributes[2] != "" )
						{
							var aIdsCheckboxs = aCheckAttributes[2].split( "$" );
							if ( aIdsCheckboxs.length == 1 )
								sCheckId = ds.Tables[0].Rows[i][ aCheckAttributes[2] ];
							else
							{
								if ( aIdsCheckboxs[0].indexOf( "@" ) == 0 )
									sCheckId = aIdsCheckboxs[0].split("@")[1] + ds.Tables[0].Rows[i][ aIdsCheckboxs[1] ];
								else
									sCheckId = ds.Tables[0].Rows[i][ aIdsCheckboxs[0] ] + "_" + ds.Tables[0].Rows[i][ aIdsCheckboxs[1] ];
							}
						}
					var sCheckValue = sItem;
					if ( aCheckAttributes.length > 3 )
						if ( aCheckAttributes[3] != "" )
							sCheckValue = ds.Tables[0].Rows[i][ aCheckAttributes[3] ];

					var sCheckChecked = "";
					if ( aCheckAttributes.length > 4 )
						sCheckChecked = ds.Tables[0].Rows[i][ aCheckAttributes[4] ]; // checked | ""
						//sCheckChecked = (ds.Tables[0].Rows[i][ aCheckAttributes[4] ]=="Stopped")?"checked":""; // checked | ""
					var sCheckFunction = "";
					if ( aCheckAttributes.length > 5 )
						sCheckFunction = aCheckAttributes[5] + "( this, " + i + " );";
					sItemShowTip = "<input type='" + sTypeCheckboxOrRadio + "' value='" + sCheckValue + "' name='" + sCheckName + "' id='" + sCheckId + "' onclick='" + sCheckFunction + "StopEvent(event);' " + sCheckChecked + ">";//"<img src='../Styles/" + sDefaultSkinName + "/icons/" + sItem + "'>";
					sAlignTd = "center";
}
/* Gets the title of the column from the title-code of one array column */
function GetTitleTextByTitleCode( array, sTitleCode )
{
	for( var i=0; i < array.length; i++ )
	{
		if ( array[i].indexOf( sTitleCode ) > 0 ) 
			return array[i].split(",")[0]
	}
	return "";
}
OrderAndFilter.ClassRowOrderFilter = function( bEvenRow )
{
	this.bEvenRow = bEvenRow;
	this.arrayText = new Array();
	return this;
}
