﻿(function(){
	intNav=intWebNav;
	switchNav=switchWebNav;
	function intWebNav(obj,para){
		if(para.isTop){
			$(obj)&&($(obj).style.top="0px");
		}else{
			$(obj)&&($(obj).style.bottom="0px");
		}
		if(!para.isShow){
			switchWebNav($(obj).getElementsByTagName("a")[0]);
		}
		$(obj).style.display="block";
	};
	function switchWebNav(obj){
			obj.className=obj.className=="closestate"?"openstate":"closestate";
			var p=$(obj).parentNode;
			var o=p.getElementsByTagName("div")[1];//$("webNavContent")
			var o1=p.getElementsByTagName("div")[2];//$("webNavContent")
			if(o){
				if(o.style.visibility=="hidden"){
					o.style.visibility="visible";
					o1.style.visibility="visible";
					p.className="webNavOpen"
				}else{
					o.style.visibility="hidden";
					o1.style.visibility="hidden";
					p.className="webNavClose"
				}
			}
		}
})()

//增加用户的收藏
function AddFav(sortid,title,url,id){
	var option={
		parameters:"action=addfav&sortid="+sortid+"&id="+escape(id)+"&title="+escape(title)+"&url="+escape(url),
		method:'post',
		onSuccess:function(req){
			if(req.responseText=="ok"){alert("收藏成功...");}else if(req.responseText=="saved"){alert("已经收藏了...")}else{if(confirm("收藏失败，因为你没有登录网站所以无法收藏...\n现在就登录网站?")){window.location='/Login.aspx'};}
		},
		onFailure:function(transport){
			alert("收藏失败，请联系管理员或请稍候再试...")
		}
	}
	var request=new Ajax.Request("/AjaxHandler.aspx",option);
	request=null
}
//加为好友
function AddFriend(friendId,NoticeMsg,returnUrl){	
	if(friendId==""||friendId==0){if(confirm("网络错误。请刷新页面重试")){window.location.reload(true);}else{return false;}}	
	var option={
		parameters:"action=addfriend&msg="+escape(NoticeMsg)+"&fid="+parseInt(friendId),
		method:'post',
		onSuccess:function(req){
			var res=eval("("+req.responseText+")");
			if(res.state=="error"||res.state=="ok"){
				 alert(res.msg);
			}else if(res.state=="nologin") {
				if(confirm(res.msg)){
					returnUrl=returnUrl==""?"":"?ReturnUrl="+returnUrl;
					window.top.location="/Login.aspx"+returnUrl;
				}
			}
		},
		onFailure:function(transport){
			alert("添加好友失败，请联系管理员或请稍候再试...")
		}
	}
	var request=new Ajax.Request("/AjaxHandler.aspx",option);
	request=null
}
//加入圈子
function JoinGroup(groupId,returnUrl){	
	if(groupId==""||groupId==0){if(confirm("网络错误。请刷新页面重试")){window.location.reload(true);}else{return false;}}	
	var option={
		parameters:"action=joingroup&gid="+parseInt(groupId),
		method:'post',
		onSuccess:function(req){
			var res=eval("("+req.responseText+")");
			if(res.state=="error"||res.state=="ok"){
				 alert(res.msg);
			}else if(res.state=="nologin") {
				if(confirm(res.msg)){
					returnUrl=returnUrl==""?"":"?ReturnUrl="+returnUrl;
					if(returnUrl!=""){
						window.top.location="/Login.aspx"+returnUrl;
					}else{
						window.top.location.reload();
					}
				}
			}
		},
		onFailure:function(transport){
			alert("申请加入圈子失败，请联系管理员或请稍候再试...")
		}
	}
	var request=new Ajax.Request("/AjaxHandler.aspx",option);
	request=null
}
//编辑好友列表备注
var editRemarks={
	editing:false,
	editThis:function(obj,friendId,maxlength){
		var _this=this;
		if(!_this.editing){
			var o=document.getElementById(obj)
			var innerhtml=o.innerHTML.replace("\r\n"," ");
			var input=document.createElement("input");
			input.id="ipt_"+obj;
			input.type="text";
			input.value=maxlength?innerhtml.substring(0,maxlength):innerhtml;
			input.onblur=function(){
					if(_this.editing){
						var input=document.getElementById("ipt_"+obj);
						var ninnerhtml=input.value;
						if(maxlength){
							ninnerhtml=ninnerhtml.slice(0,(maxlength-1));
						}
						var option={
							parameters:"action=setremarks&fid="+parseInt(friendId)+"&v="+escape(ninnerhtml),
							method:'post',
							onSuccess:function(req){
								var res=eval("("+req.responseText+")");
								if(res.state=="ok"){
									o.innerHTML=ninnerhtml;
									_this.editing=false;
								}else{
									alert(res.msg);
									o.innerHTML=innerhtml
									_this.editing=false;
								}
							},
							onFailure:function(transport){
								alert("编辑失败，请联系管理员或稍后再试...")
								o.innerHTML=innerhtml
								_this.editing=false;
							}
						}
						var request=new Ajax.Request("/AjaxHandler.aspx",option);
						request=null
					}
			}
			input.onkeypress=function(){
				if(maxlength){
					input.value=input.value.slice(0,(maxlength-1));
				}
			}
			input.onfocus=function(){
				if(input.value=="点这里编辑备注"){
					input.value="";
				}
			}
			o.innerHTML="";
			o.appendChild(input);
			input.focus();
			_this.editing=true;
		}
	}
}
