﻿<!--
/*
p_MonthCount :  1,2,3....   (def:1, 표시 개월수)
p_IsMultiSel : true/false   (def:false, 2개 선택 가능여부)
p_IsPrevSel : true/false    (def:false, 오늘이전 일자 선택가능 여부)
p_IsControlDate : true/false(def:true, 콘트롤에 선택된 날자를 기본일자로 사용)
p_Control1ID : ControlID    (def:'', 값을 적용할 콘트롤)
p_Control2ID : ControlID    (def:'', 값을 적용할 두번째 콘트롤)
*/
var CalLayer = {

    // 반환될 날자의 형식
    tmpDateFormat : "yyyy/mm/dd",
    
    // 달력이 열리는 시점의 현재시간
    tmpToday : (new Date()),
    
    // 달력표시 갯수
    tmpMonthCount : 1,
    
    // 첫번째 달력이 표시할 연도
    tmpStartYear : 2000,
    
    // 첫번쨰 달력이 표시할 월
    tmpStartMonth : 1,
    
    // 다중선택(2개) 허용여부
    tmpIsMultiSel : false,
    
    // 오늘 이전일자 선택가능여부
    tmpIsPrevSel : false,
    
    // 결과를 반환할 첫번째 콘트롤
    targetControl1ID : '',
    // 결과를 반환할 두번째 콘트롤
    targetControl2ID : '',
    
    // 첫번째 선택된 날자
    returnDate1 : '',
    // 두번째 선택된 날자
    returnDate2 : '',
    
    // 입력받은 첫번째 콘트롤의 날자
    tmpControlDate1 : (new Date()),
    // 입력받은 두번째 콘트롤의 날자
    tmpControlDate2 : (new Date()),
    
    Open : function(arg){

        var tmpback = document.getElementById("hdivCalBackLayer"); 
        
        if (arg['p_MonthCount'] != null && arg['p_MonthCount'] != '')
            this.tmpMonthCount = parseInt(arg['p_MonthCount']);
            
        if (arg['p_IsMultiSel'] != null)
            this.tmpIsMultiSel = arg['p_IsMultiSel'];
            
        if (arg['p_IsPrevSel'] != null)
            this.tmpIsPrevSel = arg['p_IsPrevSel'];
            
        if (arg['p_Control1ID'] != null && arg['p_Control1ID'] != '')
        {
            this.targetControl1ID = arg['p_Control1ID'].toString();
        }
        else {
            // 첫번째 콘트롤은 필수
            return;
        }
            
        if (arg['p_Control2ID'] != null && arg['p_Control2ID'] != '')
            this.targetControl2ID = arg['p_Control2ID'].toString();
            
            
        
        var tmpIsControlDate = true;
        if (arg['p_IsControlDate'] != null)
            tmpIsControlDate =  arg['p_IsControlDate'];
            
        var tmptargetControl1 = document.getElementById(this.targetControl1ID);
        
        // 첫번쨰 콘트롤이 없으면 열지 않는다.
        if (tmptargetControl1 == null)
            return;
        
        
        // 반활될 콘트롤의 현재 설정된 날자값을 사용할경우
        if (tmpIsControlDate) {
            this.tmpControlDate1 = new Date(tmptargetControl1.value.toString());
            
            this.tmpStartYear = this.tmpControlDate1.getFullYear();
            this.tmpStartMonth = this.tmpControlDate1.getMonth() + 1;
            
            if (this.tmpIsMultiSel)
                this.tmpControlDate2 = new Date(document.getElementById(this.targetControl2ID).value.toString());
        }
        else {
            this.tmpStartYear = this.tmpToday.getFullYear();
            this.tmpStartMonth = this.tmpToday.getMonth() + 1;
        }
 
        // 화면이 열리면 반활될 값을 초기화 한다
        this.returnDate1 = '';
        this.returnDate2 = '';
        
        // 최초 달력화면 생성
        tmpback.innerHTML = this.MakeCalendarBody();

        var tmpPostion = findPositionWithScrolling(tmptargetControl1);
		
		tmpback.style.left = tmpPostion[0] + 'px';
		tmpback.style.top = (tmpPostion[1] + tmptargetControl1.offsetHeight) + 'px';
		tmpback.style.display = 'block';		

        // 현재창이 부모창의 이벤트를 상속받지 않게 한다
        $addHandler(tmpback, "click", this.StopPropa);
        
        // 부모창(바탕)을 클릭하면 달력을 닫는다.
		$addHandler(tmpback.ownerDocument, "click", this.Close);
		
    },
    MakeCalendarBody : function()
    {
        var tmpTable = '<table border="0px" cellpadding="1px" cellspacing="1px"  bgcolor="#FFFFFF" style="z-index:2000;">';
        tmpTable = tmpTable + '<tr height="30px">';
        for (var i = 0; i < CalLayer.tmpMonthCount; i++) {
            var nowYMD = new Date(CalLayer.tmpStartYear, CalLayer.tmpStartMonth + i - 1, 1);
            tmpTable = tmpTable + '<td width="5px" rowspan="3">&nbsp;</td>';
            tmpTable = tmpTable + '<td width="20px" align="left" valign="middle">';
            
            // 이전달 이동버튼 표시(첫달력이고, 오늘이전 선택가능이거나 다음달을 표시하고 있는 경우 표시한다)
            if (i == 0
                && (CalLayer.tmpIsPrevSel || (parseInt(nowYMD.localeFormat('yyyyMM')) > parseInt(CalLayer.tmpToday.localeFormat('yyyyMM')))))
                tmpTable = tmpTable + '<a href="javascript:CalLayer.MovePrevMonth()"><img src="/Common/Images/calendar_arrow_left.gif" width="15" height="15"></a>';
            tmpTable = tmpTable + '</td>';
            tmpTable = tmpTable + '<td calss="calendarHeader"><strong>' + nowYMD.localeFormat('yyyy / MM') + '</strong></td>';
            tmpTable = tmpTable + '<td width="20px" align="right" valign="middle">';
            
            // 다음달 이동버튼 표시(끝달력일경우 무조건 표시한다)
            if (i == CalLayer.tmpMonthCount - 1)
                tmpTable = tmpTable + '<a href="javascript:CalLayer.MoveNextMonth()"><img src="/Common/Images/calendar_arrow_right.gif" width="15" height="15"></a>';
            tmpTable = tmpTable + '</td>';
            tmpTable = tmpTable + '<td width="5px" rowspan="3">&nbsp;</td>';
        }
        tmpTable = tmpTable + '</tr>';
        tmpTable = tmpTable + '<tr>';
        for (var i = 0; i < CalLayer.tmpMonthCount; i++) {
            tmpTable = tmpTable + '<td valign="top" colspan="3" style="padding-bottom:5px;">' + this.MakeCalendar(i) + '</td>';
        }
        tmpTable = tmpTable + '</tr>';
        tmpTable = tmpTable + '</table>';
        
        
        if (parseInt((new Date(CalLayer.tmpStartYear, CalLayer.tmpStartMonth - 1, 1)).localeFormat('yyyyMM')) != parseInt(CalLayer.tmpToday.localeFormat('yyyyMM'))) {
        
            // 하단 기타설정 부분
            tmpTable = tmpTable + '<table width="100%" border="0px" cellpadding="1px" cellspacing="1px" bgcolor="#EEF3FA" style="border:1px solid #C2D4E2;">';
            tmpTable = tmpTable + '<tr height=30px">';
            tmpTable = tmpTable + '<td width="100%" align="center"><a href="javascript:CalLayer.MoveToday();"><strong>Move the current month</strong></a></td>';
            tmpTable = tmpTable + '</tr>';
            tmpTable = tmpTable + '</table>';
        }
        
        return tmpTable;
    },
    MakeCalendar : function(arg)
    {
      
        var tmpTable = "";
        
        var startDate = new Date(CalLayer.tmpStartYear, CalLayer.tmpStartMonth + arg - 1, 1);
        var lastDate = new Date(CalLayer.tmpStartYear, CalLayer.tmpStartMonth + arg, 0);
        
        var tmpX = -startDate.getDay();
        var tmpY = lastDate.getDate();
        
        var tmpRowCnt = (tmpY - tmpX) / 7;
        
        var tmpTodayInt = parseInt(CalLayer.tmpToday.localeFormat('yyyyMMdd'));
        var tmpStartDateInt = parseInt(startDate.localeFormat('yyyyMMdd'));
        
        tmpTable = tmpTable + '<table border="0px" cellpadding="1px" cellspacing="1px">';
        tmpTable = tmpTable + '<tr height="21px">';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay" style="color:#FF0000;"><strong>S</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>M</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>T</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>W</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>T</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>F</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay" style="color:#0000FF;"><strong>S</strong></td>';
        tmpTable = tmpTable + '</tr>';
        for (var i = 0; i < tmpRowCnt; i++) {
            tmpTable = tmpTable + '<tr height="21px">';
            for (var j = 0; j < 7; j++) {
            
                var tmpStyle = '';
                var tmpText = '';
                var tmpIsYesterday = false;
            
                if (tmpX >= 0 && tmpX < tmpY) {
                
                    startDate.setDate(tmpX+1);
                    tmpStartDateInt = parseInt(startDate.localeFormat('yyyyMMdd'));
                    
                    if (tmpStartDateInt < tmpTodayInt)
                        tmpIsYesterday = true;
                        
                    
                    
                    if (startDate.getDay() == 6)     // 토요일표시
                        tmpText = '<strong><font color="#0000FF">' + (tmpX + 1).toString() + '</font></strong>';
                    else if (startDate.getDay() == 0) // 호텔국가별공휴일
                        tmpText = '<strong><font color="#FF0000">' + (tmpX + 1).toString() + '</font></strong>';
                    else 
                        tmpText = (tmpX + 1).toString();
                        
                    if (CalLayer.tmpIsPrevSel || !tmpIsYesterday) {
                        tmpText = '<a href="javascript:CalLayer.SelectDate(\'' + startDate.localeFormat('yyyy/MM/dd') + '\')">' + tmpText + '</a>';
                    }

                        
                    if (!CalLayer.tmpIsPrevSel && tmpIsYesterday) {
                        tmpTable = tmpTable + '<td align="center" valign="middle" class="calendarPrevDay">' + tmpText + '</td>';
                    }
                    else {
                        if (CalLayer.tmpIsMultiSel && parseInt(CalLayer.tmpControlDate2.localeFormat('yyyyMMdd')) == tmpStartDateInt) {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay" bgColor="#9ECCC7">' + tmpText + '</td>';
                        }
                        else if (parseInt(CalLayer.tmpControlDate1.localeFormat('yyyyMMdd')) == tmpStartDateInt) {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay" bgColor="#B3D7B0">' + tmpText + '</td>';
                        }
                        else {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay">' + tmpText + '</td>';
                        }
                    }
                }
                else {
                    tmpTable = tmpTable + '<td align="center" valign="middle" class="calendarDay"></td>';
                }
                
                tmpX++;
            }
            tmpTable = tmpTable + '</tr>';
        }
        tmpTable = tmpTable + '</table>';
        
        return tmpTable;
    },
    MoveNextMonth : function() {
    
        // 현재 첫번쨰 달력의 다음달로 이동한다.
    
        if (CalLayer.tmpStartMonth > 11) {
            CalLayer.tmpStartYear = CalLayer.tmpStartYear + 1;
            CalLayer.tmpStartMonth = CalLayer.tmpStartMonth - 11;
        }
        else {
            CalLayer.tmpStartMonth = CalLayer.tmpStartMonth + 1;
        }
        
        document.getElementById("hdivCalBackLayer").innerHTML = CalLayer.MakeCalendarBody();
    },
    MovePrevMonth : function() {
    
        // 현재 첫번째 달력의 이전달로 이동한다.
    
        if (CalLayer.tmpStartMonth == 1) {
            CalLayer.tmpStartYear = CalLayer.tmpStartYear - 1;
            CalLayer.tmpStartMonth = 12;
        }
        else {
            CalLayer.tmpStartMonth = CalLayer.tmpStartMonth - 1;
        }
        
        document.getElementById("hdivCalBackLayer").innerHTML = CalLayer.MakeCalendarBody();
    },
    MoveToday : function() {
    
        // 오늘날자로 이동한다.
    
        CalLayer.tmpStartYear = CalLayer.tmpToday.getFullYear();
        CalLayer.tmpStartMonth = CalLayer.tmpToday.getMonth() + 1;
        
        document.getElementById("hdivCalBackLayer").innerHTML = CalLayer.MakeCalendarBody();
    },
    SelectDate : function(arg) {
    
        var tmpDate = new Date(arg.toString());
        
        // 첫번째 반환용 날자가 비었으면 첫번째 날자를 설정하고 배경색을 바꿔준다.
        // 첫번째가 값이 있고, 다중선택 허용이면 두번째 날자를 설정하고 배경색을 바꿔준다.
        if (CalLayer.returnDate1 == '')
        {
            var tmpCalCell = document.getElementById('CalCell' + CalLayer.tmpControlDate1.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#FFFFFF";
            
            CalLayer.returnDate1 = arg.toString();
            CalLayer.tmpControlDate1 = tmpDate;
            
            tmpCalCell = document.getElementById('CalCell' + CalLayer.tmpControlDate1.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#B3D7B0";
        }
        else if (CalLayer.tmpIsMultiSel)
        {
            if (parseInt(CalLayer.tmpControlDate1.localeFormat('yyyyMMdd')) >= parseInt(tmpDate.localeFormat('yyyyMMdd')))
                return;
                
            var tmpCalCell = document.getElementById('CalCell' + CalLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#FFFFFF";

            CalLayer.returnDate2 = arg.toString();
            CalLayer.tmpControlDate2 = tmpDate;
            
            tmpCalCell = document.getElementById('CalCell' + CalLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#9ECCC7";
                
        }
        
        // 선택된 값이 확인 되었으면 반환함수 실행
        if ((CalLayer.tmpIsMultiSel && CalLayer.returnDate1 != '' && CalLayer.returnDate2 != '')
            || (!CalLayer.tmpIsMultiSel && CalLayer.returnDate1 != ''))
        {
            CalLayer.ReturnDate();
        }
    
        
    },
    ReturnDate : function() {
    
        var tmpControl1 = document.getElementById(CalLayer.targetControl1ID);
        var tmpControl2 = document.getElementById(CalLayer.targetControl2ID);
    
        // 첫번째 선택된 날자가 있으면 첫번째 콘트롤에 값 설정
        if (CalLayer.targetControl1ID != '' && tmpControl1 != null)
            tmpControl1.value = CalLayer.returnDate1;
        
        // 다중선택이고 두번째 선택된 날자가 있으면 두번째 콘트롤에 값 설정
        if (CalLayer.tmpIsMultiSel && CalLayer.targetControl2ID != '' && tmpControl2 != null)
            tmpControl2.value = CalLayer.returnDate2;
        
        // 이벤트가 있을경우 발생시키기 위해 여기서 강제로 발생시킴
        if (CalLayer.tmpIsMultiSel && tmpControl2 != null && tmpControl2.getAttribute('onchange') != null)
            tmpControl2.onchange();
        else if (tmpControl1.getAttribute('onchange') != null)
            tmpControl1.onchange();
            
        //
        CalLayer.Close();
    },
    StopPropa : function(event) {
        // 부모폼의 이벤트를 상속받지 않게 함
        event.stopPropagation();
    },
    Close : function()
	{	    
	    var tmpback = document.getElementById("hdivCalBackLayer");
	
	    // 백레이어 가림
	    tmpback.style.display = "none";
	    // 백레이어안의 카렌다 테이블 제거
	    tmpback.innerHTML = "";
		
		// 클릭이벤트 자식폼으로 프로파게이션방지를 위한 이벤트 제거
		$removeHandler(tmpback, "click", CalLayer.StopPropa);
		// 바탕화면 클릭시 카렌타 사라지는 이벤트 제거
	    $removeHandler(tmpback.ownerDocument, "click", CalLayer.Close);
	}
}




var ChkInOutLayer = {

    // 반환될 날자의 형식
    tmpDateFormat : "yyyy/mm/dd",
    
    // 달력이 열리는 시점의 현재시간
    tmpToday : (new Date()),
    
    // 1:CheckIn, 2:CheckOut
    tmpSelectKind : "1",
    
    // 0:Normal, 1:Strong
    tmpSelectButton : "0",
    
    // 첫번째 달력이 표시할 연도
    tmpStartYear : 2000,
    
    // 첫번쨰 달력이 표시할 월
    tmpStartMonth : 1,
   
    // 결과를 반환할 첫번째 콘트롤
    targetControl1ID : '',
    // 결과를 반환할 두번째 콘트롤
    targetControl2ID : '',
    
    // 첫번째 선택된 날자
    returnDate1 : '',
    // 두번째 선택된 날자
    returnDate2 : '',
    
    // 입력받은 첫번째 콘트롤의 날자
    tmpControlDate1 : (new Date()),
    // 입력받은 두번째 콘트롤의 날자
    tmpControlDate2 : (new Date()),
    
    Open : function(arg){

        var tmpback = document.getElementById("hdivCalBackLayer"); 
        
            
        if (arg['p_Control1ID'] != null && arg['p_Control1ID'] != '')
            this.targetControl1ID = arg['p_Control1ID'].toString();
        else
            return;
            
        if (arg['p_Control2ID'] != null && arg['p_Control2ID'] != '')
            this.targetControl2ID = arg['p_Control2ID'].toString();
        else
            return;
            
            
        this.tmpSelectKind = "1";
            
        this.tmpSelectButton = "0";
            
            
        var tmptargetControl1 = document.getElementById(this.targetControl1ID);
        
        // 첫번쨰 콘트롤이 없으면 열지 않는다.
        if (tmptargetControl1 == null)
            return;
            
        this.tmpControlDate1 = new Date(tmptargetControl1.value.toString());
        
        this.tmpStartYear = this.tmpControlDate1.getFullYear();
        this.tmpStartMonth = this.tmpControlDate1.getMonth() + 1;
        
        this.tmpControlDate2 = new Date(document.getElementById(this.targetControl2ID).value.toString());
        
        
 
        // 화면이 열리면 반활될 값을 입력받은 콘트롤 값으로 설정한다
        this.returnDate1 = this.tmpControlDate1.localeFormat('yyyy/MM/dd');
        this.returnDate2 = this.tmpControlDate2.localeFormat('yyyy/MM/dd');
        
        // 최초 달력화면 생성
        tmpback.innerHTML = this.MakeCalendarBody();

        var tmpPostion = findPositionWithScrolling(tmptargetControl1);
		
		tmpback.style.left = tmpPostion[0] + 'px';
		tmpback.style.top = (tmpPostion[1] + tmptargetControl1.offsetHeight) + 'px';
		tmpback.style.display = 'block';		

        // 현재창이 부모창의 이벤트를 상속받지 않게 한다
        $addHandler(tmpback, "click", this.StopPropa);
        
        // 부모창(바탕)을 클릭하면 달력을 닫는다.
		$addHandler(tmpback.ownerDocument, "click", this.Close);
		
    },
    MakeCalendarBody : function()
    {
        var tmpTable = '<table border="0px" cellpadding="1px" cellspacing="1px"  bgcolor="#FFFFFF" style="z-index:2000;">';
        tmpTable = tmpTable + '<tr height="30px">';
        for (var i = 0; i < 3; i++) {
            var nowYMD = new Date(ChkInOutLayer.tmpStartYear, ChkInOutLayer.tmpStartMonth + i - 1, 1);
            tmpTable = tmpTable + '<td width="5px" rowspan="3">&nbsp;</td>';
            tmpTable = tmpTable + '<td width="20px" align="left" valign="middle">';
            
            // 이전달 이동버튼 표시(첫번째달력이 이번달 이후인 경우 표시한다)
            if (i == 0 && ((parseInt(nowYMD.localeFormat('yyyyMM')) > parseInt(ChkInOutLayer.tmpToday.localeFormat('yyyyMM')))))
                tmpTable = tmpTable + '<a href="javascript:ChkInOutLayer.MovePrevMonth()"><img src="/Common/Images/calendar_arrow_left.gif" width="15" height="15"></a>';
            tmpTable = tmpTable + '</td>';
            tmpTable = tmpTable + '<td calss="calendarHeader"><strong>' + nowYMD.localeFormat('yyyy / MM') + '</strong></td>';
            tmpTable = tmpTable + '<td width="20px" align="right" valign="middle">';
            
            // 다음달 이동버튼 표시(끝달력일경우 무조건 표시한다)
            if (i == 2)
                tmpTable = tmpTable + '<a href="javascript:ChkInOutLayer.MoveNextMonth()"><img src="/Common/Images/calendar_arrow_right.gif" width="15" height="15"></a>';
            tmpTable = tmpTable + '</td>';
            tmpTable = tmpTable + '<td width="5px" rowspan="3">&nbsp;</td>';
        }
        tmpTable = tmpTable + '</tr>';
        tmpTable = tmpTable + '<tr>';
        for (var i = 0; i < 3; i++) {
            tmpTable = tmpTable + '<td valign="top" colspan="3" style="padding-bottom:5px;">' + this.MakeCalendar(i) + '</td>';
        }
        tmpTable = tmpTable + '</tr>';
        tmpTable = tmpTable + '</table>';
        
        // 하단 기타설정 부분
        tmpTable = tmpTable + '<table border="0px" cellpadding="1px" cellspacing="1px" bgcolor="#EEF3FA" style="border:1px solid #C2D4E2;">';
        tmpTable = tmpTable + '<tr height=30px">';
        tmpTable = tmpTable + '<td width=5px"></td>';
        
        if (ChkInOutLayer.tmpSelectKind == "1") {
            tmpTable = tmpTable + '<td id="tdChkIn" width="190px" align="center" valign="middle" style="font-weight:bold; color:#0000FF;"><input type="radio" name="radSelectType" ID="radSelectType" value="1" onclick="ChkInOutLayer.SelectRadio(this.value)" checked>';
            tmpTable = tmpTable + ' Check In : <input type="text" maxlength="10" ID="txtSelChkInYmd" value="' + ChkInOutLayer.tmpControlDate1.localeFormat('yyyy/MM/dd') + '" class="inputCenter" readonly="true" style="width:80px; font-weight:bold;"></td>';
            tmpTable = tmpTable + '<td id="tdChkOut" name="tdChkOut" width="190px" align="center" valign="middle"><input type="radio" name="radSelectType" ID="radSelectType" value="2" onclick="ChkInOutLayer.SelectRadio(this.value)">';
            tmpTable = tmpTable + 'Check Out : <input type="text" maxlength="10" ID="txtSelChkOutYmd" value="' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyy/MM/dd') + '" class="inputCenter" readonly="true" style="width:80px; font-weight:bold;"></td>';
        }
        else {
            tmpTable = tmpTable + '<td id="tdChkIn" width="190px" align="center" valign="middle"><input type="radio" name="radSelectType" ID="radSelectType" value="1" onclick="ChkInOutLayer.SelectRadio(this.value)">';
            tmpTable = tmpTable + ' Check In : <input type="text" maxlength="10" ID="txtSelChkInYmd" value="' + ChkInOutLayer.tmpControlDate1.localeFormat('yyyy/MM/dd') + '" class="inputCenter" readonly="true" style="width:80px; font-weight:bold;"></td>';
            tmpTable = tmpTable + '<td id="tdChkOut" width="190px" align="center" valign="middle" style="font-weight:bold; color:#0000FF;"><input type="radio" name="radSelectType" ID="radSelectType" value="2" onclick="ChkInOutLayer.SelectRadio(this.value)" checked>';
            tmpTable = tmpTable + 'Check Out : <input type="text" maxlength="10" ID="txtSelChkOutYmd" value="' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyy/MM/dd') + '" class="inputCenter" readonly="true" style="width:80px; font-weight:bold;"></td>';
        }
        tmpTable = tmpTable + '<td width="170px" align="center">';
        
        tmpTable = tmpTable + '<table width="160px" border="0px" cellpadding="0px" cellspacing="0px">';
            tmpTable = tmpTable + '<tr height="23px">';
        if (ChkInOutLayer.tmpSelectButton == "1") {            
            tmpTable = tmpTable + '<td id="tdSelectButton" width="75px" align="center" style="border-right:1px solid #888888;border-bottom:1px solid #888888;background-color:#FF9999;" onmouseover="ChkInOutLayer.MouseButtonEvent(this, true)" onmouseout="ChkInOutLayer.MouseButtonEvent(this, false)"><a href="javascript:ChkInOutLayer.ReturnDate();" style="color:#0000FF;"><strong>SELECT</strong></a></td>';
        }
        else {
            tmpTable = tmpTable + '<td id="tdSelectButton" width="75px" align="center" style="border-right:1px solid #888888;border-bottom:1px solid #888888;background-color:#FFFFFF;" onmouseover="ChkInOutLayer.MouseButtonEvent(this, true)" onmouseout="ChkInOutLayer.MouseButtonEvent(this, false)"><a href="javascript:ChkInOutLayer.ReturnDate();" style="color:#0000FF;"><strong>SELECT</strong></a></td>';           
        }
        tmpTable = tmpTable + '<td width="10px" align="center">&nbsp;</td>';
        tmpTable = tmpTable + '<td width="75px" align="center" style="border-right:1px solid #888888;border-bottom:1px solid #888888;background-color:#FFFFFF;" onmouseover="ChkInOutLayer.MouseButtonEvent(this, true)" onmouseout="ChkInOutLayer.MouseButtonEvent(this, false)"><a href="javascript:ChkInOutLayer.Close();" style="color:#FF0000;"><strong>CLOSE</strong></a></td>';
        tmpTable = tmpTable + '</tr></table>';
            
        tmpTable = tmpTable + '</td></tr>';
        tmpTable = tmpTable + '</table>';
        
        return tmpTable;
    },
    MakeCalendar : function(arg)
    {
      
        var tmpTable = "";
        
        var startDate = new Date(ChkInOutLayer.tmpStartYear, ChkInOutLayer.tmpStartMonth + arg - 1, 1);
        var lastDate = new Date(ChkInOutLayer.tmpStartYear, ChkInOutLayer.tmpStartMonth + arg, 0);
        
        var tmpX = -startDate.getDay();
        var tmpY = lastDate.getDate();
        
        var tmpRowCnt = (tmpY - tmpX) / 7;
        
        var tmpTodayInt = parseInt(ChkInOutLayer.tmpToday.localeFormat('yyyyMMdd'));
        var tmpStartDateInt = parseInt(startDate.localeFormat('yyyyMMdd'));
        
        tmpTable = tmpTable + '<table border="0px" cellpadding="1px" cellspacing="1px">';
        tmpTable = tmpTable + '<tr height="21px">';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay" style="color:#FF0000;"><strong>S</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>M</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>T</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>W</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>T</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay"><strong>F</strong></td>';
        tmpTable = tmpTable + '<td width="19px" align="center" valign="middle" class="calendarWeekDay" style="color:#0000FF;"><strong>S</strong></td>';
        tmpTable = tmpTable + '</tr>';
        for (var i = 0; i < tmpRowCnt; i++) {
            tmpTable = tmpTable + '<tr height="21px">';
            for (var j = 0; j < 7; j++) {
            
                var tmpStyle = '';
                var tmpText = '';
                var tmpIsYesterday = false;
            
                if (tmpX >= 0 && tmpX < tmpY) {
                
                    startDate.setDate(tmpX+1);
                    tmpStartDateInt = parseInt(startDate.localeFormat('yyyyMMdd'));
                    
                    if (tmpStartDateInt < tmpTodayInt)
                        tmpIsYesterday = true;                       
                    
                    
                    if (startDate.getDay() == 6)     // 토요일표시
                        tmpText = '<strong><font color="#0000FF">' + (tmpX + 1).toString() + '</font></strong>';
                    else if (startDate.getDay() == 0) // 호텔국가별공휴일
                        tmpText = '<strong><font color="#FF0000">' + (tmpX + 1).toString() + '</font></strong>';
                    else 
                        tmpText = (tmpX + 1).toString();
                        
                    if (!tmpIsYesterday) {
                        tmpText = '<a href="javascript:ChkInOutLayer.SelectDate(\'' + startDate.localeFormat('yyyy/MM/dd') + '\')">' + tmpText + '</a>';
                    }

                        
                    if (tmpIsYesterday) {
                        tmpTable = tmpTable + '<td align="center" valign="middle" class="calendarPrevDay">' + tmpText + '</td>';
                    }
                    else {
                        if (parseInt(ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd')) == tmpStartDateInt) {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay" bgColor="#9ECCC7">' + tmpText + '</td>';
                        }
                        else if (parseInt(ChkInOutLayer.tmpControlDate1.localeFormat('yyyyMMdd')) == tmpStartDateInt) {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay" bgColor="#B3D7B0">' + tmpText + '</td>';
                        }
                        else {
                            tmpTable = tmpTable + '<td id="CalCell' + startDate.localeFormat('yyyyMMdd') + '" align="center" valign="middle" class="calendarDay">' + tmpText + '</td>';
                        }
                    }
                }
                else
                {
                    tmpTable = tmpTable + '<td align="center" valign="middle" class="calendarDay"></td>';
                }
                
                tmpX++;
            }
            tmpTable = tmpTable + '</tr>';
        }
        tmpTable = tmpTable + '</table>';
        
        return tmpTable;
    },
    MoveNextMonth : function() {
    
        
    
        // 현재 첫번쨰 달력의 다음달로 이동한다.
    
        if (ChkInOutLayer.tmpStartMonth > 11) {
            ChkInOutLayer.tmpStartYear = ChkInOutLayer.tmpStartYear + 1;
            ChkInOutLayer.tmpStartMonth = ChkInOutLayer.tmpStartMonth - 11;
        }
        else {
            ChkInOutLayer.tmpStartMonth = ChkInOutLayer.tmpStartMonth + 1;
        }
        
        document.getElementById("hdivCalBackLayer").innerHTML = ChkInOutLayer.MakeCalendarBody();
    },
    MovePrevMonth : function() {
       
        // 현재 첫번째 달력의 이전달로 이동한다.
    
        if (ChkInOutLayer.tmpStartMonth == 1) {
            ChkInOutLayer.tmpStartYear = ChkInOutLayer.tmpStartYear - 1;
            ChkInOutLayer.tmpStartMonth = 12;
        }
        else {
            ChkInOutLayer.tmpStartMonth = ChkInOutLayer.tmpStartMonth - 1;
        }
        
        document.getElementById("hdivCalBackLayer").innerHTML = ChkInOutLayer.MakeCalendarBody();
    },
    MouseButtonEvent : function(arg1, arg2) {
        if (arg2)
            arg1.style.backgroundColor = "#D9EFB9";
        else if (arg1 == document.getElementById("tdSelectButton") && ChkInOutLayer.tmpSelectButton == "1")
            arg1.style.backgroundColor = "#FF9999";
        else
            arg1.style.backgroundColor = "#FFFFFF";
    },
    SelectRadio : function(arg) {
    
        ChkInOutLayer.tmpSelectKind = arg;
        
        if (arg == "1")
        {
            var tmpChkIn = document.getElementById('tdChkIn');
            tmpChkIn.style.fontWeight = "bold";
            tmpChkIn.style.color = "#0000FF";
            
            var tmpChkOut = document.getElementById('tdChkOut');
            tmpChkOut.style.fontWeight = "normal";
            tmpChkOut.style.color = "";
            
        }
        else {
            var tmpChkIn = document.getElementById('tdChkIn');
            tmpChkIn.style.fontWeight = "normal";
            tmpChkIn.style.color = "";
            
            var tmpChkOut = document.getElementById('tdChkOut');
            tmpChkOut.style.fontWeight = "bold";
            tmpChkOut.style.color = "#0000FF";
            
        }
    },
    SelectDate : function(arg) {
    
        var tmpDate = new Date(arg.toString());
        
        var tmpRadio = document.getElementsByName('radSelectType');
        
        // 현재 선택이 체크인이면 
        // 첫번째가 값이 있고, 다중선택 허용이면 두번째 날자를 설정하고 배경색을 바꿔준다.
        if (GetRadioValue(tmpRadio) == '1')
        {
       
            var tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate1.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#FFFFFF";
            
            ChkInOutLayer.returnDate1 = arg.toString();
            ChkInOutLayer.tmpControlDate1 = tmpDate;
            
            document.getElementById('txtSelChkInYmd').value = ChkInOutLayer.tmpControlDate1.localeFormat('yyyy/MM/dd');
            
            tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate1.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#B3D7B0";
                
            if (parseInt(ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd')) <= parseInt(tmpDate.localeFormat('yyyyMMdd')))
            {
                if (parseInt(ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd')) < parseInt(tmpDate.localeFormat('yyyyMMdd')))
                {
                    tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
                    if (tmpCalCell != null)
                        tmpCalCell.bgColor = "#FFFFFF";
                }
                    
                tmpDate = new Date(tmpDate.localeFormat('yyyy/MM/') + (parseInt(tmpDate.localeFormat('dd')) + 1).toString());

                ChkInOutLayer.returnDate2 = tmpDate.localeFormat('yyyy/MM/dd');
                ChkInOutLayer.tmpControlDate2 = tmpDate;
                
                document.getElementById('txtSelChkOutYmd').value = ChkInOutLayer.tmpControlDate2.localeFormat('yyyy/MM/dd');
                
                tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
                if (tmpCalCell != null)
                    tmpCalCell.bgColor = "#9ECCC7";
            }
            
            // 체크인 선택후 자동으로 체크아웃을 선택해 준다
            for (var i = 0; i < tmpRadio.length; i++) {
                if (tmpRadio[i].value == "2") {
                    tmpRadio[i].checked = 'checked';
                    ChkInOutLayer.SelectRadio('2');
                    return;
                }
            }
            

        }
        else
        {
            if (parseInt(ChkInOutLayer.tmpControlDate1.localeFormat('yyyyMMdd')) >= parseInt(tmpDate.localeFormat('yyyyMMdd')))
                return;
                
            var tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#FFFFFF";

            ChkInOutLayer.returnDate2 = arg.toString();
            ChkInOutLayer.tmpControlDate2 = tmpDate;
            
            document.getElementById('txtSelChkOutYmd').value = ChkInOutLayer.tmpControlDate2.localeFormat('yyyy/MM/dd');
            
            tmpCalCell = document.getElementById('CalCell' + ChkInOutLayer.tmpControlDate2.localeFormat('yyyyMMdd'));
            if (tmpCalCell != null)
                tmpCalCell.bgColor = "#9ECCC7";
                
                
            // 선택버튼을 강조하기 위해 값을 1로 바꿔준다.
            // 달력이동이 있을경우 화면을 새로 그려주기 때문에 값을 설정한다.
            ChkInOutLayer.tmpSelectButton = "1";
            
            document.getElementById("tdSelectButton").style.backgroundColor = "#FF9999";
                
        }
    },
    ReturnDate : function() {
    
        var tmpControl1 = document.getElementById(ChkInOutLayer.targetControl1ID);
        var tmpControl2 = document.getElementById(ChkInOutLayer.targetControl2ID);
    
        // 첫번째 선택된 날자가 있으면 첫번째 콘트롤에 값 설정
        if (tmpControl1 != null)
            tmpControl1.value = ChkInOutLayer.returnDate1;
        
        // 다중선택이고 두번째 선택된 날자가 있으면 두번째 콘트롤에 값 설정
        if (tmpControl2 != null)
            tmpControl2.value = ChkInOutLayer.returnDate2;
        
        // 이벤트가 있을경우 발생시키기 위해 여기서 강제로 발생시킴
        if (tmpControl2 != null && tmpControl2.getAttribute('onchange') != null)
            tmpControl2.onchange();
        else if (tmpControl1.getAttribute('onchange') != null)
            tmpControl1.onchange();
            
        //
        ChkInOutLayer.Close();
    },
    StopPropa : function(event) {
        // 부모폼의 이벤트를 상속받지 않게 함
        event.stopPropagation();
    },
    Close : function()
	{	    
	    var tmpback = document.getElementById("hdivCalBackLayer");
	
	    // 백레이어 가림
	    tmpback.style.display = "none";
	    // 백레이어안의 카렌다 테이블 제거
	    tmpback.innerHTML = "";
		
		// 클릭이벤트 자식폼으로 프로파게이션방지를 위한 이벤트 제거
		$removeHandler(tmpback, "click", ChkInOutLayer.StopPropa);
		// 바탕화면 클릭시 카렌타 사라지는 이벤트 제거
	    $removeHandler(tmpback.ownerDocument, "click", ChkInOutLayer.Close);
	}
}


//-->

