// JavaScript Document

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
	document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function f_clear()
{
	form1.content.value = "";
	if (FCKeditorAPI != null)
	{
		var oEditor = FCKeditorAPI.GetInstance('content');
		oEditor.SetHTML('');
	}
}
function f_rep()
{
	document.form1.submit();
}

function validata_form()
{
	try
	{
		validity=true;
		
		var contentlen ;
		if (document.getElementById("x_content").style.display != "none")
		{
			contentlen = document.getElementById("x_content").value;
		}
		else
		{
			if (FCKeditorAPI != null)
			{
				var oEditor = FCKeditorAPI.GetInstance('content');
				contentlen = oEditor.GetXHTML();
			}
		}

		if (contentlen == "" || contentlen.replace(/\s/g, "") == "")
		{
			validity=false;
			alert('请填写回复内容!');
			if (document.form1.content.visible == true)
			{
				document.form1.content.focus();
			}
			return validity;
		}

		if (contentlen.length > 200000)
		{
			validity=false;
			alert('您填写的内容超过系统限定的文件大小');
			if (document.form1.content.visible == true)
			{
				document.form1.content.focus();
			}
			return validity;
		}

//		if (document.form1.username.value == "")
//		{
//			validity=false;
//			alert('请填写你的大名!');
//			document.form1.username.focus();
//			return validity;
//		}

		document.getElementById("huifu").disabled = true;

		return validity;
	}
	catch (ex)
	{
		alert(ex);
		return false;
	}
}
function check_email(address)
{
	if ((address == "")
		|| (address.indexOf ('@') == -1)
		|| (address.indexOf ('.') == -1))
		return false;
	return true;
}

function c_form()
{
	validity=true;

	var len = document.form2.username.value.length - 0;
	if (len <= 0)
	{
		validity=false;
		alert('请输入用户名!');
		document.form2.username.focus();
		return validity;
	}

	len = document.form2.password.value.length - 0;
	if (len <= 0)
	{
		validity=false;
		alert('请输入密码!');
		document.form2.password.focus();
		return validity;
	}
}

function cform()
{
	if(!confirm("您确认删除吗? 请注意删除后无法恢复!"))
		return false;
}

//把指定的图片，按比例缩小到w * h 的范围内
function f_resizeimg(img,w,h)
{
	if(img.width>w || img.height>h)
	{
		var zoomX = 1;
		var zoomY = 1;
		var zoom = 1;
		zoomX = w/img.width;
		zoomY = h/img.height;
		zoom = zoomX < zoomY ? zoomX : zoomY;
		img.width = img.width * zoom;
		img.height = img.height * zoom;
	}
}

//设定最佳回复
function f_bestrep(indexid, pager_rownum, bestrepid)
{
	if (confirm("鲜花只能送给一个回复者，确认要把鲜花送给他/她吗？"))
	{
		document.location = "article_action.php?op=bestrep&indexid=" + indexid + "&pager_rownum=" + pager_rownum + "&bestrepid=" + bestrepid;
	}
	else
		return false;
}

//送楼主鲜花
function f_yfindex_haoping(indexid, pager_rownum)
{
	if (confirm("确认要送花吗？\n\n如果您已经送花，或者您就是作者本人，您的送花将不会成功。"))
	{
		document.location = "article_action.php?op=yfindex_haoping&indexid=" + indexid + "&pager_rownum=" + pager_rownum;
	}
	else
		return false;
}

//推荐帖子
function f_yfindex_recommand(indexid, pager_rownum)
{
	if (confirm("确认要推荐分享该文章吗？\n\n推荐并分享好贴你和楼主将各得1分，胡乱推荐积分将被清零，不能给自己推荐和重复推荐！"))
	{
		document.location = "article_action.php?op=yfindex_recommand&indexid=" + indexid + "&pager_rownum=" + pager_rownum;
	}
	else
		return false;
}

//显示验证码的图片
function f_showauthcode()
{
	var s='<img src="admin/authcode.php?t='+Math.round(Math.random()*1e17)+'" alt="请按此输入验证码" align="absmiddle">';
	document.write(s);
}

//引用某一楼的发言
// floorid  楼层
var timeoutGetMsg = "";
function f_getMsg(floorid, userid, username, dt)
{
	if (parseInt(floorid) <= 0) return;

	try
	{
		if (document.getElementById("x_content").style.display == "none")
		{
			if (FCKeditorAPI != null)
			{
				var oEditor = FCKeditorAPI.GetInstance('content');
				
				var html;
				html  = '<div style="BORDER-RIGHT: #999999 1px dashed; PADDING-RIGHT: 5px; BORDER-TOP: #999999 1px dashed; PADDING-LEFT: 5px; FONT-SIZE: 14px; PADDING-BOTTOM: 0px; MARGIN: 5px; BORDER-LEFT: #999999 1px dashed; PADDING-TOP: 5px; BORDER-BOTTOM: #999999 1px dashed; BACKGROUND-COLOR: #f2f8ff">';
				html += '<p style="MARGIN-BOTTOM: 5px; PADDING-BOTTOM: 5px; BORDER-BOTTOM: #999999 1px dashed">引用第' + floorid + '楼&nbsp;<span class="linkGreen"><a href="user.php?userid=' + userid + '">' + username + '</a>&nbsp;于&nbsp;' + dt + '</span></p>';
				html += '<p>' + document.getElementById('content_'+floorid).innerHTML + '</p>';
				html += '</div>';
				oEditor.InsertHtml(html);//添加html
				
				oEditor.Focus();//添加html
				
				//添加被引用文字的发言人
				var f = document.getElementById("x_quote_userid");
				f.value += " " + userid;

				timeoutGetMsg = "";
			}
		}
		else
		{
			f_chrep(); //切换回帖的输入模式
			timeoutGetMsg = "f_getMsg('"+floorid+"', '"+userid+"', '"+username+"', '"+dt+"')";
			return;
		}
	}
	catch (ex)	{return;}
	window.scrollTo(0, 100000);
}

function loadScript(url, callback)
{
	var script = document.createElement('script');
	script.type = 'text/javascript';
	if (callback)
	script.onload = script.onreadystatechange = function() {
		if (script.readyState && script.readyState != 'loaded' && script.readyState != 'complete')
			return;
		script.onreadystatechange = script.onload = null;
		callback();
	};
	script.src = url;
	document.getElementsByTagName('head')[0].appendChild (script);
}

//投票贴---投票
function f_votes_chk()
{
	//取得选中的id
	var o=document.getElementsByName('polloptionid[]');
	var idlist = new Array();
	for(i=0;i<o.length;i++)
	{
		if (o[i].checked)
		{
			idlist[idlist.length] = o[i].value;
		}
	}
	if (idlist.length <= 0)
	{
		alert("请选择需要投票的项目!");
		return false;
	}

	//如果是多项选择投票
	if (idlist.length > 1)
	{
		var maxchoices = parseInt(document.getElementById("maxchoices").value);
		if (idlist.length > maxchoices)
		{
			alert("最多可选择 " + maxchoices + " 项投票，您现在选择了 " + idlist.length + " 项");
			return false;
		}
	}
	return false;

	return true;
}

//切换回复框的输入模式
function f_chrep()
{
	if (document.getElementById("x_content").style.display != "none")
	{
		var sBasePath = './FCKeditor/';
		var oFCKeditor = new FCKeditor('content','100%','400','','');
		oFCKeditor.BasePath	= sBasePath;
		oFCKeditor.ReplaceTextarea();
		oFCKeditor.onLoad = "abc";

		document.getElementById("x_inputtype").value = "html";

		return oFCKeditor;
	}
}

//FCK读入完成提示函数
function FCKeditor_OnComplete( editorInstance )
{
    if (timeoutGetMsg != "")    {		setTimeout(timeoutGetMsg, 0);    }
}