function processReqChange() 
{
	var self=this;
	this.check=function () {
    if (self.req.readyState == 4) 
  	{
      if (self.req.status == 200) 
  		{
  			self.handler(self.req.responseText);
  			delete self.req;
      } 
      else
      {
  			self.handler("GETURLERROR");
  			delete self.req;
      }
    }
  };	
}

function getURLGO()
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
 		var changeHandler = new processReqChange;
		changeHandler.handler=this.handler;
		changeHandler.req=this.req;
        this.req.onreadystatechange = changeHandler.check;
        this.req.open("GET", this.URL, true);
        this.req.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        this.req = new ActiveXObject("Microsoft.XMLHTTP");
        if (this.req) {
		var changeHandler = new processReqChange;
		changeHandler.handler=this.handler;
		changeHandler.req=this.req;
        this.req.onreadystatechange = changeHandler.check;
            this.req.open("GET", this.URL, true);
            this.req.send();
        }
    }
}

function getURL(URL,handler)
{
	this.URL=URL;
	if (handler)
	{
		this.handler=handler;
	}
	else
	{
		this.handler= defaultHandler;
	}
	this.go=getURLGO;
}

function defaultHandler(data)
{
	//purposely left blank
}

function postURLGO()
{
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        this.req = new XMLHttpRequest();
 
 		var changeHandler = new processReqChange;
		changeHandler.handler=this.handler;
		changeHandler.req=this.req;
        this.req.onreadystatechange = changeHandler.check;
        this.req.open("POST", this.URL, true);
				if ( typeof this.req.setRequestHeader !='undefined')
				{
					this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
				}
        this.req.send(this.postdata);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        this.req = new ActiveXObject("Microsoft.XMLHTTP");
        if (this.req) {
 
		var changeHandler = new processReqChange;
		changeHandler.handler=this.handler;
		changeHandler.req=this.req;
        this.req.onreadystatechange = changeHandler.check;
            this.req.open("POST", this.URL, true);
		this.req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            this.req.send(this.postdata);
        }
    }
}

function postURL(URL,handler)
{
	this.URL=URL;
	this.seperator='';
	this.postdata='';
	if (handler)
	{
		this.handler=handler;
	}
	else
	{
		this.handler= defaultHandler;
	}
	this.go=postURLGO;
	
	this.addpost = function(name,data)
	{
		this.postdata += this.seperator + name + '=' + encodeURIComponent(data);
		this.seperator='&';
	};
}


//style for creating this data can be seen in inc/geturl_functions.php
function geturl_parsedata(data)
{
 
  data_arr=data.split("|");
 
  data_obj=new Array;
  for(a=0;a<data_arr.length;a++)
  {
    item_arr=data_arr[a].split("=");
    if (item_arr[0]!="")
    {
      item_name=item_arr[0];
      item_name=item_name.replace("&equal;","=");
      item_name=item_name.replace("&pipe;","|");
      item_name=item_name.replace("&amp;","&");
     
      if (item_arr.length==2)
      {
        item_data=item_arr[1];
        item_data=item_data.replace("&equal;","=");
        item_data=item_data.replace("&pipe;","|");
        item_data=item_data.replace("&amp;","&");
       
        data_obj[item_name]=item_data;
      }
      else
      {
        item_data="";
        data_obj[item_name]=item_data;
      }
    }
  }
 
  return data_obj;
}


