<!--
// 게시물 입력, 수정 체크
anyboard = function(boardID, Mode){
	this.docXML;				// XML데이터 return 값
	this.callback = null;		// XML결과 return함수
	this.httpRequest = null;	// httpRequest객체
	this.boardID = boardID;		// 게시판 ID	
	this.boardInfo = new Array();	// 게시판 정보
	this.boardOpt = new Array();	// 옵션 정보
	this.fileListLayer = null;		// 파일 리스트 영역
	this.Mode = (Mode != "") ? Mode : "list";	// 게시판 모드

	// httpRequest 객체 생성 함수
	anyboard.prototype.getXMLHttpRequest = function() {
		if (window.ActiveXObject) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e1) { return null; }
			}
		} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
		} else {
			return null;
		}
	}	//	end getXMLHttpRequest function
	
	// httpRequest send 함수
	anyboard.prototype.sendRequest = function(url, params, callback, method) {
		this.callback = callback;

		this.httpRequest = this.getXMLHttpRequest();
		var httpMethod = method ? method : 'GET';
		if (httpMethod != 'GET' && httpMethod != 'POST') {
			httpMethod = 'GET';
		}
		var httpParams = (params == null || params == '') ? null : params;
		var httpUrl = url;
		if (httpMethod == 'GET' && httpParams != null) {
			httpUrl = httpUrl + "?" + httpParams;
		}
		this.httpRequest.open(httpMethod, httpUrl, true);
		this.httpRequest.setRequestHeader(
			'Content-Type', 'application/x-www-form-urlencoded');
		
		var request = this;
		this.httpRequest.onreadystatechange = function() {
			request.onStateChange.call(request);
		}
		this.httpRequest.send(httpMethod == 'POST' ? httpParams : null);	
	}	// end sendRequest function

	// httpRequest return 함수
	anyboard.prototype.onStateChange = function() {
		this.callback(this.httpRequest);
	}	// end onStateChange end


	// 게시판 정보 호출
	anyboard.prototype.requestInfo = function(){
		params  = "action=getInfo";
		params += "&boardID="+this.boardID;
		params += "&Mode="+this.Mode;
		this.sendRequest("/core/xml/anyboard.xml.html", params, this.resultXML, "POST");
	}	// end requestXML function


	// 스크랩
	anyboard.prototype.scrap = function(num){
		params  = "action=scrap";
		params += "&boardID="+this.boardID;
		params += "&Mode=view";
		params += "&num="+num;
		this.sendRequest("/core/xml/anyboard.xml.html", params, this.resultXML, "POST");
	}	// end requestXML function

	// 권한확인
	anyboard.prototype.permitCheck = function(mode, num, page, keyfield, key, bCate){
		params = "action=permitCheck";
		params += "&boardID="+this.boardID;
		params += "&num="+num;
		params += "&Mode="+mode;
		params += "&page="+page;
		params += "&keyfield="+keyfield;
		params += "&key="+key;
		params += "&bCate="+bCate;
		this.sendRequest("/core/xml/anyboard.xml.html", params, this.resultXML, "POST");
	}

	// XML결과
	anyboard.prototype.resultXML = function(){
		if(this.httpRequest.readyState == 4){
			if(this.httpRequest.status == 200){

				//alert(this.httpRequest.responseText);

				this.docXML = this.httpRequest.responseXML;
				code = this.docXML.getElementsByTagName("code").item(0).firstChild.nodeValue;	// 결과코드

				// 결과 실행
				switch (code){
					case 'ErrorMsg':
						message = this.docXML.getElementsByTagName("message").item(0).firstChild.nodeValue;	// 리턴메시지
						alert(message);
						break;

					// 게시판 정보 추출
					case 'getInfo':
						this.setBoardInfo();						
						break;

					// 게시판 정보 추출
					case 'getFileList':
						this.displayFileList();						
						break;

					// 권한확인
					case 'permitCheck':
						chkresult = this.docXML.getElementsByTagName("chkresult").item(0).firstChild.nodeValue;

						switch (chkresult)
						{
							case "1":
								window.alert("글보기 권한이 없습니다.");
								break;
							case "2":
								window.alert("글보기 권한이 없습니다. \n 로그인 후 이용해 주세요.");
								openPage.createPage(window.event, '500', '216', '/core/module/membership/membership.html?Mode=login', 'auto',-1,'-1');
								break;
							default:
								info = this.docXML.getElementsByTagName("info").item(0);
								boardID = info.firstChild.nodeValue;
								page = info.getAttribute("page");
								num = info.getAttribute("num");
								mode= info.getAttribute("mode");
								keyfield= info.getAttribute("keyfield");
								key= info.getAttribute("key");
								bCate= info.getAttribute("bCate");

								if(boardID.substring(0,4) == "cafe" && boardID != "cafeBoard"){
									location.href='/core/cafe/view/sub.html?Mode='+mode+'&boardID='+boardID+'&num='+num+'&page='+page+'&keyfield='+keyfield+'&key='+key+'&bCate='+bCate;
								} else {
									location.href=location.pathname + '?Mode='+mode+'&boardID='+boardID+'&num='+num+'&page='+page+'&keyfield='+keyfield+'&key='+key+'&bCate='+bCate;
								}
								break;
						}
						break;
					default:
						alert("결과코드 없음");
						break;
				}
			}
		}
	}	// end resultXML function


	// 게시판 정보
	anyboard.prototype.setBoardInfo = function(){

		// 게시판 정보
		totalInfo = this.docXML.getElementsByTagName("boardInfo").length;
		for(i = 0; i < totalInfo; i++){
			infoObj = this.docXML.getElementsByTagName("boardInfo").item(i);
			infoVal = infoObj.firstChild.nodeValue;
			infoKey = infoObj.getAttribute('gid');
			this.boardInfo[infoKey] = infoVal;
		}

		// 게시판 추가 옵션
		totalOpt = this.docXML.getElementsByTagName("boardOpt").length;
		for(i = 0; i < totalOpt; i++){
			opt = this.docXML.getElementsByTagName("boardOpt").item(i);
			optVal = opt.firstChild.nodeValue;
			num = opt.getAttribute('num');
			boardID = opt.getAttribute('boardID');
			optCheckUse = opt.getAttribute('optCheckUse');
			optCheckEss = opt.getAttribute('optCheckEss');
			optPnt = opt.getAttribute('optPnt');
			optTitle = opt.getAttribute('optTitle');

			this.boardOpt[i] = new Array();
			this.boardOpt[i]['optVal'] = optVal;
			this.boardOpt[i]['num'] = num;
			this.boardOpt[i]['boardID'] = this.urlDecode(boardID);
			this.boardOpt[i]['optCheckUse'] = this.urlDecode(optCheckUse);
			this.boardOpt[i]['optCheckEss'] = this.urlDecode(optCheckEss);
			this.boardOpt[i]['optPnt'] = this.urlDecode(optPnt);
			this.boardOpt[i]['optTitle'] = this.urlDecode(optTitle);
		}		
	}	// end setBoardInfo function


	anyboard.prototype.optCheck = function(){
		totalOpt = this.boardOpt.length;
		var form = document.anyboardForm;

		for(i = 0; i < totalOpt; i++){
			opt = this.boardOpt[i];
			if(opt['optCheckEss'] == "N") continue;
			optObj = document.getElementById("BOPT_"+opt['num']);

			if(opt['optPnt'] == "text" || opt['optPnt'] == "textM" || opt['optPnt'] == "combo"){
				if(trim(optObj.value) == ""){
					alert("`"+opt['optTitle'] + "`항목을 입력하세요");
					optObj.focus();
					return false;
				}
			}else{
				if(opt['optPnt'] == "radio" || opt['optPnt'] == "radioM"){
					var chk = false;
					for(j = 0; j < form.elements['BOPT_'+opt['num']].length; j++){
						if(form.elements['BOPT_'+opt['num']][j].checked == true){
							chk = true;
						}
					}
					if(chk == false){
						alert("`"+opt['optTitle'] + "`항목을 선택하세요");
						return false;
					}
				}

				if(opt['optPnt'] == "checkbox" || opt['optPnt'] == "checkboxM"){
					var chk = false;
					for(j = 0; j < form.elements['BOPT_'+opt['num']+'[]'].length; j++){
						if(form.elements['BOPT_'+opt['num']+'[]'][j].checked == true){
							chk = true;
						}
					}
					if(chk == false){
						alert("`"+opt['optTitle'] + "`항목을 선택하세요");
						return false;
					}
				}
			}
		}

		return true;
	}	// end optCheck function


	// 글 등록 체크
	anyboard.prototype.writeCheck = function(){
		var form = document.anyboardForm;
		// 작성자 체크
		if(trim(form.name.value) == ""){
			alert("\n작성자를 입력하세요. ");
			form.name.focus();
			return false;
		}

		// 이메일 체크
		if(trim(form.email.value) != ""){
			if(!emailCheck(trim(form.email.value))){
				alert("잘못된 이메일 주소입니다.");
				form.email.focus();
				return false;
			}
		}

		// 제목 체크
		if(trim(form.subject.value) == ""){
			alert("\n제목을 입력하세요. ");
			form.subject.focus();
			return false;
		}

		// 추가 항목 체크
		if(!this.optCheck()){
			return false;
		}

		// 내용 체크(에디터 사용할경우
		if(form.optEditor.value != "Y"){
			if(trim(form.content.value) == ""){
				alert("\n내용을 입력하세요. ");
				form.content.focus();
				return false;
			}			
		}else{
			form.content.value = boardEditor.outputBodyHTML();
			if(trim(form.content.value) == ""){
				alert("내용을 입력하세요");
				return false;
			}
		}

		// 비밀번호를 입력하세요
		if(trim(form.password.value) == ""){
			alert("\비밀번호를 입력하세요. ");
			form.password.focus();
			return false;
		}

		// 첨부파일 등록시
		if(this.boardInfo['optUpload'] == "Y"){
			// 업로드중인지 체크
			if(form.uploadType.value == "flex"){
				if(simpleUpload.isUploading()){
					alert("파일 업로드중입니다. 잠시만 기다려주세요.");
					return false;
				}
			}

			// 앨번형 게시판의 경우 이미 파일첨부
			//11.01.10 앨범게시판 수정시 오류로 인하여 && this.Mode == 'write' 삭제(process.php도 수정)
			if(this.boardInfo['boardType'] == "album"){
				// HTML형태 게시판
				if(typeof form.elements['boardFile[]'] != "undefined"){
					var chk = false;
					if(typeof form.elements['numFileMemo[]'] == "object"){
						chk = true;
					}
					if(form.elements['boardFile[]'].length){
						for(j = 0; j < form.elements['boardFile[]'].length; j++){
							if(form.elements['boardFile[]'][j].value != ""){
								chk = true;
							}
						}
					}else{
						if(form.elements['boardFile[]'].value != ""){
							chk = true;
						}
					}
					if(chk == false){
						alert("첨부 이미지를 입력하세요.");
						return false;
					}
				}else{
					// flex게시판
					if(form.processType.value == "modify"){
						if(trim(form.uploadFiles.value) == "" && parseInt(form.uploadedCount.value) == 0){
							alert("첨부 이미지를 입력하세요.");
							return false;
						}
					}else{
						if(trim(form.uploadFiles.value) == ""){
							alert("첨부 이미지를 입력하세요.");
							return false;
						}
					}
				}
			}
		}

		document.getElementById('dataBtnArea').style.display='none';
		document.getElementById('dataTxtArea').style.display='block';

		new cryptSubmit(form, form.cryptKey); // 글등록
	}	// end checkValue function


	// 삭제체크
	anyboard.prototype.deleteCheck = function(num, dire){		
		// 권한자 바로삭제
		if(dire == 0){
			if(confirm("정말로 삭제하시겠습니까?")){
				// 삭제폼
				form = document.anyboardAct;
				form.chNum.value = num;
				form.processType.value = 'delete';
				new cryptSubmit(form, form.cryptKey);
			}
		// 비밀번호 입력 체크
		}else{
			// 삭제폼
			form = document.anyboardForm;

			// 비밀번호를 입력하세요
			if(trim(form.password.value) == ""){
				alert("\비밀번호를 입력하세요. ");
				form.password.focus();
				return false;
			}
			if(confirm("정말로 삭제하시겠습니까?")){
				document.getElementById('dataBtnArea').style.display='none';
				document.getElementById('dataTxtArea').style.display='block';
				new cryptSubmit(form, form.cryptKey);
			}
		}
	}	// end deleteCheck function


	// 첨부파일 삭제
	anyboard.prototype.fileDeleteCheck = function(num){
		if(confirm("정말로 선택한 파일을 삭제하시겠습니까?")){
			// 삭제폼
			form = document.anyboardAct;
			form.chNum.value = num;
			form.processType.value = 'fileDelete';
			new cryptSubmit(form, form.cryptKey);
		}
	}	// end fileDeleteCheck function


	// 댓글 체크
	anyboard.prototype.commentWriteCheck = function(form, act, idx){		

		// 작성자를 체크
		if(act != 'commentDelete'){
			if(trim(form.name.value) == ""){
				alert("\작성자를 입력하세요. ");
				form.name.focus();
				return false;
			}
		}

		// 비밀번호 체크
		if(trim(form.password.value) == ""){
			alert("\비밀번호를 입력하세요. ");
			form.password.focus();
			return false;
		}

		// 내용 체크
		if(act != 'commentDelete'){
			if(trim(form.content.value) == ""){
				alert("\내용을 입력하세요. ");
				form.content.focus();
				return false;
			}
		}

		actForm = document.commentForm;
		if(act != 'commentDelete'){
			actForm.name.value = form.name.value;		
			actForm.content.value = form.content.value;
		}
		actForm.processType.value = act;
		actForm.commentNum.value = idx;
		actForm.password.value = form.password.value;
		new cryptSubmit(actForm, actForm.cryptKey); // 글등록
	}	// end commentWriteCheck function


	// 코멘트 답변 또는 수정 폼 생성
	anyboard.prototype.commentFormSet = function(idx, act){

		switch(act){
			// 코멘트 수정
			case 'commentModify':
				if(document.getElementById("comment_modify_"+idx).style.display != "block"){
					document.getElementById("comment_modify_"+idx).style.display = "block";
					document.getElementById("comment_reply_"+idx).style.display = "none";
					document.getElementById("comment_delete_"+idx).style.display = "none";
					document.getElementById("comment_modify_"+idx).innerHTML = document.getElementById(act).innerHTML;			
					document.forms["comment_modify_"+idx].name.value = document.getElementById("comment_name_"+idx).innerHTML;
					document.forms["comment_modify_"+idx].content.value = document.getElementById("comment_content_"+idx).value;
					document.forms["comment_modify_"+idx].inputBtn.onclick = function(){ anyboard.commentWriteCheck(document.forms["comment_modify_"+idx], 'commentModify', idx); }
				}else{
					document.getElementById("comment_modify_"+idx).style.display = "none";
				}
				break;

			// 댓글의 댓글
			case 'commentReply':
				if(document.getElementById("comment_reply_"+idx).style.display != "block"){
					document.getElementById("comment_reply_"+idx).style.display = "block";
					document.getElementById("comment_modify_"+idx).style.display = "none";
					document.getElementById("comment_delete_"+idx).style.display = "none";
					document.getElementById("comment_reply_"+idx).innerHTML = document.getElementById(act).innerHTML;
					document.forms["comment_reply_"+idx].inputBtn.onclick = function(){ anyboard.commentWriteCheck(document.forms["comment_reply_"+idx], 'commentReply', idx); }
				}else{
					document.getElementById("comment_reply_"+idx).style.display = "none";
				}
				break;

			// 코멘트 삭제
			case 'commentDelete':
				if(document.getElementById("comment_delete_"+idx).style.display != "block"){
					document.getElementById("comment_delete_"+idx).style.display = "block";
					document.getElementById("comment_modify_"+idx).style.display = "none";
					document.getElementById("comment_reply_"+idx).style.display = "none";
					document.getElementById("comment_delete_"+idx).innerHTML = document.getElementById(act).innerHTML;
					document.forms["comment_delete_"+idx].inputBtn.onclick = function(){ anyboard.commentWriteCheck(document.forms["comment_delete_"+idx], 'commentDelete', idx); }
				}else{
					document.getElementById("comment_delete_"+idx).style.display = "none";
				}
				break;

			////
			default:
				alert("잘못된 값입니다.");
				break;
		}		
	}	// end commentFormSet function


	// 코멘트 삭제
	anyboard.prototype.commentDelete = function(num){
		if(confirm("정말로 삭제하시겠습니까?")){
			actForm = document.commentForm;
			actForm.processType.value = 'commentDelete';
			actForm.commentNum.value = num;
			new cryptSubmit(actForm, actForm.cryptKey);
		}
	}	// end fileDeleteCheck function


	// 이미지 열기
	anyboard.prototype.imageOpen = function(width, height, num){
		screenWidth = window.screen.width; // 윈도우 넓이
		screenHeight = window.screen.height; // 윈도우 높이

		// 이미지 크기가 윈도우 사이즈보다 클경우
		if(width >= screenWidth && height < screenHeight){
			openWidth = screenWidth;
			openHeight = (screenWidth/width)*height;
		}else if(width < screenWidth && height >= screenHeight){
			openHeight = screenHeight -110 ;
			openWidth = (screenHeight/height)*width;
		}else if(width >= screenWidth && height >= screenHeight){
			openHeight = ((screenHeight/height)*height)-110;
			openWidth = (screenHeight/height)*width;
		}else{
			openWidth = width;
			openHeight = height;
		}
		if(openHeight >= screenHeight){
			openWidth = (screenHeight/openHeight)*openWidth;
			openHeight = screenHeight;
		}
		openWidth = parseInt(openWidth);
		openHeight = parseInt(openHeight);
		openLeft = (screenWidth-openWidth)/2;
		openLeft = parseInt(openLeft);
		openTop = (screenHeight-openHeight)/3;		
		openTop = parseInt(openTop);

		window.open('/core/anyboard/imageOpen.php?boardID='+this.boardID+'&num='+num+'&width='+openWidth+'&height='+openHeight, num, 'left='+openLeft+',top='+openTop+',height='+openHeight+',width='+openWidth+',toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=no,resizable=no,modal=yes,dependent=yes');

	}	// end imageOpen function


	// 리스트 부분 파일 정보보기
	anyboard.prototype.fileListView = function(e, num){
		this.fileListRemove();	// 이전 레이어 삭제

		this.fileListLayer = document.createElement("DIV");
		this.fileListLayer.setAttribute('id', 'anyboardFileListLayer');
		this.fileListLayer.style.position = 'absolute';		
		this.fileListLayer.style.zIndex = '9999';
		this.fileListLayer.style.border = '1px solid #C6CAFF';
		this.fileListLayer.style.backgroundColor = 'EFF3FF';
		this.fileListLayer.style.padding = '5px';
		this.fileListLayer.style.textAlign = 'left';
		this.fileListLayer.style.lineHeight = '18px';
		this.fileListLayer.style.width = "220px";

		pX = (!window.event) ? e.pageX : document.documentElement.scrollLeft + window.event.clientX;
		pY = (!window.event) ? e.pageY : document.documentElement.scrollTop + window.event.clientY;
		pX -= 110;
		pY -= 2;
		pX += "px";
		pY += "px";

		this.fileListLayer.style.left = pX;
		this.fileListLayer.style.top = pY;
		this.fileListLayer.innerHTML = "";
		//this.fileListLayer.onmouseout = function(){ anyboard.fileListRemove(); };
		document.body.appendChild(this.fileListLayer);


		params  = "action=getFileList";
		params += "&boardID="+this.boardID;
		params += "&Mode=list";
		params += "&num="+num;
		this.sendRequest("/core/xml/anyboard.xml.html", params, this.resultXML, "POST");
	}	// end fileListView function

	// 파일 리스트 부분 없애기
	anyboard.prototype.fileListRemove = function(){
		if(this.fileListLayer != null){
			document.body.removeChild(this.fileListLayer);
			this.fileListLayer = null;
		}
	}	// end fileListRemove function


	// 파일 리스트 부분 출력
	anyboard.prototype.displayFileList = function(){
		totalFile = this.docXML.getElementsByTagName("fileInfo").length;
		this.fileListLayer.innerHTML += "<img src=\"/core/images/etc/icon_filelist_close.gif\" title=\"닫기\" style=\"cursor:pointer;\" onClick=\"anyboard.fileListRemove();\" align='right'><br />";
		for(i = 0;  i < totalFile; i++){
			fileObj = this.docXML.getElementsByTagName("fileInfo").item(i);
			fileName = fileObj.firstChild.nodeValue;
			fileSize = fileObj.getAttribute('fileSize');
			fileNum = fileObj.getAttribute('num');

			tmpNum = i+1;
			

			this.fileListLayer.innerHTML += "<span style=\"cursor:pointer; font-size:12px; color:#333333;\" onClick=\"ABHiddenFrame.document.location.href='/core/anyboard/download.php?boardID=" + this.boardID + "&fileNum=" + fileNum + "';\" onMouseover=\"this.style.color='#FF07F2';\" onMouseout=\"this.style.color='#333333';\">" + tmpNum + ". " + fileName + " ("+fileSize+") <br></span>";
		}	

	}	// end displayFileList function


	// 파일전체 완료후
	anyboard.prototype.fileUploadComplete = function(str){
		document.anyboardForm.uploadFiles.value = str;
	}	// end fileUploadComplete function


	// 파일 삭제 (flex전용)
	anyboard.prototype.fileUploadedDelete = function(key, fileNum){
		delObj = document.anyboardForm.deleteFiles;
		if(delObj.value == ""){
			delObj.value = fileNum;
		}else{
			delObj.value = delObj.value+"-"+fileNum;
		}
		document.anyboardForm.uploadedCount.value = parseInt(document.anyboardForm.uploadedCount.value) - 1;
		simpleUpload.fileCancel(key);
	}	// end fileUploadedDelete function


	// 앨번게시판 사진목록 출력
	anyboard.prototype.fileWriteImage = function(key, saveName){

		baseObj = document.getElementById("uploadMainDiv_"+key);
		baseObj.innerHTML = "";	// 리스트 초기화

		var baseHTML = "";
		baseHTML += "<table border='0' cellpadding='0' cellspacing='0' style='width:100%;'>";
		baseHTML += "<tbody>";
		baseHTML += "<tr>";
		baseHTML += "<td style='width:80px; height:64px;  position:relative;'>";
		baseHTML += "<img src='/core/anyboard/defaultAlbum/images/d_btn.gif' style='position:absolute; z-index:2; left:1px; top:1px; cursor:pointer;' onclick='simpleUpload.fileCancel("+key+");' />";
		baseHTML += "<img src='/core/anyboard/imageTemp.php?saveName="+saveName+"' width='80' height='64' style='border:1px solid #ddd;'></td>";
		//baseHTML += "<img src='/user/saveDir/tmpDir/"+saveName+"' width='80' height='64' style='border:1px solid #ddd;'></td>";
		baseHTML += "<td><textarea style='width:400px; height:64px; border:1px solid #ddd; margin-left:5px;' name='boardFileMemo[]'></textarea></td>";
		baseHTML += "</tr>";
		baseHTML += "<tr>";
		baseHTML += "<td colspan='2' height='5'></td>";
		baseHTML += "</tr>";
		baseHTML += "</tbody>";
		baseHTML += "</table>";

		baseObj.innerHTML = baseHTML;

	}	// end fileWriteImage function

	
	// urlDecode
	anyboard.prototype.urlDecode = function(data){
		var lsRegExp = /\+/g;
		return decodeURIComponent(String(data).replace(lsRegExp, " "));
	}	// end urlDecode function

	
	this.requestInfo();
}

//-->
