dojo.require("dojo.dnd.Moveable");
WSGWindow.prototype = new Object();
WSGWindow.prototype.constructor = WSGWindow;
WSGWindow.superclass = null;

function WSGWindow(windowId, title, width, height, depth, closeFunctionName) {
	this.id = windowId;
	this.tableId = _wsgUtils.generateUUID();
	this.bodyId = _wsgUtils.generateUUID();
	this.title = title;
	this.width = width;
	this.height = height;
	this.depth = depth;
	this.closeFunctionName = closeFunctionName;
	this.clickedOnWindowTitleBar = false;	
};

WSGWindow.prototype.buildWindowFrame = function(showDivBorder) {
	var bundle = new WSGResourceBundle();
	var sb = new StringBuffer();
	sb.append('<table id="' + this.tableId + '" cellpadding="0" cellspacing="0" border="0" align="center">');
		sb.append('<tr>');
			sb.append('<td width="100%">');
				sb.append('<table cellpadding="0" cellspacing="0" border="0" width="' + ((this.width != null) ? this.width : "100%") + '">');
				
				// WINDOW HEADER	
				
					sb.append('<tr>');
						sb.append('<td><img src="' + wsgImagesLocation + 'window_header_l.png" width="9" border="0"/></td>');
						sb.append('<td onmouseover="new WSGDOMObject(this).setMoveCursor();"; onmousedown="this.clickedOnWindowTitleBar=true;" onmouseup="this.clickedOnWindowTitleBar=false;" id="wTh_' + this.id + '" class="window-header-bg">');
							sb.append('<table cellpadding="0" cellspacing="0" border="0" width="100%">');
								sb.append('<tr>');
									sb.append('<td width="50%" align="left" class="window-title" style="padding-top: ' + ((_mozilla) ? 1 : 2) + 'px;" nowrap="nowrap">&nbsp;');
									sb.append(this.title);
									sb.append('</td>');
									sb.append('<td width="50%" align="right" class="window-title" style="padding-top: ' + ((_mozilla) ? 0 : 2) + 'px;" nowrap="nowrap">&nbsp;<span title="' + bundle.WINDOW_CLOSE + '" onmouseover="this.style.textDecoration=\'underline\'; this.style.cursor=\'pointer\'" onmouseout="this.style.textDecoration=\'none\';" onclick="' + ((this.closeFunctionName != null) ?  this.closeFunctionName : ' var _wind = new WSGWindow(); _wind.closeDefaultButton(\'' + this.id + '\', \'' + this.width + '\');') + '">' + bundle.WINDOW_CLOSE +' [x]</span>&nbsp;&nbsp;</td>');
								sb.append('</tr>');
							sb.append('</table>');
						sb.append('</td>');
						sb.append('<td><img src="' + wsgImagesLocation + 'window_header_r.png" width="9" border="0"/></td>');					
					sb.append('</tr>');

				// END WINDOW HEADER	
					
				// WINDOW BODY
					
					sb.append('<tr valign="top">');
						sb.append('<td width="9" class="window-border-l"></td>');							
						sb.append('<td width="100%">');
							sb.append('<table cellpadding="0" cellspacing="0" border="0" width="100%" bgcolor="#FFFFFF">');	
								sb.append('<tr valign="top"><td height="10"><img src="' + wsgImagesLocation + 'blank.gif" height="10" border="0"/></td></tr>');
								sb.append('<tr valign="top">');
									sb.append('<td width="16"><img src="' + wsgImagesLocation + 'blank.gif" width="16" border="0"/></td>');
									sb.append('<td width="100%">');
										sb.append('<div id="'+ this.bodyId + '" style="overflow: auto;');
//										sb.append('<div id="'+ this.bodyId + '" style="overflow: auto;' + ((this.height != null) ? "height:" + this.height + "px;\"" : ""));
										if (showDivBorder) {
											sb.append(' border-right:1px solid #AAAAAA; border-left:1px solid #AAAAAA;');
										}
										sb.append('"></div>');
									sb.append('</td>');
									sb.append('<td width="16"><img src="' + wsgImagesLocation + 'blank.gif" width="16" border="0"/></td>');								
								sb.append('</tr>');
								sb.append('<tr valign="top"><td height="10"><img src="' + wsgImagesLocation + 'blank.gif" height="10" border="0"/></td></tr>');
							sb.append('</table>');	
						sb.append('</td>');
						sb.append('<td width="9" class="window-border-r" align="right"></td>');
					sb.append('</tr>');

				// END WINDOW BODY
				
				// WINDOW FOOTER

					sb.append('<tr valign="top">');					
					sb.append('<td><img src="' + wsgImagesLocation + 'window_bottom_l.png" width="9" height="9" border="0"/></td>');
					sb.append('<td class="window-border-b"></td>');
					sb.append('<td><img src="' + wsgImagesLocation + 'window_bottom_r.png" width="9" height="9" border="0"/></td>');
					sb.append('</tr>');

				// END WINDOW FOOTER
					
				sb.append('</table>');
			sb.append('</td>');	
		sb.append('</tr>');
	sb.append('</table>');
	return sb.toString();
};

WSGWindow.prototype.create = function () {		
	this.createDIV();
	var window = document.getElementById(this.id);
	window.innerHTML = this.buildWindowFrame(false);			
};

WSGWindow.prototype.align = function() {
	var obj = document.getElementById(this.id);
	var bd = new BrowserDimensions();
	
	var maxX = bd.getScrollFromLeft() + bd.getViewableAreaWidth();
	var maxY = bd.getScrollFromTop() + bd.getViewableAreaHeight();

	var windowWidth = document.getElementById(this.tableId).offsetWidth;
	var windowHeight = document.getElementById(this.tableId).offsetHeight;
	this.width = windowWidth;
	this.height = windowHeight;	
	var offset = (bd.getScrollFromTop() > 0) ? 40 : 80;
	//var offset = (bd.getScrollFromTop() > 0 || Math.abs((maxY - this.height)) < 80) ? 40 : 80;	
	
	obj.x = parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10); 
	obj.y = Math.abs((parseInt(maxY)/2) - (windowHeight/2) - offset);			
	obj.style.left = (parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10)) + "px";
	obj.style.top = Math.abs(((parseInt(maxY)/2) - (windowHeight/2) - offset)) + "px";
	
	obj.style.top = (parseFloat(obj.style.top) + 50) + 'px';
	obj.style.top = (parseFloat(obj.style.top) + 50) + 'px';
	
	if ((maxY - this.height) < 0) {
		obj.y = 0;
		obj.style.top = "0px";
	}
};

WSGWindow.prototype.simpleAlign = function(id, tableId) {	
	if (_ie || _ns6){
		var obj = document.getElementById(id);			
		// SHOW FOR A WHILE IN ORDER TO RETREIVE THE REAL WIDTH...
		new WSGDOMObject(obj).display();
		this.reAlign(id, tableId);		
		this.makeMoveable(tableId, 'wTh_' + id);				
	}
};

WSGWindow.prototype.reAlign = function(id, tableId) {
	var obj = document.getElementById(id);
	var bd = new BrowserDimensions();
	
	var maxX = bd.getScrollFromLeft() + bd.getViewableAreaWidth();
	var maxY = bd.getScrollFromTop() + bd.getViewableAreaHeight();

	var windowWidth = document.getElementById(tableId).offsetWidth;
	var windowHeight = document.getElementById(tableId).offsetHeight;
	var offset = (bd.getScrollFromTop() > 0 || Math.abs((maxY - windowHeight)) < 80) ? 40 : 80;	
	
	obj.x = parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10); 
	obj.y = Math.abs((parseInt(maxY)/2) - (windowHeight/2) - offset);			
	obj.style.left = (parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10)) + "px";
	obj.style.top = Math.abs(((parseInt(maxY)/2) - (windowHeight/2) - offset)) + "px";
	if ((maxY - windowHeight) < 0) {
		obj.y = 0;
		obj.style.top = "0px";
	}
};

//WSGWindow.prototype.show = function() {
//	if (_ie || _ns6){
//		var obj = document.getElementById(this.id);
//		var bd = new BrowserDimensions();
//		var maxX = bd.getScrollFromLeft() + bd.getViewableAreaWidth();
//		var maxY = bd.getScrollFromTop() + bd.getViewableAreaHeight();
//		// SHOW FOR A WHILE IN ORDER TO RETREIVE THE REAL WIDTH...
//		new WSGDOMObject(obj).display();
//		var windowWidth = document.getElementById(this.tableId).offsetWidth;
//		var windowHeight = document.getElementById(this.tableId).offsetHeight;
//		new WSGDOMObject(obj).displayNone();
//		this.width = windowWidth;
//		this.height = windowHeight;
//		var offset = (bd.getScrollFromTop() > 0) ? 40 : 80;
//		
//		obj.x = parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10); 
//		obj.y = Math.abs((parseInt(maxY)/2) - (windowHeight/2) - offset);	
//		obj.style.left = (parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10)) + "px";
//		obj.style.top = Math.abs(((parseInt(maxY)/2) - (windowHeight/2) - offset)) + "px";		
//		
//		this.makeMoveable(this.tableId, 'wTh_' + this.id);		
//		if (_wsgWindowFadeAnimation) {
//			new WSGDOMObject(obj).setAlpha(0);
//			new WSGDOMObject(obj).display();
//			obj.style.top = (parseFloat(obj.style.top) + 50) + 'px';
//			obj.style.top = (parseFloat(obj.style.top) + 50) + 'px';
//			this.showFadeIn();
//		} else {
//			new WSGDOMObject(obj).display();
//			_wsgBlockerObject.show();
//		}		
//		_eventListener.registerWindow(this);
//		_eventListener.releaseClickEvent();		
//	}
//};

WSGWindow.prototype.show = function() {	
	if (_ie || _ns6){
		var obj = document.getElementById(this.id);			
		// SHOW FOR A WHILE IN ORDER TO RETREIVE THE REAL WIDTH...
		new WSGDOMObject(obj).display();
		this.align();
		new WSGDOMObject(obj).displayNone();
		
		this.makeMoveable(this.tableId, 'wTh_' + this.id);		
		if (_wsgWindowFadeAnimation) {
			new WSGDOMObject(obj).setAlpha(0);			
			new WSGDOMObject(obj).display();
			this.showFadeIn();
		} else {			
			new WSGDOMObject(obj).display();
			_wsgBlockerObject.show();
		}
		_eventListener.registerWindow(this);
		_eventListener.releaseClickEvent();	
	}
};

WSGWindow.prototype.showContent = function(id, content) {
	new WSGDOMObject(document.getElementById(id)).setAlpha(0);
	document.getElementById(id).innerHTML = content;
	new WSGWindow().fadeInContent(id);	
};

WSGWindow.prototype.fadeInContent = function(id) {
	var element = document.getElementById(id);
	if (element == null) return;	 
    setTimeout("new WSGWindow().animateFadeInContent('" + id + "')", 10);	  	
};

WSGWindow.prototype.animateFadeInContent = function (id) {
	var element = document.getElementById(id);
	
	if (element.style.opacity == 1 || element.style.opacity >= 0.95) {
	    element.style.opacity = 1;
	    element.style.filter = 'alpha(opacity = 100)';	    
	    return;
	}
	
	var currentOpVal = parseFloat(element.style.opacity);
	var newOpVal = (currentOpVal == 0.9 || currentOpVal == 0.95) ? currentOpVal + 0.05 : currentOpVal + 0.1;	
	if (currentOpVal == 0.9 || currentOpVal == 0.95) {
		newOpVal = Math.round(newOpVal * 100) / 100;
	} else {
		newOpVal = Math.round(newOpVal * 10) / 10;
	}
	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
	setTimeout("new WSGWindow().animateFadeInContent('" + id + "')", 33);
};

WSGWindow.prototype.showFadeIn = function() {
	var element = document.getElementById(this.id);
	if (element == null) return;	 
	_windowTimeOut = setTimeout("new WSGWindow().animateFadeIn('" + this.id + "')", 10);	  
};

WSGWindow.prototype.animateFadeIn = function (id) {
	var element = document.getElementById(id);
	if (element == undefined || element == null) {
		clearTimeout(_windowTimeOut);
		return;
	}
	if (parseFloat(element.style.top) > 60) {
		tmp = parseFloat(element.style.top) - 5;
		element.style.top = tmp + 'px';		
	}
	if (element.style.opacity == 1 || element.style.opacity >= 0.95) {
	    element.style.opacity = 1;
	    element.style.filter = 'alpha(opacity = 100)';
	    _wsgBlockerObject.show();
	    clearTimeout(_windowTimeOut);
	    return;
	}
	
	var currentOpVal = parseFloat(element.style.opacity);
	var newOpVal = (currentOpVal == 0.9 || currentOpVal == 0.95) ? currentOpVal + 0.05 : currentOpVal + 0.1;	
	if (currentOpVal == 0.9 || currentOpVal == 0.95) {
		newOpVal = Math.round(newOpVal * 100) / 100;
	} else {
		newOpVal = Math.round(newOpVal * 10) / 10;
	}
	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
	_windowTimeOut = setTimeout("new WSGWindow().animateFadeIn('" + id + "')", 33);
};

WSGWindow.prototype.closeDefaultButton = function(id) {
	this.fadeOut(id, false);
};

WSGWindow.prototype.close = function(id) {
	this.fadeOut(id, false);
};

WSGWindow.prototype.fadeOut = function(id, animate) {
	var element = document.getElementById(id);
	if (element == null) return;	  		
	if (!_wsgWindowFadeAnimation) new WSGWindow().destroy(id); 
	var stepX = 0;
	var stepY = 0;
	if (animate) {
		// CALCULATE STEPS...
		new WSGDOMObject(document.getElementById(id)).displayNone();
		new WSGDOMObject(document.getElementById(id)).display();
		var window = _eventListener.getWindow(id);
		var bd = new BrowserDimensions();
		var maxX = bd.getScrollFromLeft() + bd.getViewableAreaWidth();	
		var maxY = bd.getScrollFromTop() + bd.getViewableAreaHeight();
		var windowWidth = document.getElementById(window.tableId).offsetWidth;
		var windowRightX = ((parseInt(maxX/2, 10) - parseInt(windowWidth/2, 10)) + windowWidth);	
		var windowTopY = _wsgUtils.getY(document.getElementById(id));
		var trashObjectX = new WSGTrashObject().getX();
		var maxViewX = (maxX < trashObjectX) ? maxX : trashObjectX;
		var maxViewY = (bd.getScrollFromTop() > 0) ? 0 : windowTopY; 	
		stepX = (maxViewX - windowRightX) / 10;
	 	stepY = maxViewY / 10;	 	
//	 	alert("windowRightX = " + windowRightX + ",windowTopY=" + windowTopY + ",trashObjectX=" + trashObjectX + ", maxY = "  + maxY + ", maxX = " + maxX + ", maxViewX = " + maxViewX);
//		alert("stepX = " + stepX + ", stepY = " + stepY);
	 	
	 	if (stepY == 0 || stepX == 0) {
	 		stepY = 0;
	 		stepX = 0; 		
	 	}
	}
	_windowTimeOut = setTimeout("new WSGWindow().animateFadeOut('" + id + "'," + stepX + "," + stepY + ")", 10);
};

WSGWindow.prototype.animateFadeOut = function (id, stepX, stepY) {
	var element = document.getElementById(id);
	if (element == undefined || element == null) {
		clearTimeout(_windowTimeOut);
		return;
	}
	
	if (stepX != 0 && stepY != 0) {
		if (parseFloat(element.style.left) < parseFloat(new WSGTrashObject().getX())) {		
			tmp = parseFloat(element.style.left) + stepX;
			element.x = tmp; 
			element.style.left = tmp + 'px';		
		}
		if (parseFloat(element.style.top) > 0) {
			tmp = parseFloat(element.style.top) - stepY;
			element.y = tmp;	
			element.style.top = tmp + 'px';		
		}
	}
	if (element.style.opacity == 0.1) {
		element.style.opacity = '0';
		element.style.filter = 'alpha(opacity = 0)';
		new WSGWindow().destroy(id);
		clearTimeout(_windowTimeOut);
		return;
	}
	var currentOpVal = parseFloat(element.style.opacity);
	var newOpVal = (currentOpVal == 1 || currentOpVal == 0.95) ? currentOpVal - 0.05 : currentOpVal - 0.1;	
	if (currentOpVal == 1 || currentOpVal == 0.95) {
		newOpVal = Math.round(newOpVal * 100) / 100;
	} else {
		newOpVal = Math.round(newOpVal * 10) / 10;
	}
	element.style.opacity = newOpVal;
	element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
	
	if (element.style.opacity == 0) {
		new WSGWindow().destroy(id);
		clearTimeout(_windowTimeOut);
		return;		
	}
	_windowTimeOut = setTimeout("new WSGWindow().animateFadeOut('" + id + "'," + stepX + "," + stepY + ")", 33);
};

WSGWindow.prototype.makeMoveable = function(node){
	var dnd = new dojo.dnd.Moveable(dojo.byId(node));
};
WSGWindow.prototype.makeMoveable = function (node, _handle){
	var dnd = new dojo.dnd.Moveable(dojo.byId(node), {handle: _handle});
};

WSGWindow.prototype.createDIV = function() {
	var newdiv = document.createElement('div');
	newdiv.setAttribute('id', this.id);
	newdiv.style.position = "absolute";
	newdiv.style.zIndex = this.depth;
	newdiv.style.left = "0px";
	newdiv.style.top = "0px";
	newdiv.x = 0; 
	newdiv.y = 0;			
	document.body.appendChild(newdiv);
	new WSGDOMObject(newdiv).displayNone();
};

WSGWindow.prototype.destroy = function(id) {
	try {				
		document.body.removeChild(document.getElementById(id));		
	} catch (e) {}
	_eventListener.releaseWindow(id);
	_wsgBlockerObject.hide();
};

WSGWindow.prototype.showMessageWindow = function(type, text, focusField) {
	var windowId = _wsgUtils.generateUUID();
	var window = new WSGWindow(windowId, "", 500, null, 200, null);
	window.create();
	document.getElementById(window.bodyId).innerHTML = new WSGLayout().getMessage(type, text);
	document.getElementById(window.bodyId).innerHTML += new WSGLayout().getDefaultCloseButton(windowId, focusField);
	window.show();		
};
WSGWindow.prototype.showConfirmMessageWindow = function(type, text, func) {
	var bundle = new WSGResourceBundle();
	var width = 500;
	if ((parseFloat(text.length) * 10) > 500) {
		width = (parseFloat(text.length) * 10);
	}
	if ((parseFloat(text.length) * 10) > 1000) {
		width = 900;
	}
	var windowId = _wsgUtils.generateUUID();
	var window = new WSGWindow(windowId, "", width, null, 200, null);
	window.create();
	document.getElementById(window.bodyId).innerHTML = new WSGLayout().getMessage(type, text);
	document.getElementById(window.bodyId).innerHTML += new WSGLayout().getSpace(5) + new WSGLayout().getButtons('windowId', new Array(bundle.BUTTON_LABEL_YES, bundle.BUTTON_LABEL_NO), new Array(func, 'new WSGWindow().closeDefaultButton(\'windowId\');'), false);
	window.show();		
};

WSGResultNavigator.prototype = new Object();
WSGResultNavigator.prototype.constructor = WSGResultNavigator;
WSGResultNavigator.superclass = null;

function WSGResultNavigator(instanceId) {
	this.bundle = new WSGResourceBundle(); 
	this.navigatorHeaderFirstButton = 'nHFB_' + _wsgUtils.generateUUID();
	this.navigatorHeaderLeftButton = 'nHFLeftB_' + _wsgUtils.generateUUID();
	this.navigatorHeaderRightButton = 'nHRB_' + _wsgUtils.generateUUID();
	this.navigatorHeaderLastButton = 'nHLastB_' + _wsgUtils.generateUUID();
	this.navigatorHeaderGoButton = 'nHGB_' + _wsgUtils.generateUUID();
	this.navigatorHeaderGoField = 'nHGF_' + _wsgUtils.generateUUID();
	this.navigatorFooterFirstButton = 'nFFB_' + _wsgUtils.generateUUID();
	this.navigatorFooterLeftButton = 'nFFLeftB_' + _wsgUtils.generateUUID();
	this.navigatorFooterRightButton = 'nFRB_' + _wsgUtils.generateUUID();
	this.navigatorFooterLastButton = 'nFLastB_' + _wsgUtils.generateUUID();
	this.navigatorFooterGoButton = 'nFGB_' + _wsgUtils.generateUUID();
	this.navigatorFooterGoField = 'nFGF_' + _wsgUtils.generateUUID();
	this.navigatorFirstButtonPressed = 0;
	this.navigatorLeftButtonPressed = 1;
	this.navigatorRightButtonPressed = 2;
	this.navigatorLastButtonPressed = 3;
	this.navigatorGoButtonHeaderPressed = 4;	
	this.navigatorGoButtonFooterPressed = 5;
	this.currentPage = 1;
	this.totalPages = 1;	
	this.results = null;
	this.resultsPerPage = 10;
	this.resultFunction = null;
	
	this.currentPageLabelIdHeader = 'cPLIdH_' + _wsgUtils.generateUUID();
	this.currentPageLabelIdFooter = 'cPLIdF_' + _wsgUtils.generateUUID();
	this.currentPageIdHeader = 'cPIdH_' + _wsgUtils.generateUUID();
	this.currentPageIdFooter = 'cPIdF_' + _wsgUtils.generateUUID();
	this.gotoPageLabelHeader = 'nGtPIdH_' + _wsgUtils.generateUUID();
	this.gotoPageLabelFooter = 'nGtPIdF_' + _wsgUtils.generateUUID();
	this.tableHeight = null;
	this.bodyId = null;
	this.instanceId = instanceId;
	
	this.imagesLocation = wsgImagesLocation + "navigator/";
	this.buttonFirstImage = "button_first.gif";
	this.buttonLeftImage = "button_left.gif";
	this.buttonRightImage = "button_right.gif";
	this.buttonLastImage = "button_last.gif";
	this.buttonGoToImage = "button_go.gif";
		
};

WSGResultNavigator.prototype.setTableHeight = function (height) {
	this.tableHeight = height;
};

WSGResultNavigator.prototype.create = function() {
	var sb = new StringBuffer();
	this.bodyId = _wsgUtils.generateUUID();
	sb.append('<table cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF" width="100%">');
		sb.append('<tr class="navigator-top">');
			sb.append('<td width="6"><img src="' + wsgImagesLocation + 'navigator/top_l.gif" border="0" width="6"/></td>');
			sb.append('<td width="100%" class="navigator-top" align="left">');
				sb.append('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
					sb.append('<tr>');	
						sb.append('<td align="right" width="100%" class="textb">');
						sb.append(this.getNavigator("header"));
						sb.append('</td>');		
					sb.append('</tr>');							
				sb.append('</table>');
			sb.append('</td>');
			sb.append('<td width="6" align="right"><img src="' + wsgImagesLocation + 'navigator/top_r.gif" border="0" width="6"/></td>');
		sb.append('</tr>');
		sb.append('<tr valign="top">');
//			sb.append('<td width="100%" id="' + this.bodyId + '" style="border-left:1px solid #A9A9A9; border-right:1px solid #A9A9A9;" colspan="3" class="text11" height="' + ((this.tableHeight != null) ? this.tableHeight-56 : "100%") + '"></td>');
			sb.append('<td width="100%" colspan="3">');
				sb.append('<table cellspacing="0" cellpadding="0" border="0" width="100%" style="border-left:1px solid #A9A9A9; border-right:1px solid #A9A9A9;"><tr valign="top"><td id="' + this.bodyId + '" class="text11" height="' + ((this.tableHeight != null) ? this.tableHeight-56 : "100%") + '" style="background-color:#FFFFFF;"></td></tr></table>');
			sb.append('</td>');
		sb.append('</tr>');
		sb.append('<tr valign="middle" class="navigator-bottom">');	
			sb.append('<td width="6"><img src="' + wsgImagesLocation + 'navigator/bottom_l.gif" border="0" width="6"/></td>');
			sb.append('<td width="100%" class="navigator-bottom" align="left">');
				sb.append('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
					sb.append('<tr valign="middle">');	
						sb.append('<td align="right" width="100%" class="textb">');
						sb.append(this.getNavigator("footer"));
						sb.append('</td>');		
					sb.append('</tr>');							
				sb.append('</table>');
			sb.append('</td>');
			sb.append('<td width="6" align="right"><img src="' + wsgImagesLocation + 'navigator/bottom_r.gif" border="0" width="6"/></td>');
		sb.append('</tr>');				
	sb.append('</table>');	
	sb.append('</td>');
	sb.append('</tr>');	
	sb.append('</table>');
	
	return sb.toString();
};

WSGResultNavigator.prototype.getNavigator = function(type) {
	var sb = new StringBuffer();
	
	var className = 'navigator-control-text';
	var navigatorFirstButton = this.navigatorHeaderFirstButton;
	var navigatorLeftButton = this.navigatorHeaderLeftButton;
	var navigatorRightButton = this.navigatorHeaderRightButton;
	var navigatorLastButton = this.navigatorHeaderLastButton;
	var navigatorGoField = this.navigatorHeaderGoField;
	var navigatorGoButton = this.navigatorHeaderGoButton;
	var gotoPageLabel = this.gotoPageLabelHeader;
	var currentPageId = this.currentPageIdHeader;
	var currentPageLabelId = this.currentPageLabelIdHeader;
	var navigatorGoButtonPressed = this.navigatorGoButtonHeaderPressed;
	
	if ("footer" == type) {
		navigatorFirstButton = this.navigatorFooterFirstButton;
		navigatorLeftButton = this.navigatorFooterLeftButton;
		navigatorRightButton = this.navigatorFooterRightButton;
		navigatorLastButton = this.navigatorFooterLastButton;
		navigatorGoField = this.navigatorFooterGoField;
		navigatorGoButton = this.navigatorFooterGoButton;
		gotoPageLabel = this.gotoPageLabelFooter;
		currentPageId = this.currentPageIdFooter;
		currentPageLabelId = this.currentPageLabelIdFooter;
		navigatorGoButtonPressed = this.navigatorGoButtonFooterPressed;
	}
	
	if (_safari || _ie) {
		sb.append('<table cellspacing="0" cellpadding="0" border="0" width="100%" style="padding-bottom:1px;">');
		sb.append('<tr valign="middle">');			
		className = "navigator-control-text-safari";			
	} else {
		sb.append('<table cellspacing="0" cellpadding="0" border="0" width="100%">');
		sb.append('<tr valign="top">');
	}
	sb.append('<td width="100%"><img src="' + wsgImagesLocation + 'blank.gif" width="10" border="0"/></td>');
	sb.append('<td><img style="cursor:pointer;" title="' + this.bundle.NAVIGATOR_FIRST_PAGE + '" id="' + navigatorFirstButton + '" onclick="' + this.instanceId + '.navigatorEvent(' + this.navigatorFirstButtonPressed + ');" src="' + this.imagesLocation + this.buttonFirstImage + '" border="0"></td>');
	sb.append('<td>&nbsp;&nbsp;</td>');
	sb.append('<td><img style="cursor:pointer;" title="' + this.bundle.NAVIGATOR_PREVIOUS_PAGE + '" id="' + navigatorLeftButton + '" onclick="' + this.instanceId + '.navigatorEvent(' + this.navigatorLeftButtonPressed + ');" src="' + this.imagesLocation + this.buttonLeftImage + '" border="0"></td>');
	sb.append('<td>&nbsp;&nbsp;</td>');
	sb.append('<td id=' + currentPageLabelId + ' class="' + className + '">' + this.bundle.NAVIGATOR_PAGE + '&nbsp;<span id="' + currentPageId + '">');
	if (this.currentPage > 0) {
		sb.append(this.currentPage + ((parseFloat(this.totalPages) > 1) ? '&nbsp;' + this.bundle.NAVIGATOR_OF +'&nbsp;' + this.totalPages : ''));
	} else { 
		sb.append('&nbsp;');
	}
	sb.append('</span></td>');
	sb.append('<td>&nbsp;&nbsp;</td>');
	sb.append('<td><img style="cursor:pointer;" title="' + this.bundle.NAVIGATOR_NEXT_PAGE + '" id="' + navigatorRightButton + '" onclick="' + this.instanceId + '.navigatorEvent(' + this.navigatorRightButtonPressed + ');"  src="' + this.imagesLocation + this.buttonRightImage + '" border="0"></td>');
	sb.append('<td>&nbsp;&nbsp;</td>');
	sb.append('<td><img style="cursor:pointer;" title="' + this.bundle.NAVIGATOR_LAST_PAGE + '" id="' + navigatorLastButton + '" onclick="' + this.instanceId + '.navigatorEvent(' + this.navigatorLastButtonPressed + ');"  src="' + this.imagesLocation + this.buttonLastImage + '" border="0"></td>');
	sb.append('<td>&nbsp;&nbsp;</td>');
	sb.append('<td class="' + className + '" nowrap="nowrap" id="' + gotoPageLabel + '">' + this.bundle.NAVIGATOR_GOTO_PAGE + ':&nbsp;</td>');
	sb.append('<td><input class="navigator-box" type="text" size="2" id="' + navigatorGoField + '" onkeypress="if (_wsgUtils.checkEnter(event)) {' + this.instanceId + '.navigatorEvent(' + navigatorGoButtonPressed + ');}"></td>');
	sb.append('<td><img src="' + wsgImagesLocation + 'blank.gif" width="10" border="0"/></td>');
	sb.append('<td><img style="cursor:pointer;" title="' + this.bundle.NAVIGATOR_GO + '" id="' + navigatorGoButton + '" onclick="' + this.instanceId + '.navigatorEvent(' + navigatorGoButtonPressed + ');"  src="' + this.imagesLocation + this.buttonGoToImage + '" border="0"></td>');
	sb.append('<td><img src="' + wsgImagesLocation + 'blank.gif" width="10" border="0"/></td>');
	sb.append('</tr>');			
	sb.append('</table>');
	return sb.toString();	
};

WSGResultNavigator.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;
	}
};

WSGResultNavigator.prototype.changeResultsPerPage = function() {
	if (this.resultFunction != null) {
		eval(this.resultFunction + "('" + this.instanceId + "')");
	}		
};

WSGResultNavigator.prototype.navigatorEvent = function (action) {
	switch (action) {
		case this.navigatorFirstButtonPressed: {
			this.currentPage = 1;	
			break;
		}
		case this.navigatorLeftButtonPressed: {
			if (this.currentPage > 1) {
				this.currentPage -= 1;
			}
			break;
		}
		case this.navigatorRightButtonPressed: {
			if (this.currentPage < this.totalPages) {
				this.currentPage += 1;
			}
			break;
		}
		case this.navigatorLastButtonPressed: {
			this.currentPage = this.totalPages;
			break;
		}
		case this.navigatorGoButtonHeaderPressed: {
			if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
				try {
					var value = document.getElementById(this.navigatorHeaderGoField).value;
					if (!_wsgUtils.allSpaces(value) && _wsgUtils.hasOnlyDigits(value)) {						
						if (parseInt(value, 10) <= this.totalPages) {
							if (parseInt(value, 10) < 1) {
								this.currentPage = 1;
								document.getElementById(this.navigatorHeaderGoField).value = 1;
							} else {
								this.currentPage = parseInt(value, 10);
							}
						} else {
							this.currentPage = this.totalPages;
							document.getElementById(this.navigatorHeaderGoField).value = this.totalPages; 
						}
						if (document.getElementById(this.navigatorFooterGoField) != undefined) {
							document.getElementById(this.navigatorFooterGoField).value = document.getElementById(this.navigatorHeaderGoField).value; 
						}
					}
				} catch (e) {}
			}
			break;
		}	
		case this.navigatorGoButtonFooterPressed: {
			if (document.getElementById(this.navigatorFooterGoField) != undefined) {
				try {
					var value = document.getElementById(this.navigatorFooterGoField).value;
					if (!_wsgUtils.allSpaces(value)) {						
						if (parseInt(value, 10) <= this.totalPages) {
							if (parseInt(value, 10) < 1) {
								this.currentPage = 1;
								document.getElementById(this.navigatorFooterGoField).value = 1;
							} else {
								this.currentPage = parseInt(value, 10);
							}
						} else {
							this.currentPage = this.totalPages;
							document.getElementById(this.navigatorFooterGoField).value = this.totalPages; 
						}
						if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
							document.getElementById(this.navigatorHeaderGoField).value = document.getElementById(this.navigatorFooterGoField).value; 
						}
					}
				} catch (e) {}
			}
			break;
		}	
	}
	if (action != this.navigatorGoButtonHeaderPressed && action != this.navigatorGoButtonFooterPressed) {
		if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
			document.getElementById(this.navigatorHeaderGoField).value = '';
		}
		if (document.getElementById(this.navigatorFooterGoField) != undefined) {
			document.getElementById(this.navigatorFooterGoField).value = '';
		}
	}
	this.changeResultsPerPage();
	this.updateNavigatorState();
};

WSGResultNavigator.prototype.updateNavigatorState = function() {
	if (this.currentPage > 1) {		
		if (document.getElementById(this.navigatorHeaderFirstButton) != undefined) {			
			new WSGDOMObject(document.getElementById(this.navigatorHeaderFirstButton)).display();	
		}
		if (document.getElementById(this.navigatorFooterFirstButton) != undefined) {			
			new WSGDOMObject(document.getElementById(this.navigatorFooterFirstButton)).display();	
		}		
		if (document.getElementById(this.navigatorHeaderLeftButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorHeaderLeftButton)).display();
		}	
		if (document.getElementById(this.navigatorFooterLeftButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorFooterLeftButton)).display();
		}
		if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorHeaderGoField)).display();
		}	
		if (document.getElementById(this.navigatorFooterGoField) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorFooterGoField)).display();
		}	
		if (document.getElementById(this.navigatorHeaderGoButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorHeaderGoButton)).display();
		}			
		if (document.getElementById(this.navigatorFooterGoButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorFooterGoButton)).display();
		}
		if (this.totalPages == this.currentPage) {
			if (document.getElementById(this.navigatorHeaderLastButton) != undefined) {		
				new WSGDOMObject(document.getElementById(this.navigatorHeaderLastButton)).displayNone();	
			}
			if (document.getElementById(this.navigatorFooterLastButton) != undefined) {			
				new WSGDOMObject(document.getElementById(this.navigatorFooterLastButton)).displayNone();	
			}		
			if (document.getElementById(this.navigatorHeaderRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderRightButton)).displayNone();
			}	
			if (document.getElementById(this.navigatorFooterRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterRightButton)).displayNone();
			}
		} else {
			if (document.getElementById(this.navigatorHeaderLastButton) != undefined) {			
				new WSGDOMObject(document.getElementById(this.navigatorHeaderLastButton)).display();	
			}
			if (document.getElementById(this.navigatorFooterLastButton) != undefined) {			
				new WSGDOMObject(document.getElementById(this.navigatorFooterLastButton)).display();	
			}		
			if (document.getElementById(this.navigatorHeaderRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderRightButton)).display();
			}	
			if (document.getElementById(this.navigatorFooterRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterRightButton)).display();
			}
		}
	} else {			
		if (document.getElementById(this.navigatorHeaderFirstButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorHeaderFirstButton)).displayNone();
		}
		if (document.getElementById(this.navigatorFooterFirstButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorFooterFirstButton)).displayNone();
		}
		if (document.getElementById(this.navigatorHeaderLeftButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorHeaderLeftButton)).displayNone();
		}
		if (document.getElementById(this.navigatorFooterLeftButton) != undefined) {
			new WSGDOMObject(document.getElementById(this.navigatorFooterLeftButton)).displayNone();
		}
		
		if (this.totalPages == 1) {			
			if (document.getElementById(this.navigatorHeaderGoButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderGoButton)).displayNone();
			} 
			if (document.getElementById(this.navigatorFooterGoButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterGoButton)).displayNone();
			} 			
			if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderGoField)).displayNone();
			}
			if (document.getElementById(this.navigatorFooterGoField) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterGoField)).displayNone();
			}
			if (document.getElementById(this.navigatorHeaderRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderRightButton)).displayNone();
			}
			if (document.getElementById(this.navigatorFooterRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterRightButton)).displayNone();
			}
			if (document.getElementById(this.navigatorHeaderLastButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderLastButton)).displayNone();
			}	
			if (document.getElementById(this.navigatorFooterLastButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterLastButton)).displayNone();
			}
			if (document.getElementById(this.gotoPageLabelHeader) != undefined) {
				new WSGDOMObject(document.getElementById(this.gotoPageLabelHeader)).displayNone();
			}
			if (document.getElementById(this.gotoPageLabelFooter) != undefined) {
				new WSGDOMObject(document.getElementById(this.gotoPageLabelFooter)).displayNone();
			}
		} else {
			if (document.getElementById(this.navigatorHeaderGoButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderGoButton)).display();
			}
			if (document.getElementById(this.navigatorFooterGoButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterGoButton)).display();
			}
			if (document.getElementById(this.navigatorHeaderGoField) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderGoField)).display();
			}	
			if (document.getElementById(this.navigatorFooterGoField) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterGoField)).display();
			}
			if (document.getElementById(this.navigatorHeaderRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderRightButton)).display();
			}
			if (document.getElementById(this.navigatorFooterRightButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterRightButton)).display();
			}
			if (document.getElementById(this.navigatorHeaderLastButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorHeaderLastButton)).display();
			}
			if (document.getElementById(this.navigatorFooterLastButton) != undefined) {
				new WSGDOMObject(document.getElementById(this.navigatorFooterLastButton)).display();
			}
			if (document.getElementById(this.gotoPageLabelHeader) != undefined) {
				new WSGDOMObject(document.getElementById(this.gotoPageLabelHeader)).display();
			}
			if (document.getElementById(this.gotoPageLabelFooter) != undefined) {
				new WSGDOMObject(document.getElementById(this.gotoPageLabelFooter)).display();
			}
		}
	} 
	
	if (this.results != null && this.results.length > 0) {
		if (document.getElementById(this.currentPageLabelIdFooter) != undefined) {
			new WSGDOMObject(document.getElementById(this.currentPageLabelIdFooter)).display();
		}
		if (document.getElementById(this.currentPageLabelIdHeader) != undefined) {
			new WSGDOMObject(document.getElementById(this.currentPageLabelIdHeader)).display();
		}
		if (document.getElementById(this.currentPageIdHeader) != undefined) {		
			document.getElementById(this.currentPageIdHeader).innerHTML = this.currentPage + ((this.totalPages > 1) ? '&nbsp;' + this.bundle.NAVIGATOR_OF +'&nbsp;' + this.totalPages : '');
		}
		if (document.getElementById(this.currentPageIdFooter) != undefined) {		
			document.getElementById(this.currentPageIdFooter).innerHTML = this.currentPage + ((this.totalPages > 1) ? '&nbsp;' + this.bundle.NAVIGATOR_OF +'&nbsp;' + this.totalPages : '');
		}
	} else {
		if (document.getElementById(this.currentPageLabelIdFooter) != undefined) {			
			new WSGDOMObject(document.getElementById(this.currentPageLabelIdFooter)).displayNone();
		}
		if (document.getElementById(this.currentPageLabelIdHeader) != undefined) {			
			new WSGDOMObject(document.getElementById(this.currentPageLabelIdHeader)).displayNone();
		}
	}
};

WSGResultNavigator.prototype.hideNavigator = function (id) {
	if (document.getElementById(navigatorId + id) != undefined) {
		setZeroAlphaDefaultCursor(document.getElementById(navigatorId + id));
	}
};
