var load;
var activity={
	change:function(type)
	{
		var userid=$("#userid").val();
		if(type==1)
		{
			$("#showMyMsg").load("templet/showmymsg.php?type="+type+"&userid="+userid+"");
			//alert("showMyMsg.php?type="+type+"&userid="+userid+"");
		}
		else if(type==2)
		{
			//alert(type);
			$("#showMyMsg").load("templet/showmymsg.php?type="+type+"&userid="+userid+"");
		}
		else if(type==3)
		{
			//alert(type);
			$("#showMyMsg").load("templet/showmymsg.php?type="+type+"&userid="+userid+"");
			//alert("showMyMsg.php?type="+type+"&userid="+userid+"");
		}
	},
	changespot:function(spottype)
	{
		var userid=$("#userid").val();
		if(spottype==1)
		{
			$("#showMySpot").load("templet/showmyspot.php?userid="+userid+"&type="+spottype+"");
		}
		else if(spottype==2)
		{
			$("#showMySpot").load("templet/showmyspot.php?userid="+userid+"&type="+spottype+"");
		}
	},
	updateTags:function(src)
	{
		var uid=$("#uid").val();
		var uUid=$("#uUid").val();
		//var stype=$("#stype").val();
		var stype=1;
		var str="";
		if(uUid!=null && uUid==uid)
		str="activityissuespace.php?type="+stype+"";
		else str="activitylistspace.php?uUid="+uid+"";
		var array=new Array("更多活动","更多招贴","更多广播");
		var arraylink=new Array(str,"/space/poster.php?&type=person&uid="+uid+"","broadcast.php?userid="+uid+"");
		var arrayh=new Array("myactivityh","myclassh","mybordcasth");
		var msg=$("#msg");
		for(var i=0;i<arrayh.length;i++)
		{
			if(arrayh[i]==src.getAttribute("id"))
			{
				msg.html("<a href='"+arraylink[i]+"'>"+array[i]+"</a>");
				//document.getElementById(arrayh[i]).className="uleft h4";
				document.getElementById(arrayh[i]).className="uleft my_spot";
			}
			else
			{
				//(document.getElementById(arrayh[i])).className="uleft h4bg";
				(document.getElementById(arrayh[i])).className="uleft my_join";
			}
		}
	},
	updateSpotTags:function(src)
	{
		var spotarr=new Array("ownerspot","joinspot");
		var uid=$("#uid").val();
		var arraylink=new Array("spotspace.php?userid="+uid+"","spotspace.php?userid="+uid+"&type=1");
		var linkurl=$("#spotmsg");
		var array=new Array("更多据点","更多据点");
		for(var i=0;i<spotarr.length;i++)
		{
			if(spotarr[i]==src.getAttribute("id"))
			{
				linkurl.html("<a href='"+arraylink[i]+"'>"+array[i]+"</a>");
				//document.getElementById(spotarr[i]).className="uleft h4";
				document.getElementById(spotarr[i]).className="uleft my_spot";
			}
			else
			{
				//(document.getElementById(spotarr[i])).className="uleft h4bg";
				document.getElementById(spotarr[i]).className="uleft my_join";
			}
		}
	},
	gotoactivity:function(src)
	{
		activity.updateTags(src);
		clearTimeout(load);
		$("#showMyMsg").html('<div align="center" style="padding:20px;"><img src="images/loading.gif" alt="数据加载中,请稍候..." /></div>');
		load=setTimeout("activity.change(1);",500);
	},
	gotoclass:function(src)
	{
		activity.updateTags(src);
		clearTimeout(load);
		$("#showMyMsg").html('<div align="center" style="padding:20px;"><img src="images/loading.gif" alt="数据加载中,请稍候..." /></div>');
		load=setTimeout("activity.change(2);",500);
	},
	gotobordcast:function(src)
	{
		activity.updateTags(src);
		clearTimeout(load);
		$("#showMyMsg").html('<div align="center" style="padding:20px;"><img src="images/loading.gif" alt="数据加载中,请稍候..." /></div>');
		load=setTimeout("activity.change(3);",500);
	},
	gotoownerspot:function(src)
	{
		activity.updateSpotTags(src);
		clearTimeout(load);
		$("#showMySpot").html('<div align="center" style="padding:20px;"><img src="images/loading.gif" alt="数据加载中,请稍候..." /></div>');
		load=setTimeout("activity.changespot(1);",500);
	},
	gotojoinspot:function(src)
	{
		activity.updateSpotTags(src);
		clearTimeout(load);
		$("#showMySpot").html('<div align="center" style="padding:20px;"><img src="images/loading.gif" alt="数据加载中,请稍候..." /></div>');
		load=setTimeout("activity.changespot(2);",500);
	},
	doaction:function(src)
	{
		  var userid=$("#userid").val();
		  var action=src.getAttribute("title");
		  var actiontype=$("#actiontype").val();
		 // alert(userid);
		  $.ajax({
					url: "templet/attention.php?action="+action+"&userid="+userid,
					async:false,
					type: "GET",
					dataType: "text",
					timeout: 10000,
					success: function(data)
					{
						if(actiontype==0)
						{
							$("#showMyProfile").load("templet/showmyprofile.php?userid="+userid+"&sss="+new Date().getTime()+"");
						}
						else
						{
							$("#showMyProfile").load("templet/showmyprofile.php?userid="+userid+"&actiontype="+actiontype+"&sss="+new Date().getTime()+"");
						}
					}
				}
			);
	},
	
	isTelephone:function(str)
	{
		var res=/^[0]{0,1}(13|15|01|18){1}(\d){1}[ ]?[-]?(\d){7,8}$/;
		var re = new RegExp(res);
		return re.test(str);
	},
	addFriend:function(src,box)
	{
		var userid=$("#userid").val();
		var relation=$("#relation").val();
		var actiontype=$("#actiontype").val();
		//alert(actiontype);
		//alert(userid);
		var mobile=$("#mobile").val();
		var addfriend=src.getAttribute("title");
		var content=$("#note").val();
		var flag="";
		//src.onclick=null;
		if((mobile)!=null&&(mobile)!="")
		{
			if(activity.isTelephone(mobile))
			{
				$.ajax
					(
						{
						url: "/space/templet/attention.php?action="+addfriend+"&mobile="+encodeURIComponent(mobile)+"&userid="+userid+"&relation="+relation+"&content="+encodeURIComponent(content),
						type: "GET",
						dataType: "text",
						timeout: 10000,
						success: function(data){
							//alert(data);
							if(data=="0")
							{
								Boxy.alert("请确认你要加为好友的手机号！",'',{title:'提示框'});
								flag=false;
							}
							else if(data=="1")
							{
								//alert("等对方确认后就行了！");
								//document.location.reload("");
								box.hide();
								if(actiontype==0)
								{
									$("#showMyProfile").load("/space/templet/showmyprofile.php?userid="+userid+"&sss="+new Date().getTime()+"");
								}
								else
								{
									$("#showMyProfile").load("/space/templet/showmyprofile.php?userid="+userid+"&actiontype="+actiontype+"&sss="+new Date().getTime()+"");
								}
								flag=true;
							}
						 }
						}
					);
					return flag;
			}
			else
			{
				Boxy.alert("手机好格式不正确！",'',{title:'提示框'});
				return false;
			}
		}
		else
		{	
			Boxy.alert("手机号必须要填的！",'',{title:'提示框'});
			return false;
		}
	},
	checkLength:function()
	{
	 var content=$("#note").val();
	 var sum=activity.fucCheckLength(content);
	 if(sum>24)
	 {
		content=activity.cutstr(content,24);
		$("#note").val(content);
		return false;
	 }
	 else return true;
	},
	fucCheckLength:function(strTemp)
	{
		var i,sum,str;   
		sum=0;
		for(i=0;i<strTemp.length;i++)   
		{   
		  if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))   
			sum=sum+1;   
		  else  
			sum=sum+2;   
		}   
		return sum;   

	},
	cutstr:function(strTemp,length)
	{
		var i,sum,str='';   
		sum=0;
		for(i=0;i<strTemp.length;i++)
		{
			if(sum>=length)return str;
			str=str+strTemp.charAt(i);
			//alert(str);
			if ((strTemp.charCodeAt(i)>=0) && (strTemp.charCodeAt(i)<=255))
			{
				sum=sum+1;
			}
			else
			{
				sum=sum+2;
			}
		}
		return str;
	},
	checkmsgtitle:function()
		{
		var msgtitle=$("#msgtitle").val();
		if(msgtitle==null ||msgtitle=="")
			{
				Boxy.alert("私信标题不允许为空~！",'',{title:'提示框'});
				return false;
			}
		else
			{
				return true;	
			}
		},
	 checkmsgcontent:function()
		{
		   var msgcontent=$("#msgcontent").val();
			if(msgcontent==null ||msgcontent=="")
			{
				Boxy.alert("私信内容不允许为空~！",'',{title:'提示框'});
				return false;
			}
			else
		   {
				return true;	
			}
		},
		  sendMsg:function(src,box2)
		  {
			//src.onclick=null;
			var msgtitle=$("#msgtitle").val();
			//alert(msgtitle);
			var msgcontent=$("#msgcontent").val();
			//alert(msgcontent);
			var userid=$("#userid").val();
			var sendmsg=src.getAttribute("title");
			var uUid=$("#uUid").val();
			if(userid!=uUid)
			{
				if(activity.checkmsgcontent())//activity.checkmsgtitle() &&
				{
					src.innerHTML="发送中...";
					src.onclick=null;
					$.ajax
						(
							{
							url: "/space/templet/attention.php?action="+sendmsg+"&userid="+userid,
							type: "POST",
							data:"msgtitle="+msgtitle+"&msgcontent="+msgcontent,
							dataType: "text",
							timeout: 10000,
							success: function(data){
									box2.hide();
								}
							 }
						);
				}
				else
				{
					return false;
				}
				return true;
			}
			else 
			{
				Boxy.alert("自己不能给自己发私信哦",'',{title:'提示框'});
				return false;
			}
	 },
	joinBlackList:function(userid)
	{
		var actiontype=$("#actiontype").val();
		bConfirm("您是否确定进行该操作！",function(){
		$.ajax({
			url: "/class/ajax/blacklist/?uid="+userid+"&ssss="+new Date().getTime(),
			type: "Get",
			dataType: "text",
			timeout: 10000,
			async:false,
			success: function(data){
					bAlert(data);
					if(actiontype==0)
					{
						$("#showMyProfile").load("/space/templet/showmyprofile.php?userid="+userid+"&sss="+new Date().getTime()+"");
					}
					else
					{
						$("#showMyProfile").load("/space-bak/templet/showmyprofile.php?userid="+userid+"&actiontype="+actiontype+"&sss="+new Date().getTime()+"");
					}
				}
			 });
		},"提示");
	}
}