/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2010 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 254 2010-07-23 05:14:44Z emartin24 $
 */

jQuery(function ($) {
	// Load dialog on page load
	//$('#basic-modal-content').modal();

	// Load dialog on click
	$('#basic-modal .basic').click(function (e) {
        
        jQuery('#basic-modal-content').modal();

		return false;
	});
    
    $('.btn-parrainer a').click( function(){
       $('#basic-modal-content').load( 'inviter/manual_invite.php'); 
       
    });
    
    
    $('#btn_login_invite').click( function(){
        
        if( $('#login_email').val() == '' ||  $('#login_email').val() == ''){
            alert('invalid login data');
            return false;
        }
        
        $('#td_btn').append("<img src='images/images_201108/loading.gif' id='load_login' />");    
        
       $.ajax({
           type: "POST",
           url: "inviter/import_invite.php",
           data: $('#import_form').serialize(),
           dataType: 'text',
           success: function( msg){
                if( msg == 0)
                    alert('Infomations Invalides');
                else
                    $('#basic-modal-content').html( msg);
                    
             $('#load_login').remove();
             $('#pane').jScrollPane();
            }
        }); 
        return false;
        
    });
    
    
    //Send manual invite form
    $('#btn_invite_form').live('click', function() {
        $('#btn_invite_form a').append("<img src='images/images_201108/loading.gif' style='margin-left: 160px; margin-top: 14px' />");
        $.ajax({
           type: "POST",
           url: "ajax/invite_mail.php",
           data: $('#manual_invite_form').serialize(),
           dataType: 'json',
           success: function( res){
                alert('Votre filleul / Vos filleuls ont bien été parrainés.');
                $('.simplemodal-close').click();
            }
        });
        return false;
        
    });  
    
    
    //Check max 15 email for send invite
    $('form#manual_invite_form input[type=checkbox]').live( 'click', function(){
        if( $("form#manual_invite_form input[type=checkbox]:checked").length > 15){
            return false;
        }
    });
    
    
    //Login & Pass Mask   
    $('#identifiant_loginmask, #passwordmask').click( function(){
        var eleid_name = $( this).attr('id');
        $( this).hide();
        
        if( eleid_name == 'identifiant_loginmask'){
            $('#identifiant_login').focus();
        }else if( eleid_name == 'passwordmask'){
            $('#password').focus();
        }                  
    });
    
    $('#identifiant_login, #password').focus( function(){
        var eleid_name = $( this).attr('id');
        
        if( eleid_name == 'identifiant_login'){
            $('#identifiant_loginmask').hide();
        }else if( eleid_name == 'password'){
            $('#passwordmask').hide();
        }
    });
    
    $('#identifiant_login, #password').blur( function(){
        var eleid_name = $( this).attr('id');
        var elemask, eleid;
        
        if( eleid_name == 'identifiant_login'){
            eleid = $('#identifiant_login');
            elemask = $('#identifiant_loginmask');
        }else if( eleid_name == 'password'){
            eleid = $('#password');
            elemask = $('#passwordmask');
        }
        
        if( eleid.val() == ''){
           elemask.show(); 
        }else{
            elemask.hide();
        }
        
    });       
        
});



$(document).ready(function() {
   $(".parrainage-no").hover(function() {
        if ($(".hover-parrainage", this).css("display") == "block") { return false; }
        os = $(this).offset();
        $(".hover-parrainage", this).css({top: os.top+28+"px", left: "20px"}).animate({opacity: "show"}, 750);
    },
    function() {
        os = $(this).offset();
        $(".hover-parrainage", this).animate({top: os.top+"px", opacity: "hide"}, 500);
    });
    
    
    $('form#content-form').keypress(function(e){
          if(e.which == 13){
                $('form#content-form').submit();
           }
      });
      
      //fix remove lable login for remember od and password by browser
      if( $('#identifiant_login').val() != '')
        $('#identifiant_loginmask').hide();
      if( $('#password').val() != '')
        $('#passwordmask').hide();

});

