if (typeof dynamo == "undefined") { 
  var dynamo = new Object();
}

if (typeof rootPath == "undefined") { 
  var rootPath = "";
}
  
if (typeof dynamo.newsletterInterface == "undefined") {
  dynamo.newsletterInterface = function() {
    this.ajax = new luckymarble.ajaxUtil();
    var oldonload = window.onload;

    if (typeof window.onload != 'function') {

      window.onload = function() {
        newsletter.initialize();
      }

    } else {

      window.onload = function() {

        if (oldonload) {

          oldonload();

        }

        newsletter.initialize();

      }
    }
  }

  dynamo.newsletterInterface.prototype = {
    subscribe: function () {
      if (window.location.href.indexOf("http")) {
        alert("Dynamo function not active from local web -- try again from live web address.");
      } else {
      
        myForm  = document.forms['dynamo_newsletter_signup_form'];
        myEmailField = myForm['dynamo_newsletter_email'];
        myEmailValue = myEmailField.value;
    
        myUserNameField = myForm['dynamo_newsletter_user_name'];
        myUserNameValue = myUserNameField.value;
    
        myFormatTypeField = myForm['dynamo_newsletter_format'];
        myFormatTypeValue = myFormatTypeField.value;
        
        // need to find the lists, if any
        var myLists = "";
        for (var i = 0; i < myForm.elements.length; i++) {
          if (myForm.elements[i].type == "checkbox" && myForm.elements[i].checked) {
            myLists = myLists + "&" + myForm.elements[i].name + "=yes";
          }
        }
        
        this.ajax.getAjaxRequest(rootPath + "dynamo/index.asp", "module=newsletter&component=signup_box-ajax&cmd=add_subscriber&bypass=1&email="+myEmailValue+"&user_name="+myUserNameValue+"&format_type="+myFormatTypeValue + myLists, this.processGetPost, "txt");
      }
    },
    unsubscribe: function () {
      if (window.location.href.indexOf("http")) {
        alert("Dynamo function not active from local web -- try again from live web address.");
      } else {
        myForm  = document.forms['dynamo_newsletter_signup_form'];
        myEmailField = myForm['dynamo_newsletter_email'];
        myEmailValue = myEmailField.value;
    
        this.ajax.getAjaxRequest(rootPath + "dynamo/index.asp", "module=newsletter&component=signup_box-ajax&cmd=remove_subscriber&bypass=1&email="+myEmailValue, this.processGetPost, "txt");
      }
    },                                                      
    processGetPost: function() {
      var myAjax     = dynamo.newsletterInterfaceObj.ajax.ajaxObj;
      var myFileType = dynamo.newsletterInterfaceObj.ajax.fileType;
  
      if (myAjax.readyState == "4") {
        if (myAjax.status == 200 || window.location.href.indexOf("http") == -1) {
          if (myFileType == "txt") {
            if (myAjax.responseText != "") {
              alert(myAjax.responseText);
            }
          } else {
            alert(myAjax.responseXML);
          }
        } else  {
          alert(myAjax.status + " Error:\nNewsletter subscription currently not available.\n\nPlease contact webmaster.");
        }
      } 
    },
    processListGetPost: function() {
      var myAjax     = dynamo.newsletterInterfaceObj.ajax.ajaxObj;
      var myFileType = dynamo.newsletterInterfaceObj.ajax.fileType;
  
      if (myAjax.readyState == "4") {
        if (myAjax.status == 200 || window.location.href.indexOf("http") == -1) {
          if (myFileType == "txt") {
            if (myAjax.responseText != "") {
              var signupElementsContainer = document.getElementById('dynamo_newsletter_signup_middle');
              var buttonDiv = document.getElementById('dynamo_newsletter_form_buttons'); 
              var listElement = document.createElement("div");
              listElement.innerHTML = myAjax.responseText;
              
              signupElementsContainer.insertBefore(listElement, buttonDiv);
            }
          } else {
            alert(myAjax.responseXML);
          }
        } else  {
          //alert(myAjax.status + " Error:\nNewsletter subscription currently not available.\n\nPlease contact webmaster.");
        }
        newsletter.brand();
      } 
      
    },
    initialize: function() {   
      this.ajax.getAjaxRequest(rootPath + "dynamo/index.asp", "module=newsletter&component=signup_box-ajax&cmd=getlists&bypass=1&page="+document.location, this.processListGetPost, "txt");
      
    },  
    brand: function() {}
  }

  dynamo.newsletterInterfaceObj = new dynamo.newsletterInterface();
  newsletter = dynamo.newsletterInterfaceObj;
}