function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0 && a[i] != ""){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.010
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function nvl(value, rep)
{
	if(value == null || $.trim(value) == "") return rep;
	return value;
}

//문자열을 자른후 post값이 있으면 붙이고 없으면 ...을 붙힌다.
function cutStr(str,limit, post)
{
    if(post == null) post = "...";

    if(str.length > limit)
    {
        str = str.substring(0, limit-post.length);
        str = str + post;
    }

    return str;

}

function printSwf(src, width, height , addParams)
{
    document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
    document.writeln('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
    document.writeln('width="' + width + '" height="' + height + '">');
    //document.writeln('<param name="allowScriptAccess" value="sameDomain" />');
    document.writeln('<param name="movie" value="' + src + '" />');
    document.writeln('<param name="wmode" value="transparent" />');
    document.writeln('<param name="quality" value="high" />');
    document.writeln('<param name="bgcolor" value="#ffffff" />');

    if(addParams != null)
    {
        for(var i=0 ; i<addParams.length ; i++)
        {
            document.writeln(addParams[i]);
        }
    }

    document.writeln('<embed src="' + src + '" quality="high" bgcolor="#ffffff" wmode="transparent" width="' + width + '" height="' + height + '" name="menu_navi" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
    document.writeln('</object>');
}

var _idNum = 1;
function printSwf2(url, width, height, idName) {

    if(idName == null) idName = "swf" + _idNum++;

	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' id='" + idName + "' ");
	document.write("codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0'");
	document.write("WIDTH='"+width+"' HEIGHT='"+height+"' id='main' ALIGN='left'>");
	document.write("<PARAM NAME=movie VALUE='"+url+"'>");
	document.write("<PARAM NAME=quality VALUE=high>");
	document.write("<PARAM NAME=scale VALUE=noscale>");
	document.write("<PARAM NAME=salign VALUE=LT>");
	document.write("<PARAM NAME=wmode VALUE=transparent>");
	document.write("<PARAM NAME=bgcolor VALUE=#FFFFFF>");
	document.write("<EMBED src='"+url+"' quality=high scale=noscale salign=LT wmode=transparent bgcolor=#FFFFFF  WIDTH='"+width+"' HEIGHT='"+height+"' NAME='main' ALIGN='left'");
	document.write("TYPE='application/x-shockwave-flash' PLUGINSPAGE='https://www.macromedia.com/go/getflashplayer'></EMBED></OBJECT>");
}

function printStr(str)
{
    document.write(str);
}

function setVisible2(name, is_show)
{
	var display = "none";
	if(is_show) display = "inline";

	var obj;
	if(document.getElementById(name) == null)
	{
		if(frm[name] == null)
		{
			if(document.images[name] == null)
			{
				alert("ERROR : Method setVisible2(), NAME is " + name + " and is_show is " + is_show);
				return;
			}
			else obj = document.images[name];
		}
		else obj = frm[name];
	}
	else obj = document.getElementById(name);
	
	obj.style.display = display;
}

function lpad(str, leng, repChar) {
    str = new String(str);
	for(var i=str.length; i<leng; i++) str = repChar + str;
    return str;
}

function rpad(str, leng, repChar) {
    for(var i=str.length; i<leng; i++)
        str=str+repChar;
    return str;
}

function removeTag(xStr)
{
    var regExp = /<\/?[^>]+>/gi;
    xStr = xStr.replace(regExp,"");

    return xStr;
}

function getDateStr(year, month, day, sdate)
{
    var d = new Date(parseInt(sdate.substring(0, 4)) + year, Number(sdate.substring(5, 7))-1 + month, Number(sdate.substring(8, 10))+day, 0, 0, 0, 0);
    
    return d.getYear() + "-" + lpad(d.getMonth()+1, 2, "0") + "-" + lpad(d.getDate(), 2, "0");
}

function setCookie( name, value, expiredays ) 
{ 
	//var todayDate = new Date(); 
	//todayDate.setDate( todayDate.getDate() + expiredays ); 
	//document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";" 
    var expire_date = new Date();
    expire_date.setDate(expire_date.getDate() + expiredays );
    expire_date.setHours(0,0,0,0);
    document.cookie = name + "=" + escape( value ) + "; expires=" + expire_date.toGMTString() + "; path=/";
}

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 getCheckboxByValue(arr, value)
{
    if(arr.length == undefined) 
    {
        if(arr.value == value) return arr;
    }
    else
    {
        for(var i=0 ; i<arr.length ; i++)
        {
            var obj = arr[i];
            if(obj.value == value) return obj;
        }
    }

    return null;
}

function showIframe(parentIframeName, isDisplay)
{
    if(isDisplay)
    {
        parent.document.getElementById(parentIframeName).style.display = "block";
        parent.document.getElementById(parentIframeName).height = document.body.scrollHeight + 10;
    }
    else
    {
        parent.document.getElementById(parentIframeName).style.display = "none";
        parent.frames[parentIframeName].location.href = "/blank.jsp";
    }
}

/**
	이미지 파일인지 여부 확인
*/
function isImageFile(filename)
{
	var ext = getExtend(filename).toLowerCase();
	
	var arr = ["jpg", "jpeg", "gif", "bmp", "png"];
	
	for(var i=0 ; i<arr.length ; i++) if(arr[i] == ext) return true;
	
	return false;
}

function checkAll2(obj, isChecked)
{
	if(obj == null) return;
	if(obj.length == undefined)
	{
        if(isChecked != null) obj.checked = isChecked;
		else obj.checked = !obj.checked;
	}
	else
	{
		for(var i=0 ; i<obj.length ; i++)
		{
            if(isChecked != null) obj[i].checked = isChecked;
			else obj[i].checked = !obj[i].checked;
		}
	}
}

function getCheckBoxValue(obj)
{
	var ret = new Array();
	if(obj == null) return ret;

	if(obj.length == undefined) 
	{
		if(obj.checked) ret[0] = obj.value;
	}
	else
	{
		var j=0;
		for(var i=0 ; i<obj.length ; i++) 
		{
			if(obj[i].checked) ret[j++] = obj[i].value;
		}
	}

	return ret;
}

function openPopup2(url, name, width, height, top, left, scrollbars, resizable)
{
	if(scrollbars == null) scrollbars = "no";
	if(resizable == null) resizable = "no";
	var w = window.open(
        url, 
        name, 
        "width=" + width + 
        ",height=" + height + 
        ", scrollbars=" + scrollbars + 
        ", status=yes, resizable=" + resizable + 
        ", top=" + top + 
        ", left=" + left
    );
	if(w != null) w.focus();
	return w;
}

function openPopup(url, name, width, height, scrollbars, resizable)
{
	if(scrollbars == null) scrollbars = "no";
	if(resizable == null) resizable = "no";

	var top = window.screen.height/2 - height/2 -20;
    var left = window.screen.width/2 - width/2;

	var w = window.open(
        url, 
        name, 
        "width=" + width + ",height=" + height + ", scrollbars=" + scrollbars + ", status=yes, resizable=" + resizable + 
        ", top=" + top + ", left=" + left
    );
	if(w != null) w.focus();
	return w;
}

function initCombo(obj)
{
    while(obj.options.length > 0)
	{
		obj.options[obj.options.length-1] = null;
	}
}

function addOption(obj, value, text, is_selected)
{
	var index = obj.options.length;
	obj.options[index] = new Option(text, value);
	if(is_selected) obj.options[index].selected = true;

	return obj.options[index];
}

function delOption(obj)
{
    var index = obj.selectedIndex;
    if(index < 0) return false;
    obj.options[index] = null;

    return true;
}

function remove(str, gubun)
{
	return str.split(gubun).join("");
}

function split(str, delim, arrLength)
{
	if(arrLength == null) arrLength = str.split(delim).length;

	var ret = new Array(arrLength);
	if(str == "")
	{
		for(var i=0 ; i<arrLength ; i++) ret[i] = "";
	}
	var t = str.split(delim);

	if(t.length < arrLength)
	{
		for(var i=0 ; i<arrLength ; i++)
		{
			if(i < t.length) ret[i] = t[i];
			else ret[i] = "";
		}
	}
	else
	{
		for(var i=0 ; i<arrLength ; i++)
		{
			ret[i] = t[i];
		}

		for(var i=arrLength ; i<t.length ; i++)
		{
			if(i == arrLength) ret[arrLength-1] += delim;

			if(i == t.length-1) ret[arrLength-1] += t[i];
			else ret[arrLength-1] += t[i] + delim;
		}
	}

	return ret;
}

function replace(str, gubun, rep)
{
	return str.split(gubun).join(rep);
}

function existValue(obj, value){
    if(obj.tagName == "select"){
        for(var i=0 ; i<obj.options.length ; i++){
            if(obj.options[i].value == value) return true;
        }
        return false;
    }

    if(obj.length == null){
        if(obj.value == value) return true;
        else return false;
    }
    else{
        for(var i=0 ; i<obj.length ; i++){
            if(obj[i].value == value) return true;
        }
        return false;
    }
}

var selectedDateInputObject = null;
function openModalCalendar(test, root)
{
	if(test == null) 
	{
		alert("달력 함수 호출시 파라미터가 잘못 되었습니다. 관리자에게 문의하세요.");
		return;
	}

    if(jQuery.browser.msie)
    {
        if(test.disabled) return;
        //xpos = event.screenX-155;
        //ypos = event.screenY+10;
        var ret 	= window.showModalDialog(root + "common/calendar.jsp?fieldvalue="+test.value,"c1", 'dialogHeight:220px;dialogWidth:220px;status:yes; help:no; scroll:auto; center:yes');
        if (ret) test.value = ret;
    }
    else
    {
        selectedDateInputObject = test;
        openPopup(root + "common/calendar.jsp?fieldvalue="+test.value, "c1", 235, 220);
    }
}

function openModal(url, width, height, arg)
{
	if(arg == null) arg = window;
	var ret = showModalDialog(url, arg, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; center=yes; screenTop=yes; scroll=auto; status=yes; help=yes;");
	return ret;
}

function openModal2(url, width, height, arg)
{
	if(arg == null) arg = window;
	var arr = url.split("?");

	url = window.documentRoot + "inc/modal.jsp?submit_page=" + arr[0] + "&" + arr[1];
	var ret = showModalDialog(url, arg, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; center=yes; screenTop=yes; scroll=auto; status=yes; help=yes;");
	return ret;
}

function setClickedCalendar(value){
    selectedDateInputObject.value = value;
}

function getKeySet(frm){
    var ret = new Object();
    for(var i=0 ; i<frm.elements.length ; i++){
        if(frm.elements[i] == null || frm.elements[i].name == null) continue;
        var name = frm.elements[i].name;
        if(name.indexOf("sc_") != 0 && name.indexOf("pk_") != 0) continue;
        if(frm.elements[i].value == "") continue;
        //alert(name + ", " + frm.elements[i].value);

        ret[name] = frm.elements[i].value;
    }

    return ret;
}

function leapyear(year) 
{
	if (((year%4 == 0) && (year%100 != 0)) || (year%400 == 0)) return true;
	else return false;
}

function getLastDay(month, year)
{
	var days;
	month = month-1;
	switch (month)
	{
		case 0 : days=31; break;
		case 1 : if (leapyear(year)) days=29;
					else days=28;
					break;
		case 2 : days=31; break; 
		case 3 : days=30; break;
		case 4 : days=31;  break;
		case 5 : days=30;  break;
		case 6 : days=31;  break;
		case 7 : days=31;  break;
		case 8 : days=30;  break;
		case 9 : days=31;  break;
		case 10 : days=30;  break;
		case 11 : days=31;  break;
	}
	return days;
}

function getStrBytes(val)
{
      // 입력받은 문자열을 escape() 를 이용하여 변환한다.
      // 변환한 문자열 중 유니코드(한글 등)는 공통적으로 %uxxxx로 변환된다.
      var temp_estr = escape(val);
      var s_index   = 0;
      var e_index   = 0;
      var temp_str  = "";
      var cnt       = 0;

      // 문자열 중에서 유니코드를 찾아 제거하면서 갯수를 센다.
      while ((e_index = temp_estr.indexOf("%u", s_index)) >= 0)  // 제거할 문자열이 존재한다면
      {
        temp_str += temp_estr.substring(s_index, e_index);
        s_index = e_index + 6;
        cnt ++;
      }

      temp_str += temp_estr.substring(s_index);

      temp_str = unescape(temp_str);  // 원래 문자열로 바꾼다.

      // 유니코드는 2바이트 씩 계산하고 나머지는 1바이트씩 계산한다.
     
      return ((cnt * 2) + temp_str.length);
       
}

function joinArray(arr, separator)
{
    if(arr == null) return "";

    var str = "";
    for(var i=0 ; i<arr.length ; i++)
    {
        if(i != arr.length-1) str += arr[i] + separator;
        else str += arr[i];
    }

    return str;
}

function parseNumber(num)
{
	num = new String(num);
	num = remove(num, ",");
	if (num.length==0 || isNaN(num)) return 0;
	return Number(num);
}
