var xmlhttp;
var bIsFirstLoad=true;

function AjaxRequest(url){
  hideTooltip();
  bAlertCookieShown=false;
  if(!bIsFirstLoad)
  {
    document.getElementById('loadbartable').style.display='block';
    document.getElementById('loadbartable').style.visibility='visible';
    document.getElementById('loadbar').style.display='block';
  }
  bIsFirstLoad=false; // is not the first time an ajax request is done 
  xmlhttp=null;
//   code for Mozilla, etc.
  if (window.XMLHttpRequest){
    xmlhttp=new XMLHttpRequest();
  }
//   code for IE
  else if (window.ActiveXObject){
//     IE7 (and newer)
    try
    {
      if ( ActiveXObject("Msxml2.XMLHTTP") ){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
//     IE6 and older
      }else{
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    } catch(e) {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
  }
  if (xmlhttp!=null){
    xmlhttp.onreadystatechange=state_Change;
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
  }
  else{
    alert("Your browser does not support XMLHTTP.");
  }
}

function state_Change(){

  // if xmlhttp shows "loaded"
  if (xmlhttp.readyState==4){
      document.getElementById('loadbar').style.display='none';
      document.getElementById('loadbartable').style.visibility='hidden';
      document.getElementById('loadbartable').style.display='none';
      document.getElementById('contenttd').style.visibility='visible';
    // if "OK"
//     alert(xmlhttp.status);
    if (xmlhttp.status==200){
//       document.getElementById('loadbar').style.display='none';
//       document.getElementById('loadbartable').style.visibility='hidden';
//       document.getElementById('loadbartable').style.display='none';
//       document.getElementById('contenttd').style.visibility='visible';
      responseText = xmlhttp.responseText;

      var entities = htmlentities(responseText);

      try // this might throw an error since requests to 'assistantredirector.exe' return no valid javascript statement
      {
        eval(entities);
      } catch (exc){
//         alert('(' +exc.toString()+ ') - not yet implemented ;)');
      }
    }
    else if (xmlhttp.status==204){
//       do nothing (HTTP 204 - NO CONTENT)
    }    
    else{
      alert("Problem retrieving XML data\n"+xmlhttp.responseText +"\nxmlhttp.status: "+xmlhttp.status+"\n");
      
    }
  }
}


function htmlentities(str,typ) {
  if(typeof str=="undefined") str="";
  if(typeof typ!="number") typ=2;
  typ=Math.max(0,Math.min(3,parseInt(typ)));
  var html=new Array();
//   html[38]="&amp;"; 
//   html[60]="&lt;"; html[62]="&gt;";
  if(typ==1 || typ==3) html[39]="&#039;";
  if(typ==2 || typ==3) html[34]="&quot;";
  for(var i in html) eval("str=str.replace(/"+String.fromCharCode(i)+"/g,\""+html[i]+"\");");
  var entity=new Array(
    "&nbsp;","&iexcl;","&cent;","&pound;","&curren;","&yen;","&brvbar;","&sect;",
    "&uml;","&copy;","&ordf;","&laquo;","&not;","&shy;","&reg;","&macr;",
    "&deg;","&plusmn;","&sup2;","&sup3;","&acute;","&micro;","&para;","&middot;",
    "&cedil;","&sup1;","&ordm;","&raquo;","&frac14;","&frac12;","&frac34;","&iquest;",
    "&Agrave;","&Aacute;","&Acirc;","&Atilde;","&Auml;","&Aring;","&AElig;","&Ccedil;",
    "&Egrave;","&Eacute;","&Ecirc;","&Euml;","&Igrave;","&Iacute;","&Icirc;","&Iuml;",
    "&ETH;","&Ntilde;","&Ograve;","&Oacute;","&Ocirc;","&Otilde;","&Ouml;","&times;",
    "&Oslash;","&Ugrave;","&Uacute;","&Ucirc;","&Uuml;","&Yacute;","&THORN;","&szlig;",
    "&agrave;","&aacute;","&acirc;","&atilde;","&auml;","&aring;","&aelig;","&ccedil;",
    "&egrave;","&eacute;","&ecirc;","&euml;","&igrave;","&iacute;","&icirc;","&iuml;",
    "&eth;","&ntilde;","&ograve;","&oacute;","&ocirc;","&otilde;","&ouml;","&divide;",
    "&oslash;","&ugrave;","&uacute;","&ucirc;","&uuml;","&yacute;","&thorn;","&yuml;"
  );
  for(var i in entity) eval("str=str.replace(/"+String.fromCharCode(i*1+160)+"/g,\""+entity[i]+"\");");
  return str;
}
