var debug = true
var xmlHttpDuration = 1000;

function GetXmlHttpObject(xmlHttp) { 
// builds a XML HTTP request

  if (window.XMLHttpRequest) {
    xmlHttp=new XMLHttpRequest()
    if (xmlHttp.overrideMimeType)
      xmlHttp.overrideMimeType('text/html; charset=UTF-8');
  } else if (window.ActiveXObject) {
    try {
      xmlHttp = new ActiveXObject('Msxml2.XMLHTTP');
    } catch (e) {
      try {
        xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
      } catch (e) {}
    }
  }
  
  return xmlHttp
}

//"Range: bytes=%u-\r\n",m_uContentOffset

function doFeedId(mapArray, xmlHttp, time) {
  try {
    if (xmlHttp.readyState==4)
      if (xmlHttp.status == 200) {
      xmlHttpDuration = (new Date()).getTime() - time
      //document.getElementById(mapArray[0].id).innerHTML=xmlHttp.responseText
      instr = new String(xmlHttp.responseText)
      decompress()
      //document.getElementById(mapArray[0].id).innerHTML=outstr
      mapArray.shift()
      feedId(mapArray)
    } else
      if (debug) alert('HTTP Request (readyState,status)=('+xmlHttp.readyState+','+xmlHttp.status+')');
    }catch (e) {
    if (debug) alert('Caught Exception: ' + e.description);
  }
} 


function feedId(mapArray) {
/* mapArray shall be am array of such elements:
 * var map = { id:"myId", url:"myUrl" }
 * feedIdAsync sets a chain of XML http requests: each stateChange handler feeds an id and
 * sets the next http request, so that feedIds returns asynchronously.
*/


  if (mapArray.length > 0) {

    var xmlHttp = false
    xmlHttp = GetXmlHttpObject(xmlHttp)
    if (!xmlHttp) {
      if (debug) alert ("Browser does not support HTTP Request")
      return
    }

    xmlHttp.onreadystatechange = function() { doFeedId(mapArray, xmlHttp, (new Date()).getTime()); } 
    xmlHttp.open("GET", mapArray[0].url, true)
    xmlHttp.send(null)
  
  }
}
