var Comment = new Object();
var $C = function(tagName)
{
	return document.createElement(tagName);
};
String.prototype.trim = function()
{
	return this.replace(/^\s*|\s*$/g,"");
};
String.prototype.realLength = function()
{
    return this.replace(/[^\x00-\xff]/g,"**").length;
};
String.prototype.left = function(n)
{
	if (this.length > n)
	{
		return this.substr(0, n) + '...';
	}
	else
	{
		return this;
	}
};
Array.prototype.remove = function(n)
{
	if (n < 0)
	{
		return this;
	}
	else
	{
		return this.slice(0, n).concat(this.slice(n + 1, this.length));
	}
};
function findPosX(obj) 
{
	var curleft = 0;
	if (obj && obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj && obj.x) curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj && obj.offsetParent) 
	{
		while (obj.offsetParent) 
		{
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} 
	else if (obj && obj.y) curtop += obj.y;
	return curtop;
}

var input_domain = 'http://input.comment.qq.com';
var index_domain = 'http://comment1.qq.com';
var pinglun_domain = 'http://pinglun.qq.com';
var js_domain = 'http://pinglun.qq.com';
var img_domain = 'http://mat1.qq.com/pinglun';
Comment.Configure = {
	version:				'1.0',
	newline:				'\n',
	site_length:			20,
	key_length:				20,
	id_length:				10,
	index_line_sum:			10000,
	index_width:			5,
	default_mode:			'origin_count',
	default_order:			1,
	default_reply_per_page:	10,
	quote_str_len:			60,
	intro_len:				150,
	debate_intro_len:		200,
	content_len:			200,
	reply_default_title:	'请填写标题',
	intro_min_length:		20,
	request_delay:			100,
	login_frame_delay:		2000,
	reply_type_def:			{
		'1':	'<strong>[<span>热帖</span>]</strong>',
		'2':	'<strong>[<span>精华</span>]</strong>',
		'3':	'<strong>[<span>精华</span>]</strong>'
	},
	postUrl:				input_domain + '/post.cmt',
	userPostUrl:			input_domain + '/userPost.cmt',
	logoutUrl:				input_domain + '/cgi-bin/qqlogout',
	commentIndex:			'http://pinglun.qq.com/',
	loginIframeUrl:			index_domain + '/i_login.htm',
	defaultLogoUrl:			img_domain + '/images/defpic.jpg',
	userSiteEn:				'userComment',
	fastreplysleeptime:		10000
};

Comment.Define = {
	getReplyType: function(type)
	{
		if (Comment.Configure.reply_type_def[type])
		{
			return Comment.Configure.reply_type_def[type];
		}
		else
		{
			return '';
		}
	}
};

Comment.PGV_Count = function(option)
{
	if (typeof(pgvMain) == 'function')
	{
		pvRepeatCount = 1;
		pvCurDomain = sDomain;
		if (option)
		{
			if (option.domain)
			{
				pvCurDomain = option.domain;
			}
			if (option.path)
			{
				pvCurUrl = option.path;
			}
		}
		pgvMain();
	}
};

Comment.UrlFactory = {
	get3LevelDir: function(id)
	{
		var path = parseInt(id / 1000000) + '/';
		path += parseInt(id / 1000) + '/';
		path += id / 1;
		return path;
	},
	getCommentUrl: function(id)
	{
		return (this.get3LevelDir(id) + '/');
	},
	getDebateUrl: function(id)
	{
		return this.get3LevelDir(id);
	},
	getUserUrl: function(id)
	{
		return this.get3LevelDir(id);
	},
	getReplyUrl: function(key)
	{
		var path = key.substr(0, 8);
		path += '/' + (key.substr(8, 4));
		path += '/' + (key.substr(12, 2));
		path += '/' + key;
		return path;
	},
	getIndexUrl: function(id)
	{
		var length = id.toString().length;
		if (length < Comment.Configure.index_width)
		{
			for (var i = 0; i < Comment.Configure.index_width - length; ++i)
			{
				id = '0' + id;
			}
		}
		return id;
	},
	getIndexDir: function(mode)
	{
		var modes = {
			'origin_count':	'originindex',
			'total_count':	'allindex',
			'top_count':	'topindex',
			'user_c_count':	'userindex',
			'user_r_count':	'ruserindex'
		};
		return modes[mode];
	},
	getRangeHeader: function(start, length, line_len)
	{
		var range_start = start * line_len;
		var range_length = length * line_len;
		return ['Range','bytes=' + range_start + '-' + (parseInt(range_start) + parseInt(range_length) - 1 - Comment.Configure.newline.length)];
	},
	getCommentNormalUrl: function(site, id)
	{
		return 'comment.htm?site=' + site + '&id=' + id;
	},
	getCommentGroupUrl: function(site, id)
	{
		return 'comment_group.htm?site=' + site + '&id=' + id;
	},
	getCommentDebateUrl: function(site, id)
	{
		return 'comment_debate.htm?site=' + site + '&id=' + id;
	},
	getUserQzone: function(uin)
	{
		return '<a href="http://user.qzone.qq.com/' + uin + '" target="_blank"><img src="http://img1.qq.com/pinglun/pics/7689/7689783.gif" border="0"></a>'
	},
	getCommentUserUrl: function(uin)
	{
		return 'http://user.comment2.qq.com/axel/comment_user2.htm?uin=' + uin;
	},
	getCommentUserLink: function(uin, nick)
	{
		return '<a href="' + this.getCommentUserUrl(uin) + '" target="_blank">' + (nick ? nick : uin) + '</a>';
	},
	getCommentUserLinkEx: function(uin, nick, ip)
	{
		var res = '';
		if (nick!=''&&nick=='手机网友')
		{
			res = '手机网友';
		}
		else
		{
			res = ''
				+ ((uin == '' || uin == '0') ? '腾讯网友' : '<span class="have_login">'+Comment.UrlFactory.getCommentUserLink(uin, nick)+'</span>');
		}
		return res;
	},
	getCommentListLink: function(site_en, site_cn, sort_en, sort_cn, className)
	{
		if (className)
		{
			className = 'class="' + className + '"';
		}
		else
		{
			className = '';
		}
		return '<a href="' + Comment.Configure.commentIndex + '" ' + className + ' target="_blank">评论首页</a> &gt;&gt; '
			+ '<a href="list.htm?' + site_en + '." ' + className + ' target="_blank">' + site_cn + '</a> &gt;&gt; '
			+ '<a href="list.htm?' + site_en + '.' + sort_en + '" ' + className + ' target="_blank">' + sort_cn + '</a>';
	},
	getIP2Mobile: function(ip)
	{
		if (Comment.Toolkit.isMobile(ip))
		{
			return ip + ' <a href="http://3gqq.qq.com/index.jsp?from=comment" target="_blank"><span style="color:#C0C0C0">手机腾讯网</span></a> '
				+ '<a href="http://3gqq.qq.com/index.jsp?from=comment" target="_blank"><img src="http://img1.qq.com/pinglun/pics/7689/7689576.gif" border="0" alt="欢迎手机访问 3g.qq.com"></a>';
		}
		
		
		return ip.split("|")[0];
	}
};

Comment.Toolkit = {
	isMobile: function(str)
	{
		if (str.length == 11 && str.indexOf('.') == -1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
};

Comment.ContentFormat = {
	decode: function(content)
	{
		return content.split(Comment.Configure.newline);
	},
	safe: function(orig_array)
	{
		var safe_array = [];
		for (var i = 0; i < orig_array.length; i++) 
		{
			if (orig_array[i] != '') safe_array[safe_array.length] = orig_array[i];
		}
		
		return safe_array;
	}
};
Comment.GetAddress = function(ip) {
	var address  = '未知';
	var distinct = ip.split("|");
	
	if (distinct.length == 1) {
		if(ip.trim()!='')
		address = ip;
	} else {
		if( distinct[1].trim()!=''){
			if(distinct[1].trim()=='手机腾讯网')
				address = distinct[1]+ '<a href="http://3gqq.qq.com/" target="_blank"><img src="http://img1.qq.com/pinglun/pics/11344/11344308.gif" border="0" alt="欢迎手机访问 3g.qq.com"></a>';	
			else
				address = distinct[1];		
		}
			
	}
	
	return address;
};
Comment.DataObjectFactory = function(content, model)
{
	content = Comment.ContentFormat.decode(content);
	var dataModel = Comment.DataObject[model];
	if (content.length - 1 != dataModel.length)
	{
		if (model != 'commentinfo' && model != 'listsum')
		{
		}
	}
	var dataObject = new Object();
	for (var i = 0; i < dataModel.length; ++i)
	{
		dataObject[dataModel[i]] = content[i];
	}
	return dataObject;
}

Comment.DataObject = {
	'commentinfo':
	[
		'site_cn',
		'sort_en',
		'sort_cn',
		'source',
		'source_url',
		'title',
		'url',
		'intro',
		'intro_img',
		'group_id',
		'intro_show',
		'create_time',
		'debate_id'
	],
	'groupinfo':
	[
	 	'site_cn',
		'title',
		'url',
		'intro',
		'intro_img',
		'comment_id',
		'intro_show',
		'create_time'
	],
	'debateinfo':
	[
	 	'site_cn',
		'title',
		'url',
		'intro',
		'intro_img',
		'agree_id',
		'disagree_id',
		'middle_id',
		'intro_show',
		'create_time'
	],
	'sum':
	[
	 	'origin_count',
		'total_count',
		'top_count'
	],
	'reply':
	[
		'comment_id',
		'uin',
		'nickname',
		'pub_time',
		'pass_time',
		'ip',
		'title',
		'content',
		'reply_key',
		'is_del',
		'reply_type',
		'reply_kind',
		'tips',
		'sums'
	],
	'pksum':
	[
	 	'agree',
		'disagree',
		'middle',
		'original',
		'agree_o',
		'disagree_o'

	],
	'listsum':
	[
		'all'
	],
	'usersum':
	[
	 	'total_count',
		'top_count',
		'is_expert',
		'user_c_count',
		'user_r_count'
	],
	'userinfo':
	[
	 	'user_img',
		'user_intro'
	],
	'point':
	[
		'last',
		'rect'
	]
}

Comment.Control = new Object();

Comment.Control.Pagination = Class.create();
Comment.Control.Pagination.prototype = {
	initialize: function(option)
	{
		this.totalPage = option.totalPage;
		this.currPage = 1;
		this.zoom_start = 3;
		this.zoom_end = 613;
		this.bindControl();
	},
	reset: function(option)
	{
		this.totalPage = option.totalPage;
		this.currPage = 1;
		this.movePageControl(this.currPage);
	},
	updateOrder: function()
	{
		
	},
	countCurrPage: function(offset)
	{
		var page = parseInt(offset * this.totalPage / this.zoom_end) + 1;
		if (page > this.totalPage)
		{
			page = this.totalPage;
		}
		return page;
	},
	movePageControl: function(toPage)
	{
		if (toPage < 1 || toPage > this.totalPage)
		{
			return;
		}
		var offset = 0;
		if (toPage == 1)
		{
			offset = this.zoom_start;
		}
		else if (toPage == this.totalPage)
		{
			offset = this.zoom_end;
		}
		else
		{
			offset = this.zoom_start + (toPage - 1) * (this.zoom_end / (this.totalPage - 1));
		}
		$('scrfloat').style.left = offset + 'px';
	},
	bindControl: function()
	{
		var self = this;
		var tooltip = $('Page_tip');
		var offsetX = 10;
		var offsetY = -10;
		function getSite(o)
		{
			var obj = o;
			var objS = obj.offsetLeft;
			while (obj != obj.offsetParent && obj.offsetParent)
			{
				obj = obj.offsetParent;
				if (obj.tagName == 'span')
				{
					objS += obj.offsetLeft;
				}
			}
			return objS;
		}
		Event.observe($('scr'), 'mousedown', mDown, false);
		var flag = false;
		function mDown()
		{
			flag = true;
			if(window.event.srcElement.id != 'scr'
			   && window.event.srcElement.id != 'scr_2')
			{
				$('scrfloat').style.left = $('scrfloat').offsetLeft;
			}
			else
			{
				$('scrfloat').style.left = (window.event.x - 5);
			}
			tooltip.style.display = 'block';
			t = $('scrfloat').offsetLeft;
			tooltip.innerHTML = self.countCurrPage(t);
			tooltip.style.left = window.event.clientX + offsetX + 'px';
			tooltip.style.top = window.event.clientY + offsetY + document.documentElement.scrollTop + 'px';
		}
		function mMove()
		{
			if(flag)
			{
				$('scrfloat').style.left = window.event.clientX - getSite($('scr')) - 5 + 'px';
			}
			if (parseInt($('scrfloat').style.left.replace('px', '')) > self.zoom_end)
			{
				$('scrfloat').style.left = self.zoom_end + 'px';
			}
			if (parseInt($("scrfloat").style.left.replace('px', '')) < self.zoom_start)
			{
				$('scrfloat').style.left = self.zoom_start + 'px';
			}
			if (flag)
			{
				t = $('scrfloat').offsetLeft;
				tooltip.innerHTML = self.countCurrPage(t);
				tooltip.style.left = window.event.clientX + offsetX + 'px';
				tooltip.style.top = window.event.clientY + offsetY + document.documentElement.scrollTop + 'px';
			}
		}  
		function mUp()
		{
			if (flag)
			{
				t = $('scrfloat').offsetLeft;
				self.setCurrPage(self.countCurrPage(t));
			}
			flag = false;
			tooltip.style.display = 'none';
		}

		function mEnd()
		{
			window.event.returnValue = false;
		}

		window.document.onmousemove = mMove;
		window.document.ondragstart = mEnd;
		window.document.onmouseup = mUp;
		
		Event.observe($('up'), 'click', mUpBtn, false);
		Event.observe($('down'), 'click', mDownBtn, false);
		function mUpBtn()
		{
			self.setCurrPage(self.currPage - 1, 1);
		}
		function mDownBtn()
		{
			self.setCurrPage(self.currPage + 1, 1);
		}
	},
	nextPage: function()
	{
		if (this.currPage < this.totalPage)
		{
			++this.currPage;
			this.onPageChange();
		}
	},
	previousPage: function()
	{
		if (this.currPage > 0)
		{
			--this.currPage;
			this.onPageChange();
		}
	},
	setCurrPage: function(page, move)
	{
		if (page > 0 && page <= this.totalPage && page != this.currPage)
		{
			this.currPage = page;
			this.onPageChange();
			if (move != null)
			{
				this.movePageControl(page);
			}
		}
	},
	onPageChange: function()
	{
	},
	getCurrPage: function()
	{
		return this.currPage;
	}
}

Comment.Iterator = {
	getIndex: function(objComment)
	{
		var rangeList = new Array();
		function getIndexId(reply_id)
		{
			return parseInt(reply_id / Comment.Configure.index_line_sum);
		}
		function getReplyPos(reply_id)
		{
			return (reply_id % Comment.Configure.index_line_sum);
		}
		
		if (objComment.order == 0)
		{
			var reply_start = (objComment.currPage - 1) * objComment.replyPerPage;
			var start_index_id = getIndexId(reply_start);
			var start_reply_id = getReplyPos(reply_start);
			var currReply = 1;
			var replySum = 0;
			while (currReply++)
			{
				if (reply_start + currReply > objComment.totalReply)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(start_reply_id, currReply - replySum - 1, objComment.index_line_len)
					});
					break;
				}
				if (currReply == objComment.replyPerPage)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(start_reply_id, currReply - replySum, objComment.index_line_len)
					});
					break;
				}
				if (start_reply_id + currReply > Comment.Configure.index_line_sum)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(start_reply_id, currReply, objComment.index_line_len)
					});
					start_index_id++;
					start_reply_id = 0;
					replySum = currReply - 1;
				}
			}
		}
		else
		{
			var reply_start = objComment.totalReply - 1 - (objComment.currPage - 1) * objComment.replyPerPage;
			var start_index_id = getIndexId(reply_start);
			var start_reply_id = getReplyPos(reply_start);
			var currReply = 1;
			var replySum = 0;
			while (currReply++)
			{
				if (reply_start - currReply < 0)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, objComment.index_line_len)
					});
					break;
				}
				if (currReply == objComment.replyPerPage)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(start_reply_id - currReply + replySum + 1, currReply - replySum, objComment.index_line_len)
					});
					break;
				}
				if (start_reply_id - currReply < 0)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, objComment.index_line_len)
					});
					start_index_id--;
					start_reply_id = Comment.Configure.index_line_sum - 1;
					replySum = currReply;
				}
			}
		}
		return rangeList;
	}
}

Comment.Control.Display = Class.create();
Comment.Control.Display.prototype = {
	initialize: function()
	{
	}
}

Comment.Page = new Object();
Comment.Page.Base = {
	changeMode: function(mode)
	{
		this.mode = mode;
		this.totalReply = this.data_sum[mode];
		this.totalPage = parseInt(this.totalReply / this.replyPerPage)
			+ (this.totalReply % this.replyPerPage != 0 ? 1 : 0);
	},
	changeOrder: function(order)
	{
		if (this.order == order)
			return;
		this.order = order;
		this.currPage = 1;
		this.resetPageControl();
		this.bindPageNav();
		this.bindReplyList();
		this.bindOrderControl();
	},
	bindOrderControl: function()
	{
		var self = this;
		if (self.order == 0)
		{
			$('order_front').style.color = '#000';
			$('order_front').onclick = function(e)
			{
				return false;
			}
			$('order_desc').style.cursor = 'pointer';
			$('order_desc').style.color = '#3B78AF';
			$('order_desc').onclick = function()
			{
				self.changeOrder(1);
				return false;
			}
		}
		else if (self.order == 1)
		{
			$('order_front').style.cursor = 'pointer';
			$('order_front').style.color = '#3B78AF';
			$('order_front').onclick = function(e)
			{
				self.changeOrder(0);
				return false;
			}
			$('order_desc').style.color = '#000';
			$('order_desc').onclick = function()
			{
				return false;
			}
		}
	},
	bindRowsPerPage: function()
	{
		var self = this;
		$A($('rows_page').getElementsByTagName('a')).each(function(button)
		{
			button.onclick = function()
			{
				self.replyPerPage = button.getAttribute('value');
				self.currPage = 1;
				self.resetPageControl();
				self.bindPageNav();
				self.bindReplyList();
				return false;
			}
		});
	},
	selectTab: function(mode)
	{
		var self = this;
		$A($('mode_tab').getElementsByTagName('p')).each(function(tab)
		{
			if (tab.value == mode)
			{
				$A($('mode_tab').getElementsByTagName('p')).each(function(t)
				{
					if (t.value != '')
					{
						t.className = 'none';
					}
				});
				tab.className = 'c';
			}
		});
	},
	appendTab: function(option)
	{
		var pTab = $C('p');
		pTab.innerHTML = option.title;
		pTab.value = '';
		$('mode_tab').appendChild(pTab);
		pTab.onclick = function()
		{
			window.open(option.url);
		}
		return false;
	},
	bindTabControl: function()
	{
		var self = this;
		$A($('mode_tab').getElementsByTagName('p')).each(function(tab)
		{
			var mode = tab.getAttribute('value');
			if (!!mode)
			{
				tab.onclick = function()
				{
					$A($('mode_tab').getElementsByTagName('p')).each(function(t)
					{
						t.className = 'none';
					});
					this.className = 'c';
					self.currPage = 1;
					self.changeMode(mode)
					self.resetPageControl();
					self.bindPageNav();
					self.bindReplyList();
					return false;
				}
			}
		});
	},
	bindPageNav: function(flag)
	{
		var self = this;
		var currPage = self.currPage;
		if (flag != 1)
		{
			this.pageControl.movePageControl(currPage);
		}
		var pagesPerRange = 6;
		this.totalPage = parseInt(this.totalReply / this.replyPerPage)
			+ (this.totalReply % this.replyPerPage != 0 ? 1 : 0);
		var startPage = parseInt((self.currPage - 1) / pagesPerRange) * pagesPerRange + 1;
		createPageNav($('page_nav'), false);
		createPageNav($('page_nav_2'), true);
		function createPageNav(obj, top)
		{
			obj.innerHTML = '';
			var i = startPage;
			if (self.currPage != 1)
			{
				obj.appendChild(createPage2(1, '第一页', top));
				obj.appendChild(createPage({
					page:	'上一页',
					onclick:function()
					{
						self.currPage = self.currPage - 1;
						self.bindPageNav();
						self.bindReplyList();
						if (top)
						{
							window.location.replace('#reload');
						}
						return false;
					}
				}));
			}
			for (; i < startPage + pagesPerRange; ++i)
			{
				if (i > self.totalPage)
				{
					break;
				}
				obj.appendChild(createPage2(i, '', top));
			}
			if (self.currPage < self.totalPage)
			{
				obj.appendChild(createPage({
					page:	'下一页',
					onclick:function()
					{
						self.currPage = self.currPage + 1;
						self.bindPageNav();
						self.bindReplyList();
						if (top)
						{
							window.location.replace('#reload');
						}
						return false;
					}
				}));
				obj.appendChild(createPage2(self.totalPage, '最末页', top));
			}
		}
		
		function createPage(option)
		{
			var p = $C('a');
			if (option.page == self.currPage)
			{
				p.className = 'strong';
			}
			if(option.page=='上一页'||option.page=='下一页')
				p.className = 'block_blue';
			p.innerHTML = (option.text && option.text != '') ? option.text : option.page;
			p.href = '';
			p.onclick = option.onclick;
			if (option.title)
			{
				p.title = option.title;
			}
			return p;
		}
		function createPage2(page, text, top)
		{
			return createPage({
				page:	page,
				onclick:function()
				{
					self.currPage = page;
					self.bindPageNav();
					self.bindReplyList();
					if (top)
					{
						window.location.replace('#reload');
					}
					return false;
				},
				text:	text != '' ? text : ''
			});
		}
	},
	bindPageControl: function()
	{
		this.totalPage = parseInt(this.totalReply / this.replyPerPage)
			+ (this.totalReply % this.replyPerPage != 0 ? 1 : 0);
		this.pageControl = new Comment.Control.Pagination({
			totalPage: this.totalPage
		});
		var self = this;
		this.pageControl.onPageChange = function()
		{
			self.currPage = this.getCurrPage();
			self.bindPageNav(1);
			self.bindReplyList();
		}
	},
	resetPageControl: function()
	{
		this.totalPage = parseInt(this.totalReply / this.replyPerPage)
			+ (this.totalReply % this.replyPerPage != 0 ? 1 : 0);
		this.pageControl.reset({
							  totalPage: this.totalPage
							  });
	},
	bindTopReply: function(tag,topcontent)
	{
		var self = this;
		var rangeList = new Array();
		function getIndexId(reply_id)
		{
			return parseInt(reply_id / Comment.Configure.index_line_sum);
		}
		function getReplyPos(reply_id)
		{
			return (reply_id % Comment.Configure.index_line_sum);
		}

		var top_show_sum = 5;
		var index_line_len = self.index_line_len;
		var reply_start = self.data_sum['top_count'] - 1;
		var start_index_id = getIndexId(reply_start);
		var start_reply_id = getReplyPos(reply_start);
		var currReply = 1;
		var replySum = 0;
		if(tag){
			index_line_len+=6;
			var start=0;
			var length=5;
			if(self.data_sum['top_count']<5)
				length=self.data_sum['top_count'];
			if(topcontent.length<length*index_line_len-1)
				length=parseInt(topcontent.length/index_line_len);
			rangeList.push({
				range:	Comment.UrlFactory.getRangeHeader(0, length, index_line_len)
			});		
		}
		else
		{
			while (currReply++)
			{
			
				if (reply_start - currReply < 0)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, index_line_len)
					});
					break;
				}
				if (currReply == top_show_sum)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(start_reply_id - currReply + replySum + 1, currReply - replySum, index_line_len)
					});
					break;
				}
				if (start_reply_id - currReply < 0)
				{
					rangeList.push({
						url:	Comment.UrlFactory.getIndexUrl(start_index_id),
						range:	Comment.UrlFactory.getRangeHeader(0, start_reply_id + 1, index_line_len)
					});
					start_index_id--;
					start_reply_id = Comment.Configure.index_line_sum - 1;
					replySum = currReply;
				}
			}
		
		}
		var replyList = new Array();
		var replyAllList = new Array();
		var rangeSum = rangeList.length;
		for (var i = 0; i < rangeList.length; ++i)
		{
			new getReplyList(i);
		}

		function getReplyList(i)
		{

			if(tag){
				replyList[i] = Comment.ContentFormat.decode(topcontent);
				if (i == rangeSum - 1)
				{
					replySort();
					self.bindReplyList();
				}
			}
			else{
				var comment_type = 'normal';
				var comment_id = self.commentId;
				if (self.name == 'Group')
				{
					comment_type = 'group';
					comment_id = self.groupId;
				}
				var sCommentIndexUrl = '/' + self.site + '/' + comment_type + '/'
					+ Comment.UrlFactory.getCommentUrl(comment_id)
					+ Comment.UrlFactory.getIndexDir('top_count')
					+ '/'
					+ rangeList[i].url
					+ '.htm' + noCacheUrl();	
					
				function onSucc(response)
				{
					replyList[i] = Comment.ContentFormat.decode(response.responseText);
					if (i == rangeSum - 1)
					{
						replySort();
						self.bindReplyList();
					}
				}
				function onError()
				{
				}
				new Ajax.Request(
					 sCommentIndexUrl,
					 {
						 method: 		'get',
						 asynchronous:	true,
						 onSuccess: 	onSucc,
						 onFailure:		onError,
						 requestHeaders:rangeList[i].range
					 }
				);	
			}
		}
		
		function replySort()
		{
			var order =0;
			if(tag)
				order =0;
			else
				order =self.order;	
			if (order == 0)
			{
				if (replyList.length == 1)
				{
					
					for (var i =0; i < length; ++i)
					{
						if(tag)
							replyAllList.push(replyList[0][i].substr(0,index_line_len-7));
						else
							replyAllList.push(replyList[0][i]);
					}					
				}
				else
				{
					for (var i = 0; i < replyList.length; ++i)
					{
						for (var j = 0; j < replyList[i].length; --j)
						{
							if(tag)
								replyAllList.push(replyList[i][j].substr(0,index_line_len-7));
							else
								replyAllList.push(replyList[i][j]);
						}						
					}
				}
			}
			else
			{
				if (replyList.length == 1)
				{
					for (var i = replyList[0].length - 1; i >= 0; --i)
					{
						if(tag)
							replyAllList.push(replyList[0][i].substr(0,index_line_len-7));
						else
							replyAllList.push(replyList[0][i]);
					}
				}
				else
				{
					for (var i = 0; i < replyList.length; ++i)
					{
						for (var j = replyList[i].length - 1; j >= 0; --j)
						{
							if(tag)
								replyAllList.push(replyList[i][j].substr(0,index_line_len-7));
							else
								replyAllList.push(replyList[i][j]);
						}
					}
				}
			}
			
			var str = '';
			for (var j = 0; j < replyAllList.length; ++j)
			{
				str += replyAllList[j] + '\r\n';
			}
			
			self.topReplyList = replyAllList;
		}
	}
}

Comment.User = {
	logined:	null,
	uin:		null
}

Comment.Post = {
	init: function(option)
	{
		this.base = option.base;
		this.option = option;
		this.initAsyncForm();
		this.bindPostTypeSelector();
		this.bindOtherEvent();
		this.bindPostBtn();
		this.bindBottomPostBtn();
		this.bindBottomTitleEvent();
		this.bindBottomPostTypeEvent();
		this.setDefault();
	},
	bindOpenPostBtn: function(btn, c_id)
	{
		$(btn).onclick = function()
		{
			Comment.Post.beforeOpenPost(0, '', c_id);
			return false;
		}
	},
	formElem: [
		'b_anonymous',
		'c_id',
		'c_site',
		'c_sort',
		'c_title',
		'c_content',
		'r_key',
		'r_type',
		'r_tips',
		'g_id',
		'verifycode',
		'c_type',
		'c_soul',
		'd_id',
		'v',
		'c_agree',
		'c_object',
		'c_neutral'
	],
	initAsyncForm: function()
	{
		var formElem = this.formElem;
		var form = $C('form');
		form.id = 'post_form';
		$A(formElem).each(function(elem_name)
		{
			var elem = $C('input');
			elem.type = 'hidden';
			elem.name = elem_name;
			elem.value = '';
			form.appendChild(elem);
		});
		document.getElementsByTagName('body')[0].appendChild(form);
	},
	clearAsyncForm: function()
	{
		$A($('post_form').getElementsByTagName('input')).each(function(elem)
		{
			elem.value = '';
		});
	},
	setDefault: function()
	{
		if ($('stat_post_type'))
		{
			$('stat_post_type').innerHTML = '非匿名发表';
		}
	},
	bindOtherEvent: function()
	{
		if (!$('r_quote_del'))
		{
			return;
		}
		$A($('reply_type').getElementsByTagName('input')).each(
		function(radio)
		{
			if (radio.value == 'middle')
			{
				radio.checked = true;
			}
			radio.onclick = function()
			{
				if (this.value == 'agree')
				{
					makeFormValue({r_type:'0'});
				}
				else if (this.value == 'disagree')
				{
					makeFormValue({r_type:'1'});
				}
				else
				{

					makeFormValue({r_type:'2'});
				}
			}
		});
		$A($('debate_id').getElementsByTagName('input')).each(
		function(radio)
		{
			radio.onclick = function()
			{
				if (this.value == 'agree')
				{
					$('stat_debate_type').innerHTML = '我是正方';					
					makeFormValue({c_id:Comment.Post.base.data_info.agree_id});
				}
				else if (this.value == 'disagree')
				{
					$('stat_debate_type').innerHTML = '我是反方';
					makeFormValue({c_id:Comment.Post.base.data_info.disagree_id});
				}
				else if (this.value == 'middle')
				{
					$('stat_debate_type').innerHTML = '我是中立方';
					makeFormValue({c_id:Comment.Post.base.data_info.middle_id});
				}
			}
		});
	},
	setReplyType: function(type)
	{
		$A($('reply_type').getElementsByTagName('input')).each(
		function(radio)
		{
			if (radio.value == type)
			{
				radio.click();
				return;
			}
			else
			{
				radio.checked = false;
			}
		});
	},
	setDebate: function(type, c_id)
	{
		$A($('debate_id').getElementsByTagName('input')).each(
		function(radio)
		{
			if (radio.value == type)
			{
				radio.checked = true;
				makeFormValue({c_id:c_id});
			}
			else
			{
				radio.checked = false;
			}
		});
	},
	clearValue: function()
	{
		$A($(
			 'l_c_title',
			 'l_c_content'
			 )).each(
		function(input)
		{
			input.value = '';
		});
	},
	bindTitleEvent: function()
	{
		var d_title = Comment.Configure.reply_default_title;
		$('l_c_title').value = d_title;
		$('l_c_title').onfocus = function()
		{
			if ($('l_c_title').value == d_title)
			{
				$('l_c_title').value = '';
			}
		}
		$('l_c_title').onblur = function()
		{
			if ($('l_c_title').value == '')
			{
				$('l_c_title').value = d_title;
			}
		}
	},
	bindBottomTitleEvent: function()
	{
		if (!$('b_c_title'))
		{
			return;
		}
		var d_title = Comment.Configure.reply_default_title;
		$('b_c_title').value = d_title;
		$('b_c_title').onfocus = function()
		{
			if ($('b_c_title').value == d_title)
			{
				$('b_c_title').value = '';
			}
		}
		$('b_c_title').onblur = function()
		{
			if ($('b_c_title').value == '')
			{
				$('b_c_title').value = d_title;
			}
		}		
	},
	setPostTypeSelector: function(type)
	{
		if (type == 'login_select')
		{
			$('l_login_frame').src = 'i_login.htm?l_login_frame';
			showElement('l_login_post');
			$('stat_post_type').innerHTML = '登录发表';
			$('l_b_anonymous').checked = false;
		}
		else if (type == 'anonymous_select')
		{
			hideElement('l_login_post');
			$('stat_post_type').innerHTML = '匿名发表';
			$('l_b_anonymous').checked = true;
		}
	},
	bindPostTypeSelector: function()
	{
		if (!$('l_b_anonymous'))
		{
			return;
		}
		$('l_b_anonymous').onclick = function()
		{
			if ($('l_b_anonymous').checked)
			{
				Comment.Post.setPostTypeSelector('anonymous_select');
			}
			else
			{
				Comment.Post.setPostTypeSelector('login_select');
			}
		}
	},
	bindPostBtn: function()
	{
		if (!$('l_post_btn'))
		{
			return;
		}
		var self = this;
		$('l_post_btn').onclick = function()
		{
			if ($('l_c_title').value.length > 32)
			{
				alert('很抱歉，标题不得超过32个字符');
				return;
			}
			var c_content = $('l_c_content').value.trim();
			if (c_content == '')
			{
				alert('很抱歉，请填写评论内容');
				$('l_c_content').focus();
				return;
			}
			else if (c_content.realLength() > 10000)
			{
				alert('很抱歉，评论内容不能超过10,000个字符（5,000个汉字）');
				$('l_c_content').focus();
				return;
			}
			if (self.base.min_len)
			{
				if (c_content.realLength() < self.base.min_len)
				{
					alert('很抱歉，评论内容不能少于' + self.base.min_len + '个字符（' + self.base.min_len / 2 + '个汉字）');
					$('l_c_content').focus();
					return;
				}
			}
			var bAnonymous = $('l_b_anonymous').checked;
			if (!islogging() && bAnonymous != true)
			{
				if (!confirm('很抱歉，您尚未登录，确定要匿名发表吗？'))
				{
					return;
				}
				bAnonymous = true;
			}
			makeFormValue(
			{
				b_anonymous:	bAnonymous ? '1' : '',
				c_site:			self.base.site,
				c_sort:			self.base.sort_en,
				c_title:		($('l_c_title').value == Comment.Configure.reply_default_title ? '' : $('l_c_title').value),
				c_content:		$('l_c_content').value,
				c_soul:			$('l_b_soul').checked ? '1' : '0',
				g_id:			self.base.comment_g_id
			});
			var commentck = getCookie('comment');
			if (commentck&&commentck== self.base.site+self.base.Id+$('l_c_content').value.trim()) {
					alert('谢谢您的回复，内容重复，请重新输入！');
					return;				
			}
			self.postData();
			setCookie('comment',self.base.site+self.base.Id+$('l_c_content').value.trim());
			return false;	
		};
	},
	bindBottomPostBtn: function()
	{
		if (!$('b_post_btn'))
		{
			return;
		}
		var self = this;
		$('b_post_btn').onclick = function()
		{
			if ($('b_c_title'))
			{
				if ($('b_c_title').value.length > 32)
				{
					alert('很抱歉，标题不得超过32个字符');
					$('b_c_title').focus();
					return;
				}
			}

			var c_content = $('b_c_content').value.trim();
			if (c_content == '')
			{
				alert('很抱歉，请填写评论内容');
				$('b_c_content').focus();
				return;
			}
			else if (c_content.realLength() > 10000)
			{
				alert('很抱歉，评论内容不能超过10,000个字符');
				$('b_c_content').focus();
				return;
			}
			if (self.base.min_len)
			{
				if (c_content.realLength() < self.base.min_len)
				{
					alert('书评内容不能少于' + self.base.min_len + '字符');
					$('b_c_content').focus();
					return;
				}
			}
			
			var bAnonymous = $('b_b_anonymous').checked;
			if (!islogging() && bAnonymous != true)
			{
				if (!confirm('很抱歉，您尚未登录，确定要匿名发表吗？'))
				{
					return;
				}
				bAnonymous = true;
			}
			makeFormValue(
			{
				b_anonymous:	bAnonymous ? '1' : '',
				c_site:			self.base.site,
				c_sort:			self.base.sort_en,
				c_title:		($('b_c_title').value == Comment.Configure.reply_default_title ? '' : $('b_c_title').value),
				c_content:		$('b_c_content').value,
				c_soul:			$('b_b_soul').checked ? '1' : '0',
				g_id:			self.base.comment_g_id,
				c_id:			self.base.commentId
			});
			var commentck = getCookie('comment');
			if (commentck&&commentck== self.base.site+self.base.Id+$('b_c_content').value.trim()) {
					alert('谢谢您的回复，内容重复，请重新输入！');
					return;				
			}
			self.postData();
			setCookie('comment',self.base.site+self.base.Id+$('b_c_content').value.trim());
			return false;
		};
	},
	bindBottomPostTypeEvent: function()
	{
		var self = this;
		if (!$('b_b_anonymous'))
		{
			return;
		}
		if (islogging())
		{
			if (self.base.name == 'MiniNormal')
			{
				$('b_login_frame').src = 'i_login.htm?b_login_frame&&true';
			}
			else
			{
				$('b_login_frame').src = 'i_login.htm?b_login_frame';
			}
			showElement('b_login_post');
			$('b_b_anonymous').checked = false;

			if($('to_login2'))
				hideElement('to_login2');
			
		}
		else
		{
			hideElement('b_login_post');
			$('b_b_anonymous').checked=true;
			if($('to_login2')){
				showElement('to_login2');
				$('to_login2').onclick = function(){
					$('b_login_frame').src = 'i_login.htm?b_login_frame';
					showElement('b_login_post');					
					$('b_b_anonymous').checked=false;					
				}
			}
		}
		$('b_b_anonymous').onclick = function()
		{
			if ($('b_b_anonymous').checked)
			{
				hideElement('b_login_post');
			}
			else
			{
				if (self.base.name == 'MiniNormal')
				{
					$('b_login_frame').src = 'i_login.htm?b_login_frame&&true';
				}
				else
					$('b_login_frame').src = 'i_login.htm?b_login_frame';
				showElement('b_login_post');
			}
			if (self.base.name == 'MiniNormal')
			{
				self.base.updateHeight();
			}
		}
		if ($('b_c_content'))
		{
			var self=this;
			var cc= getCookie('formContent');
			if(cc){
				var bcontent=self.base.site+self.base.Id+self.base.name;
				if(cc.substr(0, bcontent.length)==bcontent)
					$('b_c_content').innerHTML=cc.substr(bcontent.length);
			}		
			
			$('b_c_content').onfocus=function()
			{
				this.autoContentSave = setInterval(autosave,5000);			
			}
			function autosave()
			{
				
				var formContent= $('b_c_content').value.trim();
				if(formContent!='')
					setCookie('formContent',self.base.site+self.base.Id+self.base.name+formContent,1000*3600);
			}

		}


	},
	postData: function(action_url,tag)
	{
		if(!tag)
			showLoading('正在发送...');	
		var post_form = $('post_form');
		if(this.autoContentSave)
			clearInterval(this.autoContentSave);
		delCookie('formContent');
		if (action_url)
		{
			post_form.action = action_url;
		}
		else
		{
			post_form.action = Comment.Configure.postUrl;
		}
		post_form.target = 'post_async';
		post_form.method = 'post';
		post_form.submit();
	},

	fastReplyWords:
	[
		[
			'精彩，一针见血',
			'观点独到',
			'说得很对',
			'你说得有道理',
			'支持'
		],
		[
		 	'乱七八糟说什么',
			'你说得没道理',
			'简直是胡说八道',
			'请不要乱说',
			'反对'
		]
	],
	fastReply: function(btn, type, r_key, c_id)
	{
		var self = this;
		replyPost (self.fastReplyWords[type][4]);
		function replyPost(content)
		{
			makeFormValue(
			{
				b_anonymous:	(islogging() ? '' : '1'),
				c_id:			c_id,
				c_site:			self.base.site,
				c_sort:			self.base.data_commentinfo.sort_en,
				r_key:			r_key,
				r_type:			(type == 0 ? '3' : '4'),
				r_tips:			'',
				c_title:		'',
				c_content:		content,
				g_id:			self.base.comment_g_id
			});
			
			self.postData(Comment.Configure.postUrl,true);
		}
	},
	onError: function(msg)
	{
		alert(msg);
	},
	onSucc: function()
	{
		var self = this;
		setTimeout(reload, 300);
		function reload()
		{
			
			
			self.base.reload();
			if(self.base.jumptag&&self.base.name != 'ReplyPK'){
				window.location.replace('#load');
				self.base.jumptag=false;
			}				
			else
				window.location.replace('#reload');
		}
	},
	onAudit: function()
	{
		if ($('imgVerify'))
		{
			$('imgVerify').src = "http://ptlogin2.qq.com/getimage?aid=5001501&" + Math.random();
		}
		if ($('verifycode'))
		{
			$('verifycode').value = '';
		}
	},
	clearBottomInput: function()
	{
		$A($(
			'b_c_title',
			'b_c_content'
		)).each(function(elem)
		{
			if (elem)
			{
				elem.value = '';
			}
		});
	},
	logout: function()
	{
		var url = Comment.Configure.loginIframeUrl;
		if ($('l_login_frame'))
		{
			$('l_login_frame').src = Comment.Configure.logoutUrl + '?url=' + url + '?l_login_frame';
		}
		if ($('b_login_frame'))
		{
			$('b_login_frame').src = Comment.Configure.logoutUrl + '?url=' + url + '?b_login_frame';
		}
	},
	callback: function(url)
	{
		hideLoading();
		$('post_async').src = 'about:blank';
		
		var code = url.substr(url.indexOf('code=') + 5);
		if (code == '-')
		{
			code = -1;
		}
		code = code / 1;
		getFormValue('r_type');
		if (code == -1 && Comment.Post.r_type >= 3)
		{
			code = 0;
		}
		var errMsg = '';
		switch (code)
		{
		case -1:
			errMsg = '您的评论已提交审核，感谢您的参与！';
			this.onAudit();
			this.closePostLayer();
			this.clearBottomInput();
			break;
		case 0:
			errMsg = '提交成功，感谢您的参与！';
			this.onSucc();
			this.closePostLayer();
			this.clearBottomInput();
			break;
		case 1:
			errMsg = '很抱歉，您填写的内容不完整，请重新输入您的内容。';
			break;
		case 2:
			errMsg = '很抱歉，您尚未登录或登录已经过期，请先登录。';
			this.logout();
			break;
		case 3:
			errMsg = '您的评论已提交审核，感谢您的参与！';
			this.onAudit();
			this.closePostLayer();
			this.clearBottomInput();
			break;
		case 4:
			errMsg = '您的IP地址已暂时被屏蔽。';
			break;
		case 5:
			errMsg = '您的QQ号已暂时禁止在本评论系统发言。';
			break;
		case 6:
			errMsg = '很抱歉，您的QQ号码和密码不匹配。';
			break;
		case 7:
			errMsg = '很抱歉，系统繁忙，请稍候再试。';
			break;
		case 8:
			errMsg = '很抱歉，您发表的频率太快，请稍后再试。';
			break;
		case 9:
			errMsg = '很抱歉，您的验证码输入错误。';
			break;
		case 10:
			this.closePostLayer();
			this.clearBottomInput();
			break;
		case 100:
			errMsg = '您的评论已提交审核，感谢您的参与！';
			break;
		}
		if (errMsg != '')
		{
			this.onError(errMsg);
		}
	},
	openPostLayer: function()
	{
		var self = this;
		$('sPost').style.top  = self.base.name == 'iNormal'?((parent.document.documentElement.scrollTop - 150) < 0 ? 0 : (parent.document.documentElement.scrollTop - 150)):(ClsScreen.getBodyTop() + 100);
		$('sPost').style.left = self.base.name == 'iNormal'?(document.documentElement.scrollLeft + (document.documentElement.scrollWidth - 475)/2) : (ClsScreen.getBodyWidth() - 475)/2 + "px";
		$('sLayer').style.height = document.documentElement.scrollHeight+'px';
		$('sLayer').oncontextmenu = function(){return false};
		$('sLayer').className = 'dis';
		$('sPost').className= 'dis';
		this.auto = setInterval(setAuto, 200);
		function setAuto()
		{
			$('sPost').style.top = self.base.name == 'iNormal'?((parent.document.documentElement.scrollTop - 150) < 0 ? 0 : (parent.document.documentElement.scrollTop - 150)):(ClsScreen.getBodyTop() + 100);
		}
	},
	closePostLayer: function()
	{
		if (!$('sLayer'))
		{
			return;
		}
		$('sLayer').oncontextmenu = function(){return true};
		$('sLayer').className = 'undis';
		$('sPost').className = 'undis';
		showlogging();
		clearInterval(this.auto);
		this.bindBottomPostTypeEvent();
		this.clearAsyncForm();
		this.clearValue();
		Debug.log('clearAsyncForm');
	},
	beforeOpenPost: function(type, r_key, c_id, content)
	{
		this.bindTitleEvent();
		$('post_article').innerHTML = this.base.comment_title.left(20);
		if (islogging())
		{
			this.setPostTypeSelector('login_select');
		}
		else
		{
			this.setPostTypeSelector('anonymous_select');
		}
		switch (type)
		{
		case 0:
			hideElement('debate_id', 'reply_type', 'r_quote');
			makeFormValue(
			{
				c_id:			c_id
			});
			break;
		case 1:
			this.setjumptag();
			hideElement('debate_id', 'reply_type');
			$('post_quote').innerHTML = (content).stripTags();
			showElement('r_quote');
			this.setReplyType('middle');
			makeFormValue(
			{
				r_key:			r_key,
				r_type:			'2',
				c_id:			c_id
			});
			break;
		case 2:
			hideElement('reply_type', 'r_quote');
			showElement('debate_id');
			break;
		}
		this.openPostLayer();
	},
	setjumptag: function(){
		var self =this;
		self.base.jumptag=true;
	},
	beforeOpenPostEx: function(obj)
	{
		this.bindTitleEvent();
		if (obj.ref_title)
		{
			$('post_article').innerHTML = obj.ref_title.left(20);
		}
		if (islogging())
		{
			this.setPostTypeSelector('login_select');
		}
		else
		{
			this.setPostTypeSelector('anonymous_select');
		}
		hideElement('debate_id', 'reply_type');
		if (obj.ref_content)
		{
			$('post_quote').innerHTML = obj.ref_content.stripTags();
			showElement('r_quote');
		}
		else
		{
			hideElement('r_quote');
		}
		makeFormValue(obj);
		this.openPostLayer();
	},
	bindPostBtnEx: function()
	{
		if (!$('l_post_btn'))
		{
			return;
		}
		var self = this;
		$('l_post_btn').onclick = function()
		{
			if (!islogging() && !$('l_b_anonymous').checked)
			{
				alert('很抱歉，您尚未登录，请先登录');
				return;
			}
			var c_title = $('l_c_title').value.trim();
			if ($('l_c_title').value.length > 32)
			{
				alert('很抱歉，标题不得超过32个字符');
				$('l_c_title').focus();
				return;
			}
			var c_content = $('l_c_content').value.trim();
			if (c_content == '')
			{
				alert('很抱歉，请填写评论内容');
				$('l_c_content').focus();
				return;
			}
			else if (c_content.realLength() > 10000)
			{
				alert('很抱歉，评论内容不能超过10,000个字符（5,000个汉字）');
				$('l_c_content').focus();
				return;
			}
			
			makeFormValue(
			{
				b_anonymous:	$('l_b_anonymous').checked ? '1' : '',
				c_title:		($('l_c_title').value == Comment.Configure.reply_default_title ? '' : $('l_c_title').value),
				c_content:		$('l_c_content').value

			});
			var commentck = getCookie('comment');
			if (commentck&&commentck== self.base.site+self.base.Id+$('l_c_title').value.trim()) {
					alert('谢谢您的回复，内容重复，请重新输入！');
					return;				
			}
			Comment.Post.postData(Comment.Configure.userPostUrl);
			setCookie('comment',self.base.site+self.base.Id+$('l_c_title').value.trim());
			
			return false;
		};
	}
}

var NDEBUG = true;
var Debug = {
	init: function()
	{
		if (NDEBUG == true)
		{
			return;
		}
		var divDebug = $C('div');
		this.divDebug = divDebug;
		with (divDebug.style)
		{
			top = '10px';
			left = '10px';
			width = '300px';
			height = '200px';
			overflow = 'scroll';
			verticalAlign = 'top';
			position = 'absolute';
			backgroundColor = '#fff';
			padding = '5px';
			lineHeight = '110%';
		}
		document.getElementsByTagName('body')[0].appendChild(divDebug);
		this.auto = setInterval(setAuto, 200);
		function setAuto()
		{
			divDebug.style.top = document.documentElement.scrollTop + 10;
		}
		Debug.log('<b>Debug</b>');
		divDebug.ondblclick = function()
		{
			NDEBUG = true;
			Element.remove(divDebug);
		}
		this.height = 0;
	},
	log: function(str)
	{
		if (NDEBUG == true)
		{
			return;
		}
		var now = new Date();
		this.divDebug.innerHTML += '[' + now.getHours() + ':' 
			+ now.getMinutes() + ':'
			+ now.getSeconds() + '] ' + str + '<br>';
		this.divDebug.scrollTop = 10000000;
	}
}

var divLoading = null;
function showLoading(action)
{
	if (!divLoading)
	{
		divLoading = $C('div');
		divLoading.className = 'loading';
		document.getElementsByTagName('body')[0].appendChild(divLoading);
	}
	if (!action)
	{
		divLoading.innerHTML = '正在读取...';
	}
	else
	{
		divLoading.innerHTML = action;
	}
	divLoading.style.top = document.documentElement.scrollTop;
	divLoading.style.left = '0px';
	divLoading.style.display = 'block';
}
function hideLoading()
{
	if (!divLoading)
	{
		return;
	}
	divLoading.style.display = 'none';
}
function showElement()
{
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if ($(element))
		{
			$(element).style.display = 'block';
		}
	}
}
function hideElement()
{
	for (var i = 0; i < arguments.length; i++)
	{
		var element = arguments[i];
		if ($(element))
		{
			$(element).style.display = 'none';
		}
	}
}
function getFormValue(name)
{
	$A($('post_form').getElementsByTagName('input')).each(function(elem)
	{
		if (elem.name == name)
		{
			Comment.Post.r_type = elem.value;
			return elem.value;
		}
		else
		{
			return null;
		}
	});
}
function makeFormValue(name2Value)
{
	Debug.log('makeFormValue start');
	$A($('post_form').getElementsByTagName('input')).each(function(elem)
	{
		if (name2Value[elem.name] != null)
		{
			elem.value = name2Value[elem.name];
		}
		Debug.log(elem.name + ': ' + elem.value);
	});
	Debug.log('makeFormValue end');
}
function noCacheUrl()
{
	return '?cache=' + rndNum(9);
}
function rndNum(n)
{
    var rnd= '1.';
    for(var i = 0; i < n; i++)
        rnd += Math.floor(Math.random() * 10);
    return rnd;
}
var sUrl = window.location.href.toString();
var sDomain = sUrl.substring(7, sUrl.indexOf('/', 7));
var sPath = sUrl.substring(sUrl.indexOf('/', 7));
var sParam = '';
if (window.location.search.substr(0, 1) == '?') {
	if (sUrl.indexOf('#') == -1)
		sParam = window.location.search.substr(1);
	else if (sUrl.indexOf('?') < sUrl.indexOf('#'))
		sParam = window.location.search.substr(1);
	else
		sParam = window.location.hash.substr(1);
} else if (window.location.hash.substr(0, 1) == '#') {
	sParam = window.location.hash.substr(1);
}
var objParam = sParam.toQueryParams();
document.domain = 'qq.com';

var initWith = {
	'comment':		'Normal',
	'i_comment':		'MiniNormal',
	'i_comment2':		'MiniNormal1',
	'comment_group':	'Group',
	'comment_debate':	'Debate',
	'comment_debate_ifr':	'DebateIfr',
	'comment_reply_pk':	'ReplyPK',
	'reply':		'Reply',
	'comment_user':		'UserReply',
	'comment_user2':	'UserReply2',
	'list':			'List',
	'list2':		'ListMix',
	'i_minicomment':	'iNormal',
	'i_comment_stock': 	'MiniNormal',
	'comment_ojs08':		'Normal',
	'comment_group_ojs08':		'Group'
};

window.onload = function()
{
	Comment.Start();
}

Comment.Start = function()
{
	Debug.init();
	for (var url in initWith)
	{
		if (sUrl.indexOf('/' + url + '.htm') != -1)
		{
			if (url == 'list')
			{
				Comment.Page[initWith[url]].load(sUrl);
			}
			else
			{
				Comment.Page[initWith[url]].load(sParam.toQueryParams());
			}
		}
	}

	document.body.onclick = function()
	{
		if ($('fastLayer'))
		{
			$('fastLayer').style.display = 'none';
		}
	}
}

Comment.HotList = 
{
	siteObject:	{
		'news':	'新闻',
		'ent':	'娱乐',
		'finance':	'财经',
		'tech':	'科技',
		'auto':	'汽车',
		'gamezone':	'游戏',
		'edu':	'教育',
		'book':	'读书',
		'lady':	'女性',
		'astro':	'星座',
		'sports':	'体育',
		'comic':	'动漫',
		'luxury':	'时尚',
		'joke':	'笑话',
		'cq':	'重庆',
		'xian':	'西安',
		'view':	'说吧',
		'kid':	'儿童',
		'2008': '奥运',
		'cd':'大成网',
		'house':'房产'
	},
	getRandomSite: function()
	{
		if (!this.siteArray)
		{
			this.siteArray = new Array();
			for (var site_en in this.siteObject)
			{
				this.siteArray.push(site_en);
			}
		}
		var site_sum = this.siteArray.length;
		var rnd_site = Math.floor(Math.random() * site_sum);
		return this.siteArray[rnd_site];
	},
	bindTopHotList: function(container, site)
	{
		var topSiteSum = 6;
		if (site == 'kid')
		{
			topSiteSum = 1;
		}
		var topSite = new Object();
		if (site != '')
		{
			if (this.siteObject[site])
			{
				topSite[site] = this.siteObject[site];
				topSiteSum--;
			}
		}
		
		while (topSiteSum > 0)
		{
			var rnd_site = this.getRandomSite();
			if (topSite[rnd_site])
			{
				continue;
			}
			topSite[rnd_site] = this.siteObject[rnd_site];
			topSiteSum--;
		}
		
		var hot_index = 0;
		var hot_header = '';
		var hot_body = '';
		for (var site_en in topSite)
		{
			hot_header += '<p' + (hot_index == 0 ? ' class="c"' : '') + ' onclick="getMe(this)">' + topSite[site_en] + '</p>';
			hot_body += '<dd' + (hot_index != 0 ? ' class="undis"' : '') + ' id="Hot_Top_' + site_en + '"></dd>';
			hot_index++;
		}
		var hot_html = '<dl><dt>' + hot_header + '</dt>' + hot_body + '</dl>';
		$(container).innerHTML = hot_html;
		
		for (var site_en in topSite)
		{
			this.bindTopSite('Hot_Top_' + site_en, '/c/async_html/' + site_en + '_top.htm');
		}
	},
	bindRightHotList: function(container, site)
	{
		var topSiteSum = 3;
		if (site == 'kid')
		{
			topSiteSum = 1;
		}
		var topSite = new Object();
		if (site != '')
		{
			if (this.siteObject[site])
			{
				topSite[site] = this.siteObject[site];
				topSiteSum--;
			}
		}
		
		while (topSiteSum > 0)
		{
			var rnd_site = this.getRandomSite();
			if (topSite[rnd_site])
			{
				continue;
			}
			topSite[rnd_site] = this.siteObject[rnd_site];
			topSiteSum--;
		}
		
		var hot_body = '';
		for (var site_en in topSite)
		{
			hot_body += '<dl><dt>' + topSite[site_en] + '热评</dt><div id="Hot_Right_' + site_en + '"></div></dl>';
		}
		$(container).innerHTML = hot_body;
		
		for (var site_en in topSite)
		{
			this.bindTopSite('Hot_Right_' + site_en, '/c/async_html/' + site_en + '_right.htm');
		}
	},
	bindTopSite: function(container, url, pre)
	{
		if (pre == undefined)
			pre = '';
		function onSucc(response)
		{
			$(container).innerHTML = pre + response.responseText;
		}
		function onError()
		{
			$(container).innerHTML = pre;
		}
		new Ajax.Request(
			 url,
			 {
				 method: 		'get',
				 onSuccess: 	onSucc,
				 onFailure:		onError
			 }
		);
	}
}

var ClsScreen = {
	getPageWidth: function()
	{
		return document.documentElement.scrollWidth || document.body.scrollWidth || 0;
	},

	getPageHeight: function()
	{
		return document.documentElement.scrollHeight || document.body.scrollHeight || 0;
	},

	getBodyWidth: function()
	{
		return document.documentElement.clientWidth || document.body.clientWidth || 0;
	},

	getBodyHeight: function()
	{
		return document.documentElement.clientHeight || document.body.clientHeight || 0;
	},

	getBodyLeft: function()
	{
		return window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft || 0;
	},

	getBodyTop: function()
	{
		return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
	},

	getBody: function()
	{
		return {
			width	: this.getBodyWidth(),
			height	: this.getBodyHeight(),
			left	: this.getBodyLeft(),
			top	: this.getBodyTop()
		};
	},

	getScreenWidth: function()
	{
		return window.screen.width;
	},

	getScreenHeight: function()
	{
		return window.screen.height;
	}
};


function E(obj){return document.getElementById(""+obj+"")}
function setSize(v){
	E('Content').className="f"+v+"";
	if(v==12)
		E('fontCtrl').innerHTML="<a href='javascript:setSize(14)' class='b1'>大字</a>/小字";
	if(v==14)
		E('fontCtrl').innerHTML="大字/<a href='javascript:setSize(12)' class='b1'>小字</a>";
}





function getSite(o){
        var obj = o;
        var objS = obj.offsetLeft;
        while(obj!=obj.offsetParent && obj.offsetParent){
                obj=obj.offsetParent;
                if(obj.tagName=="span")objS += obj.offsetLeft;
        }
        return objS;
}

function getMe(obj){
	var theTit=E('comment_info').getElementsByTagName('p');
	var theDD=E('comment_info').getElementsByTagName('dd');
	var num=theTit.length;
	for(var i=0;i<num;i++){		
		theTit[i].className='';
		obj.className='c';
		theDD[i].className='undis';
		if(theTit[i].className=='c')
			theDD[i].className='dis';
		}
}

function picCtrl(obj)
{
	var tWidth = 401;
	var pWidth = 183;
	var All = tWidth + pWidth;
	var picWidth = obj.width; 
	var picHeight = obj.height; 
	if (picWidth / picHeight > 1.6)
	{
		obj.width = 174;
		obj.height = 150;
		return true;
	}
	else
	{
		obj.width = picWidth * 150 / picHeight;
		obj.height = 150;
		E('comment_pic').style.width = obj.width;
		E('comment_text').style.width= All - obj.width;
		return true;
	}
}

function showSiteNav(site)
{
	if (site == 'kid')
	{
		return;
	}
	document.write('<a href="http://www.qq.com" target="_blank" class="b0">腾讯首页</a> '
		+ '<a href="http://pinglun.qq.com" target="_blank" class="b0">评论首页</a> '
		+ '<a href="http://comment1.news.qq.com/comment.htm?site=news&id=515622" target="_blank" class="b0">用户反馈</a>');
}

function showLogo(site)
{
	if (site == 'kid')
	{
		document.write('<a href="http://kid.qq.com" target="_blank"><img src="http://img1.qq.com/pinglun/pics/7715/7715483.jpg" /></a>');
	}
	else
	{
		document.write('<a href="http://www.qq.com" target="_blank"><img src="http://img1.qq.com/pinglun/pics/7689/7689781.gif" /></a>');
	}
}
	

function comptime(beginTime,endTime,tag){
	var showtime=beginTime;
	var beginTimes=beginTime.substring(0,10).split('-');	
	if(showtime.indexOf("-")<0){
		var tmpDate = new Date(beginTime*1000);
		var vMonth=tmpDate.getMonth()+1;
		var vdate=tmpDate.getDate();
		var vHour = tmpDate.getHours();
		var vMin = tmpDate.getMinutes();
		showtime=tmpDate.getYear()+"-"+((vMonth<10 ? "0" + vMonth : vMonth) )+"-"+(vdate<10 ? "0" + vdate : vdate)+" "+(vHour<10 ? "0" + vHour : vHour)+":"+(vMin<10 ? "0" + vMin : vMin);
		var secondNum = parseInt((endTime-beginTime*1000)/1000);	
	}
	else{	
		beginTime=beginTimes[1]+'-'+beginTimes[2]+'-'+beginTimes[0]+' '+beginTime.substring(10,19);
		var secondNum = parseInt((endTime-Date.parse(beginTime))/1000);
	}
	if(secondNum>=0&&secondNum<60){
		return secondNum+'秒前';
	}
	else if (secondNum>=60&&secondNum<3600){
		var nTime=parseInt(secondNum/60);
		return nTime+'分钟前';
	}
	else if (secondNum>=3600&&secondNum<3600*24){
		var nTime=parseInt(secondNum/3600);
		return nTime+'小时前';
	}
	else if (secondNum>=3600*24&&secondNum<3600*24*7){
		var nTime=parseInt(secondNum/(3600*24));
		return nTime+'天前';
	}
	else{
		if (tag)
		{
			return showtime.substr(0,16);
		}
		return showtime;
	}
}

function StringBuffer() {
	this._strings_ = new Array;
}

StringBuffer.prototype.append = function(str) {
	this._strings_.push(str);
}

StringBuffer.prototype.toString = function() {
	return this._strings_.join("");
}

StringBuffer.prototype.reset= function() {
	this._strings_ = new Array;
}

function GetUserLevel(pt) {
	if (0<=pt&&pt<600)
	{
		return '等级一';
	}
	else if(600<=pt&&pt<1800)
	{
		return '等级二';
	}
	else if(1800<=pt&&pt<3600)
	{
		return '等级三';
	}
	else if(3600<=pt&&pt<6000)
	{
		return '等级四';
	}
	else if(6000<=pt&&pt<10800)
	{
		return '等级五';
	}
	else if(10800<pt)
	{
		return '等级六';
	}
	else 
		return '等级一';
}

function getOs()
{
	if(navigator.userAgent.indexOf("MSIE")>0)return 1;
	if(isFirefox=navigator.userAgent.indexOf("Firefox")>0)return 2;
	if(isSafari=navigator.userAgent.indexOf("Safari")>0)return 3;  
	if(isCamino=navigator.userAgent.indexOf("Camino")>0)return 4;
	if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0)return 5;
	return 0;
}

function fixFF(login_frame)
{
	if(getOs() == 2)
	{
		if(islogging())$(login_frame).height = 20;
		else $(login_frame).height = 105;
		$(login_frame).setAttribute('style', '');
	}
}

function addFavorite(href, title)
{
	switch(getOs())
	{
		case 1:
			window.external.AddFavorite(href, title);
			break;
		case 2:
			window.sidebar.addPanel(title, href, '');
			break;
		default:
			break;
	}
}
/*  |xGv00|560fb7f7d0083f33261a25fff3eeb214 */