Mys.EventReplyList = function(config)
{
	Mys.ReplyList.superclass.constructor.call(this, config);
	
	this.createPager();
	this.on("move", function(start, maxRow){
		Global.modelEventReply.getList(this.eventID, start, maxRow, this.onMove, this);
	}, this);
};

Ext.extend(Mys.EventReplyList, Mys.ReplyList, {
	checkLogin : true,
	elTemplate : (new Ext.Template([
		'<form style="margin : 0px"class="{footerClassName}" onSubmit="return false;"></form>',
		'<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>',
		'<div class="{loadingClassName}"><img class="mys-loading-img" src="/images/common/loadinbar.gif"/></div>'
	])).compile(),
	
	footerTemplate : (new Ext.Template([
		'<textarea name="reply_text" class="reply-text"></textarea>',
		'<button type="submit" class="reply-submit"></button>',
		'<div class="text-count"><span class="text-length">0</span><span class="text-max">/600 bytes(한글 300자)</span></div>'
	])).compile(),
	maxRow : 10,
	
	createPager : function(){
		this.pager = new Mys.TemplatePager({
			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()
		});
	},
	
	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(this.checkLogin && !Global.Session.checkLogin())
					this.footerEl.dom.reply_text.blur();
			}, this);
		}
	},
	
	add : function()
	{
		if(this.checkLogin && !Global.Session.checkLogin())
			return ;
		
		if(!this.footerEl.dom.reply_text.value){
			alert("내용을 입력하세요");
			return false;
		}
		
		Global.modelEventReply.add(this.eventID, null, this.footerEl.dom.nick ? this.footerEl.dom.nick.value : '', this.footerEl.dom.reply_text.value, this.maxRow, this.onAdd, this);
	},
	
	setEventID : function(eventID)
	{
		this.eventID = eventID;
	}
});
