//DOM载入时做的一些准备工作
Event.observe(window,"load",function()
{
	add_table_hover_support();
});
//为AJAX请求加上一个右上角的小提示
Ajax.Responders.register(
{
	onCreate: function()
	{
		var ajax_waiting=$("ajax_waiting");
		ajax_waiting.style.top=document.documentElement.scrollTop+"px";
		ajax_waiting.show();
	},
	onComplete: function()
	{
		var ajax_waiting=$("ajax_waiting");
		ajax_waiting.hide();
	}
});
//找到所有className包含"hover_table"的table为它们加上鼠标悬停效果
function add_table_hover_support()
{
	$$("table.hover_table").each(function(table){
		Event.observe(table,"mousemove",function(event)
		{
			var target=Event.findElement(event,"TR");
			target.id="rowCurrent";
		});
		Event.observe(table,"mouseout",function(event)
		{
			var target=Event.findElement(event,"TR");
			target.id="";
		});
	});
}
//导航栏的弹出MYCLUB菜单的事件注册
function create_myclub_menu()
{
	var link=$("myclub_link");
	var mainclub=document.createElement("DIV");
	mainclub.innerHTML='<ul>'
		+'<li><a href="/invitations" >邀请朋友</a></li><li><a href="/inbox_messages" >我的消息</a></li>'
		+'<li><a href="/friends" >我的好友</a></li>'
		+'<li><a href="/topics/bbs_console_topics_released_index" >我的话题</a></li>'
		+'<li><a href="/fav_topics" >我的收藏</a></li>'
		+'<li><a href="/tag_categories/sub_categories/0" >我的tags</a></li>'
		+'<li><a href="/users/basic_info" >个人设置</a></li>'
		+'</ul>';
	mainclub.id="mainclub";
	document.body.appendChild(mainclub);
	mainclub=$(mainclub);
	mainclub.hide();
	if(link && mainclub){
		Event.observe(document,'click', function(event)
		{
			var target=$(Event.element(event));
			if(target==link || target==mainclub || target.ancestors().indexOf(mainclub)>-1){
				var pos=link.cumulativeOffset();
				mainclub.style.left=pos[0]-17+"px";
				mainclub.style.top=pos[1]+link["offsetHeight"]-1+"px";
				mainclub.show();
			}else{
				mainclub.hide();
			}
		});
	}
}
//快速提交
var submit_flag = true;
function QuickSubmit(form)
{
	if(event.keyCode==13 && event.ctrlKey && submit_flag)
	{
		var f = $(form);
		submit_flag = false;
		$("submit_image").src = "/images/button_submit_disabled.gif";
		$("submit_image").onclick = '';
		$("submit_image").disable = true;
		setTimeout("$('post_form').submit();",1000);
		setTimeout("history.go(0);submit_flag = true;alert('服务器连接超时,请再试一遍')",30000);

		return true;
   }
   else
   {
		return false;
   }
}
//如果没有点击“同意发帖须知”那就不让表单提交
function submit_form()
{
	var checked=$("agree").checked;
	if(checked)
	{
		$("submit_image").src = "/images/button_submit_disabled.gif";
		$("submit_image").onclick = '';
		$("submit_image").disable = true;
//		$("post_form").submit();
		setTimeout("$('post_form').submit();",1000);
		setTimeout("history.go(0);alert('服务器连接超时,请再试一遍')",15000);

	}
	else
	{
		alert("必须同意发贴须知才能发帖！");
	}
}

//显示验证码的图片
function show_captcha()
{
	$('captcha').show();
}
//展开或者收起子论坛
function show_or_hide(img,id)
{
	var obj=$(id);
	if(obj.visible())
	{
		obj.hide();
		img.src="/images/forum/close.gif";
		img.alt="展开";
	}
	else
	{
		obj.show();
		img.src="/images/open.gif";
		img.alt="收起";
	}
}
//显示一个弹出对话框
function show_popbox(box_title,box_body)
{
	$("box_title").innerHTML=box_title;
	if($("box_body").childElements().length>0 && $("box_body").childElements()[0]!=box_body)
	{

		document.body.appendChild($("box_body").childElements()[0]);
	}
	if(box_body)
	{
		$("box_body").appendChild(box_body);
	}
	var popbox=$("popbox");
	popbox.show();
	var left=(document.documentElement.clientWidth-popbox["offsetWidth"])/2;
	var top=(document.documentElement.clientHeight-popbox["offsetHeight"])/2;
	popbox.style.left=document.documentElement.scrollLeft+left+"px";
	popbox.style.top=document.documentElement.scrollTop+top+"px";
}
function show_popbox2(box_title,box_body)
{
	$("box_title").innerHTML=box_title;
    has_showed=false;
    for( i=0;i<body_list.length;i++)
    {alert(body_list[i][0]);
		if(body_list[i][0]==box_body.id)
		{
			box_body.innerHTML= body_list[i][1];
			has_showed=true;
			break;
		}
    }
    if(has_showed==false)
    {
    	body_list[body_list.length]=new Array(box_body.id,box_body.innerHTML);

    }

	$("box_body").appendChild(box_body);
	var popbox=$("popbox");
	popbox.show();
}

//为版主操作的弹出对话框提供快捷函数
function show_operate_form(operate,id)
{
	var box_title="";
	if("top"==operate){
		box_title="置顶";
		$("operate_form").action="/topics/top/"+id;
		$("operate_type").value="1";
	}
	else if("untop"==operate)
	{
		box_title="取消置顶";
		$("operate_form").action="/topics/top/"+id;
		$("operate_type").value="0";
	}
	else if("notice"==operate)
	{
		box_title="高亮";
		$("operate_form").action="/topics/notice/"+id;
		$("operate_type").value="1";
	}
	else if("unnotice"==operate)
	{
		box_title="取消高亮";
		$("operate_form").action="/topics/notice/"+id;
		$("operate_type").value="0";
	}
	else if("recommend"==operate)
	{
		box_title="加精";
		$("operate_form").action="/topics/recommend/"+id;
		$("operate_type").value="1";
	}
	else if("unrecommend"==operate)
	{
		box_title="解除精华";
		$("operate_form").action="/topics/recommend/"+id;
		$("operate_type").value="0";
	}
	else if("close"==operate)
	{
		box_title="关闭";
		$("operate_form").action="/topics/close/"+id;
		$("operate_type").value="1";
	}
	else if("unclose"==operate)
	{
		box_title="重新打开";
		$("operate_form").action="/topics/close/"+id;
		$("operate_type").value="0";
	}
	else if("add_credits"==operate)
	{
		box_title="加分";
		$("operate_form").action="/topics/add_credits/"+id;
		$("operate_type").value="0";
	}
	show_popbox(box_title,$("operate_form"));
}
