/** Read cookie */
var g_BrowserType = getBrowserType();
function leftMenuOver(code)
{
	if(!document.getElementById("mu_"+code)) return;
	document.getElementById("mu_"+code).style.display = "block";
}

function leftMenuOut(code)
{
	if(!document.getElementById("mu_"+code)) return;
    document.getElementById("mu_"+code).style.display = "none";
}

function leftMenuOver2(code)
{
    if(!document.getElementById("mu2_"+code)) return;
    document.getElementById("mu2_"+code).style.display = "block";
}

function leftMenuOut2(code)
{
    if(!document.getElementById("mu2_"+code)) return;
    document.getElementById("mu2_"+code).style.display = "none";
}

function getBrowserType()
{
    var ua = navigator.userAgent;

	if(ua.split('AppleWebKit/')[1])
		return "safari";
	else if(ua.split('Konqueror/')[1])
		return "konqueror";
	else if(ua.split('Gecko/')[1])
		return "gecko";
	else if (!!window.opera && (typeof XMLHttpRequest) == 'function')
		return "opera";
	else if (!!window.ActiveXObject)
		return "msie";
	else 
		return "unknown";

}
function getBrowser()
{
    var a, ua = navigator.userAgent;

    this.bw =
    {
        safari : ((a=ua.split('AppleWebKit/')[1]) ? a.split('(')[0]:0) >=124,
        konqueror : ((a=ua.split('Konqueror/')[1]) ? a.split('(')[0]:0) >=124,
        mozes : ((a=ua.split('Gecko/')[1]) ? a.split('(')[0]:0) >=124,
        opera : (!!window.opera) && ((typeof XMLHttpRequest) == 'function'),
        msie : (!!window.ActiveXObject) ? (!!createHttpRequest()) : false
    }

    return (this.bw.safari || this.bw.konqueror || this.bw.mozes || this.bw.opera || this.bw.msie);
}

function createHttpRequest() 
{
    if(window.ActiveXObject)
    {
        try
        {
            return new ActiveObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
            try
            {
                return new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e2)
            {
                return null;
            }
        }
    }
    else if(window.XMLHttpRequest)
    {
        return new XMLHttpRequest();
    }
    else
        return null;
}

function sendRequest(callback, data, method, url, async, sload, user, password)
{
    var oj = createHttpRequest();

    if(oj == null)
        return null;

    var sload = (!!sendRequest.arguments[5]) ? sload:false;
    if(sload || method.toUpperCase() == 'GET')
        url += "?";
    if(sload)
        url = url + "t=" + (new Date()).getTime();

    var bwoj = new getBrowser();

    var opera = bwoj.bw.opera;
    var safari = bwoj.bw.safari;
    var konqueror = bwoj.bw.konqueror;
    var mozes = bwoj.bw.mozes;

    if(opera || safari || mozes)
    {
        oj.onload = function()
        {
            callback(oj);
        }
    }
    else
    {
        oj.onreadystatechange = function()
        {
            if(oj.readyState == 4)
            {
                callback(oj);
            }
        }
    }

    data = uriEncode(data);
    if(method.toUpperCase() == 'GET')
        url += data;

    oj.open(method, url, async, user, password);

    setEncHeader(oj);
    oj.send(data);


    function setEncHeader(oj)
    {
        //var contentTypeUrlenc = 'application/xml; charset=UTF-8';
        var contentTypeUrlenc = 'application/x-www-form-urlencoded; charset=UTF-8';
        if(!window.opera)
        {
            oj.setRequestHeader('Content-Type', contentTypeUrlenc);
        }
        else
        {
            if((typeof oj.setRequestHeader) == 'function')
            {
                oj.setRequestHeader('Content-Type', contentTypeUrlenc);
            }
        }

        return oj;
    }

    function uriEncode(data)
    {
        if(data != '')
        {
            var encdata = '';
            var datas = data.split('&');

            for(i = 1; i < datas.length; i++)
            {
                var dataq = datas[i].split('=');
                encdata += '&' + encodeURIComponent(dataq[0]) + '=' + encodeURIComponent(dataq[1]);
            }
        }
        else
        {
            encdata = '';
        }

        return encdata;
    }

    return oj;
}

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 "";
}

function setCookie(name, value, expiredays)
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function goURL(url)
{
	document.location.href = url;
}

function removeOptions(ob)
{
    var len = ob.options.length;
    for(i = len - 1; i >= 0; i--)
        ob.options[i] = null;
}

function hoverRecode(obj)
{
	obj.style.backgroundColor = '#ccc;'
}

function addOption(ob, title, val)
{
    ob.options[ob.length] = new Option(title, val);
}

function insertComma(num) 
{
	var rtn = "";
	var val = "";
	var kq1 = 0;

	var str = '' + num;
	var len = str.length;
	for(kq0 = len; kq0 > 0; kq0--) 
	{
		if(str.substring(kq0, kq0-1) != ",") 
		{
			val = str.substring(kq0, kq0-1) + val;
		}
	}

	len = val.length;

	for(kq0 = len; kq0 > 0; kq0--) 
	{
		if(kq1%3 == 0 && kq1 !=0) 
		{
			rtn = val.substring(kq0, kq0-1)+","+rtn; 
		} else {
			rtn = val.substring(kq0, kq0-1)+rtn;
		}
		kq1++;
	}
	return rtn;
}

/** Show Flash */
function showFlash(name, width, height, cpos)
{
    document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
    document.write(' codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"  width=' + width);
    document.writeln(' height=' + height + ' id="' + name + '" align="middle">');
    document.writeln('<param name="movie" value="/img/' + name + '.swf?pageNum=<? echo $cur_pos; ?>" />');
    document.writeln('<param name="quality" value="high" />');
    document.writeln('<param name="wmode" value="opaque" />');
    //document.writeln('<param name="wmode" value="transparent" />');
	document.writeln('<param name="bgcolor" value="#ffffff" />');
    document.writeln('<embed src="/img/' + name + '.swf?pageNum=' + cpos + '" quality="high" ');
	document.writeln('bgcolor="#ffffff" width="' + width + '" height="' + height + '" ');
    document.writeln('name="' + name + '" align= "middle" type="application/x-shockwave-flash" wmode="opaque" /');
	document.writeln('pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.writeln('</object>');
}

function hidePanel()
{
    var hh = document.getElementById('panel');
    var hb = document.getElementById('panel_back');

    hb.style.display = 'none';
    hh.style.display = 'none';
	
	setOpacity("main_area", 1);	
}

function showPanel(title, content, buttons, w, h)
{
    var f_width = w;
    var f_height = h;

    var f_title = title;
    var f_contents = content;

	var hh = document.getElementById("panel");
	var hb = document.getElementById("panel_back");

    if(g_BrowserType == 'msie')
    {
        width = document.body.clientWidth;
        height = document.body.clientHeight;
    }
    else
    {
        width = window.innerWidth;
        height = window.innerHeight;
    }

	var sy = 0;
	if(g_BrowserType == 'msie')
		sy = document.body.scrollTop;
	else
		sy = window.pageYOffset;
		
    hh.style.top = hb.style.top = (height/2 - f_height/2 + sy) + 'px';
    hh.style.left = hb.style.left = (width/2 - f_width/2) + 'px';
    hh.style.width = hb.style.width = f_width + 'px';
    hh.style.height = hb.style.height = f_height + 'px';

    hh.innerHTML = '<div id="panel_head"><p>' + f_title + '</p><span class="xbtn"><a href="javascript:hidePanel()"><img src="/ncz/img/panel_close.gif"></a></span></div>';
    hh.innerHTML += '<div id="panel_content">' + f_contents + '</div>';

	if(buttons)
		buttons += "&nbsp;";

	buttons += '&nbsp;<a href="javascript:hidePanel()"><img src="/img/btn_close.jpg"></a>';

    hh.innerHTML += '<div style="text-align:center;margin-top:10px;">' + buttons + '</div>';

    if(g_BrowserType == 'msie')
        hb.style.display = 'block';
    hh.style.display = 'block';

    setOpacity("main_area", 0.5);

}

function setOpacity(layName, arg)
{
    if(g_BrowserType == 'opera')
        return;
        
    if(g_BrowserType == 'Safari')
    {   
        document.getElementById(layName).style.opacity = arg;
    }   
    else if(g_BrowserType == 'gecko')
	{
        document.getElementById(layName).style.MozOpacity = arg;
    }
	else if(g_BrowserType == 'msie')
    {
        document.all(layName).style.filter = "alpha(opacity=0)";
        document.all(layName).filters.alpha.Opacity = (arg * 100);
    }
}

function checkInputDate(obj)
{
	var str = obj.value;
	var valid = true;
	
	if(/^[-0-9]+$/.test(str))
	{
		if(str.length > 12 || str.length < 6)
			valid = false;
		else
		{
			if(/^[-]+$/.test(str) == false)
			{
				var y = str.substr(0, 4);
				var m = str.substr(4, 2);
				var d = str.substr(6, 2);

				var nd = y+'-'+m+'-'+d;

				obj.value = nd;
			}
		}	
	}
	else
		valid = false;
		
	if(valid == false)
	{
		alert('날짜는 yyyy-mm-dd (예:2000-2-20)와 같은 형식으로 입력하셔야 합니다.');
		obj.focus();
		return;
	}	
}

function loginMessage()
{
	alert('로그인 후 사용해 주세요.');
}

