// 空格剔除
function KillSpace(x)
{
	while((x.length>0) && (x.charAt(0)==' '))
		x = x.substring(1,x.length)
	while((x.length>0) && (x.charAt(x.length-1)==' '))
		x = x.substring(0,x.length-1)
	return x
}
// 发帖校验
function checkpostarticle()
{
	fdTitleSize=document.pmform.fdTitleSize.value;
	fdContentSize=document.pmform.fdContentSize.value;
	fdTitile=KillSpace(document.pmform.fdTitle.value);
	fdContent=KillSpace(document.pmform.fdContent.value);
	if((fdTitile=='')||(fdContent==''))
	{
		alert("文章标题、内容不能够为空");
		return false;
	}
	else if((fdTitleSize<document.pmform.fdTitle.value.length)||(fdContentSize<document.pmform.fdContent.value.length))
	{
		alert("文章标题或内容超过最大字符串");
		return false;
	}
		else return true;
		
	
}

// 回帖校验
function checkpostreply()
{
	fdContentSize=document.pmform.fdContentSize.value;
	fdContent=KillSpace(document.pmform.fdContent.value);
	if(fdContent=='')
	{
		alert("文章内容不能够为空");
		return false;
	}
	else if(fdContentSize<document.pmform.fdContentSize.value.length)
	{
		alert("文章内容超过最大字符串");
		return false;
	}
	else return true;
}

// 弹出新窗口
function MM_openBrWindow(theURL,winName,features)
{ 
	  window.open(theURL,winName,features);
}

function BarMove(barPosition){
	if(document.all(barPosition).style.display=="none")
	{
		document.all(barPosition).style.display=""
	}
	else
	{
		document.all(barPosition).style.display="none"
	}
}

function check_page(){
	if(((document.change_page.intGotoPage.value*1)>(document.change_page.intMaxPage.value*1))||((document.change_page.intGotoPage.value*1)<1)){
		var intMaxPage=document.change_page.intMaxPage.value;
		var message="已经到达最后一页";
		alert(message);//
		return false;
	}else{
		return true;
	}
}

// 文章检索表单检查
function checksearch() {
    if (document.searchform.searchkey.value.length<2) {
		alert("检索关键字长度不得少于两个字符"); return false;
    } else {
	    return true;
	}
}
//vb选项
// *******************************************************

tags = new Array();

// *******************************************************
// replacements for unsupported array functions (because arrayname.push(var)
// and arrayname.pop() are not implemented in IE until version 5.5)

function getarraysize(thearray) {
// replacement for arrayname.length property
	for (i = 0; i < thearray.length; i++) {
		if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
			return i;
		}
	return thearray.length;
}

function arraypush(thearray,value) {
// replacement for arrayname.push(value)
	thearraysize = getarraysize(thearray);
	thearray[thearraysize] = value;
}

function arraypop(thearray) {
// replacement for arrayname.pop()
	thearraysize = getarraysize(thearray);
	retval = thearray[thearraysize - 1];
	delete thearray[thearraysize - 1];
	return retval;
}

// *******************************************************

function setmode(modevalue) {
// sets cookie for normal (0) and enhanced (1) modes
	document.cookie = "vbcodemode="+modevalue+"; path=/; expires=Wed, 1 Jan 2020 00:00:00 GMT;";
}

function normalmode(pmform) {
// checks value of mode radio buttons. returns true if normal mode
	if (pmform.mode[0].checked) return true;
	else return false;
}

function stat(thevalue) {
// places mini-help text into help/error textbox
// strings are stored in vbcode_language.js
	document.pmform.status.value = eval(thevalue+"_text");
}

// *******************************************************

function closetag(pmform) {
// closes last opened tag
	if (normalmode(pmform))
		stat('enhanced_only');
	else
		if (tags[0]) {
			pmform.fdContent.value += "[/"+ arraypop(tags) +"]";
			}
		else {
			stat('no_tags');
			}
	//pmform.closecurrent.checked=false;
	pmform.fdContent.focus();
}

function closeall(pmform) {
// closes all open tags
	if (normalmode(pmform))
		stat('enhanced_only');
	else {
		if (tags[0]) {
			while (tags[0]) {
				pmform.fdContent.value += "[/"+ arraypop(tags) +"]";
				}
			pmform.fdContent.value += " ";
			}
		else {
			stat('no_tags');
			}
		}
	//pmform.closealltags.checked=false;
	pmform.fdContent.focus();
}

// *******************************************************

function vbcode(pmform,vbcode,prompttext) {
// insert [x]yyy[/x] style markup
	if ((normalmode(pmform)) || (vbcode=="IMG")) {
		inserttext = prompt(tag_prompt+"\n["+vbcode+"]xxx[/"+vbcode+"]",prompttext);
		if ((inserttext != null) && (inserttext != ""))
			pmform.fdContent.value += "["+vbcode+"]"+inserttext+"[/"+vbcode+"] ";
		}
	else {
		donotinsert = false;
		for (i = 0; i < tags.length; i++) {
			if (tags[i] == vbcode)
				donotinsert = true;
			}
		if (donotinsert)
			stat("already_open");
		else {
			pmform.fdContent.value += "["+vbcode+"]";
			arraypush(tags,vbcode);
			}
		}
	pmform.fdContent.focus();
}

// *******************************************************

function fontformat(pmform,thevalue,thetype) {
// insert two-parameter markup - [x=y]zzz[/x]
	if (normalmode(pmform)) {
		if (thevalue != 0) {
			inserttext = prompt(font_formatter_prompt+" "+thetype,"");
			if ((inserttext != null) && (inserttext != ""))
				pmform.fdContent.value += "["+thetype+"="+thevalue+"]"+inserttext+"[/"+thetype+"] ";
			}
		}
	else {
		pmform.fdContent.value += "["+thetype+"="+thevalue+"]";
		arraypush(tags,thetype);
		}
	pmform.sizeselect.selectedIndex = 0;
	pmform.fontselect.selectedIndex = 0;
	pmform.colorselect.selectedIndex = 0;
	pmform.fdContent.focus();
}

// *******************************************************

function namedlink(pmform,thetype) {
// inserts named url or email link - [url=mylink]text[/url]
	linktext = prompt(link_text_prompt,"");
		var prompttext;
		if (thetype == "URL") {
			prompt_text = link_url_prompt;
			prompt_contents = "http://";
			}
		else {
			prompt_text = link_email_prompt;
			prompt_contents = "";
			}
	linkurl = prompt(prompt_text,prompt_contents);
	if ((linkurl != null) && (linkurl != "")) {
		if ((linktext != null) && (linktext != ""))
			pmform.fdContent.value += "["+thetype+"="+linkurl+"]"+linktext+"[/"+thetype+"] ";
		else
			pmform.fdContent.value += "["+thetype+"]"+linkurl+"[/"+thetype+"] ";
		}
	pmform.fdContent.focus();
}

// *******************************************************

function dolist(pmform) {
// inserts list with option to have numbered or alphabetical type
	listtype = prompt(list_type_prompt, "");
	if ((listtype == "a") || (listtype == "1")) {
		thelist = "[list="+listtype+"]\n";
		listend = "[/list="+listtype+"] ";
		}
	else {
		thelist = "[list]\n";
		listend = "[/list] ";
		}
	listentry = "initial";
	while ((listentry != "") && (listentry != null)) {
		listentry = prompt(list_item_prompt, "");
		if ((listentry != "") && (listentry != null))
			thelist = thelist+"[*]"+listentry+"\n";
		}
	pmform.fdContent.value += thelist+listend;
	pmform.fdContent.focus();
}

// *******************************************************

function smilie(thesmilie) {
// inserts smilie text
	document.pmform.fdContent.value += thesmilie+" ";
	document.pmform.fdContent.focus();
}

function opensmiliewindow(x,y,sessionhash) {
// um... opens smilie overflow window.
		window.open("misc.php?action=getsmilies&s"+sessionhash, "smilies", "toolbar=no,scrollbars=yes,resizable=yes,width="+x+",height="+y);
}
// the following are the text prompts for buttons etc.
// DO NOT ADD LINE-BREAKS BETWEEN THE "...." QUOTES!

// MINI-HELP fdContentS

b_text = "文本加粗";  // "Insert BOLD text"
i_text = "文本变斜体";  // "Insert ITALIC text"
u_text = "文本加入下画线";  // "Insert UNDERLINED text"

size_text = "改变文本的大小"; // "Alter the SIZE of your text"
font_text = "改变文本的字体"; // "Alter the FONT of your text"
color_text = "改变文本的颜色"; // "Alter the COLOR of your text"

url_text = "在内容中插入超级链接"; // "Insert a hyperlink into your fdContent"
email_text = "在内容中插入email地址"; // "Insert an email-link into your fdContent"
img_text = "在内容中插入图象"; // "Insert an image into your fdContent"

code_text = "在内容中插入代码"; // "Insert monospace text into your fdContent"
php_text = "在内容中插入PHP代码"; // "Insert text with PHP syntax highlighting"
list_text = "在内容中插入顺序列表"; // "Insert an ordered list into your fdContent"
quote_text = "在内容中插入引用"; // "Insert a quote into your fdContent"

norm_text = "普通代码模式"; // "Switch to normal code-editing mode"
enha_text = "高级代码模式"; // "Enhanced mode: allows complex nesting of tags"

closecurrent_text = "关闭当前标签"; // "Close the current vBcode tag"
closeall_text = "关闭所有标签"; // "Close all open vBcode tags"

// ERROR fdContentS

enhanced_only_text = "<< 只能在高级代码模式中起作用 >>"; // "<< This is only available in Enhanced Mode >>"
no_tags_text = "没有发现打开的VB代码标签"; // "<< No open vBcode tags detected. >>"
already_open_text = "您已经打开了该类型的一个标签"; // "<< You already have an open tag of this type >>"

// TEXT FOR POP-UP PROMPTS

tag_prompt = "请输入内容进行格式定义:"; // "Enter the text to be formatted:"

font_formatter_prompt = "请输入内容进行格式定义"; // "Enter the text to be formatted with the specified"

link_text_prompt = "请输入需要链接的内容"; // "Enter the text to be displayed for the link (optional)"
link_url_prompt = "请输入完成路径"; // "Enter the full URL for the link"
link_email_prompt = "请输入EMAIL地址链接"; // "Enter the email address for the link"

list_type_prompt = "您需要什么类型的列表？ 输入1按数字列表，输入a按字母列表，不输入表示按照默认状态"; // "What type of list do you want? Enter '1' for a numbered list, enter 'a' for an alphabetical list, or leave blank for a list with bullet points.";
list_item_prompt = "请输入列表项，按'Cancel'结束"; // "Enter a list item.\nLeave the box empty or press 'Cancel' to complete the list.";