/**
*** 気になるユーザ関連
**/
//ポップアップ
//PopupDiv.jsが必要
var MyFavoritesUsersPUP = function()  {
  var fInit_  = false;
  var id_;
  var err_;

  function check_Success( obj ) {
    var res = parseInt( obj.responseText );
    if( res==1 )  {
      $( 'add_favoritesusers' ).style.display     = '';
      $( 'add_favoritesusers_ng' ).style.display  = 'none';
    }
  }
  function check_Failure( obj ) {
  }

  //-----------------------------------------

  function baseInit( base, mosPos ) {
      base.style.display  = 'none'; //まず消す
      var html  = '<div align="right" style="margin-bottom: 2px;"><a href="javascript:PopupDiv.Close();"><img src="/shashin-bu/img/photo/close.gif" alt="閉じる" border="0"></a></div>'
        + '<table width="290">'
        + '  <tr>';
      if( err_==null )  {
        html  += '    <td width="50" align="center"><img src="/shashin-bu/syscontents/userimg/type/ts40/id/' + id_ + '" width="40" height="40" border="0"></td>'
               + '    <td width="240" align="left">この部員を「お気に入り部員」に追加しました。</td>';
      }
      else  {
        html  += '    <td align="center">' + err_ + '</td>';
      }
      html  += '  </tr></table>';
      base.innerHTML  = html;
      PopupDiv.SetBasePos( mosPos.x - 290, mosPos.y -  20 );
      return  true;
  }

  function add_Success( obj ) {
    err_  = null;
    var res = parseInt( obj.responseText );
    if( res!=0 )  {
      if( res<0 || res>4 )  res = 1;
      var mes = [ '', 'ただいま混みあっています。', 'ログインして下さい。', 'ユーザIDが不正です。', 'このユーザは既に追加されています。' ];
      err_  = mes[ res ];
    }
    else  {
      $( 'add_favoritesusers' ).style.display     = 'none';
      $( 'add_favoritesusers_ng' ).style.display  = '';
    }
    PopupDiv.Popup( baseInit );
  }
  function add_Failure( obj ) {
    err_  = 'ただいま混みあっています。';
    PopupDiv.Popup( baseInit );
  }

  return  {
    //画像IDを設定

    SetFavoritesUsersID: function( id )  {
      id_ = id;
      //追加できるか確認
      new Ajax.Request('/shashin-bu/Favoritesusers/check/id/' + id_, {
      	method: 'get',
          requestHeaders: [ 'If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT' ], //キャッシュ無効化

      	  onSuccess: check_Success,
          onFailure: check_Failure
      } );
    },

    //初期化

    Init: function( baseID ) {
      var parent  = $( baseID );
      var base    = document.createElement( 'div' );
      base.className      = 'myfavorite_pop';
      base.style.display  = 'none';
      base.style.position = 'absolute';
      parent.appendChild( base );
      //
      PopupDiv.Init( base );
      fInit_  = true;
    },
    //コレクション追加
    Add: function()  {
      if( fInit_ )  {
        new Ajax.Request('/shashin-bu/Favoritesusers/add/id/' + id_, {
        	method: 'get',
            requestHeaders: [ 'If-Modified-Since', 'Wed, 15 Nov 1995 00:00:00 GMT' ], //キャッシュ無効化

        	  onSuccess: add_Success,
            onFailure: add_Failure
        } );
      }
    }
  }
}();
