/**
 * @package iCMS
 * @copyright 2007-2010, iDreamSoft
 * @license http://www.idreamsoft.cn iDreamSoft
 * @author coolmoo <idreamsoft@qq.com>
**/
var iCMS = iCMS||{};
iCMS.config = {
	commURI:'/action.php?do=comment&callback=?&action=',
	diggURI:'/action.php?do=digg&callback=?&action='
}
iCMS.digg = function (act,aid,cid){
	if(act=='up'||act=='against'){
		var pars = {'id':aid,'cid':cid,'ajax':'1'};
		$.getJSON(this.publicURL+this.config.commURI+act,pars, function(json){
		 	if(json.state=='1'){
		 		var obj=$("#"+act+"_"+cid);
			 	var Num=parseInt(obj.text());
			 	obj.text(Num+1); 
		 	}else if(json.state=='0'){
		 	 	alert(json.text);
		 	 }
		});
		return;
	}else if(act=='good'||act=='bad'){
		var pars = {'id':aid};
		$.getJSON(this.publicURL+this.config.diggURI+act,pars, function(json){
		 	if(json.state=='1'){
		 		var obj=$("#"+act+"_"+aid);
			 	var Num=parseInt(obj.text());
			 	obj.text(Num+1); 
		 	}else if(json.state=='0'){
		 	 	alert(json.text);
		 	 }
		});
		return;
	}
}
iCMS.quote = function (id,floor){
	$("#iQuote").val(id);
	$("#iFloor").val(parseInt(floor)+1);
	$("a[id^=unquote]").hide();
	$("a[id^=quote]").show();
	$("#quote"+id).hide();
	$("#unquote"+id).show();
	this.addUBB('');
}
iCMS.unquote = function (id){
	$("#iQuote").val(0);
	$("#iFloor").val(0);
	$("#quote"+id).show();
	$("#unquote"+id).hide();
}
iCMS.reply = function (cid){
		this.addUBB('[reply]---[i]回复[/i] ' + $("#lou_" + cid).text() + ' [' + $("#comment_username_" + cid).text() + '] 时间:[' + $("#comment_time_" + cid).text() + "]---[/reply]\r\n");
}
iCMS.addUBB = function (text){
	$('#iCommenText').val(text).focus();
}
iCMS.smiley = function (sid){
	var cText=$('#iCommenText').val();
	$('#iCommenText').val(cText+"[s:"+sid+"]").focus();
}
iCMS.setcookie = function (cookieName, cookieValue, seconds, path, domain, secure) {
	var expires = new Date();
	expires.setTime(expires.getTime() + seconds);
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}
iCMS.getcookie = function (name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : unescape(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
iCMS._cookie = function (name) {
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	return cookie_start == -1 ? '' : decodeURI(document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length)));
}
iCMS.userinfo = function (name) {
	var u = this._cookie(name);
	if(u){
		var info ='<a href="'+this.URL+'/usercp.php" target="_blank">'+u+'</a> '+
		'<a href="javascript:void(0);" onclick="return iCMS.logout();">退出</a>';
		$("#iUserInfo").html(info).show();
		$("#iUserLogin").hide();
		return true;
	}
	return false;
}
iCMS.logout = function () {
	$.get(this.URL+"/ajax.php?do=logout");
	$("#iUserInfo").empty().hide();
	$("#iUserLogin").show();
}
function textareasize(obj,height) {
	height=height||70;
	if(obj.scrollHeight > height) {
		obj.style.height = obj.scrollHeight + 'px';
	}
}