function setDateStr(a,b,c,d,e1) 
{
    //alert(document.all.calendarType);
    if(document.all.calendarType != undefined) {
        if(document.all.calendarType.value == 1) {
            eval("document.all."+e1).value = ""+a+"/"+b+"/"+c;
            eval("document.all."+d).style.display='none';            
        }
        else if(document.all.calendarType.value == 2) {
            eval("document.all."+e1).value = ""+a+"."+b+"."+c;
            eval("document.all."+d).style.display='none';            
        }        
    } else {
        eval("document.all."+e1).value = ""+a+""+b+""+c;
        eval("document.all."+d).style.display='none';
    }
}

//ÀÚ¹ÙÇÔ¼ö ¶óÀÌºê·¯¸®¿¡ Ãß°¡ÇßÀ¸¸é ÇÏ´Â ÇÔ¼ö´ú..
function user_lpad(str,fill,leng)
{
    var n = leng - str.length;
    var out ="";
    for (i =0; i < n; i++)  out = out + fill;
    out=out+str;
    return out;
}
//parseInt¿¡¼­´Â '08'À» 8Áø¼ö·Î ÀÎ½ÄÇØ¼­ 0ÀÌ³ª NaNÀ» µ¹·ÁÁØ´Ù
function toInt(str)
{
    i=0;
    while(1)
    {
        if( str.substr(0,1)=='0' && str.substr(1,2)=='0') {str=0;break;}
        else if(str.substr(0,1)=='0') {str=str.substr(1,str.length)};
        else break;
        i++;
    }
    return parseInt(str);
}

//var oPopup = window.createPopup();

// selectDate ÇöÀç³¯Â¥ , calDivObj´Þ·ÂÀ» »Ñ¸± DIVÅÂ±× ¾ÆÀÌµð, type ³¯Â¥°¡ ¼¼ÆÃµÉ Object Name, 
// WhereClick Àº ³»ºÎ¿¡¼­ Å¬¸¯À» Çß´ÂÁö ¿ÜºÎ¿¡¼­ Å¬¸¯À» Çß´ÂÁö 
function show_cal(selectDate,textCalDivObj,textSetObject,whereClick) 
{
    //Àü¿ªº¯¼öµé ¼¼ÆÃ
    var selectDate = ''+selectDate; //Àü¿ªº¯¼ö1 - ÀÌ½´°¡ µÇ´Â ³¯Â¥ ÁöÁ¤
    today = new Date();
    toDate = today.getYear() + user_lpad(''+(today.getMonth()+1),'0',2) + user_lpad(''+today.getDate(),'0',2); // ¿À´Ã³¯Â¥ ÁöÁ¤
    //alert(toDate);
    if (selectDate == '')
    {
        selectDate=toDate;
    }

    var preMonDate;
    var nextMonDate;

    //alert(user_lpad(''+(toInt(selectDate.substr(4,2))-1),'0',2));
    
    preMonDate= selectDate.substr(0,4)+user_lpad(''+(toInt(selectDate.substr(4,2))-1),'0',2)+selectDate.substr(6,2);
    nextMonDate= selectDate.substr(0,4)+user_lpad(''+(toInt(selectDate.substr(4,2))+1),'0',2)+selectDate.substr(6,2);
    //alert(selectDate+":"+ preMonDate +":"+ nextMonDate);
    if(selectDate.substr(4,2)=='01') preMonDate= (toInt(selectDate.substr(0,4))-1) + '12' + selectDate.substr(6,2);
    if(selectDate.substr(4,2)=='12') nextMonDate= (toInt(selectDate.substr(0,4))+1) + '01' + selectDate.substr(6,2);
    //alert(selectDate+":"+ preMonDate +":"+ nextMonDate);

    var firstDay = getFirstDay(selectDate.substr(0,4), selectDate.substr(4,2));            // Ã¹¹øÂ° ¿äÀÏÀÇ ¼ýÀÚ°ª        
    var lastDay = getLastDay(selectDate.substr(0,4), selectDate.substr(4,2));            // ¸¶Áö¸· ¿äÀÏÀÇ ¼ýÀÚ°ª
    var daysOfMonth = getDaysOfMonth(selectDate.substr(0,4), selectDate.substr(4,2));    // 28, 29, 30, 31 Áß ÇÏ³ª
    //alert(firstDay+":"+ lastDay +":"+ daysOfMonth);
    var calString;//´Þ·Â HTMLÀ» ÀúÀåÇÏ±â À§ÇÑ º¯¼ö´Ù.

    var thisDay2;

    calString='<div class="mb5" style="font-size:12px">';
    calString+="<a href=\"javascript:show_cal('"+ (parseInt(selectDate.substr(0,4))-1)+ selectDate.substr(4,4) +"','"+ textCalDivObj +"','"+ textSetObject +"','inner');\" style=\"text-decoration:none;\">¢¸¢¸</a>&nbsp;";
    calString+="<a href=\"javascript:show_cal('"+ preMonDate +"','"+ textCalDivObj +"','"+ textSetObject +"','inner');\"  style=\"text-decoration:none;\">¢¸</a>&nbsp;";
    calString+="<b><font color='#000000'>"+selectDate.substr(0,4)+"</font> / <font color='#FF6600'>"+selectDate.substr(4,2)+"</font></b>&nbsp;";
    calString+="<a href=\"javascript:show_cal('"+ nextMonDate +"','"+ textCalDivObj +"','"+ textSetObject +"','inner');\"  style=\"text-decoration:none;\">¢º</a>&nbsp;";
    calString+="<a href=\"javascript:show_cal('"+ (parseInt(selectDate.substr(0,4))+1)+ selectDate.substr(4,4) +"','"+ textCalDivObj +"','"+ textSetObject +"','inner');\"  style=\"text-decoration:none;\">¢º¢º</a>";
    calString+="</div>";
    calString+='<table cellspacing="0" cellpadding="0">';
    calString+="<td width='19' align=center style='color=#C60000'>ÀÏ</td>";
    calString+="<td width='19' align=center style='color=#000000'>¿ù</td>";
    calString+="<td width='19' align=center style='color=#000000'>È­</td>";
    calString+="<td width='19' align=center style='color=#000000'>¼ö</td>";
    calString+="<td width='19' align=center style='color=#000000'>¸ñ</td>";
    calString+="<td width='19' align=center style='color=#000000'>±Ý</td>";
    calString+="<td width='19' align=center style='color=#0000C6'>Åä</td>";
    calString+="</tr>";
    
    // ´Þ·Â textfield Ãâ·Â
    for (var i=0; i < Math.ceil( (firstDay+daysOfMonth)/7 ); i++) {
        calString+="<tr valign='middle' height='19'>";
        for (var j=1; j <= 7; j++) {         
            colNum=i*7+j; //´Þ·ÂÀÇ °¢ Ä­ÀÇ Ä®·³À» ¹øÈ£·Î ÁöÁ¤
            
            if (colNum>firstDay && colNum<firstDay+daysOfMonth+1) //´Þ·Â¿¡ ³¯Â¥°¡ ³ª¿Í¾ß µÇ´Â Á¶°Ç
            {
                thisDay=colNum-firstDay; //ÀÌ³¯ÀÇ ³¯Â¥(¼ýÀÚ)
                
                //¿äÀÏÀÇ »ö±òÀ» °áÁ¤ÇÏÀÚ ¤»¤»
                if(colNum%7==1) {tdColor="C60000";}
                else if(colNum%7==0) {tdColor="0000C6";}
                else {tdColor="000000";}
                
                if(thisDay < 10) thisDay2 = "0"+thisDay;
                else thisDay2 = thisDay;
                
                calString+="<td align='center' style='cursor: hand' onClick=\"setDateStr('"+selectDate.substr(0,4)+"','"+selectDate.substr(4,2)+"','"+ thisDay2+"','"+textCalDivObj+"','"+textSetObject+"');\" style='color=#"+tdColor+"'>"+thisDay+"</td>";
            }
            else
            {
                calString+="<td></td>";
            }
            //calString+="<td>"+colNum+"</td>";
        }
        calString+="</tr>";
    }
    calString+="</table>";

/*
var oPopBody = oPopup.document.body;
oPopBody.innerHTML = calString;
oPopBody.ClassName = 'showCalender';
oPopup.show(100, 100, 280, 125, oPopup.document.body);
*/

    //ÀúÀåµÈ ½ºÆ®¸µº¯¼ö¸¦ DIV·¹ÀÌ¾î¿¡ ¿Ã¸®ÀÚ.. 
    eval("document.all."+textCalDivObj).innerHTML=calString;

    if(whereClick == 'outer') {
        if(eval("document.all."+textCalDivObj).style.display == "") eval("document.all."+textCalDivObj).style.display = "none";
        else eval("document.all."+textCalDivObj).style.display="";
    } else {
        eval("document.all."+textCalDivObj).style.display="";
    }

}

/////////////////////////³¯Â¥ °ü·ÃµÈ ¿¬»ê ÇÔ¼öµé////////////////////////////
function getDaysOfMonth(year, month) { 
    var DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];        // Non-Leap year Month days.. 
    var lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];    // Leap year Month days.. 
    /* 
    Check for leap year .. 
    1.Years evenly divisible by four are normally leap years, except for... 
    2.Years also evenly divisible by 100 are not leap years, except for... 
    3.Years also evenly divisible by 400 are leap years. 
    */ 
    if ((year % 4) == 0) {
        if ((year % 100) == 0 && (year % 400) != 0)
            return DOMonth[toInt(month)-1];
     
        return lDOMonth[toInt(month)-1];
    } else 
        return DOMonth[toInt(month)-1];
} 

// Ã¹¹øÂ° ¿äÀÏ ±¸ÇÏ±â
function getFirstDay(year, month) {
    var tmpDate = new Date(); 
    tmpDate.setDate(1); 
    tmpDate.setMonth(toInt(month)-1); 
    tmpDate.setFullYear(year); 
    return tmpDate.getDay(); 
}

// ¸¶Áö¸· ¿äÀÏ ±¸ÇÏ±â
function getLastDay(year, month) {
    var tmpDate = new Date(); 
    tmpDate.setDate( getDaysOfMonth(year,month) ); 
    tmpDate.setMonth(toInt(month)-1); 
    tmpDate.setFullYear(year); 
    return tmpDate.getDay(); 
}
/////////////////////////³¯Â¥ °ü·ÃµÈ ¿¬»ê ÇÔ¼öµé////////////////////////////
