Mys.ReplyList = function(config)
{
	Mys.ReplyList.superclass.constructor.call(this, config);
	
	this.pager = new Mys.TemplatePager({
		kk :2,
		elTemplate : (new Ext.Template([
			'<table class="pager-table" height="5" border="0" cellspacing="0" cellpadding="0">',
				'<tr>',
					'<td height="15" class="{firstClassName} page">',
						'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trilg.gif"/>',
						'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trilg.gif"/>',
						' <a href="#" class="txt1266" onfocus="this.blur();">맨앞</a>',
					'</td>', 
					
					'<td class="{previousClassName} page">',
					'<span class="mys-page-partition">|</span>',
					'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trilg.gif"/>',
					' <a href="#" class="txt1266" onfocus="this.blur();">이전</a>',
					'<span class="mys-page-partition">|</span>',
					'</td>',
					
					'<td class="{pagingClassName}"></td>',
					'<td class="{nextClassName} page">',
						'<a href="#" class="txt1266" onfocus="this.blur();">다음</a> ',
						'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trir.gif"/>',
					'</td>',
					'<td class="{lastClassName} page">',
						'<span class="mys-page-partition">|</span>',
						'<a href="#" class=" txt1266" onfocus="this.blur();">맨끝</a> ',
						'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trir.gif"/>',
						'<img width="3" vspace="3" height="5" align="absmiddle" class="forward" src="../images/common/icon_trir.gif"/>',
					'</td>',
				'</tr>',
			'</table>'
		])).compile(),
			
		activeClassName : "thispage",
		disabledClassName : "pageoff",
		
		pageTemplate : (new Ext.Template('<span class="page"><a href="#reply" class="{pageClassName} txt1266b" value="{page}">{page}</a></span><span class="mys-page-partition">|</span>')).compile(),
		activeTemplate : (new Ext.Template('<span class="page {activeClassName}">{page}</span><span class="mys-page-partition">|</span>')).compile()
	});
	this.on("move", function(start, maxRow){
		Global.modelReply.getList(this.itemData.item_id, start, maxRow, this.onMove, this);
	}, this);
};

Ext.extend(Mys.ReplyList, Mys.TemplateList, {
	footerTemplate : (new Ext.Template([
		'<table class ="pg_er" width="100%" border="0" cellspacing="0" cellpadding="0">',
			'<tr bgcolor="#e7e7e7">',
				'<td height="2" colspan="2"></td>',
			'</tr>',
			'<tr>',
				'<td height="1" colspan="2"></td>',
			'</tr>',
			'<tr>',
				'<td height="10" colspan="2" bgcolor="#f0f0f1"></td>',
			'</tr>',
			'<tr>',
				'<td bgcolor="#f0f0f1" style="padding-left:10px"><textarea name="reply_text" id="reply_text" style="height:49px"></textarea></td>',
			'<td width="75" bgcolor="#f0f0f1"><button type="submit" name="submitBtn" class="btn" value="" style="border: medium none ; background:url(../images/common/btn_writecomment.gif);width:69px;height:53px;"></button></td>',
			'</tr>',
			'<tr>',
				'<td height="25" colspan="2" align="right" bgcolor="#f0f0f1" style="padding-right:5px" class="txt1188"><span class="txt11f6c txt11f6b text-length">0</span><span class="txt11f6c">/600 bytes(한글 300자)</span></td>',
			'</tr>',
			'<tr>',
				'<td height="1" colspan="2"></td>',
			'</tr>',
			'<tr bgcolor="#e7e7e7">',
				'<td height="2" colspan="2"></td>',
			'</tr>',
		'</table>',
	])).compile(),
	
	elTemplate : (new Ext.Template([
		//비었을때
		'<table class="{emptyClassName}" width="100%" border="0" cellspacing="0" cellpadding="0">',
			'<tr>',
				'<td height="60" align="center" class="txt1266">등록된 댓글이 없습니다.</td>',
			'</tr>',
		'</table>',
		'<div class="{bodyClassName}"></div>',
		'<div class="{pagerClassName}"></div>',
		'<form style="margin : 0px"class="{footerClassName}" onSubmit="return false;">',
		'</form>',
		'<div class="{loadingClassName}"><img class="mys-loading-img" src="/images/common/loadinbar.gif"/></div>'
	])).compile(),
	itemClass : Mys.ReplyItem,
	maxRow : 100,
	
	setEvents : function()
	{
		this.footerEl.on("submit", this.add, this);
		
		if(this.footerEl.dom.reply_text)
		{
			this.textLengthEl = this.footerEl.child(".text-length");
			Ext.fly(this.footerEl.dom.reply_text).on("keyup", function(e, el){
				this.textLengthEl.update(el.value.getByte());
			}, this);
			this.footerEl.on("reset", function(){
				this.textLengthEl.update(0);
			}, this);
			
			Ext.fly(this.footerEl.dom.reply_text).on("focus", function(e, el){
				if(!Global.Session.checkLogin(ViewManager.getViewURL(this.itemData)))
					this.footerEl.dom.reply_text.blur();
			}, this);
		}
	},
	
	add : function()
	{
		if(!Global.Session.checkLogin(ViewManager.getViewURL(this.itemData)))
			return ;
		
		if(!this.footerEl.dom.reply_text.value){
			alert("내용을 입력하세요");
			return false;
		}
		
		Global.modelReply.add(this.itemData.item_id, null, this.footerEl.dom.reply_text.value, this.maxRow, this.onAdd, this);
	},
	
	onAdd : function(data)
	{
		if(data && data.response.code == 100)
			this.footerEl.dom.reset();
		else
			return false;
		
		this.onMove(data);
	},
	
	onMove : function(data)
	{
		if(data && data.response.code == 100)
		{
			if(this.pager)
				this.pager.page = Math.ceil(data.response.reply_start / this.maxRow) + 1 || 1;
			
			this.update(data.response.reply, data.response.reply_total);
		}
		else
			this.empty();
	},
	
	setItemData : function(data)
	{
		this.itemData = data;
	},
	
	update : function(data, total)
	{
		if(Mys.ReplyList.superclass.update.call(this, data, total) === false)
			return false;
		
		if(this.pager)
		{
			if(this.totalRow > this.maxRow)
				this.pager.el.show();
			else
				this.pager.el.setStyle("display", "none");
		}
	}
});
