/**
 * common.js
 *
 * Utility Class
 *
 * @author     李永珍
 * @version    1.0
 * 
 * @history
 *     - 20060619 / 이영진 / 최초작성
 */




/*****************************************************************************/




/**
 * StringUtil Constructor
 * 문자열 처리에 관련된 기본적인 메소드를 제공한다
 */
function StringUtil()
{
    this.checkField = checkField;
    this.nullTostring = nullTostring;
    this.isNumber = isNumber;
    this.parseInt = parseInt;
    this.trim = trim;
	this.isEmpty = isEmpty;
}


/**
 * 필드를 테스트 한다
 *
 * @param     str   값
 * @param     type  체크할 타입
 * @return    true, false
 */
function checkField(str, type)
{
    if(str == null || str == "" || type == null || isNaN(type)) return false;
    
    switch(type)
    {
        /** 한글 이름 */
        case 1 :
            if(!str.match(/^[ㄱ-힣]{3,5}$/g)) return false;
            break;
        /** 영문 이름 */
        case 2 :
            if(!str.match(/^[^a-zA-Z0-9 ]{3,5}$/g)) return false;
            break;
        /** 한자 이름 */
        case 3 :
            if(!str.match(/^[a-zA-Z ]{3,15}$/g)) return false;
            break;    
        /** 생년월일 (YYYYMMDD) */
        case 4 :
            if(!str.match(/^[0-9]{8}$/g)) return false;
            break;
        /** 우편번호 (XXX-XXX) */
        case 5 :
            if(!str.match(/^[0-9]{3}-[0-9]{3}$/g)) return false;
            break;
        /** 주소 */
        case 5 :
            if(!str.match(/^[0-9ㄱ-힣 ]{2,}$/g)) return false;
            break;
        /** 전화번호 (XXX-XXXX-XXXX) */
        case 6 :
            if(!str.match(/^[0-9]{2,3}-[0-9]{3,4}-[0-9]{3,4}$/g)) return false;
            break;
        /** 휴대폰번호 (XXX-XXXX-XXXX) */
        case 7 :
            if(!str.match(/^(010|011|016|017|018|019)-[0-9]{3,4}-[0-9]{3,4}$/g)) return false;
            break;
        /** 패스워드 (4자리이상) */
        case 8 :
            if(!str.match(/^.{4}$/g)) return false;
            break;
        /** 주민번호 */
        case 9 :
            if(!str.match(/^[0-9]{6}-[0-9]{7}$/g)) return false;
            break;
        /** 메일주소 (aaa@bbb.com) */
        case 10 :
            if(!str.match(/^(\S+)@(\S+)\.(\S+)/g)) return false;
            break;
        /** Default */
        default :
            return false;
            break;
    }
    return true;
}


/**
 * null 을 "" 로 돌려준다
 * 
 * @param     str 체크할 string
 * @return    null 이면 ""
 */
function nullTostring(str)
{
    if(str == null) return "";
    else return str;
}


/**
 * 숫자인지 체크한다
 *
 * @param     str 체크할 string
 * @return    true, false
 */
function isNumber(str)
{
    if(str == null || str == "" || isNaN(str)) return false;
    return true;
}


/**
 * Int 형으로 parsing 한다
 * null 이면 0 을 리턴한다
 *
 * @param     str    문자
 * @return    number 숫자
 */
function parseInt(str)
{
    if(str == null || str == "" || isNaN(str)) return 0;
    return str;
}


/**
 * 문자열 앞뒤에 있는 white space 를 삭제한다
 *
 * @param     str 대상 문자열
 * @return    white space 가 삭제된 문자열
 */
function trim(str)
{
    return str.replace(/(^\s*)|(\s*$)/g, "");
}


/**
 * 값이 있는지 검사 한다. 
 */
function isEmpty(str)
{
	if(str.length <= 0) return true;
	else return false;
}

/*****************************************************************************/




/**
 * Popup Util Constructor
 * 팝업에 관련된 메소드를 호출한다
 */
function PopupUtil()
{
    this.obj = null;
    //this.extVal = null;
    
    this.afterCallWork = null;
    this.openPopup = openPopup;
    this.checkOpenPopup = checkOpenPopup;
    this.afterWork = afterWork;
    this.setCookie = setCookie;
    this.getCookie = getCookie;
}


/**
 * 팝업을 오픈한다
 *
 * @param     url           open 할 URL
 * @param     width         가로
 * @param     height        세로
 * @param     param         파라미터
 * @param     obj           오픈한 객체
 * @param     afterCallWork 후처리 작업을 진행할 메소드
 */
function openPopup(url, width, height, param, obj, afterCallWork)
{
    var parm = "";
    
    if(obj != null) this.obj = obj;
    if(afterCallWork != null) this.afterCallWork = afterCallWork;
    if(param != null) parm = "?" + param;

    window.popup(url + parm, "POPUP", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height + ",left=0, top=0");
}


/**
 * 쿠키값을 체크해서, 값이 존재하지 않으면 창을 오픈한다
 *
 * @param     cookieName 쿠키 이름
 * @param     url        open할 URL
 * @param     width      가로
 * @param     height     세로
 */
function checkOpenPopup(cookieName, url, width, height, param)
{
    if(cookieName == null || this.getCookie(cookieName) == "done") return;
    
    var parm = "";
    if(param != null) parm = "?" + param;

    window.popup(url + parm, "POPUP", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, width=" + width + ", height=" + height + ",left=0, top=0");
}


/**
 * 쿠키값을 세팅한다
 * 
 * @param     name       변수
 * @param     value      값
 * @param     expiredays 유효일
 */
function setCookie(name, value, expiredays)
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expiredays );
    document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}


/**
 * 쿠키값을 가져온다
 *
 * @param     name  변수
 * @return    value 값
 */
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 "";
}


/**
 * 오픈한 POPUP 에서 호출할 메소드
 * Object 값이 있을경우, 해당 객체에 값을 세팅한다
 *
 * @param     value 세팅할 값
 */
function afterWork(value)
{
    if((this.obj != null) && (value != null))
        this.obj.value = value;
    
    if(this.afterCallWork != null)
        this.afterCallWork();
}

/*****************************************************************************/




var xmlHttpObject = null;   /** XML HTTP Object */
var afterCallWork = null;   /** 후처리 작업을 진행할 Function */


/**
 * AjaxUtil Constructor
 * 동기식, 비동기식으로 페이지를 호출할때 사용할수 있다.
 * 단, 비동기식으로 여러가지 Control 에서 호출시 문제가 발생할수 있음
 * 코드값 호출시 등과 같은 비교적 Cost 가 적게 발생하는 사항에 대해서는
 * 되도록, 동기식 호출을 하는 편이 낫다.
 * 단, 여러가지 컨트롤을 연속적으로 값을 변경해야 할시에는
 * 꼭 동기식 호출을 하도록 권장함
 */
function AjaxUtil()
{
    //this.xmlHttpObject = null;

    this.afterCallWork = null;
    this.createXmlHttpObject = createXmlHttpObject;
    this.sendRequest = sendRequest;
    this.sendAsyncRequest = sendAsyncRequest;
    this.afterWork = afterWork;
    this.uriEncode = uriEncode;

    //this.createXmlHttpObject();
}


/**
 * 새로운 XML HTTP Instance 생성
 */
function createXmlHttpObject()
{
    if(window.ActiveXObject != null)
    {
        xmlHttpObject = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
        xmlHttpObject = new XMLHttpRequest();
    }
}


/**
 * 비동기식 request 메세지 생성
 * 비동기 식으로 연속 호출시에는 문제가 발생할 소지가 있음
 *
 * @param   url               open 할 URL
 * @param   afterCallWorkProc 페이지 로딩후, 호출할 함수
 */
function sendAsyncRequest(url, afterCallWorkProc)
{
    this.createXmlHttpObject();

    if(afterCallWorkProc != null) afterCallWork = afterCallWorkProc;
    xmlHttpObject.onreadystatechange = this.afterWork;
    xmlHttpObject.open("GET", this.uriEncode(url), true);
    xmlHttpObject.send("");
}


/**
 * 동기식 request 메세지 생성
 *
 * @param   url               open URL
 * @param   afterCallWorkProc 페이지 로딩후, 호출할 함수
 */
function sendRequest(url, afterCallWorkProc)
{
    this.createXmlHttpObject();

    if(afterCallWorkProc != null) afterCallWork = afterCallWorkProc;
    xmlHttpObject.onreadystatechange = this.afterWork;
    xmlHttpObject.open("GET", this.uriEncode(url), false);
    xmlHttpObject.send("");
}


/**
 * 후처리 작업
 * 페이지가 완전히 Open 된 후에 작업을 처리 한다
 */
function afterWork()
{
    if(xmlHttpObject.readyState == 4) 
    {
        if(xmlHttpObject.status == 200) 
        {
            if(afterCallWork != null) afterCallWork(xmlHttpObject.responseText);
        }
    }
}


function uriEncode(data)
{
    var encdata;

    // Query String 이 있는 경우
    if(data.indexOf("?") != -1)
    {
        var spData = data.split("?");
        var queryString = spData[1];

        encdata = spData[0] + "?";

        var spQueryString = queryString.split("&");
        for(i=0; i<spQueryString.length; i++)
        {
            var queue = spQueryString[i].split("=");
            if(i != 0) encdata += "&";
            encdata += encodeURIComponent(queue[0]) + "=" + encodeURIComponent(queue[1]);
        }
    }

    // Query String 이 없을 경우
    else
    {
        encdata = data;
    }

    //alert(data);
    return encdata;
}




/*****************************************************************************/




var webControl = null;            /** Control Object for Ajax */
var webControlCustonValue = null; /** Extend Value */


/**
 * WebControl Constoructor
 */
function WebControlUtil()
{
    this.selectValue = null;
    this.makeOption = makeOption;
    this.setOption = setOption;
    this.printNamoEditor = printNamoEditor;
    this.getNamoMimeValue = getNamoMimeValue;

    this.namoCounter = 0;
}


/**
 * Option 을 동적으로 생성해준다
 * 
 *
 * @param   selectObj option 을 붙일 select object
 * @param   codePage  코드값을 가져올수 있는 페이지
 */
function makeOption(selectObj, codePage, selectValue)
{
    if(ajaxUtil == null || selectObj == null || codePage == null) return;

    webControl = selectObj;
    webControlCustonValue = selectValue;
    ajaxUtil.sendRequest(codePage, this.setOption);
}


/**
 * Ajax 가 호출해 주는 메소드
 * 일정 메세지 규칙이 필요하다.
 * JSP 단에서 뿌려줄때, JSON 형식으로 뿌려준다
 * [ [VALUE,TEXT,CHECK], ... ] 배열 생성
 *
 * @param    resultStr 결과 문자열
 * @param    selectObj Option 값을 붙일 객체
 */
function setOption(resultStr)
{
    if(resultStr == null || stringUtil.trim(resultStr) == "")
        return;

    var selectObj = webControl;

    eval("var result = " + resultStr);

    var strLen = result.length;
    var selectedIndex = 0;

    // 초기화
    selectObj.length = 0;
    selectObj.options[0] = new Option("선택하세요", "", false);

    for(i = 0; i < strLen; i++)
    {
        var value  = result[i][0];
        var text   = result[i][1];
        //if(result[i][2]) selectedIndex = i + 1;
        if(webControlCustonValue == value) selectedIndex = i + 1;

        selectObj.options[i + 1] = new Option(text, value, false);
    }

    selectObj.options[selectedIndex].selected = true;

    webControl = null;
    webControlCustonValue = null;
}


/**
 * Namo Editor 를 출력한다
 * @param name 내용 폼의 이름
 * @param value 값
 * @param customWidth 가로크기
 * @param customHeight 세로크기
 */
//function printNamoEditor(name, value, customWidth, customHeight)
function printNamoEditor(customWidth, customHeight, wecName)
{
    var width = "100%";
    var height = "400";
    var objName = "wec";

    if(customWidth != null)
        width = customWidth;
    if(customHeight != null)
        height = customHeight;
    if(wecName != null)
        objName = wecName;

    document.write('<OBJECT classid=clsid:5220cb21-c88d-11cf-b347-00aa00a28331 width=0 height=0>');
    document.write('<PARAM NAME="LpkPath" VALUE="/include/NamoWec6_cheil_intranet.lpk">');
    document.write('</OBJECT>');
    document.write('<OBJECT id="' + objName + '" CLASSID="CLSID:6065A966-009E-44d1-9718-EC3DB8EB204E" CODEBASE="/include/NamoWec.cab#version=6,0,0,43" width="' + width + '" height="' + height + '" style="z-index:1">');
    document.write('<param name="UseNamoNet" value="0">');
    document.write('<param name="InitFileURL" value="/include/namowec.env">');
    document.write('<param name="InstallSourceURL" value="http://www.namo.co.kr/activesquare/products/update">');
    document.write('</OBJECT>');
    document.write('<input type="hidden" name="isNamoEditor" value="Y">');
}




function getNamoMimeValue(namoControl)
{
    if(namoControl == null)
        return;

    var header = '';
    header += '<html>\n';
    header += '<head>\n';
    header += '<meta http-equiv="content-type" content="text/html; charset=utf-8">\n';
    header += '</head>';
    header += '<body>\n\n';
    
    var footer = '\n\n';
    footer += '</body>\n';
    footer += '</html>\n';

    namoControl.value = header + namoControl.value + footer;

    return namoControl.MIMEValue;
}




/*****************************************************************************/




/**
 * Calendar Util Constructor
 * 달력 출력 및 날짜 추출에 사용된다
 */
function CalendarUtil()
{
    this.objName       = null;
    this.calendarLayer = null;

    // 현재 캘린더의 사이즈
    // 디자인을 변경할시 같이 늘려줄것!!!!!!!!!!!!
    this.calendarWidth = 177;
    this.calendarHeight = 187;

    // 현재 이동하고 있는 일
    this.year  = null;
    this.month = null;
    this.day   = null;

    // 처음 선택한 일
    this.selectYear  = null;
    this.selectMonth = null;
    this.selectDay   = null;

    this.printCalendar        = printCalendar;
    this.printCalendarBase    = printCalendarBase;
    this.getCalendarTemplete  = getCalendarTemplete;
    this.printCalendarContent = printCalendarContent;
    this.goMonth              = goMonth;
    this.setValue             = setValue;
    this.closeCalendar        = closeCalendar;

    // 월별 마지막 일
    this.lastDay     = new Array();
    this.lastDay[1]  = 31;
    this.lastDay[2]  = 29;
    this.lastDay[3]  = 31;
    this.lastDay[4]  = 30;
    this.lastDay[5]  = 31;
    this.lastDay[6]  = 31;
    this.lastDay[7]  = 30;
    this.lastDay[8]  = 31;
    this.lastDay[9]  = 30;
    this.lastDay[10] = 31;
    this.lastDay[11] = 30;
    this.lastDay[12] = 31;
}


/**
 * 달력 레이어를 출력한다
 */
function printCalendarBase()
{
    if(this.calendarLayer != null) return;

    var tag = document.createElement("DIV");
    var div = document.body.appendChild(tag);

    div.style.position = "absolute";
    div.style.diplay   = "none";
    div.style.zIndex = 9;

    this.calendarLayer = div;
}


/**
 * 달력 템플릿을 돌려준다
 */
function getCalendarTemplete()
{
    var strHTML  = '';
    strHTML += '<TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1"><TR><TD BGCOLOR="#C3C3C3">';
    strHTML += '<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" BGCOLOR="#FFFFFF">';
    strHTML += '<TR>';
    strHTML += '    <TD ALIGN=CENTER></TD>';
    strHTML += '    <TD ALIGN=CENTER><A HREF="JavaScript:calendarUtil.goMonth(-1);" ONFOCUS="this.blur();" STYLE="font-family:돋움; font-size:6pt; color:#6B6B6B; text-decoration:none;">◀</A></TD>';
    strHTML += '    <TD ALIGN=CENTER COLSPAN="3" HEIGHT="25"><FONT STYLE="font-family:Tahoma; font-size:13pt; color:#000000;">__CALENDAR_YEAR__</FONT><FONT STYLE="font-family:Tahoma; font-size:13pt; color:#AE0000;">__CALENDAR_MONTH__</FONT></TD>';
    strHTML += '    <TD ALIGN=CENTER><A HREF="JavaScript:calendarUtil.goMonth(1);" ONFOCUS="this.blur();" STYLE="font-family:돋움; font-size:6pt; color:#6B6B6B; text-decoration:none;">▶</A></TD>';
    strHTML += '    <TD ALIGN=CENTER></TD>';
    strHTML += '</TR>';
    strHTML += '<TR HEIGHT="20">';

	// 제일모직 스타렉스의 도메인에 맞게끔 언어 표현을 위해 ( 수정자 : 강상주, 수정일 : 2007-04-16 )
	 var Dns;
	 Dns=location.href;
	 Dns=Dns.split("//");
	 Dns="http://"+Dns[1].substr(0,Dns[1].indexOf("/"));

	if( Dns == 'http://samsungstarex.com' || Dns == 'http://www.samsungstarex.com' )
	{
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#AE0000;">Su</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">Mo</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">Tu</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">We</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">Th</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">Fr</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">Sa</TD>';
	}
	else if( Dns == 'http://samsungstarex.com.cn' || Dns == 'http://www.samsungstarex.com.cn' )
	{
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#AE0000;">日</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">月</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">火</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">水</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">木</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">金</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">土</TD>';
	}
	else
	{
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#AE0000;">일</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">월</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">화</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">수</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">목</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">금</TD>';
		strHTML += '    <TD ALIGN="CENTER" WIDTH="25" STYLE="font-family:돋움; font-size:8pt; color:#000000;">토</TD>';
	}
    
	strHTML += '</TR>';
    strHTML += '__CALENDAR_CONTENT__';
    strHTML += '<TR HEIGHT="20"><TD COLSPAN="7" ALIGN="RIGHT"><A HREF="JavaScript:calendarUtil.closeCalendar();" STYLE="font-family:돋움; font-size:8pt; color:#BFBFBF; font-weight:bold; text-decoration:none;">창닫기</A>&nbsp;</TD></TR>';
    strHTML += '</TABLE>';
    strHTML += '</TD></TR></TABLE>';

    return strHTML;
}


/**
 * 달력을 출력한다
 *
 * @param    objName 값을 뿌려줄 Object
 */
function printCalendar(obj, eventHandler, bEtc)
{
    if(bEtc == null) bEtc = false;

    //if(obj == null || eventHandler == null) return;
    if(obj == null) return;

    if(this.objName != null)
    {
        alert("이미 열려있는 달력이 있습니다");
        return;
    }

    var nowDate = null;

    this.objName = obj;
    this.printCalendarBase(); 

    var posX = document.body.scrollLeft + eventHandler.clientX;
    var posY = document.body.scrollTop + eventHandler.clientY;

    // 기타 설정으로, 무조건 위쪽으로 나오게 할때
    if(bEtc)
    {
        posX = document.body.scrollLeft + eventHandler.clientX - this.calendarWidth;
        posY = document.body.scrollTop + eventHandler.clientY - this.calendarHeight;
    }
    else
    {
        //if(posX + this.calendarWidth >= window.document.body.offsetWidth)
        if(eventHandler.clientX + this.calendarWidth >= window.document.body.offsetWidth)
            posX = document.body.scrollLeft + window.document.body.offsetWidth - this.calendarWidth - 10;
        //if(posY + this.calendarHeight >= window.document.body.offsetHeight)
        if(eventHandler.clientY + this.calendarHeight >= window.document.body.offsetHeight)
            posY = document.body.scrollTop + window.document.body.offsetHeight - this.calendarHeight - 10;
    }

    this.calendarLayer.style.left = posX + "px";
    this.calendarLayer.style.top = posY + "px";
    this.calendarLayer.style.filter = "alpha(opacity=80)";

    // Object 에 값이 있을 경우
    if(this.objName != null && this.objName.value != "")
    {
        var tmpDate  = this.objName.value;

        var strYear  = tmpDate.substr(0, 4);
        var strMonth = tmpDate.substr(4, 2);
        var strDay   = tmpDate.substr(6, 2);

        var nowDate = new Date(strYear, strMonth - 1 , strDay);
    }
    // 값이 없을 경우
    else
    {
        var nowDate = new Date();
    }

    //this.year   = nowDate.getYear();
    this.year   = nowDate.getFullYear();
    this.month  = nowDate.getMonth();
    this.day    = nowDate.getDate();

    this.selectYear  = this.year;
    this.selectMonth = this.month;
    this.selectDay   = this.day;

    this.printCalendarContent();
}


/**
 * 달력을 닫는다
 */
function closeCalendar()
{
    this.calendarLayer.style.display = "none";
    this.objName = null;
}


/**
 * 해당하는 월로 이동한다
 *
 * @param    flag 월에 더해질 값
 */
function goMonth(flag)
{
    var date = new Date(this.year, this.month + flag, 1);
    //this.year = date.getYear();
    this.year = date.getFullYear();
    this.month = date.getMonth();

    this.printCalendarContent();
}


/**
 * 객체에 값을 세팅한다
 *
 * @param    dayNum 날짜
 */
function setValue(dayNum)
{
    var strMonth = null;
    var strDay   = null;

    strMonth = (this.month + 1 < 10) ? "0" + (this.month + 1) : (this.month + 1);
    strDay   = (dayNum < 10) ? "0" + dayNum : dayNum;

    this.objName.value = this.year + "" + strMonth + "" + strDay;
    this.calendarLayer.style.display = "none";

    this.objName = null;
}


/**
 * 달력 내용을 출력한다
 */
function printCalendarContent()
{
    var strHTML     = '';
    var contentHTML = '';
    var firstOfDate = null;
    var firstOfDay  = null;
    var strMonth    = (this.month + 1 < 10) ? "0" + (this.month + 1) : (this.month + 1);
    var numDay      = 1;
    var rowCounter  = 0;

    // 첫일의 요일을 구한다
    firstOfDate = new Date(this.year, this.month, 1);
    firstOfDay  = firstOfDate.getDay();
    rowCounter = Math.ceil((this.lastDay[this.month + 1] + firstOfDay ) / 7);

    for(i = 0; i < rowCounter; i++)
    {
        contentHTML += '<TR HEIGHT="20">';
        for(j = 0; j < 7; j++)
        {
            // 공백일
            if((i == 0 && j < firstOfDay) || numDay > this.lastDay[this.month + 1])
            {
                contentHTML += '<TD></TD>'
            }
            // 휴일
            else if(j == 0) 
            {
                if(this.month == this.selectMonth && this.selectDay == numDay) 
                    contentHTML += '<TD ALIGN="CENTER"><A HREF="JavaScript:calendarUtil.setValue(' + numDay + ');" STYLE="font-family:돋움; font-size:8pt; color:#FF3306; font-weight:bold; text-decoration:none;">' + numDay + '</A></TD>';
                else 
                    contentHTML += '<TD ALIGN="CENTER"><A HREF="JavaScript:calendarUtil.setValue(' + numDay + ');" STYLE="font-family:돋움; font-size:8pt; color:#FF8306; text-decoration:none;">' + numDay + '</A></TD>';
                numDay ++;
            }
            // 평일
            else
            {
                if(this.month == this.selectMonth && this.selectDay == numDay) 
                    contentHTML += '<TD ALIGN="CENTER"><A HREF="JavaScript:calendarUtil.setValue(' + numDay + ');" STYLE="font-family:돋움; font-size:8pt; color:#000000; font-weight:bold; text-decoration:none;">' + numDay + '</A></TD>';
                else 
                    contentHTML += '<TD ALIGN="CENTER"><A HREF="JavaScript:calendarUtil.setValue(' + numDay + ');" STYLE="font-family:돋움; font-size:8pt; color:#BFBFBF; text-decoration:none;">' + numDay + '</A></TD>';
                numDay ++;
            }
        }
        contentHTML += '</TR>';
    }
    
    strHTML = this.getCalendarTemplete();
    strHTML = strHTML.replace("__CALENDAR_YEAR__", this.year);
    strHTML = strHTML.replace("__CALENDAR_MONTH__", strMonth);
    strHTML = strHTML.replace("__CALENDAR_CONTENT__", contentHTML);
    
    this.calendarLayer.innerHTML = strHTML;
    this.calendarLayer.style.display = "inline";
}




/*****************************************************************************/




/**
 * Tree 구조의 메뉴를 만들기 위한 유틸
 */
function TreeUtil()
{
    this.treeTable       = null;                // Tree Table
    this.actionEnabled   = false;               // 추가, 수정, 삭제등의 Action 이 가능한지 여부
    this.actionURL       = "#";                 // Action 을 할 URL : Ajax 통신을 하게 된다
    this.arrNodeObject   = new Array();         // Node 정보가 저장된 배열
    this.rootNodeName    = null;                // 최상위 루트 이름

    this.fontColor       = null;                // 글꼴 색상
    this.fontSize        = null;                // 글꼴 사이즈
    this.imgSpacer       = null;                // 왼쪽 공백 이미지
    this.imgFolderOpen   = null;                // 열린 폴더 이미지
    this.imgFolderClosed = null;                // 닫힌 폴더 이미지
    this.imgNodeLine     = null;                // 노드 연결 라인
    this.imgNodeLineTail = null;                // 노드 연결 마지막 처리 라인
    
    this.setTreeConfig    = setTreeConfig;      // 사용자 설정을 읽어 들임
    this.printTreeBase    = printTreeBase;      // Tree Table 생성
    this.setActionURL     = setActionURL;       // 실제 처리를 할 URL
    this.setActionEnabled = setActionEnabled;   // 별도로 처리 실행 여부
    this.setRoot          = setRoot;            // 최상위 루트를 세팅한다
    this.addNode          = addNode;            // 새로운 Node 를 생성
    this.printTree        = printTree;          // 트리를 출력한다

    // 사용자 정의 변수 초기화
    this.setTreeConfig();
}


/**
 * 트리메뉴에 대한 설정
 */
function setTreeConfig()
{
    this.fontColor       = "#000000";
    this.fontSize        = "9pt";

    this.imgSpacer       = "/images/tree/spacer.gif";
    this.imgFolderOpen   = "/images/tree/folder_open.gif";
    this.imgFolderClosed = "/images/tree/folder_closed.gif";
    this.imgNodeLine     = "/images/tree/node_line.gif";
    this.imgNodeLineTail = "/images/tree/node_line_tail.gif";
}


/**
 * Tree 레이어를 생성한다
 */
function printTreeBase()
{
    if(this.treeTable != null) return;

    var tag = document.createElement("TABLE");
    var table = document.body.appendChild(tag);

    this.treeTable = table;

    table.style.display     = "none";
    table.style.cellPadding = "0";
    table.style.cellspacing = "0";

    // User define style
    table.style.fontSize    = this.fontSize;
    table.style.color       = this.fontColor;
}


/**
 * ROOT 노드를 입력한다
 *
 * @param    rootNodeName 최상위 루트 노드 이름
 */
function setRoot(rootNodeName)
{
    if(rootNodeName == null) return;

    this.printTreeBase();
    this.rootNodeName = rootNodeName;
    this.addNode("", rootNodeName, 0, 0);
}


/**
 * Action 을 하게 할지 여부 결정
 * 오른쪽 마우스 버튼을 눌렀을때, Context 메뉴가 보이게 한다.
 *
 * @param   true, false
 */
function setActionEnabled(bAction)
{
    this.actionEnabled = bAction;
}


/**
 * Action 을 할 URL 을 입력한다
 *
 * @param   url Action 을 할 URL
 */
function setActionURL(url)
{
    this.actionURL = url;
}


/**
 * Tree Menu 를 출력한다
 */
function printTree()
{
    if(this.rootNodeName == null) 
    {
        alert('트리메뉴의 최상위 루트가 정의 되지 않았습니다');
        return;
    }

    this.treeTable.style.display = "inline";
}


/**
 * Node 를 정해진 위치에 Add 한다
 *
 * @param    nodeCode 노드 코드
 * @param    nodeName 노드 이름
 * @param    nodePosition 삽입할 노드의 위치
 * @param    depth 현재 노드의 Depth
 */
function addNode(nodeCode, nodeName, sort, depth)
{
    var row  = this.treeTable.insertRow(sort);
    var cell = row.insertCell(0);
    cell.innerHTML = nodeName;

    row.setAttribute("CODE", nodeCode);
    row.setAttribute("NAME", nodeName);
    row.setAttribute("SORT", sort);
    row.setAttribute("DEPTH", depth);
}




/*****************************************************************************/




var stringUtil     = null;  /** 문자열 관련 Util */
var popupUtil      = null;  /** 팝업 관련 Util */
var ajaxUtil       = null;  /** Ajax 관련 Util */
var webControlUtil = null;  /** WebControl 관련 Util */
var calendarUtil   = null;  /** Calendar Util */
var treeUtil       = null;  /** Tree Util */


/**
 * 모든 Util 의 Instance 를 생성함
 * 단, prototype 으로 상속했을시, 다시 호출해줘야 반영됨
 */
function initUtil()
{
    stringUtil     = new StringUtil();
    popupUtil      = new PopupUtil();
    ajaxUtil       = new AjaxUtil();
    webControlUtil = new WebControlUtil();
    calendarUtil   = new CalendarUtil();
    treeUtil       = new TreeUtil(); // 좌절 ㅡ_ㅡ; 유틸
}


/**
 * Create Instance
 */
initUtil();


<!---------------------------------------------------------------------------->
function f_nul_chk(obj,lbl)
{
	if( obj.value.replace(/^\s+|\s+$/g,"") == '' )
	{
		alert(lbl + ' 입력 하십시오.');
		obj.focus(); 
		return true;   
	}
	return false; 
}
<!---------------------------------------------------------------------------->
function f_com_chk(obj,lbl)
{
	if( obj.value == '' )
	{
		alert(lbl + ' 선택 하세요.');
		obj.focus(); 
		return true;   
	}
	return false; 
}
<!---------------------------------------------------------------------------->
function f_len_chk(obj, lbl, num)
{
	if( obj.value.length < num)
	{
		alert(lbl + ' '  + num + '문자 이상 입력하십시오.');
		obj.focus(); 
		return true;   
	}
	return false; 
}
<!---------------------------------------------------------------------------->
// 숫자 여부 체크
function f_is_int(obj,lbl)
{
		var nLen = obj.value.length; 
		for( i = 0 ; i < nLen ; i++)
		{
			temp = obj.value.substring(i,i+1);
			if( temp < '0' || temp > '9' )
			{
				
				alert( lbl + ' 숫자만 입력할 수 있습니다.' );
				obj.focus();
				return true;
				
			}     
		}
		return false;
}
<!---------------------------------------------------------------------------->

function f_is_num(obj, lbl)
	{
		var nLen = obj.value.length; 
		for( i = 0 ; i < nLen ; i++)
		{
			temp = obj.value.substring(i,i+1);
			if( temp < '0' || temp > '9' )
			{
				if ( temp != '.' )
				{
					alert( lbl + ' 숫자만 입력할 수 있습니다.' );
					obj.focus();
					return true;
				}
			}     
		}
		return false;
	}
<!---------------------------------------------------------------------------->
function f_byte_chk(obj, nByte, lbl)
{
	with(Math) {
		
		var nLength = obj.value.length;
		var nCnt = 0;
		var nHan, nTemp;

		
		// 한글 문자수 계산(버림)
		nHan  = nByte / 3;
		nTemp = round(nHan);

		if   (nHan != nTemp)
		nHan = nTemp - 1;

		for (i = 0; i < nLength; i++)
		{

			sTemp = escape(obj.value.substring(i, i+1));

			
			if(sTemp.substring(1,2) == "u" )
				nCnt += 3;
			else
				nCnt += 1;
		}
		
		if  (nCnt > nByte) 
		{
			alert(lbl + ' 한글 ' + nHan + ' 자, 영문 ' + nByte + ' 자 이내로 입력하십시오. ');
			obj.focus(); 
			return true;   
		} 
		return false;
	}
}   
<!---------------------------------------------------------------------------->

/**
 * 파일을 다운로드 한다
 */
function downloadClick2(attachIdd)
{
	downloadClick(attachIdd);
}