﻿
function AddFriend(id,username)
{
  if(getCookie('dnt=userid')== null)
  {
    alert('您还没有登陆,无法加对方为好友!');
    return;
  }
   var exp = parent.window.hs.getExpander("addfd");	//框框对象
   var area = document.getElementById("area"); //DIV
   var Remark =document.getElementById("Remark").value;//输入内容，可能出现字符串溢出
   Remark = escape(Remark);
  $.ajax({
         url: "ajaxfriend.ashx?action=request&fid="+id+"&remark="+Remark ,//被请求的用户ID
         error: function(xhr) {
             //$('.containerLeftIn').html(response);
             alert('服务器错误');
         },
         success: function(response) {
             if (response == 'err') {
                 window.location = "login.aspx"; 
             }
             else if(response == '200')
             {
                parent.window.document.getElementById('msg').style.display="block";
                parent.window.document.getElementById('msg').innerHTML="等待"+username+"接受好友邀请";
                parent.window.document.getElementById('addfd').style.display = "none";
                area.innerHTML = "<br/><br/><em>Closing soon...</em>";
                //exp.close();
                parent.window.hs.close();
             }
             else if(response == '100')
             {
                alert('可能系统忙，添加失败!');
                parent.window.hs.close();
                //exp.close();
             }
             else if(response == "300")
             {
                alert('您已经请求过要与'+username+'成为朋友了,请耐心等待对方的确认.');
                parent.window.hs.close();
                //exp.close();
             }
             else if(response == '400')
             {
                alert(username+'已经请求过要与您成为朋友了,请去提醒页面确认.');
                parent.window.hs.close();
                //exp.close();
             }
             else if(response == '500'){
                alert(username+'已经与您是朋友了.');
                parent.window.hs.close();
                //exp.close();
             }

         }
     });
	
}


   //添加，删除朋友的AJAX
function DeleteFriend(id,username)
{
  if(confirm('您确定要从朋友列表中删除'+username+'吗?')==false)
  {
    return;
  }
  
  $.ajax({
         url: "ajaxfriend.ashx?action=delete&fid="+id ,//被请求的用户ID
         error: function(xhr) {
             //$('.containerLeftIn').html(response);
             alert('服务器错误');
         },
         success: function(response) {
             if (response == 'err') {
                 window.location = "login.aspx"; 
             }
             else if(response == '200')
             {
                window.location.reload(true);
             }
             else if(response == '100')
             {
                alert('可能系统忙，删除失败!');
             }
         }
     });
  
 }


function isLogin(arg)
{
  var str;
  if(arg=='1')
  {
    str='您还没有登陆,无法给对方发送消息!';
  }
  else if(arg=='2')
  {
    str='您还没有登陆,无法加对方为好友!';
  }
  if(getCookie('dnt=userid')== null)
  {
    //alert(str);
    GB_showCenter('用户登录','/signin.aspx',235,360);
    return false;
  }
  return true;
}


function getCookie(cookieName) {
  var cookieString = document.cookie;
  var start = cookieString.indexOf(cookieName + '=');
  // 加上等号的原因是避免在某些 Cookie 的值里有
  // 与 cookieName 一样的字符串。
  if (start == -1) // 找不到
  return null;
  start += cookieName.length + 1;
  var end = cookieString.indexOf('&', start);
  if (end == -1) return unescape(cookieString.substring(start));
  return unescape(cookieString.substring(start, end));
}



function RequestAddFriend(args)
{
  if(isLogin('2')){
    return hs.htmlExpand( args, {
    	objectType: 'iframe', outlineType: 'rounded-white', wrapperClassName: 'highslide-wrapper drag-header',
        outlineWhileAnimating: true, preserveContent: false, width: 250 } );
  }
  else 
  {
    return false;
  }
}


/*
  显示全部文字
*/
function ShowAll()
{
  var hdbio = document.getElementById('hdbio').value;
 // alert(strReplace(hdbio));
  document.getElementById('bio').innerHTML = strReplace(hdbio);
  
  document.getElementById('a_show').innerHTML='（收起...）';
  document.getElementById('a_show').onclick = Function("ShowShort();");
  return false;
}
/*
  显示部分文字
*/
function ShowShort()
{ 
  
  var hdbio = document.getElementById('hdbio').value;
  if(hdbio == "")
  {
    return ;
  }
    if(hdbio.length>50)
    {
      //alert(strReplace(hdbio));
      document.getElementById('bio').innerHTML = strReplace(hdbio.substring(0,50)+'...');
    }
    else
    {
      //alert(strReplace(hdbio));
      document.getElementById('bio').innerHTML = strReplace(hdbio)+'...';
    }
    document.getElementById('a_show').innerHTML='（查看全部...）';
    document.getElementById('a_show').onclick = Function("ShowAll();"); 
    return false;
  
}

//替换字符的方法
function strReplace(str){
  var re = /</g;
  str = str.replace(re,'&lt;');
  re = />/g;
  str = str.replace(re,'&gt;');
  
  re = /\n/g;
  str = str.replace(re,'<br/>');
  
  return str;
}