function post_form_checkdata(theform)
{
	if (theform.BoardIDBox.value == "" || theform.BoardIDBox.value == "0")
	{
		alert("请选择话题类别！");
		theform.BoardIDBox.focus();
		return false;
	}
	if (theform.TopicTitleBox.value.replace(/\s/gi,'') == "")
	{
		alert("请输入标题！");
		theform.TopicTitleBox.focus();
		return false;
	}
	var s = edit_mode ? "" : edt_htm2code(htmldoc.body.innerHTML);
	if (s.replace(/\s/gi,'') == "")
	{
		alert("请输入内容！");
		return false;
	}
	else
	{
		theform.TopicContent.value = s;
	}
	if (theform.SFlag.value.replace(/\s/gi,'') == "")
	{
		alert("本网站启用了身份认证，请在页面加载完后再发表，若仍然出现此问题，请与网站客服或管理员联系！");
		return false;
	}
	theform.submit_button.disabled = true;
	return true;
}

function create_PostFlag(formName)
{
	var theform = CheckObject(formName);
	if (!theform) return;
	var obj1 = theform.SFlag;
	var obj2 = theform.TopicIDBox;
	obj1.value = "";
	if (!obj2) return;
	var xmlhttp = CreateXmlHttpObj();
	if (CheckXML(xmlhttp))
	{
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200) 
				{
					var strResult = xmlhttp.responseText;
					if (strResult != "")
					{
						obj1.value = strResult;
					}
				}				
			}
		}
		xmlhttp.open("GET", "/inc/CreateFlag.aspx?ID=BBS&IDH=" + obj2.value, true);
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.setRequestHeader("Content-Type","text/html")
		xmlhttp.send(null);
	}
}

var rowid = 1;
var rowcount = "1";
function addContent1()
{
	rowid++;
	rowcount = rowcount + "," + rowid.toString();
	document.getElementById("filecount").value = rowcount;
	var table = document.getElementById("contentTable");
	var tr = document.getElementById("textTR");
	var td = document.getElementById("textTD");
	var row,cell;
	td.rowSpan += 1;
	var rowscount = table.rows.length;
	row = table.insertRow(rowscount);
	row.style.backgroundColor = "#FFFFFF";
	row.id = "texttr1_" + rowid;
	cell = row.insertCell(0);
	cell.innerHTML = "&nbsp;<INPUT id=\"TopicAddText" + rowid + "\" type=\"text\" size=\"20\" maxlength=\"240\" name=\"TopicAddText\">&nbsp;<input type=\"file\" id=\"TopicAddPath" + rowid + "\" name=\"TopicAddPath\" size=\"50\" onchange=\"reset_name(this, " + rowid + ")\">&nbsp;<input type=button onclick='deleteContent(" + rowid + ")' value=' 删除本图 '>";
}
function addContent2()
{
	rowid++;
	rowcount = rowcount + "," + rowid.toString();
	document.getElementById("filecount").value = rowcount;
	var table = document.getElementById("contentTable");
	var tr = document.getElementById("textTR");
	var td = document.getElementById("textTD");
	var row,cell;
	td.rowSpan += 1;
	var rowscount = table.rows.length;
	row = table.insertRow(rowscount);
	row.style.backgroundColor = "#FFFFFF";
	row.id = "texttr1_" + rowid;
	cell = row.insertCell(0);
	cell.innerHTML = "&nbsp;<INPUT id=\"TopicLinkText" + rowid + "\" type=\"text\" size=\"20\" maxlength=\"240\" name=\"TopicLinkText\">&nbsp;<input type=\"text\" id=\"TopicLinkPath" + rowid + "\" name=\"TopicLinkPath\" size=\"60\" onchange=\"size_ok(this, " + rowid + ")\"><font size=1>&nbsp;&nbsp;</font><input type=button onclick='deleteContent(" + rowid + ")' value=' 删除本图 '>";
}

function deleteContent(id)
{
	rowcount = ("," + rowcount + ",").replace("," + id + ",",",");
	rowcount = rowcount.substring(1,rowcount.length - 1);
	document.getElementById("filecount").value = rowcount;
	var table = document.getElementById("contentTable");
	var td = document.getElementById("textTD");
	td.rowSpan -= 1;
	table.rows("texttr1_" + id).removeNode(true);
}

function reset_name(o, i)
{
	var obj = CheckObject("TopicAddText" + i);
	if (!obj) return;
	var strpath = "";
	if (window.navigator.userAgent.indexOf("MSIE")>=1)
	{
		o.select();
		strpath = document.selection.createRange().text;
	}
	else if (window.navigator.userAgent.indexOf("Firefox")>=1)
	{
		if(o.files)
		{
			strpath = o.files.item(0).getAsDataURL();
		}
	}  
	if (strpath != "" && (obj.value == "" || obj.value == "图片说明"))
	{
		if (i == 1)
		{
			obj.value = "";
		}
		else
		{
			var filename = strpath;
			var iindex = filename.lastIndexOf("\\") + 1;
			var jindex = filename.lastIndexOf(".");
			if (jindex > iindex)
			{
				filename = filename.substr(iindex, jindex - iindex);
			}
			obj.value = filename;
			var imgobj = CheckObject("sl_img");
			if (imgobj)
			{
				var strValue = strpath.substring(strpath.lastIndexOf(".") + 1,strpath.length).toLowerCase();
				var strFilter = ",jpg,jpeg,gif,png,bmp,";
				if (strFilter.indexOf(strValue) > 0)
				{
					var img = new Image();
					try
					{
						img.src = strpath;
						var imgw = img.width;
						var imgh = img.height;
						imgobj.src = "";
						imgobj.src = strpath;
						imgobj.width = 50;
						imgobj.height = 50;
						imgobj.style.display = "";
					}
					catch(e)
					{
						obj.value = "";
						imgobj.src = "";
						imgobj.style.display = "none";
					}
				}
			}
		}
	}
}

function size_ok(obj, i)
{
	var b = true;
	if (obj.value != "")
	{
		var img = new Image();
		img.src = obj.value;
		var w = img.width;
		var h = img.height;
		if (w > 920 || h > 920)
		{
			b = false;
			alert("图片太大，请处理后再添加！");
			obj.value = "";
		}
		else
		{
			var imgobj = CheckObject("sl_img");
			if (imgobj)
			{
				imgobj.src = "";
				imgobj.src = obj.value;
				imgobj.width = 50;
				imgobj.height = 50;
				imgobj.style.display = "";
			}
			else
			{
				imgobj.src = "";
				imgobj.style.display = "none";
			}
		}
	}
	return b;
}

function IsPost(formname, istyle)
{
	var theform = CheckObject(formname);
	if (!theform) return;
	if (event.ctrlKey && event.keyCode == 13)
	{
		if (post_form_checkdata(theform))
		{
			theform.submit();
		}
	}
}

function Post_Login()
{
	var aLayer = CheckObject("newwindowlayer");
	if (!aLayer)
	{
		aLayer = document.createElement("<div id=\"newwindowlayer\"></div>");
		document.body.appendChild(aLayer);
	}
	var bLayer = CheckObject("newwindow_content_layer");
	if (!bLayer)
	{
		bLayer = document.createElement("<div id=\"newwindow_content_layer\"></div>");
		document.body.appendChild(bLayer);
	}
	var cLayer = CheckObject("newwindow_loading_layer");
	if (!cLayer)
	{
		cLayer = document.createElement("<div id=\"newwindow_loading_layer\"></div>");
		document.body.appendChild(cLayer);
	}
	openNewWindowLayer("用户登录", 260, 150);
	setUserLoginContent(2);
	var UserLoginForm = CheckObject("UserLoginForm");
	if (!UserLoginForm) return;
	UserLoginForm.UserName.focus();
}

function Update_UserNameBox()
{
	var obj = CheckObject("UserNameBox");
	if (!obj) return false;
	if (Public_User_Object != null && Public_User_Object.UserID > 0)
	{
		obj.value = Public_User_Object.NiceName;
	}
}

function ListBoard(boardid)
{
	var obj = CheckObject("board_list");
	if (!obj) return;
	var xmlhttp = CreateXmlHttpObj();
	if (CheckXML(xmlhttp))
	{
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200) 
				{
					var strResult = xmlhttp.responseText;
					if (strResult != "")
					{
						obj.innerHTML = strResult;
					}
				}				
			}
		}
		xmlhttp.open("GET", "/inc/BBS_BoardList.aspx?BoardID=" + boardid, true);
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.setRequestHeader("Content-Type","text/html")
		xmlhttp.send(null);
	}
}

function create_PostName(formName)
{
	var theform = CheckObject(formName);
	if (!theform) return;
	var xmlhttp = CreateXmlHttpObj();
	if (CheckXML(xmlhttp))
	{
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200) 
				{
					var strResult = xmlhttp.responseText;
					if (strResult != "")
					{
						theform.UserNameBox.value = strResult;
					}
				}				
			}
		}
		xmlhttp.open("GET", "/inc/BBS_GetDefaultName.aspx", true);
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.setRequestHeader("Content-Type","text/html")
		xmlhttp.send(null);
	}
}

function show_item(obj, i)
{
	for (var j = 1;j<= 4 ;j++ )
	{
		if (j != i)
		{
			var o1 = CheckObject("m_" + j);
			o1.className = "items m_" + j + "_1";
			var o2 = CheckObject("c_" + j);
			o2.style.display = "none";
			o2.style.position = "absolute";
		}
	}
	obj.className = "items m_" + i + "_2";
	var o0 = CheckObject("c_" + i);
	o0.style.display = "";
	o0.style.position = "absolute";
}

var userpointarray = new Array();
var userpointarrayindex = 0;
function cls_userpoint(userid, username, nicename, userpoint)
{
	this.UserID = userid;
	this.UserName = username;
	this.NiceName = nicename;
	this.UserPoint = userpoint;
}
function UserPoint_List(objname, pagesize)
{
	var xmlhttp = CreateXmlHttpObj();
	if (CheckXML(xmlhttp))
	{
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4)
			{
				if (xmlhttp.status == 200) 
				{
					var strResult = xmlhttp.responseText;
					if (strResult != "")
					{
						eval(strResult);
						List_UserPoint(objname);
					}
				}				
			}
		}
		xmlhttp.open("GET", "/inc/User_PointRank.aspx?PageSize=" + pagesize, true);
		xmlhttp.setRequestHeader("If-Modified-Since","0");
		xmlhttp.setRequestHeader("Content-Type","text/html")
		xmlhttp.send(null);
	}
}
function List_UserPoint(objname)
{
	var obj = CheckObject(objname);
	if (!obj) return;
	var strBody = "";
	for (var i=0;i<userpointarray.length ;i++ )
	{
		strBody += "<div style=\"float: left\" class=\"list_td\"><li class=\"l_1\"><font class=\"entxt f11\">" + (i + 1) + ".</font>&nbsp;<a href=\"http://user.ly234.com/userindex.aspx?UserID=" + userpointarray[i].UserID + "\" target=\"_blank\">" + userpointarray[i].NiceName + "</a></li><li class=\"l_2\">" + userpointarray[i].UserPoint + "</li></div>";
	}
	obj.innerHTML = strBody;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function fSetBorderMouseOver(obj) {
	obj.style.borderRight = "1px solid #aaa";
	obj.style.borderBottom = "1px solid #aaa";
	obj.style.borderTop = "1px solid #fff";
	obj.style.borderLeft = "1px solid #fff";
	obj.style.cursor = "hand";
}

function fSetBorderMouseOut(obj) {
	obj.style.border = "none";
}

function fSetBorderMouseDown(obj) {
	obj.style.borderRight="1px #F3F8FC solid";
	obj.style.borderBottom="1px #F3F8FC solid";
	obj.style.borderTop="1px #cccccc solid";
	obj.style.borderLeft="1px #cccccc solid";
}

var array_editflag = new Array();
function editflag_item(aid, tid, bedit)
{
	this.AnnounceID = aid;
	this.TopicID = tid;
	this.BEdit = bedit;
}

function topic_load()
{
	create_EditFlag();
	resize_pic();
	fillQQService("scroll_online_layer");
}


function resize_pic()
{
	var objs = document.getElementsByTagName("img");
	for (var i=0;i<objs.length ;i++ )
	{
		var strsrc = objs[i].src.toLowerCase();
		if (strsrc.indexOf("uploadfile/post/") > 0)
		{
			var pwidth = objs[i].width;
			var pheight = objs[i].height;
			if (pwidth > 810)
			{
				objs[i].width = 810;
			}
		}
	}
}

function create_EditFlag()
{
	var objs = document.getElementsByTagName("div");
	var strannounceid = "";
	for (var i=0;i<objs.length ;i++ )
	{
		var objid = objs[i].id;
		if (objid.length > 13 && objid.substr(0, 13) == "editor_layer_")
		{
			strannounceid += (strannounceid == "" ? "" : ",") + objid.substr(13);
		}
	}
	if (strannounceid != "")
	{
		var xmlhttp = CreateXmlHttpObj();
		if (CheckXML(xmlhttp))
		{
			xmlhttp.onreadystatechange = function()
			{
				if (xmlhttp.readyState == 4)
				{
					if (xmlhttp.status == 200) 
					{
						var strResult = xmlhttp.responseText;
						if (strResult != "")
						{
							eval(strResult);
							reset_EditFlag();
						}
					}
				}				
			}
			xmlhttp.open("GET", "/inc/User_PostEdit.aspx?AnnounceID=" + strannounceid, true);
			xmlhttp.setRequestHeader("If-Modified-Since","0");
			xmlhttp.setRequestHeader("Content-Type","text/html")
			xmlhttp.send(null);
		}
	}
}

function reset_EditFlag()
{
	if (array_editflag.length > 0)
	{
		for (var i=0;i<array_editflag.length ;i++ )
		{
			if (array_editflag[i].BEdit)
			{
				var obj = CheckObject("editor_layer_" + array_editflag[i].AnnounceID);
				if (!obj)
				{
					obj = CheckObject("editor_layer_" + array_editflag[i].TopicID);
					if (obj)
					{
						obj.innerHTML += "　<a href=\"../EditTopic.aspx?ID=" + array_editflag[i].AnnounceID + "\">编辑此贴</a>";
					}
				}
				else
				{
					obj.innerHTML += "　<a href=\"../EditTopic.aspx?ID=" + array_editflag[i].AnnounceID + "\">编辑此贴</a>";
				}
			}
		}
	}
}
