
  var HttpRequest = {
    _XHR: null, ///< xml http request object

    GetXMLHttpRequest: function()
    {
      if (this._XHR === null) {
      	if(window.XMLHttpRequest) { // Mozilla, Safari, ...
      		this._XHR = new XMLHttpRequest();
      		if (this._XHR.overrideMimeType) {
      			this._XHR.overrideMimeType('text/html');
      		}
      	} else if (window.ActiveXObject) { // IE
      		try {
      			this._XHR = new ActiveXObject("Msxml2.XMLHTTP");
      		} catch (e) {
      			try {
      				this._XHR = new ActiveXObject("Microsoft.XMLHTTP");
      			} catch (e) {
              this._XHR = null;
            }
      		}
      	}
      }
      return(this._XHR);
    },

    /// make GET request to server
    /// @return bool    true on success;
    Get: function(url, callback)
    {
    	if (!this.GetXMLHttpRequest()) {
    	  return(false);
    	}

      try {
      	this.GetXMLHttpRequest().onreadystatechange = callback;
      	this.GetXMLHttpRequest().open('GET', url, true);
      	this.GetXMLHttpRequest().setRequestHeader("Content-type", "text/html");
      	this.GetXMLHttpRequest().setRequestHeader("Connection", "close");
      	this.GetXMLHttpRequest().send("");
      } catch (e) {
        return(false);
      }
      return(true);
    }

  };

  var SignUpFormHandler = {
    _SavedCaption: null,
    _suc: null, ///< SignUpCaption
    _suf: null, ///< SignUpForm
    _sue: null, ///< SignUpEmail
    _ResponseTexts: new Array(),

    _Init: function()
    {
      if ((this._suc === null) || (this._suf === null)) {
        this._suc = document.getElementById('signupcaption');
        this._suf = document.getElementById('SignUpForm');
        this._sue = document.getElementById('SignUpEmail');
      }
    },

    SetResponseText: function(Response,Value)
    {
//       alert(Response+'\n'+Value);
      this._ResponseTexts[Response] = Value;
    },

    Show: function()
    {
      SignUpFormHandler._Init();
      if ((SignUpFormHandler._suc) && (SignUpFormHandler._suf) && (SignUpFormHandler._sue)) {
        SignUpFormHandler._suc.style.display = 'none';
        SignUpFormHandler._suf.style.display = 'inline';
        SignUpFormHandler._sue.focus();
      }
    },

    Hide: function()
    {
      this._Init();
      if ((this._suc) && (this._suf)) {
        this._suc.style.cursor = 'pointer';
        this._suc.style.display = 'inline';
        this._suf.style.display = 'none';
      }
    },

    SetCaption: function(Caption,SavePreviousCaption)
    {
      if (Caption === undefined) {
        Caption = this._SavedCaption;
      }
      this._Init();
      if (this._suc) {
        if (SavePreviousCaption !== undefined) {
          this._SavedCaption = this._suc.innerHTML;
        }
        this._suc.innerHTML = Caption;
      }
    },

    /// @return bool    true on success;
    Request: function()
    {
      this.SetCaption(this._ResponseTexts['Processing'],true);
      this.Hide();
      if (this._sue) {
        if (this._suc) {
          this._suc.onclick = null;
          this._suc.style.textDecoration = 'none';
          this._suc.style.cursor = 'default';
        }

        var RequestString = AJAX_TARGET + '/newsletter_signup/' + escape(this._sue.value);
        return(HttpRequest.Get(RequestString,function(){SignUpFormHandler.RequestHandler();}));
      } else {
        return(false);
      }
    },

    RequestHandler: function()
    {
      if ((HttpRequest.GetXMLHttpRequest().readyState == 4) && (HttpRequest.GetXMLHttpRequest().status == 200)) {
        var s = '';
        if (this._ResponseTexts[HttpRequest.GetXMLHttpRequest().responseText] !== undefined) {
          s = this._ResponseTexts[HttpRequest.GetXMLHttpRequest().responseText];
        }

        setTimeout('SignUpFormHandler.RestoreCaption()',5000);
        SignUpFormHandler.SetCaption(s);
      }
    },

    RestoreCaption: function()
    {
      SignUpFormHandler.SetCaption();
      SignUpFormHandler._Init();
      if (SignUpFormHandler._suc) {
        SignUpFormHandler._suc.onclick = SignUpFormHandler.Show;
        SignUpFormHandler._suc.style.textDecoration = 'none';
        SignUpFormHandler._suc.style.cursor = 'pointer';
      }
    }

  };
