//TODO: FIND ALL USES OF THE CODE IN THE TOP HALF OF THIS FILE AND REPLACE IT WITH CODE IN BOTTOM HALF
//TODO: THEN PERHAPS REMOVE XMLHTTP_ PREFIX?

    var xmlHttpReq = null;
    var targetId   = 'theContent';

    function tgt(nn) {
        if ( nn == 1 ) {
            targetId = 'theContent';
        } else if ( nn == 2 ) {
            targetId = 'ctl00_QuickLaunchContent_theContent';
        } else if ( nn == 3 ) {
            targetId = 'theStudent';
        } else if ( nn == 4 ) {
            targetId = 'ctl00_QuickLaunchContent_theStudent';
        } else {
            targetId = 'theContent';
        }
    }

    function go(nn, url) {
      tgt(nn);
      //document.location.href=url;
      loadXmlDoc(url, null);
    }

    function go2(nn, url, querystring) {
      tgt(nn);
      loadXmlDoc(url, querystring);
    }

    function go3(tgt, url) {
      targetId = tgt;
      loadXmlDoc(url, null);
    }

    function go4(tgt, url, querystring) {
      targetId = tgt;
      loadXmlDoc(url, querystring);
    }

    function loadXmlDoc(url, querystring) {
      // code for Mozilla, etc.
      if (window.xmlHttpRequest) {
        xmlHttpReq=new XMLHttpRequest();
      }
      // code for IE
      else if (window.ActiveXObject) {
        xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
      }

      if (xmlHttpReq!=null) {
        xmlHttpReq.onreadystatechange=onResponse;
        if ( ( querystring == null) || ( querystring == '' ) ) {
          xmlHttpReq.open("GET",url,true);
        } else {
          xmlHttpReq.open("GET", url + "?" + querystring, true);
        }
        xmlHttpReq.send(null);
      } else {
        alert("Your browser does not support XMLHTTP.");
      }
    }

    function checkReadyState(obj) {
      if(obj.readyState == 4) {
        if(obj.status == 200) {
          return true;
        } else {
          alert("Problem retrieving XML data");
        }
      }
    }

    function onResponse() {
      if(checkReadyState(xmlHttpReq)) {
        document.getElementById(targetId).innerHTML = xmlHttpReq.responseText;
      }
    }

    function commandLineToArray(s) {
      var done      = 0;
      var args      = new Array();
      var numArgs   = 0;
      var firstChar = '';
      var matchChar = '';
      var matchPos  = -1;

      while ( done != 1 ) {
        if ( s.length == 0 ) {
          done = 1;
        } else {
          firstChar = s.charAt(0);
          if ( firstChar == '"' ) {
            matchChar = '"';
          } else if ( firstChar == '\'' ) {
            matchChar = '\'';
          } else {
            matchChar = ' ';
          }
          matchPos  = s.indexOf(matchChar, 1);
          if ( matchPos == -1 ) {
            //Missing matching quote OR end of string
            if ( matchChar == ' ' ) {
              // Unquoted case, just hit end of string
              args[numArgs]  = s.substring(0);
            } else {
              // Quoted case, hit end of string without matching quote
              // Really an error, but we'll just treat things like there was a final quote
              args[numArgs]  = s.substring(1);
            }
            numArgs       += 1;
            s              = null;
            done           = 1;
          } else {
            if ( matchChar == ' ' ) {
              // Unquoted case
              args[numArgs]  = s.substring(0, matchPos);
            } else {
              // Quote case
              args[numArgs]  = s.substring(1, matchPos);
            }
            numArgs       += 1;
            s              = s.substring(matchPos+1);
            // Check to see if we're at the end of string. If so, short circuit and be done
            // Also, handle trailing space -- just ignore it
            if ( s.length == 0 ) {
              s = null;
              done = 1;
            } else if ( ( s.length == 1 ) && ( s.charAt(0) == ' ' ) ) {
              s = null;
              done = 1;
            }
          }
        }
      }
      return ( args );
    }

  // ----------- BELOW HERE IS THE GOOD VERSION WITH ONLY ONE GLOBAL VARIABLE -----------

  function XMLHTTP_getPage(url, querystring) {
    XMLHTTP_getPageIntoSpan(url, querystring, null, null);
  }

  function XMLHTTP_getPageIntoSpan(url, querystring, docObj, spanId) {
    //alert('Within XMLHTTP_getPageIntoSpan: url=' + url);

    xmlHttpReq = null;

    // code for Mozilla, etc.
    if (window.XMLHttpRequest) {
      xmlHttpReq=new XMLHttpRequest();
    }
    // code for IE
    else if (window.ActiveXObject) {
      xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP");
    }

    if (xmlHttpReq!=null) {

      // TODO: Figure out if these lines are right and whether to include them...
      //xmlHttpReq.overrideMimeType('text/xml');
      //xmlHttpReq.setRequestHeader('Cache-Control', 'no-cache');

      functRef = XMLHTTP_callLater(xmlHttpReq, url, querystring, docObj, spanId);
      xmlHttpReq.onreadystatechange=functRef;
      if ( ( querystring == null) || ( querystring == '' ) ) {
        xmlHttpReq.open("GET",url,true);
      } else {
        xmlHttpReq.open("GET", url + "?" + querystring, true);
      }
      xmlHttpReq.send(null);
    } else {
      alert("Your browser does not support XMLHTTP.");
    }
  }

  function XMLHTTP_checkReadyState(obj, url, querystring, docObj, spanId) {
    if(obj.readyState == 4) {
       if(obj.status == 200) {
        return true;
      } else {
        alert("Problem retrieving XML data");
      }
    }
  }

  function XMLHTTP_callLater(obj, url, querystring, docObj, spanId) {
    return ( function() {
               XMLHTTP_onResponse(obj, url, querystring, docObj, spanId);
             } );
  }

  function XMLHTTP_onResponse(obj, url, querystring, docObj, spanId) {
    if(XMLHTTP_checkReadyState(obj, url, querystring, docObj, spanId)) {
      // We have the ready xml object in the global xmlHttpReq now
      if ( ( docObj != null ) && ( spanId != null ) ) {
        docObj.getElementById(spanId).innerHTML = xmlHttpReq.responseText;
      }
    }
  }
