/*
// DAX Client specific code
*/

var clientVersion = 'v11.1';

{
	
	window.onresize = function () {
		if(taskbar) {
			if (taskbar.dom.style.display != 'none')
				taskbar.refresh();
		}
		if (aSidebar) {
			if (aSidebar.dom.style.display != 'none')
				aSidebar.redraw();
		}
	}

	window.onscroll = function () {
		if ((browser.ie) && (taskbar)) {
			if (taskbar.dom.style.display != 'none')		
				taskbar.refresh();
		}
		if ((browser.ie) && (aSidebar)) {
			if (aSidebar.dom.style.display != 'none')
				aSidebar.redraw();
		}		
	}
	
	// 11-15-06 - Julien
	window.onbeforeunload = function(event) {
		if (taskbar) {
			var text = STR['onbeforeunload'];
			//if (browser.ie)
			//	event.returnValue = text;
			//else
			return text;
		}
	}
	
}

// localize admin and login widgets
function localize_widgets() {

	// localize login widget first
	var loginWidget = $('loginForm');

	// find all text elements and update them
	if (loginWidget) {
		$('loginFormLogin').innerHTML = STR['login_login'];
		$('loginFormUsername').innerHTML = STR['login_username'];
		$('loginFormPassword').innerHTML = STR['login_password'];
	}
	
	// localize admin table widget
	var adminTableWidget = $('admintableprivileges');
	
	// find all text elements and update them
	if (adminTableWidget) {
		// document.getElementById('adminTablePrivilegesAccessControl').innerHTML = STR['admin_accesscontrol'];
		$('adminGroupPopup').innerHTML = STR['admin_grouppopup'];
		// document.getElementById('adminGroupPopupForPrefs').innerHTML = STR['admin_grouppopupforprefs'];
		$('adminTablePrivilegesSelections').innerHTML = STR['admin_selections'];
		$('adminTablePrivilegesAllowAccess1').innerHTML = STR['admin_allowaccess'];
		$('adminTablePrivilegesProperties').innerHTML = STR['admin_properties'];
		$('adminTablePrivilegesAllowAccess2').innerHTML = STR['admin_allowoutput'];
		$('adminTablePrivilegesAllowAccess3').innerHTML = STR['admin_allowinput'];
		$('adminTablePrivilegesAllowAccess4').innerHTML = STR['admin_allowsearch'];
		$('adminTablePrivilegesToggleAll1').innerHTML = STR['admin_toggleall'] + $('adminTablePrivilegesToggleAll1').innerHTML;
		$('adminTablePrivilegesToggleAll2').innerHTML = STR['admin_toggleall'] + $('adminTablePrivilegesToggleAll2').innerHTML;
		
		// general prefs tab
		$('adminTaskbarLocation').innerHTML = STR['admin_taskbarlocation'];
		$('adminTaskbarTop').innerHTML = STR['admin_taskbartop'];
		$('adminTaskbarBottom').innerHTML = STR['admin_taskbarbottom'];
		$('adminStyle').innerHTML = STR['admin_style'];
//		$('adminPreload').innerHTML = STR['admin_preload'];
		
		// ddw manager tab
		$('adminDDWList').innerHTML = STR['adminDDW_list'];
		$('adminDDWTitle').innerHTML = STR['adminDDW_title'];
		$('adminDDWContent').innerHTML = STR['adminDDW_content'];
		$('adminDDWType').innerHTML = STR['adminDDW_type'];
		$('adminDDWNewLink').innerHTML = STR['adminDDW_newLink'];
		$('adminDDWNewHTML').innerHTML = STR['adminDDW_newHTML'];
		$('adminDDWNewText').innerHTML = STR['adminDDW_newText'];
		$('adminDDWAssociatedTo').innerHTML = STR['adminDDW_associatedTo'];
		$('adminDDWPortal').innerHTML = STR['adminDDW_portal'];
		$('adminDDWOther').innerHTML = STR['adminDDW_other'];	
		$('adminDDWCreate').innerHTML = STR['adminDDW_create'];
		$('adminDDWCancel').innerHTML = STR['adminDDW_cancel'];
		$('adminDDWcreateButton').value = STR['adminDDW_create'];
		
		// query manager tab
		$('adminQueryList').innerHTML = STR['adminQuery_List'];
		$('adminQuerycreateButton').value = STR['adminQuery_save'];
		$('adminQueryCreate').innerHTML = STR['adminQuery_create'];
		$('adminQueryCancel').innerHTML = STR['adminQuery_cancel'];
		$('QueryListFilterTitle').innerHTML = STR['adminQuery_filter'];
		$('QueryListAllRecordsTitle').innerHTML = STR['adminQuery_allrecords'];
		$('adminQuerySelection').innerHTML = STR['adminQuery_createtitle'];
		$('adminQueryNewTitle').innerHTML = STR['adminQuery_new'];
		$('adminQueryDynamicTitle').innerHTML = STR['adminQuery_dynamic'];
		$('adminQueryUseTemplateCBTitle').innerHTML = STR['adminQuery_template'];
		$('adminQueryUseTemplateCBTitle2').innerHTML = STR['adminQuery_template2'];
		$('adminQueryNext').value = STR['adminQuery_Next'];
		$('adminqueryDynamicfieldPopup').options[0].innerHTML = STR['adminQuery_NotAvailable'];
		$('adminquerytemplatefieldPopup').options[0].innerHTML = STR['adminQuery_NotAvailable'];
		$('adminQuerySortFieldPopup').options[0].innerHTML = STR['adminQuery_NotAvailable'];
		$('adminQueryConditionFieldPopup').options[0].innerHTML = STR['adminQuery_NotAvailable'];
		$('adminQuerySetNameTitle').innerHTML = STR['adminQuery_Name'];
		$('adminQuerySetSelectionTitle').innerHTML = STR['adminQuery_BoundTo'];
		$('adminQuerySortFieldTitle').innerHTML = STR['adminQuery_SortField'];
		$('adminQuerySortOrderTitle').innerHTML = STR['adminQuery_SortOrder'];
		$('adminQueryMaxNbRecordsTitle').innerHTML = STR['adminQuery_MaxNb'];
		$('adminQueryAddACondition').innerHTML = STR['adminQuery_AddCondition'];
		$('adminQueryConditionField').innerHTML = STR['adminQuery_Field'];
		$('adminQueryConditionOperator').innerHTML = STR['adminQuery_Operator'];
		$('adminQueryCondition').innerHTML = STR['adminQuery_Value'];
		$('adminQueryConditonType').innerHTML = STR['adminQuery_IsAMethod'];
		$('adminQueryConditionLink').innerHTML = STR['adminQuery_Link'];
		$('adminQueryConditionAddUpdate').value = STR['adminQuery_Add'];
		$('adminQueryConditionsTitle').innerHTML = STR['adminQuery_Conditions'];
		$('adminQuerySortOrderPopup').options[0].innerHTML = STR['adminQuery_Asc'];
		$('adminQuerySortOrderPopup').options[1].innerHTML = STR['adminQuery_Desc'];
		$('adminQueryConditionOperatorPopup').options[0].innerHTML = STR['adminQuery_Operator1'];
		$('adminQueryConditionOperatorPopup').options[1].innerHTML = STR['adminQuery_Operator2'];
		$('adminQueryConditionOperatorPopup').options[2].innerHTML = STR['adminQuery_Operator3'];
		$('adminQueryConditionOperatorPopup').options[3].innerHTML = STR['adminQuery_Operator4'];
		$('adminQueryConditionOperatorPopup').options[4].innerHTML = STR['adminQuery_Operator5'];
		$('adminQueryConditionOperatorPopup').options[5].innerHTML = STR['adminQuery_Operator6'];
		$('adminQueryConditionOperatorPopup').options[6].innerHTML = STR['adminQuery_Operator7'];
		$('adminQueryConditionOperatorPopup').options[7].innerHTML = STR['adminQuery_Operator8'];
		$('adminQueryConditionLinkPopup').options[0].innerHTML = STR['adminQuery_Link1'];
		$('adminQueryConditionLinkPopup').options[1].innerHTML = STR['adminQuery_Link2'];
		
		$('adminReportList').innerHTML = STR['dash_toplefttitle'];
		$('adminReportCreate').innerHTML = STR['dash_create'];
		$('adminReportCancel').innerHTML = STR['dash_cancel'];
		$('adminReportSelection').innerHTML = STR['dash_create_selection'];
		$('adminReportNameTitle').innerHTML = STR['dash_create_name'];
		$('adminReportName').value = STR['dash_create_defaultname'];
		$('adminReportDescriptionTitle').innerHTML = STR['dash_create_description'];
		$('adminReportStyleTitle').innerHTML = STR['dash_create_platform'];
		$('adminReportStyleType_iPhone').nextSibling.nodeValue = STR['dash_create_iphoneflag'];
		$('adminReportNext').value = STR['dash_create_button'];

		$('adminPropertiesFormatting_Boolean').innerHTML = STR['dash_pi_for_info1'];
		$('adminPropertiesFormatting_Numeric').innerHTML = STR['dash_pi_for_info2'];
		$('adminPropertiesFormatting_Date').childNodes[0].nodeValue = STR['dash_pi_for_info3'];
		$('adminPropertiesFormatting_Date_Format').options[0].text = STR['dash_pi_for_date1'];
		$('adminPropertiesFormatting_Date_Format').options[1].text = STR['dash_pi_for_date2'];
		$('adminPropertiesFormatting_Date_Format').options[2].text = STR['dash_pi_for_date3'];
		$('adminPropertiesFormatting_Date_Format').options[3].text = STR['dash_pi_for_date4'];
		$('adminPropertiesFormatting_Date_Format').options[4].text = STR['dash_pi_for_date5'];
		$('adminPropertiesFormatting_Date_Format').options[5].text = STR['dash_pi_for_date6'];
		$('adminPropertiesFormatting_Date_Format').options[6].text = STR['dash_pi_for_date7'];
		$('adminPropertiesFormatting_Date_Format').options[7].text = STR['dash_pi_for_date8'];
		$('adminPropertiesFormatting_Date_Format').options[8].text = STR['dash_pi_for_date9'];
		$('adminPropertiesFormatting_Time').childNodes[0].nodeValue = STR['dash_pi_for_info4'];
		$('adminPropertiesFormatting_Time_Format').options[0].text = STR['dash_pi_for_time1'];
		$('adminPropertiesFormatting_Time_Format').options[1].text = STR['dash_pi_for_time2'];
		$('adminPropertiesFormatting_Time_Format').options[2].text = STR['dash_pi_for_time3'];
		$('adminPropertiesFormatting_Time_Format').options[3].text = STR['dash_pi_for_time4'];
		$('adminPropertiesFormatting_Time_Format').options[4].text = STR['dash_pi_for_time5'];
		$('adminPropertiesFormatting_Time_Format').options[5].text = STR['dash_pi_for_time6'];

	}	
}

function on_login_error()
{
	// alerts the user that there was an error logging in
	$("loginStatus").style.display = "";
	assert("loginStatus", "Nombre de Usuario ó Password Invalidos!");
	
}

function on_error(errorCode)
{
	//alert(errorCode);
}

// user customizable on login event
function onLoginSuccess()
{

	var loginStatus = $("loginStatus");
	if (loginStatus)
		loginStatus.style.display = "none";

	// the login is displayed on the dashboard
	do_hideDashboard($('loginForm'));
		
	CheckPreferences();

if (AdminShowAdmin) {
	LoadAdmin();
	do_showDashboard($('adminSettings'), '1');
	if (tablelistinitialized) {
		admintablegridobject.viewport.refresh();
		admintablegridobject.grid.dom.style.maxHeight = "150px";
		admintablegridobject.viewport.vscrollbar.dom.style.top = admintablegridobject.viewport.content.offsetTop+"px";
		admintablegridobject.viewport.vscrollbar.dom.style.left = admintablegridobject.viewport.content.offsetLeft + admintablegridobject.viewport.content.offsetWidth+"px";	
	}
}
else {
	//do_roundCorners($('tp'));
	
	// show taskbar
	//do_showTaskbar();
	if (!taskbar)
		taskbar = new taskbarObject();

		
	var body = document.body;
	
	setStyle (taskbar.dom, 'display','block');

	// draw a table list
	do_drawSidebar();

	
	// hide splash screen
	var ss = $('splashscreen');
	if (ss)
		ss.style.display = "none";
	
	body.className = "niceBody";
}	
	localize_widgets();
	initTooltop();

}

// user customizable on login event
function onLogoutSuccess() {

	//alert (STR['logoutsuccess']);
	window.onbeforeunload = null;
	window.location = "index.html";


}

function onLogoutFail() {

	//alert (STR['logoutfail']);
	window.onbeforeunload = null;
	window.location = "index.html";

}

function on_login_success()
{

	// initialize bridge
	if (dax_bridge) {
		dax_bridge.sessionId = connection.sessionId;
		if (userlanguage=="")
			dax_bridge.language = connection.language;
		else
			dax_bridge.language = userlanguage;
		dax_bridge.updateTables(true);
		dax_bridge.username = connection.username;
	}

	dax_bridge.localize();

	if (clientVersion != dax_bridge.version)
		alert(STR['versionmismatch']);
	
	onLoginSuccess();	
	
	if (callback_onLoginSuccess)
		callback_onLoginSuccess (dax_bridge.username);
}

/**
 * Event to handle when a tab is switched to another tab
 */
function on_tab_switched(tab)
{
	// do an inline query
	var fieldid = tab.fieldid;
	var value = tab.label;
	
	if (fieldid == -1)
		value = "*";
	
	inline_query(tab.obj, fieldid, value);
}

function CheckPreferences() {
	
	var sessionId = connection.sessionId;
 
 	if (sessionId == "")
 		return;
 		
 	var http_request = getXMLHttpRequest();
		
	if (http_request) {
		var url = connection.address.getgeneralprefs+"?sessionId="+sessionId;
		
		http_request.onreadystatechange = 
			function() {
				onGetPrefs(http_request);
			};
			
		try {
		
			debugAlert('<b>DAX:</b>'+'<a href="'+url+'" target="_blank">'+url+'</a>');
		
			http_request.open("GET", url, true);
	  	  	http_request.send(null);
	   	} catch(e) {
			if (browser.ie6)
				http_request.onreadystatechange = function(){};
			else
				http_request.onreadystatechange = null;
	   		delete http_request;
		}
	}
	
	return true;
};

function onGetPrefs(http_request)
{
	if (http_request.readyState != 4)
		return;

	// parse through the XML
	var result = http_request.responseXML.getElementsByTagName("Preferences").item(0);
	var errorResponse = checkResponse(http_request);
	
	if (!isDefined(result)) {
		// return this.onerror(http_request); // won't work
		return false;
	}

	// column width	
	var resultElements = result.getElementsByTagName("*");
	for (var elCount = 0; elCount < resultElements.length; elCount++) {
		if (resultElements.item(elCount).nodeName.indexOf('dax_colwidth') != -1) {
			var table = getTable(resultElements.item(elCount).nodeName.substr(13));
			table.columnWidths = resultElements.item(elCount).firstChild.nodeValue;
		}	
	}

	
	/*
	
	var preloadpref= result.getElementsByTagName("preloadmaxnb");
	if ((preloadpref) && (preloadpref.item(0)))
		objectsToPreload = preloadpref.item(0).lastChild.nodeValue;
	else
		objectsToPreload = 0;
	
	TableHListPreload();
	
	*/
	
	var taskbarposition= result.getElementsByTagName("taskbar");
	
	if (taskbarposition.length>0) {
		if (taskbar) 
			taskbar.position(taskbarposition.item(0).lastChild.nodeValue);
	}

	var stylepref= result.getElementsByTagName("style");
	
	if (stylepref.length>0) {
		setActiveStyleSheet(stylepref.item(0).lastChild.nodeValue); WindowManager.redraw();
	}
	
	if(taskbar) {
		if (taskbar.dom.style.display != 'none')
			taskbar.refresh();
	}		
	
	if (aSidebar) {
		aSidebar.redraw(true);
		//aSidebar.show();
	}
		
	if (browser.ie6)
		http_request.onreadystatechange = function(){};
	else
		http_request.onreadystatechange = null;
	delete http_request;
};

/*
// Client specific code
*/

function do_login(username, password, language) {
	if (username == "") {
		on_login_error();
		return;
	}
	
	$("loginStatus").style.display = "None";
	
	dax_bridge.isClient = true;
	
	if (AdminShowAdmin)
		isAdminLoggedIn = true;
	else
		isAdminLoggedIn = false;
	
	var url = connection.address.login + "?username=" + dax_bridge.encode(username) + "&password=" + dax_bridge.encode(password);
	
	connection.username = username;
	
	makeRequest(url, login);
}

function do_drawSidebar()
{
	if (!structure.isUpdated()) {
		setTimeout("do_drawSidebar()", 10);
		return;
	} else {
		
		var taskbar_main = new taskbarItem(taskbar);
		taskbar_main.setLabel(STR['taskbar_views']);
		taskbar_main.setIcon("portal");
		setStyle (taskbar_main.dom, 'display', 'block');
		
		// safari fix for portal taskbar button width
		if (browser.safari)
			taskbar_main.button_m.style.width = '80px';

		// create a handler for taskbar clicking
		taskbar_main.dom.onclick = function() {
			if (aSidebar)
				if (aSidebar.state == 'visible')
					aSidebar.hide();
				else
					aSidebar.show();
		};

		
		var hl = new TableHList();
	
		//var tabs = new Tabs();
		
		aSidebar = new Sidebar();

		aButton = aSidebar.addButton ('logout_button');
		aButton.tooltip = STR['sidebar_logout'];
		
		aButton.onclick = function () {
		
			var aConfirm = confirm(STR['logoutconfirm']);
			
			if (aConfirm)
				dax_bridge.logout();
		
		}
		
		if (connection.admin) {
			// hl2
			
			/*
			var taskbar_admin = new taskbarItem(taskbar);
			taskbar_admin.setLabel(STR['taskbar_admin_label']);
			taskbar_admin.setIcon("admin");
			setStyle (taskbar_admin.dom, 'display', 'block');
			*/

			aButton = aSidebar.addButton ('console_button');
			aButton.tooltip = STR['sidebar_console'];
			
			// create a handler for taskbar clicking
			aButton.onclick = function() {
				showDebugger();
			};			
			
			aButton = aSidebar.addButton ('admin_button');
			aButton.tooltip = STR['sidebar_settings'];
						
			// create a handler for taskbar clicking
			aButton.onclick = function() {
				// scroll window to 0,0 to avoid grayout bugs
				parent.window.scrollTo(0,0);
			
				do_showDashboard($('adminSettings'), '1');
				if (tablelistinitialized) {
					admintablegridobject.viewport.refresh();

					admintablegridobject.grid.dom.style.maxHeight = "150px";
					admintablegridobject.viewport.vscrollbar.dom.style.top = admintablegridobject.viewport.content.offsetTop+"px";
					admintablegridobject.viewport.vscrollbar.dom.style.left = admintablegridobject.viewport.content.offsetLeft + admintablegridobject.viewport.content.offsetWidth+"px";	
				}
				//do_showDashboard($('adminGeneralPrefs'), '2');
			};

			/*
			
			var taskbar_debugger = new taskbarItem(taskbar);
			taskbar_debugger.setLabel(STR['taskbar_debug']);
			taskbar_debugger.setIcon("debug");
			setStyle (taskbar_debugger.dom, 'display', 'block');

			*/
			


			LoadAdmin();
		}

	
		// Tables tab
		//var container = $("table_list");
		//container.style.display = "block";
		//container.appendChild(hl.dom);
		aSidebar.contents.appendChild (hl.dom);
		aSidebar.contents.hList = hl;

		// safari fix
		if (!browser.safari2)
			setStyle (hl.dom, 'width', '500px');
		else {
			setStyle (hl.dom, 'width', '130px');
		}
		
		aSidebar.dom.style.opacity = '0.8';
		
		// ie6 fix
		if (browser.ie6) {
			hl.dom.style.position = 'absolute';
			aSidebar.contents.style.height = hl.dom.offsetHeight;
		}		
		
		
		//aSidebar.setTitle ('tables');
		
		//tabs.insert("Tables", 0, container);
		
		//var sidebar = $('sidebar');
		//sidebar.appendChild(tabs.dom);
		//sidebar.style.display = "block";
		//tabs.dom.style.opacity = "0.8";		

		aSidebar.show();
		aSidebar.hList = hl;
		
	}
}

function do_redrawSidebar() 
{
	var	dax_sidebar = $('dax_sidebar0');
	dax_sidebar.parentNode.removeChild(dax_sidebar);
	structure.cached = false;
	structure.tables.length = 0;
	dax_bridge.tables.length = 0;

	// close all preloaded windows
	var preloadedWindows = new Array();
	for (var pr = 0; pr < WindowManager.windows.length; pr++) {
		//if (WindowManager.windows[pr].preloaded)
			// skip console window
			if (!WindowManager.windows[pr].bridgeLink)
				preloadedWindows.push(WindowManager.windows[pr]);
	}

	if (preloadedWindows.length > 0) {
		for (var pr = 0; pr < preloadedWindows.length; pr++) {
			var thisWindow = preloadedWindows[pr];
			WindowManager.destroyWindow(thisWindow);
			setTimeout(function() {thisWindow = null;}, 1);
		}
	}
	
	preloadedWindows = null;
	
	
	dax_bridge.updateTables();			
	do_redrawSidebar2();
}

function do_redrawSidebar2()
{
	if (!structure.isUpdated() | dax_bridge.updating) {
		setTimeout("do_redrawSidebar2()", 10);
		return;
	} else {
				
		var hl = new TableHList();
	
		//var tabs = new Tabs();
		
		aSidebar = new Sidebar();
		
		// Tables tab
		aSidebar.contents.appendChild (hl.dom);
		aSidebar.contents.hList = hl;
		
		// safari fix
		if (!browser.safari2)
			setStyle (hl.dom, 'width', '500px');
		else {
			setStyle (hl.dom, 'width', '130px');
		}
			
		aSidebar.dom.style.opacity = '0.8';
		
		// ie6 fix
		if (browser.ie6) {
			hl.dom.style.position = 'absolute';
			aSidebar.contents.style.height = hl.dom.offsetHeight;
		
		}

		aSidebar.show();
		aSidebar.hList = hl;
		
		aButton = aSidebar.addButton ('logout_button');
		aButton.tooltip = STR['sidebar_logout'];

		aButton.onclick = function () {
		
			var aConfirm = confirm(STR['logoutconfirm']);
			
			if (aConfirm)
				dax_bridge.logout();
		
		}
		
		if (connection.admin) {
			// hl2
			
			/*
			var taskbar_admin = new taskbarItem(taskbar);
			taskbar_admin.setLabel(STR['taskbar_admin_label']);
			taskbar_admin.setIcon("admin");
			setStyle (taskbar_admin.dom, 'display', 'block');
			*/
			aButton = aSidebar.addButton ('console_button');
			aButton.tooltip = STR['sidebar_console'];
			
			// create a handler for taskbar clicking
			aButton.onclick = function() {
				showDebugger();
			};
			
			aButton = aSidebar.addButton ('admin_button');
			aButton.tooltip = STR['sidebar_settings'];
						
			// create a handler for taskbar clicking
			aButton.onclick = function() {
				// scroll window to 0,0 to avoid grayout bugs
				parent.window.scrollTo(0,0);
			
				do_showDashboard($('adminSettings'), '1');
				if (tablelistinitialized) {
					admintablegridobject.viewport.refresh();

					admintablegridobject.grid.dom.style.maxHeight = "150px";
					admintablegridobject.viewport.vscrollbar.dom.style.top = admintablegridobject.viewport.content.offsetTop+"px";
					admintablegridobject.viewport.vscrollbar.dom.style.left = admintablegridobject.viewport.content.offsetLeft + admintablegridobject.viewport.content.offsetWidth+"px";	
				}
				//do_showDashboard($('adminGeneralPrefs'), '2');
			};

			/*
			
			var taskbar_debugger = new taskbarItem(taskbar);
			taskbar_debugger.setLabel(STR['taskbar_debug']);
			taskbar_debugger.setIcon("debug");
			setStyle (taskbar_debugger.dom, 'display', 'block');

			*/
			

		
		}

		//aSidebar.setTitle ('tables');
		
		//tabs.insert("Tables", 0, container);
		
		//var sidebar = $('sidebar');
		//sidebar.appendChild(tabs.dom);
		//sidebar.style.display = "block";
		//tabs.dom.style.opacity = "0.8";		

	}
}

/*
// Append reports to the sidebar portal
//
// Rudolf Psenicnik
*/

function appendReportsToSidebar()
{
	if (!aSidebar)
		return false;

	// get list of reports for the table
	for (var tableCount = 0; tableCount < aSidebar.hList.items.length; tableCount++) {
		var hTable = getTable(aSidebar.hList.items[tableCount].tableid);
		if (hTable.reports.length > 0) {
			var reportList = new HList();
			for (var reportCount = 0; reportCount < hTable.reports.length; reportCount++) {
				var reportListItem = reportList.insert(hTable.reports[reportCount].name);
				reportListItem.reportName = hTable.reports[reportCount].name;
				reportListItem.label.onclick = function() {
					dax_bridge.dashboardView = new dax_dashboardViewer(this.parent.reportName);
					//dax_bridge.reportView.getReport(this.parent.reportName);
				}
			}
			if (!aSidebar.hList.items[tableCount].list)
				aSidebar.hList.items[tableCount].attach(reportList);			
		}
	}
	
	
}

/**
 * TableHList
 *
 * @author Jonathan Le
 * @author Rudolf Psenicnik
 */
function TableHList()
{
	var hl = new HList();
		
	for (var i = 0; i < structure.tables.length; i++) {
		var table = structure.tables[i];
		//var fields = table.fieldsList;
		
		var li = hl.insert(table.tablename);
		li.tableid = table.tableid;
		li.cached = table.cached;		

		// set icon based on the type
		var hTable = getTable (table.tableid);

		if (hTable.ddw) {
			li.icon.className += ' icon_ddw';
		} else {					
			if (hTable.tablecalendarview == "True") {
				li.icon.className += ' icon_calendarview';
			} else if (hTable.tabledatatreeview == "True") {
				li.icon.className += ' icon_datatree';
			} else if (hTable.tableimagematrixview == "True"){
				li.icon.className += ' icon_imagebrowser';
			} else if (hTable.tabledatamatrixview == "True"){
				li.icon.className += ' icon_datamatrix';
			} else {
				li.icon.className += ' icon_datawindow';
			}
		}
		
		li.label.onclick =
			function()
			{
				if (!labeledit) {
				
					hTable = getTable (this.parent.tableid);

					if (hTable.ddw) {
						if (hTable.ddwtype.indexOf ('Static') != -1)
							new DDW (hTable.ddw, 'static_url', hTable.tablealias);
						else if (hTable.ddwtype.indexOf ('Dynamic') != -1)
							new DDW (hTable.ddw, 'dynamic_url', hTable.tablealias);
						// else if (hTable.ddwtype.indexOf ('Message') != -1)
							// new DDW (hTable.ddw, 'message_window', hTable.tablealias);
					} else {					
						// check if this window already exists
						var windowRef = findWindowByTableId (this.parent.tableid);
						// if window exists, show it
						if (windowRef) {
							windowRef.activate();
							windowRef.resize(1,1);
							windowRef.tbitem.dom.style.display = 'block';
							
							// finish preloading
							if (windowRef.preloaded) {
								// if loaded for first time, finish the init
								if (hTable.tablecalendarview == "True") {
									// display calendar view
									windowRef.boundTo.refresh();
									windowRef.resize(1,1);
								
								} else if (hTable.tabledatatreeview == "True") {
									// display hgrid view
									windowRef.boundTo.initialize();
									windowRef.resize(1,1);
								} else if (hTable.tableimagematrixview == "True"){
									// display grid view
									//windowRef.grid.populate({tableId : windowRef.aTableId, comparison : windowRef.aComparison });									
									
								} else if (hTable.tabledatamatrixview == "True"){
									// display grid view
									windowRef.boundTo.wakeUp();								
									
								} else {
									// display grid view
									//windowRef.boundTo.wakeUp();		
									windowRef.parent.wakeClient();									
									
								}		
								windowRef.preloaded = null;
								windowRef.dom.style.left = '250px';
							}
							
							windowRef = null;
							
							return;
						}
						
						// cache field info if needed
						if (this.parent.cached == false) {
							//buildFieldList(this.parent.tableid);
							this.parent.cached = true;
						}
						dax_bridge.cacheFields(hTable);
						// check which view is used
						if (hTable.tablecalendarview == "True") {
							// display calendar view
							new calendarView(null, this.parent.tableid, null, null);
						} else if (hTable.tabledatatreeview == "True") {
							// display hgrid view
							new HGrid (null, this.parent.tableid);
						} else if (hTable.tabledatamatrixview == "True") {
							// display data matrix
							var dataMatrixObject = new dataMatrix (null, this.parent.tableid, 'auto', 'auto', null, null, 'left', null, null, null, null, null);
							dataMatrixObject.window.tableid = this.parent.tableid;
							dataMatrixObject.window.closeBox.onmouseup = function (aEvent) {
								this.parent.boundTo.hibernate();
								if (taskbar)
									this.parent.tbitem.dom.style.display = 'none';
								return false;
							}							
							dataMatrixObject = null;
						} else if (hTable.tableimagematrixview == "True") {
							// display image matrix
							var dataMatrixObject = new dataMatrix (null, this.parent.tableid, 'auto', 'auto', null, null, 'top', null, null, null, null, null);
							// modify the icon
							dataMatrixObject.window.logo.className = 'window_logo_imagebrowser';
							dataMatrixObject.window.tbitem.setIcon("imagebrowser");
							dataMatrixObject.window.tableid = this.parent.tableid;
							dataMatrixObject.window.closeBox.onmouseup = function (aEvent) {
								this.parent.boundTo.hibernate();
								if (taskbar)
									this.parent.tbitem.dom.style.display = 'none';
								return false;
							}		
							dataMatrixObject = null;
						} else {
							dax_client_dataGrid(this.parent.tableid);
						}
					}
				}
			};
		
		/*
		
		if (fields) {
			var fieldlist = new HList();
			for (var k = 0; k < fields.length; k++) {
				fieldlist.insert(fields[k].fieldname,
					"js/templates/images/" + fields[k].fieldtype + ".png");
			}
						
			li.attach(fieldlist);
		}
		*/
	}
	
	hl.refresh();
	
	return hl;
}