
jQuery(function() {

    $('#newsletter').ajaxStart(function(){
       $(this).attr('disabled', true).val('Please wait ...');
    }).ajaxStart(function(){
        $(this).attr('disabled', false).val('');
    });

    $("#newsletter").focus(function(){
        if($.trim($(this).val()) == 'Your email') $(this).val('');
    }).blur(function(){
        if($.trim($(this).val()) == '') $(this).val('Your email');
    }).keypress(function(event){
        if(event.which == 13) $("#ok").trigger('click');
    });
   

    $("#ok").click(function () {
        if($.trim($("#newsletter").val()) == '') return false;

        if(! /^\s*[\w\-\+_]+(\.[\w\-\+_]+)*\@[\w\-\+_]+\.[\w\-\+_]+(\.[\w\-\+_]+)*\s*$/.test(jQuery('#newsletter').val())){
            alert('Please, enter a valid email adresse.');
            return false;
        }

        jQuery.post('/dev.php/newsletter', {
            adr: $('#newsletter').val()
        }, function(){ $("#msg_confirm").fadeIn();  $("#newsletter").val(''); });

    });
    
    $("#close").click(function(){
        $("#msg_confirm").fadeOut();
    });

});


