﻿// 쿠키 값을 얻는다
// name : Cookie Name
function getCookie(name) {
    var nameOfCookie = name + "=";
    var x = 0;
    while (x <= document.cookie.length) {
        var y = (x + nameOfCookie.length);
        if (document.cookie.substring(x, y) == nameOfCookie) {
            if ((endOfCookie = document.cookie.indexOf(";", y)) == -1)
                endOfCookie = document.cookie.length;
            return unescape(document.cookie.substring(y, endOfCookie));
        }
        x = document.cookie.indexOf(" ", x) + 1;
        if (x == 0)
            break;
    }
    return "";
}

// 쿠키 값을 설정 한다.
// name         : Cookie Name
// value        : Cookie Value
// expiredays   : Setting Expired Days, 일(Day) 단위로만 설정가능
// path         : Cookie Path
// domain       : Cookie Domain
// secure       : Cookie Secure
function setCookie(name, value, expiredays, path, domain, secure) {
    var todayDate = new Date();
    todayDate.setDate(todayDate.getDate() + expiredays);
    expires = todayDate.toGMTString();
    
    document.cookie = name + "=" + escape(value) +
        ((expires) ? ";expires=" + expires : "") +
        ((path) ? ";path=" + path : "") +
        ((domain) ? ";domain=" + domain : "") +
        ((secure) ? ";secure" : "");
}

function get_byte(str) { //문자열의 byte 길이를 알아냄(한글 2byte로 처리)
    var i, m = str.length, re_count = 0, val = 0; ;
    for (i = 0; i < m; i++) {
        val = escape(str.charAt(i)).length;
        if (val > 3) re_count++;
        re_count++;
    } return re_count;
}

function get_byte_length(str, limit_byte) { //지정된 바이트 길이만큼의 length를 반환, 홀수로 짤리면 -1의 길이반환
    var i, m = str.length, re_count = 0, val = 0; ;
    var len_count = 0;
    for (i = 0; re_count < limit_byte; i++) {
        val = escape(str.charAt(i)).length;
        len_count++;
        if (val > 3) re_count++;
        re_count++;
    }
    if (re_count % 2 == 1) return (len_count - 1);
    else return (len_count);
}

// 객체를 숨기거나 보이게 한다.
function ToggleObject(obj_id, bShow) {
    var obj = document.getElementById(obj_id);
    if (obj) {
        if (bShow == true) {
            obj.style.visibility = "visible";
            obj.style.display = "block";
        }
        else {
            obj.style.visibility = "hidden";
            obj.style.display = "none";
        }
    }
}

function fn_show_popup(url, name, param1, param2) {
    return window.open(url, name, param1, param2);
}

function fn_show_popup_and_focus(url, name, param1, param2) {
    var obj = fn_show_popup(url, name, param1, param2);
    if (null != obj)
        obj.focus();
}

function fn_get_popup_param1_all(width, height, toolbar, menubar, scrollbars) {
    var param = "";
    if (null != width)
        param += "width=" + width;
    if (null != height)
        param += ((param.length > 0) ? "," : "") + "height=" + height;
    if (null != toolbar)
        param += ((param.length > 0) ? "," : "") + "toolbar=" + toolbar;
    if (null != menubar)
        param += ((param.length > 0) ? "," : "") + "menubar=" + menubar;
    if (null != scrollbars)
        param += ((param.length > 0) ? "," : "") + "scrollbars=" + scrollbars;

    return param;
}

function fn_get_popup_param1_size(width, height) {
    return fn_get_popup_param1_all(width, height, "no", "no", "no");
}

function fn_get_popup_param1_size_scroll(width, height, scrollbars) {
    return fn_get_popup_param1_all(width, height, "no", "no", scrollbars);
}

