
function did(id){return document.getElementById(id);}
function showWaitCursor( show, pos )
{
  var o=did((!pos || pos == 0) ? "waitcursor" : "waitcursor1" );
  if (o) o.innerHTML=(show ? "<img src='/images/wait20.gif'>" : "" );
}
function showError( line )
{
  if(did("errorinfo")) did("errorinfo").innerHTML = line;
}
function encu(str){return encodeURIComponent( str );}

function execAjax( url, callback_fn, waitcursorpos )
{
  var xmlhttp = null;
  if ( xmlhttp == null )
  {
    if (window.XMLHttpRequest)
    {// code for IE7, Firefox, Mozilla, etc.
      xmlhttp =new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {// code for IE5, IE6
      xmlhttp	 = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  else
  {
    xmlhttp.abort();
  }
  if (xmlhttp != null && ( xmlhttp.readyState == 4 || xmlhttp.readyState == 0 ) )
  {
    xmlhttp.onreadystatechange = 
    function() { 
      if( this.readyState==4 ) 
      { 
        showWaitCursor( false, waitcursorpos );
        if ( this.status==200 )
          callback_fn( this.responseText ); 
		
        this.obj = null; 
      } 
    };
    showWaitCursor( true, waitcursorpos );
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
  }
  else
  {
    // post("Your browser does not support XMLHTTP.");
  }
}

function execAjaxQuery( script, params, callbackfn, noauth,waitcursorpos )
{
  if (noauth)
    noauth=true;
  var url=script;
  if (noauth )
  {
    if (params && params != "" )
      url += "?" + params;
  }
  else
  {
    url += "?" + "u=" + username + "&t=" + token;
    if ( params && params != "" )
      url += "&" + params;
  }
  if (!waitcursorpos) waitcursorpos=0;
  //did('debuginfo').innerHTML=url;
  execAjax( url, onFetchedResponse,waitcursorpos );
  showError( "" );
  function onFetchedResponse(responseText)
  {
    var response = eval( '(' + responseText + ')' );
    if ( response.errcode == 0 )
    {
      callbackfn( response );
    }
    else if ( response.errcode == 120 )
      signOut();
    else
      showError( response.errmsg );
    this.obj = null;
  }
}

