var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

var pathroot = "/";
var ajaxtimeout = 10000; // ajax 请求等待超时的毫秒,超时后则跳转到传统页面处理
var postid = 0;
var topicoffset = 0;
var vforumoffset = 0;

var isguest = true;
var bgfloat="<div id=\"BoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";				 


if(nickname != ""&& nickname != "游客" && nickname !='undefined')
{
	isguest = false;
}

function getvalue(str,name)
{

	if (str.indexOf(name)!=-1)
	{
		var pos_start=str.indexOf(name)+name.length+1;
		
		var pos_end=str.indexOf("&",pos_start);
		
		if (pos_end==-1)
		{
			
			return str.substring(pos_start);
		}
		else
		{
			return str.substring(pos_start,pos_end)
		}
	}
	else
	{
		return "not find";
	}
}

function ctrl_enter(id)
{
	$().keydown(function(e)
 	{
 		if(e.ctrlKey && e.keyCode == 13)
 		{
 			$(id).click();
 		}
 	}) 
}

function ctrl_enter_input(input,id)
{
	$("#"+input).keydown(function(e)
 	{
 		if(e.ctrlKey && e.keyCode == 13)
 		{
 			$("#"+id).click();
 		}
 	}) 
}

function movePopBox()
{
	var startdrag = false;
	var mx = 0;
	var my = 0;
	var moffsetTop = 0;
	var moffsetLeft = 0;
	$(".menubar").mousedown(function(e)
	{
		startdrag = true;
		if(is_ie)
		{	
			mx = event.x; 
			my = event.y;
		 }
		 else
		 {
		    mx = e.pageX ; 
			my = e.pageY;
		 }
		 moffsetTop = $("#popbox").offset().top; 
		 moffsetLeft = $("#popbox").offset().left; 
	})
	$(document).mousemove(function(e)
	{ 
		if(startdrag == true) 
		{
			if(is_ie)
			{ 
		    	$("#popbox").css('left',moffsetLeft+event.x-mx+'px');
				$("#popbox").css('top', moffsetTop+event.y-my+'px'); 
			}
			else
			{
				$("#popbox").css('left',moffsetLeft+e.pageX-mx+'px'); 
				$("#popbox").css('top', moffsetTop+e.pageY-my+'px');
			}
		}
	});
	$(document).mouseup(function()
	{ 
		startdrag = false; 
	});
		    
}
function addDiv(divid,css,before)
{
	if(before == undefined || before == "")
		before = "body";
	$(before).append("<div id='"+divid+"' class='"+css+"' ></div>");
	
}
function minDiv()
{
	$("#popboxbody").css("height",'275px');
	$("#popbox").css({ height: "300px", width: "500px" });
	$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
	$("#popbox").css({left:(($(document).width()/2)-320)+"px"});
}
function NormalDiv()
{
	$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
	$("#popbox").css({left:(($(document).width()/2)-320)+"px"});
}

function resize(width,height)
{
	var bodyheight = height-25;
	$("#popboxbody").css("height",bodyheight+'px');
	$("#popbox").css({ height: height+"px", width: width+"px" });
	$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
	$("#popbox").css({left:(($(document).width()/2)-320)+"px"});
}


function removeDiv(divid)
{
	$("#"+divid).remove();
}
function hideMedia(bool)
{
	
	if(bool == undefined || bool == "")
	{
		//$("object").hide();
		//$("#searchtype").attr("Disabled",true);
		
		$("object[@classid!=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000]").hide();
		$("#birthdayselect").hide();
	}
	else
	{
		//$("object").show();
		//$("#searchtype").show();
		$("object[@classid!=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000]").show();
		$("#birthdayselect").show();
	}
}
function showFloatBg(floatdiv)
{
	$("#"+floatdiv).before(bgfloat);
	$("#BoxBg").addClass("floatBg");
	$("#BoxBg").show();	
	$("#BoxBg").css({opacity:"0.2"});
}
function hideFloat(floatdiv)
{
	$("#"+floatdiv).remove();
	$("#BoxBg").remove();
}

function closeFloat(div,fun)
{
	$("[@id*=close]").click(function()
	{	
		if(div =='avatardiv') 
		{
			$("#byear").show();
			$("#bmonth").show();
			$("#bday").show();				
		}
		hideFloat(div)
		try
		{
			//alert('close try');
			loading();
			hideMedia('show');	
		}
		catch(err)
		{}
		if(fun != '' && fun != undefined)
		{   
			eval(fun);
		}
		return false;
	})
	movePopBox();
}

var loadingid = "#waiting";
var noloadingid = "#nowaiting";
function loading(bool)
{
	if(bool)
	{
		//addDiv("loading","floatBar");
		//$("#loading").html("正在读取数据.....");
		//$("#loading").show();
		$(loadingid).show();
		$(noloadingid).hide();
		
	}
	else
	{
		//$("#loading").hide();
		//removeDiv("loading");	
		
		$(noloadingid).show();
		
		$(loadingid).hide();		
	}
}

function randStr()
{
	var rand = Math.random();
	return rand.toString().substring(5,10);
}

function go2href(href)
{
	
	if(href == '' || href == undefined)
	{
		pathroot = "";
		href = window.location.toString();
	}
	
	//alert(href);
	var find = href.indexOf('rand');
	
	if(find != -1)
	{
		//alert("rand");
		var start = href.indexOf("rand");
		var end = href.indexOf("&",start);
		var href1 = href.substring(0,start);
		
		var href2 = href.substring((end+1));	
		href = href1+"rand="+randStr()+"&"+href2;
	}
	else
	{
		//alert("norand");
		var start = href.indexOf("?");
		if(start != -1)
		{
			var href1 = href.substring(0,start);
			var href2 = href.substring((start+1));
		
			href = href1+"?rand="+randStr()+"&"+href2;
		}
		
		
	}
	
	
	
	
	if(href.indexOf(pathroot) != -1)
		window.location = href;
	else
		
		window.location = pathroot+href;
}

function checklogin()
{
	if(nickname == "" || nickname == "游客" || nickname == undefined)
	{
		
		return false;
	}
	else
		return true;
}
function shownewpm1(html,pmnum)
{
	if(html != "hide")
	{
		$("#showmessageinfo").html("<a href='"+pathroot+"message.php' target='_blank'><img src='"+pathroot+"images/cdelbbs/hasmessage.gif' title='您有"+pmnum+"条未读短消息' /></a>");
		$("#showmessageinfoacc").removeClass("showmessageinfo");
		$("#showmessageinfoacc").addClass("showmessageinfonew");
	}
	else
	{
		$("#showmessageinfo").html("<a href='"+pathroot+"message.php' target='_blank'><img src='"+pathroot+"images/cdelbbs/nomessage.gif' title='您目前没有新的短消息' /></a>");
		$("#showmessageinfoacc").removeClass("showmessageinfonew");
		$("#showmessageinfoacc").addClass("showmessageinfo");
	}
}
function doerror()
{
	href= window.location;
	
	//window.location = href;
}

//获取新的短消息
function getNewMessage()
{
	
   	$.ajax  //检查新短消息
	({
		type: "POST",
		url: pathroot+"ajaxxml.php",
		data:   "act=cpm",
		timeout: ajaxtimeout,
		beforeSend:function(){loading(true)},
		async:true,
		success: 
		function(xml)
		{ 
			var status = parseInt($(xml).find('status').text());
        	var pmnum = parseInt($(xml).find('pmnum').text());
        	var allnum = parseInt($(xml).find('sid').text());
        	
        	
        	if(status == 1 && pmnum >0)
        	{
        		
        		shownewpm1("html",pmnum);
        			
        	}
        	else
        	{
        		
        		shownewpm1("hide",0);
        		
        		
        	}
		},
		error: function() 
		{
			
		},
		complete:function()
		{
			loading();
						
		}
	});
}
function autologin()//自动登录
{
	
	$.ajax  
	({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=autologin&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 				
				var status = parseInt($(xml).find('status').text());
				
				
				if(status == 1)
				{
					go2href(window.location.toString());
				}
					
 			},
 			error: function() //请求失败时直接调用普通页面
 			{
 				//window.location="login.php";
 				//go2href("login.php");
 			},
 			complete:function(){loading()}
		});
}
function forlogin()//获取存储的密码
{
	
	$.ajax  
	({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=loginform&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 				var nickname = $(xml).find('nickname').text();
				
				var pass = $(xml).find('pass').text();
				var save = parseInt($(xml).find('save').text());
				
				$("#username").val(nickname);
				if(save == 1)
				{
					$("#password").val(pass);
					$("#savepwd").attr("checked",true);
				}
				
				/*   密码加密传输时启用
				if(pass != "")
				{
					pass = pass.split("|");
					
					var tmp = "";
					var key = "YTozOntzOjg6Im5pY2tuYW1lIjtzOjU6ImFkbWluIjtzOjQ6InBhc3MiO3M6NDoiMTAwfCI7czo0OiJzYXZlIjtiOjE7fQ";
					for(var i=0;i<pass.length-1;i++)
					{
						tmpkey = key.charAt(i).charCodeAt();
						
						tmpkey = parseInt(tmpkey);
						alert(tmpkey);
						tmp += String.fromCharCode(pass[i]^tmpkey);
						
					}
					alert(tmp);
					pass = tmp;
					
					$("#password").val(pass);
				}*/
				
					
 			},
 			error: function() //请求失败时直接调用普通页面
 			{
 				//window.location="login.php";
 				go2href("login.php");
 			},
 			complete:function(){loading()}
		});
}
function login(fun)// 登录
{
	//alert("hello");
	
	
	$("#loginsubmit").click(function()
	{
		if($("#username").val() == "")
		{
			$("#msg").html("请输入用户名");
			$("#msg").show();
			return false;
		}
		if($("#password").val() == "")
		{
			$("#msg").html("请输入密码");
			$("#msg").show();
			return false;
		
		}
		if($("#vdcode1").val() == "")
		{
			$("#msg").html("请输入验证码");
			$("#msg").show();
			return false;
		
		}
		var savepwd = $('input[@name=savepwd][@checked]').val();
		if(savepwd == undefined)
			savepwd = 0 ;
		
		$.ajax  
		({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=login&vdcode="+$("#vdcode1").val()+"&username="+$("#username").val()+"&password="+$("#password").val()+"&savepwd="+savepwd,
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
				var status =parseInt($(xml).find('status').text());
				//var meg = $(xml).find('msg').text();				
	            if(status == 0)
	            {
	         		$("#msg").html($(xml).find('msg').text());
	         							
	         		$("#msg").show();
	         		
	         		$("#randcodeimg").attr("src",pathroot+"randcode.php?rand="+randStr());
	         		return false;
	         	}
	         	else if(status == 2)
	         	{
	         		$("#msg").html($(xml).find('msg').text());
	         		$("#msg").show();
	         		$("#randcodeimg").attr("src",pathroot+"randcode.php?rand="+randStr());
	         		return false;
	         	}
	         	else
	         	{
	         		window.location.reload();
	         		nickname = $(xml).find('nickname').text();
	         		//$("#msg").hide();
	         		$("#BoxBg").hide();
					$("#popbox").hide();					
					$("#loginspan").hide();
	         		$("#nicknameonbar").html(nickname);	
					$("#loginoutspan").show();
					$("#showmessageinfo").show();
				
				//logoutbox
				$("#loginbox").hide();
				$("#logoutbox").show();
				$("#nicknameinlogoutbox").html(nickname);

	         		try
	         		{
	         			$("#logindiv").remove();
	         			
	         		}
	         		catch(err)
	         		{}	
	         		var sid = $(xml).find('sid').text();
	         		var nowsid = $.cookie('SID');
	         		
	         		
	         		//showDiv("dialogdiv","dialogBox","登录","登录成功,点击下面链接继续下一步操作。"+sid,fun); 
	         		eval(fun);
	         		getNewMessage();
	         		
					 
	         	}
 			},
 			error: function() 
 			{
 				
 				eval(fun);
        		fun = undefined;
 			},
 			complete:function(){loading()}
		});
	})
	
}


function sureTask(thepostid)
{
	$("#popboxbody #sure").click(function()
	{
		 
		 $.ajax  
		({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=taskresult&topicid="+thetopicid+"&postid="+thepostid+"&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 				var status = parseInt($(xml).find('status').text());
 				
 				if(status == 1)
 				{
					$("[@id*=close]").click();
					//alert(window.location);
					go2href();
 				}
 			},
 			error: function() 
 			{
 				doerror();
 				
 			},
 			complete:function(){loading()}
		}); 
	})
}
function showDiv(div,box,title,msg,fun,evalfun)
{
	
	var popdiv = "popbox";
	hideMedia();
	if(evalfun == "" || evalfun == undefined)
		evalfun = true;
	//bgfloat="<div id=\"BoxBg\" style=\"height:"+$(document).height()+"px;filter:alpha(opacity=0);opacity:0;\"></div>";				 
	var addon = "";
	if(div == "voteusersdiv"||div == "operatelog")
	{
		addon = "&topicid="+thetopicid;
	}
	if(div == 'flowerusersdiv'||div == 'eggusersdiv')
	{
		postid = msg;
	}
	$.ajax   //使用$.ajax 可以设置请求超时以及超时后的处理方法
	({
 		type: "get",
		url: pathroot+"getdiv.php?div="+div+"&rand="+randStr()+addon,
		data: "postid="+postid,
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success: 
 		function(xml)
 		{
 			var loginform = $(xml).find('root').text();
 			addDiv(div);
 			document.getElementById(div).innerHTML=loginform; 
 			$("#"+popdiv).before(bgfloat);
			$("#"+popdiv).css({top:($(document).scrollTop()+120)+"px"});
			$("#BoxBg").addClass("floatBg");	
			$("#popboxtitle").html(title);
			
			
			$("#BoxBg").show();
			$("#BoxBg").css({opacity:"0.2"});
			$("#"+box).show();
			
			if(msg != "" && msg != undefined)
			{
				$("#msg").html(msg);
				$("#msg").show();
				
			}
			if(div =='avatardiv')
			{
				$("#avatarbox ul li").click(function()
				{
					//alert(this.id);
					var avatarpath = pathroot+"images/avatars/"+this.id;
					$("#selectedavatar").attr("src",avatarpath);
					$("#avatar").val(this.id);
					hideFloat("popbox");
					
					hideMedia('show');
				})				
			}
			if(div == 'logindiv')
			{
				
				//$("#popbox").css("height",'300px');
				$("#popboxbody").css("height",'275px');
				$("#popbox").css({ height: "300px", width: "500px" });
				forlogin();
				if(domain != "bbs.chinaacc.com")
				{	
					usernameinput("username","usernamehelp2",98,313);
					usernameinput("username3","usernamehelp3",0,0);
				}	
				login(fun);
				
				try
				{
					document.getElementById('username').focus();
					//$("#popbox #username")[0].focus()
					
				}
				catch(err)
				{
				}
				closeFloat(div);
			}
			if(div == 'confirmdiv')
			{
				$("#popboxbody").css("height",'275px');
				$("#popbox").css({ height: "300px", width: "500px" });
				if($("#popboxbody #sure").click(
				function()
				{
					eval(fun);
					fun = undefined;
				}
				));
				closeFloat(div);
				
				
			}
			if(div == 'dialogdiv' || div == 'interestsusdiv'  || div == 'interestfaildiv')
			{
				$("#popboxbody").css("height",'275px');
				$("#popbox").css({ height: "300px", width: "500px" });
				
				var url = window.location.toString();
				var end = url.indexOf("#");
				url = url.substring(0,end);
				
				var closeli = "<li><a id='closeauto' href='"+url+"' >5秒后窗口自动关闭,不等待可点击此处</a></li>";
				$("#dialogBox ul").append(closeli);
				closeFloat(div,fun);
				
				if(fun == undefined || fun =="")
					fun = "hideFloat('"+div+"')";
				
				
				setTimeout(fun,5000);
				
			}
			
			closeFloat(div,fun);
			
			/*  
			$("[@id*=close]").click(function()
			{
				
				
				$("#"+div).remove();
				$("#"+box).remove();
				$("#BoxBg").remove();				
				try
				{
					loading();	
				}
				catch(err)
				{}
				
				
			})
			*/
			
 		},
 		error:function()
 		{
 			doerror();
 		}
 	})	
}
function plvXml(theact,forumid,href,fun,evalfun)  // 认证过程
{
	
	
	if(evalfun == undefined || evalfun == "")
		evalfun = true;
	//alert("plvXml.start:"+fun);
	
	$.ajax   //使用$.ajax 可以设置请求超时以及超时后的处理方法
		({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=plv&dowhat="+theact+"&fid="+forumid+"&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 			   loading();
 			   
		       var status =parseInt($(xml).find('status').text());
		        
		       if(status == 0)
		       {
		        	var msg = $(xml).find('msg').text();
		        	showDiv("logindiv","floatBox",'没有权限',msg,fun);	 
         			
         			return 'false';
		        }
		        else
		        {
		        	if(theact == "canRead")
		        	{
		        		
		        		go2href(href);
		        	}
		        	else if(evalfun)
		        	{
		        		//alert(fun);
		        		eval(fun);
		        	}  	
		        }
		        	

		       
 			},
 			error: function() 
 			{
 				//go2href(href);
 			},
 			complete:function(){loading()}
	});		     
}



//权限验证
function checkPlv(theact,forumid,href,logintag,fun,evalfun)
{
	
	hideMedia()	
	//alert("chekcPlv.start:"+fun);
	if(logintag)
	{
		
		$.ajax  
		({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=loginbar"+"&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){ loading(true)},
 			success: 
 			function(xml)
 			{ 
				
				var status =parseInt($(xml).find('status').text());
				
				
				if(status == 0) 
		       {
		           
		           
		           showDiv("logindiv","floatBox",'登录','您还没有登录请先登录',"plvXml('"+theact+"','"+forumid+"','"+href+"','"+fun+"')");
		           //return lgoin(); 			 		
		       }
		       else
		       {
		           return plvXml(theact,forumid,href,fun,evalfun);
		       }
 			},
 			error: function() 
 			{
 				
 				go2href(href);
 			},
 			complete:function(){loading()}
		});
		
    }
    else
    {    	
    	plvXml(theact,forumid,href,fun,evalfun);    	
    }   
}



function  sureConfirm(thepostid,vforumoffset,topicoffset)
{
	ctrl_enter("#popboxbody #submit");	
	
	$("#popboxbody #submit").click(function()
	{
		
		var sendpm = $("#sendpm").attr("checked");
		var sendmeg = $("#sendpmmessage").val();
		var inall = 0;
		var inall = $("#allin[@checked]").val();
		
		var whydel = $("#whydel[@checked]").val();
		
		
		if(whydel == "" || whydel == "undefined")
		{
			whydel = 0
		}
		
		//alert(inall);
		 $.ajax  //删除贴子
		({
 			
 			
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "inall="+inall+"&sendpm="+sendpm+"&sendmeg="+sendmeg+"&act=deletepost&postid="+thepostid+"&vforumoffset="+vforumoffset+"&topicoffset="+topicoffset+"&whydel="+whydel+"&rand="+randStr(),
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 				
 				var status = parseInt($(xml).find('status').text());
 				var opid = parseInt($(xml).find('opid').text());
 				
 				if(status == 1)
 				{
 					//$("#postbody-"+thepostid).hide();
        			//$("#cmd"+thepostid).html("");
					//$("[@id*=close]").click();
					//go2href(window.location.toString());
					window.location.reload();
					//showDiv("dialogdiv","dialogBox",'操作成功','此贴已被成功删除',"go2href('"+window.location+"')");	
 				}
 				if(status == 2)
 				{
 					var rurl = $(xml).find('returnurl').text();
 					
 					//$("#postcontent"+thepostid).html("此贴已被删除");
 					//$("#postbody-"+thepostid).hide();
        			//$("#cmd"+thepostid).html("");
					//$("[@id*=close]").click();
					go2href(rurl);
					//showDiv("dialogdiv","dialogBox",'操作成功','此贴已被成功删除',"go2href('"+rurl+"')");	
 				}
        		
        		 
         		
 			},
 			error: function() 
 			{
 				doerror();
 				//go2href("delete.php?postid="+thepostid)
 				
 			},
 			complete:function(){loading()}
		}); 
	})
}

function confirmDel(thepostid,vforumoffset,topicoffset)
{
	//showDiv("confirmdiv","confirmBox",'确定删除么','确定删除这个贴子么？',"sureConfirm('"+thepostid+"','"+vforumoffset+"','"+topicoffset+"')");	
	var div = "confirmdiv";
	$.ajax  
	({
 		type: "get",
		url: pathroot+"getdiv.php",
		data: "postid="+thepostid+"&div=confirmdeldiv&rand="+randStr(),
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success: 
 		function(xml)
 		{
 			var cmfdiv = $(xml).find('root').text();
 			addDiv(div);
 			document.getElementById(div).innerHTML=cmfdiv; 
 			showFloatBg(div);
 			
 			
			$("#popboxtitle").html("删除贴子");
			
			//$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
			
			//$("#popboxbody").css("height",'275px');
			//$("#popbox").css({ height: "300px", width: "500px" });
			
			//NormalDiv();
			minDiv();
			$("#popbox").show();
			
			$("#sendpm").click(function()
			{
				if(this.checked)
				{
					$("#sendmeg").show();
				}
				else
				{
					$("#sendmeg").hide();
				}
			})
			closeFloat(div);
 			sureConfirm(thepostid,vforumoffset,topicoffset);
 		}
 		,
 		error:function()
 		{
 			doerror();
 		},
 		complete:function()
 		{
 			loading();
 		}
 	})
	
}

function confirmTask(thepostid)
{
	showDiv("confirmdiv","confirmBox",'确定么','确定将这个回答设为最佳答案么？',"sureTask('"+thepostid+"')");	
}
function showPostDiv(divtitle,postmode,postid,quotepostid)
{
	hideMedia();
	
	if(quotepostid == 'not found')
		quotepostid = 0;
	if(postmode == "createtopic"||postmode == "createtask")
		topicid = "";
	else
		topicid = thetopicid;
	var div = "theEditor";
	var topictype = 0;
	if(postmode == 'createtask')
	{
		postmode = 'createtopic';
		topictype = 2;
	}
	var editboxurl = "/postiframe.php?refloor="+refloor+"&postid="+postid+"&topicid="+topicid+"&forumid="+forumid+"&mode="+postmode+"&vforumoffset="+vforumoffset+"&topicoffset="+topicoffset+"&quotepostid="+quotepostid+"&topictype="+topictype;
	
	$.ajax  
	({
 		type: "get",
		url: pathroot+"getdiv.php",
		data: "refloor="+refloor+"&postid="+postid+"&topicid="+topicid+"&div=editordiv&forumid="+forumid+"&postmode="+postmode+"&vforumoffset="+vforumoffset+"&topicoffset="+topicoffset+"&quotepostid="+quotepostid+"&rand="+randStr(),
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success: 
 		function(xml)
 		{
 			var postform = $(xml).find('root').text();
 			addDiv(div);
 			$("#"+div).show();
 			document.getElementById(div).innerHTML=postform; 
 			$("#popbox").before(bgfloat);
			$("#BoxBg").addClass("floatBg");	
			$("#popboxtitle").html(divtitle);
			
			
			$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
			//alert($(document).width());
			//$("#editordiv").css({left:(($(document).width()/2)-320)+"px"});
			$("#BoxBg").show();
			$("#BoxBg").css({opacity:"0.2"});
			
			$("#popbox").show();
			
			$.ajax  
			({
		 		type: "get",
		 		url:editboxurl,
		 		data: "rand="+randStr(),
		 		timeout:500000,
				beforeSend:function()
				{
					$("#float_iframe_waiting").show();
					$("#popbox #float_iframe").hide();
					
					//loading(true)
				},
				success:function()
				{
					$("#float_iframe_waiting").hide();
					$("#popbox #float_iframe").show();
					
		 			$("#popbox #float_iframe").attr("src",editboxurl);
		 			
				},
				error:function()
		 		{
		 			doerror();
		 		},
		 		complete:function()
		 		{
		 			
		 		}
		 	 })
				
			
			
			
			//alert($($("#float_iframe").document).find("f_content").height());
			
			var max = 0 ;
			var noww = 620;
			var nowh = 450;
			$("#maxwindow").click(function()
			{
				
				
				$("#searchtype").hide();
				
				var nh = $("#editordiv #float_iframe").contents().find("#f_content").height();
				
				//alert(nh);
				
				var w = $(document).width()-50;
				var h = window.screen.height-200;
				var eh = h-40;
				var fh = h-145;
				var pbh = h-30;
				//alert(nh);
				if(parseInt(nh)< 250)
					fh = fh-160;
					
				if(max == 0)
				{
					$("#popbox").css({ top:"30px", left: "15px" });
					$("#popbox").css({ height: h+"px", width: w+"px" });
					$("#editordiv").css({ height: eh+"px"});
					$("#popboxbody").css({ height: pbh+"px"});
					$("#editordiv #float_iframe").contents().find("#f_content").css({height: fh+"px"});
					max = 1;
					
				}
				else if(max == 1)
				{
					eh = nowh - 40;
					pbh = nowh - 30;
					fh = nowh - 145;
					var ath = $("#editordiv #float_iframe").contents().find("#attachlist").css('display');
					if(ath == 'block')
						fh = fh-150;
					$("#popbox").css({ top:"202px", left: "25%" });
					$("#popbox").css({ height: nowh+"px", width: noww+"px" });
					$("#editordiv").css({ height: eh+"px"});
					$("#popboxbody").css({ height: pbh+"px"});
					$("#editordiv #float_iframe").contents().find("#f_content").css({height: fh+"px"});
					max = 0;
				}
				
				
			})
			
			$("#submit").click(function()
			{
				
				var tmpcontent = editor.document.body.innerHTML;
				$("#content").val(html2bbcode(tmpcontent));
				var cansubmit = true;
				if($("#title").val() == "" &&postmode == "topic")
				{
					cansubmit = false;
					$("#errormeg").html("<li>请填写标题</li>");
					$("#errormeg").show();
					 
				}
				if($("#content").val() == "")
				{
					cansubmit = false;
					$("#errormeg").append("<li>请填写内容</li>");
					$("#errormeg").show();
					 
				}
			})
			
			closeFloat(div);
			
			
 		},
 		error:function()
 		{
 			doerror();
 		},
 		complete:function()
 		{
 			loading();
 		}
 	})
}

function showStick(topicid,vforumoffset,act,href)
{
	//alert(vforumoffset);
	hideMedia();
	var div = 'stick';
	$.ajax  
	({
 		type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+act+"&topicid="+topicid+"&act="+act+"&rand="+randStr(),
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success: 
 		function(xml)
 		{
 			var stickdiv = $(xml).find('root').text();
 			addDiv(div);
 			document.getElementById(div).innerHTML=stickdiv; 
 			
 			$("#popbox").before(bgfloat);
			$("#BoxBg").addClass("floatBg");	
			if(act == 'stick')
				$("#popboxtitle").html("置顶操作");
			else
				$("#popboxtitle").html("解除置顶");
			$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
			$("#BoxBg").show();
			$("#BoxBg").css({opacity:"0.2"});
			
			$("#popbox").show();
			
			$("#sendpm").click(function()
			{
				if(this.checked)
				{
					$("#sendmeg").show();
				}
				else
				{
					$("#sendmeg").hide();
				}
			})
			ctrl_enter("#popboxbody #submit");	
			
			
			$("#popboxbody #submit").click(function()
			{
				
				var priority = $('input[@name=priority][@checked]').val()
				var stype =$('input[@name=stype][@checked]').val();
				var forumid = $("#forumid").val();
				var sendpm = $("#sendpm").attr("checked");
				var sendmeg = $("#sendpmmessage").val();
				var enddate = $("#enddate").val();
				var daterange = $("#daterange").val();
				
				if(enddate == "" && daterange == 0)
				{
					$("#stickmeg").html("<font color=red>请选择或填写置顶时限</font>")
					return ;
				}
				
				
				//return false;
			
				var perforumid = "";
				$("#forumids option[@selected]").each(function()
				{
					if(perforumid == "")
						perforumid = perforumid + "forumids[]="+this.value;
					else
						perforumid = perforumid + "&forumids[]="+this.value;
					
				})
				
				
				
				$.ajax  
				({
			 		type: "post",
					url: pathroot+"ajaxxml.php",
					data: "daterange="+daterange+"&enddate="+enddate+"&sendmeg="+sendmeg+"&sendpm="+sendpm+"&forumid="+forumid+"&act="+act+"&topicid="+topicid+"&priority="+priority+"&stype="+stype+"&"+perforumid+"&rand="+randStr(),
			 		timeout: ajaxtimeout,
			 		beforeSend:function(){loading(true)},
			 		success: function(xml)
			 		{
			 			var status = parseInt($(xml).find('status').text());
			 			var msg = $(xml).find('msg').text();
			 			var rurl = window.location;
			 			if(status == 1)
			 			{
			 				$("#BoxBg").remove();
			 				$("#popbox").remove();
			 				
			 				showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+rurl+"')");	
			 			}
			 			else
					 	{
					 		$("#BoxBg").remove();
					 		$("#popbox").remove();
					 		showDiv("dialogdiv","dialogBox","失败",msg,"go2href('"+rurl+"')");	
				
					 	}
			 		},
			 		error:function(){doerror();}, //go2href(href);},
			 		complate:function(){loading()}
			 		
				})
			})
			closeFloat(div);
			
 			
 		},
 		error:function()
 		{ 
 			go2href(href);
 			//alert('error')
 		},
 		complate:function()
 		{
 			loading();
 		}
 	})
}		
function showDigest(topicid,act)
{
	hideMedia();
	
	var div = 'digest';
	$.ajax  
	({
 		type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+act+"&topicid="+topicid+"&act="+act+"&rand="+randStr(),
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success: 
 		function(xml)
 		{
			
			var digestdiv = $(xml).find('root').text();
 			addDiv(div);
 			document.getElementById(div).innerHTML=digestdiv; 
 			showFloatBg(div);
 			
 			if(act == 'digest')
				$("#popboxtitle").html("设置精华");
			else
				$("#popboxtitle").html("解除精华");
			$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
			
			$("#popboxbody").css("height",'275px');
			$("#popbox").css({ height: "300px", width: "500px" });
				
			$("#popbox").show();
			
			$("#sendpm").click(function()
			{
				if(this.checked)
				{
					$("#sendmeg").show();
				}
				else
				{
					$("#sendmeg").hide();
				}
			})
			ctrl_enter("#popboxbody #submit");	
			$("#popboxbody #submit").click(function()
			{
				var sendpm = $("#sendpm").attr("checked");
				var sendmeg = $("#sendpmmessage").val();
				$.ajax  
				({
					type: "post",
					url: pathroot+"ajaxxml.php",
					data: "act="+act+"&topicid="+topicid+"&sendpm="+sendpm+"&sendmeg="+sendmeg+"&rand="+randStr(),
					timeout: ajaxtimeout,
					beforeSend:function(){loading(true)},
					success: function(xml)
					{
						 var status = parseInt($(xml).find('status').text());
						 var msg = $(xml).find('msg').text();
						 var rurl = window.location;			
						 if(status == 1)
						 {
						 	hideFloat("popbox");
							hideFloat(div);
						 	showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+rurl+"')");	
						 }
						 else
						 {
						 	hideFloat("popbox");
							hideFloat(div);
						 	showDiv("dialogdiv","dialogBox","失败",msg,"go2href('"+rurl+"')");	
						 }
					},
					error:function(){
					
					doerror();
					//alert('error1');
					
					},
					complate:function(){loading()}
						 		
				})
			})
			closeFloat(div);
		},
 		error:function()
 		{ 
 			go2href(href);
 			//alert('error')
 		},
 		complate:function()
 		{
 			loading();
 		}
 	})
		
	
}

function showCommonDiv(uid,div,divtitle,href) //用于好友请求和短消息发送
{
	
	hideMedia();
	var tmpdiv = div+'div';
	$.ajax  
	({
		type: "post",
		url: pathroot+"ajaxxml.php",
		data: "act=loginbar",
		timeout: ajaxtimeout,
		beforeSend:function(){loading(true)},
		success: function(xml)
		{
			 var status = parseInt($(xml).find('status').text());
			 var msg = $(xml).find('msg').text();
			 			
			 if(status == 1)
			 {
			 	$.ajax  
				({
					type:"get",
					url:pathroot+"getdiv.php",
					data:"div="+div+"&touid="+uid,
					timeout:ajaxtimeout,
					beforeSend:function(){loading(true)},
					success:function(xml)
					{
						var addfriendform = $(xml).find('root').text();
						addDiv(tmpdiv);
						document.getElementById(tmpdiv).innerHTML=addfriendform; 
						showFloatBg("popbox");
						$("#popboxtitle").html(divtitle);
						
						$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
						$("#popbox").css({left:(($(document).width()/2)-320)+"px"});
						$("#popbox").show();
						minDiv();
						
						
						
						closeFloat("popbox");
						try
						{
							document.getElementById("content").focus();
						}
						catch(err)
						{}
						$().keydown(function(e)
					 	{
					 		if(e.ctrlKey && e.keyCode == 13)
					 		{
					 			$("#popbox #submit").click();
					 		}
					 	}) 
						
						$("#popboxbody #submit").click(
						
						function()
						{
							
							var canSendmessage = true;
							var theuid = $("#touid").val();
							var thecontent = $("#popboxbody #content").val();
							var subject = '';
							var theuname = '';
							
							
							
							if(div == "sendmessage")
							{	
								subject = $("#subject").val();
								if(subject == "" || subject == undefined )
								{
									$("#errormeg").html("<li>标题不能为空</li>");
									return;
									
								}
								theuname = $("#touname").val();
								if(theuname == "" || theuname == undefined )
								{
									$("#popboxbody #errormeg").html("<li>接收者不能为空</li>");
									return;
								}
							}
							
							
							if(thecontent == "" || thecontent == undefined )
							{
								$("#popboxbody #errormeg").html("<li>内容不能为空</li>");
								//alert(div+"2");
								return;
							}		
							
							
							
							
							$.ajax(
							{
								type:"post",
								url:pathroot+"ajaxxml.php",
								data:"touname="+theuname+"&act="+div+"&touid="+theuid+"&subject="+subject+"&content="+thecontent,
								timeout:ajaxtimeout,
								beforeSend:function(){loading(true)},
								success:function(xml)
								{
									var status = parseInt($(xml).find('status').text());
									var msg = $(xml).find('msg').text();
									
									if(status == 1)
									{
										$("#popbox").remove();
										$("#"+div).remove();
										hideFloat("popbox");
										hideFloat(div);
										
										
										showDiv("dialogdiv","dialogBox","操作成功",msg);	
										
									}
									else
									{
										$("#popboxbody #errormeg").html("<li>"+msg+"</li>");
										
										//showDiv("dialogdiv","dialogBox","操作失败",msg);
									}
								},
								error:function(){
								//alert("eddd");
								hideFloat("popbox");
								$("#popbox").remove();
								doerror();
								},
								complate:function(){loading()}
							}
							)	
							
						})
						
					
					},
					error:function(){
					hideFloat("popbox");
					doerror();
					},
			 		complate:function(){loading()}
			 	})
			 	
			 }
			 else
			 {
			 	showDiv("logindiv","floatBox","没有登录","您还没有登录不能进行此操作。","showCommonDiv('"+uid+"','"+div+"','"+divtitle+"','"+href+"')");	
			 }
		},
		error:function(){
		
		doerror();
		
		},
		complate:function(){loading()}
			 		
	})
}

function showPostRate(postid,href,fun)
{
	var div = 'postratediv';
	hideMedia();
	if(!checklogin())
	{
		showDiv("logindiv","floatBox","无法操作","您还没有登录，不能进行评分,点击关闭按钮关闭对话框。");	
	}
	else
	{
		$.ajax  
		({
	 		type: "get",
			url: pathroot+"getdiv.php",
			data: "div=postrate&postid="+postid+"&rand="+randStr(),
	 		timeout: ajaxtimeout,
	 		beforeSend:function(){loading(true)},
	 		success: 
	 		function(xml)
	 		{
	 			var ratediv = $(xml).find('root').text();
	 			addDiv(div);
	 			document.getElementById(div).innerHTML=ratediv; 
	 			showFloatBg("popbox");
				$("#popboxtitle").html('评分');
				$("#popbox").css({top:($(document).scrollTop()+100)+"px"});
				$("#popbox").css({left:(($(document).width()/2)-320)+"px"});
				$("#popbox").show();
				closeFloat("popbox");
	 			$("#postrate #submit").click(function()
	 			{
	 				var therate = $("input[@type=radio][@checked]").val();
	 				
	 				var thereason = $("#postrate #reason").val();
	 				if(therate == '0')
	 				{
	 					
	 					hideFloat(div);
	 					return "";
	 				}
	 				$.ajax
	 				({
	 					type:"post",
	 					url:pathroot+"ajaxxml.php",
	 					data:"act=postrate&postid="+postid+"&rate="+therate+"&reason="+thereason,
	 					timeout:ajaxtimeout,
	 					beforeSend:function(){loading(true)},
	 					success:
	 					function(xml)
	 					{
	 						var status = parseInt($(xml).find('status').text());
							var msg = $(xml).find('msg').text();
							hideFloat("popbox");
							if(status == 1)
							{
								showDiv("dialogdiv","dialogBox","操作成功",msg,fun);	
								
							}
							else
							{
								showDiv("dialogdiv","dialogBox","操作失败",msg);	
							}
	 					},
	 					error:function()
	 					{
	 						doerror();
	 						//go2href(href);
	 					},
	 					complate:function()
	 					{
	 						loading();
	 					}
	 				})
	 			})
	 		},
	 		error:function()
	 		{
	 			doerror();
	 			//go2href(href);
	 		},
	 		complate:function()
	 		{
	 			loading();
	 		}
	 		
	 	})
 	}
}
function addInterest(topicid)
{
	$.ajax  
	({
 		type: "POST",
		url: pathroot+"ajaxxml.php",
 		data:   "act=interest&topicid="+thetopicid,
 		timeout: ajaxtimeout,
 		beforeSend:function(){loading(true)},
 		success:function(xml)
 		{
 			var status = parseInt($(xml).find('status').text());
			var msg = $(xml).find('msg').text();
			
			if(status == 1)
			{
				showDiv("interestsusdiv","interestBox","收藏成功",msg);	
								
			}
			else
			{
				showDiv("interestfaildiv","interestBox","收藏失败",msg);	
			}
 		},
 		error:function()
 		{
 			doerror();
 		},
 		complate:function()
 		{
 			loading();
 		}
 	})
}

function  doEventThing(event)
{     
	if(is_ie)
	{
		if(event.keyCode == 13)
		{
			if($("#popbox #password").val()!="" && $("#popbox #vdcode1").val()!="")
			
			 $("#loginsubmit").click();
		}
	}
	else
	{
		if($("#popbox #password").val()!="" && $("#popbox #vdcode1").val()!="")
		{
			if(doEventThing.arguments[0].keyCode == 13)
			$("#loginsubmit").click();
		}
	}	
	
} 

function showFlowerDiv(act,title,postid)
{
	div = act+"div";
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&postid="+postid+"&randcode="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html(title);
	 		//$("#flowerBox #msg").html("")
			NormalDiv();
			$("#popbox").show();
			closeFloat("popbox");
			$("#popboxbody #sure").click(function()
			{
				thepage = window.location.toString().replace(/&/g,"|");
				
				$.ajax
	 			({
	 				type:"post",
	 				url:pathroot+"ajaxxml.php",
	 				data:"act="+act+"&postid="+postid+"&thepage="+thepage,
	 				timeout:ajaxtimeout,
	 				beforeSend:function()
	 				{
	 					loading(true);	
	 				},
	 				success:
	 				function(xml)
	 				{
	 					var status = parseInt($(xml).find('status').text());
						var msg = $(xml).find('msg').text();
						//alert(msg);
						//hideFloat("popbox");
						if(status == 1)
						{
							hideFloat("popbox");
							var refval = $("#"+act+postid).html();
							$("#"+act+postid).html(parseInt(refval)+1);
							showDiv("dialogdiv","dialogBox","成功",msg);	
							//hideMedia('show');
						}
						else
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","失败",msg);	
						}
	 				},
	 				error:function()
	 				{
	 					doerror();	
	 				},
	 				complate:function()
	 				{
	 					
	 					loading();
	 				}
	 			})	
			})
		},
		error:function()
	 	{
	 		doerror();
	 				//go2href(href);
	 	},
	 	complate:function()
	 	{
	 		//$("#checknicknametag").html("");
	 	}
	 })
	
}
function showHighlight(topicid)
{
	div = "highlightdiv";
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&topicid="+topicid+"&rand="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html("高亮标题");
	 		//$("#flowerBox #msg").html("")
			NormalDiv();
			$("#popbox").show();
			closeFloat("popbox");
			
			$("#popboxbody #submit").click(function()
			{
				var h_s = "";
				$("input[@id=stype][@checked]").each(function()
				{
					if(h_s == "")
						h_s = this.name+"=1";
					else
						h_s = h_s + "&"+this.name+"=1";
					
				})
				
				var h_c = $("input[@id=highlight_color][@checked]").val();
				var c_h = $("input[@id=clearhighlight][@checked]").val();
				$.ajax
	 			({
	 				type:"post",
	 				url:pathroot+"ajaxxml.php",
	 				data:"act=highlight&c_h="+c_h+"&topicid="+topicid+"&hc="+h_c+"&"+h_s,
	 				timeout:ajaxtimeout,
	 				beforeSend:function()
	 				{
	 					loading(true);	
	 				},
	 				success:
	 				function(xml)
	 				{
	 					var status = parseInt($(xml).find('status').text());
						var msg = $(xml).find('msg').text();
						//alert(msg);
						//hideFloat("popbox");
						if(status == 1)
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+window.location+"')");	
							hideMedia('show');
						}
						else
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","失败",msg);	
							hideMedia('show');
						}
	 				},
	 				error:function()
	 				{
	 					doerror();	
	 				},
	 				complate:function()
	 				{
	 					
	 					loading();
	 				}
	 			})	
				
			})
		},
		error:function()
		{
			doerror();
		},
		complate:function()
		{
			
		}
	})
}

function showRecommend(topicid)
{
	div = "recommenddiv";
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&topicid="+topicid+"&rand="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html("推荐");
	 		//$("#flowerBox #msg").html("")
			NormalDiv();
			resize(800,600);
			$("#popbox").show();
			closeFloat("popbox");
		},
		error:function()
		{
			doerror();
		},
		complate:function()
		{
			
		}
	})
}

function showUpdown(topicid)
{
	div = "updowndiv";
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&topicid="+topicid+"&rand="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html("提升/下沉主题");
	 		//$("#flowerBox #msg").html("")
			minDiv();
			$("#popbox").show();
			closeFloat("popbox");
			
			$("#popboxbody #submit").click(function()
			{
				
				var updowntype = $("input[@id=updowntype][@checked]").val();
				
				
				$.ajax
	 			({
	 				type:"post",
	 				url:pathroot+"ajaxxml.php",
	 				data:"act=updown&udtype="+updowntype+"&topicid="+topicid,
	 				timeout:ajaxtimeout,
	 				beforeSend:function()
	 				{
	 					loading(true);	
	 				},
	 				success:
	 				function(xml)
	 				{
	 					var status = parseInt($(xml).find('status').text());
						var msg = $(xml).find('msg').text();
						//alert(msg);
						//hideFloat("popbox");
						if(status == 1)
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+window.location+"')");	
							hideMedia('show');
						}
						else
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","失败",msg);	
							hideMedia('show');
						}
	 				},
	 				error:function()
	 				{
	 					doerror();	
	 				},
	 				complate:function()
	 				{
	 					
	 					loading();
	 				}
	 			})	
				
			})
		},
		error:function()
		{
			doerror();
		},
		complate:function()
		{
			
		}
	})
}


function showMoreDel(act,title)
{
	div = act+"div";
	var pertopic = "";
	var thei = 0;
	$("input[@id=moredel][@checked]").each(function()
	{
		if(pertopic == "")
			pertopic = pertopic + "topicid[]="+this.value;
		else
			pertopic = pertopic + "&topicid[]="+this.value;
		thei++;
	})
	
	if(thei>0)
	
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&"+pertopic+"&rand="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html(title);
			NormalDiv();
			$("#popbox").show();
			closeFloat("popbox");
			$("#popboxbody #sure").click(function()
			{
				var cpertopic = "";
				var cthei = 0;
				$("input[@id=cmfmoredel][@checked]").each(function()
				{
					if(cpertopic == "")
						cpertopic = cpertopic + "topicid[]="+this.value;
					else
						cpertopic = cpertopic + "&topicid[]="+this.value;
					cthei++;
				})
				
				if(cthei>0)
				
				$.ajax
	 			({
	 				type:"post",
	 				url:pathroot+"ajaxxml.php",
	 				data:"act=moredel&forumid="+forumid+"&"+cpertopic,
	 				timeout:ajaxtimeout,
	 				beforeSend:function()
	 				{
	 					 waitsure("popboxbody #sure");
	 					loading(true);	
	 				},
	 				success:
	 				function(xml)
	 				{
	 					var status = parseInt($(xml).find('status').text());
						var msg = $(xml).find('msg').text();
						//alert(msg);
						//hideFloat("popbox");
						if(status == 1)
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+window.location+"')");	
							hideMedia('show');
						}
						else
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","失败",msg);	
							hideMedia('show');
						}
	 				},
	 				error:function()
	 				{
	 					doerror();	
	 				},
	 				complate:function()
	 				{
	 					waitsure("popboxbody #sure");
	 					loading();
	 				}
	 			})	
			})
		},
		error:function()
		{
			doerror();
		},
		complate:function()
		{
			
		}
	})
}
function showMove(act,title,onetopicid)
{
	div = act+"div";
	
	var pertopic = "";
	var thei = 0;
	if(onetopicid == "" || onetopicid == undefined)
	{
		$("input[@id=moredel][@checked]").each(function()
		{
			if(pertopic == "")
				pertopic = pertopic + "topicid[]="+this.value;
			else
				pertopic = pertopic + "&topicid[]="+this.value;
			thei++;
		})
	}
	else
	{
		thei = 1;
		pertopic = "topicid[]="+onetopicid;
	}
	if(thei>0)
	
	$.ajax  
	({
	 	type: "get",
		url: pathroot+"getdiv.php",
		data: "div="+div+"&"+pertopic+"&rand="+randStr(),
	 	timeout: ajaxtimeout,
	 	beforeSend:function(){loading(true)},
	 	success: 
	 	function(xml)
	 	{
	 		var ratediv = $(xml).find('root').text();
	 		addDiv(div);
	 		document.getElementById(div).innerHTML=ratediv; 
	 		showFloatBg("popbox");
	 		hideMedia();
	 		$("#popboxtitle").html(title);
			NormalDiv();
			$("#popbox").show();
			closeFloat("popbox");
			
			$("#forumids").click(function()
			{
				
				var forumname = $("#forumids option[@selected]").html();
				
				var movemeg = $("#movemeg").val();
				$("#sendpmmessage").html(movemeg+"["+forumname+"]");
				
			})
			
			$("#sendpm").click(function()
			{
				if(this.checked)
				{
					$("#sendmeg").show();
				}
				else
				{
					$("#sendmeg").hide();
				}
			})
			
			$("#popboxbody #sure").click(function()
			{
				var cpertopic = "";
				var cthei = 0;
				$("input[@id=cmfmove][@checked]").each(function()
				{
					if(cpertopic == "")
						cpertopic = cpertopic + "topicid[]="+this.value;
					else
						cpertopic = cpertopic + "&topicid[]="+this.value;
					cthei++;
				})
				
				var movetoforumid = $("#forumids option[@selected]").val();
				
				if(movetoforumid == '' || movetoforumid == undefined)
				{
					
					$("#popbox #movetotag").html("<font color=red>请选择版块</font>")
					return false;
				}
				
				var sendpm = $("#sendpm").attr("checked");
				var sendmeg = $("#sendpmmessage").val();
				
				
				if(cthei>0)
				
				$.ajax
	 			({
	 				type:"post",
	 				url:pathroot+"ajaxxml.php",
	 				data:"act=movetopic&forumid="+forumid+"&movetoforumid="+movetoforumid+"&"+cpertopic+"&sendpm="+sendpm+"&sendmeg="+sendmeg,
	 				timeout:ajaxtimeout,
	 				beforeSend:function()
	 				{
	 					loading(true);	
	 				},
	 				success:
	 				function(xml)
	 				{
	 					var status = parseInt($(xml).find('status').text());
						var msg = $(xml).find('msg').text();
						//alert(msg);
						//hideFloat("popbox");
						if(status == 1)
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","成功",msg,"go2href('"+window.location+"')");	
							hideMedia('show');
						}
						else
						{
							hideFloat("popbox");
							showDiv("dialogdiv","dialogBox","失败",msg);	
							hideMedia('show');
						}
	 				},
	 				error:function()
	 				{
	 					doerror();	
	 				},
	 				complate:function()
	 				{
	 					
	 					loading();
	 				}
	 			})	
			})
		},
		error:function()
		{
			doerror();
		},
		complate:function()
		{
			
		}
	})
}
function  showOperate(opid,type,title)
{
	div = type+"div";
		
		
		$.ajax  
		({
		 	type: "get",
			url: pathroot+"getdiv.php",
			data: "div="+div+"&opid="+opid+"&type="+type+"&rand="+randStr(),
		 	timeout: ajaxtimeout,
		 	beforeSend:function(){loading(true)},
		 	success: 
		 	function(xml)
		 	{
		 		var ratediv = $(xml).find('root').text();
		 		addDiv(div);
		 		document.getElementById(div).innerHTML=ratediv; 
		 		showFloatBg("popbox");
		 		hideMedia();
		 		$("#popboxtitle").html(title);
		 		//$("#flowerBox #msg").html("")
				minDiv();
				$("#popbox").show();
				closeFloat("popbox");
				
				$("#popboxbody #sure").click(function()
				{
					var expire = $("#expire option[selected]").val();
					
					$.ajax  
					({
			 			type: "POST",
						url: pathroot+"ajaxxml.php",
			 			data:   "act="+type+"&opid="+opid+"&expire="+expire,
			 			timeout: ajaxtimeout,
			 			beforeSend:function(){loading(true)},
			 			success: 
			 			function(xml)
			 			{
			 				var status =parseInt($(xml).find('status').text());
			 				var msg = $(xml).find('msg').text();
			 				if(status == 1)
			 				{
			 					hideFloat(div);
			 					showDiv("dialogdiv","dialogBox",'操作成功',msg,"go2href('"+window.location+"')");	 
			 				}
			 				else
			 				{
			 					showDiv("dialogdiv","dialogBox",'操作失败',msg);	 
			 				}
			 			},
			 			error:function()
			 			{
			 				//alert("err");
			 				//go2href(href);
			 			},
			 			complate:function()
			 			{
			 				loading();
			 			}
			 		})
				})
			},
			error:function()
			{
				alert("error");
			},
			complate:function()
			{
				
			}
		})
		
}
function  showCancelTask()
{
	div = "confirmdiv";
		$.ajax  
		({
		 	type: "get",
			url: pathroot+"getdiv.php",
			data: "div="+div+"&topicid="+thetopicid+"&rand="+randStr(),
		 	timeout: ajaxtimeout,
		 	beforeSend:function(){loading(true)},
		 	success: 
		 	function(xml)
		 	{
		 		var cdiv = $(xml).find('root').text();
		 		addDiv(div);
		 		document.getElementById(div).innerHTML=cdiv; 
		 		showFloatBg("popbox");
		 		hideMedia();
		 		$("#popboxtitle").html('确认取消悬赏');
		 		
				minDiv();
				$("#popbox").show();
				
				$("#msg").html('确定要取消此悬赏贴么？');
				$("#msg").show();
				closeFloat("popbox");
				
				$("#popboxbody #sure").click(function()
				{
					
					$.ajax  
					({
			 			type: "POST",
						url: pathroot+"ajaxxml.php",
			 			data:   "act=canceltask&topicid="+thetopicid,
			 			timeout: ajaxtimeout,
			 			beforeSend:function(){loading(true)},
			 			success: 
			 			function(xml)
			 			{
			 				var status =parseInt($(xml).find('status').text());
			 				var msg = $(xml).find('msg').text();
			 				if(status == 1)
			 				{
			 					hideFloat(div);
			 					showDiv("dialogdiv","dialogBox",'操作成功',msg,"go2href('"+window.location+"')");	 
			 				}
			 				else
			 				{
			 					showDiv("dialogdiv","dialogBox",'操作失败',msg);	 
			 				}
			 			},
			 			error:function()
			 			{
			 				alert("err");
			 				//go2href(href);
			 			},
			 			complate:function()
			 			{
			 				loading();
			 			}
			 		})
				})
			},
			error:function()
			{
				//alert("error");
			},
			complate:function()
			{
				
			}
		})
		
}

function  showPushscore(theuid,thepostid)
{
	div = "pushscorediv";
	
		$.ajax  
		({
		 	type: "get",
			url: pathroot+"getdiv.php",
			data: "div="+div+"&opuid="+theuid+"&rand="+randStr(),
		 	timeout: ajaxtimeout,
		 	beforeSend:function(){loading(true)},
		 	success: 
		 	function(xml)
		 	{
		 		var cdiv = $(xml).find('root').text();
		 		addDiv(div);
		 		document.getElementById(div).innerHTML=cdiv; 
		 		showFloatBg("popbox");
		 		hideMedia();
		 		$("#popboxtitle").html('积分奖惩');
		 		
				minDiv();
				$("#popbox").show();
				
				onlynumber("score");
				closeFloat("popbox");
				
				$("#popboxbody #submit").click(function()
				{
					
					var scoretype = $("input[@type=radio][@id=scoretype][checked]").val();
					var score = $("#score").val();
					
					if(score == "0")
					{
						$("#scoremeg").html("<font color='red'>不能为0</font>");
						return false;
					}
					
					var sendpmmessage = $("#sendpmmessage").val();
					if(sendpmmessage == '')
					{
						$("#msg").html('<font color=red>请选择输入操作原因</font>');
						return false;
					}
					var sendpm = $("input[@id=sendpm][@checked]").val();
					if(scoretype == "" || scoretype == undefined )
					{
						$("#msg").html('<font color=red>请选择积分类型</font>');
						return false;
					}
					if(score == '' || score == undefined)
					{
						$("#msg").html('<font color=red>请选择输入具体分值</font>');
						
						return false ;
					}	
					if(sendpm == "" || sendpm == undefined)
						sendpm = 0;
					
									
					$.ajax  
					({
			 			type: "POST",
						url: pathroot+"ajaxxml.php",
			 			data:   "act=pushscore&opuid="+theuid+"&scoretype="+scoretype+"&score="+score+"&sendpmmessage="+sendpmmessage+"&postid="+thepostid+"&sendpm="+sendpm,
			 			timeout: ajaxtimeout,
			 			beforeSend:function(){loading(true)},
			 			success: 
			 			function(xml)
			 			{
			 				var status =parseInt($(xml).find('status').text());
			 				var msg = $(xml).find('msg').text();
			 				if(status == 1)
			 				{
			 					hideFloat(div);
			 					showDiv("dialogdiv","dialogBox",'操作成功',msg,"go2href('"+window.location+"')");	 
			 				}
			 				else
			 				{
			 					showDiv("dialogdiv","dialogBox",'操作失败',msg);	 
			 				}
			 			},
			 			error:function()
			 			{
			 				//alert("err");
			 				//go2href(href);
			 			},
			 			complate:function()
			 			{
			 				loading();
			 			}
			 		})
				})
			},
			error:function()
			{
				alert("error");
			},
			complate:function()
			{
				
			}
		})
		
}
function waitsure(btnid)
{
	
	if($("#"+btnid).attr("disabled") == true)
	{
		$("#"+btnid).attr("disabled",false);
	}
	else
		$("#"+btnid).attr("disabled",true);
}
function  showEditcode(thepostid)
{
	div = "editcodediv";
		$.ajax  
		({
		 	type: "get",
			url: pathroot+"getdiv.php",
			data: "div="+div+"&postid="+thepostid+"&rand="+randStr(),
		 	timeout: ajaxtimeout,
		 	beforeSend:function(){loading(true)},
		 	success: 
		 	function(xml)
		 	{
		 		var cdiv = $(xml).find('root').text();
		 		addDiv(div);
		 		document.getElementById(div).innerHTML=cdiv; 
		 		showFloatBg("popbox");
		 		hideMedia();
		 		$("#popboxtitle").html('代码编辑状态');
		 		
				NormalDiv();
				$("#popbox").show();
				
				closeFloat("popbox");
				
				$("#popboxbody #submit").click(function()
				{
					
					var content = $("#codecontent").val();
					
					content = preg_replace(['\t', '   ', '  ', '(\r\n|\n|\r)'], ['&nbsp; &nbsp; &nbsp; &nbsp; ', '&nbsp; &nbsp;', '&nbsp;&nbsp;', '<br/>'], content);
					//alert(content);
					$.ajax  
					({
			 			type: "POST",
						url: pathroot+"ajaxxml.php",
			 			data:   "act=editcode&postid="+thepostid+"&content="+content,
			 			timeout: ajaxtimeout,
			 			beforeSend:function(){loading(true)},
			 			success: 
			 			function(xml)
			 			{
			 				var status =parseInt($(xml).find('status').text());
			 				var msg = $(xml).find('msg').text();
			 				if(status == 1)
			 				{
			 					hideFloat(div);
			 					go2href(window.location.toString());
			 					//showDiv("dialogdiv","dialogBox",'操作成功',msg,"go2href('"+window.location+"')");	 
			 				}
			 				else
			 				{
			 					showDiv("dialogdiv","dialogBox",'操作失败',msg);	 
			 				}
			 			},
			 			error:function()
			 			{
			 				//alert("err");
			 				//go2href(href);
			 			},
			 			complate:function()
			 			{
			 				loading();
			 			}
			 		})
				})
			},
			error:function()
			{
				//alert("error");
			},
			complate:function()
			{
				
			}
		})
		
}
function divList(listid,options,inputid,fun)
{
	
	for(var i = 0 ; i<options.length;i++)
	{
		var option = "<li id='"+options[i][0]+"'>"+options[i][1]+"++++</li>";
		$("#"+listid+" ul").append(option);
		
		
		if($("#"+inputid).val()== options[i][0])
		{
			$("#"+listid+" p").html(options[i][1]);
		}
		
	}
	
	$("#"+listid+" p").mouseover(function()
	{
		$(this).addClass("orderbylistpover");
		onoptlist = 1;	
	})
	$("#"+listid+" p").mouseout(function()
	{
		$(this).removeClass("orderbylistpover");
		onoptlist = 0;	
	})
	
	$("#"+listid+" p").click(function()
	{
		$("#"+optdivname).hide();
		$("#"+listid+" ul").show();
		optdivname = listid+" ul";
 		clearInterval(hideintval);
		hideintval = setInterval("hideadminopt()",1000);
	})
	
	$("#"+listid+" ul li").mouseover(function()
	{
		$(this).attr("class",'listover');
	})
	$("#"+listid+" ul li").mouseout(function()
	{
		$(this).attr("class",'');
	})
	
	
	$("#"+listid+" ul").mouseover(function()
	{
		onoptlist = 1;	
	})
	$("#"+listid+" ul").mouseout(function()
	{
		onoptlist = 0;	
	})
	
	$("#"+listid+" ul li").click(function()
	{
		$("#"+listid+" ul").hide();
		$("#"+listid+" p").html($(this).html());
		$("#"+inputid).val(this.id);
	})
}
function onlynumber(tag)
{

	$("input[@id="+tag+"]").keyup(function()
	{
		tmpn = $("#"+tag).val();
		$("input[@id="+tag+"]").val(tmpn.replace(/[^-*\d|^\d]/g,''));
		
	})
}

var onoptlist = 0
var hideintval = '';
var optdivname = 'adminopt';

function hideadminopt()
{
	//alert(optdivname+onoptlist);
	
	if(onoptlist == 0)
	{
			$("#"+optdivname).hide();
			onoptlist = 1;
	}
	
	if(optdivname == 'returnlist' || optdivname == 'returnlistbtm')
		checkFloatDiv(optdivname)
}

function checkFloatDiv()
{
	
	if($("#"+optdivname).css("display") == "none")
		$(".goback").css("position","static");
	else
		$(".goback").css("position","relative");
		
	
}

var key40 = 0;
var enter = 0;
var inputval = '';
function usernameinput(inputtag,divtag,top,left)
{
	$("#"+inputtag).keyup(function()
	{
		
		inputval = $("#"+inputtag).val();
		
		var thetop = $(this).offset().top-top;
 		var theleft = $(this).offset().left-left;
 		thetop+="px";
 		theleft+="px";
 		if(top !=0 || left != 0)
 		{
	 		if(top == 0)
	 			$("#"+divtag).css({left:theleft});
	 		else
	 			$("#"+divtag).css({top:thetop,left:theleft});
 		}
 		if(inputval.length>1 && inputval.indexOf("@")==-1)
 		{
			enter = 0;
			$("#"+divtag).show();
			
			
		}
		if(inputval.length<=1)
		{
			
			$("#"+divtag).hide();
			key40 = 1;
		}
		/* 
		$("#"+divtag+" li").each(function()
		{
			$(this).html(inputval+this.title);
		})
		*/
	})
	$("#"+inputtag).keydown(function(e)
 	{
 		
 		if(e.keyCode == 40)
 		{
 			if(key40 != 0)
 			{
 				$("#"+divtag+" #"+key40.toString()).attr("class","");
 			}
 			key40 += 1;
 			
 			$("#"+divtag+" li").each(function(){$(this).attr("class","")});
 			$("#"+divtag+" #"+key40.toString()).attr("class","usernamehelplistover");
 			
 			if(key40 >= 9)
 				key40 = 0;
 		}
 		if(e.keyCode == 38)
 		{
 			if(key40 != 0)
 			{
 				$("#"+divtag+" #"+key40.toString()).attr("class","");
 			}
 			key40 -= 1;
 			$("#"+divtag+" li").each(function(){$(this).attr("class","")});
 			$("#"+divtag+" #"+key40.toString()).attr("class","usernamehelplistover");
 			
 			if(key40 <= 0)
 				key40 = 9;
 		}
 		if(e.keyCode == 13 && enter == 0)
 		{
 			//$("#"+inputtag).val($("#"+divtag+" #"+key40.toString()).html());
			//$("#"+divtag).hide();
			//key40 = 0;
			inputval = $("#"+inputtag).val();
			//alert(inputval);
			var selectval = $("#"+divtag+" li[@class=usernamehelplistover]").attr("title");
			if(selectval != "" && inputval.indexOf("@")==-1 && selectval != undefined)
				$("#"+inputtag).val(inputval+selectval);//
			$("#"+divtag).hide();
			key40 = 0;
			enter = 1;
			
			return false;
 		}
 	}) 
 	
	
	
	
	$("#"+divtag+" li").click(function()
	{
		
		$("#"+inputtag).val(inputval+$(this).attr("title"));
		$("#"+divtag).hide();
		key40 = 0;
		
	})
	$("#"+divtag+" li").mouseover(function()
	{
		$("#"+divtag+" li").each(function(){$(this).attr("class","")});
		$(this).attr("class","usernamehelplistover");
	});
	
	$("#"+divtag+" li").mouseout(function()
	{
		$(this).attr("class","");
	});
	
	$("#"+inputtag).blur(function()
	{
			inputval = $("#"+inputtag).val();
			var selectval = $("#"+divtag+" li[@class=usernamehelplistover]").attr("title");
			if(selectval != "" && inputval.indexOf("@")==-1 && selectval != undefined &&inputval != "")
				$("#"+inputtag).val(inputval+selectval);//
			$("#"+divtag).hide();
			key40 = 0;
		
	})
	
}
	
	
	if(isguest)
	{
		$("#loginspan").show();
		
		//loginbox
		$("#loginbox").show();
		$("#logoutbox").hide(); 
		
		//;
		if(typeof autologintag == 'undefined')
			setTimeout("autologin()",1000);
		usernameinput("username2","usernamehelp",0,13);
	}
	else
	{
		$("#loginspan").hide();
        $("#loginoutspan").show();
		$("#showmessageinfo").show();
        
        $("#nicknameonbar").html(nickname);
		
		//logoutbox
		$("#loginbox").hide();
		$("#logoutbox").show();
		$("#nicknameinlogoutbox").html(nickname);
		
		
      
       	setTimeout('getNewMessage()',5000);
        setInterval("getNewMessage()",300000);
        
        
        //newpmbg();
	}
	
	$("#logoutbut2").click(function()
	{
		$("#logoutbut").click();
		
		
	});	
	$("#loginbut").click(function()
	{
		var href = "/login.php";
		
		href = href.substring(0,href.indexOf("#"));
		
		
		showDiv("logindiv","floatBox",'登录','',"go2href('"+href+"')");	 
		
		return false;
		 	 
	});
	 
	$("#logoutbut").click(function()
	{
		var href = window.location.toString();
		
		//href = href.substring(0,href.indexOf("#"));  返回当前页
		//href = pathroot;  // 返回首页
		
		if(href.indexOf("editprofile.php") != -1 
		|| href.indexOf("viewscore.php") != -1
		|| href.indexOf("mylist.php") != -1
		|| href.indexOf("message.php") != -1
		|| href.indexOf("friendmanage.php") != -1
		|| href.indexOf("sendmessage.php") != -1
		|| href.indexOf("sendmessage.php") != -1)
		{
			href = pathroot;
		}
		
		$.ajax  
		({
 			type: "POST",
			url: pathroot+"ajaxxml.php",
 			data:   "act=loginout",
 			timeout: ajaxtimeout,
 			beforeSend:function(){loading(true)},
 			success: 
 			function(xml)
 			{ 
 				
				nickname = "";
	         	//showDiv("dialogdiv","dialogBox",'注销','注销成功',"go2href('"+href+"')");	 
	         	go2href(href);
	         	$("#loginspan").show();
	         	$("#loginoutspan").hide();
				$("#showmessageinfo").hide();
	         	$("#loginoutspan span").html(nickname);
 			},
 			error: function() //请求失败时直接调用普通注销页面
 			{
 				go2href("login.php?act=logout");
 				
 			},
 			complete:function(){loading()}
		}); 
	})	
	
	
	if(typeof searchtypeoptions != 'undefined')
	{
		
		divList('searchtypelist',searchtypeoptions,'searchtype');
	}
	
	
	// 发新贴 
	function newTopic(href)
	{
		var postmode = "createtopic";
		checkPlv('canPost',forumid,this.href,false,"showPostDiv('发贴','"+postmode+"',0)",false); 
		return false;
	}
	
	// 发悬赏
	function newTask(href)
	{
		var postmode = "createtask";
		checkPlv('canPost',forumid,this.href,false,"showPostDiv('发贴','"+postmode+"',0)",false); 
		return false;
	}
			
	//回贴 
	function repost(href,quotepostid,refloor)
	{
		
		
		var postmode = "createpost";
		
		checkPlv('canReply',forumid,href,false,"showPostDiv('回贴','"+postmode+"',0,'"+quotepostid+"')",false); 
		
		return false;
	}
	
	
	//收藏
	function interest(thetopicid)
	{
		
		checkPlv('canInterest',forumid,'',false,'addInterest('+thetopicid+')'); 	
		return false;
	}
	
	//送鲜花
	function sendFlower(postid)
	{
		checkPlv('canFlower',forumid,this.href,false,"showFlowerDiv('flower','送鲜花',"+postid+")"); 
		
		return false;
	}
	
	//扔鸡蛋
	function sendEgg(postid)
	{
		checkPlv('canEgg',forumid,this.href,false,"showFlowerDiv('egg','扔鸡蛋',"+postid+")"); 
		return false;
	}	

	//送勋章
	
	function sendMedal(postid)
	{
		checkPlv('canEgg',forumid,this.href,false,"showFlowerDiv('medal','送勋章',"+postid+")"); 
		return false;
	}
	
	//好友请求
	
	function addFriend(fuid,href)
	{
		showCommonDiv(fuid,'addfriend','发送好友请求',href);
		return false;
	}
	
	$("#showvotelist").click(function()
	{
		showDiv('voteusersdiv','voteusersbox','投票用户(显示24个)');
		return false;
	})
	
	
	$("#gobackbtn").mouseover(function()
	{
		if(optdivname != "returnlist")
			$("#"+optdivname).hide();
		$(".goback").css("position","relative");
		$("#returnlist").show();
		optdivname = "returnlist";
 		clearInterval(hideintval);
 		onoptlist = 1;	
		hideintval = setInterval("hideadminopt()",500);
		$("#gobackbtn").addClass("mouseover");
	})
	
	$("#gobackbtn").mouseout(function()
	{
		onoptlist = 0;
		$("#gobackbtn").removeClass("mouseover");
	})
	$("#returnlist").mouseover(function()
	{
		onoptlist = 1;	
	})
	$("#returnlist").mouseout(function()
	{
		onoptlist = 0;	
		
	})
	
	
	$("#gobackbtnbtm").mouseover(function()
	{
		$("#"+optdivname).hide();
		$(".goback").css("position","relative");
		$("#returnlistbtm").show();
		optdivname = "returnlistbtm";
 		clearInterval(hideintval);
 		onoptlist = 1;	
		hideintval = setInterval("hideadminopt()",500);
		$("#gobackbtnbtm").addClass("mouseover");
		
	})
	$("#gobackbtnbtm").mouseout(function()
	{
		onoptlist = 0;
		$("#gobackbtnbtm").removeClass("mouseover");
	})
	$("#returnlistbtm").mouseover(function()
	{
		onoptlist = 1;	
	})
	$("#returnlistbtm").mouseout(function()
	{
		onoptlist = 0;	
		
		
	})
	
	
	
	
	function showJumplist()
	{
		$("#goback").css("position","static");
		$("#"+optdivname).hide();
		$("#newforumnavigator").show();
		optdivname = "newforumnavigator";
 		clearInterval(hideintval);
 		onoptlist = 1;	
		hideintval = setInterval("hideadminopt()",1000);
		
	}
	
	$("#accforumtitlenva").mouseout(function()
	{
		onoptlist = 0;
	})
	
	
	$("#newforumnavigator").mouseover(function()
	{
		
		onoptlist = 1;	
	})
	$("#newforumnavigator").mouseout(function()
	{
		onoptlist = 0;	
		
		
	})
	
	
	
	function showJumplistbtm()
	{
		
		$("#"+optdivname).hide();
		$("#newforumnavigatorbtm").show();
		optdivname = "newforumnavigatorbtm";
 		clearInterval(hideintval);
		hideintval = setInterval("hideadminopt()",1000);
	}
	$("#newforumnavigatorbtm").mouseover(function()
	{
		onoptlist = 1;	
	})
	$("#newforumnavigatorbtm").mouseout(function()
	{
		onoptlist = 0;	
	})
	
	
	function showJumplist()
	{
		
		$("#"+optdivname).hide();
		$("#newforumnavigator").show();
		optdivname = "newforumnavigator";
 		clearInterval(hideintval);
		hideintval = setInterval("hideadminopt()",1000);
		
	}
	$("#newforumnavigator").mouseover(function()
	{
		onoptlist = 1;	
		
	})
	$("#newforumnavigator").mouseout(function()
	{
		onoptlist = 0;
		
	})
	
	
	//翻页
	
	$(".pagenavigator input[@id=gotopage]").focus(function()
	{
		
		if($(this).val() == "转至")
		{
			$(this).val("");
			$(this).addClass("oninput");
			
		}
	})
	$(".pagenavigator input[@id=gotopage]").blur(function()
	{
		
		if($(this).val() == "")
		{
			$(this).val("转至");
			$(this).removeClass("oninput");
		}
	})
	
	$(".pagenavigator input[@id=gotopage]").keyup(function()
	{
		$("input[@id=gotopage]").val($(this).val());
		topage = $("#gotopage").val();
		$("input[@id=gotopage]").val(topage.replace(/[^\d]/g,''));
		
	})
	
	
	$(".pagenavigator input[@id=gotopage]").keydown(function(e)
	{
		
		if(e.keyCode == 13)
		{
			var topage = parseInt($("#gotopage").val());
			var golink = $(this).attr("class");
			var pernum = $("#gotopage").attr("maxlength");
			if(topage<=parseInt(this.name))
			{
				
				topage = topage - 1;
				if(topage>0)
					golink = golink.replace("OFFSETVALUE",topage*pernum);
				else
				{
					golink = golink.replace("offset-OFFSETVALUE/","");
					golink = golink.replace("-OFFSETVALUE","");
				}
				
				golink = golink.replace("oninput","");
				window.location = golink;
				return false;
			}
			else
			{
				showDiv("dialogdiv","dialogBox","错误的页码","请输入正确的页码。");
			}
		}
	})
	
	function makeGoto()
	{
		var topage = parseInt($("#gotopage").val());
		var golink = $("#gotopage").attr("class");
		var pernum = $("#gotopage").attr("maxlength");
			
		if(topage<=parseInt($("#gotopage").attr('name')))
		{
			topage = topage - 1;
				
			if(topage>0)
				golink = golink.replace("OFFSETVALUE",topage*pernum);
			else
			{
				golink = golink.replace("offset-OFFSETVALUE/","");
				golink = golink.replace("-OFFSETVALUE","");
			}
				golink = golink.replace("oninput","");
				top.location = golink;
		}
		else
		{
			showDiv("dialogdiv","dialogBox","错误的页码","请输入正确的页码。");
		}
		return false;
	}
	
	
	
	//控制快速回复头像
	
	var quickavatarwidth = $(".quickreply .avatar img").width();
	
	if(quickavatarwidth > 120)
		$(".quickreply .avatar img").attr("width",120);
		
		
	
	//控制签名档链接为新窗口
/* 
	$("#signarea a").each(function()
	{
		this.target = "_blank";
	});
	$(".postcontent img").each(function()
	{
		if(this.width >640)
			this.width = 640;
	})
*/	
	//加载快速回复
	
	//setTimeout("setEditorUrl()",500);
	
	var screenwidth = window.screen.width * 0.98 - 300;
	var maxwidth = 1000 - 300 ;
	
	$(".postcontent img").each(function()
	{
		
		if(this.width > screenwidth)
		{
			
			this.width = maxwidth;
			
			$(this).attr("onclick","javascript:window.open('"+$(this).attr('src')+"')");
			
			$(this).click(function(){window.open($(this).attr('src'))});
			$(this).css("cursor","pointer");
		}
		
		
	});
	
	//控制签名档图片大小
 	
	$(".signarea img").each(function()
	{
		
		if(this.width > screenwidth - 100)
		{
			this.width = maxwidth-100;
			
		}
		
		
	});
	
	$(".postcontent a").each(function()
	{
		this.target = "_blank";
	});
	
	
	function showpost(postid)
	{
		
		
		$.ajax  
			({
				
				
				type: "post",
				url: pathroot+"showpost.php",
				data: "postid="+postid,
				timeout: ajaxtimeout,
				async:true,
				beforeSend:function()
				{
					
				},
				success: function(xml)
				{
					var status = parseInt($(xml).find('status').text());
					var cdiv = $(xml).find('postcontentdiv').text();
					$("#postsdiv"+postid).html(cdiv);
					$("#postsdiv"+postid).show();
				},
				errot: function(){}
			})
	}
	
	
	
	function userinfopop(popuid,floor)
	{
		
		$.ajax  
		({
			
			
			type: "get",
			url: pathroot+"normalxml.php",
			data:"act=popinfo&popuid="+popuid+"&rand="+randStr(),
			timeout: ajaxtimeout,
			async:true,
			beforeSend:function()
			{
				
			},
			success: function(xml)
			{
				var status = parseInt($(xml).find('status').text());
				if(status == 1)
				{
					var cdiv = $(xml).find('content').text();
					$("#popinfo-"+popuid+"-"+floor).html(cdiv);
					
					$("#"+optdivname).hide();
					
					$("#popinfo-"+popuid+"-"+floor).show();
					optdivname = "popinfo-"+popuid+"-"+floor;
 					clearInterval(hideintval);
					hideintval = setInterval("hideadminopt()",1000);
					
					$("#popinfo-"+popuid+"-"+floor).mouseout(function()
					{
						onoptlist = 0;	
					})
					
					$("#popinfo-"+popuid+"-"+floor).mouseover(function()
					{
						onoptlist = 1;	
					})
				}
			},
			errot: function(){}
		})
	}
	
	if(isguest)
	{
		if(domain != "bbs.chinaacc.com")
		{	
			usernameinput("username3","usernamehelp3",0,0);
		}
	}
	if(!isguest)
	{
		
		//提交投票

		$("#topicpoll #submitpoll").click(function()
		{
			
			var polltype = $("#topicpoll #polltype").val();
			var maxchoices =parseInt($("#topicpoll #maxchoices").val());
			var choicesnum = $("input[@id=pollopt][@checked]").length;
			
			if(choicesnum == 0)
			{
				var ameg = "最多只能选择"+maxchoices+"个选项";
				if(polltype == 0 && maxchoices ==0)
				{
					var ameg = "最多只能选择1个选项"
					
				}
				if(polltype !=0 && maxchoices == 0)
				{
					var ameg = "选责数不限";
				}
				$("#topicpoll #pollalert").html("<font color=red>请选择后投票,"+ameg+"</font>");
				return false;
			}
			if(polltype != 0 && maxchoices!=0)
			{
				
				
				if(choicesnum > maxchoices)
				{
					$("#topicpoll #pollalert").html("<font color=red>最多只能选择"+maxchoices+"个选项</font>")
					return false;
				}
				
			}
			return true;
	
		})
		
		
		//编辑
		
		function editPostSelf(href,postid,tfo,vfo)
		{
			var postmode = "edit";
			
			topicoffset = tfo;
			vforumoffset = vfo;
			
			checkPlv('canEditSelf',forumid,href,true,"showPostDiv('编辑','"+postmode+"','"+postid+"')",true); 
			
			return false;
		}
		
		function deleteSelf(href,postid,tfo,vfo)
		{
			checkPlv('canDeleteSelf',forumid,'',true,'confirmDel('+postid+','+vfo+','+tfo+')'); 
			return false;
		}
		

		
		// 管理操作按钮
		
		 
		$(".cmd a[@id=showadminopt]").mouseover(function()
		{
			//hidelastdiv();
			//lastdivobj = this.name;
			$("#"+optdivname).hide();
			optdivname = this.name;
			$("#"+optdivname).show();
			onoptlist = 1;
		})
		$(".cmd a[@id=showadminopt]").mouseout(function()
		{
			//alert(optdivname);
			//alert(onoptlist);
			onoptlist = 0;
			clearInterval(hideintval);
			hideintval = setInterval("hideadminopt()",1000);
			
		})
		
		
		$(".cmd div[name=adminopt]").mouseover(function()
		{
			
			//$("#"+optdivname).show();
			onoptlist = 1;
		})
		$(".cmd div[name=adminopt]").mouseout(function()
		{
			//$("#"+optdivname).hide();
			onoptlist = 0;
		})
		
		
		
		//管理编辑
		
		function editPost(href,postid,tfo,vfo)
		{
			postmode = "edit";
			
			vforumoffset = vfo;
			topicoffset = tfo ;	
			checkPlv('canEdit',forumid,href,true,"showPostDiv('编辑','"+postmode+"','"+postid+"')",true); 
			
			return false;
		}
		
		
		//管理删除
		
		function deletePost(postid,tfo,vfo)
		{
			
			vforumoffset = vfo;
			topicoffset = tfo;	
			checkPlv('canDelete',forumid,'',true,'confirmDel('+postid+','+vforumoffset+','+topicoffset+')'); 
			return false;
		}
		
				
		// 置顶
		function makeStick(href,topicid,vfo)
		{
			vforumoffset = vfo;
			checkPlv('canStick',forumid,href,true,"showStick('"+topicid+"','"+vforumoffset+"','stick','"+href+"')"); 
			
			return false;
		}
		
		
		
		//解除置顶
		
		function makeUnstick(href,topicid,vfo)
		{
			vforumoffset = vfo;	
			
			checkPlv('canStick',forumid,href,true,"showStick('"+topicid+"','"+vforumoffset+"','unstick','"+href+"')"); 
			
			return false;
		}
		
		
		//精华
		
		function makeDigest(topicid,vfo)
		{
			vforumoffset = vfo;
			checkPlv('canDigest',forumid,'',true,"showDigest('"+topicid+"','digest')"); 
			return false;
		}
	
		//解除精华
		function makeUndigest(topicid,vfo)
		{
			
			vforumoffset = vfo;
			
			checkPlv('canDigest',forumid,'',true,"showDigest('"+topicid+"','undigest')"); 
			
			return false;
		}
		
		
		//管理主题
		$("#showpostbyuid").click(function()
		{
			var spluid = $("#spluid").val();
			showPostBy('uid',spluid)
			
			return false;
		})
		
		//显示ip
		$(".username img[@id=filteruser]").mouseover(function()
		{
			thealt = this.alt;
			$("#floatip"+this.alt).show();	
			
		})
		
		$(".ip a[id=killip]").mouseover(function()
		{
			$("#killip"+this.title).show();	
		})
		
		$(".ip a[id=killip]").mouseout(function()
		{
			$("#killtip"+this.title).hide();	
		})
		
		//封IP
		$(".ip a[@id=killip]").click(function()
		{
			var thisip = this.name;
			div = "killipdiv";
			
			
			$.ajax  
			({
			 	type: "get",
				url: pathroot+"getdiv.php",
				data: "div="+div+"&ip="+thisip,
			 	timeout: ajaxtimeout,
			 	beforeSend:function(){loading(true)},
			 	success: 
			 	function(xml)
			 	{
			 		var ratediv = $(xml).find('root').text();
			 		addDiv(div);
			 		document.getElementById(div).innerHTML=ratediv; 
			 		showFloatBg("popbox");
			 		hideMedia();
			 		$("#popboxtitle").html('确认禁止IP');
			 		//$("#flowerBox #msg").html("")
					minDiv();
					$("#popbox").show();
					closeFloat("popbox");
					
					$("#popboxbody #sure").click(function()
					{
						var expire = $("#expire option[selected]").val();
						
						$.ajax  
						({
				 			type: "POST",
							url: pathroot+"ajaxxml.php",
				 			data:   "act=killip&ip="+thisip+"&expire="+expire,
				 			timeout: ajaxtimeout,
				 			beforeSend:function(){loading(true)},
				 			success: 
				 			function(xml)
				 			{
				 				var status =parseInt($(xml).find('status').text());
				 				var msg = $(xml).find('msg').text();
				 				if(status == 1)
				 				{
				 					hideFloat(div);
				 					showDiv("dialogdiv","dialogBox",'操作成功',msg);	 
				 				}
				 				else
				 				{
				 					showDiv("dialogdiv","dialogBox",'操作失败',msg);	 
				 				}
				 			},
				 			error:function()
				 			{
				 				go2href(href);
				 			},
				 			complate:function()
				 			{
				 				loading();
				 			}
				 		})
					})
				},
				error:function()
				{
					alert("error");
				},
				complate:function()
				{
					
				}
			})
			
			return false;
			
		})

	}
	
	var inLinkDiv = '0';
	var hideLinkDivIntval;
	function hideLinkDiv() {
		//$('#link_div #msg').html(inLinkDiv);	
		if (inLinkDiv == '0') {
			$('#link_div').hide();
		}
	}	
	function openLinkDiv(obj, url) {
		var link_div = $('#link_div');
		clearInterval(hideLinkDivIntval);
		hideLinkDivIntval = setInterval("hideLinkDiv()",1000);
		
		link_div.mouseover(function(){                   
            inLinkDiv = '1';
        });
        link_div.mouseout(function(){                   
            inLinkDiv = '0';
        });
		
		if (document.documentElement.getBoundingClientRect) {
			var a = obj.getBoundingClientRect();			
			$('#link_div #open').attr('href', url);
			var x = Math.ceil(a.left) + document.documentElement.scrollLeft;
			var y = Math.ceil(a.top) + document.documentElement.scrollTop + 20;
			$('#link_div').css('left', x + 'px');
			$('#link_div').css('top', y +'px');		
			$('#link_div').show();
		} else {
			alert('no getBoundingClientRect function');
		} 
	}
	function closeDivLink(){
		$('#link_div').hide();
	}
	


$('#jumplistbtn_s2').bind('mouseenter', function() {
	$('#newforumnavigator_sl').hide();
	$('#newforumnavigator_s2').show();
	$('#newforumnavigator_s2').bind('mouseleave', function() {
		$('#newforumnavigator_s2').hide();
	});
});