﻿// JScript 文件
//显示对话框
position = function(x,y)
{
    this.x = x;
    this.y = y;
}
getPosition = function(oElement)
{
    var objParent = oElement
    var oPosition = new position(0,0);
    while (objParent.tagName != "BODY")
    {
        oPosition.x += objParent.offsetLeft;
        oPosition.y += objParent.offsetTop;
        objParent = objParent.offsetParent;
    }
    return oPosition;
} 
function HideAlertBox()
{
    var obj = document.getElementById('div_AlertBox');
    document.body.removeChild(obj);
}
function ShowDlg(width,height,title,content,onok)
{
    if(document.getElementById('div_AlertBox') != null)
        return;
    var pos = getPosition(document.body);
	objDiv = document.createElement("div");
	objDiv.id="div_AlertBox";
	objDiv.className="f_box";
	
	objDiv.style.width = width +"px";
	objDiv.style.height = height +"px";
    objDiv.style.position = "absolute";
    objDiv.style.left = (((window.screen.width/2)-(width/2))-15) + "px";
	objDiv.style.top = ((((window.screen.height/2)-(height))+document.documentElement.scrollTop)+20) + "px";
	var s ="   <div class=\"f_titles\">"+ title +"</div>";
    s +="   <div class=\"alertboxmain\">"+ content +"</div>";
 	s +="   <div class=\"alertboxbutn\"><input onclick=\""+ onok +"\" class=\"f-button\" type=\"button\" value=\" 确定 \"/>     <input type=\"button\" class=\"f-button\" onclick=\"HideAlertBox()\" value=\" 取消 \"/></div>";
	objDiv.innerHTML = s;
    document.body.appendChild(objDiv);
}
//创建的内容
function GetCreateContent(uid)
{
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=CreateContent&uid="+uid,
       cache:false,
       success: function(msg){
           var obj = document.getElementById('div_CreateContent');
           obj.innerHTML=msg;
            var str=document.getElementById('div_CreateContent').innerHTML;
            var indexstr=str.indexOf("还没有创建内容");
            if(indexstr>0)
            {
                document.getElementById('noCreate').style.display="";
            }
        }
    }); 
}
//参与过的内容
function GetOpContent(uid)
{
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=OpContent&uid="+uid,
       cache:false,
       success: function(msg){
            var obj = document.getElementById('div_OpContent');
            obj.innerHTML=msg;
        }
    }); 
}
//留言
function GetGbookTop(uid,pagaindex)
{
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=GbookTop&uid="+uid+"&Page="+pagaindex,
       cache:false,
       success: function(msg){
            var obj = document.getElementById('div_gbook');
            obj.innerHTML=msg;
        }
    }); 
}
//删除留言
function DelMsg(ID,uid)
{
    if(window.confirm("确定要删除留言吗？"))
    {
        jQuery.ajax({
           type: "GET",
           url: "/ajax/Space.aspx",
           data: "action=DelGbook&uid="+uid+"&gid="+ID,
           cache:false,
           success: function(msg){
	           if (msg=="succ")
               {
                  window.location.reload();
               }
               else
               {
                    alert("删除失败！");
               }
            }
        }); 
    }
}
function reply(object)
{
   document.getElementById(object).style.display= document.getElementById(object).style.display=="none"?"":"none";
}
function AddGbook(pid)
{
    document.getElementById('gbookparentid').value=pid;
    document.addgbook.repcontent_0.focus();
}
function sendreplybookhome(recid)
{       
    var floatdiv = document.getElementById("sendstate_0"); 
    floatdiv.style.display="";
    if(document.getElementById("repcontent_0").value=="")
    {
        floatdiv.innerHTML="<span class=\"reshow\">请填写留言内容!</span>";
        return false;
    }
    if(document.getElementById("repcontent_0").value.length>5000)
    {
        floatdiv.innerHTML="<span class=\"reshow\">留言最多字符为5000个字符!</span>";
        return false;
    }
    var Action = "action=EditGbook&uid="+recid+"&content="+escape(document.getElementById("repcontent_0").value)+"&pid="+document.getElementById("gbookparentid").value+"&issecret="+document.getElementById("hdissecret").value;
    
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: Action,
       cache:false,
       success: function(msg){
	       if (msg!="error")
	       {
                window.navigate(location)
                window.location.replace="/user_index-"+recid+".html#commentdiv_"+returnvalue;
	       }
	       else
	       {
	            floatdiv.innerHTML=msg;
	            return false;
	       }
        }
    });    
}
//好友动态
function GetFriendUserLog(uid)
{
    var obj = document.getElementById('div_FriendUserLog');
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=FriendUserLog&uid="+uid,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
            var friendstr=document.getElementById('div_FriendUserLog').innerHTML;
            var indexstr=friendstr.indexOf("还没有吸TA");
            if(indexstr>0)
            {
                document.getElementById('friendpic').style.display="";
            }
        }
    });
}
//参与者
function GetParticipation(uid)
{
    var obj = document.getElementById('div_Participation');
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=Participation&uid="+uid,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
        }
    });
}
//引用者
function GetQuote(uid)
{
    var obj = document.getElementById('div_Quote');
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=Quote&uid="+uid,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
        }
    });
}
//加好友
function AddFrd(uid,uname,upic)
{
    ShowDlg(464,280,'对'+ uname +'挺有兴趣的，把TA吸进你的小宇宙吧？','<img src="'+ upic +'" alt="'+ uname +'" /> 确认后TA成为你的小宇宙行星。','OnAddFrd('+ uid +')' );
}
function OnAddFrd(uid)
{
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=ApplyFrd&uid="+ uid,
       cache:false,
       success: function(msg){
            if (msg=="succ")
            {
              window.location.reload();
            }
        }
    });
	HideAlertBox();
}


//评论区
function GetCommentTop(oType,oID,num,uid)
{
    var obj = document.getElementById('div_gbook');
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=CommentTop&oType="+oType+"&oID="+oID+"&Page="+num+"&uid="+uid,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
        }
    });
}
function AddComment(pid,commentNo,nickname)
{
    document.getElementById('gbookparentid').value=pid;
    document.getElementById('divprompt').innerHTML="回复<span style='color:#f96c00;font-weight:bold;'>"+commentNo+"</span>楼　<span style='color:#f96c00;font-weight:bold;'>"+nickname+"</span>　的帖子";
    window.location.hash="#addcoment";
}



//引用
function Addquote(pid,commentNo,nickname)
{
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=CommentModel&oID="+pid,
       cache:false,
       success: function(msg){
            var ContentStr="<fieldset class=\"comment_quote\"><legend>引用 <span style='color:#f96c00;font-weight:bold;'>"+commentNo+"</span>楼　<span style='color:#f96c00;font-weight:bold;'>"+nickname+"</span>　的帖子：</legend>"+msg+"</fieldset>";
            var oEditor = FCKeditorAPI.GetInstance("txtContent") ; 
            oEditor.SetHTML(ContentStr) ; 
            window.location.hash="#addcoment";
        }
    });
}


//删除评论
function DelComment(ID,uid,isadmin)
{
    if(window.confirm("确定要删除评论吗？"))
    {
        jQuery.ajax({
           type: "GET",
           url: "/ajax/Space.aspx",
           data: "action=DelComment&cid="+ID+"&uid="+uid+"&isadmin="+isadmin,
           cache:false,
           success: function(msg){
	               if (msg=="succ")
                   {
                       window.location.reload();
                   }
                   else
                   {
                        alert("删除失败！");
                   }
                }
            });
      }
}
function sendsubject()
{       
    if(document.getElementById("txtadvise").value=="")
    {
        alert("请填写内容!");
        return false;
    }
    if(document.getElementById("txtadvise").value.length>200)
    {
        alert("最多字符为200个字符!")
        return false;
    }
    var url=window.location.href;
    
    var Action = "action=AddSubject&content="+escape(document.getElementById("txtadvise").value)+"&url="+url+"&os="+jQuery.client.os +"&browser="+jQuery.client.browser;
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: Action,
       cache:false,
       success: function(msg){
	       if (msg!="error")
	       {
	            window.open('/detail-47-1-3115.html');
	       }
	       else
	       {
	           return false;
	       }
        }
    });   
}

//获取评论准确平均值及评论喜欢值
//a:shy;at:2009-11-16
function GetCommentCount(oType,oID)
{
    var obj = document.getElementById('span_comment');
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=GetCommentCount&oType="+oType+"&oID="+oID,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
        }
    });
}


//谁在关注我 a:shy;at:2010-03-31
function GetAttention(uid,type,divid)
{
    var obj = document.getElementById(divid);
    jQuery.ajax({
       type: "GET",
       url: "/ajax/Space.aspx",
       data: "action=attention&uid="+uid+"&oType="+type,
       cache:false,
       success: function(msg){
            obj.innerHTML=msg;
        }
    });
}



(function() {
	
	var BrowserDetect = {
		init: function () {
			this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchString(this.dataOS) || "an unknown OS";
		},
		searchString: function (data) {
			for (var i=0;i<data.length;i++)	{
				var dataString = data[i].string;
				var dataProp = data[i].prop;
				this.versionSearchString = data[i].versionSearch || data[i].identity;
				if (dataString) {
					if (dataString.indexOf(data[i].subString) != -1)
						return data[i].identity;
				}
				else if (dataProp)
					return data[i].identity;
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		dataBrowser: [
			{
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome"
			},
			{ 	string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb"
			},
			{
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version"
			},
			{
				prop: window.opera,
				identity: "Opera"
			},
			{
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab"
			},
			{
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror"
			},
			{
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox"
			},
			{
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino"
			},
			{		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape"
			},
			{
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE"
			},
			{
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv"
			},
			{ 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [
			{
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			},
			{
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			},
			{
				string: navigator.userAgent,
				subString: "iPhone",
				identity: "iPhone/iPod"
		    },
			{
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	
	};
	
	BrowserDetect.init();
	
	window.$.client = { os : BrowserDetect.OS, browser : BrowserDetect.browser };
	
})();