// *****************************************************************************
//      Simple Calendar Widget - Cross-Browser Javascript pop-up calendar.
//
//   Copyright (C) 2005-2007  Anthony Garrett
//
//   This library is free software; you can redistribute it and/or
//   modify it under the terms of the GNU Lesser General Public
//   License as published by the Free Software Foundation; either
//   version 2.1 of the License, or (at your option) any later version.
//
//   This library is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//   Lesser General Public License for more details.
//
//   You should have received a copy of the GNU Lesser General Public
//   License along with this library; if not, it is available at
//   the GNU web site (http://www.gnu.org/) or by writing to the
//   Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
//   Boston, MA  02110-1301  USA
//
// *****************************************************************************
//

// ************************************
// Start of Simple Calendar Widget Code
// ************************************

// This date is used throughout to determine today's date.

    var calDateNow = new Date(2010,8,1);

//******************************************************************************
//------------------------------------------------------------------------------
// Customisation section
//------------------------------------------------------------------------------
//******************************************************************************

    var calBaseYear        = 2010;

    var calDropDownYears   = 1;

    var calLanguage;

    function calSetDefaultLanguage()
        {try
            {calSetLanguage();}
         catch (exception)
            {// Deutsch
             calToday               = 'buchbar ab:';
             calClear               = 'Clear';
             calDrag                = 'click here to drag';
             calArrMonthNames       = ['Jan','Feb','Mar','Apr','Mai','Jun',
                                       'Jul','Aug','Sep','Okt','Nov','Dez'];
             calArrWeekInits        = ['So','Mo','Di','Mi','Do','Fr','Sa'];
             calInvalidDateMsg      = 'Das eigetragene Datum ist ungültig.\n';
             calOutOfRangeMsg       = 'Das eigetragene Datum ist ausserhalb des möglichen Zeitraums.';
             calDoesNotExistMsg     = 'Das eigetragene Datum existiert nicht.';
             calInvalidAlert        = ['Ungültiges Datum (',') ignoriert.'];
             calDateDisablingError  = ['Fehler ',' ist kein Datum.'];
             calRangeDisablingError = ['Fehler ',
                                       ' should consist of two elements.'];
            }
        };

    var calWeekStart       =    1;

    var calWeekNumberDisplay    = false;

    var calWeekNumberBaseDay    = 4;

    var calShowInvalidDateMsg       = false,
        calShowOutOfRangeMsg        = false,
        calShowDoesNotExistMsg      = false,
        calShowInvalidAlert         = false,
        calShowDateDisablingError   = false,
        calShowRangeDisablingError  = false;

    var calArrDelimiters   = ['/','-','.',',',' '];

    var calDateDisplayFormat = 'dd-mm-yy';     // e.g. 'MMM-DD-YYYY' for the US

    var calDateOutputFormat  = 'DD.MM.YYYY'; // e.g. 'MMM-DD-YYYY' for the US

    var calZindex          = 1;

    var calBlnStrict       = false;

    var calClearButton     = true;

    var calAutoPosition    = true;

    var calEnabledDay      = [true, true, true, true, true, true, true,
                              true, true, true, true, true, true, true,
                              true, true, true, true, true, true, true,
                              true, true, true, true, true, true, true,
                              true, true, true, true, true, true, true,
                              true, true, true, true, true, true, true];

    var calDisabledDates   = new Array();

    calDisabledDates[1] = [new Date(2010,0,1),new Date(2010,3,29)];
    calDisabledDates[2] = [new Date(2010,3,30),new Date(2010,3,30)];
    calDisabledDates[3] = [new Date(2010,4,1),new Date(2010,7,31)];
    calDisabledDates[4] = [new Date(2010,10,16),new Date(2010,10,23)];
    calDisabledDates[5] = new Date(2010,8,10);
    calDisabledDates[6] = new Date(2010,8,29);
    calDisabledDates[7] = new Date(2010,9,9);
    calDisabledDates[8] = new Date(2010,9,29);

    var calActiveToday = false;
    var calOutOfMonthDisable = false;
    var calOutOfMonthHide    = true;
    var calOutOfRangeDisable = true;
    var calFormatTodayCell = true;
    var calTodayCellBorderColour = 'red';
    var calAllowDrag = false;
    var calClickToHide = true;


    document.writeln(
        '<style type="text/css">'                                       +
            '.cal           {padding:1px;vertical-align:middle;}'       +
            'iframe.cal     {position:absolute;z-index:' + calZindex    +
                            ';top:0px;left:0px;visibility:hidden;'      +
                            'width:1px;height:1px;}'                    +
            'table.cal      {padding:0px;visibility:hidden;'            +
                            'position:absolute;cursor:default;'         +
                            'width:200px;top:0px;left:0px;'             +
                            'z-index:' + (calZindex+1)                  +
                            ';text-align:center;}'                      +
        '</style>'  );

    document.writeln(
        '<style type="text/css">'                                       +
            '/* IMPORTANT:  The SCW calendar script requires all '      +
            '               the classes defined here.'                  +
            '*/'                                                        +
            'table.cal      {padding:       1px;'                       +
                            'vertical-align:middle;'                    +
                            'border:        ridge 2px;'                 +
                            'font-size:     10pt;'                      +
                            'font-family:   ' +
                                   'Verdana,Arial,Helvetica,Sans-Serif;'+
                            'font-weight:   bold;}'                     +
            'td.calDrag,'                                               +
            'td.calHead                 {padding:       0px 0px;'       +
                                        'text-align:    center;}'       +
            'td.calDrag                 {font-size:     8pt;}'          +
            'select.calHead             {margin:        3px 1px;'       +
                                        'text-align:    center;}'       +
            'input.calHead              {height:        22px;'          +
                                        'width:         22px;'          +
                                        'vertical-align:middle;'        +
                                        'text-align:    center;'        +
                                        'margin:        2px 1px;'       +
                                        'font-weight:   bold;'          +
                                        'font-size:     10pt;'          +
                                        'font-family:   fixedSys;}'     +
            'td.calWeekNumberHead,'                                     +
            'td.calWeek                 {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'font-weight:   bold;}'         +
            'td.calNow,'                                                +
            'td.calNowHover,'                                           +
            'td.calNow:hover,'                                          +
            'td.calNowDisabled          {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'vertical-align:middle;'        +
                                        'font-weight:   normal;}'       +
            'table.calCells             {text-align:    right;'         +
                                        'font-size:     8pt;'           +
                                        'width:         96%;}'          +
            'td.calCells,'                  +
            'td.calCellsHover,'             +
            'td.calCells:hover,'            +
            'td.calCellsDisabled,'          +
            'td.calCellsExMonth,'           +
            'td.calCellsExMonthHover,'      +
            'td.calCellsExMonth:hover,'     +
            'td.calCellsExMonthDisabled,'   +
            'td.calCellsWeekend,'           +
            'td.calCellsWeekendHover,'      +
            'td.calCellsWeekend:hover,'     +
            'td.calCellsWeekendDisabled,'   +
            'td.calInputDate,'              +
            'td.calInputDateHover,'         +
            'td.calInputDate:hover,'        +
            'td.calInputDateDisabled,'      +
            'td.calWeekNo,'                 +
            'td.calWeeks                {padding:           3px;'       +
                                        'width:             16px;'      +
                                        'height:            16px;'      +
                                        'border-width:      1px;'       +
                                        'border-style:      solid;'     +
                                        'font-weight:       bold;'      +
                                        'vertical-align:    middle;}'   +
            '/* Blend the colours into your page here...    */'         +
            '/* Calendar background */'                                 +
            'table.cal                  {background-color:  #0040FF;}'  +
            '/* Drag Handle */'                                         +
            'td.calDrag                 {background-color:  #9999CC;'   +
                                        'color:             #CCCCFF;}'  +
            '/* Week number heading */'                                 +
            'td.calWeekNumberHead       {color:             #6666CC;}'  +
            '/* Week day headings */'                                   +
            'td.calWeek                 {color:             #CCCCCC;}'  +
            '/* Week numbers */'                                        +
            'td.calWeekNo               {background-color:  #776677;'   +
                                        'color:             #CCCCCC;}'  +
            '/* Enabled Days */'                                        +
            '/* Week Day */'                                            +
            'td.calCells                {background-color:  #A0FF00;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.calInputDate            {background-color:  #CC9999;'   +
                                        'color:             #FF0000;}'  +
            '/* Weekend Day */'                                         +
            'td.calCellsWeekend         {background-color:  #A0FF00;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.calCellsExMonth         {background-color:  #CCCCCC;'   +
                                        'color:             #666666;}'  +
            '/* Today selector */'                                      +
            'td.calNow                  {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
            '/* Clear Button */'                                        +
            'td.calClear                {padding:           0px;}'      +
            'input.calClear             {padding:           0px;'       +
                                        'text-align:        center;'    +
                                        'font-size:         8pt;}'      +
            '/* MouseOver/Hover formatting '                            +
            '       If you want to "turn off" any of the formatting '   +
            '       then just set to the same as the standard format'   +
            '       above.'                                             +
            ' '                                                         +
            '       Note: The reason that the following are'            +
            '       implemented using both a class and a :hover'        +
            '       pseudoclass is because Opera handles the rendering' +
            '       involved in the class swap very poorly and IE6 '    +
            '       (and below) only implements pseudoclasses on the'   +
            '       anchor tag.'                                        +
            '*/'                                                        +
            '/* Active cells */'                                        +
            'td.calCells:hover,'                                        +
            'td.calCellsHover           {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.calInputDate:hover,'                                    +
            'td.calInputDateHover       {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Weekend cells */'                                       +
            'td.calCellsWeekend:hover,'                                 +
            'td.calCellsWeekendHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day outside the current month */'                       +
            'td.calCellsExMonth:hover,'                                 +
            'td.calCellsExMonthHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Today selector */'                                      +
            'td.calNow:hover,'                                          +
            'td.calNowHover             {color:             #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'font-weight:       bold;}'     +
            '/* Disabled cells */'                                      +
            '/* Week Day */'                                            +
            '/* Day matching the input date */'                         +
            'td.calInputDateDisabled    {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            'td.calCellsDisabled        {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            '/* Weekend Day */'                                         +
            'td.calCellsWeekendDisabled {background-color:  #999999;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.calCellsExMonthDisabled {background-color:  #999999;'   +
                                        'color:             #666666;}'  +
            'td.calNowDisabled          {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
        '</style>'
                    );

//******************************************************************************
//------------------------------------------------------------------------------
// End of customisation section
//------------------------------------------------------------------------------
//******************************************************************************

    var calTargetEle,
        calTriggerEle,
        calMonthSum            = 0,
        calBlnFullInputDate    = false,
        calPassEnabledDay      = new Array(),
        calSeedDate            = new Date(),
        calParmActiveToday     = true,
        calWeekStart           = calWeekStart%7,
        calToday,
        calClear,
        calDrag,
        calArrMonthNames,
        calArrWeekInits,
        calInvalidDateMsg,
        calOutOfRangeMsg,
        calDoesNotExistMsg,
        calInvalidAlert,
        calDateDisablingError,
        calRangeDisablingError;

    Date.prototype.calFormat =
        function(calFormat)
            {var charCount = 0,
                 codeChar  = '',
                 result    = '';

             for (var i=0;i<=calFormat.length;i++)
                {if (i<calFormat.length && calFormat.charAt(i)==codeChar)
                        {charCount++;
                        }
                 else   {switch (codeChar)
                            {case 'y': case 'Y':
                                result += (this.getFullYear()%Math.
                                            pow(10,charCount)).toString().
                                            calPadLeft(charCount);
                                break;
                             case 'm': case 'M':
                                result += (charCount<3)
                                            ?(this.getMonth()+1).
                                                toString().calPadLeft(charCount)
                                            :calArrMonthNames[this.getMonth()];
                                break;
                             case 'd': case 'D':

                                result += this.getDate().toString().
                                            calPadLeft(charCount);
                                break;
                             default:

                                while (charCount-- > 0) {result += codeChar;}
                            }

                         if (i<calFormat.length)
                            {// Store the character we have just worked on
                             codeChar  = calFormat.charAt(i);
                             charCount = 1;
                            }
                        }
                }
             return result;
            };

    String.prototype.calPadLeft =
        function(padToLength)
            {var result = '';
             for (var i=0;i<(padToLength - this.length);i++) {result += '0';}
             return (result + this);
            };

    Function.prototype.runsAfterSCW =
        function()  {var func = this,
                         args = new Array(arguments.length);

                     for (var i=0;i<args.length;++i) {args[i] = arguments[i];}

                     return function()
                        {for (var i=0;i<arguments.length;++i) {args[args.length] = arguments[i];}
                         return (args.shift()==calTriggerEle)?func.apply(this, args):null;
                        };
                    };

    function calID(id)
        {if (document.getElementById(id) || (!document.getElementById(id) && document.getElementsByName(id).length==0))
                {return document.getElementById(id);}
         else   {if (document.getElementsByName(id).length==1)
                       {return document.getElementsByName(id)[0];}
                 else   {if (document.getElementsByName(id).length>1)
                            {
                             alert( 'SCW' +
                                    ' \nCannot uniquely identify element named: ' + id +
                                    '.\nMore than one identical NAME attribute defined' +
                                    '.\nSolution: Assign the required element a unique ID attribute value.');
                            }
                        }
                }
        };

    var calNextActionReturn, calNextAction;

    function showCal(calEle,calSource) {calShow(calEle,calSource);};
    function calShow(calEle,calSource)
        {if (!calSource) {calSource = window.event;}

         if (calSource.tagName)
            {var calSourceEle = calSource;

             if (calID('calIE'))  {window.event.cancelBubble = true;}
             else {calSourceEle.parentNode.addEventListener('click',calStopPropagation,false);}
            }
         else
            {var calSourceEle = (calSource.target)
                                    ?calSource.target
                                    :calSource.srcElement;

             if (calSource.stopPropagation) {calSource.stopPropagation();}
             else                           {calSource.cancelBubble = true;}
            }

         calTriggerEle = calSourceEle;

         calParmActiveToday = true;

         for (var i=0;i<7;i++)
            {calPassEnabledDay[(i+7-calWeekStart)%7] = true;
             for (var j=2;j<arguments.length;j++)
                {if (arguments[j]==i)
                    {calPassEnabledDay[(i+7-calWeekStart)%7] = false;
                     if (calDateNow.getDay()==i) {calParmActiveToday = false;}
                    }
                }
            }

         calSeedDate = calDateNow;

         var calDateValue = '';

         if (calEle.value) {calDateValue = calEle.value.replace(/^\s+/,'').replace(/\s+$/,'');}
         else   {if (typeof calEle.value == 'undefined')
                    {var calChildNodes = calEle.childNodes;
                     for (var i=0;i<calChildNodes.length;i++)
                        {if (calChildNodes[i].nodeType == 3)
                            {calDateValue = calChildNodes[i].nodeValue.replace(/^\s+/,'').replace(/\s+$/,'');
                             if (calDateValue.length > 0)
                                {calTriggerEle.calTextNode = calChildNodes[i];
                                 calTriggerEle.calLength   = calChildNodes[i].nodeValue.length;
                                 break;
                                }
                            }
                        }
                    }
                }

         calSetDefaultLanguage();

         calID('calDragText').innerHTML = calDrag;

         calID('calMonths').options.length = 0;
         for (var i=0;i<calArrMonthNames.length;i++)
            {calID('calMonths').options[i] = new Option(calArrMonthNames[i],calArrMonthNames[i]);}

         calID('calYears').options.length = 0;
         for (var i=0;i<calDropDownYears;i++)
            {calID('calYears').options[i] =  new Option((calBaseYear+i),(calBaseYear+i));}

         for (var i=0;i<calArrWeekInits.length;i++)
            {calID('calWeekInit' + i).innerHTML = calArrWeekInits[(i+calWeekStart)%calArrWeekInits.length];}

         if (((new Date(calBaseYear + calDropDownYears, 0, 0)) > calDateNow &&
              (new Date(calBaseYear, 0, 0))                    < calDateNow) ||
             (calClearButton && (calEle.readOnly || calEle.disabled))
            )   {calID('calFoot').style.display = '';
                 calID('calNow').innerHTML = '<p onclick=calHide()>Kalender ausblenden';
                 calID('calClearButton').value = calClear;
                 if ((new Date(calBaseYear + calDropDownYears, 0, 0)) > calDateNow &&
                     (new Date(calBaseYear, 0, 0))                    < calDateNow
                    )   {calID('calNow').style.display = '';
                         if (calClearButton && (calEle.readOnly || calEle.disabled))
                                {calID('calClear').style.display   = '';
                                 calID('calClear').style.textAlign = 'left';
                                 calID('calNow').style.textAlign   = 'right';
                                }
                         else   {calID('calClear').style.display = 'none';
                                 calID('calNow').style.textAlign = 'center';
                                }
                        }
                 else   {calID('calClear').style.textAlign = 'center';
                         calID('calClear').style.display = '';
                         calID('calNow').style.display = 'none';
                        }
                }
         else   {calID('calFoot').style.display = 'none';}

         if (calDateValue.length==0)
            {
             calBlnFullInputDate=false;

             if ((new Date(calBaseYear+calDropDownYears,0,0))<calSeedDate ||
                 (new Date(calBaseYear,0,1))                 >calSeedDate
                )
                {calSeedDate = new Date(calBaseYear + Math.floor(calDropDownYears / 2), 5, 1);}
            }
         else
            {function calInputFormat()
                {var calArrSeed = new Array(),
                     calArrInput = calDateValue.split(new RegExp('[\\'+calArrDelimiters.join('\\')+']+','g'));

                 if (calArrInput[0]!=null)
                    {if (calArrInput[0].length==0)                      {calArrInput.splice(0,1);}
                     if (calArrInput[calArrInput.length-1].length==0)   {calArrInput.splice(calArrInput.length-1,1);}
                    }

                 calBlnFullInputDate = false;

                 calDateOutputFormat = calDateOutputFormat.toUpperCase();

                 // List all the allowed letters in the date format
                 var template = ['D','M','Y'];

                 // Prepare the sequence of date input elements
                 var result = new Array();

                 for (var i=0;i<template.length;i++)
                    {if (calDateOutputFormat.search(template[i])>-1)
                        {result[calDateOutputFormat.search(template[i])] = template[i];}
                    }

                 var calDateSequence = result.join('');

                 // Separate the elements of the date input
                 switch (calArrInput.length)
                    {case 1:
                        {if (calDateOutputFormat.indexOf('Y')>-1 &&
                             calArrInput[0].length>calDateOutputFormat.lastIndexOf('Y'))
                            {calArrSeed[0] = parseInt(calArrInput[0].substring(calDateOutputFormat.indexOf('Y'),
                                                                               calDateOutputFormat.lastIndexOf('Y')+1),10);
                            }
                         else   {calArrSeed[0] = 0;}

                         if (calDateOutputFormat.indexOf('M')>-1 &&
                             calArrInput[0].length>calDateOutputFormat.lastIndexOf('M'))
                            {calArrSeed[1] = calArrInput[0].substring(calDateOutputFormat.indexOf('M'),
                                                                      calDateOutputFormat.lastIndexOf('M')+1);
                            }
                         else   {calArrSeed[1] = '6';}

                         if (calDateOutputFormat.indexOf('D')>-1 &&
                             calArrInput[0].length>calDateOutputFormat.lastIndexOf('D'))
                            {calArrSeed[2] = parseInt(calArrInput[0].substring(calDateOutputFormat.indexOf('D'),
                                                                               calDateOutputFormat.lastIndexOf('D')+1),10);
                            }
                         else   {calArrSeed[2] = 1;}

                         if (calArrInput[0].length==calDateOutputFormat.length) {calBlnFullInputDate = true;}
                         break;
                        }
                     case 2:
                        {// Year and Month entry
                         calArrSeed[0] =
                             parseInt(calArrInput[calDateSequence.
                                                    replace(/D/i,'').
                                                    search(/Y/i)],10);  // Year
                         calArrSeed[1] = calArrInput[calDateSequence.
                                                    replace(/D/i,'').
                                                    search(/M/i)];      // Month
                         calArrSeed[2] = 1;                             // Day
                         break;
                        }
                     case 3:
                        {// Day Month and Year entry

                         calArrSeed[0] =
                             parseInt(calArrInput[calDateSequence.
                                                    search(/Y/i)],10);  // Year
                         calArrSeed[1] = calArrInput[calDateSequence.
                                                    search(/M/i)];      // Month
                         calArrSeed[2] =
                             parseInt(calArrInput[calDateSequence.
                                                    search(/D/i)],10);  // Day

                         calBlnFullInputDate = true;
                         break;
                        }
                     default:
                        {
                         calArrSeed[0] = 0;     // Year
                         calArrSeed[1] = 0;     // Month
                         calArrSeed[2] = 0;     // Day
                        }
                    }


                 var calExpValDay    = new RegExp('^(0?[1-9]|[1-2][0-9]|3[0-1])$'),
                     calExpValMonth  = new RegExp('^(0?[1-9]|1[0-2]|'        +
                                                  calArrMonthNames.join('|') +
                                                  ')$','i'),
                     calExpValYear   = new RegExp('^([0-9]{1,2}|[0-9]{4})$');


                 if (calExpValYear.exec(calArrSeed[0])  == null ||
                     calExpValMonth.exec(calArrSeed[1]) == null ||
                     calExpValDay.exec(calArrSeed[2])   == null
                    )
                    {if (calShowInvalidDateMsg)
                        {alert(calInvalidDateMsg  +
                               calInvalidAlert[0] + calDateValue +
                               calInvalidAlert[1]);}
                     calBlnFullInputDate = false;
                     calArrSeed[0] = calBaseYear +
                                     Math.floor(calDropDownYears/2); // Year
                     calArrSeed[1] = '6';                            // Month
                     calArrSeed[2] = 1;                              // Day
                    }


                 return calArrSeed;
                };


             calArrSeedDate = calInputFormat();


             if (calArrSeedDate[0]<100) {calArrSeedDate[0] += (calArrSeedDate[0]>50)?1900:2000;}


             if (calArrSeedDate[1].search(/\d+/)<0)
                {for (i=0;i<calArrMonthNames.length;i++)
                    {if (calArrSeedDate[1].toUpperCase()==calArrMonthNames[i].toUpperCase())
                        {calArrSeedDate[1]=i+1;
                         break;
                        }
                    }
                }

             calSeedDate = new Date(calArrSeedDate[0],calArrSeedDate[1]-1,calArrSeedDate[2]);
            }

         if (isNaN(calSeedDate))
            {if (calShowInvalidDateMsg) {alert(calInvalidDateMsg + calInvalidAlert[0] + calDateValue + calInvalidAlert[1]);}
             calSeedDate = new Date(calBaseYear + Math.floor(calDropDownYears/2),5,1);
             calBlnFullInputDate=false;
            }
         else
            {
             if ((new Date(calBaseYear,0,1)) > calSeedDate)
                {if (calBlnStrict && calShowOutOfRangeMsg) {alert(calOutOfRangeMsg);}
                 calSeedDate = new Date(calBaseYear,0,1);
                 calBlnFullInputDate=false;
                }
             else
                {if ((new Date(calBaseYear+calDropDownYears,0,0))<calSeedDate)
                    {if (calBlnStrict && calShowOutOfRangeMsg) {alert(calOutOfRangeMsg);}
                     calSeedDate = new Date(calBaseYear + Math.floor(calDropDownYears)-1,11,1);
                     calBlnFullInputDate=false;
                    }
                 else
                    {if (calBlnStrict && calBlnFullInputDate &&
                          (calSeedDate.getDate()      != calArrSeedDate[2] ||
                           (calSeedDate.getMonth()+1) != calArrSeedDate[1] ||
                           calSeedDate.getFullYear()  != calArrSeedDate[0]
                          )
                        )
                        {if (calShowDoesNotExistMsg) alert(calDoesNotExistMsg);
                         calSeedDate = new Date(calSeedDate.getFullYear(),calSeedDate.getMonth()-1,1);
                         calBlnFullInputDate=false;
                        }
                    }
                }
            }


         for (var i=0;i<calDisabledDates.length;i++)
            {if (!((typeof calDisabledDates[i] == 'object') && (calDisabledDates[i].constructor == Date)))
                {if ((typeof calDisabledDates[i] == 'object') && (calDisabledDates[i].constructor == Array))
                    {var calPass = true;

                     if (calDisabledDates[i].length !=2)
                        {if (calShowRangeDisablingError)
                            {alert(calRangeDisablingError[0] + calDisabledDates[i] + calRangeDisablingError[1]);}
                         calPass = false;
                        }
                     else
                        {for (var j=0;j<calDisabledDates[i].length;j++)
                            {if (!((typeof calDisabledDates[i][j] == 'object') && (calDisabledDates[i][j].constructor == Date)))
                                {if (calShowRangeDisablingError)
                                    {alert(  calDateDisablingError[0] + calDisabledDates[i][j] + calDateDisablingError[1]);}
                                 calPass = false;
                                }
                            }
                        }

                     if (calPass && (calDisabledDates[i][0] > calDisabledDates[i][1])) {calDisabledDates[i].reverse();}
                    }
                 else
                    {if (calShowRangeDisablingError) {alert(calDateDisablingError[0] + calDisabledDates[i] + calDateDisablingError[1]);}}
                }
            }

         calMonthSum =  12*(calSeedDate.getFullYear()-calBaseYear)+calSeedDate.getMonth();

         calID('calYears' ).options.selectedIndex = Math.floor(calMonthSum/12);
         calID('calMonths').options.selectedIndex = (calMonthSum%12);
         calID('calDrag').style.display=(calAllowDrag)?'':'none';

         calShowMonth(0);

         calTargetEle=calEle;

         var offsetTop =parseInt(calEle.offsetTop ,10) + parseInt(calEle.offsetHeight,10),
             offsetLeft=parseInt(calEle.offsetLeft,10);

         if (!window.opera)
             {while (calEle.tagName!='BODY' && calEle.tagName!='HTML')
                 {offsetTop -=parseInt(calEle.scrollTop, 10);
                  offsetLeft-=parseInt(calEle.scrollLeft,10);
                  calEle=calEle.parentNode;
                 }
              calEle=calTargetEle;
             }

         do {calEle=calEle.offsetParent;
             offsetTop +=parseInt(calEle.offsetTop, 10);
             offsetLeft+=parseInt(calEle.offsetLeft,10);
            }
         while (calEle.tagName!='BODY' && calEle.tagName!='HTML');

         if (calAutoPosition)
             {var calWidth      = parseInt(calID('cal').offsetWidth, 10),
                  calHeight     = parseInt(calID('cal').offsetHeight,10),
                  calWindowLeft =
                     (document.body && document.body.scrollLeft)
                          ?document.body.scrollLeft                  //DOM compliant
                          :(document.documentElement && document.documentElement.scrollLeft)
                              ?document.documentElement.scrollLeft   //IE6+ standards compliant
                              :0,                                    //Failed
                  calWindowWidth =
                      (typeof(innerWidth) == 'number')
                          ?innerWidth                                //DOM compliant
                          :(document.documentElement && document.documentElement.clientWidth)
                              ?document.documentElement.clientWidth  //IE6+ standards compliant
                              :(document.body && document.body.clientWidth)
                                  ?document.body.clientWidth         //IE non-compliant
                                  :0,                                //Failed
                  calWindowTop =
                      (document.body && document.body.scrollTop)
                          ?document.body.scrollTop                   //DOM compliant
                          :(document.documentElement && document.documentElement.scrollTop)
                              ?document.documentElement.scrollTop    //IE6+ standards compliant
                              :0,                                    //Failed
                  calWindowHeight =
                      (typeof(innerHeight) == 'number')
                          ?innerHeight                               //DOM compliant
                          :(document.documentElement && document.documentElement.clientHeight)
                              ?document.documentElement.clientHeight //IE6+ standards compliant
                              :(document.body && document.body.clientHeight)
                                  ?document.body.clientHeight        //IE non-compliant
                                  :0;                                //Failed

              offsetLeft -= (offsetLeft - calWidth + parseInt(calTargetEle.offsetWidth,10) >= calWindowLeft &&
                             offsetLeft + calWidth > calWindowLeft + calWindowWidth
                            )?(calWidth - parseInt(calTargetEle.offsetWidth,10)):0;

              offsetTop -= (offsetTop - calHeight - parseInt(calTargetEle.offsetHeight,10) >= calWindowTop &&
                            offsetTop + calHeight > calWindowTop + calWindowHeight
                           )?(calHeight + parseInt(calTargetEle.offsetHeight,10)):0;
             }

         calID('cal').style.top         = offsetTop+'px';
         calID('cal').style.left        = offsetLeft+'px';
         calID('calIframe').style.top   = offsetTop+'px';
         calID('calIframe').style.left  = offsetLeft+'px';

         calID('calIframe').style.width =(calID('cal').offsetWidth-(calID('calIE')?2:4))+'px';
         calID('calIframe').style.height=(calID('cal').offsetHeight-(calID('calIE')?2:4))+'px';
         calID('calIframe').style.visibility='inherit';

         // Show it on the page
         calID('cal').style.visibility='inherit';
        };

    function calHide()
        {calID('cal').style.visibility='hidden';
         calID('calIframe').style.visibility='hidden';
         if (typeof calNextAction!='undefined' && calNextAction!=null)
             {calNextActionReturn = calNextAction();
              // Explicit null set to prevent closure causing memory leak
              calNextAction = null;
             }
        };

    function calCancel(calEvt)
        {if (calClickToHide) {calHide();}
         calStopPropagation(calEvt);
        };

    function calStopPropagation(calEvt)
        {if (calEvt.stopPropagation)
                {calEvt.stopPropagation();}     // Capture phase
         else   {calEvt.cancelBubble = true;}   // Bubbling phase
        };

    function calBeginDrag(event)
        {var elementToDrag = calID('cal');

         var deltaX    = event.clientX,
             deltaY    = event.clientY,
             offsetEle = elementToDrag;

         do {deltaX   -= parseInt(offsetEle.offsetLeft,10);
             deltaY   -= parseInt(offsetEle.offsetTop ,10);
             offsetEle = offsetEle.offsetParent;
            }
         while (offsetEle.tagName!='BODY' &&
                offsetEle.tagName!='HTML');

         if (document.addEventListener)
                {document.addEventListener('mousemove',moveHandler,true);        // Capture phase
                 document.addEventListener('mouseup',  upHandler,  true);        // Capture phase
                }
         else   {elementToDrag.attachEvent('onmousemove',moveHandler); // Bubbling phase
                 elementToDrag.attachEvent('onmouseup',  upHandler);   // Bubbling phase
                 elementToDrag.setCapture();
                }

         calStopPropagation(event);

         function moveHandler(calEvt)
            {if (!calEvt) calEvt = window.event;

             elementToDrag.style.left = (calEvt.clientX - deltaX) + 'px';
             elementToDrag.style.top  = (calEvt.clientY - deltaY) + 'px';

             calID('calIframe').style.left = (calEvt.clientX - deltaX) + 'px';
             calID('calIframe').style.top  = (calEvt.clientY - deltaY) + 'px';

             calStopPropagation(calEvt);
            };

         function upHandler(calEvt)
            {if (!calEvt) calEvt = window.event;

             if (document.removeEventListener)
                    {document.removeEventListener('mousemove',moveHandler,true);     // Capture phase
                     document.removeEventListener('mouseup',  upHandler,  true);     // Capture phase
                    }
             else   {elementToDrag.detachEvent('onmouseup',  upHandler);   // Bubbling phase
                     elementToDrag.detachEvent('onmousemove',moveHandler); // Bubbling phase
                     elementToDrag.releaseCapture();
                    }

             calStopPropagation(calEvt);
            };
        };

    function calShowMonth(calBias)
        {

         var calShowDate  = new Date(Date.parse(new Date().toDateString())),
             calStartDate = new Date();

         calShowDate.setHours(12);

         calSelYears  = calID('calYears');
         calSelMonths = calID('calMonths');

         if (calSelYears.options.selectedIndex>-1)
            {calMonthSum=12*(calSelYears.options.selectedIndex)+calBias;
             if (calSelMonths.options.selectedIndex>-1) {calMonthSum+=calSelMonths.options.selectedIndex;}
            }
         else
            {if (calSelMonths.options.selectedIndex>-1) {calMonthSum+=calSelMonths.options.selectedIndex;}}

         calShowDate.setFullYear(calBaseYear + Math.floor(calMonthSum/12),(calMonthSum%12),1);

         calID('calWeek_').style.display=(calWeekNumberDisplay)?'':'none';

         if (window.opera)
            {calID('calMonths').style.display = 'inherit';
             calID('calYears' ).style.display = 'inherit';
           }

         calTemp = (12*parseInt((calShowDate.getFullYear()-calBaseYear),10)) + parseInt(calShowDate.getMonth(),10);

         if (calTemp > -1 && calTemp < (12*calDropDownYears))
            {calSelYears.options.selectedIndex=Math.floor(calMonthSum/12);
             calSelMonths.options.selectedIndex=(calMonthSum%12);

             calCurMonth = calShowDate.getMonth();

             calShowDate.setDate((((calShowDate.
                                    getDay()-calWeekStart)<0)?-6:1)+
                                 calWeekStart-calShowDate.getDay());

             var calCompareDateValue = new Date(calShowDate.getFullYear(),
                                                calShowDate.getMonth(),
                                                calShowDate.getDate()).valueOf();

             calStartDate = new Date(calShowDate);

             if ((new Date(calBaseYear + calDropDownYears, 0, 0)) > calDateNow &&
                 (new Date(calBaseYear, 0, 0))                    < calDateNow)
                {var calNow = calID('calNow');

                 function calNowOutput() {calSetOutput(calDateNow);};

                 if (calDisabledDates.length==0)
                    {if (calActiveToday && calParmActiveToday)
                        {calNow.onclick     = calNowOutput;
                         calNow.className   = 'calNow';

                         if (calID('calIE'))
                            {calNow.onmouseover  = calChangeClass;
                             calNow.onmouseout   = calChangeClass;
                            }

                        }
                     else
                        {calNow.onclick     = null;
                         calNow.className   = 'calNowDisabled';

                         if (calID('calIE'))
                            {calNow.onmouseover  = null;
                             calNow.onmouseout   = null;
                            }

                         if (document.addEventListener)
                                {calNow.addEventListener('click',calStopPropagation,false);}
                         else   {calNow.attachEvent('onclick',calStopPropagation);}
                        }
                    }
                 else
                    {for (var k=0;k<calDisabledDates.length;k++)
                        {if (!calActiveToday || !calParmActiveToday ||
                             ((typeof calDisabledDates[k] == 'object')                   &&
                                 (((calDisabledDates[k].constructor == Date)             &&
                                   calDateNow.valueOf() == calDisabledDates[k].valueOf()
                                  ) ||
                                  ((calDisabledDates[k].constructor == Array)               &&
                                   calDateNow.valueOf() >= calDisabledDates[k][0].valueOf() &&
                                   calDateNow.valueOf() <= calDisabledDates[k][1].valueOf()
                                  )
                                 )
                             )
                            )
                            {calNow.onclick     = null;
                             calNow.className   = 'calNowDisabled';

                             if (calID('calIE'))
                                {calNow.onmouseover  = null;
                                 calNow.onmouseout   = null;
                                }

                             if (document.addEventListener)
                                    {calNow.addEventListener('click',calStopPropagation,false);}
                             else   {calNow.attachEvent('onclick',calStopPropagation);}
                             break;
                            }
                         else
                            {calNow.onclick=calNowOutput;
                             calNow.className='calNow';

                             if (calID('calIE'))
                                {calNow.onmouseover  = calChangeClass;
                                 calNow.onmouseout   = calChangeClass;
                                }
                            }
                        }
                    }
                }

             function calSetOutput(calOutputDate)
                {if (typeof calTargetEle.value == 'undefined')
                      {calTriggerEle.calTextNode.replaceData(0,calTriggerEle.calLength,calOutputDate.calFormat(calDateOutputFormat));}
                 else {calTargetEle.value = calOutputDate.calFormat(calDateOutputFormat);}
                 calHide();
                };

             function calCellOutput(calEvt)
                {var calEle = calEventTrigger(calEvt),
                     calOutputDate = new Date(calStartDate);

                 if (calEle.nodeType==3) calEle=calEle.parentNode;

                 calOutputDate.setDate(calStartDate.getDate() + parseInt(calEle.id.substr(8),10));

                 calSetOutput(calOutputDate);
                };

             function calChangeClass(calEvt)
                {var calEle = calEventTrigger(calEvt);

                 if (calEle.nodeType==3) {calEle=calEle.parentNode;}

                 switch (calEle.className)
                    {case 'calCells':
                        calEle.className = 'calCellsHover';
                        break;
                     case 'calCellsHover':
                        calEle.className = 'calCells';
                        break;
                     case 'calCellsExMonth':
                        calEle.className = 'calCellsExMonthHover';
                        break;
                     case 'calCellsExMonthHover':
                        calEle.className = 'calCellsExMonth';
                        break;
                     case 'calCellsWeekend':
                        calEle.className = 'calCellsWeekendHover';
                        break;
                     case 'calCellsWeekendHover':
                        calEle.className = 'calCellsWeekend';
                        break;
                     case 'calNow':
                        calEle.className = 'calNowHover';
                        break;
                     case 'calNowHover':
                        calEle.className = 'calNow';
                        break;
                     case 'calInputDate':
                        calEle.className = 'calInputDateHover';
                        break;
                     case 'calInputDateHover':
                        calEle.className = 'calInputDate';
                    }

                 return true;
                }

             function calEventTrigger(calEvt)
                {if (!calEvt) {calEvt = event;}
                 return calEvt.target||calEvt.srcElement;
                };

             function calWeekNumber(calInDate)
                {// The base day in the week of the input date
                 var calInDateWeekBase = new Date(calInDate);

                 calInDateWeekBase.setDate(calInDateWeekBase.getDate()
                                            - calInDateWeekBase.getDay()
                                            + calWeekNumberBaseDay
                                            + ((calInDate.getDay()>
                                                calWeekNumberBaseDay)?7:0));

                 // The first Base Day in the year
                 var calFirstBaseDay = new Date(calInDateWeekBase.getFullYear(),0,1);

                 calFirstBaseDay.setDate(calFirstBaseDay.getDate()
                                            - calFirstBaseDay.getDay()
                                            + calWeekNumberBaseDay
                                        );

                 if (calFirstBaseDay < new Date(calInDateWeekBase.getFullYear(),0,1))
                    {calFirstBaseDay.setDate(calFirstBaseDay.getDate()+7);}

                 var calStartWeekOne = new Date(calFirstBaseDay
                                                - calWeekNumberBaseDay
                                                + calInDate.getDay());

                 if (calStartWeekOne > calFirstBaseDay)
                    {calStartWeekOne.setDate(calStartWeekOne.getDate()-7);}

                 var calWeekNo = '0' + (Math.round((calInDateWeekBase - calFirstBaseDay)/604800000,0) + 1);

                 return calWeekNo.substring(calWeekNo.length-2, calWeekNo.length);
                };

             var calCells = calID('calCells');

             for (i=0;i<calCells.childNodes.length;i++)
                {var calRows = calCells.childNodes[i];
                 if (calRows.nodeType==1 && calRows.tagName=='TR')
                    {if (calWeekNumberDisplay)
                        {//Calculate the week number using calShowDate
                         calTmpEl = calRows.childNodes[0];
                         calTmpEl.innerHTML = calWeekNumber(calShowDate);
                         calTmpEl.style.borderColor =
                             (calTmpEl.currentStyle)
                                ?calTmpEl.currentStyle['backgroundColor']
                                :(window.getComputedStyle)
                                    ?document.defaultView.getComputedStyle(calTmpEl,null).getPropertyValue('background-color')
                                    :'';
                         calTmpEl.style.display='';
                        }
                     else
                        {calRows.childNodes[0].style.display='none';}

                     for (j=1;j<calRows.childNodes.length;j++)
                        {var calCols = calRows.childNodes[j];
                         if (calCols.nodeType==1 && calCols.tagName=='TD')
                            {calRows.childNodes[j].innerHTML=
                                calShowDate.getDate();
                             var calCell=calRows.childNodes[j],
                                 calDisabled =
                                    ((calOutOfRangeDisable &&
                                        (calShowDate <
                                            (new Date(calBaseYear,0,1,
                                                      calShowDate.getHours()))
                                         ||
                                         calShowDate >
                                            (new Date(calBaseYear+
                                                      calDropDownYears,0,0,
                                                      calShowDate.getHours()))
                                        )
                                     ) ||
                                     (calOutOfMonthDisable &&
                                        (calShowDate <
                                            (new Date(calShowDate.getFullYear(),
                                                      calCurMonth,1,
                                                      calShowDate.getHours()))
                                         ||
                                         calShowDate >
                                            (new Date(calShowDate.getFullYear(),
                                                      calCurMonth+1,0,
                                                      calShowDate.getHours()))
                                        )
                                     )
                                    )?true:false;

                             calCell.style.visibility =
                                (calOutOfMonthHide &&
                                    (calShowDate <
                                        (new Date(calShowDate.getFullYear(),
                                                  calCurMonth,1,
                                                  calShowDate.getHours()))
                                     ||
                                     calShowDate >
                                        (new Date(calShowDate.getFullYear(),
                                                  calCurMonth+1,0,
                                                  calShowDate.getHours()))
                                    )
                                )?'hidden':'inherit';

                             for (var k=0;k<calDisabledDates.length;k++)
                                {if ((typeof calDisabledDates[k]=='object') &&
                                     (calDisabledDates[k].constructor == Date) &&
                                     calCompareDateValue == calDisabledDates[k].valueOf()
                                    )
                                    {calDisabled = true;}
                                 else
                                    {if ((typeof calDisabledDates[k]=='object') &&
                                         (calDisabledDates[k].constructor == Array) &&
                                         calCompareDateValue >= calDisabledDates[k][0].valueOf() &&
                                         calCompareDateValue <= calDisabledDates[k][1].valueOf()
                                        )
                                        {calDisabled = true;}
                                    }
                                }

                             if (calDisabled ||
                                 !calEnabledDay[j-1+(7*((i*calCells.childNodes.length)/6))] ||
                                 !calPassEnabledDay[(j-1+(7*(i*calCells.childNodes.length/6)))%7]
                                )
                                {calRows.childNodes[j].onclick = null;

                                 if (calID('calIE'))
                                    {calRows.childNodes[j].onmouseover  = null;
                                     calRows.childNodes[j].onmouseout   = null;
                                    }

                                 calCell.className=
                                    (calShowDate.getMonth()!=calCurMonth)
                                        ?'calCellsExMonthDisabled'
                                        :(calBlnFullInputDate &&
                                          calShowDate.toDateString()==
                                          calSeedDate.toDateString())
                                            ?'calInputDateDisabled'
                                            :(calShowDate.getDay()%6==0)
                                                ?'calCellsWeekendDisabled'
                                                :'calCellsDisabled';

                                 calCell.style.borderColor =
                                     (calFormatTodayCell && calShowDate.toDateString()==calDateNow.toDateString())
                                        ?calTodayCellBorderColour
                                        :(calCell.currentStyle)
                                            ?calCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(calCell,null).getPropertyValue('background-color')
                                                :'';
                                }
                             else
                                {calRows.childNodes[j].onclick=calCellOutput;

                                 if (calID('calIE'))
                                    {calRows.childNodes[j].onmouseover  = calChangeClass;
                                     calRows.childNodes[j].onmouseout   = calChangeClass;
                                    }

                                 calCell.className=
                                     (calShowDate.getMonth()!=calCurMonth)
                                        ?'calCellsExMonth'
                                        :(calBlnFullInputDate &&
                                          calShowDate.toDateString()==
                                          calSeedDate.toDateString())
                                            ?'calInputDate'
                                            :(calShowDate.getDay()%6==0)
                                                ?'calCellsWeekend'
                                                :'calCells';

                                 calCell.style.borderColor =
                                     (calFormatTodayCell && calShowDate.toDateString() == calDateNow.toDateString())
                                        ?calTodayCellBorderColour
                                        :(calCell.currentStyle)
                                            ?calCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(calCell,null).getPropertyValue('background-color')
                                                :'';
                               }

                             calShowDate.setDate(calShowDate.getDate()+1);
                             calCompareDateValue = new Date(calShowDate.getFullYear(),calShowDate.getMonth(),calShowDate.getDate()).valueOf();
                            }
                        }
                    }
                }
            }

         if (window.opera)
            {calID('calMonths').style.display = 'inline';
             calID('calYears' ).style.display = 'inline';
             calID('cal').style.visibility='hidden';
             calID('cal').style.visibility='inherit';
           }
        };

// *************************
//  End of Function Library
// *************************
// ***************************
// Start of Calendar structure
// ***************************

    document.writeln("<!--[if IE]><div id='calIE'></div><![endif]-->");
    document.writeln("<!--[if lt IE 7]><div id='calIElt7'></div><![endif]-->");
    document.write(
     "<iframe class='cal' " + (calID('calIElt7')?"src='/calblank.html '":'') +
             "id='calIframe' name='calIframe' frameborder='0'>" +
     "</iframe>" +
     "<table id='cal' class='cal'>" +
       "<tr class='cal'>" +
         "<td class='cal'>" +
           "<table class='calHead' id='calHead' width='100%' " +
                    "cellspacing='0' cellpadding='0'>" +
            "<tr id='calDrag' style='display:none;'>" +
                "<td colspan='4' class='calDrag' " +
                    "onmousedown='calBeginDrag(event);'>" +
                    "<span id='calDragText'></span>" +
                "</td>" +
            "</tr>" +
            "<tr class='calHead' >" +
                 "<td class='calHead'>" +
                    "<input class='calHead' id='calHeadLeft' type='button' value='<' " +
                            "onclick='calShowMonth(-1);'  /></td>" +
                 "<td class='calHead'>" +
                    "<select id='calMonths' class='calHead' " +
                            "onchange='calShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='calHead'>" +
                    "<select id='calYears' class='calHead' " +
                            "onchange='calShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='calHead'>" +
                    "<input class='calHead' id='calHeadRight' type='button' value='>' " +
                            "onclick='calShowMonth(1);' /></td>" +
                "</tr>" +
              "</table>" +
            "</td>" +
          "</tr>" +
          "<tr class='cal'>" +
            "<td class='cal'>" +
              "<table class='calCells' align='center'>" +
                "<thead>" +
                  "<tr><td class='calWeekNumberHead' id='calWeek_' ></td>");

    for (i=0;i<7;i++)
        {document.write(
                      "<td class='calWeek' id='calWeekInit" + i + "'></td>");
        }

    document.write("</tr>" +
                "</thead>" +
                "<tbody id='calCells' onClick='calStopPropagation(event);'>");

    for (i=0;i<6;i++)
        {document.write(
                    "<tr>" +
                      "<td class='calWeekNo' id='calWeek_" + i + "'></td>");
         for (j=0;j<7;j++)
            {document.write(
                        "<td class='calCells' id='calCell_" + (j+(i*7)) +
                        "'></td>");
            }

         document.write(
                    "</tr>");
        }

    document.write(
                "</tbody>" +
                "<tfoot>" +
                  "<tr id='calFoot'>" +
                    "<td colspan='8' style='padding:0px;'>" +
                      "<table width='100%'>" +
                        "<tr>" +
                          "<td id='calClear' class='calClear'>" +
                            "<input type='button' id='calClearButton' class='calClear' " +
                                   "onclick='calTargetEle.value = \"\";calHide();' />" +
                          "</td>" +
                          "<td class='calNow' id='calNow'></td>" +
                        "</tr>" +
                      "</table>" +
                    "</td>" +
                  "</tr>" +
                "</tfoot>" +
              "</table>" +
            "</td>" +
          "</tr>" +
        "</table>");

    if (document.addEventListener)
            {calID('cal'         ).addEventListener('click',calCancel,false);
             calID('calHeadLeft' ).addEventListener('click',calStopPropagation,false);
             calID('calMonths'   ).addEventListener('click',calStopPropagation,false);
             calID('calMonths'   ).addEventListener('change',calStopPropagation,false);
             calID('calYears'    ).addEventListener('click',calStopPropagation,false);
             calID('calYears'    ).addEventListener('change',calStopPropagation,false);
             calID('calHeadRight').addEventListener('click',calStopPropagation,false);
            }
    else    {calID('cal'         ).attachEvent('onclick',calCancel);
             calID('calHeadLeft' ).attachEvent('onclick',calStopPropagation);
             calID('calMonths'   ).attachEvent('onclick',calStopPropagation);
             calID('calMonths'   ).attachEvent('onchange',calStopPropagation);
             calID('calYears'    ).attachEvent('onclick',calStopPropagation);
             calID('calYears'    ).attachEvent('onchange',calStopPropagation);
             calID('calHeadRight').attachEvent('onclick',calStopPropagation);
            }

// ***************************
//  End of Calendar structure
// ***************************
// ****************************************
// Start of document level event definition
// ****************************************

    if (document.addEventListener)
            {document.addEventListener('click',calHide, false);}
    else    {document.attachEvent('onclick',calHide);}

// ****************************************
//  End of document level event definition
// ****************************************
// ************************************
//  End of Simple Calendar Widget Code
// ************************************