jQuery(document).ready(function(){

        jQuery('#send_message').click(function(e){
										  
            e.preventDefault();

            var error = false;
            var name = jQuery('#name').val();
            var email = jQuery('#email').val();
            var name_dest = jQuery('#name_dest').val();
            var email_dest = jQuery('#email_dest').val();
            var message = jQuery('#message').val();
            
            if(name.length == 0){
                var error = true;
                jQuery('#name_error').fadeIn(1000);
            }else{
                jQuery('#name_error').fadeOut(1000);
            }

            if(email.length == 0 || email.indexOf('@') == '-1'){
                var error = true;
                jQuery('#email_error').fadeIn(1000);
            }else{
                jQuery('#email_error').fadeOut(1000);
            }





            if(name_dest.length == 0){
                var error = true;
                jQuery('#namedest_error').fadeIn(1000);
            }else{
                jQuery('#namedest_error').fadeOut(1000);
            }
            if(email_dest.length == 0 || email_dest.indexOf('@') == '-1'){
                var error = true;
                jQuery('#emaildest_error').fadeIn(1000);
            }else{
                jQuery('#emaildest_error').fadeOut(1000);
            }
            

            if(error == false){

             //   jQuery('#send_message').attr({'disabled' : 'true', 'value' : 'Envoi en cours...'});

                jQuery.post("/wp-content/themes/TheProfessional/send.php", jQuery("#contact_form").serialize(),function(result){

                    if(result == 'sent'){

              

                        jQuery('#mail_success').fadeIn(1000);
                        jQuery('#mail_success').fadeOut(5000);
                   jQuery('#name').val("");
         jQuery('#email').val("");
jQuery('#name_dest').val("");
       jQuery('#email_dest').val("");
   jQuery('#message').val("");
                        // jQuery('#send_message').attr({'disabled' : 'false', 'value' : 'Envoyer'});
           
                    }else{
						
                        jQuery('#mail_fail').fadeIn(1000);
                        
                        jQuery('#send_message').removeAttr('disabled').attr('value', 'Message envoyé');
                    }
                });
            }
        });  
        
        

    });

// --- code popup ---
function openPopup() {
    jQuery(".contentpopup").clone(false).appendTo(jQuery("#_code"));
    jQuery("#_code").show();
}

function closePopup() {
    jQuery("#_code").html("");
    jQuery("#_code").hide();
}

function initCode() {
    jQuery(".code").click(openPopup);
    jQuery(".code").css({cursor: "pointer"});
    jQuery('body').append('<div id="_code"></div>');
    jQuery('#_code').css( {'text-align': "justify", position: "fixed",
                        left:0, top:0, width: "100%", height: "100%",
                        "background-color": "rgba(0, 0, 0, 0.8)", 'z-index':8882000, 'padding':'3px'} );
    jQuery('#_code').hide();
    jQuery('#_code').click(closePopup);
}
// --- end of code popup section ---



jQuery(document).ready(function(){




initCode();
});


jQuery(document).ready(function(){


   jQuery(".sf-with-ul").css("color","lightgrey");
});
