jQuery(document).ready( function($) { 
    $('div#email_subscribe #submit').click( function() {
        if(check_email_form()) 
            mailpress_ajax();     
        return false;
    } );

    function check_email_form(){       
        mail=$("#input_email").val();
        if(mail.match('\\s*?[\\w-.]+@[\\w-]+(\\.[\\w-]+)+\\s*?')==null || mail.match('\\s*?[\\w-.]+@[\\w-]+(\\.[\\w-]+)*\\s*')[0]!=mail){
            $("#help_pop_up .pop_up_txt").text("Введите корректный email!!!");    
            $("#input_email").focus();      
            $("#help_pop_up").css("left","20px");
            $("#help_pop_up").show();
            return false;           
        }          
        if($("#input_email_name").val().length<2 || $("#input_email_name").val()==emailName_helper){
            $("#help_pop_up .pop_up_txt").text("Введите корректное имя!!!"); 
            $("#input_email_name").focus();         
            $("#help_pop_up").css("left","200px");        
            $("#help_pop_up").show();  
            return false;   
        }
        return true;
    }

    function mailpress_ajax()            
    {
        var data = {};
        var div = $('div#email_subscribe');
        $('form#mp-form [type!=submit]',div).each(function(){
            data[ $(this).attr('name') ] = $(this).val();
        });  
        $('#email_subscribe div.subscribe_chekbox_label div.subscribe_checkbox_cheked').each(function(){
            data[ $(this).attr('id') ] = "cheked";
        }); 
        if ($.browser.safari) { 
            $('div#email_subscribe div#mp-formdiv').css("position","relative");     
        }   
        $('div#email_subscribe div#mp-formdiv').fadeTo(500,0);
        $('div#email_subscribe div#mp-loading').css("z-index","100");     
        $('div#email_subscribe div#mp-loading').fadeTo(500,1);
     
        $.post(mp_url,data,function(data){mailpress_ajax_response(data);});
    }

    function mailpress_ajax_response(xd)
    {
         var mess = $('message',xd).text();
         var email = $('email',xd).text();

        $('div#email_subscribe form#mp-form [name=email]').val(email);

         $('div#email_subscribe div#mp-loading').fadeTo(500,0);
        $('div#email_subscribe div#mp-loading').css("z-index","-2");  
        $('div#email_subscribe div#mp-message').html(mess).fadeTo(1000,1);
     /*   $('#jGrowl_ajaxs').jGrowl(mess, { 
                    theme: 'smoke',
                    life: 10000,  
                    closer: false                    
                });   */
         setTimeout('mailpress_show_form()',4000);
    }

 } );
 
     function mailpress_show_form()
    {
         jQuery('div#email_subscribe div#mp-message').fadeTo(1000,0);
        jQuery('div#email_subscribe div#mp-formdiv').fadeTo(500,1);
    }




