//
var commandCue = Array() ;
var loader = '<img src="/images/ajax-loader.gif" border="0">';

//Grab a URL, without using the queueing service
//Use this if you want to wait for a response
function xmlhttpGetWithLoader(url) {

  var statusDisplay ;

  var xmlHttpReq = false;
  var self = this;

  if (window.XMLHttpRequest) {
    // Mozilla/Safari
    self.xmlHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    // IE
    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }

  var requestURL = url ;

  self.xmlHttpReq.open('POST', requestURL, false);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.send('');
  if (self.xmlHttpReq.readyState == 4) {
        return self.xmlHttpReq.responseText ;
  }

  document.getElementById(divname).innerHTML = '';

}

//Grab a URL, without using the queueing service
//Use this if you want to wait for a response
function xmlhttpGet(url) {
  var statusDisplay ;

  var xmlHttpReq = false;
  var self = this;

  if (window.XMLHttpRequest) {
    // Mozilla/Safari
    self.xmlHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    // IE
    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }

  var requestURL = url ;

  self.xmlHttpReq.open('POST', requestURL, false);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.send('');
  if (self.xmlHttpReq.readyState == 4) {
        return self.xmlHttpReq.responseText ;
  }

}

//An internal function, do not use
function xmlhttpPost(divname, url) {
  var statusDisplay ;

  var xmlHttpReq = false;
  var self = this;
  var tempString ;

  if (window.XMLHttpRequest) {
    // Mozilla/Safari
    self.xmlHttpReq = new XMLHttpRequest();
  }
  else if (window.ActiveXObject) {
    // IE
    self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
  }

  var requestURL = url ;

  self.xmlHttpReq.open('POST', requestURL, true);
  self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  self.xmlHttpReq.onreadystatechange =

     function() {
       var responseText = "" ;
       if (self.xmlHttpReq.readyState == 4) {
         responseText = self.xmlHttpReq.responseText ;
         ajaxCallBack(divname, responseText) ;
       }
     }

  self.xmlHttpReq.send('');
}

//The main timer, do not use
function ajaxCallBack(divname, responseText) {
  var statusDisplay ;

  document.getElementById(divname).innerHTML = responseText;
  setTimeout("postCue()", 10) ;
}

//The main ajax call, will cue the ajax call up and execute this and
//all following requests in order
function cueXMLHTTPPost(divname, url) {
  var cuecount = commandCue.length ;

  var commandArray = Array()
  commandArray['divname'] = divname ;
  commandArray['url'] = url ;

  commandCue[cuecount] = commandArray ;

  if (cuecount ==0) {
    // because the cue was empty, kick the cue in to action
    setTimeout("postCue()", 10) ;
  }
}

//The main ajax call, will cue the ajax call up and execute this and
//all following requests in order
function cueXMLHTTPPostWithLoader(divname, url) {
  //document.getElementById(divname).innerHTML = loader;
  var cuecount = commandCue.length ;

  var commandArray = Array()
  commandArray['divname'] = divname ;
  commandArray['url'] = url ;

  commandCue[cuecount] = commandArray ;

  if (cuecount ==0) {
    // because the cue was empty, kick the cue in to action
    setTimeout("postCue()", 10) ;
  }
}

function postCue() {
  var cuecount = commandCue.length ;
  if (cuecount > 0) {
     var command = commandCue.shift() ;
     xmlhttpPost(command['divname'], command['url']) ;
  }
}


