function newRequest() { // create the XML data structures req = false; // For Safari, Firefox, and other non-MS browsers if (window.XMLHttpRequest) { try { req = new XMLHttpRequest(); XML = new XMLHttpRequest(); } catch (e) { req = false; XML = false; } } else if (window.ActiveXObject) { // For Internet Explorer on Windows try { req = new ActiveXObject("Msxml2.XMLHTTP"); XML = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); XML = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { req = false; XML = false; } } } } // ******************************************************************* function newData() { // called when XML data is returned if (XML.readyState != 4) { return; } // once the data is loaded reset the newDataLoaded flag for the diaplyData routine if (XML.status == 200) { if (XML.responseXML) { newDataLoaded = true; message.innerHTML = ""; } else { message.innerHTML = "Error retrieving new XML data. (data is not XML)"; } } else { message.innerHTML = "Error retrieving new XML data. (" + XML.status + ")"; } } // ******************************************************************* function getXML(dontWait) { newDataLoaded = false; XML.open("POST", "edot.xml", dontWait); if (dontWait) { XML.onreadystatechange = newData; } XML.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); XML.send(""); if (dontWait) { message.innerHTML = ""; } else { req = XML; } } // ******************************************************************* // ******************************************************************* function parseData() { var xml = (req.responseXML); // get the actuall XML data if (xml) { // is it really XML data? // extract the parameters params = xml.getElementsByTagName("parameters"); var this_param = params[0]; rows = this_param.attributes.getNamedItem("ROW_COUNT").value; cols = this_param.attributes.getNamedItem("COLUMN_COUNT").value; dataTS = this_param.attributes.getNamedItem("TIMESTAMP").value; pageCount = this_param.attributes.getNamedItem("PAGE_COUNT").value; referesh = this_param.attributes.getNamedItem("REFRESH_RATE").value; // load the raw data into global data structures all_codes = xml.getElementsByTagName("code"); all_papers= xml.getElementsByTagName("paper"); // extract the sytle data var instr = xml.getElementsByTagName("instr"); var instr = instr[0]; var header= xml.getElementsByTagName("header"); var header= header[0]; var cells = xml.getElementsByTagName("cells"); var cells = cells[0]; var instrFontSize = instr.attributes.getNamedItem("fontSize").value; var headerFontSize= header.attributes.getNamedItem("fontSize").value; var headerColor = header.attributes.getNamedItem("color").value; var headerbgColor = header.attributes.getNamedItem("bgColor").value; var cellsFontSize = cells.attributes.getNamedItem("fontSize").value; // set the styles based on the data extracted var hdr = document.getElementById ("HDR"); hdr.style.fontSize = headerFontSize; hdr.style.color = headerColor; hdr.style.backgroundColor = headerbgColor; // set the attributes of the style sheets for the table cells var theRules = new Array(); if (document.styleSheets[0].cssRules) { theRules = document.styleSheets[0].cssRules; } else if (document.styleSheets[0].rules) { theRules = document.styleSheets[0].rules; } theRules[0].style.fontSize = cellsFontSize; theRules[1].style.fontSize = instrFontSize; // set the table cells background color style var all_statusColor = xml.getElementsByTagName("statusColor"); for (var i = 0; i < all_statusColor.length; i++) { thisStatusColor = all_statusColor[i]; var fgColor = thisStatusColor.attributes.getNamedItem("color").value; var bgColor = thisStatusColor.attributes.getNamedItem("backgroundColor").value; theRules[i+3].style.color = fgColor; theRules[i+3].style.backgroundColor = bgColor; } return (true); } return (false); } // ******************************************************************* function gen_cell_data (row, col) { // write the paper data for a single element in the array (indx) // get the data for this paper from the XML data structure // indx is calculate based on the cells being built row by row // whereas the paper data is displayed sorted column by column var indx = ( (thisPage-1)*(rows*cols) ) + ((col-1)*rows) + row - 1 if (indx <= all_papers.length-1 ) { // else no more papers var this_paper = all_papers[indx]; var ID = this_paper.attributes.getNamedItem("SESSION").value; var SEQ = this_paper.attributes.getNamedItem("SEQUENCE").value; var CODE = this_paper.attributes.getNamedItem("CODE").value; bodyText = bodyText + '' + ID + SEQ + ''; } } // ******************************************************************* function displayData() { // update the current data (req) with new data (XML) if (thisPage == 1) { if (newDataLoaded) { req = XML; parseData(); } } // create the table data bodyText = ""; // loop through the rows and columns and write the data for (var i = 1; i <= rows; i++) { bodyText = bodyText + ""; for (var j = 1; j <= cols; j++) { gen_cell_data(i, j); } bodyText = bodyText + ""; } bodyText = bodyText + "
"; bodyHTML.innerHTML = bodyText; // set some informative text pages.innerHTML = "Page " + thisPage + " of " + pageCount; timestamp.innerHTML = dataTS; // requery the XML data; but do not wait; javascript keeps running if (thisPage == pageCount) { getXML(true); } thisPage = thisPage + 1; // loop back to the first page after displaying the last page if (thisPage > pageCount) { thisPage = 1; } // Note: refresh rate in seconds, function requires milliseconds setTimeout ("displayData()", referesh*1000); } // ******************************************************************* // ******************************************************************* function loadDots() { // message is needed to display any error messages on the web browser. message = document.getElementById ("MSG"); // create the data structures newRequest(); if (!req) { message.innerHTML = "newRequest failed"; return; } // initial load of the XML data; wait for data to return getXML(false); if (req.status != 200) { message.innerHTML = "There was a communications error."; return; } if (parseData()) { // more browser text fiedls pages = document.getElementById ("PAGES"); timestamp = document.getElementById ("TIMESTAMP"); bodyHTML = document.getElementById ("BODYHTML"); // initialization bodyText = ""; thisPage = 1; newDataLoaded = false; // write the data into the table cells; this kicks of an infinite loop displayData(); } else { message.innerHTML = "Error parsing data."; } } // end of function