
function subscribe()
{
   checkSubscribeValues();$('div#newsletter_layer_wrapper').load('http://cb-news.de/subscribe.php', {
         newsletter: '94',
         EMAIL: $('input#EMAIL').attr('value'),
         SURNAME: $('input#SURNAME').attr('value'),
         FIRSTNAME: $('input#FIRSTNAME').attr('value'),
         ADDRESS: $('input#ADDRESS').attr('value'),
         HOUSENR: $('input#HOUSENR').attr('value'),
         CITY: $('input#CITY').attr('value')

      });
}

               function checkSubscribeValues() {
                  checkDefaultValue("FIRSTNAME", "Vorname");
                  checkDefaultValue("SURNAME", "Nachname");
                  checkDefaultValue("ADDRESS", "Strasse");
                  checkDefaultValue("HOUSENR", "Hausnr");
                  checkDefaultValue("CITY", "Stadt");
                  checkDefaultValue("EMAIL", "meine E-mail");
                  checkDefaultValue("EMAIL_UN", "meine E-mail");
                  tActionNode = document.getElementsByName("subscribeaction")[0];
                  if (null != tActionNode) {
                     if ("subscribe" == tActionNode.value) {
                        tMailNode = document.getElementsByName("EMAIL")[0];
                     }
                     if (null != tMailNode) {
                        return checkMail(tMailNode.value);
                     }
                  }
                  return false;
               }

               function checkDefaultValue(pNodename, pDefaultValue) {
                  tNode = document.getElementsByName(pNodename)[0];
                  if (null != tNode) {
                     if (pDefaultValue == tNode.value) {
                        tNode.value = "";
                     }
                  }
               }
                              
               function checkMail(pEmail)
               {
                  var filter  = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                  if (filter.test(pEmail)) {
                     return true;
                  } else {
                     alert("Die von Ihnen eingegebene Email-Adresse ist inkorrekt : " + pEmail);
                  }
                  return false;
               }

function checkSubscribe()
{
   if (checkSubscribeValues()) {
      var tAction = document.getElementsByName('subscribeaction')[0];
      //alert(tAction.value);
      //alert($('input#subscribeaction').attr('value'));
      //alert($('input#FIRSTNAME').attr('value'));
      //alert($('input#SURNAME').attr('value'));
      //alert($('input#ADDRESS').attr('value'));
      //alert($('input#HOUSENR').attr('value'));
      //alert($('input#CITY').attr('value'));
      //alert($('input#EMAIL').attr('value'));
      $.post('/module/forms/ajax/newsletter_subscribe.php',
            {
               user : newsletterUserID,
               newsletter : newsletterID,
               languageID : languageID,
               subscribeaction: 'subscribe',
               FIRSTNAME: $('input#FIRSTNAME').attr('value'),
               SURNAME: $('input#SURNAME').attr('value'),
               ADDRESS: $('input#ADDRESS').attr('value'),
               HOUSENR: $('input#HOUSENR').attr('value'),
               CITY: $('input#CITY').attr('value'),
               EMAIL: $('input#EMAIL').attr('value')
            },
            function(data) {
               //var tTmp = document.createElement('div');
               //tTmp.innerHTML = data;
               var tClose = '<div id="newsletter_close"><a onclick="showAjaxWaitDialog(false, null);$(\'div#layer_wrapper\').slideUp(\'slow\');" href="javascript://"><img alt="Fenster schliessen" src="pics/close_login.gif"/></a></div>';
               
               document.getElementById("layer_wrapper").innerHTML = '<div id="newsletter_layer"><div id="newsletter_layer_inner">' + tClose + data + '</div></div>';
               //alert(data);
            }
         ); //.post
   }
}


function checkSubscribeSubmit() {
   var tForm = document.forms["subscribeform"];
   var tResult = AIM.submit(tForm, {'onStart' : checkSubscribeValues, 'onComplete' : completeCallback});
   if (tResult) {
      tForm.submit();
   }
}

function completeCallback(response) {
   alert('completeCallback: ' + response);
}

AIM = {

    frame : function(c) {

        var n = 'f' + Math.floor(Math.random() * 99999);
        var d = document.createElement('DIV');
        d.innerHTML = '<iframe style="display:none" src="about:blank" id="'+n+'" name="'+n+'" onload="AIM.loaded(\''+n+'\')"></iframe>';
        document.body.appendChild(d);

        var i = document.getElementById(n);
        if (c && typeof(c.onComplete) == 'function') {
            i.onComplete = c.onComplete;
        }

        return n;
    },

    form : function(f, name) {
        f.setAttribute('target', name);
    },

    submit : function(f, c) {
        AIM.form(f, AIM.frame(c));
        if (c && typeof(c.onStart) == 'function') {
            return c.onStart();
        } else {
            return true;
        }
    },

    loaded : function(id) {
        var i = document.getElementById(id);
            var d = window.frames[id].document;
        if (i.contentDocument) {
            var d = i.contentDocument;
        } else if (i.contentWindow) {
            var d = i.contentWindow.document;
        } else {
            var d = window.frames[id].document;
        }
        if (d.location.href == "about:blank") {
            return;
        }

        if (typeof(i.onComplete) == 'function') {
            i.onComplete(d.body.innerHTML);
        }
    }

}

