// Active X 비활성화 대응 : 플래시
function flash(a,b,c,d) {
	var http_on;
	if (location.href.indexOf("https://") != -1) {
		http_on = "https://";
	} else {
		http_on = "http://";
	}

	var flash_tag = "";
	flash_tag = '<OBJECT classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
	flash_tag +='codebase="'+http_on+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0" ';
	flash_tag +='WIDTH="'+a+'" HEIGHT="'+b+'"  id="'+d+'">';
	flash_tag +='<param name="movie" value="'+c+'">';
	flash_tag +='<param name="quality" value="high">';
	flash_tag +='<param name="allowFullScreen" value="true">';
	flash_tag +='<param name="wmode" value="transparent">';//플래시 배경 투명 설정
	flash_tag +='<embed src="'+c+'" quality="high" wmode="transparent" pluginspage="'+http_on+'www.adobe.com/go/getflashplayer" ';
	flash_tag +='type="application/x-shockwave-flash"  WIDTH="'+a+'" HEIGHT="'+b+'"/></object>'
	document.write(flash_tag);
}

// 모달	윈도우 함수	(IE	전용)
function modalWindow(vWidth, vHeight,	vUrl)	{
	var	mdWindow=null;
	//var	kiho = (vUrl.indexOf("?")<0)?"?":"&";
	var	x=(screen.width-vWidth)/2;
	var	y=(screen.height - vHeight)/2;
	opt="status:no;	help:no; edge:raised;";
	opt=opt+"dialogWidth:"+vWidth+"px; dialogHeight:"+vHeight+"px; dialogLeft:"+x+";scroll:no; dialogTop:"+y+";";
	var	mdWindow=showModalDialog(vUrl,'',opt);
}

// 팝업윈도우	함수(원하는	크기로 툴바없이	화면 가운데	띄우기)
function openWindow(vWidth,	vHeight, vUrl, vOpt) {
	var	mdWindow = null;
	var	x	=	(screen.width	-	vWidth)/2;
	var	y	=	(screen.height - vHeight)/2;
	var	opt;
	if (vOpt ==	"" ||	vOpt ==	null)	vOpt = 0;
	opt	=			"width=" + vWidth	+	",height=" + vHeight;
	opt	=	opt	+	",scrollbars=" + vOpt	+	",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0";
	opt	=	opt	+	",outerWidth=" + vWidth	+	",outerHeight="	+	vHeight	+	",resizable=0";
	opt	=	opt	+	",left=" + x + ",top=" + y;
	opt	=	opt	+	",channelmode=no,	titlebar=no";
	var	mdWindow = window.open(vUrl, "openWindow", opt,	false);
}

//인스턴스이름 있는	창 열기.
function openNameWindow(vWidth,	vHeight, vUrl, vName, vOpt)	{
	var	mdWindow = null;
	var	x	=	(screen.width - vWidth)/2;
	var	y	=	(screen.height - vHeight)/2;
	var	opt;
	if (vOpt ==	"" || vOpt == null)	vOpt = 0;
	opt	=			"width=" + vWidth	+	",height=" + vHeight;
	opt	=	opt	+	",scrollbars=" + vOpt	+	",toolbar=0,menubars=0,locationbar=0,historybar=0,statusbar=0";
	opt	=	opt	+	",outerWidth=" + vWidth	+	",outerHeight="	+	vHeight	+	",resizable=0";
	opt	=	opt	+	",left=" + x + ",top=" + y;
	opt	=	opt	+	",channelmode=no,	titlebar=no";
	var	mdWindow = window.open(vUrl, vName,	opt, false);
	if (!mdWindow) {
		alert("팝업차단을 해제해주세요.");
		return false;
	}
	mdWindow.focus();
}

//페이징 링크
function goPage(formNm,	PageNo)	{
	f=document.getElementById(formNm);
	f.page.value=PageNo;
	f.submit();
}

function checkPattern(sType, str)	//형식 체크
{
	var	pattern	=	new	String() ;
	switch (sType){
		case "NUM" :	// 숫자만
			pattern	=/^[0-9]+$/;
			break;
		case "PHONE" :
			pattern	=/^[0-9]{2,4}-[0-9]{3,4}-[0-9]{4}$/;										 //전화번호	형식 : 033-1234-5678
			break;
		case "EMAIL" :
			pattern	=/^[_a-zA-Z\d\-\.]+@([_a-zA-Z\d\-]+(\.[_a-zA-Z\d\-]+)+)/;						//메일
			break;
		case "DOMAIN"	:
			pattern	=/^[.a-zA-Z0-9-]+.[a-zA-Z]+$/; ///영자 숫자와	.	다음도 영자
			break;
		case "ENG" : //영자만
			pattern	=/^[a-zA-Z]+$/;
			break;
		case "ENGNUM"	:	//영자와 숫자
			pattern	=/^[a-zA-Z0-9]+$/;
			break;
		case "HAN" : //	한글만
			pattern	=/^[가-힣]*$/;
			break;
		case "USERID"	:	//첫글자는 영자	그뒤엔 영어숫자	4이상	15자리 이하
			pattern	=/^[a-zA-Z]{1}[a-zA-Z0-9_-]{4,15}$/;
			break;
		case "DATE"	:	// 날짜	:	2002-08-15
			pattern	=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/;
			break;
		case "PASS"	:	// 날짜	:	2010-07-13
			pattern	=/^[_a-z0-9-]{6,16}$/;
			break;
		case "ID"	:
			pattern	=/^[_a-z0-9-]{5,10}$/;
			break;
		default :
		  return false;
		  break;
	}

	//alert(str	+	"|"	+	pattern);

	if(!pattern.test(str)){
			return false;
	}
	return true;
}

//해당패턴으로 검사후	메세지 출력
function isValidType(field,	type,	msg)
{
	if(!checkPattern(type, field.value))
	{
		if(msg !=	"")	alert(msg);
		field.focus();
		return false;
	}
	return true;
}

//숫자만 눌리게	하기 , 방향키	+	Delele + BackSpace 포함
function onlynum() {
	var	iCode	=	event.keyCode;
	if(!(	((iCode	>= 48) &&	(iCode <=	57)) ||	((iCode	>= 37) &&	(iCode <=	40)) ||	(iCode ==	8	)	|| (iCode	== 46	)||	(iCode ==	9	)	)) event.returnValue = false;
}

// 날짜	유효성체크
function isValidDate(yyyy, mm, dd, limitYearS, limitYearE) {
	var	arrLastDay = [31,	28,	31,	30,	31,	30,	31,	31,	30,	31,	30,	31];
	if (!/^[0-9]{4}$/.test(yyyy))	return false;
	if (!/^[0-9]{1,2}$/.test(mm))	return false;
	if (!/^[0-9]{1,2}$/.test(dd))	return false;

	if(limitYearS	!= null	&& limitYearE	!= null){
		if(yyyy	<	limitYearS &&	yyyy > limitYearE) return	false;
	}
	if(limitYearS	!= null){
		if(yyyy	<	limitYearS)	return false;
	}
	if(limitYearE	!= null){
		if(yyyy	>	limitYearE)	return false;
	}

	if (yyyy%1000	!= 0 &&	yyyy%4 ==	0) arrLastDay[1] = 29; //	윤년
	if (dd > arrLastDay[mm-1]	|| dd	<	1) return	false; //	날짜 체크
	if (mm < 1 ||	mm > 12) return	false; //	월 체크
	if (mm%1 !=	0	|| yyyy%1	!= 0 ||	dd%1 !=	0) return	false; //	정수 체크

	return true;
}

// 주민번호	체크
function checkJumin(formname1,formname2){
	var	chk=0
	var	yy=formname1.value.substring(0,2)
	var	mm=formname1.value.substring(2,4)
	var	dd=formname1.value.substring(4,6)
	var	sex=formname2.value.substring(0,1)
	if((formname1.value.length!=6)||(yy<25||mm<1||mm>12||dd<1)){
		formname1.select();
		formname1.focus();
		return false;
	}
	if((sex!=1&&sex!=2)||(formname2.value.length!=7)){
		formname2.select();
		formname2.focus();
		return false;
	}
	for(var	i=0;i<=5;i++){
		chk=chk+((i%8+2)*parseInt(formname1.value.substring(i,i+1)))
	}
	for(var	i=6;i<=11;i++){
		chk=chk+((i%8+2)*parseInt(formname2.value.substring(i-6,i-5)))
	}
	chk=11-(chk	%11)
	chk=chk%10
	if(chk!=formname2.value.substring(6,7)){
		formname2.select();
		formname2.focus();
		return false;
	}
	return true;
}

function CheckValid(String,	space)
{
	var retvalue =	false;

	for (var	i=0; i<String.length;	i++) {
		//String이 0(""	이나 null)이면 무조건	false
		if (space	== true) {
			if	(String.charAt(i)	== ' ')	{
				//String이 0이 아닐때	space가	있어야만 true(valid)
				retvalue = true;
				break;
			}
		}	else {
			if	(String.charAt(i)	!= ' ') {
				//string이 0이 아닐때	space가	아닌 글자가	있어야만 true(valid)
				retvalue = true;
				break;
			}
		}
	}

	return retvalue;
}

//항목이 비어있는지	체크
function isEmpty(field,	error_msg)
{
	if(error_msg ==	"")	{
		if(!CheckValid(field.value,	false))	{
			if (field.type == "text")
			field.focus();
			return true;
		}	else {
			return false;
		}
	}	else {
		if(!CheckValid(field.value,	false))	{
			alert(error_msg);
			if (field.type == "text")
			field.focus()	;
			return true;
		}	else {
			return false;
		}
	}
}

// 투명 PNG 사용하기
function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter =
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='about:blank;';
	return '';
}

/*
	.trim()
*/
String.prototype.trim = function() {
    return this.replace(/(^ *)|( *$)/g, "");
}

/*
	.ltrim()
*/
String.prototype.ltrim = function() {
    return this.replace(/(^ *)/g, "");
}

/*
	.rtrim()
*/
String.prototype.rtrim = function() {
    return this.replace(/( *$)/g, "");
}

//Radio Box, Check Box 체크되어있는지 여부
function isCheck(pName, pMsg) {
	if ($("input[name='"+pName+"']:checked").length < 1) {
		if(pMsg != "") {
			alert(pMsg);
		}

		return false;
	}
	else {
		return true;
	}
}

//Check Box 모두 선택/해제
function checkAll(pId, pName) {
	if ($("#"+pId+":checked").length > 0) {
		$("input[name='"+pName+"']:not(checked)").attr("checked", "checked");
	} else {
		$("input[name='"+pName+"']:checked").attr("checked", "");
	}
}

//입력 Byte 체크
function input_cal_byte(frm, fname, max_byte){
	var fname_str, byte_count=0, fname_length=0, one_str, ext_byte;

	fname_str = new String(fname.value);
	fname_length = fname_str.length;

	for (i=0;i<fname_length;i++){
	  one_str=fname_str.charAt(i);

	  if (escape(one_str).length > 4){
			byte_count+=2;
	  } else if (one_str != '\r'){
			byte_count++;
	  }
	}
	//frm.iTxtByte.value = byte_count;
	$("#iTxtByte").text(byte_count/2);

	if (byte_count > max_byte){
		ext_byte = byte_count - max_byte;
	  alert((max_byte/2)+'자 이상 입력하실수 없습니다.\n\n입력하신 내용 중 초과 '+(ext_byte/2)+'자는 자동 삭제 됩니다.\n');
	  input_cut_text(fname,max_byte);
	}
}

//입력창 byte대로 자르기
function input_cut_text(fname, max_byte){
    var fname_str, byte_count=0, fname_length=0, one_str;

    fname_str = new String(fname.value);
    fname_length = fname_str.length;

    for (i=0;i<fname_length;i++){

        if (byte_count < max_byte){
            one_str=fname_str.charAt(i);

            if (escape(one_str).length > 4){
                byte_count+=2;
            }
            else if (one_str != '\r'){
                byte_count++;
            }
        }
        else{
            fname_str = fname_str.substring(0,i);
            break;
        }
    }

    if ((max_byte%2) ==1){
        fname_length = (fname_str.length-1);
        if (escape(fname_str.charAt(fname_length)).length > 4){
            fname_str = fname_str.substring(0,fname_length);
        }
    }

    fname.value = fname_str;
    return fname_str;
}

//글자수 체크
function checkWordSize(obj, title, max){
	if (obj.value.length>max) {
		obj.blur();
		obj.value = obj.value.substring(0,max-1);
		alert(title+'(은/는) '+max+'자를 초과할 수 없습니다.');
		obj.focus();
	}
}

//팝업 자동 리사이즈
function popupResize(pID, pWidth, pHeight) {
	if (typeof(pWidth) == "undefined" && typeof(pHeight) == "undefined") {
		var width = 0, height = 0;

		if ($.browser.msie) { // IE
			if ($.browser.version == "6.0") {
				width = 37;
				height = 85;
			}
			else if ($.browser.version == "7.0") {
				width = 21;
				height = 108;
			}
			else {
				width = 21;
				height = 108;
			}
		}
		else if ($.browser.mozilla) {	// FF
			width = 18;
			height = 113;
		}
		else if ($.browser.safari) {	// safari, crome
			width = 20;
			height = 85;
		}

		window.resizeTo($("#" + pID).width() + width, $("#" + pID).height() + height);
	}
	else {
		window.resizeTo(pWidth, pHeight);
	}
}

// 플래시 파라미터값으로 이동
function flashMove(pVal, pTarget){
	if (pVal != "#") {
		if (pTarget == "_blank") {
			window.open(pVal,'','');
		} else {
			location.href = pVal;
		}
	}
}

function getCookie(name) {
  var nameOfCookie=name+"=";
  var a=0;

  while(a<=document.cookie.length) {
		var b=(a+nameOfCookie.length);

		if(document.cookie.substring(a,b)==nameOfCookie) {
      if((endOfCookie=document.cookie.indexOf(";",b))==-1)
				endOfCookie=document.cookie.length;

			return unescape(document.cookie.substring(b,endOfCookie));
    }

    a=document.cookie.indexOf(" ",a) +1;

		if(a==0)
			break;
	}

	return "";
}

function setCookie(name, value, expiredays) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

// -------------------------------------------------------------------
// STR : 파일 업로드
function openFileUpload() {
	var iMaxCount = document.getElementById("iMaxCount").value;
	if (iMaxCount == "") { iMaxCount = 3; }
	if (parseInt(iMaxCount) <= parseInt(document.getElementById("selFileList").length)-1) {
		alert("파일첨부는 "+ iMaxCount +"개까지 가능합니다.");
		return;
	}

	openNameWindow(500, 200, "", "file", "");
	document.getElementById("frmMain").target = "file";
	document.getElementById("frmMain").method = "post";
	document.getElementById("frmMain").action = "/common/etc/file_write.asp";
	document.getElementById("frmMain").submit();
}

function fileAdd(pFileName, pRealFileName, pFileSize) {
	var CurFileListLength = document.getElementById("selFileList").length;

	document.getElementById("selFileList").length = CurFileListLength + 1;
	document.getElementById("selFileList").options[CurFileListLength].text = pRealFileName;
	document.getElementById("selFileList").options[CurFileListLength].value = pFileSize;

	document.getElementById("selHiddenList").length = CurFileListLength + 1;
	document.getElementById("selHiddenList").options[CurFileListLength].text = pRealFileName;
	document.getElementById("selHiddenList").options[CurFileListLength].value = pFileName;

	fileSize();
}

function fileDel() {
	var selIndex = document.getElementById("selFileList").selectedIndex;

	if (selIndex <= 0) {
		alert("삭제할 파일을 선택해주세요.");
	}
	else {
		var strFileName = "";
		var strRealFileName = "";
		strFileName = document.getElementById("selHiddenList").options[selIndex].value;
		strRealFileName = document.getElementById("selHiddenList").options[selIndex].text;

		var CurSelListLenght = document.getElementById("selFileList").length;
		var blnFileSavePath = document.getElementById("blnFileSavePath").value;
		var sFilePath = document.getElementById("sFilePath").value;
		$.ajax({
			url: "/common/etc/file_del.asp",
			type: "post",
			data: {"blnFileSavePath":blnFileSavePath,"sFilePath":sFilePath,"sRealFileName":strRealFileName},
			dataType: "json",
			global: false,
			success: function(data){
				if (data.msg != "") {
					alert(data.msg);
				}
				else {
					for (var intLoop = selIndex; intLoop < CurSelListLenght - 1; intLoop++) {
						document.getElementById("selFileList").options[intLoop].text = document.getElementById("selFileList").options[intLoop + 1].text;
						document.getElementById("selFileList").options[intLoop].value = document.getElementById("selFileList").options[intLoop + 1].value;

						document.getElementById("selHiddenList").options[intLoop].text = document.getElementById("selHiddenList").options[intLoop + 1].text;
						document.getElementById("selHiddenList").options[intLoop].value = document.getElementById("selHiddenList").options[intLoop + 1].value;
					}

					document.getElementById("selFileList").length = document.getElementById("selFileList").length - 1;
					document.getElementById("selHiddenList").length = document.getElementById("selHiddenList").length - 1;
				}
			},
			error: function(xhr, status, error) { alert("#error:"+status); }
		});

		fileSize();
	}
}

function fileSize() {
	var intTotalSum = 0;

	for (intLoop=0; intLoop<document.getElementById("selFileList").length; intLoop++) {
		if (intLoop != 0) {
			intTotalSum = intTotalSum + parseInt(document.getElementById("selFileList").options[intLoop].value);
		}
	}

	//토탈 파일 사이즈를 넣어준다.(소수점 한자리까지 넣어준다.)=====================
	document.getElementById("fileTotalSize").innerHTML = fileNumberFormat(intTotalSum);
}

function fileNumberFormat(num) {
	num = Math.round(num / 1024);

	if (num < 1) { num = 1; }

	return num;
}

function fileCheck(frm) {
	var strFileName = "";
	var strRealFileName = "";
	var strFileSize = "";
	if (frm.selHiddenList.length >= 2) {
		for (i=1; i<frm.selHiddenList.length; i++) {
			strFileName += frm.selHiddenList.options[i].value+"^";
			strRealFileName += frm.selHiddenList.options[i].text+"^";
			strFileSize += frm.selFileList.options[i].value+"^";
		}
	}
	frm.arrFileName.value = strFileName;
	frm.arrRealFileName.value = strRealFileName;
	frm.arrFileSize.value = strFileSize;
}

// END : 파일 업로드
// -------------------------------------------------------------------

//select layer
function showon() {
	if(document.getElementById("selsite").style.visibility=="hidden" || document.getElementById("selsite").style.visibility=="") {
		document.getElementById("selsite").style.visibility="visible";
		return false;
	}
	if(document.getElementById("selsite").style.visibility=="visible") {
		document.getElementById("selsite").style.visibility="hidden";
		return false;
	}
}

/* layer show/hide */
function layerShow(layerId) {
	document.getElementById(layerId).style.display = "block";
}

function layerHide(layerId) {
	document.getElementById(layerId).style.display = "none";
}

// -------------------------------------------------------------------
// By HJu 2011-01-11
function flashSetCenter(pVal) {
	if (pVal == "0")  {
		menu_link("LO02");
	}
	else {
		parent.menu_link("LO05");
	}
}

function flashSearch() {
	if (document.frmGSearch.gFindWord.value == "") {
		alert("검색어를 입력해주세요.");
		return false;
	} else {
		return true;
	}
}

function checkIPin() {
	//alert("준비중입니다.");
	//return;

	var frm = document.frmMain;
	window.open("", "popupIPIN","width=450, height=550,top=100,left=100,fullscreen=no,menubar=no,status=no,toolbar=no,titlebar=yes,location=no,scrollbar=no");
	frm.target = "popupIPIN";
	frm.action = "https://cert.vno.co.kr/ipin.cb";
	frm.submit();
}

function setMyScrap(pLogin) {
	//alert("준비중입니다.");
	//return;
	if (pLogin == "False") {
		if (!confirm("마이페이지 스크랩은 로그인 하신 후 이용하실 수 있습니다.\n로그인을 원하시면 확인 버튼을 눌러 주세요.")) return;
		menu_link("LO02");
	}
	else {
		var param = $("#frmMain").serialize();
		$.ajax({
			url: "/common/etc/myscrap_proc.asp",
			type: "post",
			data: param,
			dataType: "json",
			global: false,
			success: function(data){
				if (data.result == true) {
					if (confirm(data.reason)) { menu_link('MY01'); }
				} else {
					alert(data.reason);
				}
			},
			error: function(xhr, status, error) { alert("#error:"+status); }
		});
	}
}

function printBoard() {
	var frm = document.frmMain;
	openWindow(707,	560, "", 1);
	frm.target = "openWindow";
	frm.action = "/print_content.asp";
	frm.submit();
}

