Mys.ChannelWriteCtrl = function(config)
{
		Mys.ChannelWriteCtrl.superclass.constructor.call(this, config);
}

Ext.extend(Mys.ChannelWriteCtrl, Mys.LogWriteCtrl,
{
	initFlag : true,
	writeBoxHtml : '<form class="writeLogBox" onsubmit="return false">' +
										'<div class="typeBox">' +
											'<a href="#" onclick="return false" title="전체" class="main">전체</a>' +
											'<a href="#" onclick="return false" title="토크" class="text">토크</a>' +
											'<a href="#" onclick="return false" title="링크" class="link">링크</a>' +
											'<a href="#" onclick="return false" title="사진" class="photo">사진</a>' +
											'<a href="#" onclick="return false" title="동영상" class="video">동영상</a>' +
											((Global.contentsItem)?'<a href="#" onclick="return false" title="리뷰" class="review">리뷰</a>':'') +			
											((PAGE_USER_ID == "asaag")?'<a href="#" onclick="return false" title="상품" class="minishop_photo">상품</a>':'') +
											((Global.hasTag)?'<a href="#" onclick="return false" title="태그" class="tag">태그</a>':'') +
											
											((Global.isMinishop)?'<span class="sponsor">이용 전에 꼭 읽어주세요. <img src="/images/sponsor/btn_whatsshop.gif" alt="쇼핑채널?" onclick="show'+PAGE_USER_ID.toUpperFirst()+'Notice()"/></span>':'') +

											/*'<a href="#" onclick="return false" title="질문" class="question">질문</a>' +*/
										'</div>' +


									'<div class="writeAreaBox">' +
										'<div class="memo">'+
											'<textarea name="memo"/></textarea>'+
										'</div>'+
										'<a href="#" class="writeSaveBtn" onclick="return false"><span>글쓰기</span></a>'+
									'</div>' +

									'<div class="gradeBox">'+
										'<p class="selectBox">'+
											'<a href="#" onclick="return false">전체공개</a>'+
										'</p>'+
										'<span>공개설정</span>'+
									'</div>'+

									'<ul class="gradeList list none">' +
										'<li><a href="#" class="public" onclick="return false">전체공개</a></li>' +
										'<li><a href="#" class="group" onclick="return false">채널공개</a></li>' +
										'<li><a href="#" class="friend" onclick="return false">친구공개</a></li>' +
										'<li><a href="#" class="private" onclick="return false">비공개</a></li>' +
									'</ul>' +
								'</form>',
	
	exceptCtrlArr : ["main", "text", "tag"],
			
	initialize : function(config)
	{			
			Mys.ChannelWriteCtrl.superclass.initialize.call(this, config);
	
			this.setSponsor();
					
			this.addEvents({'changeList' : true});
	},
			
	setSponsor : function()
	{
	},
			
	setVar : function()
	{
			this.selectedGrade = this.defaultGrade;
			this.setGradeName(this.selectedGrade);
	
			if(this.initFlag)
			{
			// 현재 선택된 컨텐츠 종류 버튼 - default text
				this.currentCtrlEl = this.writeBox.child(".typeBox a.main", true);
				this.addSelect(this.currentCtrlEl);
				this.currentCtrlName = "main";
				this.initFlag = false;
			}
	},
			
	removeVar : function(){
			var ctrl;

			this.memoEl.dom.value = "";

			this.contentsBoxEl = null;

			// contents box hide
			if(this.currentCtrlName && (ctrl = this.getContentsCtrl(this.currentCtrlName))){ ctrl.hideBox(); ctrl.showBox(); }

			// temp image remove
			photoCtrl = this.getContentsCtrl("photo");
			if(photoCtrl && photoCtrl.hasImage() && this.currentCtrlName	!= "photo")
					photoCtrl.removeImage();

			this.contentsItem = null;
			this.contentsCategory = null;
	},						
	removeSelect : function(el)
	{
			if(!el)
					return;
			
			Ext.fly(el).removeClass("select");
	},

	addSelect : function(el)
	{
			if(!el)
					return;
			
			Ext.fly(el).addClass("select");
	},
			
	onClickContentsBtn : function(evt, t)
	{			
			while(t.tagName != "A")
					t = t.parentNode;
			
			if(!t.className || this.isModify)
				return;
			var ctrlName;
			ctrlName = t.className.replace(/select|last/gi, "").trim();
						
			this.fireEvent("changeList", ctrlName);
			
			// 현재 선택된 탭과 선택한 탭이 같을 때 함수 종료
			if(this.currentCtrlName == ctrlName)
					return;

			// show writeAreaBox			
			if(!this.writeAreaEl.isVisible()) this.writeAreaEl.setStyle("display", "block");


			// change font-weight
			this.removeSelect(this.currentCtrlEl);
			this.addSelect(t);
					
			// hide contentsBox
			if(this.currentCtrlName && this.exceptCtrlArr.indexOf(this.currentCtrlName) == -1 && EXT_SESSION.isLog())
			{
				var currentCtrl = this.getContentsCtrl(this.currentCtrlName);
				currentCtrl.hideBox();
			}

			// set value
			this.currentCtrlName = ctrlName;
			this.currentCtrlEl = t;

			// 로그인이 안되있으면 컨트롤을 생성하지 않는다. 리스트만 변경
			if(!EXT_SESSION.isLog())
					return;

			// excepCtrlArr에 있는 ctrl은 컨트롤를 생성하지 않는다.
			if(this.exceptCtrlArr.indexOf(ctrlName) != -1)
			{
					if(ctrlName == "tag")
							this.writeAreaEl.setStyle("display", "none");
					return;
			}
			// make contentsCtrl
			if(!this.hasContentsCtrl(ctrlName)) this.makeContentsCtrl(ctrlName);

			// show contentsBox
			var ctrl = this.getContentsCtrl(ctrlName);
			
		
			// asaag exception
			if(ctrlName == "minishop_photo" && PAGE_USER_ID == "asaag" && EXT_SESSION.getID() != "asaag@pptree.co.kr")
			{
					ctrl.hideBox();
					this.writeAreaEl.setStyle("display", "none");
					return;
			}
						
			ctrl.toggleBox();
	}			
});

Mys.ReviewContentsCtrl = function(resultCtrl, container)
{
	this.resultCtrl = resultCtrl;
	
	var config = {boxName : "reviewContentsBox", container : container};

	Mys.ReviewContentsCtrl.superclass.constructor.call(this, config);
}

Ext.extend(Mys.ReviewContentsCtrl, Mys.ContentsCtrl, 
{		
		usePoint : true,
		useAgree : true,
		reviewTemplate : '<div id="reviewContentsBox" class="contentsBox">' +
												'<div class="dummy"></div>'+
										'</div>',
		
		initialize : function(config)
		{
			var ctrl;
			
			this.isVisible = false;

			if(!Global.modelContents)
				Global.modelContents = new Mys.Model.Contents;
			
			var container = config.container;

			this.boxEl = container.insertHtml(config.where?config.where:"afterEnd", this.reviewTemplate, true);			
			
			// set event			
			this.resultCtrl.on("changePoint", this.changePoint, this);
			this.resultCtrl.on("changeAgree", this.changeAgree, this);
						
			this.selectedItem = Global.contentsItem;
						
			//set category
			this.category = Mys.getContentsCategoryName(this.selectedItem.category);

			switch(this.category)
			{
					case "book" :
							ctrl = new Mys.BookContentsCtrl;
							this.imageHeight = 156;
							this.imageWidth = 108;
							break;
					
					case "shop" :
							ctrl = new Mys.ShoppingContentsCtrl;
							break;
					
					case "movie" :
							ctrl = new Mys.MovieContentsCtrl;
							break;
			}
			
			// parse item
			this.parseItem(this.selectedItem);
			
			// show item
			this.detailTpl = new Ext.Template(ctrl.detailHtml);
			this.resultCtrl.showDetailItem(this.selectedItem, this.detailTpl);
			this.resultCtrl.show(this.boxEl.child(".dummy"));			
		},
		
		parseItem : function(item)
		{
				item.title = item.con_title;
				item.pubdate = item.pubdate.substring(0, 10);
				
				if(item.image == null)
				{
						item.imageFlag = "notfound";
						delete item.image;
				}
				else
				{
						item.imageHtml = '<img src="'+item.image+'" height="'+this.imageHeight+'" width="'+this.imageWidth+'"/>';
				}
								
				delete item.con_count;
				delete item.con_title;
				delete item.con_point;
				delete item.update_date;
				delete item.agree_count;
				delete item.disagree_count;
				delete item.con_pcount;
		},
		
	  changePoint : function(item, category, point)
	  {
	  		if(!this.usePoint || !point)
	  				return;

	  		item.point = point;
	  },

	  changeAgree : function(item, category, agree)
	  {
	  		if(!this.useAgree || !agree)
	  				return;

	  		item.agree_type = agree;
	  },
	  
		showBox : function()
		{
			this.isVisible = true;
			this.boxEl.setStyle("display", "block");
			this.resultCtrl.showDetailItem(this.selectedItem, this.detailTpl);
			this.resultCtrl.show(this.boxEl.child(".dummy"));
		},
				
		hideBox : function()
		{
			this.isVisible = false;

			this.boxEl.setStyle("display", "none");
		},
				
		isSet : function()
		{
				if(this.usePoint && (typeof(this.selectedItem.point) == 'undefined' || this.selectedItem.point == ""))
				{
						alert("별점을 선택해주세요");
						return false;
				}
				return true;
		}
});

Mys.Minishop_photoContentsCtrl = function(resultCtrl, container)
{
	var config = {boxName : "minishopPhotoContentsBox", container : container};

	Mys.Minishop_photoContentsCtrl.superclass.constructor.call(this, resultCtrl, null, config);
}

Ext.extend(Mys.Minishop_photoContentsCtrl, Mys.PhotoContentsCtrl,
{
	defaultClass : "direct",
	searchTemplate : new Ext.Template('<div id="minishopPhotoContentsBox" class="contentsBox">' +
																		'<div class="tab">'+
																			'<a href="#" onclick="return false" class="direct"><img src="/images/icon/tab_direct.png" class="png24"/></a>'+
																			'<a href="#" onclick="return false" class="url"><img src="/images/icon/tab_url.png" class="png24"/></a>'+
																		'</div>'+
																		'</div>'),

	getCtrlName : function(className)
	{
			var ctrlName = "";

			switch(className)
			{
					case "direct" :
							ctrlName = "PhotoDirectContentsCtrl";
							break;

					case "url" :
							ctrlName = "PhotoUrlContentsCtrl";
							break;

					default :
							break;
			}

			return ctrlName;
	}
});
