﻿
/* === 기본 변수 설정 ==================== */
/* ======================================= */

var NS4;
var IE4;
if (document.all) {
	IE4 = true;
	NS4 = false;
}
else {
	IE4 = false;
	NS4 = true;
}
var isWin = (navigator.appVersion.indexOf("Win") != -1)

var agent = navigator.userAgent.toLowerCase();
var isIE = (agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1) && (agent.indexOf("webtv") == -1);


/* === 팝업 관련 함수 ==================== */
/* ======================================= */
function open_window(url, name, width, height, feature) {
	var oWnd;

	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 {
		oWnd = window.open(url, name, feature + ",width=" + width + ",height=" + height + ",resizable=yes");
	}

	return oWnd;
}

function pop(url, width, height, name, flag) {
	if (flag == 0)
		var oPop = open_window(url, name, width, height, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");
	if (flag == 1)
		var oPop = open_window(url, name, width, height, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0");
	if (flag == 2)
		var oPop = open_window(url, name, width, height, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0");
	if (flag == 3)
		var oPop = open_window(url, name, width, height, "toolbar=0,menubar=0,scrollbars=yes,resizable=yes");
	if (flag == 4)
		var oPop = open_window(url, name, width, height, "toolbar=0,menubar=0,scrollbars=no,resizable=yes");
	if (flag == 5)
		var oPop = open_window(url, name, width, height, "toolbar=0,menubar=0,resizable=yes,scrollbars=no");
	return oPop;
}


/* === iFrame 관련 함수 ================== */
/* ======================================= */

// iframe resize시 최소 width, height
var frmMinWidth;
var frmMinHeight;
var applyMinSize = false;
// iframe resize시 최대 width, height
var frmMaxWidth;
var frmMaxHeight;
var applyMaxSize = false;


function setMinSize(width, height) {
	frmMinWidth = width;
	frmMinHeight = height
	applyMinSize = true;
}
function setMaxSize(width, height) {
	frmMaxWidth = width;
	frmMaxHeight = height
	applyMaxSize = true;
}

function resizeIframe(name) {
	if (name == null || name == "") {
		name = "cafe_main";
	}

	try {
		if (IE4)
			var oBody = document.frames(name).document.body;
		else
			var oBody = document.getElementById(name).contentDocument.body;
		var oIFrame = document.getElementById(name);

		var frmWidth = oBody.scrollWidth;
		var frmHeight = oBody.scrollHeight;

		if (applyMinSize) {
			frmWidth = Math.max(frmWidth, frmMinWidth);
			frmHeight = Math.max(frmHeight, frmMinHeight);
		}
		if (applyMaxSize) {
			frmWidth = Math.min(frmWidth, frmMaxWidth);
			frmHeight = Math.min(frmHeight, frmMaxHeight);
		}

		oIFrame.style.height = frmHeight;
		oIFrame.style.width = frmWidth;
	}
	catch (e) { }
}
function parentResizeIframe(name) {
	if (parent && parent != this && parent.resizeIframe != null) {
		parent.resizeIframe(name);
	}
}

function resizeIframe_fix_width(name) {
	try {
		if (IE4)
			var oBody = document.frames(name).document.body;
		else
			var oBody = document.getElementById(name).contentDocument.body;
		var oIFrame = document.getElementById(name);

		var frmHeight = oBody.scrollHeight;

		if (document.getElementById('preloadingSection') != null) document.getElementById('preloadingSection').style.display = 'none';

		oIFrame.style.height = frmHeight + 'px';
	}
	catch (e) { }
}

function parentResizeIframe(name) {
	if (parent && parent != this && parent.resizeIframe != null) {
		parent.resizeIframe(name);
	}
}

function parentResizeIframe_fix_width(name) {
	if (parent && parent != this && parent.resizeIframe != null) {
		parent.resizeIframe_fix_width(name);
	}
}


function resizeIframe_v2(name) {
	if (name == null || name == "") {
		name = "cafe_main";
	}
	try {
		document.getElementById(name).style.height = '0px';
		document.getElementById(name).style.width = '0px';
		var oBody = window.frames[name].document.body;
		var frmWidth = oBody.scrollWidth;
		var frmHeight = oBody.scrollHeight;
		document.getElementById(name).style.height = frmHeight + 'px';
		document.getElementById(name).style.width = frmWidth + 'px';
	}
	catch (e) { }
}



// F5를 눌렀을때 iframe 내부만 refresh 되도록 처리 start
if (NS4) {
	document.captureEvents(Event.KEYDOWN)
	document.onkeydown = trapRefresh;
}
else if (IE4) {
	document.onkeydown = trapRefresh;
}

function trapRefresh(e) {
	var event;
	if (window.event) event = window.event;
	else event = e;

	if (event.keyCode == 116) {
		if (window.event)
			event.keyCode = 0;
		event.cancelBubble = true;
		event.returnValue = false;
		document.location.reload();
	}
}

/* === Cookie 관련 함수 ================== */
/* ======================================= */

function set_cookie(Key, Val) {
	document.cookie = Key + "=" + Val;
}

function set_cookie_long(Key, Val) {
	document.cookie = Key + "=" + escape(Val) + "; expires=Fri, 31 Dec 2047 23:59:59 GMT;";
}

function SetCookie(sName, sValue) {
	date = new Date();
	document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}

function DelCookie(sName) {
	document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

function GetCookie(sName) {
	// cookies are separated by semicolons
	var aCookie = document.cookie.split("; ");
	for (var i = 0; i < aCookie.length; i++) {
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
}


/* === 다중 탭 핸들링 함수 =============== */
/* ======================================= */

var tShowTab = null;

function change_tab(obj) {
	clearTimeout(tShowTab)
	fobj = obj;
	obj.onmouseout = function() { clearTimeout(tShowTab) };

	tShowTab = setTimeout('set_tab(fobj)', 120);
	return;
}

function set_tab(obj) {
	// 이 펑션을 운영하기 위해서는 이 함수를 onmouseover에 넣어야 하며 ("change_tab(this)")
	// 호출하는 탭 오브젝트의 아이디는 반드시 xxxxxxxxx:#(한자리 숫자) 형태여야 하며, 이 이름은 폼 안에서 유일하도록 알아서 잘 지어야 한다.
	// 이 탭에 의해서 제어되는 정보 박스의 아이디는 반드시 xxxxxxxxx:C#(한자리 숫자) 형태여야 하며(C만 다르고 위와 다 같아야 함), 이 이름은 폼 안에서 유일하도록 알아서 잘 지어야 한다.
	var ps = obj.id.split(':');

	var Tab = null;
	var Box = null;

	for (var i = 0; i < 10; i++) {
		if (document.getElementById(ps[0] + ':' + i) != null) {
			Tab = document.getElementById(ps[0] + ':' + i);
			Box = document.getElementById(ps[0] + ':C' + i);
			if (Tab.id == obj.id) {
				Tab.className = 'BC_TAB_SELC';
				Box.style.display = 'block';
			}
			else {
				Tab.className = 'BC_TAB_CELL';
				Box.style.display = 'none';
			}
		}
	}
}


/* === 각종 라이브러리 =================== */
/* ======================================= */

function get_filename(fullname) {
	var idx = fullname.lastIndexOf("\\");
	var rslt = '';
	if (idx > -1) {
		rslt = fullname.substring(idx + 1, fullname.length);
	}
	else {
		rslt = fullname;
	}
	return rslt;
}

function file_add(SelectControl, TextControl, HiddenControl) {
	var o = document.getElementById(SelectControl);
	var t = document.getElementById(TextControl);
	var h = document.getElementById(HiddenControl);
	var chk = 1;
	for (i = 0; i < o.length; i++) {
		if (o.options(i).value == t.value) {
			chk = 0;
			break;
		}
	}
	if (chk > 0) {
		var oOption = document.createElement("OPTION");
		oOption.text = get_filename(t.value);
		oOption.value = t.value;
		o.add(oOption);
	}
	else {
		alert("이미 선택되어 있는 파일입니다.");
	}
	var cstr = "";
	for (i = 0; i < o.length; i++) {
		cstr = cstr + o.options(i).value;
	}
	if (cstr != "")
		cstr = cstr.substring(0, cstr.length - 1);
	h.value = cstr;
}

function file_del(SelectControl, HiddenControl) {
	var o = document.getElementById(SelectControl);
	var h = document.getElementById(HiddenControl);
	var idx = o.selectedIndex;
	if (idx > -1)
		o.remove(idx);
	if (cstr != "")
		cstr = cstr.substring(0, cstr.length - 1);
	h.value = cstr;
}

function listing(SelectControl, ViewControl) {
	var o = document.getElementById(SelectControl);
	var vw = document.getElementById(ViewControl);
	for (i = 0; i < o.length; i++) {
		vw.innerText = vw.innerText + o.options(i).text + " : ";
		vw.innerText = vw.innerText + o.options(i).value + "\n";
	}
}

function realen(val) {
	var P = 1;
	var CNT = 0;
	var CODE = 0;

	//val = val.trim();
	for (i = 0; i < val.length; i++) {
		CODE = val.charCodeAt(i);
		if ((CODE >= 32) && (CODE <= 126))
			CNT = CNT + 1;
		else
			CNT = CNT + 2;
	}
	return CNT;

}
function realpartstr(data, strlen) {
	var P = 0;
	var CNT = 0;
	var CODE = 0;

	if (strlen == 0) return data;

	for (i = 0; i < data.length; i++) {
		CODE = data.charCodeAt(i);
		if ((CODE >= 32) && (CODE <= 126))
			CNT = CNT + 1;
		else
			CNT = CNT + 2;

		if (strlen < CNT) break;

		P = i;
	}

	return data.substring(0, P);
}

function CheckLen(field, ment, min, max) // 입력된 데이터의 길이를 검사하는 함수, 공백도 검사
{
	// min = -1 : 최소 입력 조건이 없는 경우 
	// min = 0 : 공백이 입력되면 안되는 경우
	// min > 0 : 최소 입력 조건이 있는 경우
	var fl = realen(field.value)
	var cond = true;
	if (fl <= min) {
		if (fl == 0) {
			alert(ment + " 란은 필수 입력 필드 입니다.");
			field.focus();
			cond = false;
		}
		else {
			if (fl < min) {
				alert(ment + "의 길이는 " + min + "자 이상이어야 합니다.");
				field.focus();
				cond = false;
			}
		}
	}
	if (realen(field.value) > max) {
		alert(ment + "의 길이가 허용범위 " + max + "자 를 초과 하였습니다.")
		field.focus()
		cond = false;
	}
	return cond;
}

function go(where) {
	if (where != '')
		window.location.href = where;
	else
		window.location.href = '/';
}
function gon(where) {
	if (where != '')
		window.open(where, '_blank');
	else
		window.open('/', '_blank');
}


function global_SaveId(val, CheckControl) {
	var o = document.getElementById(CheckControl);
	if (val != '') {
		set_cookie_long('jx_portal_uid', val)
		o.checked = true;
	}
	else {
		alert('우선 사용자 아이디를 입력해 주세요');
		o.checked = false;
	}
}

function zeroPad(num, width) { num = num.toString(); while (num.length < width) num = "0" + num; return num; }

function Replacing(Source, From, To) { var Rslt = Source; while (Rslt.indexOf(From) > -1) { Rslt = Rslt.replace(From, To); } return Rslt; }

function rpc(Source, From, To) { var Rslt = Source; while (Rslt.indexOf(From) > -1) { Rslt = Rslt.replace(From, To); } return Rslt; }

function IsBlank(Src) {	var Rslt = rpc(Src, " ", "");	return Rslt == ""; }

function spt(Source, From, To) {var Rslt = Source;Rslt = Source.split(From); return Rslt[To]; }

// get 파라미터 가져오기
var request = new Request(
    (function() {
    	var parameters = unescape(location.search).substring(1).split(/\&|\=/g);
    	var obj = {}, i;
    	for (i in parameters) obj[parameters[i++]] = parameters[i++];
    	return obj;
    })()
  );

function Request(properties) {
	for (var i in properties) {
		this["get_" + i.substring(0)] = (function(_i) {
			return function() {
				return properties[_i];
			}
		})(i);
	}
}

function Restore_JSON(p_Source) {
	var Rslt = p_Source;

	Rslt = rpc(Rslt, "&nbsp;", "");
	Rslt = rpc(Rslt, "&#x002C;", ",");
	Rslt = rpc(Rslt, "&#x003A;", ":");
	Rslt = rpc(Rslt, "&#x005B;", "[");
	Rslt = rpc(Rslt, "&#x005D;", "]");
	Rslt = rpc(Rslt, "&#x007B;", "{");
	Rslt = rpc(Rslt, "&#x007D;", "}");
	Rslt = rpc(Rslt, "&#x0022;", "\"");

	return Rslt;
}

function strCombo(pId, pVal, pVals, pLbls, pClass, pScript) {
	var vcontrol = "<select id=\"" + pId + "\" class=\"" + pClass + "\" onchange=\"" + pScript + "\">";
	var Vals = pVals.split(";");
	var Lbls = pLbls.split(";");
	var ranges = null;
	var Fi = 0;
	var Ti = 0;
	var dd = "";

	if (pVals.indexOf(".....") >= 0) {
		ranges = pVals.split(".....");
		Fi = parseInt(ranges[0]);
		Ti = parseInt(ranges[1]);
		vcontrol += "<option value=\"\">" + ((pLbls != "") ? "<" + pLbls + ">" : "") + "</option>";
		if (Fi > Ti) {
			for (nn = Fi; nn >= Ti; nn--) {
				dd = ((nn > 0) && (nn < 10)) ? "0" + nn : nn.toString();
				vcontrol += "<option value=\"" + dd + "\" " + ((pVal == nn) ? "selected" : "") + ">" + dd + "</option>";
			}
		}
		else {
			for (nn = Fi; nn <= Ti; nn++) {
				dd = ((nn > 0) && (nn < 10)) ? "0" + nn : nn.toString();
				vcontrol += "<option value=\"" + dd + "\" " + ((pVal == nn) ? "selected" : "") + ">" + dd + "</option>";
			}
		}
	}
	else {
		for (mm = 0; mm < Vals.length; mm++) {
			if (Vals[mm] == "-----") {
				vcontrol += (vcontrol.indexOf("<optgroup>") >= 0) ? "</optgroup><optgroup>" : "<optgroup>";
			}
			else {
				vcontrol += "<option value=\"" + Vals[mm] + "\" " + ((pVal == Vals[mm]) ? "selected" : "") + ">" + Lbls[mm] + "</option>";
			}
		}
	}
	return vcontrol + ((vcontrol.indexOf("<optgroup>") >= 0) ? "</optgroup></select>" : "</select>");
}

function show_message(msg, timeout) {
    $(document.body).append('<table id="ITF_Msg5832123" cellpadding=\"0\" cellspacing=\"0\" style="background:url(/_img/Dlg/D310-073.png) 0px 0px no-repeat; position:absolute; left:0px; top:0px; width:310px; height:73px; display:none; z-index:30000;"><tr><td id="ITF_indiMsg5832123" style="padding:17px 0px 0px 55px; vertical-align:middle; width:auto; height:auto; line-height:15px;">데이터를 읽어오고 있습니다. 감사합니다.</p></td></tr></table>');

	$("#ITF_Msg5832123").css("top", ($(window).height() / 2) - 73).css("left", ($(window).width() / 2) - 155);
	$("#ITF_indiMsg5832123").html(msg);
	$("#ITF_Msg5832123").show();

	setTimeout(function() { $("#ITF_Msg5832123").hide(); }, timeout);
}

function js_show_message(msg, widt) {
    $("#ITF_Msg5832113").remove();
    
    var s_str = "";
    if (widt == null || widt == "") { widt = "auto;"; }
    s_str += '<table cellspacing="0" id="ITF_Msg5832113" style="position:absolute; z-index:1000; width:'+widt+'">';
    s_str += '        <tbody>';
    s_str += '            <tr>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -40px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_line.png) 0px 0px; width:10px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -8px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '            <tr>';
    s_str += '                <td  style="background:url(/_img/module/popup_line.png); width:3px; height:100%; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="padding:10px; background:#fff; margin:0px;">';
    s_str += '                <div oldblock="block">';
    s_str += '                <div>' + msg + '</div></div>';
    s_str += '                <div oldblock="block" style="text-align:right; border-top:#dddddd 1px solid; margin:0px; margin-top:10px; padding:5px;"><a style="text-decoration:none; color:#3b5998;" href="#"><img style="padding:0px; margin:0px; border:0px;" title=close src="/_img/module/closelabel.gif" onclick="$(this).parent().parent().parent().parent().parent().parent().remove();"> </a></div></td>';
    s_str += '                <td  style="background:url(/_img/module/popup_line.png); width:3px; height:100%; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '            <tr>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -20px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_line.png); width:10px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -30px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '        </tbody>';
    s_str += '    </table>';

    $(document.body).append(s_str);

    $("#ITF_Msg5832113").css("top", ($(window).height() / 2) - 233).css("left", ($(window).width() / 2) - 305);
    $("#ITF_Msg5832113").draggable();
}

function js_show_message_2(msg, widt) {
    
    
    var s_str = "";
    if (widt == null || widt == "") { widt = "auto;"; }
    s_str += '<table cellspacing="0" id="ITF_Msg5832114" class="ITF_Msg5832114" style="position:absolute; z-index:1000; width:' + widt + '">';
    s_str += '        <tbody>';
    s_str += '            <tr>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -41px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_line.png) 0px 0px; width:10px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -8px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '            <tr>';
    s_str += '                <td  style="background:url(/_img/module/popup_line.png); width:3px; height:100%; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="padding:10px; background:#fff; margin:0px;">';
    s_str += '                <div oldblock="block">';
    s_str += '                <div>' + msg + '</div></div>';
    s_str += '                <div oldblock="block" style="text-align:right; border-top:#dddddd 1px solid; margin:0px; margin-top:10px; padding:5px;"><a style="text-decoration:none; color:#3b5998;" href="#"><img style="padding:0px; margin:0px; border:0px;" title=close src="/_img/module/closelabel.gif" onclick="$(this).parent().parent().parent().parent().parent().parent().remove();"> </a></div></td>';
    s_str += '                <td  style="background:url(/_img/module/popup_line.png); width:3px; height:100%; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '            <tr>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -20px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_line.png); width:10px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '                <td style="background:url(/_img/module/popup_side.png) -30px 0px; width:3px; height:10px; padding:0px; margin:0px;"></td>';
    s_str += '            </tr>';
    s_str += '        </tbody>';
    s_str += '    </table>';

    if ($(".ITF_Msg5832114").length > 0) { $("#ITF_Msg5832114").html(s_str); } else { $("#ITF_Msg5832114").remove(); $(document.body).append(s_str); $("#ITF_Msg5832114").css("top", ($(window).height() / 2) - 233).css("left", ($(window).width() / 2) - 305); };
    
    $("#ITF_Msg5832114").draggable();
}

function modal_interface(cu) {
    switch (cu) {
        case "S":
            {
                var backcolor = $("#ITF_main_ITF_Bottom_Sub").attr("offsetTop") + 350;
                $("body").append("<div id='ITF_backgroundBlK' style='position:absolute; top:0px; left:0px; filter:Alpha(Opacity=50);BACKGROUND:#666666 50% 50%; z-index:2;height:" + backcolor + "px;width:" + 100 + "%;'></div>");
            } break;
        case "H": $("#ITF_backgroundBlK").remove(); break;
        case "R": $("#ITF_backgroundBlK").css({ "height": $("#ITF_main_ITF_Bottom_Sub").attr("offsetTop") + 200, "width": 100 + "%" }); break; //리사이즈
    }

}

function ltrim(value) {
    var LeftTrimValue = "";
    var i = 0;
    if (value == "")
        return "";
    strLen = value.length;
    while (i < strLen) {
        if (value.charAt(i) != " ") break;
        i++;
    }
    for (s = i; s < strLen; s++) {
        LeftTrimValue = LeftTrimValue + value.charAt(s);
    }
    return LeftTrimValue;
}
function rtrim(value) {
    var RightTrimValue = "";
    if (value == "")
        return "";
    strLen = value.length;
    --strLen;
    while (0 <= strLen) {
        if (value.charAt(strLen) != " ") break;
        --strLen;
    }
    for (s = 0; s <= strLen; s++) {
        RightTrimValue = RightTrimValue + value.charAt(s);
    }
    return RightTrimValue;
}


//날짜 더하기
function addDay(ymd, v_day) {


    var yyyy = ymd.substr(0, 4);
    var mm = eval(ymd.substr(4, 2) + '- 1');
    var dd = ymd.substr(6, 2);

    var dt3 = new Date(yyyy, mm, eval(dd + '+' + v_day));

    yyyy = dt3.getYear();
    mm = (dt3.getMonth() + 1) < 10 ? '0' + (dt3.getMonth() + 1) : (dt3.getMonth() + 1);
    dd = dt3.getDate() < 10 ? '0' + dt3.getDate() : dt3.getDate();

    return '' + yyyy + '' + mm + '' + dd;

}

//그달의 몇번째 주인지 확인
function getSecofWeek(date) {
    var d = new Date(date.substring(0, 4), parseInt(date.substring(4, 6)) - 1, date.substring(6, 8));
    var fd = new Date(date.substring(0, 4), parseInt(date.substring(4, 6)) - 1, 1);
    return Math.ceil((parseInt(date.substring(6, 8)) + fd.getDay()) / 7);
}

function retWeekZero(prm) { prm = parseInt(prm); if (prm < 10) { prm = '0' + prm; return prm } else { return prm } }


