//The browser detection function.
//This function can be used for other purposes also.

function UserAgent()
{
  var b=navigator.appName.toUpperCase();

  if (b=="NETSCAPE") this.b="ns";
  else if (b=="MICROSOFT INTERNET EXPLORER") this.b="ie";
  else if (b=="OPERA") this.b="op";
  else this.b=b;

  this.version=navigator.appVersion;
  this.v=parseInt(this.version);

  this.ns=(this.b=="ns" && this.v>=4);
  this.ns4=(this.b=="ns" && this.v==4);
  this.ns5=(this.b=="ns" && this.v==5);

  this.ie=(this.b=="ie" && this.v>=4);
  this.ie4=(this.version.indexOf('MSIE 4')>0);
  this.ie5=(this.version.indexOf('MSIE 5')>0);
  this.ie55=(this.version.indexOf('MSIE 5.5')>0);
  this.ie6=(this.version.indexOf('MSIE 6')>0);

  this.op = (this.b=="op");
  this.op4 = (this.b=="op" && this.v==4);
  this.op5 = (this.b=="op" && this.v==5);
}

at=new UserAgent();

//if you want to create the frame or layer dynamically, do not
//specify a name, do something like this, new exchanger();
function exchanger(name)
{
  this.lyr = null;
  this.frm = null;
  this.obj = null;

  this.name=name||"";
  this.fakeid=0;

  if (name == null || name=="")
  {
   alert('The name must not be null!!!');
   return;
  }
  else
  {
    this.name=name;
    if (at.ns4)
    {
     this.lyr = window.document.layers[this.name];
     this.obj = this.lyr;
    }
    else
    if (at.ie || at.ns5 || at.op)
    {
     this.frm = window.frames[this.name];
     this.obj = this.frm;
    }
    else
    {
     alert('Error while checking for browser version!!!');
     return;
    }
  }
}

exchanger.prototype.sendData=function(url)
{
  //window.status += '-3';
  this.fakeid += 1;
  var newurl = "";

//Keeping parameter ...
  this.url = url;
//Computing new url ...
  if (url.indexOf("?") >= 0)
    newurl = url + "&fakeId" + this.fakeid;
  else
    newurl = url + "?fakeId" + this.fakeid;
//Changing the url of the document ...
  if (this.lyr != null)
  {
    var oReq;
    if (window.XMLHttpRequest)
    {
        oReq = new XMLHttpRequest();
    }
    else
    {
        oReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    oReq.open("GET", newurl, false);
    oReq.send();
    //window.status += '-4';
    this.lyr.document.clear();
    //window.status += '-5';
    this.lyr.document.write(oReq.responseText);
    //window.status += '-6';
    this.lyr.document.close();
   //this.lyr.src=newurl;
  }
  else if (this.frm != null)
  {
    if(! self.oReq )
    {
        if (window.XMLHttpRequest)
        {// IE 7 - Mozilla
            self.oReq = new XMLHttpRequest();
        }
        else
        {//IE 6
            self.oReq = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    //window.status += '-4';
    self.oReq.open("GET", newurl, false);
    self.oReq.send();
    //window.status += '-5';
    try
    {
        this.frm.document.clear();
        //window.status += '-6';
        this.frm.document.write(self.oReq.responseText);
        //window.status += '-6b';
        this.frm.document.close();
    }
    catch(e)
    {
        ;
    }
  }
}

exchanger.prototype.sendData2=function(url)
{
  this.fakeid += 1;
  var newurl = "";

//Keeping parameter ...
  this.url = url;
//Computing new url ...
  if (url.indexOf("?") >= 0)
    newurl = url + "&fakeId" + this.fakeid;
  else
    newurl = url + "?fakeId" + this.fakeid;
//Changing the url of the document ...
  if (this.lyr != null)
   this.lyr.src=newurl;
  else
  if (this.frm != null)
   this.frm.document.location.replace(newurl);
}
