/*
	'****************************************************************
  	'*
   	'*  # PROGRAM TITLE : Board Javascript
	'*
	'*  # PROGRAMER : smalldevil
	'*
	'*  # FILE CREATE DAY : 2010-01-23
   	'*
   	'*  # PROGRAM CONT : Board Javascript File
	'*
   	'*  # FILE NAME : /sitelib/js_common_board.js
   	'*
   	'*	# MODIFICATIONS
	'*
   	'****************************************************************
*/

// -- list
	function goBoardPage(encP,fName, sVal, pVal){
		var frm = document.frmBoard;
		if (frm != undefined){
			if(encP != undefined){
				if(fName != undefined){
					if (sVal != undefined) {
						frm.action = fName + "?p=" + encP + "&ps="+ pVal +"&s=" + sVal + "&f=" + sVal;
					} else {
						frm.action = fName + "?p=" + encP;
					}
					frm.submit();
				}else{
					frm.action = document.location.pathname + "?p=" + encP;
					frm.submit();
				}
			}else{
				frm.action = document.location.pathname;
				frm.submit();
			}
		}else{
			if(encP != undefined){
				document.location.href=document.location.pathname + "?p=" + encP;
			}else{
				document.location.href=document.location.pathname;
			}
		}
	}

	function goBoardView(encVal, tVal){
		var frm = document.frmBoard;
		if(frm != undefined && encVal != undefined){
			if (tVal != undefined) {
				frm.target = "_blank"
			}
			frm.action = encVal;
			frm.submit();
		}else{
			return false;
		}
	}


	function goBaordSch(encMID,fName){
		var frm = document.frmBoard;
		var schField = document.getElementById("keyField");
		var schWord = document.getElementById("keyWord");
		var strFileName;
		if(frm != undefined && schField != undefined && schWord != undefined){
			if(schWord.value.length > 1){
				frm.txtSchType.value = schField.options[schField.selectedIndex].value;
				frm.txtSchWord.value = schWord.value;
				if (fName != undefined){
					strFileName = fName;
				}else{
					strFileName = document.location.pathname;
				}
				if (encMID != undefined && encMID != ""){
					frm.action = strFileName + "?m=" + encMID;
				}else{
					frm.action = strFileName;
				}
				frm.submit();
			}else{
				alert('You must enter at least two characters.');schWord.focus();return false;
			}
		}else{
			alert('Unable to use the search function.');return false;
		}
	}

	function goBaordOtherSch(aVal, fName){
		var frm = document.frmBoard;
		var schWord = document.getElementById("keyWord");
		var strFileName;
		if(frm != undefined && aVal != undefined){
			if (aVal == "s") {
				frm.txtSchType.value = 2;
				frm.txtSchWord.value = schWord.value;
			} else if (aVal == "f") {
				if(schWord.value.length > 1){
					var arrSchField = document.getElementsByName("schField");
					for (var i = 0; i<arrSchField.length; i++) {
						if (arrSchField[i].checked == true) {
							frm.txtSchType.value = arrSchField[i].value;
						}
					}
					frm.txtSchWord.value = schWord.value;
				} else {alert('You must enter at least two characters.');schWord.focus();return false;}
			} else {
				frm.txtSortBy.value = aVal;
			}
			if (fName != undefined){
				strFileName = fName;
			} else {
				strFileName = document.location.pathname;
			}
			frm.action = strFileName;
			frm.submit();
		} else {
			alert('Unable to use the search function.');return false;
		}
	}

	//my id search
	function goBaordMySch(aVal, iVal, fName){
		var frm = document.frmBoard;
		var schWord = document.getElementById("keyWord");
		var strFileName;
		if(frm != undefined && aVal != undefined && iVal != undefined){
			frm.txtSchType.value = aVal;
			frm.txtSchWord.value = iVal;
			if (fName != undefined){
				strFileName = fName;
			} else {
				strFileName = document.location.pathname;
			}
			frm.action = strFileName;
			frm.submit();
		} else {
			alert('Unable to use the search function.');return false;
		}
	}

	//go category search
	function goBoardCate(aVal, fName, c1d, c2d, c3d, c4d){
		var frm = document.frmBoard;
		if (frm != undefined && aVal != undefined && c1d != undefined){
			frm.txtCateC1d.value = c1d;
			frm.txtCateC2d.value = c2d;
			frm.txtCateC3d.value = c3d;
			frm.txtCateC4d.value = c4d;
			if (fName != undefined){
				strFileName = fName;
			} else {
				strFileName = document.location.pathname;
			}
			frm.action = strFileName;
			frm.submit();
		}else{
			alert('Unable to use the category function.');return false;
		}
	}


	function setImgList(){
		var arrImg = document.getElementsByName("imgListThumb");
		for ( var i = 0 ; i < arrImg.length ; i++){
			if (arrImg[i].complete == true){
				if(arrImg[i].height > arrImg[i].width || arrImg[i].height > 110){
					arrImg[i].width = arrImg[i].width*110/arrImg[i].height;
					arrImg[i].height = 110;
				}
				window.clearInterval(Window_ID);
			}
		}
	}

// -- view

	function goLoginForCmt(){
		if (confirm('You can use it once you are logged in.\n\nMove to login page?') == true){
			var rUrl = top.document.location.href;
			if (rUrl.lastIndexOf("#") > 0){
				rUrl = rUrl.substring(0,rUrl.lastIndexOf("#")-1);
			}
			rUrl = escape(rUrl);
			top.document.location.href = '/member/member_login.asp?url='+rUrl;
		}
	}

	function sndCmtWrite(encS){
		var frm = document.frmBoard;
		var objCmt = document.getElementById("txtCmtField");
		if (frm != undefined && objCmt != undefined && encS != undefined){
			if(objCmt.value.length < 2 ){
				alert('Replies must contain at least two characters.'); objCmt.focus();return false;
			}else{
				if(sndFlag == false){
					frm.aType.value = "ci";
					frm.txtCmt.value = objCmt.value;
					frm.txtEncS.value = encS;
					frm.target = "fraAction";
					frm.action = "/sitelib/board_action.asp";
					frm.submit();
				}else{
					alert('Saving your reply. Please wait.');return false;
				}
			} // 덧글 글자수
		}else{
			alert('Unable to save your reply.');return false;
		}
	}


	function sndCmtDelete(encS,encC){
		var frm = document.frmBoard;
		if (frm != undefined && encS != undefined && encC != undefined){
			if( confirm('Do you really want to delete your reply?') == false ){
				return false;
			}else{
				if(sndFlag == false){
					frm.aType.value = "cd";
					frm.txtEncS.value = encS;
					frm.txtEncC.value = encC;
					frm.target = "fraAction";
					frm.action = "/sitelib/board_action.asp";
					frm.submit();
				}else{
					alert('Deleting your reply. Please wait.');return false;
				}
			} // 덧글 글자수
		}else{
			alert('Unable to delete your reply.');return false;
		}
	}

	function goBoardModify(encS,fName, encP){
		var frm = document.frmBoard;
		if (frm != undefined && fName != undefined && encS != undefined){
			if(encP != undefined){
				frm.aType.value = "m";
				frm.txtEncS.value = encS;
				frm.action = fName + "?p=" + encP;
				frm.submit();
			}else{
				frm.aType.value = "m";
				frm.txtEncS.value = encS;
				frm.action = fName;
				frm.submit();
			}
		}else{
			alert('Unable to modify the post.');return false;
		}
	}

	function goBoardDelete(encS, encP){
		var frm = document.frmBoard;
		if (frm != undefined && encS != undefined){
			if (confirm('Do you really want to delete your post?') == true){
				if (sndFlag == false){
					frm.aType.value = "d";
					frm.txtEncS.value = encS;
					frm.txtEncP.value = encP;
					frm.target = "fraAction";
					frm.action = "/sitelib/board_action.asp";
					frm.submit();
				}else{
					alert('Deleting your post. Please wait.'); return false;
				}
			}else{
				return false;
			}
		}else{
			alert('Unable to delete the post.');return false;
		}
	}


	function goActAfterList(encP,fName){
		var frm = document.frmBoard;
		fraAction.document.location.href='about:blank;';
		frm.target = "_self";
		if (fName != undefined){
			if (encP != undefined){
				frm.action = fName+"?p="+document.getElementById("txtEncP").value;
			}else{
				frm.action = fName;
			}
			frm.submit();
		}else{
			top.document.location.href= '/';
		}
	}

	function imgWinOpen(objImg,aType, wVal, hval){
		if (aType != undefined || aType == "t") {
			winImg = window.open('/sitelib/viewimg_common.asp?img='+escape(objImg), 'imgWin', 'width='+wVal+',height='+hval+',scrollbars=yes');
		} else {
			winImg = window.open('/sitelib/viewimg_common.asp?img='+escape(objImg.src), 'imgWin', 'width='+objImg.width+',height='+objImg.height+',scrollbars=yes');
		}
		winImg.focus();
	}

	function imgWinOpenUrl(strImgSrc){
		winImg = window.open('/sitelib/viewimg_common.asp?img='+escape(strImgSrc), 'imgWin', 'width=200,height=200,scrollbars=no');
		winImg.focus();
	}

	function setObjContet(objImg){
		var objSpn = document.getElementById("spnCont");
		var arrImg = objSpn.getElementsByTagName("img");
		if (arrImg != undefined && arrImg.length > 0){
			for( var i = 0 ; i < arrImg.length; i++){
				if (arrImg[i].complete == true){
					if ( arrImg[i].width > 495 ) {
						arrImg[i].height = arrImg[i].height * 495/arrImg[i].width;
						arrImg[i].width = 495;
						arrImg[i].style.height = String(arrImg[i].height * 495/arrImg[i].width)+'px';
						arrImg[i].style.width='495px';
					}else if (arrImg[i].width == 0){
						arrImg[i].width = 495;
					}
					window.clearInterval(Window_ID);
				}
			}
		}
	}

	function setImgViewList(){
		var arrImg = document.getElementsByName("imgListThumb");
		for ( var i = 0 ; i < arrImg.length ; i++){
			if (arrImg[i].complete == true){
				if(arrImg[i].height > arrImg[i].width || arrImg[i].height > 83){
					arrImg[i].width = arrImg[i].width*83/arrImg[i].height;
					arrImg[i].height = 83;
				}
				window.clearInterval(View_ID);
			}
		}
	}

// -- write
	function findFile(){
		var objFile = fraUpload.document.getElementById("upFile");
		if ( objFile != "undefined"){
			objFile.click();
		}
	}

	function sndFormWrite(aType){
		var frm = document.frmBoard;
		if (frm.txtSubject.value.length < 2){
			alert('The title must be at least two characters long.'); frm.txtSubject.focus(); return false;
		}
		if (frm.txtContents.length < 2){
			alert('The body of the post must contain text.');return false;
		}
		if ( sndFlag == false){
			sndFlag = true;
			if (aType != undefined){
				frm.aType.value = "u";
			}else{
				frm.aType.value = "i";
			}
			frm.target = "fraAction";
			frm.action = "/sitelib/board_action.asp";
			frm.submit();
		}else{
			alert('Transferring.\n\nIt may take a few minutes. Please wait.');return false;
		}
	}


	function addFileList(edtSeq, optVar){
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if Internet Explorer
		var frm = document.frmBoard;
		if ( edtSeq != undefined && optVar != undefined){
			addSelectOpt('selFileList', edtSeq, optVar)
			//addSelectOpt('selTmpList', edtSeq, optVar)
		}
	}


	function goActAfterView(encP,fName){
		var frm = document.frmBoard;
		fraAction.document.location.href='about:blank;';
		frm.target = "_self";
		if (fName != undefined){
			if (encP != undefined){
				frm.action = fName+"?p="+encP+"&s="+document.getElementById("txtEncS").value+"&f="+document.getElementById("txtEncF").value;
			}else{
				frm.action = fName+"?p="+document.getElementById("txtEncP").value+"&s="+document.getElementById("txtEncS").value+"&f="+document.getElementById("txtEncF").value;
			}
			frm.submit();
		}else{
			top.document.location.href= '/';
		}
	}

	function delAttach(updInfo){
		var arrUpdInfo;
		if (updInfo != undefined && updInfo.indexOf('|||') > 0 && updInfo.lastIndexOf('|||') > 0){
			arrUpdInfo = updInfo.split('|||');
			document.getElementById("buf_delFile").innerHTML += '<input type="hidden" name="delFileList" value="' + updInfo + '">';
			document.getElementById("ath_"+arrUpdInfo[0]).style.display = "none";
			document.getElementById("cntDel").value += 1;
		}else{
			return false;
		}
	}

	

// -- common

	function goBoardWrite(encP,fName){
		var frm = document.frmBoard;
		if (frm != undefined && fName != undefined){
			if(encP != undefined){
				frm.action = fName + "?p=" + encP;
				frm.submit();
			}else{
				frm.action = fName;
				frm.submit();
			}
		}else{
			alert('Unable to write.');return false;
		}
	}

	function refreshBoardPage(){
		var frm = document.frmBoard;
		var cUrl = document.location.href;
		if (cUrl.indexOf("#") > 0){
			cUrl = cUrl.substring(0,cUrl.indexOf("#"));
		}
		fraAction.document.location.href='about:blank;';
		frm.target = "_self";
		frm.action = cUrl;
		frm.submit();
	}


	//file upload
	function createElem(tag){		
		return document.createElement(tag);
	}

	function winFileUpload(uVal){
		var f;
		try {
			f = createElem('<form></form>');
		} catch(e) {
			f = createElem('form');
		}
		document.body.appendChild(f)
		var winFileUp = window.open("about:blank","winFileUp","toolbar=0,menubar=0,scrollbars=no,resizable=no,width=450,height=150;");
		if(winFileUp != undefined){
			f.action = uVal + "/_action/upload_regist_gsp.asp";
			f.target = "winFileUp";
			f.submit();
			document.body.removeChild(f);
			winFileUp.focus();
		}
	}

	function removeSelectOpt(objSelect, point){
		var objSelLen = objSelect.options.length;
		for (var i = 0; i < objSelLen ; i++){
			objSelect.removeChild(objSelect.options[0]);
		}
	}

	function addSelectOpt(objSelect, txtValue, txtName, objIndex){
		var newOption = document.createElement("OPTION");
		newOption.value = txtValue;
		newOption.text = unescape(txtName);
		var objPoint = (objIndex != undefined && objIndex != '') ? objIndex : 0;
		objSelect.options.add(newOption);
	}

	function setOriUpName(iVal) {
		var txtOriUpfile = document.getElementById("txtOriUpName");
		if (iVal != undifined && txtOriUpfile != undefined)	{
			txtOriUpfile.value = iVal;
		}
	}


	function getPosition(oE,which) {
		var Position = 0;
		while (oE!=null) {
			Position += oE["offset" + which];
			oE = oE.offsetParent;
		}
		return Position;
	}


	function setHandleMove(e){
		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if Internet Explorer
		if ( isIE == true){
			mousePosX = event.x;
			mousePosY = event.y;
		}else{
			mousePosX = window.event.x;
			mousePosY = window.event.y;
		}
		var divSvrChar = document.getElementById("server_cahr");
		var spnSvrCharInfo = document.getElementById("server_charinfo");
		if (divSvrChar != 'undefined' && spnSvrCharInfo != 'undefined'){
			spnSvrCharInfo.innerText = mousePosX + '<br>' + mousePosY;
		}
	}

	/* 브라우저별 이벤트 처리*/
	function addEvent(obj, evType, fn){
		if (obj.addEventListener) {
			obj.addEventListener(evType, fn, true);
			return true;
		} else if (obj.attachEvent) {
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} else {
			return false;
		}
	}

	var mousePosX = 0;
	var mousePosY = 0;
//	addEvent(window.document, 'mousemove', setHandleMove);
//	window.document.onmousemove = setHandleMove;