
//==================================
// 论坛导航栏
var bbsnavbuttons = new Array(
	new Array('首页',  '/Forum/'),
	new Array('登录',  '/Login.aspx?ReturnUrl=/Forum'),
	new Array('注册',  '/Home/Service/UserRegiste.aspx'),
	new Array('搜索',  '/Forum/Search.aspx'),
	new Array('短消息',  '/Forum/ShortMessage.aspx'),
	new Array('控制面板',  '/Forum/UserSettings.aspx'),
	new Array('退出', '/Logout.aspx?ReturnUrl=/Forum' )//,
	//new Array('帮助',  '/Forum/Help.aspx' )
	);
	
// 创建导航
// ismember 是会员
// newsm 有新短消息
function createNavBar( ismember, newsm )
{
	var bar = document.getElementById("navBar");
	bar.style.paddingTop = "4px";
	
	for( var i = 0; i < bbsnavbuttons.length; i++ )
	{
		if( ismember.toLowerCase() == "true" )
		{
			if( i==2 ){ continue; }
		}
		else
		{
			if(i==6){ continue; }
		}
		var span = document.createElement("span");
		var t = "";
		if( i == 4 && newsm > 0 )
		{
			t += "<img src='/icon/newsm.gif' align='absmiddle' hspace='4' alt='有"+ newsm +"条新短消息'>";
		}
		t += "&nbsp;<a href='" + bbsnavbuttons[i][1] + "'>" + bbsnavbuttons[i][0] + "</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
		
		span.innerHTML = t;
		bar.appendChild(span);
	}
}

//
// 发布主题按钮 2007-11-11 20:14
//=====================================
// barId 容器路径
// boardId 版面编号
// imgPath 图片路径
function createPostButtonHtml( barId, boardId, imgPath )
{
	var bar = document.getElementById( barId );
	if( !bar ){ return; }
	
	// 发布按钮
	var newtopic = document.createElement("img");
	newtopic.setAttribute( "src", imgPath + "newTopic_Button1.gif" );
	newtopic.setAttribute( "border", "0" );
	newtopic.setAttribute( "hspace", "4" );
	newtopic.onmouseover = function()
	{
		newtopic.setAttribute( "src", imgPath + "newTopic_Button2.gif" );
	}
	newtopic.onmouseout = function()
	{
		newtopic.setAttribute( "src", imgPath + "newTopic_Button1.gif" );
	}
	var topiclink = document.createElement("a");
	topiclink.setAttribute("href", "NewTopic.aspx?BoardID=" + boardId);
	topiclink.appendChild( newtopic );
	
	bar.appendChild( topiclink );
	
	// 投票按钮
	var newvote = document.createElement("img");
	newvote.setAttribute( "src", imgPath + "newVote_Button1.gif" );
	newvote.setAttribute( "border", "0" );
	newvote.setAttribute( "hspace", "4" );
	newvote.onmouseover = function()
	{
		newvote.setAttribute( "src", imgPath + "newVote_Button2.gif" );
	}
	newvote.onmouseout = function()
	{
		newvote.setAttribute( "src", imgPath + "newVote_Button1.gif" );
	}
	var votelink = document.createElement("a");
	votelink.setAttribute("href", "NewVote.aspx?BoardID=" + boardId);
	votelink.appendChild( newvote );
	
	bar.appendChild( votelink );
	
}

// 主题列表  翻页尾巴 (2007-11-10 11:04)
//=================================
// 页号是从最后一页开始显示的
// barid 容器编号
// boardid	版面编号
// topicid	主题编号
// index 当前索引(倒显示)
// sz 尾巴上显示页连接的数量
// max	最大页号
// next 向后
function topicTailPager( barid, boardid, topicid, sz, index, max, next )
{
	var showPre = true;
	var first;

	if( next == 0 )	// 向前( 往回翻页 )
	{	
		index ++;
		if( index <= 0 ){ index = 1;}	// 因为已经是第一页所以要先驱动一下
	}
	else	// 向后
	{
		index --;
	}
	first =  max - (index+1) * sz;	// 下一篇的尾页号
	first = first + (index+1);	// 偏移(向后1位)补偿
	
	if( first <= 0 || first == 1 )
	{
		showPre = false;
		first = 1;
	}
	var len = first + sz;
	//alert( index+"\r\nlen:"+ len + "\r\nfirst:" + first);
	var bar = document.getElementById(barid);
	bar.innerHTML = "";
	
	// pre button
	if( showPre )
	{
		var js = "topicTailPager('"+ barid +"',"+ boardid +","+ topicid +","+ sz +","+ index +","+ max +", 0)";
		var pre = document.createElement("font");
		pre.innerHTML = "<font face=webdings>3</font>";
		pre.style.fontSize = "12px";
		pre.style.cursor = "hand";
		pre.onclick = new Function( js );
		bar.appendChild( pre );
	}
	
	for( var i = first; i < len; i ++ )
	{
		var a = document.createElement("a");
		a.href = "/Forum/ShowTopic.aspx?BoardID="+boardid+"&TopicID="+topicid+"&Page="+i;
		a.innerText = i;
		bar.appendChild( a );
		
		if ( i < len - 1 )
		{
			var s = document.createElement("font");
			s.innerText = " ";
			bar.appendChild( s );
		}
	}

	// next button
	if( index > 0 )
	{
		var js2 = "topicTailPager('"+ barid +"',"+ boardid +","+ topicid +","+ sz +","+ index +","+ max +", 1)";
		var nex = document.createElement("font");
		nex.innerHTML = "<font face=webdings>4</font>";
		nex.style.cursor = "hand";
		nex.style.fontSize = "12px";
		nex.onclick = new Function( js2 );
		bar.appendChild( nex );
	}
}
//========================================
//
// 短消息选择
function msgSelectAll( span, smId )
{
	var all = true;
	var boxs = document.getElementsByTagName( "input" );

	for( var i =0; i < boxs.length; i++ )
	{
		if( boxs[i].id == smId )
		{
			if( !boxs[i].checked )
			{
				all = false;
				break;
			}
		}
	}
	
	var c = true;
	var h = "清除";
	if( all )
	{
		c = false;
		h = "全选";
	}
	
	for( var i =0; i < boxs.length; i++ )
		{
			if( boxs[i].id == smId )
			{
				boxs[i].checked = c;
			}
		}
	span.innerHTML = h;
}
///////////////////////////////////////////
// 头像 Head Pick (2007-11-16 11:02) 
///////////////////////////////////////////
//初始化头像
// barId 容器ID
// folder 头像文件夹
// total 文件数量
// default 默认头像
// enable 是否开启头像使用
function initHead( barId, folder, total, defaultHead, enable )
{
	var bar = document.getElementById( barId );
	if( !bar ){ return; }
	
	// img
	var img = document.createElement("img");
	img.setAttribute( "src", folder + "1000.jpg" );
	img.className = "imgFrame";
	if( enable == 1 )
	{
		img.style.cursor = "hand";
		img.setAttribute( "alt", "点击选定" );
	}
	bar.appendChild( img );
	
	// select
	var select = document.createElement("select");
	select.style.bottom = "4px";
	select.style.left = "8px";
	select.style.position = "relative";
	var max = 1000 + total;
	for( var i = 1000; i < max; i++ )
	{
		var op = document.createElement("option");
		op.text = i;
		op.value = i + ".jpg";
		select.options.add( op );
	}
	select.onchange = function()
	{
		img.setAttribute( "src", folder + select.value );
	}
	bar.appendChild( select );
	
	// 设置默认值
	if( defaultHead != "" )
	{
		if( defaultHead.indexOf("~") == 0 )
		{
			select.value = defaultHead.substring( 1 );
			img.setAttribute( "src", folder + select.value );
		}
	}
	
	// 用于在box未启用的时候存储图片路径
	var hid = null;
	
	// 图片事件
	img.onclick = function()
	{
		if( enable == 0 ){ return; }
		var boxs = bar.getElementsByTagName("input");
		if( boxs.length > 0 )
		{
			boxs[0].value = "~" + select.value;
			if( boxs.disabled = "disabled" )
			{
				if( hid == null )
				{
					hid = document.createElement("input");
					hid.type = "hidden";
					hid.id = barId + "value";
					hid.name = barId + "value";
					bar.appendChild( hid );
				}
				hid.value = boxs[0].value;
			}
		}
	}
}

function gotoBoard(ddl)
{
	var url = "/Forum/ShowBoard.aspx?ID=" + ddl.value;
	location.href = url;
}

//-----------------------------------------------
// 预览

function goPreview()
{
	glb_Privew = true;	
}