/* -------------------------------------------------------------
   You may use this code as you need it, but do leave 
   the authors name somewhere in it please. Thanks.
   (c) 2005-3010 Renzo Kooi/NICon
   -------------------------------------------------------------*/
RSL          = RSL;
gbAppend     = false;
defStat      = RSL_setStat;
remoteApp    = '';
allowHTML    = false;
noStatChange = false;
goRS         = new Object();

function RSL()
{
  if (arguments.length<1)
  { this.result = 'ERROR: no query string provided!';
    alert(this.result);
    return false
  }

  if (!remoteApp || remoteApp == '')
  { this.result = 'ERROR: remote app unknown!\n'
                  +'Please supply the path of the remote\n'
                  +'application this object should use\n'
                  +'either in this object file or in the\n'
                  +'additional client scripting';
    alert(this.result);
    return false
  }

  this.oQ           = arguments[0];
  var oExTest       = this.oQ.callback;

    if (!String(oExTest).match(/undef|null/) || !oExTest)
     if ( (String(typeof oExTest).match(/funct|obj/i)))
      this.exit      = oExTest;
    else
     this.exit       = function() {return true};

  var sQNow         = new RSL_ComposeQuery(this.oQ);
  this.sSrc         = remoteApp+'?'+sQNow.sQ;
  this.initScr      = RSL_setScript;
  this.dispatch     = RSL_dispatchMOZ;
}

function RSL_setScript()
{
   var tScript    = document.createElement('script');
   tScript.id     = 'remotejs';
   tScript.defer  = true;
   tScript.onload = function(){return true};

   tScript.setAttribute('src',this.sSrc);

   if (!gbAppend)
   {
    var oRemote = document.createElement('div');
    oRemote.id  = 'remote';
    document.body.appendChild(oRemote);
    document.getElementById('remote').appendChild(tScript);
    gbAppend    = true;
   }
   else
   {
     var oRDiv = document.getElementById('remote');
     oRDiv.removeChild(oRDiv.firstChild);
     oRDiv.appendChild(tScript);
   }
 }

function RSL_ComposeQuery(oArgs)
{
  var aWrk  = new Array();
  var sT = '';
  for (var i in oArgs)
   if (i != 'callback')
   { var sArg = oArgs[i].replace(/\+/g,'&#43;');

      if (!allowHTML)
      {
       sArg = sArg.replace(/</g,'&lt;');
       sArg = sArg.replace(/>/g,'&gt;');
      }

     aWrk.push(i+'='+escape(sArg))
   }

  this.sQ = aWrk.join('&');
}

function RSL_dispatchMOZ(sStat)
{ 
  if (String(navigator.userAgent).match(/gecko/i))
  {
   var oDisp = document.getElementById('Moz_Dispatcher');
   if (sStat && !noStatChange)
    oDisp.onload=function(){top.defStat(sStat)}
   oDisp.src=''; return
  }
  else if (sStat && !noStatChange)
   defStat(sStat);
}

function RSL_setStat(sTxt)
{  window.defaultStatus = sTxt; }
