
// Jean 06/08/2009 (création de ce fichier)

//var SocialEngine.Language = SocialEngineAPI.Language();

var jeton_25_05_2010 = true;

SocialEngineAPI.Profile = new Class({

  // Class
  Implements: [Options],

  tabIbTimeout: Array(),
  ibTimeout: null,
  ibTimeoutH: null,
  isOnMouseOver: false,
  largeurInfoBulle : 600,
  hauteurInfoBulle : 125,

  lastInfoBulleContent : null,
  lastUserName : null,
  lastUserId : null,

  // Properties
  Base: {},


  options: {
    'ajaxURL' : 'profile_ajax.php',
    'ajaxMethod' : 'post',
    'ajaxSecure' : false,

    'defaultView' : false
  },


  userExists: false,


  userInfo: {},

  infoBulle_hide: function()
   {
    clearTimeout(this.ibTimeout);
    clearTimeout(this.ibTimeoutH);
    this.ibTimeoutH = setTimeout("if (!SocialEngine.Profile.isOnMouseOver) SocialEngine.Profile.infoBulle_hide_suite();", 200);
   },

  infoBulle_hide_suite: function()
   {
/*
    $('infobulle_user').innerHTML = '';
    $('infobulle_user').style.visibility = 'hidden';
    $('infobulle_user').style.display = 'none';
*/
    $('infobulle_user').fade('out');
    setTimeout("$('infobulle_user').innerHTML = ''; $('infobulle_user').style.visibility = 'hidden'; $('infobulle_user').style.display = 'none'", 300);
   },

  infoBulle_show: function(username, userID, timeout, ev)
   {
    var x, y;
    if (ev.x!=null && ev.y!=null) { x = ev.x; y = ev.y; }
    if (ev.clientX!=null && ev.clientY!=null) { x = ev.clientX; y = ev.clientY; }

    clearTimeout(this.ibTimeout);
    clearTimeout(this.ibTimeoutH);
    this.ibTimeout = setTimeout("SocialEngine.Profile.infoBulle_show_suite("+ (username ? "'"+ username +"'" : "null") +", "+ (userID ? userID : "null") +","+ x +","+ y +");", timeout != null ? timeout : 200);
   },

  infoBulle_show_suite: function(username, userID, x, y)
   {
    // Image d'attente...
    $('infobulle_user').style.width = '200px';
    $('infobulle_user').innerHTML = "<div onmouseover='SocialEngine.Profile.isOnMouseOver = true;'"
                                       +" onmouseout='SocialEngine.Profile.isOnMouseOver = false; SocialEngine.Profile.infoBulle_hide();' "
                                       +" class='infobulle_wait_content'>"
                                       +"<img src='/"+ SocialEngine.Profile.options.subdir +"images/icons/loading2.gif' alt='Quelques instants...' width='32' height='32' border='0' /></div>";
    this.positionneInfoBulle(x, y);
    this.rendVisibleInfoBulle();

    // Si on vient tout juste de récupérer l'info demandée
    if (this.lastUserName == username && username != null  ||  this.lastUserId == userID && userID != null)
     {
      $('infobulle_user').innerHTML = this.lastInfoBulleContent;
      $('infobulle_user').style.width = this.largeurInfoBulle +'px';
      this.positionneInfoBulle(x, y);
      return;
     }

    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'get_user_infos',
        'username' : username,
        'user_id' : userID,
        'from_admin' : SocialEngine.Profile.options.fromAdmin ? "1" : "0"
      },
      'onComplete':function(responseObject)
      {
        if( $type(responseObject)!="object" || !responseObject.result || responseObject.result=="failure" )
         {
          if (responseObject && responseObject.is_debug) alert(responseObject.error);
          /*
          else alert(SocialEngine.Language.Translate(3000153));
          */
         }
        else
         {
           var userInfos = responseObject.infos;

           strHtml = "<div onmouseover='SocialEngine.Profile.isOnMouseOver = true;' onmouseout='SocialEngine.Profile.isOnMouseOver = false; SocialEngine.Profile.infoBulle_hide();' "
                        +" class='infobulle_content'"
                        +" style='"+ (isIE ? ' margin-left: 3px;' : '') +"'>";
           if (!userInfos)
            {
             $('infobulle_user').innerHTML = strHtml +'<center><b><big>?</big></b></center></div>';
             $('infobulle_user').style.width = '100px';
             SocialEngine.Profile.positionneInfoBulle(x, y);
             return;
            }

           // Jean 27/08/2009 : le "status"
           if (userInfos['status'] && userInfos['status'] != "")
             strHtml += '<div style="position: absolute; padding: 48px 0px 0px 17px; width: 200px; color: #000; font: lighter 11px/1.3 Arial,sans-serif; text-decoration: none; text-align: center;">'
                          +'<div style="background: url(/'+ SocialEngine.Profile.options.subdir +'images/phylactere.gif) no-repeat top;">'
                            +'<div style="position: absolute; width: 192px; padding-top: 21px; text-align: right;">'
                               +'<a href="javascript:;" onclick="this.parentNode.parentNode.parentNode.style.display = \'none\';" style="font-size: 13px; text-decoration: none; font-weight: normal;">x</a>'
                            +'</div>'
                            +'<div style="padding: 30px 8px 0; font-size: 10px;">'+ userInfos['status'] +'</div>'
                          +'</div>'
                          +'<div style="background: url(/'+ SocialEngine.Profile.options.subdir +'images/phylactere.gif) no-repeat bottom; overflow: hidden; height: 11px;">&nbsp;</div>'
                        +'</div>';

           strHtml += '<table cellpadding="2" width="100%" border="0">';
           strHtml += '<tr>';
           strHtml += '<td valign="top" style="width: 60px; padding: 0px;">';
           strHtml += '<a href="/'+ userInfos['username'] +'--'+ to_url(userInfos['displayname']) +'">';
           strHtml += '<img src="'+ userInfos['photo_src'] +'" class="photo" style="display: block; margin-left: auto; margin-right: auto;" width="60" height="60" border="0" /></a>';
           strHtml += '</td>';
           strHtml += '<td valign="top">';

           strHtml += '<table cellpadding="3" width="100%" border="0">';

           strHtml += '<tr><td colspan="2" style="padding: 0px; font-weight: bold; font-size: 12px;" valign="top">';
           strHtml += '<a target="_blank" href="/'+ userInfos['username'] +'--'+ to_url(userInfos['displayname']) +'">'+ userInfos['displayname'] +'</a>';

           strHtml += '<span style="float: right; font-size: 10px; font-weight: normal;"><i>';

           // Jean 24/02/2010 : Pour les CM, on indique clairement si les utilisaturs sont en "mode brouillon"
           if (userInfos['user_enabled'] == "NO" )
             strHtml += '<font style="font-size: 14px;"><font class="com_manager">'+ SocialEngine.Language.Translate(3000728) +'</font>'
                      + ' '
                      + '<a href="'+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'admin/admin_viewusers_edit.php?user_id='+ userInfos['user_id'] +'" target="_blank">'
                      + '<font style="color: #AA0000; font-weight: bold;">'+ SocialEngine.Language.Translate(1137) +'&nbsp;</font></font> / ';  // État : désactivé

           // Jean 08/09/2009 : nombre d'amis
           strHtml += userInfos['nb_friends'] +' '+ SocialEngine.Language.Translate(3000844);

           // Jean 16/11/2009 : date de création
           if (userInfos['signupdate'] != "")
             strHtml += ', '+ SocialEngine.Language.Translate(850) +' '+ userInfos['signupdate'];

           // Jean 27/08/2009 : date de dernière connexion
           if (userInfos['lastlogindate'] != "")
             strHtml += ', '+ SocialEngine.Language.Translate(906) +' '+ userInfos['lastlogindate'];

           strHtml += '</i></span>';

           strHtml += '</td></tr>';

           // "Fait partie des %1$s" (user level)
           strHtml += '<tr><td valign="top" align="left" colspan="2"><i>'
                    + SocialEngine.Language.TranslateFormatted(3000827,['<a href="/'+ SocialEngine.Profile.options.subdir +'search_advanced.php?user_level='+ userInfos['level_id'] +'">'+ userInfos['profile'].toLowerCase() +'</a>']);

           // Jean 19/05/2010 -  / comité éditorial
           if (userInfos['user_belongs_comity'] == '1')
             strHtml += ' / <font style="color: #DD0000; font-weight: bold;">'+ SocialEngine.Language.Translate(3510265).toLowerCase() +'</font>';

           // Jean 17/06/2010 -  / utilisateur certifié
           if (userInfos['user_is_certifed'] == '1')
             strHtml += ' <div style="float: right; color: #1B5C8D;"><img src="images/icons/verified-account.png" align="absmiddle" /> '+ SocialEngine.Language.Translate(3510615) +'</div>';

           strHtml += '</i></td></tr>';

           cpt = 0;
           for (var lib in userInfos['profile_values'])
            {
             if (userInfos['profile_values'][lib])
               strHtml += "<tr><td valign='top' align='right' style='width: 140px;'"+ (userInfos.for_com_managers && userInfos.for_com_managers[lib] == "1" ? 'class=com_manager' : '') +">"
                        + lib +"&nbsp;: </td>"
                        + '<td valign="top">'
                          + '<font '+ (userInfos.for_com_managers && userInfos.for_com_managers[lib] == "1" ? 'class=com_manager' : 'color=black') +'>'
                          + userInfos['profile_values'][lib].replace(/\n/g,'<br>') +'</font>'
                        + '</td></tr>';
             // On laisse la place pour l'éventuel phylactère
             /*
             if (cpt++ == 1 && userInfos['status'] != "")
               strHtml += "<tr><td colspan='2' style='height: 50px;'></td></tr>";
             */
            }
           strHtml += '<tr><td colspan="2">';
           for (var lib in userInfos['buz'])
            {
             if (userInfos['buz'][lib][0])
               strHtml += '&nbsp;<a target="_blank" href="'+ userInfos['buz'][lib][0] +'">'
                         +'<img align="absmiddle" title="'+ lib +'\r\r'+ userInfos['buz'][lib][0] +'" border="0" src="/'+ SocialEngine.Profile.options.subdir +'images/icons/sociable/'+ userInfos['buz'][lib][1] +'" /></a>';
            }
           strHtml += '<div style="float: right;">';
           strHtml += '<div align="right">';

           var cptLiensCtxels = 0;

           // Jean 27/08/2009 : on désactive les interrations avec cet utilisateur si on est dans la console d'admin,
           // car on peut s'être logué à la place de qq d'autre
           if (!SocialEngine.Profile.options.fromAdmin)
            {
             // Lien "SEND MESSAGE"
             if (userInfos['message_enabled'] == "1")
             {
              strHtml += '<a href="javascript:;" onclick="SocialEngine.Profile.infoBulle_hide_suite(); TB_show(SocialEngine.Language.Translate(784), \''+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'user_messages_new.php?to_user='+ escape(userInfos['username']) +'&to_id='+ userInfos['username'] +'&TB_iframe=true&height=450&width=450\', \'\', \'./images/trans.gif\');">';
              strHtml += '<img src="images/icons/newmessage16.gif" align="absmiddle" border="0" />&nbsp;';
              strHtml += SocialEngine.Language.Translate(839) +'</a>';
              cptLiensCtxels ++;
             }
             // Lien "ADD TO MY FRIENDS"
             if (userInfos['friend_enabled'] == "1")
             {
              if (cptLiensCtxels == 1 || cptLiensCtxels == 2)
                strHtml += '&nbsp;&nbsp;&nbsp;';
              else if (cptLiensCtxels == 3)
                { strHtml += '<br />'; cptLiensCtxels = 0; }
              strHtml += '<a href="javascript:;" onclick="SocialEngine.Profile.infoBulle_hide_suite(); TB_show(SocialEngine.Language.Translate(876), \''+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'user_friends_manage.php?user='+ escape(userInfos['username']) +'&TB_iframe=true&height=350&width=450\', \'\', \'./images/trans.gif\');">';
              strHtml += '<img src="images/icons/action_addfriend.gif" align="absmiddle" border="0" />&nbsp;';
              strHtml += SocialEngine.Language.Translate(838) +'</a>';
              cptLiensCtxels ++;
             }

            // Jean 17/11/2009 : Pour les CM, lien "Inviter sur ce tournage" dans le contexte d'un event
            var can_invite_this_event = userInfos['can_invite'] == "1" && parent.objTournage && parent.objTournage.members.indexOf('#'+ userInfos['user_id'] +'#') == -1
            if (can_invite_this_event)
             {
              if (cptLiensCtxels == 1 || cptLiensCtxels == 2)
                strHtml += '&nbsp;&nbsp;&nbsp;';
              else if (cptLiensCtxels == 3)
                { strHtml += '<br />'; cptLiensCtxels = 0; }
              strHtml += '<a href="javascript:;" onclick="parent.SocialEngine.Event.oneMemberInviteSend('+ userInfos['user_id'] +');">';
              strHtml += '<img src="images/icons/message_outbox16.gif" align="absmiddle" border="0" />&nbsp;';
              strHtml += SocialEngine.Language.Translate(3510054) +'</a>';
              cptLiensCtxels ++;
             }

            // Jean 18/11/2009 : Pour les CM et les contributeurs membres, lien "Inviter à un tournage" en dehors du contexte d'un event
            if (userInfos['can_invite'] == "1")
             {
              if (cptLiensCtxels == 1 || cptLiensCtxels == 2)
               strHtml += '&nbsp;&nbsp;&nbsp;';
              else if (cptLiensCtxels == 3)
               { strHtml += '<br />'; cptLiensCtxels = 0; }
              strHtml += '<a href="javascript:;" onclick="parent.SocialEngine.Profile.inviteToOneEvent_list('+ userInfos['user_id'] +'); //SocialEngine.Profile.infoBulle_hide_suite();">';
              strHtml += '<img src="images/icons/message_outbox16.gif" align="absmiddle" border="0" />&nbsp;';
              // L'inviter à un (autre) tournage
              strHtml += SocialEngine.Language.Translate(parent.objTournage ? 3510134 : 3510056) +'</a>';
              cptLiensCtxels ++;
             }
            } // fin "si pas dans super admin"


          // Jean 07/12/2009 : pour lancer l'édition d'un message de bienvenue
          if (userInfos['i_am_com_manager'])
           {
            if (cptLiensCtxels == 1 || cptLiensCtxels == 2)
              strHtml += '&nbsp;&nbsp;&nbsp;';
            else if (cptLiensCtxels == 3)
              { strHtml += '<br />'; cptLiensCtxels = 0; }

            strHtml += '<a class="com_manager" href="javascript:;" onclick="parent.SocialEngine.Profile.envoyerMessageBienvenue('+ userInfos['user_id'] +'); //SocialEngine.Profile.infoBulle_hide_suite();">';
            strHtml += '<img src="images/icons/chat_chat16.gif" align="absmiddle" border="0" />&nbsp;';

            // Jean 30/01/2010 : "Message de bienvenue envoyé le XXXXXX"
            if (userInfos['user_welcome_date'])
              strHtml += '<font style="font-size: 8pt;" class="com_manager">'+ SocialEngine.Language.TranslateFormatted(3510170,[userInfos['user_welcome_date']]) +'</font>';
            else
              strHtml += SocialEngine.Language.Translate(3510099);

            strHtml += '</a>';
            cptLiensCtxels ++;
           }

          // Jean 07/12/2009 : pour "Éditer" (pour aller dans l'édition en mode "super admin" de l'utilisateur)
          if (userInfos['i_am_the_boss'])
           {
            if (cptLiensCtxels == 1 || cptLiensCtxels == 2)
              strHtml += '&nbsp;&nbsp;&nbsp;';
            else if (cptLiensCtxels == 3)
              { strHtml += '<br />'; cptLiensCtxels = 0; }
            strHtml += '<a class="com_manager" href="'+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'admin/admin_viewusers_edit.php?user_id='+ userInfos['user_id'] +'" target="_blank">';
            strHtml += '<img src="images/icons/admin_users16.gif" border="0" align="bottom" /> ';
            strHtml += SocialEngine.Language.Translate(187) +'</a>';
            cptLiensCtxels ++;
           }

           strHtml += '</div>';
           strHtml += '</div>';
           strHtml += '</td></tr>';
           strHtml += '</table></td></tr></table>';
           strHtml += '</div>';

           $('infobulle_user').innerHTML = strHtml;
           $('infobulle_user').style.width = SocialEngine.Profile.largeurInfoBulle +'px';
           if ($('infobulle_user').offsetHeight)
             SocialEngine.Profile.hauteurInfoBulle = $('infobulle_user').offsetHeight;
           SocialEngine.Profile.positionneInfoBulle(x, y);

           // Scroll auto sur zone des chaînes
           

           // On retient pour la prochaine fois...
           SocialEngine.Profile.lastInfoBulleContent = strHtml;
           SocialEngine.Profile.lastUserName = userInfos['username'];
           SocialEngine.Profile.lastUserId = userInfos['user_id'];
         }
      }
    });

    request.send();
  },

  // Jean 22/07/2010 : infobulle de thématique
  infoBulleGroupCat_show: function(groupcat_id, timeout, ev)
   {
    var x, y;
    if (ev.x!=null && ev.y!=null) { x = ev.x; y = ev.y; }
    if (ev.clientX!=null && ev.clientY!=null) { x = ev.clientX; y = ev.clientY; }

    clearTimeout(this.ibTimeout);
    clearTimeout(this.ibTimeoutH);
    this.ibTimeout = setTimeout("SocialEngine.Profile.infoBulleGroupCat_show_suite("+ (groupcat_id ? "'"+ groupcat_id +"'" : "null") +","+ x +","+ y +");", timeout != null ? timeout : 200);
   },

  infoBulleGroupCat_show_suite: function(groupcat_id, x, y)
   {
    // Image d'attente...
    $('infobulle_user').style.width = '200px';
    $('infobulle_user').innerHTML = "<div onmouseover='SocialEngine.Profile.isOnMouseOver = true;'"
                                       +" onmouseout='SocialEngine.Profile.isOnMouseOver = false; SocialEngine.Profile.infoBulle_hide();' "
                                       +" class='infobulle_wait_content'>"
                                       +"<img src='/"+ SocialEngine.Profile.options.subdir +"images/icons/loading2.gif' alt='Quelques instants...' width='32' height='32' border='0' /></div>";
    this.positionneInfoBulle(x, y);
    this.rendVisibleInfoBulle(80);

    // Si on vient tout juste de récupérer l'info demandée
    if (groupcat_id != null && this.lastGroupCatId == groupcat_id)
     {
      $('infobulle_user').innerHTML = this.lastInfoBulleGroupCatContent;
      $('infobulle_user').style.width = this.largeurInfoBulle +'px';
      this.positionneInfoBulle(x, y);
      return;
     }

    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'get_groupcat_infos',
        'groupcat_id' : groupcat_id,
        'from_admin' : SocialEngine.Profile.options.fromAdmin ? "1" : "0"
      },
      'onComplete':function(responseObject)
      {
        if( $type(responseObject)!="object" || !responseObject.result || responseObject.result=="failure" )
         {
          if (responseObject && responseObject.is_debug) alert(responseObject.error);
         }
        else
         {
           var groupCatInfos = responseObject.groupcat_infos;
           var groupCatChannels = responseObject.groupcat_channels;

           strHtml = "<div onmouseover='SocialEngine.Profile.isOnMouseOver = true;' onmouseout='SocialEngine.Profile.isOnMouseOver = false; SocialEngine.Profile.infoBulle_hide();' "
                        +" class='infobulle_content infobulle_thema_content'"
                        +" style='"+ (isIE ? ' margin-left: 3px;' : '') +"'>";
           if (!groupCatInfos)
            {
             $('infobulle_user').innerHTML = strHtml +'<center><b><big>?</big></b></center></div>';
             $('infobulle_user').style.width = '100px';
             SocialEngine.Profile.positionneInfoBulle(x, y);
             return;
            }

           strHtml += '<table cellpadding="3" cellspacing="0" width="100%" border="0">';
           strHtml += '<tr><td colspan="2" valign="top">';

           // Si vignette thématique
           if (groupCatInfos['groupcat_vignette'])
             strHtml += '<img style="float: left; margin-right: 4px;" border="0" src="'+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'images/vignettes/groupcats/mini_'+ groupCatInfos['groupcat_vignette'] +'" />';

           // Titre de la thématique
           strHtml += '<b><a href="themes/'+ groupCatInfos['groupcat_id'] +'/0/'+ to_url(groupCatInfos['groupcat_title']) +'">'+ groupCatInfos['groupcat_title'] +'</a></b>';

           // Si texte de description
           if (groupCatInfos['groupcat_desc'])
             strHtml += '<div>'+ groupCatInfos['groupcat_desc'] +'</div>';

           strHtml += '</td></tr>';

           // Liste des chaînes rangées dans cette thématique
           if (groupCatChannels.length > 0)
            {
             // "Chaînes rangées dans cette thématique :"
             strHtml += '<tr><td colspan="2" class="infobulle_channel_list_title">';
             strHtml += '<div>'+ SocialEngine.Language.Translate(3510738) +'</div>';
             strHtml += '</td></tr>';

             strHtml += '<tr><td colspan="2"><div id="DIV_infobulle_channel_list">';

             strHtml += '<table cellpadding="3" cellspacing="0" width="100%" border="0" class="infobulle_channel_list">';
             for (var i=0; i<groupCatChannels.length; i++)
              {
               // "Cliquez ici pour découvrir les autres chaînes de la thématique "%1$s""
               if (i >= 5)
                {
                 strHtml += '<tr>';
                 strHtml += '<td valign="top" colspan="2" style="border-bottom: 0px; font-style: italic; font-weight: bold; padding-top: 5px;">';
                 strHtml +=  '<a href="themes/'+ groupCatInfos['groupcat_id'] +'/0/'+ to_url(groupCatInfos['groupcat_title']) +'">'+ SocialEngine.Language.TranslateFormatted(3510741, [groupCatInfos['groupcat_title']]) +'</a>';
                 strHtml += '</td>';
                 strHtml += '</tr>';
                 break;
                }
               var channel = groupCatChannels[i];
               strHtml += '<tr class="infobulle_channel_item">';
               strHtml += '<td valign="top" colspan="2">';
               strHtml += '<a href="'+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'channel/'+ channel['group_id'] +'/'+ to_url(channel['group_title']) +'">';
               if (channel['group_photo'] && channel['group_photo'] != '')
                 strHtml +=  '<img border="0" src="'+ (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'/'+ channel['group_photo'] +'" style="width: 60px; height: 60px; margin-right: 10px;" align="left" />';
               strHtml +=  '<b>'+ channel['group_title'] +'</b></a>';
               strHtml +=  '<br />'+ channel['group_desc'];
               strHtml += '</td>';
               strHtml += '</tr>';
              }
             strHtml += '</table></div>';
            }

           strHtml += '</td></tr>';

           strHtml += '</table>';
           strHtml += '</div>';

           $('infobulle_user').innerHTML = strHtml;
           $('infobulle_user').style.width = SocialEngine.Profile.largeurInfoBulle +'px';
           if ($('infobulle_user').offsetHeight)
             SocialEngine.Profile.hauteurInfoBulle = $('infobulle_user').offsetHeight;
/*
           // Scroll auto pour la liste
           if ($('DIV_infobulle_channel_list') && $('DIV_infobulle_channel_list').offsetHeight > 300)
            {
             $('DIV_infobulle_channel_list').style.height = '300px';
             $('DIV_infobulle_channel_list').style.overflow = 'auto';
            }
*/
           SocialEngine.Profile.positionneInfoBulle(x, y);

           // On retient pour la prochaine fois...
           SocialEngine.Profile.lastInfoBulleGroupCatContent = strHtml;
           SocialEngine.Profile.lastGroupCatId = groupCatInfos['groupcat_id'];
         }
      }
    });

    request.send();
  },

  positionneInfoBulle : function(x, y)
   {
       var hauteurDoc = typeof( window.innerHeight ) == 'number' ? window.innerHeight : document.documentElement.clientHeight;
       if (hauteurDoc == 0) hauteurDoc = document.documentElement.offsetHeight;
       var largeurDoc = typeof( window.innerWidth ) == 'number' ? window.innerWidth : document.documentElement.clientWidth;
       if (largeurDoc == 0) largeurDoc = document.documentElement.offsetWidth;

       var scrollTop = isIE || isFirefox ? document.documentElement.scrollTop : document.body.scrollTop;
       if (scrollTop == 0) scrollTop = document.body.scrollTop;
       var scrollLeft = isIE || isFirefox ? document.documentElement.scrollLeft : document.body.scrollLeft;
       var depasseAdroite = (x + SocialEngine.Profile.largeurInfoBulle) > largeurDoc;
       var depasseAgauche = (x - SocialEngine.Profile.largeurInfoBulle) < 0;
       var depasseEnBas = (y + SocialEngine.Profile.hauteurInfoBulle) > hauteurDoc;
       var depasseEnHaut = (y - SocialEngine.Profile.hauteurInfoBulle) < 0;
       var diffWidthAvecAttente = SocialEngine.Profile.largeurInfoBulle - $('infobulle_user').offsetWidth;
       var diffHeightAvecAttente = SocialEngine.Profile.hauteurInfoBulle - $('infobulle_user').offsetHeight;

       if (!depasseAdroite)
         $('infobulle_user').style.left = (x + scrollLeft + 5) +'px';
       else if (!depasseAgauche)
         $('infobulle_user').style.left = (x + scrollLeft + diffWidthAvecAttente - SocialEngine.Profile.largeurInfoBulle - 35) +'px';
       else
         $('infobulle_user').style.left = (scrollLeft + diffWidthAvecAttente + 5) +'px';

//alert(y +"+"+ SocialEngine.Profile.hauteurInfoBulle +">"+ hauteurDoc)

       if (!depasseEnBas)
         $('infobulle_user').style.top = (y + scrollTop + 10) +'px';
       else if (!depasseEnHaut)
         $('infobulle_user').style.top = (y + scrollTop + diffHeightAvecAttente - SocialEngine.Profile.hauteurInfoBulle - 10) +'px';
       else
         $('infobulle_user').style.top = (scrollTop + diffHeightAvecAttente + 5) +'px';
    },

  rendVisibleInfoBulle: function(opacityLevel)
   {
    $('infobulle_user').style.visibility = 'inherit';
    $('infobulle_user').style.display = 'inline';
    $('infobulle_user').setStyle('opacity', opacityLevel ? opacityLevel : 0);
    $('infobulle_user').fade('in');
/*
*/
   },


  currentInvitedID: 0,

  // Jean 18/11/2009 : Pour afficher une liste de tournages auxquels inviter telle personne
  inviteToOneEvent_list: function(user_id)
   {
    SocialEngine.Profile.infoBulle_hide_suite();
    this.currentInvitedID = user_id;

    selectedEventIdForInvite = null;
    selectedUserIdForInvite = user_id;

    if (htmlMesTournages)
     {
      //$("zone_invite_liste_tournages").innerHTML = htmlMesTournages;
     }
    else
     {
      $("imgLoadingMyTournages").style.display = "inline";

      // Ajax
      var bind = this;
      var request = new Request.JSON({
        'method' : 'post',
        'url' : this.options.ajaxURL,
        'data' : {
          'task' : 'get_my_tournages',
          'user_id' : user_id
        },
        'onComplete':function(responseObject)
        {
          if( $type(responseObject)!="object" || !responseObject.result || responseObject.result=="failure" )
           {
            if (responseObject && responseObject.is_debug) alert(responseObject.error);
           }
          else
           {
            var myTournages = responseObject.event_list;
            //var strHtml = '<script>var Tips1 = new Tips($$(\'.Tips1\'));</script>';
            //var Tips1 = new Tips($$('.Tips1'));

            var strHtml = '';

            for (var i=0; i<myTournages.length; i++)
             {
              var event = myTournages[i]['event'];
              strHtml += '<input onclick="selectedEventIdForInvite = '+ event['event_info']['event_id'] +';"'
                              +' type="radio"'
                              +' name="event_id"'
                              +' id="'+ event['event_info']['event_id'] +'"'
                              +' value="'+ event['event_info']['event_id'] +'" />'
                       + '<label for="'+ event['event_info']['event_id'] +'"'
                              +' class="Tips1"'
                              +' title="N°'+ event['event_info']['event_id'] +'\n..............................\n'+ event['event_info']['event_summary'].replace(/\"/g,'&#34;')
                          +'"> '
                       + event['event_info']['event_title'].replace(/\n/g,'<br>') +'</label>'
                       + '<br />'
              }

            if (myTournages.length == 0)
              $("zone_invite_liste_tournages").innerHTML = '<i>('+ SocialEngine.Language.Translate(3000654) +')</i>';
            else
              $("zone_invite_liste_tournages").innerHTML = strHtml;

            htmlMesTournages = strHtml;
  /*
             $('inviteOneUser_buttons_memberInviteSend').style.display = 'inline';
             $('inviteOneUser_loading_memberInviteSend').style.display = 'none';
  */
           }
          $("imgLoadingMyTournages").style.display = "none";

          TB_init();
          TB_show(SocialEngine.Language.Translate(3510056), '#TB_inline?height=520&width=700&inlineId=displayshowlistforinvite', '', '../images/trans.gif');
        }
      });

      request.send();
     }

    TB_show(SocialEngine.Language.Translate(3510056), '#TB_inline?height=520&width=700&inlineId=displayshowlistforinvite', '', '../images/trans.gif');
   },


  // Jean 13/12/2009 : composition d'un message de bienvenue
  envoyerMessageBienvenue: function(user_id)
   {
    this.envoyerMessageType('manual_welcoming', user_id);
   },

  // Jean 24/02/2010 - composition d'un message type
  envoyerMessageType: function(systememail_name, user_id)
   {
    //$("imgLoadingMyTournages").style.display = "inline";

    // Ajax
    var bind = this;
    var request = new Request.JSON({
      'method' : 'post',
      'url' : this.options.ajaxURL,
      'data' : {
        'task' : 'message_type',
        'systememail_name' : systememail_name,
        'user_id' : user_id
      },
      'onComplete':function(responseObject)
      {
        if( $type(responseObject)!="object" || !responseObject.result || responseObject.result=="failure" )
         {
          if (responseObject && responseObject.is_debug) alert(responseObject.error);
         }
        else
         {
          // On ouvre une pop-up de message
          TB_show(SocialEngine.Language.Translate(3000967), (SocialEngine.Profile.options.fromAdmin ? '../' : '') +'user_messages_new.php?to_user='+ escape(responseObject.username) +'&to_id='+ escape(responseObject.username) +'&TB_iframe=true&height=620&width=750', '', './images/trans.gif');

          // On attend son chargement avant de de pouvoir interagir avec elle
          setTimeout("SocialEngine.Profile.envoyerMessageType_suite()", 200);

          SocialEngine.Profile.infoBulle_hide_suite();

          SocialEngine.Profile.systememailName = systememail_name;
          SocialEngine.Profile.corpsMessage = responseObject.corps_message;
          SocialEngine.Profile.sujetMessage = responseObject.sujet_message;
         }
      }
    });

    request.send();
   },

   envoyerMessageType_suite: function()
    {
     if (!$('TB_iframeContent') || !$('TB_iframeContent').contentWindow || !$('TB_iframeContent').contentWindow.document || !$('TB_iframeContent').contentWindow.document.getElementById('subject'))
      {
       setTimeout("SocialEngine.Profile.envoyerMessageType_suite()", 100);
       return;
      }

      // Sujet du message
      $('TB_iframeContent').contentWindow.document.getElementById('subject').value = SocialEngine.Profile.sujetMessage;
      // Corps du message
      $('TB_iframeContent').contentWindow.document.getElementById('message').value = SocialEngine.Profile.corpsMessage;

      // Jean 25/05/2010 - Pour renseigner la table se_users une fois le message parti
      if ( SocialEngine.Profile.systememailName == 'manual_incitation')
        $('TB_iframeContent').contentWindow.document.getElementById('is_incitation_message').value = '1';
      else if (SocialEngine.Profile.systememailName == 'manual_complete_profile')
        $('TB_iframeContent').contentWindow.document.getElementById('is_complete_profile_message').value = '1';
      else if (SocialEngine.Profile.systememailName == 'manual_welcoming')
        $('TB_iframeContent').contentWindow.document.getElementById('is_welcome_message').value = '1';

      $('TB_iframeContent').contentWindow.document.getElementById('message').style.width = '680px';
      $('TB_iframeContent').contentWindow.document.getElementById('message').style.height = '350px';
      // Focus auto
      $('TB_iframeContent').contentWindow.addEvent('load', function () { setTimeout("$('TB_iframeContent').contentWindow.document.getElementById('message').focus();", 400); });

      //$("imgLoadingMyTournages").style.display = "none";
    }

  });
