var TvagriManager = Class.create();

TvagriManager.prototype = {
		
	initialize : function(){
		this.attachPath = "/user/infomd/tvagri";
		this.del_file_str = '';
	},
	
	/* 페이징 처리 */ 
	changePage: function(pageNo){
		$('nowPageNo').value = pageNo;
		$('listForm').action="/user/infomd/tvagri/getListBbs.aff";
		$('listForm').submit();		
	},
	
	/* 목록개수 변경 */
	changePageSize : function(val){
		$('pageSize').value = val;
		$('nowPageNo').value = '1';

		$('listForm').action="/user/infomd/tvagri/getListBbs.aff";
		$('listForm').submit();
	},
	
	/* 전체선택|취소 */
	checkAll : function(obj){
		var isChecked = obj.checked;
		var items = $$('input.check');
		for(var i=0; i<items.length ; i++){
			items[i].checked = isChecked;
		}		
	},
	
	/* 검색(엔터키) */
	searchEnter : function(evt){
		Event.extend(evt);
		
		if(evt.keyCode == Event.KEY_RETURN || evt.type == 'click'){
			Event.stop(evt);
			this.search();
		}
	},
	
	/* 검색 */
	search : function(){
		if($F('searchWord').strip().length != 0){
			$('searchWord').value = $F('searchWord').strip();
			$('nowPageNo').value = '1';
			
			$('listForm').action="/user/infomd/tvagri/getListBbs.aff";
			$('listForm').submit();		
		}else{
			alert('검색어를 입력하세요');
			$('searchWord').focus();
			return;
		}
	},
	
	/* 전체 검색 */
	searchAll : function(){
		$('searchWord').value = '';
		$('nowPageNo').value = '1';
		
		$('listForm').action="/user/infomd/tvagri/getListBbs.aff";
		$('listForm').submit();
	},
	
	/* 첨부파일 임시삭제(실제 삭제는 수정완료시 진행하고 현재는 보이지만 않게한다.) */
	delAttachFile : function (bbs_file_seq){
		if(confirm("정말 삭제 하시겠습니까?")){
			$('at'+bbs_file_seq).hide();
			$('uploadFiles'+$('at'+bbs_file_seq).getAttribute("type")).show();
			if($('bbs_file_seq') == ''){
				$('bbs_file_seq').value = bbs_file_seq;
			}else{
				$('bbs_file_seq').value += bbs_file_seq+";";
			}
		}
	},
	
	/* 삭제 */
	deleteTvagri : function() {
		var items = $$('input.check');
		var deleteIdxList = '';
		var cnt = 0;
		
		for(var i=0; i<items.length ; i++){
			if(items[i].checked == true) {
				if(deleteIdxList == ''){
					deleteIdxList += parseInt(items[i].value);
				}else{
					deleteIdxList += ";"+(parseInt(items[i].value));
				}
				cnt += 1;				
			}
		}	
		if(cnt == 0) {
			alert("선택한 항목이 없습니다.");
			return;
		}else{
			if(confirm("선택한 글을 삭제 하시겠습니까?")){
				$('file_cnt').value = 0;
				$('del_bbs_seq').value = deleteIdxList;
				$('listForm').action="/user/infomd/tvagri/deleteBbs.aff";
				$('listForm').submit();
			}		
		}			
	},
	
	/* 등록폼에서 목록가기 */ 
	goListFromCreate : function(){
		$('createForm').action = '/user/infomd/tvagri/getListBbs.aff';
		$('createForm').submit();
	},
	
	/* 수정폼에서 목록가기 */ 
	goListFromModify : function(){
		$('modifyForm').action = '/user/infomd/tvagri/getListBbs.aff';
		$('modifyForm').submit();
	},
	
	/* 리스트에서 등록폼가기*/
	goCreateFromList : function(){
		$('file_cnt').value = 0;
		$('listForm').action = '/user/infomd/tvagri/createBbsForm.aff';
		$('listForm').submit();
	},
	
	/* 상세보기 팝업에서 수정폼가기 */
	goModifyFromView : function(bbs_seq, file_cnt){
		opener.location.href = '/user/infomd/tvagri/modifyBbsForm.aff?bbs_seq='+bbs_seq+'&file_cnt='+file_cnt;
		self.close();
	},
		
	/* 글쓰기 */
	createTvagri : function (){
		var instance = FCKeditorAPI.GetInstance("contents");
		
		if($('title').value.strip() == ''){
			alert('제목을 입력해 주세요');
			$('title').focus();
			return;
		} else if (instance.GetHTML().strip() == '') {
			alert('내용을 입력해 주세요');
			instance.Focus();
			return;
		} else if($('uploadFiles1').value == ''){
			alert('썸네일 이미지를 등록해 주세요');
			$('uploadFiles1').focus();
			return;
		} else if($('uploadFiles2').value == ''){
			alert('300K 영상을 등록해 주세요');
			$('uploadFiles2').focus();
			return;
		} else if($('uploadFiles3').value == ''){
			alert('고화질 영상을 등록해 주세요');
			$('uploadFiles3').focus();
			return;
		}
		
		if($('uploadFiles1').style.display == '' && $('uploadFiles1').value != '') {
			if(this.thum_check() == false) return;
		}
		if($('uploadFiles2').style.display == '' && $('uploadFiles2').value != '') {
			if(this.low_check() == false) return;
		}
		if($('uploadFiles3').style.display == '' && $('uploadFiles3').value != '') {
			if(this.high_check() == false) return;
		}
		
		$('createForm').action="/user/infomd/tvagri/createBbs.aff";
		$('createForm').submit();
		
	},
	
	/* 글읽기 */
	readTvagri : function (bbs_seq, file_cnt, type){
		//$('bbs_seq').value = bbs_seq;
		$('type').value = type;
		$('file_cnt').value = file_cnt;
		var url = '/user/infomd/tvagri/viewBbs.aff?bbs_seq='+bbs_seq+'&file_cnt='+file_cnt+'&type='+type;
		window.open(url ,'poptvagri','width=630,height=420, left=100, top=100, resizable=no, scrollbars=no');
		//$('listForm').action="/user/infomd/tvagri/viewBbs.aff";
		//$('listForm').target = "poptvagri";
		//$('listForm').submit();
	},
	
	/* 글수정 */
	modifyTvagri : function (){
		var instance = FCKeditorAPI.GetInstance("contents");
		
		if($('title').value.strip() == ''){
			alert('제목을 입력해 주세요');
			$('title').focus();
			return;
		} else if (instance.GetHTML().strip() == '') {
			alert('내용을 입력해 주세요');
			instance.Focus();
			return;
		} else if($('uploadFiles1').style.display == '' && $('uploadFiles1').value == ''){
			alert('썸네일 이미지를 등록해 주세요');
			$('uploadFiles1').focus();
			return;
		} else if($('uploadFiles2').style.display == '' && $('uploadFiles2').value == ''){
			alert('300K 영상을 등록해 주세요');
			$('uploadFiles2').focus();
			return;
		} else if($('uploadFiles3').style.display == '' && $('uploadFiles3').value == ''){
			alert('고화질 영상을 등록해 주세요');
			$('uploadFiles3').focus();
			return;
		}
		
		if($('uploadFiles1').style.display == '' && $('uploadFiles1').value != '') {
			if(this.thum_check() == false) return;
		}
		if($('uploadFiles2').style.display == '' && $('uploadFiles2').value != '') {
			if(this.low_check() == false) return;
		}
		if($('uploadFiles3').style.display == '' && $('uploadFiles3').value != '') {
			if(this.high_check() == false) return;
		}
		
		var type_thum = $('uploadFiles1').value;
		var type_low = $('uploadFiles2').value;
		var type_high = $('uploadFiles3').value;
		
		if(type_thum != '' && type_low == '' && type_high == '') {
			$('type_cnt').value = 0;
		} else if(type_thum == '' && type_low != '' && type_high == '') {
			$('type_cnt').value = 1;
		} else if(type_thum == '' && type_low == '' && type_high != '') {
			$('type_cnt').value = 2;
		} else if(type_thum != '' && type_low != '' && type_high == '') {
			$('type_cnt').value = 3;
		} else if(type_thum != '' && type_low == '' && type_high != '') {
			$('type_cnt').value = 4;
		} else if(type_thum == '' && type_low != '' && type_high != '') {
			$('type_cnt').value = 5;
		} else if(type_thum != '' && type_low != '' && type_high != '') {
			$('type_cnt').value = 6;
		}
		
		$('modifyForm').action="/user/infomd/tvagri/modifyBbs.aff";
		$('modifyForm').submit();
		
	},
	
	//썸네일 확장자 체크
	thum_check : function() {
		var  thum_str,thum_dotlocation,thum_ext;
	    
	    file_thum			= $('uploadFiles1').value;
	    thum_str			= file_thum.toLowerCase(file_thum);
	    thum_dotlocation	= thum_str.lastIndexOf(".");
	    thum_ext			= thum_str.substring(thum_dotlocation+1);
	    
	    if(thum_ext != "gif" && thum_ext != "jpg" && thum_ext != "png" && thum_ext != "bmp" && thum_ext != "tif" && thum_ext != "jpe") {
    		alert("썸네일 이미지 파일 입력 양식에 맞지 않는 파일입니다.");
    		$('uploadFiles1').focus();
    		return false;
	    }
	    
	},
	
	//300K 확장자 체크
	low_check : function() {
		var  low_str,low_dotlocation,low_ext;
	    
	    file_low		= $('uploadFiles2').value;
	    low_str			= file_low.toLowerCase(file_low);
	    low_dotlocation	= low_str.lastIndexOf(".");
	    low_ext			= low_str.substring(low_dotlocation+1);
	    
	    if(low_ext != "wmv" && low_ext != "avi") {
    		alert("300K 동영상 파일 입력 양식에 맞지 않는 파일입니다.");
    		$('uploadFiles2').focus();
    		return false;
	    }
	    
	},
	
	//고화질 확장자 체크
	high_check : function() {
		var  high_str,high_dotlocation,high_ext;
	    
	    file_high			= $('uploadFiles3').value;
	    high_str			= file_high.toLowerCase(file_high);
	    high_dotlocation	= high_str.lastIndexOf(".");
	    high_ext			= high_str.substring(high_dotlocation+1);
	    
	    if(high_ext != "wmv" && high_ext != "avi") {
    		alert("고화질 동영상 파일 입력 양식에 맞지 않는 파일입니다.");
    		$('uploadFiles3').focus();
    		return false;
	    }
	    
	},
	
	/* 전체화면 보기 */
	resize : function() {
		$('Player').DisplaySize = 3;
	}

	
	/*  */
	
};