openedTab = false; http_request = false; destinationLayer = ''; function navigate(activeTab, panelName) { for (t = 0; t < 5; t++) { if (t == activeTab) { /* This if prevents a user from clicking on an already 'opened' tab, so it doesn't generate unnecessary XHR's.*/ if ((document.getElementById('TD' + t).style.backgroundImage != 'url(img/darkTab.gif)') || !openedTab) { openedTab = true; document.getElementById('TD' + t).style.backgroundImage='url(img/darkTab.gif)'; document.getElementById('TD' + t).style.cursor='text'; retrieveData(panelName + 'Main', 'http://localhost:8080/dbwtk/code/echoTabs.php', 'POST', true, 'tab=' + t, 'setLayerContent'); retrieveData(panelName + 'Buttons', 'http://localhost:8080/dbwtk/code/echoButtons.php', 'POST', true, 'tab=' + t, 'setLayerContent'); } } else { document.getElementById('TD' + t).style.backgroundImage='url(img/lightTab.gif)'; document.getElementById('TD' + t).style.cursor='pointer'; } } } function retrieveData(toLayer, requestURL, requestMethod, requestAsynchronous, requestData, returnFunction) { http_request = false; destinationLayer = toLayer; // Defines the value of this global so the right layer is populated if (window.XMLHttpRequest) { http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } } else if (window.ActiveXObject) { try { http_request = new ActiveXObject("Msxml2.XMLHTTP") } catch(e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP") } catch(e) { } } } if (!http_request) { alert('Your browser is not equiped to use this tool.'); } http_request.onreadystatechange = eval(returnFunction); http_request.open(requestMethod, requestURL, requestAsynchronous); http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); http_request.send(requestData); } function setLayerContent() { functionStatus = false; xmlReturn = ''; if (http_request.readyState == 4) { if (http_request.status == 200) { xmlReturn = http_request.responseText; functionStatus = true; alert(http_request.responseText); } else { alert('AJAX request error.'); functionStatus = false; } } document.getElementById(destinationLayer).innerHTML = xmlReturn; return functionStatus; }