function UnicodeToUTF8(strInUni){
  if(null==strInUni)
    return null;
  var strUni=String(strInUni);
  var strUTF8=String();
  for(var i=0;i<strUni.length;i++){
    var wchr=strUni.charCodeAt(i);
    if(wchr<0x80){
      strUTF8+=strUni.charAt(i);
      }
    else if(wchr<0x800){
      var chr1=wchr&0xff;
      var chr2=(wchr>>8)&0xff;
      strUTF8+=String.fromCharCode(0xC0|(chr2<<2)|((chr1>>6)&0x3));
      strUTF8+=String.fromCharCode(0x80|(chr1&0x3F));
      }
    else{
      var chr1=wchr&0xff;
      var chr2=(wchr>>8)&0xff;
      strUTF8+=String.fromCharCode(0xE0|(chr2>>4));
      strUTF8+=String.fromCharCode(0x80|((chr2<<2)&0x3C)|((chr1>>6)&0x3));
      strUTF8+=String.fromCharCode(0x80|(chr1&0x3F));
      }
    }
  return strUTF8;
  }
function URLDecode(Str){
  if(Str==null||Str=="")
    return "";
  var newStr="";
  function toCase(sStr){
    return sStr.toString(16).toUpperCase();
    }
  for(var i=0,ichar,len=Str.length;i<len;){
    if(Str.charAt(i)=="%"){
      ichar=Str.charAt(i+1);
      if(ichar.toLowerCase()=="e"){
        newStr+=String.fromCharCode((parseInt("0x"+Str.substr(i+1,2))-0xE0)*0x1000+(parseInt("0x"+Str.substr(i+4,2))-0x80)*0x40+parseInt("0x"+Str.substr(i+7,2))-0x80);
        i+=9;
        }
      else if(ichar.toLowerCase()=="c"||ichar.toLowerCase()=="d"){
        newStr+=String.fromCharCode((parseInt("0x"+Str.substr(i+1,2))-0xC0)*0x40+parseInt("0x"+Str.substr(i+4,2))-0x80);
        i+=6;
        }
      else{
        newStr+=String.fromCharCode(parseInt("0x"+Str.substr(i+1,2)));
        i+=3;
        }
      }
    else{
      newStr+=Str.charAt(i).replace(/\+/," ");
      i++;
      }
    }
  return newStr;
  }
function checkLogin(){
	var strCookie=document.cookie;
	//alert(strCookie);
	var arrCookie=strCookie.split("; ");
	for(var i=0;i<arrCookie.length;i++){
	    var arr=arrCookie[i].split("=");
	    if("sso.ssoId" == arr[0]){
	    	return true;
	    }
	}
	return false;
}

/*获得cookie*/


function getCookie(name) { 
    var start = document.cookie.indexOf( name + "=" ); 
    var len = start + name.length + 1; 
    if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) { 
        return null; 
    } 
    if ( start == -1 ) return null; 
    var end = document.cookie.indexOf( ';', len ); 
    if ( end == -1 ) end = document.cookie.length; 
    return document.cookie.substring( len, end ); 
} 

//发送纸条
function sendMessage(receiverId){
	if (checkLogin()){
	window.open("/circle/main/reader/userManager.do?method=userManageScrip&receiverId="+receiverId);
	} else{
		login();
	}
}
//加为好友
function addFriend(toId){
	if (checkLogin()){
		$.openWindow({"onclick":"closeWindow();","loadUrl":"/circle/main/reader/friend.do?method=addFriend&id="+toId});
	} else{
		login();
	}
}
//加入圈子
function joinQmain(toId){
	if (checkLogin()){
	 	$.openWindow({"onclick":"closeWindow();","loadUrl":"/circle/main/reader/joinQmain.do?method=joinQmain&qid="+toId});
	} else{
		login();
	}
}
//查看精华
function primetalkbar(id){
window.location.href="/circle/comment/bookcommentQ.do?method=showBookComment&type=prime&id="+id;
}
//修改文章
function editArticle(userId,articleId){
window.location.href="/circle/comment/bookcommentQ.do?method=showBookComment&type=prime&id="+id;
}
//删除文章
function delArticle(userId,articleId){
var b=false;
$.openWindow({"onclick":"closeWindow();","title":"提示信息","content":"确认删除吗？","dbutton":"<div class=\"btBox\"><button onclick=\"closeWindow();dodelArticle("+userId+","+articleId+",true);\">确定</button> <button onclick=\"closeWindow();\">取消</button></div>"});    
 }
 function dodelArticle(userId,articleId,flag){
 if (flag){
 $.ajax({
type: "POST",
dataType:"json",
url:"/circle/main/reader/article.do",
data:"method=deleteUserActicle&id="+userId+"&userArticleId="+articleId,
success: function(msg){
 if(msg==0){
   window.location.reload();
 }else{
   alert("您的权限不够！");
 }
}
});  
 }else{
   return ;
}
}
