<!--
//==================================================================================================
//■Program Name		: 공통 자바스크립트 함수 모음
//■File	 Name		: /JsFile/Common/common_js.js
//■Description		: 공통 자바스크립트 함수 모음
//■Etc					: 
//==================================================================================================
//※History
//==================================================================================================
//Number		Date				Author		Version			Description
//==================================================================================================
//	1			2008-07-16			이승훈		1.0
//==================================================================================================

//--------------------------------------------------------------------------------------------------
// Form체크를 위한 함수
//--------------------------------------------------------------------------------------------------
String.prototype.IsId = function() {
	if (this.search(/[^A-Za-z0-9_-__-]/) == -1)
		return true;
	else 
		return false;
}

String.prototype.IsPasswd = function() {
	if (this.search(/[^a-z0-9]/)== -1){
		return true;
	}else{
		return false;
	}
}


String.prototype.IsTel = function() {
	if (this.search(/[^0-9_-]/) == -1)
		return true;
	else 
		return false;
}

String.prototype.IsMoney = function() {
	if (this.search(/[^0-9_,]/) == -1)
		return true;
	else 
		return false;
}

String.prototype.IsAlpha = function() {
	if (this.search(/[^A-Za-z]/) == -1)
		return true;
	else
		return false;
}
//psh 2010-01-06 공백도 사용할 수 있는 영문자
String.prototype.EmpAlpha = function() {
   if (this.search(/[^A-Z a-z]/) == -1)
		return true;
   else
		return false;
}

String.prototype.IsNumber = function() {
	if (this.search(/[^0-9]/) == -1)
		return true;
	else
		return false;
}

String.prototype.IsJumin = function() {
	var jumin= this
	if (jumin.length  != 13) 
		return false;
	tval=jumin.charAt(0)*2 + jumin.charAt(1)*3 + jumin.charAt(2)*4
	+ jumin.charAt(3)*5 + jumin.charAt(4)*6 + jumin.charAt(5)*7
	+ jumin.charAt(6)*8+ jumin.charAt(7)*9 + jumin.charAt(8)*2
	+ jumin.charAt(9)*3 + jumin.charAt(10)*4 + jumin.charAt(11)*5;

	tval2=11- (tval % 11);
	tval2=tval2 % 10;
	
	if (jumin.charAt(12)==tval2 &&  (jumin.charAt(6)=="1" ||jumin.charAt(6)=="2")) {
		return true;
	}
	else{
		return false ;
	}
}

String.prototype.IsEmail = function() {
	if (this.search(/(.+)@.+\..+/) == -1)
		return false;
	else {
		for(var i=0; i < this.length;i++)
			if (this.charCodeAt(i) > 256)
				return false;
		return true;
	}
}

String.prototype.IsDate = function() {
	if (this.search(/\d{4}\.\d{2}\.\d{2}/) == -1)
		return false;
	else {
		return true;
	}
}

String.prototype.StrLen = function() {
	var temp;
	var set = 0;
	var mycount = 0;

	for( k = 0 ; k < this.length ; k++ ){
		temp = this.charAt(k);

		if( escape(temp).length > 4 ) {
			mycount += 2
		}
		else mycount++;
	}

	return mycount;
}

String.prototype.LTrim = function() {
	var i, j = 0;
	var objstr

	for ( i = 0; i < this.length ; i++){
		if (this.charAt(i) == ' ' ){
			j = j + 1;
		}
		else{
			break;
		}
	}
	return this.substr(j, this.length - j+1)  
}

String.prototype.RTrim = function() {
	var i, j = 0;

	for ( i = this.length - 1; i >= 0 ; i--){
		if (this.charAt(i) == ' ' ){
			j = j + 1
		}
		else{
			break;
		}
	}
	return 	this.substr(0, this.length - j);
}

String.prototype.Trim = function() {
	return this.replace(/\s/g, "");
}

//--------------------------------------------------------------------------------------------------
// Form 입력값 체크
// formField		form개체
// checkName	
// message		alert메세지
// maxlength		최대입력 byte
// minlength		최소입력 byte
//--------------------------------------------------------------------------------------------------
function checkform(formField, checkName, message, maxlength, minlength) {	

	//각 필드별 입력값 체크
	//주민등록시 반드시 값으로 넘긴다.
	//필수입력 check
	//글자수 check
	//field 유효성 check
		
	formValue = formField.value.LTrim().RTrim();

	if(checkName != 'jumin'){
		if (formField == null ) {
			return false;
		}
	
		if (formValue == '' && minlength > 0){
			alert("请输入"+message);
			_cmdfocus(formField);
			return false;
		}

		if (formValue.StrLen() < minlength) {
			alert(message + " 최소" + minlength + "자(한글" + minlength/2 + " 자)이상 입력하세요.");
			_cmdfocus(formField);
			return false;
		}

		if (formValue.StrLen() > maxlength) {
			alert(message + " 최대" + maxlength + "자(한글" + maxlength/2 + " 자)까지 입력 가능합니다.");
			_cmdfocus(formField);
			return false;
		}
	}		

	switch(checkName) {
		case "" :
			return true;
		//psh 2010-01-06 영문자에 빈공간도 포함하고 있음
		case "empAlpha" :
			if (formValue.EmpAlpha()){
				return true;
			} else {
				alert(message + " 영문자만 입력 가능 합니다.");
				_cmdfocus(formField);
				return false;
			}
		case "alpha" :
			if (formValue.IsAlpha()) {
				return true;
			} else {
				alert(message + " 영문자만 입력 가능 합니다.");
				_cmdfocus(formField);
				return false;
			}
			break;
		case "number" :

			if (formValue.IsNumber()) {
				return true;
			} else {
				alert(message + " 숫자만 입력 가능 합니다.");
				_cmdfocus(formField);		
				return false;
			}
			break;
		case "id" :
			if (formValue.IsId()) {
				return true;
			} else {
				alert(message + " 영문자와 숫자만 입력 가능 합니다.");
				_cmdfocus(formField);		
				return false;
			}
			break;
		case "tel" :
			if (formValue.IsTel()) {
				return true;
			} else {
				alert(message + " 请输入项目");
				_cmdfocus(formField);		
				return false;
			}
			break;
		case "email" :
			if (formValue.IsEmail()) {
				return true;
			} else {
				alert("이메일 형식이 틀립니다. 다시 입력해 주세요(형식: admin@localhost.com)");
				return false;
			}
			break;
		case "date" :
			if (formValue.IsDate()) {
				return true;
			} else {
				alert(message + " 날짜 형식이 틀립니다. 다시 입력해 주세요(형식: 1999.09.09)");
				_cmdfocus(formField);		
				return false;
			}
			break;
		case "jumin" :
			if(formValue.StrLen() != 13){
				alert("주민등록번호를 정확히 입력해주세요");
				return false
			}

			if (formValue.IsJumin()) {
				return true;
			} else {
				alert("주민등록번호를 정확히 입력해주세요");
				return false;
			}
			break;
	}
}

//--------------------------------------------------------------------------------------------------
// Form focus
//--------------------------------------------------------------------------------------------------
function _cmdfocus(formobj){
	formobj.select();
	formobj.focus();
}

//--------------------------------------------------------------------------------------------------
// 검색어에서 입력하지 말아야 할 문자 체크
//--------------------------------------------------------------------------------------------------
function isSearchText(val) {		
	var valid = true;
	var cmp = "!#$%^&*|'<>-;";
	
	for (var i=0; i<val.length; i++) {
		if (cmp.indexOf(val.charAt(i)) > 0) {
			valid = false;
			break;
		}
	}		
	return valid;
}

function isSearchText2(val) {		
	var valid = true;
	var cmp = "$&|=<>-";
	
	for (var i=0; i<val.length; i++) {
		if (cmp.indexOf(val.charAt(i)) > 0) {
			valid = false;
			break;
		}
	}		
	return valid;
}



//--------------------------------------------------------------------------------------------------
//이미지가 클시 이미지 사이즈 줄이기
//--------------------------------------------------------------------------------------------------
function imgResize(which, max_width){
	var width = eval("document."+which+".width");
	var height = eval("document."+which+".height");
	var temp = 0;

	if ( width > max_width ) {  
	   height = height/(width / max_width);
	   eval("document."+which+".width = max_width");
	   eval("document."+which+".height = height");
	}
}

//--------------------------------------------------------------------------------------------------
// 숫자만 입력가능
//ex) 입력방법 (단 Comm_Js.js가 Include 되어있어야 한다.
//onkeyPress="javascript:numberKeyPress();" style="ime-mode; disabled" 
//--------------------------------------------------------------------------------------------------
function numberKeyPress(){
	
	//alert(event.keyCode);
	if ((event.keyCode<48) || (event.keyCode>57)){ 
		event.returnValue=false;
		return;
	}
	event.returnValue=true;
}

//숫자입력시 금액에 맞춰서 ,를 리턴하는 함수
function formatComma(tx) {
  var oldv = "";
  if(oldv == tx.value) return;
  oldv = tx.value;
  tx.value = formatNumber(oldv);
}

//
function formatNumber(s) {
  var str  = s.replace(/\D/g,"");
  var len  = str.length;
  var tmp  = "";
  var tm2  = "";
  var i    = 0;
  while (str.charAt(i) == '0') i++;
  str = str.substring(i,len);
  len = str.length;
  if(len < 3) {
    return str;
  } else {
    var sit = len % 3;
    if (sit > 0) {
      tmp = tmp + str.substring(0,sit) + ',';
      len = len - sit;
    }
    while (len > 3) {
      tmp = tmp + str.substring(sit,sit+3) + ',';
      len = len - 3;
      sit = sit + 3;
    }
    tmp = tmp + str.substring(sit,sit+3) + tm2;
    str = tmp;
  }
  return str;
}

//--------------------------------------------------------------------------------------------------
//openWin_Scrollbars:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바등을 모든 값을 정의하는 창입니다.)
//--------------------------------------------------------------------------------------------------
function openWinDefinition(url,Center,Toolbar,Resizable,Scrollbars,Width,Height,Left,Top) {
 	window.open(url, "", "toolbar=" + Toolbar + ",resizable=" + Resizable + ",scrollbars=" + Scrollbars + ",width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top);
}

//--------------------------------------------------------------------------------------------------
//업로드하는 파일 체크
//	obj	파일개체	ex) document.form.file_name
// exe	허용확장자 ex) jpg,gif
// maxFileSize		ex) 
//--------------------------------------------------------------------------------------------------
function chkUploadFile(object, exe, maxFileSize, isNull) {
	var src = getFileExtension(object.value);
	var tmp = object.value;

	/*null입력 체크*/
	if(src == "") {
			if(isNull) {
				return true;
			} 
			else {
				alert("파일은 필수항목입니다.");
				return false;
			}
	} 
	else{
		var filename = tmp.substring(tmp.lastIndexOf('\\') + 1);

		/*허용되는 확장자 체크*/
		if(exe.trim() != "") {
			var fileEXE = exe.split(",");
			var cnt = 0;
			for(var i = 0; i < fileEXE.length; i++) if(fileEXE[i].toLowerCase().trim() == src.toLowerCase()) cnt++;
			if(cnt == 0) {
				alert('허용되지 않는 파일의 확장자입니다.');
				return false;
			}
		}
		/*파일크기체크*/
/*
		if(maxFileSize != "" & maxFileSize > 0){
			var imgInfo = new Image();
			imgInfo.src = object.value;
			if(parseInt(imgInfo.fileSize) > maxFileSize) {
				alert("파일 크기를 체크해 주세요.");
				return false;
			} else {
				return true;
			}
		}
*/
	}
	return true;
}

//--------------------------------------------------------------------------------------------------
//레이어 show/hide부분
//--------------------------------------------------------------------------------------------------
function MM_showHideLayers() { //v9.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) 
		with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
			if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
		obj.visibility=v; }
}

//==================================================================================================
//■Program Name		: chkJuminNo
//■Description		: 주민번호 체크 함수
//■Values			: str1 - 주민번호 앞자리
//					  str2 - 주민번호 뒷자리
//==================================================================================================
function chkJuminNo(str1, str2) {
	if (chkNumber(str1) == false) return false;
	if (chkNumber(str2) == false) return false;

	var x, y, z;
	var L11,L12,L13,L14,L15,L16;
	var L21,L22,L23,L24,L25,L26,L27;

	L11 = parseInt(str1.substring(0,1));
	L12 = parseInt(str1.substring(1,2));
	L13 = parseInt(str1.substring(2,3));
	L14 = parseInt(str1.substring(3,4));
	L15 = parseInt(str1.substring(4,5));
	L16 = parseInt(str1.substring(5,6));
	L21 = parseInt(str2.substring(0,1));
	L22 = parseInt(str2.substring(1,2));
	L23 = parseInt(str2.substring(2,3));
	L24 = parseInt(str2.substring(3,4));
	L25 = parseInt(str2.substring(4,5));
	L26 = parseInt(str2.substring(5,6));
	L27 = parseInt(str2.substring(6,7));
	x = (L11*2) + (L12*3) + (L13*4) + (L14*5) + (L15*6) + (L16*7) + (L21*8) + (L22*9) + (L23*2) + (L24*3) + (L25*4) + (L26*5);
	y = x % 11;
	z = 11 - y;

	if (z == 10) z = 0;
	else if (z == 11) z = 1;
	if (z == parseInt(str2.substring(6,7))) {
		return true;
	} else {
		return false;
	}

	return false;
}

//==================================================================================================
//■Program Name		: chkNumber
//■Description		: 입력 필드에 들어온 데이타가 숫자면 true, 숫자가 아니라면 false를 리턴한다.
//■Values			: num   - 체크하고자하는 필드값
//					  fName - alert메세지를 뿌려줄것인지 구분 메세지를 넣어주면 해당메세지와 함께 alert창이 뜨고
//							- 메세지를 넣어주지않으면 alert창이 뜨지 않는다.
//==================================================================================================
function chkNumber(num) {
	var numTemp   = Number(num);

	//값이 있다면
	if(num != "") {
		//숫자면 false반환 - if는 문자라면
		if(isNaN(numTemp)) return false;
		else return true;
	} else {
		return false;
	}
}

//사업자등록번호 체크
function chkREG_NO(strNumb) {
	sumMod	=	0;
	sumMod	+=	parseInt(strNumb.substring(0,1));
	sumMod	+=	parseInt(strNumb.substring(1,2)) * 3 % 10;
	sumMod	+=	parseInt(strNumb.substring(2,3)) * 7 % 10;
	sumMod	+=	parseInt(strNumb.substring(3,4)) * 1 % 10;
	sumMod	+=	parseInt(strNumb.substring(4,5)) * 3 % 10;
	sumMod	+=	parseInt(strNumb.substring(5,6)) * 7 % 10;
	sumMod	+=	parseInt(strNumb.substring(6,7)) * 1 % 10;
	sumMod	+=	parseInt(strNumb.substring(7,8)) * 3 % 10;
	sumMod	+=	Math.floor(parseInt(strNumb.substring(8,9)) * 5 / 10);
	sumMod	+=	parseInt(strNumb.substring(8,9)) * 5 % 10;
	sumMod	+=	parseInt(strNumb.substring(9,10));
	
	if	(sumMod % 10	!=	0)
	{		
		return false;
	}
	return	true;
}

//통합검색 Enter 제어
function OnTopSearchEnter() {
	if (event.keyCode == "13") {
		OnTopSearch();
	}
}

//통합검색
function OnTopSearch() {
	var frm = document.topSearch;

	if (checkform(frm.topSearchText, "", "검색어는", 50, 2) == false) {
		return;
	}

	if (isSearchText(frm.topSearchText.value) == false) {
		alert("검색어에 사용할 수 없는 문자가 있습니다.");
		frm.topSearchText.value = "";
		frm.topSearchText.focus();
		return;
	}
	
	frm.target = "_self";
	frm.action = "/Search_result.asp";
	frm.submit();
}

//날짜계산
<!--
function addDay(yyyy, mm, dd, pDay) // 년, 월, 일, 계산할 일자 (년도는 반드시 4자리로 입력)
{
	var oDate; // 리턴할 날짜 객체 선언
	dd = dd*1 + pDay*1; // 날짜 계산
	mm--; // 월은 0~11 이므로 하나 빼준다
	oDate = new Date(yyyy, mm, dd) // 계산된 날짜 객체 생성 (객체에서 자동 계산)
	return oDate;
}

function addMonth(yyyy, mm, dd, pMonth) // 년, 월, 일, 계산할 월 (년도는 반드시 4자리로 입력)
{
	var cDate; // 계산에 사용할 날짜 객체 선언
	var oDate; // 리턴할 날짜 객체 선언
	var cYear, cMonth, cDay // 계산된 날짜값이 할당될 변수
	mm = mm*1 + ((pMonth*1)-1); // 월은 0~11 이므로 하나 빼준다
	cDate = new Date(yyyy, mm, dd) // 계산된 날짜 객체 생성 (객체에서 자동 계산)

	cYear = cDate.getFullYear(); // 계산된 년도 할당
	cMonth = cDate.getMonth(); // 계산된 월 할당
	cDay = cDate.getDate(); // 계산된 일자 할당
	oDate = (dd == cDay) ? cDate : new Date(cYear, cMonth, 0); // 넘어간 월의 첫쨋날 에서 하루를 뺀 날짜 객체를 생성한다.

	return oDate;
}

function calcDate(f, y, m, d, i)
{

	var cDate;

	if(f == 1 ){
		cDate = addDay(y, m, d, i)
	}else{
		cDate = addMonth(y, m, d, i)
	}
	var sMonth;
	var sDay;

	sMonth = cDate.getMonth()+1;

	if (sMonth < 10){
		sMonth = "0" + sMonth;
	}

	sDay = cDate.getDate();
	if (sDay < 10){
		sDay = "0" + sDay;
	}

	var calDate = cDate.getFullYear() +"-" + sMonth +"-"+ sDay;

	return calDate;


}

/*replace all*/
function strReplaceAll(str, s, d){
   var i=0;
   while(i > -1){
      i = str.indexOf(s);
      str = str.substr(0,i) + d + str.substr(i+1, str.length);
   }
   return str;
}

// 
function SetLeftOil(val) {
	var elleftHOil = document.getElementById("leftHOil");
	var elleftKOil = document.getElementById("leftKOil");

	if (val == "K") {
		elleftHOil.style.display = "none";
		elleftKOil.style.display = "block";
	} else {
		elleftHOil.style.display = "block";
		elleftKOil.style.display = "none";
	}
}

//--------------------------------------------------------------------------------------------------
// 두 날짜사이의 간격
//--------------------------------------------------------------------------------------------------
	//입력형식:"YYYY/MM/DD"(다른 형식은 에러입니다.)
	function DateDiff(FromDate, ToDate){
		var D1,D2,Diff;						//변수를 선언합니다.
		var MinMilli = 1000 * 60;			//변수를 초기화합니다.
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;
		D1 = Date.parse(FromDate);			//구문 분석합니다.
		D2 = Date.parse(ToDate);			//구문 분석합니다.
		Diff = Math.round(Math.abs((D2-D1) / DyMilli))
		if (Diff>-1) {
			Diff= Diff + 1;
		} else {
			Diff= Diff - 1;
		}
		return(Diff);						//결과를 반환합니다.
	}
//--------------------------------------------------------------------------------------------------
// 라디오 박스 체크
//--------------------------------------------------------------------------------------------------
	function GetRadioValue(opt) {		
		var leng = ((isNaN(opt.length*1))?1:opt.length*1);
		
		if (leng == 1)
		{
				if (opt.checked)
				{
					return opt.value;
				}
		}
		else {
			var n = opt.length;			
			for (i=0; i<n; i++) {
				if (opt[i].checked) {					
					return opt[i].value;
				}
			}
		}
		return "";
	}
//--------------------------------------------------------------------------------------------------
// 체크박스 체크개수 반환
//--------------------------------------------------------------------------------------------------
	function GetCheckCount(opt) {		
		var leng = ((isNaN(opt.length*1))?1:opt.length*1);
		var chkcnt = 0;
		if (leng == 1)
		{
				if (opt.checked)
				{
					chkcnt = 1;
				}
		}
		else {
			var n = opt.length;			
			for (i=0; i<n; i++) {
				if (opt[i].checked) {					
					chkcnt = chkcnt + 1;
				}
			}
		}
		return chkcnt;
	}

//--------------------------------------------------------------------------------------------------
// Setting default value - combo, radio
//--------------------------------------------------------------------------------------------------
function setSelect(elName, targetValue){
    var el;
    el = document.getElementById(elName);
    
    switch (el.type) {
        case 'select-one':
            for (var i = 0; i < el.length; i++) {
                if (el.options[i].value == targetValue) {
                    el.options[i].selected = true;
                }
            }
            break;
            
        case 'radio':
            var radioEl = document.getElementsByName(elName);
            for (var i = 0; i < radioEl.length; i++) {
                if (radioEl[i].value == targetValue) {
                    radioEl[i].checked = true;
                    break;
                }
            }
            break;
    }
}

//--------------------------------------------------------------------------------------------------
// Next Form 필드
//--------------------------------------------------------------------------------------------------
	function Go_Next(curField, nextField, curLength){
		if (curField.value.length >= curLength){
			nextField.focus();
		}
	}


var imgObj = new Image();
function showImgWin(imgName) {
	imgObj.src = imgName;
	setTimeout("createImgWin(imgObj)", 100);
}
function createImgWin(imgObj) {
	if (! imgObj.complete) {
		setTimeout("createImgWin(imgObj)", 100);
		return;
	}
	imageWin = window.open("", "imageWin",
	"width="+imgObj.width+",height="+imgObj.height+"");
	imageWin.document.write("<html><body style='margin:0'>");
	imageWin.document.write("<a href='JavaScript:self.close();'><img src='" + imgObj.src + "' border='0' title='"+imgObj.src+"' width='"+imgObj.width+"' height='"+imgObj.height+"'></a>");
	imageWin.document.write("</body><html>");
	imageWin.document.title = imgObj.src;
}

//--------------------------------------------------------------------------------------------------
// 주소복사
//--------------------------------------------------------------------------------------------------
function copyWid(objNm) {
	window.clipboardData.setData('Text', objNm);
	alert("게시판 주소가 복사되었습니다.\n메신져나 게시판에 Ctrl + V로 붙여넣기 하세요.");
	return;
}

function popImage(clubid){
	open_wnd("/common/editor/Editor_About/inc_pop/popImage.asp?gubun="+clubid, "addimage", 330, 300);
}

function popFile(clubid){
	open_wnd("/common/editor/Editor_About/inc_pop/AttachFileView.asp?gubun="+clubid, "addfile", 330, 200);
}

function open_window(url, name, width, height, feature) {
    var oWnd;
	var IE4 = "";

    if (IE4 && width < window.screen.width && height < window.screen.height) 
    {
        var windowX = Math.ceil( (window.screen.width  - width) / 2 );
        var windowY = Math.ceil( (window.screen.height - height) / 2 );

        oWnd = window.open(url, name, feature+",width=" + width +",height=" + height+",left="+windowX+",top="+windowY + ",resizable=yes");
    }
    else 
    {
			alert("@@@");
        oWnd = window.open(url, name, feature+",width=" + width +",height=" + height + ",resizable=yes");
    }

    return oWnd;
}

function open_wnd(url, name, width, height) {
    var oWnd = open_window(url, name, width, height, "toolbar=0,menubar=0,resizable=yes,scrollbars=no");
    return oWnd;
}


function addList(dirname, filename, filesize, filetype){// 폴 첨부
	if (filename == 'poll@nhn'){
		document.getElementById("attachfilelist").options.add(new Option('폴이 첨부되었습니다' , filename));

	}else{ // 일반 파일 첨부
		if (filesize){
			calcFileSize(filesize, filetype, 1);
			document.getElementById("attachfilelist").options.add(new Option(filename + "   " + parseInt(parseInt(filesize)/1024) + "KB", dirname +"/" + filename));
		}else{
			document.getElementById("attachfilelist").options.add(new Option(filename, dirname +"/" + filename));
		}
	}
}


function addListEn(dirname, filename, filesize, filetype){// 폴 첨부
	if (filename == 'poll@nhn'){
		document.getElementById("attachfilelistEn").options.add(new Option('폴이 첨부되었습니다' , filename));

	}else{ // 일반 파일 첨부
		if (filesize){
			calcFileSizeEn(filesize, filetype, 1);
			document.getElementById("attachfilelistEn").options.add(new Option(filename + "   " + parseInt(parseInt(filesize)/1024) + "KB", dirname +"/" + filename));
		}else{
			document.getElementById("attachfilelistEn").options.add(new Option(filename, dirname +"/" + filename));
		}
	}
}


function addFile(dirname, filename, filesize, filetype, thumbnailnameOrImagewidth, playtimeOrImageHeight, thumbnailtime){
	
	if (filetype == "F") document.getElementById("attachfileyn").value = "Y";

	if (filetype == "I"){	// image file
		document.getElementById("attachimageyn").value = "Y";
		document.getElementById("attachfiles").value = document.getElementById("attachfiles").value + dirname +"/" + filename + "|" + filetype + "|"
		+ thumbnailnameOrImagewidth + "|" + playtimeOrImageHeight + "||";	// imagewidth, imageheight 의 용도로 사용됨.

	}else if (filetype == "M"){  // movie file 
		document.getElementById("attachmovie").value = "true";    
		document.getElementById("attachfiles").value = document.getElementById("attachfiles").value + dirname +"/" + filename + "|" + filetype + "|"
		+ thumbnailnameOrImagewidth + "|" + playtimeOrImageHeight + "|" + thumbnailtime + "||";	// thumbnail, playtime의 용도로 사용됨.

	}else		// other. include "F"
		document.getElementById("attachfiles").value = document.getElementById("attachfiles").value + dirname +"/" + filename + "|" + filetype + "||";
		document.getElementById("attachsizes").value = document.getElementById("attachsizes").value + filesize + "||"; 

}


function addFileEn(dirname, filename, filesize, filetype, thumbnailnameOrImagewidth, playtimeOrImageHeight, thumbnailtime){
	
	if (filetype == "F") document.getElementById("attachfileynEn").value = "Y";

	if (filetype == "I"){	// image file
		document.getElementById("attachimageynEn").value = "Y";
		document.getElementById("attachfilesEn").value = document.getElementById("attachfilesEn").value + dirname +"/" + filename + "|" + filetype + "|"
		+ thumbnailnameOrImagewidth + "|" + playtimeOrImageHeight + "||";	// imagewidth, imageheight 의 용도로 사용됨.

	}else if (filetype == "M"){  // movie file 
		document.getElementById("attachmovieEn").value = "true";    
		document.getElementById("attachfilesEn").value = document.getElementById("attachfilesEn").value + dirname +"/" + filename + "|" + filetype + "|"
		+ thumbnailnameOrImagewidth + "|" + playtimeOrImageHeight + "|" + thumbnailtime + "||";	// thumbnail, playtime의 용도로 사용됨.

	}else		// other. include "F"
		document.getElementById("attachfilesEn").value = document.getElementById("attachfilesEn").value + dirname +"/" + filename + "|" + filetype + "||";
		document.getElementById("attachsizesEn").value = document.getElementById("attachsizesEn").value + filesize + "||"; 

}

function calcFileSize(filesize, filetype, oper){
	var objRealSum = document.getElementById("attachsizerealsum");
	var objImageSum = document.getElementById("attachimagesizesum");
	var objFileSum = document.getElementById("attachfilesizesum");

	if (oper == 1){
		objRealSum.value = parseInt(objRealSum.value,10) + parseInt(filesize,10);
		if(filetype=="I"){ //image
			objImageSum.value = parseInt(objImageSum.value,10) + parseInt(filesize,10);
		}else{ //file
			objFileSum.value = parseInt(objFileSum.value,10) + parseInt(filesize,10);
		}
	}else{
		objRealSum.value = parseInt(objRealSum.value,10) - parseInt(filesize,10);
		if(filetype=="I"){ //image
			objImageSum.value = parseInt(objImageSum.value,10) - parseInt(filesize,10);
		}else{ //file
			objFileSum.value = parseInt(objFileSum.value,10) - parseInt(filesize,10);
		}
	}
	document.getElementById("attachsizesum").value = parseInt(objRealSum.value/1024);
}


function calcFileSizeEn(filesize, filetype, oper){
	var objRealSum = document.getElementById("attachsizerealsumEn");
	var objImageSum = document.getElementById("attachimagesizesumEn");
	var objFileSum = document.getElementById("attachfilesizesumEn");

	if (oper == 1){
		objRealSum.value = parseInt(objRealSum.value,10) + parseInt(filesize,10);
		if(filetype=="I"){ //image
			objImageSum.value = parseInt(objImageSum.value,10) + parseInt(filesize,10);
		}else{ //file
			objFileSum.value = parseInt(objFileSum.value,10) + parseInt(filesize,10);
		}
	}else{
		objRealSum.value = parseInt(objRealSum.value,10) - parseInt(filesize,10);
		if(filetype=="I"){ //image
			objImageSum.value = parseInt(objImageSum.value,10) - parseInt(filesize,10);
		}else{ //file
			objFileSum.value = parseInt(objFileSum.value,10) - parseInt(filesize,10);
		}
	}
	document.getElementById("attachsizesumEn").value = parseInt(objRealSum.value/1024);
}

function removeAttach(clubid){
	
	var attachlist = document.getElementById("attachfilelist");

	if (attachlist.selectedIndex <= 0)
		return;

	if (confirm("첨부된 파일을 삭제하시겠습니까?")) {
		if (attachlist.options[attachlist.selectedIndex].value == "poll@nhn")
			removePoll();
		else
			removeFile(attachlist.selectedIndex-1,clubid);

		attachlist.remove(attachlist.selectedIndex);    
	}
}

function removeFile(index,clubid){
	var reArrAttachfiles = "";
	var reArrAttachsize = "";

	arrAttachfile = document.getElementById("attachfiles").value.split("||");
	arrAttachsize = document.getElementById("attachsizes").value.split("||");
	arrAttach = document.getElementById("attachsizes").value.split("||");

	calcFileSize(arrAttachsize[index], -1);    

	filestring = arrAttachfile[index].split("|");
	var filename = filestring[0];
	
	document.getElementById("url").value = filename;
	document.regForm.target = "com_iFrame";
	document.regForm.method = "post";
	document.regForm.action = "/common/editor/Editor_About/UrlEncoding.asp?gubun="+clubid;
	document.regForm.submit();

	//remove(arrAttachfile,index);
	//remove(arrAttachsize,index);

	for (i = 0; i < arrAttachfile.length-1; i++) {
		if (i != index) {
			reArrAttachfiles += arrAttachfile[i] + "||";
		}
	}

	document.getElementById("attachfiles").value = reArrAttachfiles;
	document.getElementById("attachsizes").value = arrAttachsize.join("||");
	document.getElementById("attachfileyn").value = "";
	document.getElementById("attachimageyn").value = "";

	for (var i = 0; i<arrAttachfile.length; i++){
		if (arrAttachfile[i].match(/\|F$/)){
			document.getElementById("attachfileyn").value = "Y";
		}
		if (arrAttachfile[i].match(/\|I\|/)){
			document.getElementById("attachimageyn").value = "Y";
		}
		if (arrAttachfile[i].match(/\|M\|/)){
//			document.getElementById("attachmovie").value = "true";
		}
	}

}

function isImageFile(filename)
{
    if (filename.match(/(.jpg|.jpeg|.gif|.png)$/i))
        return true;
    else
        return false;
}

function isValidFilename(filename)
{
    if (!filename.match(/[\\\:\*\?\|<>]/))
        return true;
    else
        return false;
}

function imageopen(url,w,h)
{
	window.open(url);
}

// 입력값의 바이트 길이를 리턴
function getByteLength(input) {
	var byteLength = 0;

	for (var inx=0; inx < input.value.length; inx++) {
		var oneChar = escape(input.value.charAt(inx));

		if (oneChar.length == 1) {
			byteLength++;
		} else if (oneChar.indexOf("%u") != -1) {
			byteLength += 2;
		} else if (oneChar.indexOf("%") != -1) {
			byteLength += oneChar.length/3;
		}
	}

	return byteLength;
}

/**
 * 객체를 인자로 받아 인자가 원래 array 이면 그대로 리턴하고, 아니면 크기가 1인 array로 만들어 리턴한다.
 * @param oneOrArray
 */
function getObjArray(oneOrArray){

	if(oneOrArray==null) return null;
	else if(oneOrArray.length >= 1){
		return oneOrArray;
	}else{
		var newArray = new Array(1);
	    newArray[0]  = oneOrArray;
		return newArray;
	}

}

//라디오체크 값을 반환한다.
function getChekcedValue(chkObj){

	var radio = getObjArray(chkObj);
	var val = "";
	for(var i=0; i<radio.length; i++){
		if(radio[i].checked){
			val = radio[i].value;
			break;
		}
	}

	return val;
}

function loginPopUp(){
	open_wnd("/member/login/login.asp", "login", 510, 295);
}

/**
 * 덧글 입력시 해당 영역에 글자 수를 출력해주고 최대 글자 수에 걸리면 alert 메시지를 제공한다.
 * ex) 덧글 textarea에 onkeyup="document.getElementById('글자수 출력 영역ID').innerHTML=getLength(덧글입력 textarea의 value값, '글자수 출력 영역ID', '덧글입력 textareaID', 최대 글자 수);"
 *
 */
function getLength(s, id, txtId, limit){
	document.getElementById(id).innerHTML = "";

    var sum = 0;
    var len = s.length;
    for (var i=0; i<len; i++) {
		sum++;
    }
	if(sum > limit){
		alert("최대 " + limit + "자 이내로 작성해 주시기 바랍니다.");
		sum = limit;
		document.getElementById(txtId).value = s.substring(0, limit);
	}
    return sum;
}


function setOnlyNumber(event){

    event = checkEvent(event);  /* 이벤트 값 가져오기 */
    var pKey = String.fromCharCode(event.which);
    var intReg = /[0-9\\-]/g;
	
    if(pKey!="\r" && !intReg.test(pKey)) /* 엔터키 및 regkey가 아닐경우 리턴 */
        event.returnValue=false;

    delete intReg;
}

/**
 * 이벤트 체크
 * Firefox와 IE간 호환을 위함
 */
function checkEvent(event) {
 if (!event) { /* IE일 경우 */
  event = window.event;
  event.target = event.srcElement;
  event.which = event.keyCode;
 }
 return event;
}

/**
 * 스크롤바 없는 팝업창 띄움 
 */
function popNoScrollCenter(url,name,w,h)
{
	var px = (screen.availWidth/2)-(w/2)
	var py = (screen.availHeight/2)-(h/2)
	var popWins = window.open(url,name,'left='+px+',top='+py+',width='+w+',height='+h+',scrollbars=no');
	popWins.focus();
}

/* 문자열 크기 계산  strCheckByte(Object,최대크기) */
function strCheckByte(obj, maxlength) {
	var charOne = "";
	var charCount = 0;
	var charTemp = "";
	var objForm = obj;
	
	for(var i=0; i<objForm.value.length; i++){
		charOne = objForm.value.charAt(i);

		if(escape(charOne).length > 4){
			charCount += 2;
		}else if(charOne != '\r'){
			charCount++;
		}

		if(charCount > maxlength){
			alert("허용된 글자수[한글:"+ Math.floor(maxlength/2) +", 영문:"+ maxlength +"]가 초과되었습니다.\r\n초과된 부분은 자동으로 삭제됩니다.");
			objForm.value = objForm.value.substr(0,200);
			break;
		}
	}
}

function initMoving(target, position, topLimit, btmLimit) {
 if (!target)
  return false;

 var obj = target;
 obj.initTop = position;
 obj.topLimit = topLimit;
 obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;
 obj.style.position = "absolute";             // relative로 absolute로  이부분은 레이아웃에 따라 정의
 obj.top = obj.initTop;
 obj.left = obj.initLeft;
 if (typeof(window.pageYOffset) == "number") {
  obj.getTop = function() {
   return window.pageYOffset;
  }
 } else if (typeof(document.documentElement.scrollTop) == "number") {
  obj.getTop = function() {
   return document.documentElement.scrollTop;
  }
 } else {
  obj.getTop = function() {
   return 0;
  }
 }

 if (self.innerHeight) {
  obj.getHeight = function() {
   return self.innerHeight;
  }
 } else if(document.documentElement.clientHeight) {
  obj.getHeight = function() {
   return document.documentElement.clientHeight;
  }
 } else {
  obj.getHeight = function() {
   return 500;
  }
 }

 obj.move = setInterval(function() {
  if (obj.initTop > 0) {
   pos = obj.getTop() + obj.initTop;
  } else {
   pos = obj.getTop() + obj.getHeight() + obj.initTop;
   //pos = obj.getTop() + obj.getHeight() / 2 - 15;
  }

  if (pos > obj.bottomLimit)
   pos = obj.bottomLimit;
  if (pos < obj.topLimit)
   pos = obj.topLimit;

  interval = obj.top - pos;
  obj.top = obj.top - interval / 3;
  obj.style.top = obj.top + "px";
 }, 80)                        // 30은 속도를 의미
}

function show(idx) {
		if(idx =='1'){
			location.href = "/menu/newList.asp";
		}else if(idx =='2'){
			location.href = "/enter/coupon/list.asp";
		}else if(idx =='3'){
			location.href = "/network/market/list.asp";
		}
	}
//-->
