﻿// 파일업로드시 허용할 확장자
function ChkFileAllowEx(oFileItem, sExt, sMsg) {

    if (!oFileItem.value) return;

    var extFileFormat = "\.(" + sExt + ")$";  //허용할 확장자들

    if ((new RegExp(extFileFormat.toUpperCase(), "i")).test(oFileItem.value.toUpperCase())) return true;

    alert(sMsg);
    oFileItem.outerHTML = oFileItem.outerHTML;
    return false;
}

// 파일업로드시 개수제한
function ChkFileLmCnt(oFileItemTable, nLmSize, sMsg) {

    var oTbl = oFileItemTable.getElementsByTagName('INPUT');
    var cnt = 0;
    for (var i = 0; i < oTbl.length; i++) if (oTbl(i).type == 'hidden' && oTbl(i).value == 'C') {
        cnt++;
    }

    if (cnt >= nLmSize) {
        alert(sMsg);
        return false;
    }
    return true;
}

//공통 우편번호 찾기 팝업
function f_findZipCode(zip1, zip2, addr1, addr2) {
    var url = "/Cmn/UserCtrl/ZipCode/ZipCodeP.aspx?zip1=" + zip1 + "&zip2=" + zip2 + "&addr1=" + addr1 + "&addr2=" + addr2;
    var popFindZipCode = window.open(url, "popFindZipCode", "scrollbars=no, width=430, height=365");
    popFindZipCode.focus();
}


// 체크박스  전체선택/해제
// 주의 !! 반드시 전체선택 체크 박스의 itemname (선택될 아이템의 name) 이 속성으로 있어야 한다.
function SetAllChecked(oCheckbox) {
    var oList = document.getElementsByName(oCheckbox.attributes["itemname"].value);
    if (oList == null)
        return;
    var chk = oCheckbox.checked;

    oList.checked = chk;
    for (count = 0; count < oList.length; count++) {
        if (oList[count].checked == chk)
            continue;

        oList[count].checked = chk;

    }
}

// 체크 박스 목록이 선택된게 있는지
// 주의 !! 반드시 전체선택 체크 박스의 itemname (선택될 아이템의 name) 이 속성으로 있어야 한다.
function IsCheckedList(oCheckbox, sMsg) {
    var oList = document.getElementsByName(oCheckbox.attributes["itemname"].value);
    if (oList == null)
        return false;
    var bRes = false;

    for (count = 0; count < oList.length; count++) {
        if (oList[count].checked) {
            bRes = true; break;
        }
    }

    if (!bRes) {
        if (sMsg != "") alert(sMsg);

        return false;
    }
    else
        return true;
}

//체크 박스 name으로 체크
function IsCheckedListNoHead(sCheckbox, sMsg) {
    var oList = document.getElementsByName(sCheckbox);
    if (oList == null)
        return false;
    var bRes = false;

    for (count = 0; count < oList.length; count++) {
        if (oList[count].checked) {
            bRes = true; break;
        }
    }

    if (!bRes) {
        if (sMsg != "") alert(sMsg);

        return false;
    }
    else
        return true;
}

// 라디오버튼리스트 선택된 항목
function GetCheckedRBL(oTag) {

    var res = '';
    if (oTag != null) {
        var rbl = oTag.getElementsByTagName("INPUT");
        var chk = false;
        for (var i = 0; i < rbl.length; i++) {
            if (rbl(i).type == "radio") {
                if (rbl(i).checked) {
                    res = rbl(i).value; break;
                }
            }
        }
    }
    return res;
}

// 라디오버튼리스트 항목선택
function SetRBLValue(oTag, val) {

    var res = '';
    if (oTag != null) {
        var rbl = oTag.getElementsByTagName("INPUT");
        var chk = false;
        for (var i = 0; i < rbl.length; i++) {
            if (rbl(i).type == "radio" && rbl(i).value == val) {
                rbl(i).checked = true;   break;
            }
        }
    }
    return res;
}

// 드롭다운리스트 선택된 항목
function GetCheckedDDL(oTag) {

    var res = '';
    if (oTag != null) {
        if (oTag.selectedIndex > 0 && oTag.options[oTag.selectedIndex].value != "" && oTag.options[oTag.selectedIndex].value != "0") {
            res = oTag.options[oTag.selectedIndex].value;
        }
    }
    return res;
}

// 드롭다운리스트 항목선택
function SetDDLValue(oTag, val) {

    var res = '';
    if (oTag != null) {
        for (var i = 0; i < oTag.options.length; i++) {
            if (oTag.options[i].value == val) {
                oTag.selectedIndex = i; break;
            }
        }
    }
    return res;
}
/* =======================================================
달력컨트롤에 기간셋팅
=======================================================
<매개변수>
sDateTy:날짜유형(Y-년,M-월,D-일)
nVal:간격
oStDt:시작달력컨트롤object
oEtDt:종료달력컨트롤object

<예>
1주일의 기간셋팅
SetCalendar ('D', 7, document.getElementById('calStDt'), document.getElementById('calEnDt'))
=======================================================*/
function SetCalendar(sDateTy, nVal, oStDt, oEtDt) {

    if (IsEmpty(oEtDt, '')) oEtDt.value = GetToday('.'); // 현재일자
    oStDt.value = AddDate(sDateTy, nVal, oEtDt);
}

// 오늘날짜 가져오기 (divChar 구분자..)
function GetToday(divChar) {
    var dDate = new Date();
    var dCurMonth = dDate.getMonth() + 1;
    var dCurDayOfMonth = dDate.getDate();
    var dCurYear = dDate.getFullYear();
    dCurMonth = (dCurMonth < 10 ? "0" : "") + dCurMonth;
    dCurDayOfMonth = (dCurDayOfMonth < 10 ? "0" : "") + dCurDayOfMonth;
    divChar = (divChar == null ? "" : divChar);

    return dCurYear + divChar + dCurMonth + divChar + dCurDayOfMonth;
}


/* =======================================================
날짜비교
=======================================================
<매개변수>
sDateTy :비교할 날짜유형(Y-년,M-월,D-일)
oStDt   :시작달력컨트롤
oEtDt   :종료달력컨트롤
  
<결과>
int
=======================================================*/
function DateDiff(sDateTy, oStDt, oEdDt) {
    var sStDt, sEdDt; // 스트링형
    var dStDt, dEdDt;
    var nRes;

    if (typeof (oStDt) == "string")
        sStDt = document.getElementById(oStDt).value;
    else
        sStDt = oStDt.value;

    if (typeof (oEdDt) == "string")
        sEdDt = document.getElementById(oEdDt).value;
    else
        sEdDt = oEdDt.value;

    if (sStDt.length == 10) {
        dStDt = new Date(parseInt(sStDt.substring(0, 4)),
                            parseInt(sStDt.substring(5, 7)) - 1,
                            parseInt(sStDt.substring(8, 10)));
    }
    else {
        dStDt = new Date(parseInt(sStDt.substring(0, 4)),
                            parseInt(sStDt.substring(4, 6)) - 1,
                            parseInt(sStDt.substring(7, 9)));
    }

    if (sEdDt.length == 10) {
        dEdDt = new Date(parseInt(sEdDt.substring(0, 4)),
                            parseInt(sEdDt.substring(5, 7)) - 1,
                            parseInt(sEdDt.substring(8, 10)));
    }
    else {
        dEdDt = new Date(parseInt(sEdDt.substring(0, 4)),
                            parseInt(sEdDt.substring(4, 6)) - 1,
                            parseInt(sEdDt.substring(7, 9)));
    }


    var nDurInt; //환산날짜단위
    switch (sDateTy) {
        case 'Y': //년
            nDurInt = 1000 * 3600 * 24 * 30 * 12;
            break;
        case 'M': //월
            nDurInt = 1000 * 3600 * 24 * 30;
            break;
        default:
            nDurInt = 1000 * 3600 * 24;
            break;
    }

    var nDur = dEdDt.getTime() - dStDt.getTime();
    nDur = Math.floor(nDur / nDurInt);
    return nDur;

}

/* =======================================================
날짜더하기
=======================================================
<매개변수>
sDateTy : 더할 날짜유형(Y-년,M-월,D-일)
nVal    : 더할 날짜Int
oStDt   : 계산할 날짜컨트롤
  
<결과>
반환날짜
=======================================================*/
function AddDate(sDateTy, nVal, oStDt) {
    var divChar = ''; //날짜구분자
    var dEdDt = new Date();

    if (typeof (oStDt) == "string")
        sStDt = document.getElementById(oStDt).value;
    else
        sStDt = oStDt.value;

    if (sStDt.length == 10) {
        dStDt = new Date(parseInt(sStDt.substring(0, 4)),
                            parseInt(sStDt.substring(5, 7)) - 1,
                            parseInt(sStDt.substring(8, 10)));
        divChar = sStDt.substring(4, 5);
    }
    else {
        dStDt = new Date(parseInt(sStDt.substring(0, 4)),
                            parseInt(sStDt.substring(4, 6)) - 1,
                            parseInt(sStDt.substring(7, 9)));
    }

    switch (sDateTy) {
        case 'Y': //년
            dEdDt = new Date(dStDt.getFullYear() + parseInt(nVal),
		                    dStDt.getMonth(),
		                    dStDt.getDate());
            break;
        case 'M': //월

            dEdDt = new Date(dStDt.getFullYear(),
				            dStDt.getMonth() + parseInt(nVal),
				            dStDt.getDate());

            if (dStDt.getDate() != dEdDt.getDate()) {
                dEdDt = new Date(dStDt.getFullYear(),
			                      dStDt.getMonth() + parseInt(nVal) + 1,
			                      0);
            }
            break;
        default:
            dEdDt.setTime(dStDt.getTime() + (1000 * 3600 * 24 * nVal));
            break;
    }
    var yy = dEdDt.getFullYear().toString();
    var mm = dEdDt.getMonth() + 1; mm = (mm < 10 ? '0' : '') + mm.toString();
    var dd = dEdDt.getDate(); dd = (dd < 10 ? '0' : '') + dd.toString();
    return yy + divChar + mm + divChar + dd;

}

// 라디오버튼리스트 선택된값 가져오기
function GetCheckedRBL(oTag) {

    var res = '';

    if (oTag != null) {
        var rbl = oTag.getElementsByTagName("INPUT");

        for (var i = 0; i < rbl.length; i++) {
            if (rbl(i).type == "radio") {
                if (rbl(i).checked) { res = rbl(i).value; break; }
            }
        }
    }
    return res;
}

// 이미지태그 onerror에 사용
function SetEmptyImg(obj, sizeX, sizeY) {

    obj.src = '/images/spacer.gif';
    obj.style.backgroundImage = 'url(/images/blank_img.gif)';
    obj.style.backgroundRepeat = 'no-repeat';
    obj.style.backgroundPosition = ' center center ';
    if (sizeX == null || sizeY == null) {

        sizeX = 70;
        sizeY = 70;
    }
    obj.width = sizeX;
    obj.height = sizeY;
    obj.width = obj.width - 1;
    obj.height = obj.height - 1;
    obj.style.borderColor = '#d4e3e3';
    obj.style.borderStyle = 'solid';
    obj.style.borderWidth = 1;
    obj.onclick = function() { return; }
}

// 이미지태그 onerror에 사용 (스크랩용)
function SetEmptyImgScrap(obj, sizeX, sizeY, root) {

    obj.src = root + '/images/spacer.gif';
    obj.style.backgroundImage = 'url(' + root + '/images/blank_img.gif)';
    obj.style.backgroundRepeat = 'no-repeat';
    obj.style.backgroundPosition = ' center center ';
    if (sizeX == null || sizeY == null) {

        sizeX = 70;
        sizeY = 70;
    }
    obj.width = sizeX;
    obj.height = sizeY;
    obj.width = obj.width - 1;
    obj.height = obj.height - 1;
    obj.style.borderColor = '#d4e3e3';
    obj.style.borderStyle = 'solid';
    obj.style.borderWidth = 1;
    obj.onclick = function() { return; }
}


// 원본이미지보기
var poto
function ImgPopup(img2) {

    poto = new Image();
    poto.src = (img2);
    Controlla(img2);
}

function Controlla(img2) {
    if ((poto.width != 0) && (poto.height != 0)) {
        winopen(img2, poto.width, poto.height);
    } else {
        funzione = "Controlla('" + img2 + "')";
        intervallo = setTimeout(funzione, 20);
    }
}

function winopen(img_view, Width, Height) {
    var winHandle = window.open("", "windowName", "toolbar=no,scrollbars=no,resizable=no, top=200, left=200 ,width=" + Width + ",height=" + Height)
    if (winHandle != null) {
        var htmlString = "<html><head><title>원본 이미지</title></head>"
        htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
        htmlString += "<a href=javascript:window.close()><img src='" + img_view + "' border=0 alt=이미지클릭:화면닫기></a>"
        htmlString += "</body></html>"
        winHandle.document.open()
        winHandle.document.write(htmlString)
        winHandle.document.close()
    }
    if (winHandle != null) winHandle.focus()
    return winHandle
}



// 동영상 보기 (팝업)

function videoPopup(vido_view, Width, Height) {
    var winHandle = window.open("", "windowName0", "toolbar=no,scrollbars=no,resizable=no, top=200, left=200 ,width=" + String(Width) + ",height=" + String(Height + 50));
    if (winHandle != null) {
        var htmlString = "<html><head><title>동영상 보기</title></head>"
        htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>"
        htmlString += "<embed src='" + vido_view + "' width='" + String(Width) + "' height='" + String(Height) + "' align='middle'  autostart=yes showcontrols='1' ></embed>"
        htmlString += "<div style='width:100%;padding-top:10px;text-align:center;'><input type=button onclick=javascript:window.close() value=창닫기 /></div>"
        htmlString += "</body></html>"
        winHandle.document.open()
        winHandle.document.write(htmlString)
        winHandle.document.close()
    }
    if (winHandle != null) winHandle.focus()

}
// 동영상 보기 (해당화면에서)
function videoWrite(url, width, height, autostart) {
    document.write("<embed src='" + url + "' width='" + width + "' height='" + height + "' align='middle' autostart='" + autostart + "'></embed>");
}

function videoWrite1(url, width, height, autostart, SHOWCONTROLS) {
    document.write("<embed src='" + url + "' width='" + width + "' height='" + height + "' align='middle' autostart='" + autostart + "' SHOWCONTROLS='0'></embed>");
}



//***** 롤오버*****
function imgOver(param) {
    param.src = param.src.replace(".gif", "_over.gif");
    param.className = 'over';
}
function imgOut(param) {
    param.src = param.src.replace("_over.gif", ".gif");
}

/* =======================================================
글자수 세기
=======================================================*/


var MAX_TEXT_BYTE = 0;
function LimitTextSizeEx(orgText, limitSize, MAX_TEXT_BYTE) {// 텍스트 입력창의 글자 바이트수를 제한 한다.
    var prvByte = StrByteLengthEx(orgText);
    var evKey = event.keyCode;

    switch (evKey) {
        case 8:
        case 9:
        case 16:
        case 17:
        case 18:
        case 20:
        case 33:
        case 34:
        case 35:
        case 36:
        case 37:
        case 38:
        case 39:
        case 40:
        case 46:

            break;
        case 229:
            if (prvByte >= (limitSize - 1))
                return false;

            break;
        default:
            if (prvByte >= limitSize)
                return false;

            break;
    }
    return true;

}

function StrByteLengthEx(strVal) {// 2Byte(13+10)의 리턴 문자에서 1바이트(10)는 계산에서 제외...
    var strLen = 0;

    for (var i = 0; i < strVal.length; i++) {
        var chrCode = strVal.charCodeAt(i);

        if (chrCode == 10) // 무시하기 위한 바이트값
            continue;

        strLen++;

        if (chrCode > 255)
            strLen++;
    }

    return strLen;
}

function GetTextByteEx(strVal, limitByte) {// 해당 바이트 만큼만 가져오기
    var strLen = 0;

    var retVal = "";

    for (var i = 0; i < strVal.length; i++) {
        var chrCode = strVal.charCodeAt(i);

        if (chrCode == 10) // 무시하기 위한 바이트값
            continue;

        strLen++;

        if (chrCode > 255)
            strLen++;

        if (strLen > limitByte)
            break;

        retVal += strVal.charAt(i);
    }

    return retVal;
}



function viewLength(oLenView) {
    var oContent = event.srcElement;

    if (oLenView.tagName == 'INPUT')
        oLenView.value = oContent.value.length;
    else
        oLenView.innerText = oContent.value.length;

}

/* =======================================================
레이어 보이기 / 숨기기 제어
=======================================================*/
var old_oArea;

function showLayer(obj, x, y) {
    var mouse_y = 0;
    var mouse_x = 0;
    var e = window.event; // 이벤트 검사
    var oArea = window.event.srcElement;

    if (e.pageY) { // pageX/Y 표준 검사
        mouse_x = e.pageX;
        mouse_y = e.pageY;
    }
    else if (e.clientY) { //clientX/Y 표준 검사 Opera
        mouse_x = e.clientX;
        mouse_y = e.clientY;
    }
    mouse_y += document.documentElement.scrollTop;

    if (x != null) mouse_x += x;
    if (y != null) mouse_y += y;
    if (obj.style.visibility == "visible" && oArea == old_oArea) {
        obj.style.visibility = "hidden";
    }
    else {

        obj.style.visibility = "visible";
        obj.style.left = mouse_x;
        obj.style.top = mouse_y;

        old_oArea = oArea;
    }
}
/* =======================================================
RadioButto 목록에서 유일하게 체크하기
=======================================================*/
function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}





/* =======================================================
네이버 지도 보여주기
=======================================================*/
function showMap(xPos, yPos, slable, objMap) {

    var mapObj = new NMap(document.getElementById(objMap.id));

    var info = new NInfoWindow();


    mapObj.setCenterAndZoom(new NPoint(xPos, yPos), 3);

    var zoom = new NZoomControl();
    zoom.setAlign("right");
    zoom.setValign("bottom");
    mapObj.addControl(zoom);

    /* */
    var xy = new NPoint(xPos, yPos);

    xxyy = mapObj.fromTM128ToLatLng(xy);


    var pointTag = '<div class="arrowArea"><span>' + slable + '</span></div>';

    info.set(xy, pointTag);

    mapObj.addOverlay(info);

    info.showWindow();



//    var iconUrl = 'http://static.naver.com/maps2/icons/pin_spot2.png';
//    var icon = new NIcon(iconUrl, new NSize(28, 37));
//    var marker = new NMark(new NPoint(xPos, yPos), icon);
//    mapObj.addOverlay(marker);

}

/* =======================================================
플래쉬 보여주기
=======================================================
<매개변수[필수]>
url : swf 경로 (ex.  /Item/BizCtgr/Cinema/map.swf)
w    : 가로 픽셀
h   : 세로 픽셀
=======================================================*/
function flashWrite(url, w, h, vars, align, id, bg, win) {

    if (vars == null) vars = ""; //변수들
    if (align == null) align = "left";
    if (id == null) id = "flash_01";
    if (bg == null) bg = "#FFFFFF";
    if (win == null) win = "transparent";

    // 플래시 코드 정의
    var flashStr =
	"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0\" width=\"" + w + "\" height=\"" + h + "\" id=\"" + id + "\" align=\"" + align + "\">" +
    "<param name=\"allowScriptAccess\" value=\"always\" />" +
    "<param name=\"allowFullScreen\" value=\"false\" />" +
	"<param name=\"movie\" value=\"" + url + "\" />" +
	"<param name=\"flashVars\" value=\"" + vars + "\" />" +
	"<param name=\"wmode\" value=\"" + win + "\" />" +
	"<param name=\"quality\" value=\"high\" />" +
	"<param name=\"bgcolor\" value=\"" + bg + "\" />" +
	"<embed src=\"" + url + "\" flashVars=\"" + vars + "\" wmode=\"" + win + "\" quality=\"high\" bgcolor=\"" + bg + "\" width=\"" + w + "\" height=\"" + h + "\" name=\"" + id + "\" align=\"" + align + "\" allowScriptAccess=\"always\" allowFullScreen=\"false\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />" +
	"</object>";
    //alert(flashStr);
    // 플래시 코드 출력

    document.write(flashStr);
}

/* 레이어팝업 (2009.12.21) */
var isIE = (document.all) ? true : false;
var isNN = (document.getElementById && document.all) ? true : false;
var isN4 = (document.layers) ? true : false; ;
var isHot = false;
var offsetx = 0, offsety = 0, nowX = 0, idx = 0, ddEnabled = false;
var topDog, hotDog, whichDog;

function ddInit(e) {
    topDog = isIE ? "BODY" : "HTML";
    hotDog = isIE ? event.srcElement : e.target;
    idx = hotDog.id.substring(8);
    whichDog = isIE ? eval("document.all.divpop" + idx) : document.getElementById("divpop" + idx);

    while (hotDog.id != hotDog.id && hotDog.tagName != topDog) {
        hotDog = isIE ? hotDog.parentElement : hotDog.parentNode;
    }
    if (hotDog.id) {
        offsetx = isIE ? event.clientX : e.clientX;
        offsety = isIE ? event.clientY : e.clientY;
        if (whichDog != null) {
            nowX = parseInt(whichDog.style.left);
            nowY = parseInt(whichDog.style.top);
        }
        ddEnabled = true;

        document.onmousemove = dd;
    }
}
function dd(e) {
    if (!ddEnabled) return;
    if (whichDog != null) {
        whichDog.style.left = isIE ? nowX + event.clientX - offsetx : nowX + e.clientX - offsetx;
        whichDog.style.top = isIE ? nowY + event.clientY - offsety : nowY + e.clientY - offsety;
    }
    return false;
}
function ddN4(whatDog) {
    if (!isN4) return;
    N4 = eval(whatDog);
    N4.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP);
    N4.onmousedown = function(e) {
        N4.captureEvents(Event.MOUSEMOVE);
        N4x = e.x;
        N4y = e.y;
    }
    N4.onmousemove = function(e) {
        if (isHot) {
            N4.moveBy(e.x - N4x, e.y - N4y);
            return false;
        }
    }
    N4.onmouseup = function() {
        N4.releaseEvents(Event.MOUSEMOVE);
    }
}
function hideMe(id) {
    if (document.getElementById('chkbox' + id).checked) {
        setCookie("mainPop" + id, "done", 1);
        document.getElementById('chkbox' + id).checked = false;
    }
    if (isN4) document.divpop.visibility = "hide";
    else document.getElementById('divpop' + id).style.visibility = "hidden";
}
function setCookie(name, value, expiredays) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}
document.onmousedown = ddInit;
document.onmouseup = Function("ddEnabled=false");


/* =======================================================
    일반팝업관련
=======================================================*/
function goPopup(url, popNm, sW, sH, openYn)
{
    if (openYn)
        window.open(url, popNm, "width=" + sW + ", height=" + sH + " ");
}

function popCookieCheck(cookieNm, checkValue) {
    cookiedata = document.cookie;

    if (cookiedata.indexOf(cookieNm + "=" + checkValue) >= 0)
        return false;
    else
        return true;
}


/* =======================================================
    퍼플 가입관련
=======================================================*/
function getCookie(name) {
    var idx_s = document.cookie.indexOf(name + "=");
    var idx_e = 0;
    if (idx_s != -1) {
        idx_s += name.length + 1;
        idx_e = document.cookie.indexOf(";", idx_s);
        if (idx_e == -1) {
            idx_e = document.cookie.length;
        }
    } else {
        return "";
    }

    return document.cookie.substring(idx_s, idx_e);
}

function setInstantCookie(name, value) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate());
    document.cookie = name + "=" + escape(value) + "; path=/; ";
}

/* =======================================================
    플래쉬 관련
=======================================================*/


function setActiveStyleSheet(obj) {
    document.getElementById('gnbArea').className = 'skin_' + obj;
}