$(document).ready(function(){
    $('.mdpLost').click(function () {
        popinMdp();
        return false;
    });

});

function popinMdp(){

    var PageHeight = $(document).height();
    $('body').append('<div id="overlay-appear"></div>');
    $('#overlay-appear').css({
        height: PageHeight,
        opacity: 0
    });
    $('#overlay-appear').fadeTo('fast',0.8);
    $('body').append('\
        <div id="pop-mdp" class="back-png">\n\
	        <h4>Mot de passe oubli&eacute;</h4>\n\
	        <p id="pop-parag">Indiquez votre email</p>\n\
	        <form methode="post" action="">\n\
	    		<div style="height:45px;">\n\
	    			<p><input type="text" name="emailMdp" value="email" class="champ2" /></p>\n\
	    			<p class="messageMdp" style="margin-top:5px; font-weight:bold;"></p>\n\
	    		</div>\n\
	    		<p><input type="button" name="sendMdp" id="validez"/></p>\n\
	    	</form>\n\
	    	<div id="pop-btn-close">fermer</div>\n\
        </div>'
    );
    sizeElem();

    $(window).scroll(function(){
        sizeElem();
    });
    $(window).resize(function(){
        sizeElem();
    });

    function sizeElem(){
        contentScrollTop = $(window).scrollTop();
        contentScrollLeft = $(window).scrollLeft();
        $('#pop-mdp').css('top', ($(window).height()/2) + contentScrollTop - ($('#pop-mdp').height()/2));
        $('#pop-mdp').css('left', ($(window).width()/2) + contentScrollLeft - ($('#pop-mdp').width()/2));
    }

    $('#pop-btn-close').click(function(){
        $('#overlay-appear').fadeOut('fast',function(){
            $(this).remove();
        });
        $('#pop-mdp').fadeOut('fast',function(){
            $(this).remove();
        });
        return false;
    });





    $("#validez").click(function(){

        var email = $(".champ2").val();
        var message = $(".messageMdp");


         $.ajax({
           type: "POST",
           url: "lib/mdp.ajax.php",
           data: "emailMdp="+email,
           success: function(msg){
             message.html(msg);
             //alert( msg );

             if(msg == "Un nouveau mot de passe vient de vous &ecirc;tre envoy&eacute;."){


                 setTimeout('closePop()',4000);
             }

           }
         });

    });



}

function closePop(){


    $('#overlay-appear').fadeOut('fast',function(){
        $(this).remove();
    });
    $('#pop-mdp').fadeOut('fast',function(){
        $(this).remove();
    });
    return false;
}
