    /**
     * Attempt to obtain an HTTP Request object/handle which the current browser can
     * use for AJAX requests to the server for dynamic content.
     *
     * Usage:  PRIVATE!  This function is intended for the sole use of other functions within this script.
     */
    var xmlHttp=null;
    function GetXmlHttpObject()
    {
       if (xmlHttp==null) {
            if (typeof XMLHttpRequest != "undefined") {
                xmlHttp = new XMLHttpRequest();
            } else if (window.ActiveXObject) {
                var aVersions = [ "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0",
                        "MSXML2.XMLHttp","Microsoft.XMLHttp"
                    ];

                for (var i = 0; i < aVersions.length; i++) {
                    try {
                        xmlHttp = new ActiveXObject(aVersions[i]);
                        return xmlHttp;
                    } catch (oError) {
                        //Do nothing
                    }
                }
            }
            if (xmlHttp==null) {
                 throw new Error("XMLHttp object could be created.");
            }
       }
       return xmlHttp;
    }



   /**
    * Create an XML Document from a string of text.
    */
   function createXMLDocumentFromText(text)
   {
       var xmlDoc;

       try //Internet Explorer
       {
alert('create xmldoc for ' + text);
           xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
           xmlDoc.async = "false";
           if (text.indexOf(" & ")>0) {
              text = text.replace(/ & /g," &amp; ");
           }
           if (text.indexOf("--")>0) {
              text = text.replace(/--/g," - ");
           }
           xmlDoc.loadXML(text);
       } catch(e) {
           try //Firefox, Mozilla, Opera, etc.
           {
              var parser = new DOMParser();
              xmlDoc = parser.parseFromString(text, "text/xml");
           } catch(e) {
              alert ("Warning: Browser does not currently support dynamic processing (HTTP Requests) used for page updates.");
              alert(e.message)
              xmlDoc = null;
           }
       }

       return xmlDoc;
   }


   /**
    * Process HTTP Response as XML document.
    */
   function handleResponseAsXML(httpResponse) {
alert('Handling response...' + httpResponse.readyState);
       if (httpResponse.readyState == 4 || httpResponse.readyState == "complete") { 
          var xmlDoc;
          if (httpResponse.responseXML != null && httpResponse.responseXML.length > 0) {
              xmlDoc = httpResponse.responseXML;
          } else if (httpResponse.responseText != null && httpResponse.responseText.length > 0) {
              xmlDoc = createXMLDocumentFromText(httpResponse.responseText);
          } else {
              xmlDoc = null;
          }

          return xmlDoc;
       }
   }


   /**
    * Using AJAX, retrieve content from the specified URL but delegate response handling to the
    * supplied function.
    */
   function acquireContentAsXML(pgUrl) {
       var xmlRequestor = GetXmlHttpObject();
       if (xmlRequestor == null) {
          alert ("Warning: Browser does not currently support dynamic processing (HTTP Requests) used for page updates.");
          return;
       } 

       var url = null;
       if (pgUrl.indexOf("?")>0) {
          url = pgUrl + "&rid=" + Math.random();
       } else {
          url = pgUrl + "?rid=" + Math.random();
       }

alert('Get RSS feed from ' + url);

           // note: unless caller prevents, cacheing may occur...
//       xmlRequestor.onreadystatechange = handleResponseAsXML();
//       xmlRequestor.open("GET", url, true);
       xmlRequestor.open("GET", url, false);
       xmlRequestor.send(null);

       var xmlDoc = handleResponseAsXML(xmlRequestor);

       return xmlDoc;
   }


    /**
     * Using AJAX, retrieve content for the specified document element from the specified file/url.
     * Enables content, such as the navigation bar, which is used widely amongst the various pages,
     * to be defined once and automatically included into actual display pages at runtime; also, enables
     * pages, such as the calendar, to dynamically update only portions of their content without requiring
     * complete refreshes.
     *
     * Usage:  1. Include scripts.js page into target
     *         2. Define dynamic target element using 'span' and 'id' components
     *         3. Incorporate inline script invoking function and passing both id & content filename.
     *
     * Content:  Must be defined as valid XHTML and have all appropriate CSS references 
     */
    function includeContent(id,pgUrl)
    {
       var target = document.getElementById(id);

       if (pgUrl.length == 0)
       { 
         target.innerHTML="";
         return;
       }

       var httpRequestor = GetXmlHttpObject();
       if (httpRequestor == null)
       {
          alert ("Warning: Browser does not currently support dynamic processing (HTTP Requests) used for page updates.");
          return;
       } 

       //alert ("script loading content from " + pgUrl + " for " + id);
       var url = pgUrl + "?sid=" + Math.random();
       httpRequestor.open("GET", url, false);
       httpRequestor.send(null);
       //alert ("retrieved " + httpRequestor.responseText);
       target.innerHTML=httpRequestor.responseText;
    }


    function rotateActiveSpan(show)
    {
       alert("Activate/Show=" + show + ":" + rotatingSpanIDs[show] + ":" + rotatingSpanIDs.length);
       for (var i=0; i<rotatingSpanIDs.length; i++) {
          var nextSpan = document.getElementById(rotatingSpanIDs[i]);
          //alert("Assign style for span=" + rotatingSpanIDs[i]);
          if (nextSpan!=null) {
             if (i==show) {
                 nextSpan.style.display = 'inline';
             } else {
                 nextSpan.style.display = 'none';
             }
          } 
       }
    }


    /**
     * requires caller to define 'rotatingSpanIDs' as
     *   var rotatingSpanIDs = ["pg1","pg2","pg3",...];
     *
     * note: if any page(s) contain images, it is recommended the caller preload them by
     * adding 'onLoad' action to body tag.
     */
    var firstOnly = true;
    function updateRotatingContent(showing,delay)
    {
       //alert("updateRotatingContent for " + showing);
       if (firstOnly==true) {
          var spanelements = document.getElementsByTagName("span");
          if (spanelements!=null) {
             for (var se=0; se<spanelements.length; se++) {
                 alert("found span element: " + spanelements[se].id);
             }
          }
          firstOnly = false;
       }

       if (rotatingSpanIDs == null)
          return;

       var next = showing + 1;
       if (next >= rotatingSpanIDs.length)
           next = 0;

       //alert("rotate span");
       rotateActiveSpan(showing); 

       var repeat = "updateRotatingContent(" + next + "," + delay + ")";
       var tOut = setTimeout(repeat, delay);

       //alert("repeating TO: " + repeat);
   }


    /**
     * requires caller to define 'rotatingPages' as
     *   var rotatingPages = ["pg1","pg2","pg3",...];
     *
     * note: if any page(s) contain images, it is recommended the caller preload them by
     * adding 'onLoad' action to body tag.
     */
    function includeRotatingContent(id,delay,showing)
    {
       if (rotatingPages == null)
          return;

       var next = showing + 1;
       if (next >= rotatingPages.length)
           next = 0;

       //alert("elementbyid: " + id);
       includeContent(id,rotatingPages[showing]);

       var repeat = "includeRotatingContent('" + id + "'," + delay + "," + next + ")";
       var tOut = setTimeout(repeat, delay);

       //alert("repeating TO: " + repeat);
   }














































    /**
     * Create a table definition containing the content of the specified RSS feed,
     * upto 'maxMessages' individual entries and write it to the designated document
     * element.
     */
    var maxMessages = 8;
    function includeContentFromRSSFeed(id,pgUrl,ifEmpty)
    {
       if (pgUrl.length == 0)
       { 
         document.getElementById(id).innerHTML = '<font color=#800000>' + ifEmpty + '</font>';
         return;
       }

       var rssData = acquireContentAsXML(pgUrl);

        if (rssData != null) {
//            var rssVers		= rssData.getElementsByTagName("rss");
            var channel		= rssData.getElementsByTagName("channel");
            var titles		= rssData.getElementsByTagName("title");
            var items		= rssData.getElementsByTagName("item");
            var links		= rssData.getElementsByTagName("link");
            var pubDates	= rssData.getElementsByTagName("pubDate");
            var descriptions	= rssData.getElementsByTagName("description");

            var formattedContent = "<table width='100%' cellspacing=0 cellpadding=4>";

            var n = 0;
            var cn = 0;
            for (; n<titles.length && n<maxMessages; n++) {
                 var newsLink  = "";
                 for (cn=0; cn<links[n].childNodes.length && newsLink==""; cn++) {
                     newsLink = links[n].childNodes[cn].nodeValue;
                 }

                 var newsTitle  = "";
                 for (cn=0; cn<titles[n].childNodes.length && newsTitle==""; cn++) {
                     newsTitle = titles[n].childNodes[cn].nodeValue;
                 }

                 var newsDescription  = "";
                 for (cn=0; cn<descriptions[n].childNodes.length && newsDescription==""; cn++) {
                     newsDescription = descriptions[n].childNodes[cn].nodeValue;
                 }

                 if (n==0) {
                     var rssTitle = newsDescription;
                     if (rssTitle=="")
                         rssTitle = newsTitle;
                     formattedContent += "<thead><tr>";
                     formattedContent += "<td align=left valign=top width='470' bgColor=6060a0><b><font color=#ffffff>" + rssTitle + "</font></b></td>";
                     formattedContent += "<td align=right valign=top width='200' bgColor=6060a0><a href=\"" + newsLink + "\" target=hslda><font color=#ffffff>More...</font></a></td>";
                     formattedContent += "</tr></thead>";
                 } else {
                     formattedContent += "<tr>";
                     formattedContent += "<td align=left valign=top width='470'><a href=\"" + newsLink + "\" target=hslda><b><font color=#800000>" + newsTitle + "</font></b></a></td>";
                     formattedContent += "<td align=left valign=top width='200'>" + pubDates[n].childNodes[0].nodeValue + "</td>";
                     formattedContent += "</tr>";
                     if (newsDescription!="") {
                        formattedContent += "<tr><td align=left valign=top colspan=2>" + newsDescription + "</td></tr>";
                     }
                 }
            }
            if (n<1) {
                formattedContent += "<thead><tr>";
                formattedContent += "<td align=left valign=top colspan=2 bgColor=6060a0><b><font color=#ffffff>" + ifEmpty + "</font></b></td>";
                formattedContent += "</tr></thead><tbody><tr><td/></tr></tbody>";
            }
            formattedContent += "</table>";

alert('Interpreted as: ' + formattedContent);
            document.getElementById(id).innerHTML = formattedContent;
        } else {
            document.getElementById(id).innerHTML = '<font color=#800000>' + ifEmpty + '</font>';
        }
    }

