function AjaxObject() {
   this.POST = "POST";
   this.GET  = "GET";

   this.ASYNCHRONOUS_REQUEST = true;
   this.LINIER_REQUEST = false;

   this.url = "";
   this.params = "";
   this.urlParams = "";
   this.requestMethod = this.GET;
   this.writeToLayer = document.getElementsByTagName( "body" ).item( 0 );
   this.xmlHttpReq = false;
   this.responseText = "";
   this.responseHandler = function() {
      if ( local.xmlHttpReq.readyState == 4 )
      {
         local.responseText = local.xmlHttpReq.responseText;
         local.writeToLayer.innerHTML = local.responseText;
      }
   }

   this.intializeConnection = function() {
      if ( this.xmlHttpReq == false ) {
         if ( window.XMLHttpRequest )
         {
            this.xmlHttpReq = new XMLHttpRequest();
         }
         else if (window.ActiveXObject) {
            this.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
         }
      }
   }

   this.setUrl = function( newUrl ) {
      this.url = newUrl;
   }

   this.setParams = function( newParams ) {
      this.params = newParams;
   }

   this.setUrlParams = function( newUrlParams ) {
      this.urlParams = newUrlParams;
   }

   this.getUrlParams = function() {
      if ( this.urlParams != "" ) {
         return '?' + this.urlParams;
      }
      else {
         return '';
      }
   }

   this.getFinalUrlParams = function() {
      if ( this.requestMethod == this.POST ) {
         return '';
      }
      else {
         return this.getParams();
      }
   }

   this.getParams = function() {
      if ( this.params != '' ) {
         if ( this.urlParams != '' ) {
            return '&' + this.params;
         }
         else {
            return '?' + this.params;
         }
      }
      else {
         return "";
      }
   }

   this.getFinalSendParams = function() {
      if ( this.requestMethod == this.POST ) {
         return this.params;
      }
      else {
         return null;
      }
   }

   this.setRequestMethod = function( newRequestMethod ) {
      this.requestMethod = newRequestMethod;
   }

   this.setReponseHandler = function( newResponseHandler ) {
      this.responseHandler = newResponseHandler;
   }

   this.setWriteToLayer = function( newWriteToLayer ) {
      this.writeToLayer = document.getElementById( newWriteToLayer );
   }

   this.setResponseText = function( newResponseText ) {
      this.responseText = newResponseText;
   }

   this.getFinalUrl = function() {
      return this.url + this.getUrlParams() + this.getFinalUrlParams();
   }
   
   this.xmlhttpPost = function() {
      this.xmlHttpReq.open( this.requestMethod, this.getFinalUrl(), this.ASYNCHRONOUS_REQUEST );
      
      // alert( "FINAL URL: " + this.getFinalUrl() + "\nFINAL PARAMS: " + this.getFinalSendParams() + "\nMETHOD: " + this.requestMethod );
      
      // this.xmlHttpReq.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );

      this.xmlHttpReq.onreadystatechange = this.responseHandler;
      
      this.xmlHttpReq.send( this.getFinalSendParams() );
   }

   this.flush = function() {
         local.writeToLayer.innerHTML = "";
   }
   
   local = this;
}

ajaxInstance = new AjaxObject();
ajaxInstance.intializeConnection();
