﻿// Browse Type
// IE Script
var NS4;
var IE4;
if (document.all)
{
    IE4 = true;
    NS4 = false;
}
else
{
    IE4 = false;
    NS4 = true;
}
isWin = (navigator.appVersion.indexOf("Win") != -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=0");
    }
    else 
    {
        oWnd = window.open(url, name, feature+", width=" + width +", height=" + height + ", resizable=1");
    }

    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 pop(url,width,height,flag)
{
    if (flag == 1 )
        var oPop = open_window(url, "", width, height, "toolbar=0,menubar=0,scrollbars=yes,resizable=yes");    
    else
        var oPop = open_window(url, "", width, height, "toolbar=0,menubar=0,scrollbars=no,resizable=yes");    
    return oPop;        
}

function pop2(url, name, width,height,flag)
{
    if (flag == 1)
		     var oPop = open_window(url, name, width, height, "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1");    
    if (flag == 0)
		     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");
	
	//return oPop;
}

/* 페이지 이동 관련 함수 */
function toLoginPage(paramURL)
{
    if (paramURL == null || paramURL == '')
        paramURL = document.location.href;
        
    var url = "/nidlogin.login?mode=form&url=" + paramURL;
    top.location.href = url;
}
function toLogoutPage()
{
    var url = "/common/LogOut.jsp";
    top.location.href = url;
}

// change admin menu's class
function admin_menu_select(menu_num)
{
    for (i=1; i<=27; i++) 
    {
		var objMenu = parent.document.getElementById("menu" + i);
        if (objMenu != null && typeof(objMenu) == 'object') 
        {
            if (i == menu_num) 
				objMenu.className = "b u";
            else 
				objMenu.className = "";
        }
    }
}
// change cafemain menu's table
function cafemain_menu_select(menu_num)
{
    if (parent != null)
    {
        for (i=1; i<=6; i++)
        {
			var objTopMenuTab = parent.document.getElementById("CafeTopMenuTab" + i);
			if (objTopMenuTab != null && typeof(objTopMenuTab) == 'object')
			{
	            if (i == menu_num)
	                objTopMenuTab.style.display = "block";
		        else
					objTopMenuTab.style.display = "none";
			}
        }
    }
}

function resizepopup()     
{
// var winW = 356, winH = 200;
    winW = document.body.scrollWidth;
    winH = document.body.scrollHeight;
/*
    if(winH > 550)
        winH = 550;
*/
    window.resizeTo(winW + 25,winH + 40);
}

function resizepopup2(wid)     
{
    var winW = wid, winH = 200;
    winH = document.body.scrollHeight;

    if(winH > 550)
        winH = 550;

    window.resizeTo(winW,winH+40);
}

/* onLoad Handler */
LOAD_LIST = new Array();
function LH_create()
{
    this.LIST = LOAD_LIST;
    this.add = LH_add;
    this.exec = LH_exec;
}

function LH_add(strExec)
{
    LOAD_LIST[LOAD_LIST.length] = strExec;
}

function LH_exec()
{
    var list_len = LOAD_LIST.length;
    for (var i = 0; i < list_len; i++)
    {
        eval(LOAD_LIST[i]);
    }
}

/* 한글 스트링 처리 함수 */
// string String::cut(int len, string tail)
String.prototype.cut = function(len, tail) 
{
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) 
    {
        l += (str.charCodeAt(i) > 128) ? 2 : 1;
        if (l > len) return str.substring(0,i) + tail;
    }
    return str;
}

// bool String::bytes(void)
String.prototype.bytes = function() 
{
    var str = this;
    var l = 0;
    for (var i=0; i<str.length; i++) 
        l += (str.charCodeAt(i) > 128) ? 2 : 1;

    return l;
}

// string String::trim();
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, ""); 
}

// 따옴표와 역슬래쉬 처리
function replaceBackslash(paramStr) 
{
    var str = paramStr;
    if (str.indexOf("\\") >= 0) str = str.replace(/\\/g, "\\\\");
    if (str.indexOf("\"") >= 0) str = str.replace(/\"/g, "\\\"");
    return str;
}

function setTop()
{
	window.scrollTo(0,0);
}
// == Iframe Handling ==
// 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)
{
    parent.resizeIframe(name);
    //if (parent && parent != this && parent.resizeIframe != null)
    //{
    //}
}

// F5를 눌렀을때 iframe 내부만 refresh 되도록 처리 start
if (NS4) 
{
    document.captureEvents(Event.KEYDOWN)
    document.onkeydown = trapRefreshNS;
} 
else if (IE4) 
{
    document.onkeydown = trapRefreshIE;
}

function trapRefreshNS(e)
{
    if (e.keyCode == 116)
    {
        e.cancelBubble = true; 
        e.returnValue = false;
        document.location.reload();
    }
}

function trapRefreshIE()
{
    if (event.keyCode == 116)
    {
        event.keyCode = 0; 
        event.cancelBubble = true; 
        event.returnValue = false;
        document.location.reload();
    }
}
// F5를 눌렀을때 iframe 내부만 refresh 되도록 처리 end

function parentPlusIframe(name, height)
{
    if (parent && parent != this && parent.plusIframe != null)
    {
        parent.plusIframe(name, height);
    }
}

function plusIframe(name, height)     
{
    if (name == null || name == "")
    {
        name = "cafemain";
    }
    
    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)
        {
            frmHeight = Math.max(frmHeight, frmMinHeight);
        }
        if (applyMaxSize)
        {
            frmHeight = Math.min(frmHeight, frmMaxHeight);
        }
        oIFrame.style.height = frmHeight + height;
    }
    catch (e)
    {
        window.status = "IFrame Size Plus Error";
    }
  
}

function pop_studio(vSN, vLANG, vKey, vKIND)
{
    document.cookie = 'BA_ONLINE_LECTURE_URL___=' + vSN;
    document.cookie = 'BA_ONLINE_LECTURE_LANG___=' + vLANG;
    document.cookie = 'BA_LECTURE_KIND___=' + vKIND;
    pop2('/_70_Online/M/Studio.aspx?rpk=' + vKey, 'winStudio', 931, 671, 2);
}
