WSGList.prototype = new Object();
WSGList.prototype.constructor = WSGList;
WSGList.superclass = null;

function WSGList() {
	this.results;
	this.currentPage = 1;
	this.order = 1;
	this.orderType = 1;
	this.totalPages = 1;	
	this.resultsPerPage = 10;
	this.controllerFirstButton = 'cFB_' + new WSGUtils().generateUUID();
	this.controllerPreviousButton = 'cPB_' + new WSGUtils().generateUUID();
	this.controllerNextButton = 'cNB_' + new WSGUtils().generateUUID();
	this.controllerLastButton = 'cLB_' + new WSGUtils().generateUUID();
	this.firstButtonPressed = 0;
	this.previousButtonPressed = 1;
	this.nextButtonPressed = 2;
	this.lastButtonPressed = 3;
	this._actionClass = null;
	this._layoutClass = null;
};
WSGList.prototype.setResults = function (results) {
	this.results = results;
	if (results != null && results.length > 0) {
		this.totalPages = Math.ceil(results.length / this.resultsPerPage);
	} else {
		this.totalPages = 1;
	}
};

WSGList.prototype.createController = function(id) {		
	var controller = document.getElementById(id);
	if (controller == undefined || controller == null || this.results == null || this.results.length == 0 || this.totalPages == 1) return;
	
	var str = new StringBuffer();
	var bundle = new WSGResourceBundle();
	
	str.append('<table cellpadding="0" cellspacing="0" border="0">');
	str.append('<tr>');
	if (this.currentPage > 1) {
		str.append('<td class="wsg-button"><img id="' + this.controllerFirstButton + '" src="' + wsgImagesLocation + 'list/btn_first.gif" alt="' + bundle.CONTROLLER_FIRST_PAGE + '" title="' + bundle.CONTROLLER_FIRST_PAGE + '" onclick="wsgList_' + this._actionClass.moduleNamespace + '.controllerEvent(' + this.firstButtonPressed + ');" border="0"></td>');	
		str.append('<td class="wsg-button"><img id="' + this.controllerPreviousButton + '" src="' + wsgImagesLocation + 'list/btn_previous.gif" alt="' + bundle.CONTROLLER_PREVIOUS_PAGE + '" title="' + bundle.CONTROLLER_PREVIOUS_PAGE + '" onclick="wsgList_' + this._actionClass.moduleNamespace + '.controllerEvent(' + this.previousButtonPressed + ');" border="0"></td>');
	} else {
		str.append('<td class="wsg-button"><img id="' + this.controllerFirstButton + '" src="' + wsgImagesLocation + 'list/btn_first.gif" alt="' + bundle.CONTROLLER_FIRST_PAGE + '" title="' + bundle.CONTROLLER_FIRST_PAGE + '" border="0"></td>');	
		str.append('<td class="wsg-button"><img id="' + this.controllerPreviousButton + '" src="' + wsgImagesLocation + 'list/btn_previous.gif" alt="' + bundle.CONTROLLER_PREVIOUS_PAGE + '" title="' + bundle.CONTROLLER_PREVIOUS_PAGE + '" border="0"></td>');		
	}	
	str.append('<td class="wsg-button-label" nowrap="nowrap">' + this.currentPage + ' / ' + this.totalPages + '</td>');
	if (this.currentPage < this.totalPages && this.totalPages > 1) {
		str.append('<td class="wsg-button"><img id="' + this.controllerNextButton + '" src="' + wsgImagesLocation + 'list/btn_next.gif" alt="' + bundle.CONTROLLER_NEXT_PAGE + '" title="' + bundle.CONTROLLER_NEXT_PAGE + '" onclick="wsgList_' + this._actionClass.moduleNamespace + '.controllerEvent(' + this.nextButtonPressed + ');" border="0"></td>');										
		str.append('<td class="wsg-button"><img id="' + this.controllerLastButton + '" src="' + wsgImagesLocation + 'list/btn_last.gif" alt="' + bundle.CONTROLLER_LAST_PAGE + '" title="' + bundle.CONTROLLER_LAST_PAGE + '" onclick="wsgList_' + this._actionClass.moduleNamespace + '.controllerEvent(' + this.lastButtonPressed + ');" border="0"></td>');
	} else {
		str.append('<td class="wsg-button"><img id="' + this.controllerNextButton + '" src="' + wsgImagesLocation + 'list/btn_next.gif" alt="' + bundle.CONTROLLER_NEXT_PAGE + '" title="' + bundle.CONTROLLER_NEXT_PAGE + '" border="0"></td>');										
		str.append('<td class="wsg-button"><img id="' + this.controllerLastButton + '" src="' + wsgImagesLocation + 'list/btn_last.gif" alt="' + bundle.CONTROLLER_LAST_PAGE + '" title="' + bundle.CONTROLLER_LAST_PAGE + '" border="0"></td>');		
	}
	str.append('</tr>');
	str.append('</table>');
	controller.innerHTML = str.toString();	
	this.updateControllerState();
};

WSGList.prototype.controllerEvent = function (action) {
	switch (action) {
		case this.firstButtonPressed: {
			this.currentPage = 1;	
			break;
		}
		case this.previousButtonPressed: {
			if (this.currentPage > 1) {
				this.currentPage -= 1;
			}
			break;
		}
		case this.nextButtonPressed: {
			if (this.currentPage < this.totalPages) {
				this.currentPage += 1;
			}
			break;
		}
		case this.lastButtonPressed: {
			this.currentPage = this.totalPages;
			break;
		}		
	}		
	this._actionClass.changePage(this.currentPage);
};

WSGList.prototype.updateControllerState = function() {
	if (this.currentPage == 1) {
		new WSGDOMObject(document.getElementById(this.controllerFirstButton)).setCustomDisabledAlphaNotAllowedCursor(70);
		new WSGDOMObject(document.getElementById(this.controllerPreviousButton)).setCustomDisabledAlphaNotAllowedCursor(70);						
	} 
	if (this.currentPage == this.totalPages || this.totalPages == 1) {
		new WSGDOMObject(document.getElementById(this.controllerNextButton)).setCustomDisabledAlphaNotAllowedCursor(70);
		new WSGDOMObject(document.getElementById(this.controllerLastButton)).setCustomDisabledAlphaNotAllowedCursor(70);								
	}
};

WSGList.prototype.destroyController = function (id) {
	if (document.getElementById(id) != undefined) {
		document.getElementById(id).innerHTML = "";		
	}
};
