/*
 * created by hobo
 */

try
{
	document.domain = "qq.com";
}
catch (e)
{
}

var Comment = new Object();

Comment.Configure = {
	version: "1.0",
	newline: "\n",
	index_domain: "http://comment3.qq.com/"
};

function _cbCommnetInfo(){
	return {
		origin_count: arguments[7],
		total_count: arguments[6],
		top_count: arguments[8]
	}
}

function _reply(){
	return {
		agree: arguments[13],
		disagree: arguments[14],
		middle: arguments[15],
		original: arguments[16]+arguments[17]+arguments[18],
		agree_o: arguments[16],
		disagree_o: arguments[17]
	};
}

function GetPkSum(text){
	try{
		return ret = eval(text);
	}catch(e){
		return {};
	}
}

function GetSum(text){
	try{
		return ret = eval(text);
	}catch(e){
		return {};
	}
}

Comment.UrlFactory = {
	getCommentSumUrl: function(site, id, nocache)
	{
		return 'http://comment5.qq.com/php/gcomment.php?site='
			+ site + '&c_id=' + id
			+ (nocache?('&t='+new Date().getTime()):'');
	},
	
	getReplySumUrl: function(key, nocache)
	{
		return 'http://comment5.qq.com/php/greply.php?r_id=' + key
			+ (nocache?('&t='+new Date().getTime()):'');
	}
};

Comment.Proxy = {
	printCommentSum: function(site, id, container)
	{
		var commentSumUrl = Comment.UrlFactory.getCommentSumUrl(site, id, true);
		ProxyLoader.load(commentSumUrl, {
			onSuccess: function(xmlHttp)
			{
				$(container).innerHTML = GetSum(xmlHttp.responseText)['total_count'];
			},
			onFailure: function()
			{
				$(container).innerHTML = 0;
			}
		});
	},

	printReplySum: function(site, id, key, container)
	{
		var commentReplyUrl = Comment.UrlFactory.getReplySumUrl(key, true);
		ProxyLoader.load(commentReplyUrl, {
			onSuccess: function(xmlHttp)
			{
				$(container).innerHTML = GetPkSum(xmlHttp.responseText)['agree'];
			},
			onFailure: function()
			{
				$(container).innerHTML = 0;
			}
		});
	}
};

//Up
var Up = function(config)
{
	this.__construct(config);
};

Up.prototype = {
	__construct: function(config)
	{
		this._config = config;
		this.init();
	},

	init: function()
	{
		Comment.Proxy.printReplySum(this._config.site, this._config.id,
			this._config.key, this._config.sum_container);

		$(this._config.btn_container).innerHTML = "<a href='javascript:;' onclick='" +
			this._config.instance + ".up()'>" + 
			this._config.btn_text+"</a>";
	},

	up: function()
	{
		if (!!Up.curTimer)
		{
			//alert("很抱歉，您的操作频率过快，请您稍后再试");
			//return;
		}
		else
		{
			Up.curInstance = this._config.instance;
			Up.curTimer = this._config.instance;
			window.setTimeout(function(){Up.curTimer = null;}, 10000);

			$("post_form").action = "http://input.comment.qq.com/post.cmt";
			$("post_form").c_site.value = this._config.site;
			$("post_form").c_id.value = this._config.id;
			$("post_form").r_key.value = this._config.key;
			$("post_form").r_type.value = 3;
			$("post_form").submit();
		}

		$(this._config.btn_container).innerHTML = this._config.btn_done_text;
	},

	done: function()
	{
		$(this._config.sum_container).innerHTML = parseInt($(this._config.sum_container).innerHTML) + 1;
		Up.curInstance = null;
	}
};

Up.curInstance = null;
Up.curTimer = null;
Up.arrInstance = new Array();

Up.init = function(config)
{
	var len = Up.arrInstance.length++;
	config.instance = "Up.arrInstance[" + len + "]";
	Up.arrInstance[len] = new Up(config);
};

Comment.Post = {
	callback: function(url)
	{
		$('post_async').src = 'about:blank';

		if (!!Up.curInstance)
		{
			eval(Up.curInstance + ".done()");
		}
	}
};/*  |xGv00|a635d202943b4bf690d45a5d11794abd */