var _size = new Array();
var _filter = new Array();
var _firstResult = new Array();
var _maxResults = new Array();
var _orderColumn = new Array();
var _orderAsc = new Array();

// Esta função tem por objetivo exibir a quantidade de itens encontrados, bem como
// a posição (ou página) na qual o usuário se encontra e exibir links de navegação
// para as outras páginas. 
function createDisplayTableHeader(ID, size) {
	_size[ID] = size;
	
	DWRUtil.setValue(
		ID + '_PAGINATION',
		'<b>' +
			(_size[ID] > 1
				? 
					'Exibindo de ' + (_firstResult[ID] + 1) + ' a ' + (_firstResult[ID] + _maxResults[ID] > _size[ID] ? _size[ID] : _firstResult[ID] + _maxResults[ID]) + ' (de ' + _size[ID] + ' itens)<br>' +
					(hasPrevPage(ID)
						? '<a href="javascript:prevPage(\'' + ID + '\');">&lt;Prev</a>'
						: '&lt;Prev'
					) +
					' | ' +
					(hasNextPage(ID)
						? '<a href="javascript:nextPage(\'' + ID + '\');">Next&gt;</a>'
						: 'Next&gt;'
					)
				: _size[ID] > 0 ? 'Um item encontrado.' : 'Nenhum item encontrado.'
			) +
		'</b>',
		{escapeHtml:false}
	);
}

function hasPrevPage(ID) {
	return _firstResult[ID] > 0;
}

function prevPage(ID) {
	_firstResult[ID] -= _maxResults[ID];
	
	if (_firstResult[ID] < 0)
		_firstResult[ID] = 0;
	
	eval('filter_' + ID + '()');
}

function hasNextPage(ID) {
	return _firstResult[ID] + _maxResults[ID] < _size[ID];
}

function nextPage(ID) {
	_firstResult[ID] += _maxResults[ID];
	eval('filter_' + ID + '()');
}

function clearFilter(ID) {
	document.getElementById(ID + '_FILTER').value = '';
	eval('filter_' + ID + '()');
}

function rowCreator(options) {
	var row = document.createElement('tr');
	
	row.outBgColor = (options.rowIndex%2 == 0 ? '#FFFFFF' : '#F9F9F9');
	row.overBgColor = '#F1F1F1';
	
	row.bgColor = row.outBgColor;
	
	if (window.addEventListener) {
		row.addEventListener('mouseover', function(e) {row.bgColor = row.overBgColor;}, false);
		row.addEventListener('mouseout', function(e) {row.bgColor = row.outBgColor;}, false);
	} else {
		row.attachEvent('onmouseover', function(e) {row.bgColor = row.overBgColor;});
		row.attachEvent('onmouseout', function(e) {row.bgColor = row.outBgColor;});
	}
	
	return row;
}