/*
	----------- Common Utility Scripts ------------

		author : satellite
		date   : 2005-9-15
		all right reserved 2007 dvbbs.net

	-----------------------------------------------
*/



/* ----------- 以下几个仅用于论坛 ------------------------- */


//Board Jump
function boardJump(obj)
{
	var selectedValue = obj.options[obj.selectedIndex].value;
	if (selectedValue.indexOf(',') != -1 || selectedValue == -1)
	{
		obj.options[0].selected = true;
		return;
	}
	location.href = 'board.aspx?boardid=' + selectedValue;
}


function setCookie(name,value)
{
	var Days = 30; //此 cookie 将被保存 30 天
	var exp = new Date(); //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
}
function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}
//Collapse Or Expand Tablebody
function collapse(img, objName)
{
	
	var cateid = objName.replace("cate","");
	var cateids= getCookie("closedcateids");
	if(cateids == null)
		cateids = "";
//	alert(cateids);
	//specially, invoke another function. (topic.aspx)
	if (objName == 'loopedreplies')
	{
		collapseTables(img);
		return;
	}

	var obj = document.getElementById(objName);
/*	var min = 0;
	var max = obj.rows.length;

	if (obj.rows[0].className.toLowerCase() == 'category' || obj.rows[0].cells[0].className.toLowerCase() == 'category')
	{
		min++;
	}
	if (obj.rows[max-1].id == 'pagerrow')
	{
		max--;
	}
*/
	if (img.src.indexOf('open') != -1)
	{
		/*if (document.all && max != obj.rows.length)
		{
			obj.border = 0;
		}
		img.src = img.src.replace('open', 'close');
		for (var i=min; i<max; i++)
		{
			if (obj.rows[i].getAttribute('alwaysdisplay') == 1) continue;
			obj.rows[i].style.display = 'none';
		}*/
		obj.style.display = 'none';
		img.src = img.src.replace('open', 'close');
		//write cate id to cookie 
		setCookie("closedcateids",cateids.replace("[" + cateid + "]", "") + "[" + cateid + "]");
		
	}
	else
	{/*
		if (document.all && max != obj.rows.length)
		{
			obj.border = 1;
		}
		img.src = img.src.replace('close', 'open');
		for (var i=min; i<max; i++)
		{
			if (obj.rows[i].getAttribute('alwaysdisplay') == 1) continue;
			obj.rows[i].style.display = '';
		}*/
		obj.style.display = '';
		img.src = img.src.replace('close', 'open');
		setCookie("closedcateids",cateids.replace("[" + cateid + "]", ""));

	}
}


/* ----------- 三个实用函数 --------------------- */

//Submit Once
function submitonce(f)
{
	if (document.all || document.getElementById)
	{
		for (i=0; i<f.elements.length; i++)
		{
			var ctl = f.elements[i];
			var ctlType = ctl.type.toLowerCase();
			if (ctlType == 'submit' || ctlType == 'button' || ctlType == 'reset')
			{
				ctl.disabled = true;
			}
		}
	}
}


//Ctrl + Enter
function ctlent_backup1()
{
	if (window.event)
	{
		if(event.ctrlKey && window.event.keyCode == 13)
		{
			var f = document.forms['editor_form'];
			if (!f) f = document.forms['__aspnetForm'];
			if (!f) f = document.forms['aspnetForm'];
			f.send.click();
			return false;
		}
	}
}


//Check All
function chkAll()
{
	var f;	//define & find the form object
	var isFound = false;
	for (var i=0; i<document.forms.length; i++)
	{
		f = document.forms[i];
		if (f.checkall)	//key item : named 'checkall'
		{
			isFound = true;
			break;
		}
	}
	if (!isFound) return;

	var isAllChecked = f.checkall.checked;
	for (var i=0; i<f.elements.length; i++)
	{
		if (f.elements[i].type.toLowerCase() == 'checkbox')
		{
			f.elements[i].checked = isAllChecked;
		}
	}
}


/* ---- !!!!!!!!!!!!!!!!!!注意!!!!!!!!!!!!!!!!! --------- */
/* ---- 以下函数将被Dvbbs.Web.dll产生的代码所引用 --------- */
var originUrl
//Pager
function setPage(s, i)
{
	return s.replace('{p}', i.toString());
}
function pager(url, page, maxPage, total, per, countsIsVisible)
{
	originUrl = url;
	var first		= "<font style='font-size:12px'>首页</font>";
	var previous	= "<font style='font-size:12px'>上一页</font>";
	var next		= "<font style='font-size:12px'>下一页</font>";
	var last		= "<font style='font-size:12px'>尾页</font>";

	var s = "<div class='pager-block' style='width:100%;text-align:right'><div class='pager-links' style='float:left; text-align:left; font-family:courier new,sans-serif'>";
	if (page == 1)
	{
		s += (first + " " + previous + " <b>");
	}
	else
	{
		if (first != "") s += ("<a href='" + setPage(url, 1) + "'>" + first + "</a> ");
		s += ("<a href='" + setPage(url, (page-1)) + "'>" + previous + "</a> <b>");
	}

	var j = (page-5 < 1) ? 1 : page-5;
	var k = (page+5 > maxPage) ? maxPage : page+5;

	if (j > 1) s += " <a href='" + setPage(url, 1) + "'>1</a> ... ";
	for (var i=j; i<k+1; i++)
	{
		if (page == i)
		{
			s += ("<span class='t2'>" + i + "</span> ");
			continue;
		}
		s += ("<a href='" + setPage(url, i) + "'>" + i + "</a> ");
	}
	if (maxPage > k) s += " ... <a href='" + setPage(url, maxPage) + "'>" + maxPage + "</a> ";
	if (page == maxPage)
	{
		s += ("</b>" + next + " " + last);
	}
	else
	{
		s += ("</b><a href='" + setPage(url, page+1) + "'>" + next + "</a> ");
		if (last != "") s += ("<a href='" + setPage(url, maxPage) + "'>" + last + "</a>");
	}
	s += " 转到 <input type='text' name='gotopage' value='" + page + "' size='3' onkeydown='onpagekeydown();'/> <input type='button' value='Go' style='height:19px;' onclick='ongoto()' />";
	s += ("</div>");
	
	if (countsIsVisible)
	{
		s += ("<div class='pager-stat' style='float:lift;'>");
		s += ("总记录:<span class='t2'>" + total + "</span>　");
		s += ("每页:<span class='t2'>" + per + "</span>　");
		s += ("总页数:<span class='t2'>" + maxPage + "</span></div>");
	}
	s += "</div>";

	return s;
}

function onpagekeydown()
{
	if (window.event)
	{
		if(window.event.keyCode == 13)
		{
			//ongoto();
			//直接用ongoto()时，在线列表分页的文本框中输入页数后回车会在新窗口中打开
			var page = document.getElementById("gotopage").value;
	if (isNaN(page))
	{
		page = "1";
	}
	if(originUrl=='undefined'||originUrl==null||originUrl=='')originUrl = document.getElementById("originUrl").value;

	if(arguments.length==1&&arguments[0]!='_self'&&arguments[0]!='_target'&&arguments[0]!='_parent'&&arguments[0]!='_top')
	{
		var w = eval(arguments[0]);
		w.location.href = setPage(originUrl, page);
	}else 
	{
		location.href = setPage(originUrl, page);
	}
			event.returnValue = false;
		}
	}
}
function ongoto()
{
	var page = document.getElementById("gotopage").value;
	if (isNaN(page))
	{
		page = "1";
	}
	if(originUrl=='undefined'||originUrl==null||originUrl=='')originUrl = document.getElementById("originUrl").value;

	if(arguments.length==1&&arguments[0]!='_self'&&arguments[0]!='_target'&&arguments[0]!='_parent'&&arguments[0]!='_top')
	{
		var w = eval(arguments[0]);
		w.location.href = setPage(originUrl, page);
	}else 
	{
		location.href = setPage(originUrl, page);
	}
}

//Byte Counter
function len(str)
{
	var bytes = 0;
	for(i=0; i<str.length; i++)
	{
		ascii = str.charCodeAt(i);
		bytes += (ascii < 255 ? 1 : 2);
	}
	return bytes;
}


//Trim
function trim(str)
{
	return str.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}
String.prototype.trim = function()
{
	return this.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}


//Format
String.prototype.format = function()
{
	var s = this.replace(/\r/g, '');
	s = s.replace(/[\v\t　 ]*\n[\v\t　 ]*/g, '\n');
	s = s.replace(/(\n+)/g, '$1　　');
	s = s.replace(/[\n]{2,}/g, '\n\n');
	s = s.replace(/\n/g, '\r\n');
	s = '　　' + s;
	s = s.replace(/(　　!)/g, '');
	s = s.replace(/　　(\[uploadimage)/gi, '$1');
	return s;
}


//Filter
String.prototype.shitEncode = function()
{
	return this.replace(/(妈的|妈b|妈比|fuck|shit|我日|法轮|产党|泽东)/gi, "**");
}


//HtmlEncode
String.prototype.htmlEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/[ 　]*\r/g, '');
	s = s.replace(/  /g, '&nbsp; ');
	s = s.replace(/\t/g, '&nbsp; &nbsp; ');
	s = s.replace(/\"/, '&quot;');
	s = s.replace(/\'/, '&#39;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/g, '&gt;');
	s = s.replace(/\n/g, '<BR>');
	return s.shitEncode();
}


//TextEncode
String.prototype.textEncode = function()
{
	var s = this.replace(/&/g, '&amp;');
	s = s.replace(/</g, '&lt;');
	s = s.replace(/>/, '&gt;');
	return s.shitEncode();
}


//UbbCode
function UbbCode()
{
	//Protected Html
	this.protectHtml = function(str)
	{
		var s = str.replace(/<(\/?script)([^>]*)>/gi, '&lt;$1$2&gt;');
		s = s.replace(/<(\/?applet)([^>]*)>/gi, '&lt;$1$2&gt;');
		s = s.replace(/(javascript|vbscript|script)[\s]*:/gi, 'none:');
		s = s.replace(/<([%\?]{1})/gi, '&lt;$1');
		s = s.replace(/([%\?]{1})>/gi, '$1&gt;');
		s = s.replace(/<!\-\-[\s]*#[\s]*include/gi, '<!-- include');
		return s.shitEncode();
	}

	//Emotions
	this.showEmotion = function(str)
	{
		return str.replace(/\{\/em([\d]+)\}/gi, "<img src='<~>emotion/$1.gif' alt='emote' />&nbsp;");
	}

	//Seek URL
	this.findUrl = function(str)
	{
		var s = str.replace(/([^>=\]])((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]+[A-Za-z0-9\.\/=\?%\-&_~`@:\+!;]*)/gi, "$1<a href='<~>$2' target='_blank'>$2</a>");
		s = s.replace(/(^|<br \/>)((http|https|ftp|rtsp|mms):(\/\/|\\\\)[A-Za-z0-9%\-_@]+\.[A-Za-z0-9%\-_@]+[A-Za-z0-9\.\/=\?%\-&_~`@:\+!;]*)/gi, "$1<a href='<~>$2' target='_blank'>$2</a>");
		s = s.replace(/(^|<br \/>)(www\.[A-Za-z0-9%\-_@]+[A-Za-z0-9\.\/=\?%\-&_~`@:\+!;]+)/gi, "$1<a href='http://$2' target='_blank'>$2</a>");
		return s;
	}
	
	this.supportUbb = function(str)
	{
		return this.regExp(this.findUrl(str.htmlEncode()));
	}
	this.supportHtml = function(str)
	{
		return this.regExp(str);
	}
	
	//Regex
	this.regExp = function(str)
	{
		//font styles & simple tags
		var s = str.replace(/\[((\/?b)|(\/?i)|(\/?u)|(\/?h[1-6])|(\/?sub)|(\/?sup)|(\/?center))\]/gi, "<$1>");
		s = s.replace(/\[color=((#[A-Fa-f0-9]{3})|(#[A-Fa-f0-9]{6})|[a-zA-Z]{3,12})\]/gi, "<span style='color:$1'>");
		s = s.replace(/\[size=([1-3][0-9])\]/gi, "<span style='font-size:$1px'>");
		s = s.replace(/\[face=([^\[]+)\]/gi, "<span style='font-family:$1'>");
		s = s.replace(/\[\/(color|size|face)\]/gi, "</span>");
		//image
		s = s.replace(/\[img\]([^\[]{5,})\[\/img\]/gi, "<img src='<~>$1' class='image-from-ubb' border='0' alt='image' style='cursor:hand' onload='if(this.width>515)this.width=515' onclick=\"window.open(this.src, null, '')\" />");
		s = s.replace(/\[img=(left|right)\]([^\[]{5,})\[\/img\]/gi, "<img src='<~>$2' align='$1' class='image-from-ubb' border='0' alt='image' style='cursor:hand' onload='if(this.width>515)this.width=515' onclick=\"window.open(this.src, null, '')\" />");
		//line
		s = s.replace(/\[line\/\]/gi, "<hr size='1' color='#cccccc' noshade='noshade' />");
		s = s.replace(/\[line\]\s*(\d{1})\s*,\s*((#[A-Fa-f0-9]{3})|(#[A-Fa-f0-9]{6})|[A-Za-z]{3,12})\s*\[\/line\]/gi, "<hr size='$1' color='$2' noshade='noshade' />");
		//url
		s = s.replace(/\[url\]([^\[<]{5,})\[\/url\]/gi, "<a href='<~>$1' target='_blank'>$1</a>");
		s = s.replace(/\[url=([^\[<]{5,})\]([^\[<]+)\[\/url\]/gi, "<a href='<~>$1' target='_blank'>$2</a>");
		//email
		s = s.replace(/\[email\]([^\s@]+@[^\[\.]+\.[^\[]+)\[\/email\]/gi, "<a href='mailto:$1'>$1</a>");
		s = s.replace(/\[email=([^\s@]+@[^\[\.]+\.[^\[]+)\]([^\[]+)\[\/email\]/gi, "<a href='mailto:$1'>$2</a>");
		//flash
		s = s.replace(/\[flash\](.[^\[]*\.swf)\[\/flash\]/gi, "<embed src='<~>$1' width='500' height='400' quality='high' type='application/x-shockwave-flash'></embed><br /><a href='<~>$1' target='_blank'>[全屏欣赏　提醒：Flash中可能包含不安全内容]</a>");
		s = s.replace(/\[flash=(\d+),(\d+)\](.[^\[]*\.swf)\[\/flash\]/gi, "<embed src='<~>$3' width='$1' height='$2' quality='high' type='application/x-shockwave-flash'></embed><br /><a href='<~>$3' target='_blank'>[全屏欣赏　提醒：Flash中可能包含不安全内容]</a>");
		//media
		s = s.replace(/\*/gi, "*;");
		//	\.(avi|asx|wpl|aif|aifc|aiff|au|asf|mpeg|mpg|m1v|mp2|mpv2|mp2v|mpa|mid|midi|rmi|snd|wma|wmv|wm|wav|wax|m3u|wpl|mp3)
		s = s.replace(/\[(\/)?(MP(=([0-9]+),([0-9]+))?)\]/gi, "*$1$2*").replace(/\*MP=([0-9]+),([0-9]+)\*(.[^\*]*)\*\/MP\*/gi, "<object align='middle' classid='clsid:22d6f312-b0f6-11d0-94ab-0080c74c7e95' class='object' id='mediaplayer' width='$1' height='$2'><param name='showstatusbar' value='-1' /><param name='filename' value='$3' /><embed type='application/x-oleobject' codebase='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#version=5,1,52,701' filename='mp' src='<~>$3' width='$1' height='$2'></embed></object>");
		s = s.replace(/\*(\/)?(MP(=([0-9]+),([0-9]+))?)\*/gi, "[$1$2]").replace(/\*;/gi, "*");
		//real
		s = s.replace(/\*/gi, "*;");
		//	\.(rm|rma|ra|ram|rmm|rmvb|au|aif|mid|mp3|wav|wov|wma|smi|smil|m3u|mov|mpg|mpeg)
		s = s.replace(/\[(\/)?(RM(=([0-9]+),([0-9]+))?)\]/gi, "*$1$2*").replace(/\*RM=([0-9]+),([0-9]+)\*(.[^\*]*)\*\/RM\*/gi, "<object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' class='object' id='raocx' width='$1' height='$2'><param name='src' value='$3'><param name='console' value='clip1' /><param name='controls' value='imagewindow' /><param name='autostart' value='0' /></object><br /><object classid='clsid:cfcdaa03-8be4-11cf-b84b-0020afbbccfa' height='32' id='video2' width='$1'><param name='src' value='$3' /><param name='autostart' value='0' /><param name='controls' value='controlpanel' /><param name='console' value='clip1' /></object><br />[请确定您已安装了RealPlayer，并手动点击播放]");
		s = s.replace(/\*(\/)?(RM(=([0-9]+),([0-9]+))?)\*/gi, "[$1$2]").replace(/\*;/gi, "*");
		//code
		s = s.replace(/\[(\/?)code\]/gi, "[$1CODE]")
		//quote
		s = s.replace(/\[quotetitle\]([^\[]*)\[\/quotetitle\]/gi, "　&nbsp;<span style='position:relative;top:10px;' class='highlight bg1'>$1</span>");
		s = s.replace(/\[quote\](<br \/>|&nbsp;)*/gi, "<div class='grid bg3' style='width:96%; padding:10px 10px 9px 10px; line-height:18px'>");
		s = s.replace(/(<br \/>)*\[\/quote\]/gi, "</div>");

		return this.showCodeBlock(s);
	}

	//Set Code Highlight (CSharp)
	this.codeHighLightCSharp = function(str)
	{
		var s = str.replace(/(^|\s|<br \/>|;\s*|\)\s*)(private|protected|internal|public|using|namespace|class|interface|struct|event|virtual|abstract|static|delegate|override|readonly|return|break|continue|goto|case|default|sealed|throw)/g, "$1<span style='color:blue'>$2</span>");
		s = s.replace(/(else\s+if|if|switch|try|catch|finally|while|for|for\s+each|do|typeof|sizeof)(\s*\(|\s*\{)/gi, "<span style='color:blue'>$1</span>$2");
		s = s.replace(/(\s+|;\s*|=\s*|\(\s*|,\s*)(null|int|string|void|bool|long|short|byte|char|decimal|double|enum|event|float|object|sbyte|base|this|ulong|ushort|DateTime|true|false|get|set|var)(\s+|\.|\[|\s*\)|\s*;)/g, "$1<span style='color:blue'>$2</span>$3");
		s = s.replace(/(\}\s*|\]\s*|\s*\)|^|\s+|<br \/>)(else|is|as|in|is)(\s*\{|\s*\(|$|\s+|<br \/>)/g, "$1<span style='color:blue'>$2</span>$3");
		s = s.replace(/&quot;/gi, "\"").replace(/\\\"/g, "““””").replace(/(\"[^\"]*\")/g, "<span style='color:#ff00ff'>$1</span>").replace(/““””/g, "\\\"");
		s = s.replace(/<span style=\'color:blue\'>class<\/span>(\s*=)/gi, "class$1");

		var i = 0;	//define start index
		while ( (i = s.indexOf("//", i)) != -1)
		{
			if (s.indexOf("<BR>", i) == -1) break;

			s = s.substring(0, i) + "<span style='color:green'>" + s.substring(i, s.indexOf("<BR>", i)).replace(/<span style=\'color:#?[0-9a-zA-Z]+\'>([^<]+)<\/span>/gi, "$1") + "</span>" + s.substring(s.indexOf("<BR>", i));
			i = s.indexOf("<BR>", i);
		}

		i = 0;	//reset start index
		while ((i = s.indexOf("/*", i)) != -1)
		{
			if (s.indexOf("*/", i + 2) == -1) break;

			s = s.substring(0, i) + "<span style='color:green'>" + s.substring(i, s.indexOf("*/", i + 2) + 2).replace(/<span style=\'color:#?[0-9a-zA-Z]+\'>([^<]+)<\/span>/gi, "$1") + "</span>" + s.substring(s.indexOf("*/", i + 2) + 2);
			i = s.indexOf("*/", i + 2);
		}
		return s;
	}

	// Set CodeSource Display Mode
	this.setCodeSourceDisplayMode = function(senderId, eventerId)
	{
		var sender  = document.getElementById(senderId);
		var eventer = document.getElementById(eventerId);
		if (eventer.style.overflow == '')
		{
			sender.innerHTML = '[滚动模式]';
			eventer.noWrap = 'nowrap';
			eventer.style.height	= '400px';
			eventer.style.overflow	= 'auto';
		}
		else 
		{
			sender.innerHTML = '[全显模式]';
			eventer.noWrap = '';
			eventer.style.height	= '';
			eventer.style.overflow	= '';
		}
	}

	//Set Code Block
	this.codeBlockIndex = 0;
	this.showCodeBlock = function(str)
	{
		var arr = str.split('[CODE]');
		var quoterBegin = "　&nbsp;<span style='position:relative;top:10px;' class='highlight bg1'>本帖相关代码";
		quoterBegin    += " &nbsp; <a id='sender_$index' href=\"javascript:ubb.setCodeSourceDisplayMode('sender_$index', 'codesource_$index')\">[全显模式]</a></span>";
		quoterBegin    += "<div class='grid bg3' style='width:96%; padding:10px 10px 9px 10px; line-height:18px; font-family:宋体 !important; font-size:12px !important;' id='codesource_$index'>";

		for (var i=0; i<arr.length; i++)
		{
			var subArr = arr[i].split('[/CODE]');
			if (subArr.length == 1) continue;

			if (subArr[0].split('{').length > 1 && subArr[0].split(';').length > 4)
			{
				subArr[0] = this.codeHighLightCSharp(subArr[0]);	//如果不想语法高亮则把这行去掉
			}
			/* --- Show Line Number -------------			
			var lines = subArr[0].split('<br />');
			var maxLine = lines.length;
			for (var j=0; j<maxLine; j++)
			{
				lines[j] = "<span style='color:#bbbbbb;display:none'>"  + j.toString() + "</span > &nbsp;" + lines[j];
				for (var k=0; k<maxLine.toString().length - j.toString().length; k++)
				{
					if (k>10) break;
					lines[j] = '&nbsp;' + lines[j];
				}
			}
			subArr[0] = lines.join('<br />');
			*/
			subArr[0] = quoterBegin.replace(/\$index/g, this.codeBlockIndex++) + subArr[0];
			arr[i] = subArr.join('</div>');
		}
		return arr.join('');
	}

	//Explain The Attachment Mark
	this.showAttachment = function(str)
	{
		var s = str.replace(/\[uploadimage\]([\d]+),([0-9a-zA-Z_\.\/\\]+)\[\/uploadimage\]/gi, "<img src='<~>images/topic_hasimg.gif' align='absmiddle' alt='本帖包含图片' /> 本帖包含图片[<a href='additem.aspx?item=attach&itemid=$1'>收藏图片</a>]:<br /><a href='<~>attach.aspx?attachid=$1' target='_blank'><img src='<~>attach.aspx?attachid=$1' border='0' class='image-from-upload' alt='uploaded image' style='margin-top:3px' onload='if(this.width>515)this.width=515' /></a>");
		s = s.replace(/\[uploadimage=(left|right)\]([\d]+),([0-9a-zA-Z_\.\/\\]+)\[\/uploadimage\]/gi, "<img src='<~>images/topic_hasimg.gif' align='absmiddle' alt='本帖包含图片' /> 本帖包含图片[<a href='additem.aspx?item=attach&itemid=$1'>收藏图片</a>]:<br /><a href='<~>attach.aspx?attachid=$1' target='_blank'><img src='<~>attach.aspx?attachid=$2' style='margin:4px 6px 6px 6px' align='$1' border='0' class='image-from-upload' alt='uploaded image' onload='if(this.width>515)this.width=515' /></a>");
		s = s.replace(/\[uploadfile\]([0-9]+),([^\]]+),([0-9]+\.?[0-9\s]*kb)\[\/uploadfile\]/gi, "<img src='<~>images/topic_hasrar.gif' align='absmiddle' alt='本帖包含附件' /> 本帖包含附件[<a href='additem.aspx?item=attach&itemid=$1'>收藏附件</a>]:<br /><a href='<~>attach.aspx?attachid=$1' target='_blank'>$2</a> &nbsp;[附件大小:$3, <a href='<~>attach_list.aspx?attachid=$1&style=new_style' target='_blank'>查看信息...</a>]");
		return s;
	}

	//fix relative path
	this.fixRelativePath = function(str, pathUpSeek)
	{
		var s = str.replace(/ (href|src)=\'<~>(javascript|vbscript|script):([^\']*)\'/gi, " $1='$3'");
		s = s.replace(/ (href|src)=\'<~>(\/|[a-zA-Z]+:)([^\']*)\'/gi, " $1='$2$3'");
		s = s.replace(/ (href|src)=\'<~>([^\']*)\'/gi, " $1='" + pathUpSeek + "/$2'");
		return s;
	}

	//output
	this.print = function(str, currentPath, tagType, isFormat)
	{
		var s = isFormat ? str.format() : str;
		switch (tagType)
		{
			default:
				s = this.findUrl(s.htmlEncode());
				break;
			case 1:
				s = this.supportUbb(s);
				break;
			case -1:
				s = this.supportHtml(s);
				break;
			case 2:
				s = this.protectHtml(s);
				break;
		}

		s = this.showEmotion(this.showAttachment(s));
		s = this.fixRelativePath(s, currentPath);
		document.write(s);
	}
}
var ubb = new UbbCode();
var output;

function vgetCookie(parameter)
{
	var reg,allCookie,allCookie2,iLen,iStart,iEnd;
	allCookie = document.cookie;
	reg = new RegExp(parameter);
	if(allCookie.search(reg) == -1){
		return "";
	}
	else{
		iLen = parameter.length;
		iStart = allCookie.search(reg) + iLen +1;
		allCookie2 = allCookie.substr(iStart);
		iEnd = iStart + allCookie2.search(/;/i);		
		if((iStart - 1) == iEnd){
			return allCookie.substr(iStart);
		}
		else{
			return allCookie.substr(iStart,iEnd - iStart);
		}
	}
}

function frameon(url, img){
	if (window == top){
		top.location.href = "index_main.aspx?actleft="+escape(url);
		setCookie($app_prefix + "userleft","0");
	}else{
		setCookie($app_prefix + "userleft","1");
		top.location.href = url.indexOf("actleft") == -1 ? (url.indexOf("?") != -1 ? url + "&actleft=null" : url+"?actleft=null") : url;
	}
}
function changeframeicon(isleft, path){
	if (!isleft){return false;}
	
	if (window == top){
		isleft.innerHTML = "左右分栏";
	}else{
		isleft.innerHTML = "平版模式";
		//g.src = path + 'noleft.gif';

	}
}

// 检查并更改图片大小 added by 小点@20070612
function imgresize(o){
	var parentNode=o.parentNode;
	if (parentNode){
		if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
		}else{
		var parentNode=o.parentNode
		if (parentNode){
			if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}
		}
}

function addTitleHead(obj, tovalue){	//modified by caoxin03 2007 0816
	var x = eval('obj.form.' + tovalue);
	if (obj.options.selectedIndex > 0 && x.value.length < 46 && len(x.value) < 64)
	{
		x.value = obj.options[obj.options.selectedIndex].text + x.value;
		obj.options.selectedIndex = 0;
	}
}

function PostShowTime(stat){
	if(1 == stat){
		document.getElementById("uncertainstarttime").style.display = 'block';
		document.getElementById("certainstarttime").style.display = 'none';
	}else{
		document.getElementById("uncertainstarttime").style.display = 'none';
		document.getElementById("certainstarttime").style.display = 'block';
	}
}

