
var beAjax =
{
   _msxml_progid :
       [
       'MSXML2.XMLHTTP.3.0',
       'MSXML2.XMLHTTP',
       'Microsoft.XMLHTTP'
       ],

   getConnection : function ()
   { 
      try
       {
        // Instantiates XMLHttpRequest in non-IE browsers.
        http = new XMLHttpRequest();
       }
      catch(e)
       {
        for(var i=0; i < this._msxml_progid.length; ++i)
          try
           {
             // Instantiates XMLHttpRequest for IE.
             http = new ActiveXObject(this._msxml_progid[i]);
             break;
           }
          catch(e){}
       }
      finally { return http; }
   },

   request : function(method, url, callback, postData)
   {
      var conn = this.getConnection();
      if(!conn) return null;
      
      conn.open(method, url, true);
      conn.onreadystatechange = function()
      {
         if(conn.readyState != 4) return;
         
         if(conn.status >= 200 && conn.status < 300 && callback)
          {
           if(callback.onSuccess)
            {
             try { var vars = eval('(' + conn.responseText + ')'); }
             catch(e) { vars = null; }
             callback.onSuccess(conn, vars);
            }
          }
         else
           if(callback.onFailure) callback.onFailure(conn);
      }
      if(postData)
        conn.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      conn.send(postData || null);
   },

   sendForm : function(form, callback, postData, url)
   {
      if(typeof form == 'string')
        oForm = (document.getElementById(form) || document.forms[form]);
      else if(typeof form == 'object')
        oForm = form;
      else return null;
      
      if(!oForm) return null;
      
      var io = this.createFrame();
      if(!io) return null;
      
      if(url) oForm.action = url;
      oForm.target = io.id;

      var uploadCallback = function()
      {
        resp = {};
        try
        {
         resp.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
         resp.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
        }
        catch(e){}

        if(callback && callback.onSuccess)
         {
          try { var vars = eval('(' + resp.responseText + ')'); }
          catch(e) { vars = null; }
          callback.onSuccess(resp, vars);
         }
        try
         { 
          try { io.execCommand('Stop'); }
          catch(e) { try { io.stop(); } catch(e) {} }
          if(window.detachEvent)
            io.detachEvent('onload', uploadCallback);
          else
            io.removeEventListener('load', uploadCallback, false);
          document.body.removeChild(io);
          delete io;
         }
        catch (e) {}
//            setTimeout(function(){ document.body.removeChild(io); }, 100);
      };

      // Bind the onload handler to the iframe to detect the file upload response.
      if(window.attachEvent)
        io.attachEvent('onload', uploadCallback);
      else
        io.addEventListener('load', uploadCallback, false);

      if(postData) this.appendPostData(oForm, postData);
      oForm.submit();
      return io;
   },

   stopFormSending : function(container)
   {
      if(container)
        try
         {
          try { container.contentWindow.document.execCommand('Stop'); }
          catch(e) { try { container.stop(); } catch(e) {} }
          document.body.removeChild(container);
          delete container;
         }
        catch(e) {}
   },
   
   createFrame : function()
   {
      // IE does not allow the setting of id and name attributes as object
      // properties via createElement().  A different iframe creation
      // pattern is required for IE.
      var frameID = 'frmIO' + (new Date()).getMilliseconds();
      if(window.ActiveXObject)
       {
        var io = document.createElement('<iframe id="' + frameID + '" name="' + frameID + '" />');

        // IE will throw a security exception in an SSL environment if the
        // iframe source is undefined.
        io.src = 'javascript:false';
       }
      else
       {
        var io = document.createElement('iframe');
        io.id = frameID;
        io.name = frameID;
       }

      io.style.position = 'absolute';
      io.style.top = '-1000px';
      io.style.left = '-1000px';

      document.body.appendChild(io);
      return io;
   },

   appendPostData : function(form, postData)
   {
      var postMessage;
      if(typeof postData == "string")
       {
        postFields = postData.split('&');
        for(var i=0; i < postFields.length; i++)
         {
          var delimitPos = postFields[i].indexOf('=');
          if(delimitPos != -1)
           {
            formElement = document.createElement('input');
            formElement.type = 'hidden';
            formElement.name = postFields[i].substring(0,delimitPos);
            formElement.value = postFields[i].substring(delimitPos+1);
            form.appendChild(formElement);
           }
         }
       }
      else if(typeof postData == "object")
       {
        postFields = postData;
        for(var i in postFields)
         {
          formElement = document.createElement('input');
          formElement.type = 'hidden';
          formElement.name = i;
          formElement.value = postFields[i];
          form.appendChild(formElement);
         }
       }
   },

    formToString : function(oForm)
    {
        var oElement, oName, oValue, oDisabled;
        var hasSubmit = false;
        var _sFormData = '';
        // Iterate over the form elements collection to construct the
        // label-value pairs.
        for (var i=0; i<oForm.elements.length; i++)
         {
            oElement = oForm.elements[i];
            oDisabled = oForm.elements[i].disabled;
            oName = oForm.elements[i].name;
            oValue = oForm.elements[i].value;

            // Do not submit fields that are disabled or
            // do not have a name attribute value.
            if(!oDisabled && oName)
            {
                switch (oElement.type)
                {
                    case 'select-one':
                    case 'select-multiple':
                        for(var j=0; j<oElement.options.length; j++){
                            if(oElement.options[j].selected){
                                if(window.ActiveXObject){
                                    _sFormData += encodeURIComponentNew(oName) + '=' + encodeURIComponentNew(oElement.options[j].attributes['value'].specified?oElement.options[j].value:oElement.options[j].text) + '&';
                                }
                                else{
                                    _sFormData += encodeURIComponentNew(oName) + '=' + encodeURIComponentNew(oElement.options[j].hasAttribute('value')?oElement.options[j].value:oElement.options[j].text) + '&';
                                }

                            }
                        }
                        break;
                    case 'radio':
                    case 'checkbox':
                        if(oElement.checked){
                            _sFormData += encodeURIComponentNew(oName) + '=' + encodeURIComponentNew(oValue) + '&';
                        }
                        break;
                    case 'file':
                        // stub case as XMLHttpRequest will only send the file path as a string.
                    case undefined:
                        // stub case for fieldset element which returns undefined.
                    case 'reset':
                        // stub case for input type reset button.
                    case 'button':
                        // stub case for input type button elements.
                        break;
                    case 'submit':
                        if(hasSubmit == false){
                            _sFormData += encodeURIComponentNew(oName) + '=' + encodeURIComponentNew(oValue) + '&';
                            hasSubmit = true;
                        }
                        break;
                    default:
                        _sFormData += encodeURIComponentNew(oName) + '=' + encodeURIComponentNew(oValue) + '&';
                        break;
                }
            }
        }

        _sFormData = _sFormData.substr(0, _sFormData.length - 1);
        return _sFormData;
    }
};

   var hexchars = "0123456789ABCDEF";
   var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
   var ascii = "€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—?™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ";

   function encodeURIComponentNew(s)
   {
     enc = "";
     for(i = 0; i < s.length; i++)
      {
       if(okURIchars.indexOf(s.charAt(i))==-1)
         enc += "%" + toHex((n = s.charCodeAt(i)) < 0x80 ? n : 0x80 + ascii.indexOf(s.charAt(i)) );
       else
         enc += s.charAt(i);
      }
     return enc;
   }

   function toHex(n)
   {
     return hexchars.charAt(n>>4) + hexchars.charAt(n & 0xF);
   }

