$(document).ready(function() {
        
        jQuery.validator.addMethod("properEmail", function(value, element) {
                return this.optional(element) || /^([\w\.]+)(@([\w\.-]+\.\w{2,5}))$/.test(value);
        }, "Your email address must be in form name@domain.com");
        
        var val = $("#emailform").validate({
                rules: {"email"          : { required: true, properEmail: true }},
                messages: {"email"       : { required: "Vul uw e-mailadres in.", properEmail: "Je e-mailadres moet in de vorm zijn van naam@domein.com"}}
                });
        
        $("#send").click(function(){
                if(!val.form()) {
                        var bb = new Boxy('<h2>Uw gegevens zijn niet compleet.</h2><p><a href="#" onclick="Boxy.get(this).hide(); return false;">venster sluiten</a></p>', {modal: true});    
                }
                else {
                        var postURL = "saveData.php";
                        $.ajax({
                          cache:false,
                          async:false,
                          type: "POST",
                          data: "email=" + $("#email").val(),
                          url: postURL,
                          success: function(msg) {
                              if (msg=='TRUE') {
                                var bb = new Boxy('<p><strong>Dank u wel.</strong><br />Uw email adres is verstuurd en u ontvangt bericht als de actie van start gaat.</p><p><a href="#" onclick="Boxy.get(this).hide(); return false;">venster sluiten</a></p>', {modal: true});      
                                //alert("Dank u wel. Uw email adres is verstuurd en u ontvangt bericht als de actie van start gaat.");
                                $("#email").val("");
                             } else {   
                                var bb = new Boxy('<p><strong>E-mail adres al in gebruik!</strong></p><p><a href="#" onclick="Boxy.get(this).hide(); return false;">venster sluiten</a></p>', {modal: true});                                                         
                                //alert("E-mail adres al in gebruik!");
                              }
                          }
                        });      
                         
                } 
             
              return false;       
        });
});