/**
 * klao_calendar¸¦ º¸¿©ÁÖ°í ¼±ÅÃÇÑ Date¿¡ ´ëÇÑ Formatting °á°ú¸¦ window.openerÀÇ returnObject¿¡°Ô ¹ÝÈ¯ÇÔ
 *
 * @author      <A Href="http://nst.co.kr">New Soft Techniques,Co.,Ltd.,ES Team</A>
 * @author      A Href="mailto:funnyna@nst.co.kr">funnyna</A>
 * @version     1.2
 * @since       Samsung EIP 1.0
 *
 * History
 * 1.0  2001-10-19  °­¼±Èñ          (»ï¼ºÈ­Àç EIP)
 * 1.1  2002-05-17  ±è¿µ¿ì          »ï¼ºÈ­Àç À¶ÀÚ½Ã½ºÅÛ
 * 1.2  2003-01-20  funnyna(³ªÁöÇý) ¹ö½º°øÁ¦ ½Å½Ã½ºÅÛ Initial Version
 *                  eora(À¯»ó±Ù)    ¹ö½º°øÁ¦ ½Å½Ã½ºÅÛ Initial Version
 */

var DATE_ONCLICK_FUNCTION = "window.opener.returnDate";

// --------------------------------------------------------------------------
//  Style Setting
//  ÇØ´ç ColorÅæ¿¡ ¸Â°Ô º¯°æ
// --------------------------------------------------------------------------
var FONT_SIZE_TITLE_HEADER  = "25pt";
var FONTCOLOR_TITLE_HEADER  = "#003399";

var FONT_SIZE_TITLE     = "9pt";
var FONTCOLOR_TITLE     = "#000000";

var BGCOLOR_CALENDAR    = "#F5F8F5";
var NORMAL_FONT         = "#F5F8F5";

var BGCOLOR_WEEK_END    = "#FFFFFF";
var BGCOLOR_NOMAL_DAY   = "#FFFFFF";

var BGCOLOR_TODAY       = "#F5F8F5";
var FONTCOLOR_TODAY     = "#000099";

var FONT_FACE           = "±¼¸²";
var FONT_SIZE           = "9pt";

var HEADER_FONT_SIZE    = "9pt";
var BGCOLOR_HEADER      = "#FFFFFF";
var FONTCOLOR_HEADER    = "#F2931E";
var FONTCOLOR_SUNDAY    = "#F2931E";
var FONTCOLOR_SATDAY    = "#0092B7";

var FONTCOLOR_NEXTMONTH = "#d5d5d5";
var FONT_SIZE_NEXTMONTH = "9pt";
// ==================================================

// ---------------------------------------------------
//  Àü¿ªº¯¼ö
// isYearlyMonth = trueÀÏ °æ¿ì, ÇØ´ç¿ùÀÇ ºó Day¿¡ ´ÙÀ½¿ùÀÇ ³¯Â¥¸¦ Ã¤¿ö³ÖÀ½
//
var WEEK_END = [0,6];
var TODAY = new Date();
var isYearlyMonth = false;
var openWinControl = self;
var curMonthTitle=null;
// ---------------------------------------------------

// ================================================================================================================
// Definication Calendar Obj
// (Âü°í 1) Calendar Object¿¡ ´ëÇÑ property ¼³Á¤ ºÎºÐÀÌ¹Ç·Î,
//          ÀÌ¿¡ ´ëÇÑ º¯°æÀ» ±ÝÇÕ´Ï´Ù..
Calendar.Months     = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
Calendar.ShortMonths= [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ];
// ÀÏ¹ÝÀûÀÎ ³âÀÇ ¿ùº° ÀÏÀÚ ¼ö
Calendar.DOMonth    = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
// ¿î³âÀÎ ³âÀÇ ¿ùº° ÀÏÀÚ ¼ö
Calendar.lDOMonth   = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];


function Calendar( returnObject, curWinCtl, curMonth, curYear, dateFormat )
{
    if ( ( curMonth == null ) && ( curYear == null ) )  return;

    if ( curWinCtl == null )
    {
        this.cal_WinControl = openWinControl;
    }
    else
    {
        this.cal_WinControl = curWinCtl;
    }

    if ( curMonth == null )
    {
        this.cal_MonthName  = null;
        this.cal_Month      = null;
    }
    else
    {
        this.cal_MonthName  = Calendar.getMonthName( curMonth );
        this.cal_Month      = new Number( curMonth );
    }

    this.cal_Year           = curYear;
    this.cal_DateFormat     = dateFormat;
    this.cal_ReturnObject   = returnObject;
}

// ------------------------- Definication a Properties -------------------------------------
Calendar.getMonthName = Calendar_getMonthName;
Calendar.getShordMonthName = Calendar_getShordMonthName;
Calendar.getDaysofMonth = Calendar_getDaysofMonth;
Calendar.getMonthPos= Calendar_getMonthPos;

function Calendar_getMonthName( indexofMonth )
{
    return Calendar.Months[ indexofMonth ];
}

function Calendar_getShordMonthName( indexofMonth )
{
    return Calendar.ShortMonths[ indexofMonth ];
}

function Calendar_getDaysofMonth( indexofMonth, curYear )
{
    if ( ( curYear % 4 ) == 0 )
    {
        if ( ( curYear % 100 ) == 0
            && (  curYear % 400 ) != 0 )
        {
            return Calendar.DOMonth[ indexofMonth ];
        }

        return Calendar.lDOMonth[ indexofMonth ];
    }
    else
    {
        return Calendar.DOMonth[ indexofMonth ];
    }
}

function Calendar_getMonthPos( curMonth, curYear, incr )
{
    var ret_arr = new Array();

    if ( incr == -1 )
    {
        if ( curMonth == 0 )
        {
            ret_arr[0] = 11;
            ret_arr[1] = parseInt( curYear ) - 1;
        }
        else
        {
            ret_arr[0] = parseInt( curMonth ) - 1;
            ret_arr[1] = parseInt( curYear );
        }
    }
    else if  ( incr == 1 )
    {
        if ( curMonth == 11 )
        {
            ret_arr[0] = 0;
            ret_arr[1] = parseInt( curYear ) + 1;
        }
        else
        {
            ret_arr[0] = parseInt( curMonth ) + 1;
            ret_arr[1] = parseInt( curYear );
        }
    }

    return ret_arr;
}
// ------------------------- End Definication a Properties -------------------------------------

//´Þ·ÂÀ» ±×¸®´Â µ¥ÀÌÅÍ ¼³Á¤
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function()
{
    var vCode           = "";
    var vHeader_Code    = "";
    var vData_Code      = "";

    // Begin Table Drawing code here..
    vCode = vCode + "<table width=100% align=center border=0 cellpadding=2 cellspacing=0>";
    vCode = vCode + "<tr><td colspan=7 height=5></td></tr>";

    vHeader_Code = this.cal_header();
    vData_Code = this.cal_date();

    vCode = vCode + vHeader_Code + vData_Code;
    vCode = vCode + "<tr><td colspan=7></td></tr>";

    vCode = vCode + "</table>";

    return vCode;
}
// ´Þ·ÂÀÇ header¸¦ ¼³Á¤ÇÑ´Ù....
Calendar.prototype.cal_header = function()
{
    var vCode = "";
    //Calendar Title ÁöÁ¤
    var style_string_sun = "font-family:" + FONT_FACE + ";font-size:" + HEADER_FONT_SIZE
                        + ";font-weight:bold;text-align:center"
                        + ";background-color:" + BGCOLOR_HEADER
                        + ";color:" + FONTCOLOR_HEADER;

    var style_string_gel = "font-family:" + FONT_FACE + ";font-size:" + HEADER_FONT_SIZE
                        + ";font-weight:bold;text-align:center"
                        + ";background-color:" + BGCOLOR_HEADER
                        + ";color:black";

    var style_string_sat = "font-family:" + FONT_FACE + ";font-size:" + HEADER_FONT_SIZE
                        + ";font-weight:bold;text-align:center"
                        + ";background-color:" + BGCOLOR_HEADER
                        + ";color:#0092B7";

    vCode = vCode + "<tr>";
    vCode = vCode + "<td height=20 width=22 style=\"" + style_string_sun + "\">ÀÏ</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_gel + "\">¿ù</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_gel + "\">È­</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_gel + "\">¼ö</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_gel + "\">¸ñ</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_gel + "\">±Ý</TD>";
    vCode = vCode + "<td width=22 style=\"" + style_string_sat + "\">Åä</TD>";
    vCode = vCode + "</tr>";

    return vCode;
}

// ´Þ·ÂÀÇ ÀÏÀÚÀ» ¼³Á¤ÇÑ´Ù.
Calendar.prototype.cal_date = function()
{
    var vDate = new Date();
    vDate.setDate( 1 );
    vDate.setMonth( this.cal_Month );
    vDate.setFullYear( this.cal_Year );

    var vFirstDay       = vDate.getDay();
    var vDay            = 1;
    var vLastDay        = Calendar.getDaysofMonth( this.cal_Month, this.cal_Year );
    var vOnLastDay      = 0;
    var vCode           = "";

    /*
    Get day for the 1st of the requested month/year..
    Place as many blank cells before the 1st day of the month as necessary.
    */
    vCode = vCode + "<tr>";
    for ( i = 0; i < vFirstDay; i++ ) {
        vCode = vCode + "<td height=20 " + this.day_style_string( i ) + "></td>";
    }

    // Write rest of the 1st week
    for ( j = vFirstDay; j<7; j++ ) {

        vCode = vCode + "<td height=20 " + this.day_style_string( j ) + ">" +
                        "<a href=\"javascript:"
                            + DATE_ONCLICK_FUNCTION + "('"
                            + this.cal_ReturnObject + "', '"
                            + this.format_date( vDay ) + "');window.close()\" " + this.day_style_string( j ) + ">" +    this.format_day( vDay ) +
                        "</a>" +
                        "</td>";
        vDay = vDay + 1;
    }
    vCode = vCode + "</tr>";

    // Write the rest of the weeks
    for ( k = 2; k < 7; k++ ) {
        vCode = vCode + "<tr>";

        for ( j = 0; j < 7; j++ ) {

            vCode = vCode + "<td height=20 " + this.day_style_string( j ) + ">" +
                            "<a href=\"javascript:"
                            + DATE_ONCLICK_FUNCTION + "('"
                                                + this.cal_ReturnObject + "', '"
                                                + this.format_date( vDay ) + "');window.close()\" " + this.day_style_string( j ) + ">" +
                            this.format_day(vDay) +
                            "</a>" +
                            "</td>";

            vDay = vDay + 1;

            if ( vDay > vLastDay ) {
                vOnLastDay = 1;
                break;
            }
        }

        if ( j == 6 )
            vCode = vCode + "</tr>";
        if ( vOnLastDay == 1 )
            break;
    }

    // Fill up the rest of last week with proper blanks, so that we get proper square blocks
    for ( m = 1; m < ( 7 - j ); m++) {
        if ( this.isYearlyMonth )
            vCode = vCode + "<td height=20 " + this.day_style_string(j+m) +"> </td>";
        else
            vCode = vCode + "<td height=20 " + this.day_style_string(j+m) +
            "><span style=\"font-size:" + FONT_SIZE_NEXTMONTH + ";color:"+ FONTCOLOR_NEXTMONTH + "\">" + m + "</FONT></td>";
    }

    return vCode;
}

Calendar.prototype.day_style_string = function(vday)
{
    var i;
    var SUNDAY_FONT = "#F2931E";
    var SAT_FONT    = "#0092B7";

    var style_text_sun = "style=\"font-family:" + FONT_FACE + ";font-size:" + FONT_SIZE + ";text-align:center;background-color:" + BGCOLOR_NOMAL_DAY + ";color:#F2931E;\"" ;
    var style_text_sat = "style=\"font-family:" + FONT_FACE + ";font-size:" + FONT_SIZE + ";text-align:center;background-color:" + BGCOLOR_NOMAL_DAY + ";color:#0092B7;\"" ;
    var style_text_normal = "style=\"font-family:" + FONT_FACE + ";font-size:" + FONT_SIZE + ";text-align:center;background-color:" + BGCOLOR_NOMAL_DAY + ";color:black;\"" ;

    // Return special formatting for the weekend day.

    for ( i=0; i < WEEK_END.length; i++ ) {

        if (vday == WEEK_END[i])
        {
            if ( vday == 0 )
            {
                //return ( style_text + "color:" + SUNDAY_FONT + ";\"" );
                return ( style_text_sun);
            }
            else if ( vday == 6 )
            {
                //return ( style_text + "color:" + SAT_FONT + ";\"" );
                return ( style_text_sat );
            }
        }
    }
    //return ( style_text + "color:" + NORMAL_FONT + ";\"" );
    return ( style_text_normal );
}

Calendar.prototype.format_day = function( vday )
{
    var vNowDay = TODAY.getDate();
    var vNowMonth   = TODAY.getMonth();
    var vNowYear = TODAY.getFullYear();

    if ( vday == vNowDay && this.cal_Month == vNowMonth && this.cal_Year == vNowYear )
    {
        return ("<span style=\"background-color:" + BGCOLOR_TODAY + ";color:" + FONTCOLOR_TODAY + ";\"><b>" + vday + "</b></span>");
    }
    else
    {
        return ( vday );
    }
}

Calendar.prototype.cal_wirteln = function( writeText )
{
    this.cal_WinControl.document.writeln( writeText );
}

Calendar.prototype.cal_write = function( writeText )
{
    this.cal_WinControl.document.write( writeText );
}

Calendar.prototype.show = function()
{
    var vCode = "";

    this.cal_WinControl.document.open();

    // Setup the page...
    this.cal_wirteln("<html>");
    this.cal_wirteln("<head><title>Calendar</title>");
    this.cal_wirteln( "<meta content=\"text/html; charset=euc-kr\" http-equiv=\"Content-Type\">");
    this.cal_wirteln("</head>");
    this.cal_wirteln( "<body class=etcBody marginwidth=0 marginheight=0 topmargin=0>");

    this.cal_wirteln("<center><img src=/images/calendar/0.gif width=5 border=0 height=5><br>");
    this.cal_wirteln("<table width=100% border=0 cellspacing=0 cellpadding=2>");
    this.cal_wirteln("<tr>");
    this.cal_wirteln("<td align=left valign=bottom height=22 width=31><img src=/images/calendar/cal_title.gif></td>");
    this.cal_wirteln("<td align=left valign=bottom height=22 width=105  style=\"font-size: 12pt; color: #969641; font-weight: bold\" " + ">"+ TODAY.getFullYear().toString() + "³â " + curMonthTitle  + "¿ù" + "</td>");
    this.cal_wirteln("</tr>");
    this.cal_wirteln("</table>");
    this.cal_wirteln("<table width=100% border=0 cellspacing=0 cellpadding=2>");
    this.cal_wirteln("<tr>");
    this.cal_wirteln("<td align=left valign=bottom height=3 bgcolor=#2AAB35>");
    this.cal_wirteln("</td>");
    this.cal_wirteln("</tr>");
    this.cal_wirteln("</table>");

    // Show navigation buttons
    var aryPrevYearMonth    = Calendar.getMonthPos( this.cal_Month, this.cal_Year, -1 );
    var prevShortMonthNameth= aryPrevYearMonth[0];
    var prevYear            = aryPrevYearMonth[1];

    var aryNextYearMonth    = Calendar.getMonthPos( this.cal_Month, this.cal_Year, 1 );
    var nextMonth           = aryNextYearMonth[0];
    var nextYear            = aryNextYearMonth[1];

    this.cal_wirteln( "<table width=100% border=0 bgcolor=#CECFCE cellpadding=0 cellspacing=0>" );
    this.cal_wirteln( "<tr>" );
    this.cal_wirteln( " <td bgcolor=#EFEFEF align=center height=18 width=50% style=\"font-family:" + FONT_FACE + ";font-size:" + FONT_SIZE_TITLE + ";color:" + FONTCOLOR_TITLE + ";font-weight:bold;text-align:center\"><a href=\"" +
                        "javascript:window.opener.Build(" + " '" + this.cal_ReturnObject + "', '" + this.cal_Month + "', '" + ( parseInt( this.cal_Year ) - 1 ) + "', '" + this.cal_DateFormat + "'" +
                        ")\"><img src=/images/calendar/cal_back.gif  width=4 height=7 border=0><\/a>" );
    this.cal_wirteln(  this.cal_Year  );
    this.cal_wirteln( "<a href=\"" + "javascript:window.opener.Build(" + " '" + this.cal_ReturnObject + "', '" + this.cal_Month + "', '" + ( parseInt( this.cal_Year ) + 1 ) + "', '" + this.cal_DateFormat + "'" +
                        ")\"><img src=/images/calendar/cal_next.gif  width=4 height=7 border=0><\/a></td>" );

    this.cal_wirteln( " <td bgcolor=#EFEFEF align=center width=50% height=18 style=\"font-family:" + FONT_FACE + ";font-size:" + FONT_SIZE_TITLE + ";color:" + FONTCOLOR_TITLE + ";font-weight:bold;text-align:center\"><a href=\"" +
                        "javascript:window.opener.Build(" +
                        " '" + this.cal_ReturnObject + "', '" + prevShortMonthNameth + "', '" + prevYear + "', '" + this.cal_DateFormat + "'" +
                        ")\"><img src=/images/calendar/cal_back.gif  width=4 height=7 border=0><\/a>" );
    this.cal_wirteln( ( parseInt( this.cal_Month ) + 1 ) + "¿ù"  );
    this.cal_wirteln( "<a href=\"" + "javascript:window.opener.Build(" +
                        " '" + this.cal_ReturnObject + "', '" + nextMonth + "', '" + nextYear + "', '" + this.cal_DateFormat + "'" +
                        ")\"><img src=/images/calendar/cal_next.gif  width=4 height=7 border=0><\/a>" );
    this.cal_wirteln( "</td>" );
    this.cal_wirteln( "</tr>" );
    this.cal_wirteln( "</table>" );

    // Get the complete calendar code for the month..
    vCode = this.getMonthlyCalendarCode();
    this.cal_wirteln( vCode );

    this.cal_wirteln( "</font></center></body></html> ");
    document.close();
}

Calendar.prototype.format_date = function( curDay )
{
    var vData;

    var vMonth = 1 + this.cal_Month;
    vMonth = ( vMonth.toString().length < 2 ) ? "0" + vMonth : vMonth;
    var vShortMonthName = Calendar.getShordMonthName( this.cal_Month ).toUpperCase();
    var vFullMonthName = Calendar.getMonthName( this.cal_Month ).toUpperCase();

    var vFullYear = new String( this.cal_Year );
    var vYear = new String( this.cal_Year.substr( 2,2 ) );

    var vDay = ( curDay.toString().length < 2 ) ? "0" + curDay : curDay;

    switch ( this.cal_DateFormat )
    {
        case "YYYYMMDD" :
            vData = vFullYear + vMonth+ vDay
            break;
        case "YYYY\/MM" :
            vData = vFullYear + "\/" + vMonth
            break;
        case "YYYY/MM/DD"   :
            vData = vFullYear + "/" + vMonth + "/" + vDay
            break;
        case "YYYY\/MM\/DD" :
            vData = vFullYear + "\/" + vMonth + "\/" + vDay
            break;
        case "YY\/MM\/DD"       :
            vData = vYear + "\/" + vMonth + "\/" + vDay
            break;
        case "YYYY-MM-DD"   :
            vData = vFullYear + "-" + vMonth + "-" + vDay
            break;
        case "YY-MM-DD"     :
            vData = vYear + "-" + vMonth + "-" + vDay
            break;
        case "DD\/MON\/YYYY" :
            vData = vDay + "\/" + vShortMonthName + "\/" + vFullYear;
            break;
        case "DD\/MON\/YY" :
            vData = vDay + "\/" + vShortMonthName + "\/" + vYear;
            break;
        case "DD-MON-YYYY" :
            vData = vDay + "-" + vShortMonthName + "-" + vFullYear;
            break;
        case "DD-MON-YY" :
            vData = vDay + "-" + vShortMonthName + "-" + vYear;
            break;
        case "DD\/MONTH\/YYYY" :
            vData = vDay + "\/" + vFullMonthName + "\/" + vFullYear;
            break;
        case "DD\/MONTH\/YY" :
            vData = vDay + "\/" + vFullMonthName + "\/" + vYear;
            break;
        case "DD-MONTH-YYYY" :
            vData = vDay + "-" + vFullMonthName + "-" + vFullYear;
            break;
        case "DD-MONTH-YY" :
            vData = vDay + "-" + vFullMonthName + "-" + vYear;
            break;

        case "DD\/MM\/YYYY" :
            vData = vDay + "\/" + vMonth + "\/" + vFullYear;
            break;
        case "DD\/MM\/YY" :
            vData = vDay + "\/" + vMonth + "\/" + vYear;
            break;
        case "DD-MM-YYYY" :
            vData = vDay + "-" + vMonth + "-" + vFullYear;
            break;
        case "DD-MM-YY" :
            vData = vDay + "-" + vMonth + "-" + vYear;
            break;
        default :
            vData = vFullYear + "\/" + vMonth + "\/" + vDay;
    }

    return vData;
}

function Build( returnObject, curMonth, curYear, dateFormat )
{
    var curWinCtl = openWinControl;
    oCalendar = new Calendar( returnObject, curWinCtl, curMonth, curYear, dateFormat );

    // Customize your Calendar here..
    oCalendar.gLinkColor="black";
    oCalendar.gTextColor="black";
    oCalendar.show();
}

function returnDate ( ReturnObjctName, returnFormatDate )
{
   
    var returnObject = eval( ReturnObjctName );



    // 2003-03-10, À¯»ó±Ù, return object : Gauce EMEdit Àû¿ë
/*
    if (returnObject.id.substr(0, 4).toUpperCase() == "GAEM")
    {
        setEMEditValue(returnObject, returnFormatDate);
    }
    else
        {
        returnObject.value = returnFormatDate;
    }
*/
    switch (returnObject.tagName) {
        case "INPUT":
            returnObject.value = returnFormatDate;
            returnObject.focus();               
            break;
        case "TEXTAREA":
            returnObject.value = returnFormatDate;
            returnObject.focus();           
            break;

        case "OBJECT":
            switch (returnObject.attributes.classid.nodeValue.toUpperCase()) {
                case "CLSID:E6876E99-7C28-43AD-9088-315DC302C05F": // EMedit Component
                case "CLSID:91B0A4F0-3206-4564-9BB4-AF9055DEF8A1": // TextArea Component
                    returnObject.Text = returnFormatDate;
                    returnObject.focus();                   
                    break;
                default :
                    break;
            }
            break;
            
        default :
        returnObject = returnFormatDate;
        
    }       
}








// ============================================================


/**
 * open calendar popup
 *
 * @param   returnObject    ¹ÝÈ¯¹ÞÀ» InputBox Name
 * @param   curDate         date string, ºó°ªÀÌ¸é ÇöÀç³¯Â¥
 * @param   dateFormat      ¹ÝÈ¯¹ÞÀ» DateÀÇ format String, default format(YYYY-MM-DD)
 * @return
 */
function cfShowCalendar(){

    var returnObject = arguments[0];
    var curYear     = TODAY.getFullYear().toString();
    var curMonth    = ((TODAY.getMonth() + 1) + 100).toString().substr(1,2);
    var curDay      = ((TODAY.getDate()) + 100).toString().substr(1,2);

    if(arguments[1] != null && arguments[1] != "" ){
        var curDate = arguments[1].replace(/\/|\-/g,"");
    }
    else{
        var curDate = curYear + curMonth + curDay;
    }

    curMonthTitle = curDate.substr(4,2);

    TODAY.setYear ( curDate.substr(0,4) );

  if(curDate.substr(4,1) == '0' )
  {
    TODAY.setMonth ( curDate.substr(5,1) - 1 );
    }
    else
    {
      TODAY.setMonth ( parseInt( curDate.substr(4,2) ) - 1 );
    }

    TODAY.setDate ( curDate.substr(6,2) );

    if ( arguments[2] == null )
        dateFormat = "YYYY-MM-DD";
    else
        dateFormat = arguments[2];

    // Calendar Popup
    var top = arguments[3];
    var left = arguments[4];
    if(top==null) top = ( window.screen.availHeight - 200 ) / 2 ;
    if(left==null) left = ( window.screen.availWidth - 180 ) / 2 ;


    //if(window.screen.availHeight - window.screenTop - eval(returnObject).offsetTop < 200)
    //  top = eval(returnObject).offsetTop - 200;
    //else
    //  top = eval(returnObject).offsetTop + eval(returnObject).offsetHeight;


    curWinCtl = window.open( "", "Calendar", "width=200,height=200,status=no,resizable=no,top="+top+",left="+left );
    if( curWinCtl != null ) {
        curWinCtl.opener = self;
        openWinControl = curWinCtl;
    }
    else {
        curWinCtl = window.open( "", "Calendar", "width=200,height=200,status=no,resizable=no,top="+top+",left="+left );
        curWinCtl.opener = self;
        openWinControl = curWinCtl;
    }
    Build( returnObject, TODAY.getMonth().toString(), TODAY.getYear().toString(), dateFormat );
}