var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  function checkEmail(email) { 
    var pattern = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    var emailVal = $("#" + email).val();
    return pattern.test(emailVal);
  }
  
  
  $(function() {
    $("#subForm input:submit").click(function() { 
      
      // First, disable the form from submitting
      $('form#subForm').submit(function() { return false; });
      
      // Grab form action
      var formAction = $("form#subForm").attr("action");
      
      // Hacking together id for email field
      // Replace the xxxxx below:
      // If your form action were http://mysiteaddress.createsend.com/t/r/s/abcde/, then you'd enter "abcde" below
      var id = "ukyddy";
      var emailId = id + "-" + id;
      
      // Validate email address with regex
      if (!checkEmail(emailId)) {
        alert("Bitte geben Sie eine gueltige eMail-Adresse an");
        return;
      }
      
      // Serialize form values to be submitted with POST
      var str = $("form#subForm").serialize();
      
      // Add form action to end of serialized data
      // CDATA is used to avoid validation errors
      //<![CDATA[
      var serialized = str + "&action=" + formAction;
      // ]]>
      
      // Submit the form via ajax
      $.ajax({
        url: "/php/proxy.php",
        type: "POST",
        data: serialized,
        success: function(data){
          // Server-side validation
          if (data.search(/invalid/i) != -1) {
            alert('Ihre eMail-Adress-Eingabe ist leider ungueltig und muss fuer eine erfolgreiche Registrierung korrigiert werden.');
          }
          else
          {
            $("#facebox").overlay({

				// custom top position
				top: 260,

					// some mask tweaks suitable for facebox-looking dialogs
				mask: {

					// you might also consider a "transparent" color for the mask
				color: '#fff',

				// load mask a little faster
				loadSpeed: 200,

				// very transparent
				opacity: 0.5
				},

				// disable this for modal dialog-type of overlays
				closeOnClick: false,

					// load it immediately after the construction
				load: true

				});
          }
        }
      });
    });
  });
