// *****************************************************************************
//      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 cruDateNow = new Date(Date.parse(new Date().toDateString()));

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

    var cruBaseYear        = 2009;

    var cruDropDownYears   = 2;

    var cruLanguage;

    function cruSetDefaultLanguage()
        {try
            {cruSetLanguage();}
         catch (exception)
            {// Deutsch
             cruToday               = 'Heute:';
             cruClear               = 'Clear';
             cruDrag                = 'click here to drag';
             cruArrMonthNames       = ['Jan','Feb','Mar','Apr','Mai','Jun',
                                       'Jul','Aug','Sep','Okt','Nov','Dez'];
             cruArrWeekInits        = ['So','Mo','Di','Mi','Do','Fr','Sa'];
             cruInvalidDateMsg      = 'Das eigetragene Datum ist ungültig.\n';
             cruOutOfRangeMsg       = 'Das eigetragene Datum ist ausserhalb des möglichen Zeitraums.';
             cruDoesNotExistMsg     = 'Das eigetragene Datum existiert nicht.';
             cruInvalidAlert        = ['Ungültiges Datum (',') ignoriert.'];
             cruDateDisablingError  = ['Fehler ',' ist kein Datum.'];
             cruRangeDisablingError = ['Fehler ',
                                       ' should consist of two elements.'];
            }
        };

    var cruWeekStart       =    1;

    var cruWeekNumberDisplay    = false;

    var cruWeekNumberBaseDay    = 4;

    var cruShowInvalidDateMsg       = false,
        cruShowOutOfRangeMsg        = false,
        cruShowDoesNotExistMsg      = false,
        cruShowInvalidAlert         = false,
        cruShowDateDisablingError   = false,
        cruShowRangeDisablingError  = false;

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

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

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

    var cruZindex          = 1;

    var cruBlnStrict       = false;

    var cruClearButton     = true;

    var cruAutoPosition    = true;

    var cruEnabledDay      = [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 cruDisabledDates   = new Array();

    cruDisabledDates[1] = [new Date(2009,0,1),new Date(2009,8,23)];
    cruDisabledDates[3] = [new Date(2009,8,25),new Date(2009,8,30)];
    cruDisabledDates[4] = [new Date(2009,9,2),new Date(2009,9,7)];
    cruDisabledDates[5] = [new Date(2009,9,9),new Date(2009,9,14)];
    cruDisabledDates[6] = [new Date(2009,9,16),new Date(2009,9,21)];
    cruDisabledDates[7] = [new Date(2009,9,23),new Date(2009,9,28)];
    cruDisabledDates[8] = [new Date(2009,9,30),new Date(2009,10,4)];
    cruDisabledDates[9] = [new Date(2009,10,6),new Date(2009,10,11)];
    cruDisabledDates[11] = [new Date(2009,10,13),new Date(2009,10,18)];
    cruDisabledDates[14] = [new Date(2009,10,20),new Date(2009,10,25)];
    cruDisabledDates[15] = [new Date(2009,10,27),new Date(2009,11,2)];
    cruDisabledDates[16] = [new Date(2009,11,4),new Date(2009,11,9)];
    cruDisabledDates[17] = [new Date(2009,11,11),new Date(2009,11,16)];
    cruDisabledDates[18] = [new Date(2009,11,18),new Date(2010,0,6)];
    cruDisabledDates[19] = [new Date(2010,0,8),new Date(2010,0,13)];
    cruDisabledDates[20] = [new Date(2010,0,15),new Date(2010,0,20)];
    cruDisabledDates[21] = [new Date(2010,0,22),new Date(2010,0,27)];
    cruDisabledDates[22] = [new Date(2010,0,29),new Date(2010,1,3)];
    cruDisabledDates[23] = [new Date(2010,1,5),new Date(2010,1,10)];
    cruDisabledDates[24] = [new Date(2010,1,12),new Date(2010,1,17)];
    cruDisabledDates[25] = [new Date(2010,1,19),new Date(2010,1,24)];
    cruDisabledDates[26] = [new Date(2010,1,26),new Date(2010,2,3)];
    cruDisabledDates[27] = [new Date(2010,2,5),new Date(2010,2,10)];
    cruDisabledDates[28] = [new Date(2010,2,12),new Date(2010,2,17)];
    cruDisabledDates[29] = [new Date(2010,2,19),new Date(2010,2,24)];
    cruDisabledDates[30] = [new Date(2010,2,26),new Date(2010,2,31)];
    cruDisabledDates[31] = [new Date(2010,3,2),new Date(2010,3,7)];
    cruDisabledDates[32] = [new Date(2010,3,9),new Date(2010,3,14)];
    cruDisabledDates[33] = [new Date(2010,3,16),new Date(2010,3,21)];
    cruDisabledDates[34] = [new Date(2010,3,23),new Date(2010,3,28)];
    cruDisabledDates[35] = [new Date(2010,3,30),new Date(2010,4,5)];
    cruDisabledDates[36] = [new Date(2010,4,7),new Date(2010,4,12)];
    cruDisabledDates[37] = [new Date(2010,4,14),new Date(2010,4,19)];
    cruDisabledDates[38] = [new Date(2010,4,21),new Date(2010,4,26)];
    cruDisabledDates[39] = [new Date(2010,4,28),new Date(2010,11,31)];

    var cruActiveToday = false;
    var cruOutOfMonthDisable = false;
    var cruOutOfMonthHide    = true;
    var cruOutOfRangeDisable = true;
    var cruFormatTodayCell = true;
    var cruTodayCellBorderColour = 'red';
    var cruAllowDrag = false;
    var cruClickToHide = true;


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

    document.writeln(
        '<style type="text/css">'                                       +
            '/* IMPORTANT:  The SCW calendar script requires all '      +
            '               the classes defined here.'                  +
            '*/'                                                        +
            'table.cru      {padding:       1px;'                       +
                            'vertical-align:middle;'                    +
                            'border:        ridge 2px;'                 +
                            'font-size:     10pt;'                      +
                            'font-family:   ' +
                                   'Verdana,Arial,Helvetica,Sans-Serif;'+
                            'font-weight:   bold;}'                     +
            'td.cruDrag,'                                               +
            'td.cruHead                 {padding:       0px 0px;'       +
                                        'text-align:    center;}'       +
            'td.cruDrag                 {font-size:     8pt;}'          +
            'select.cruHead             {margin:        3px 1px;'       +
                                        'text-align:    center;}'       +
            'input.cruHead              {height:        22px;'          +
                                        'width:         22px;'          +
                                        'vertical-align:middle;'        +
                                        'text-align:    center;'        +
                                        'margin:        2px 1px;'       +
                                        'font-weight:   bold;'          +
                                        'font-size:     10pt;'          +
                                        'font-family:   fixedSys;}'     +
            'td.cruWeekNumberHead,'                                     +
            'td.cruWeek                 {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'font-weight:   bold;}'         +
            'td.cruNow,'                                                +
            'td.cruNowHover,'                                           +
            'td.cruNow:hover,'                                          +
            'td.cruNowDisabled          {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'vertical-align:middle;'        +
                                        'font-weight:   normal;}'       +
            'table.cruCells             {text-align:    right;'         +
                                        'font-size:     8pt;'           +
                                        'width:         96%;}'          +
            'td.cruCells,'                  +
            'td.cruCellsHover,'             +
            'td.cruCells:hover,'            +
            'td.cruCellsDisabled,'          +
            'td.cruCellsExMonth,'           +
            'td.cruCellsExMonthHover,'      +
            'td.cruCellsExMonth:hover,'     +
            'td.cruCellsExMonthDisabled,'   +
            'td.cruCellsWeekend,'           +
            'td.cruCellsWeekendHover,'      +
            'td.cruCellsWeekend:hover,'     +
            'td.cruCellsWeekendDisabled,'   +
            'td.cruInputDate,'              +
            'td.cruInputDateHover,'         +
            'td.cruInputDate:hover,'        +
            'td.cruInputDateDisabled,'      +
            'td.cruWeekNo,'                 +
            'td.cruWeeks                {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.cru                  {background-color:  #0040FF;}'  +
            '/* Drag Handle */'                                         +
            'td.cruDrag                 {background-color:  #9999CC;'   +
                                        'color:             #CCCCFF;}'  +
            '/* Week number heading */'                                 +
            'td.cruWeekNumberHead       {color:             #6666CC;}'  +
            '/* Week day headings */'                                   +
            'td.cruWeek                 {color:             #CCCCCC;}'  +
            '/* Week numbers */'                                        +
            'td.cruWeekNo               {background-color:  #776677;'   +
                                        'color:             #CCCCCC;}'  +
            '/* Enabled Days */'                                        +
            '/* Week Day */'                                            +
            'td.cruCells                {background-color:  #A0FF00;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.cruInputDate            {background-color:  #CC9999;'   +
                                        'color:             #FF0000;}'  +
            '/* Weekend Day */'                                         +
            'td.cruCellsWeekend         {background-color:  #A0FF00;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.cruCellsExMonth         {background-color:  #CCCCCC;'   +
                                        'color:             #666666;}'  +
            '/* Today selector */'                                      +
            'td.cruNow                  {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
            '/* Clear Button */'                                        +
            'td.cruClear                {padding:           0px;}'      +
            'input.cruClear             {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.cruCells:hover,'                                        +
            'td.cruCellsHover           {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.cruInputDate:hover,'                                    +
            'td.cruInputDateHover       {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Weekend cells */'                                       +
            'td.cruCellsWeekend:hover,'                                 +
            'td.cruCellsWeekendHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day outside the current month */'                       +
            'td.cruCellsExMonth:hover,'                                 +
            'td.cruCellsExMonthHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Today selector */'                                      +
            'td.cruNow:hover,'                                          +
            'td.cruNowHover             {color:             #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'font-weight:       bold;}'     +
            '/* Disabled cells */'                                      +
            '/* Week Day */'                                            +
            '/* Day matching the input date */'                         +
            'td.cruInputDateDisabled    {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            'td.cruCellsDisabled        {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            '/* Weekend Day */'                                         +
            'td.cruCellsWeekendDisabled {background-color:  #999999;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.cruCellsExMonthDisabled {background-color:  #999999;'   +
                                        'color:             #666666;}'  +
            'td.cruNowDisabled          {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
        '</style>'
                    );

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

    var cruTargetEle,
        cruTriggerEle,
        cruMonthSum            = 0,
        cruBlnFullInputDate    = false,
        cruPassEnabledDay      = new Array(),
        cruSeedDate            = new Date(),
        cruParmActiveToday     = true,
        cruWeekStart           = cruWeekStart%7,
        cruToday,
        cruClear,
        cruDrag,
        cruArrMonthNames,
        cruArrWeekInits,
        cruInvalidDateMsg,
        cruOutOfRangeMsg,
        cruDoesNotExistMsg,
        cruInvalidAlert,
        cruDateDisablingError,
        cruRangeDisablingError;

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

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

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

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

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

    String.prototype.cruPadLeft =
        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()==cruTriggerEle)?func.apply(this, args):null;
                        };
                    };

    function cruID(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 cruNextActionReturn, cruNextAction;

    function showCal(cruEle,cruSource) {cruShow(cruEle,cruSource);};
    function cruShow(cruEle,cruSource)
        {if (!cruSource) {cruSource = window.event;}

         if (cruSource.tagName)
            {var cruSourceEle = cruSource;

             if (cruID('cruIE'))  {window.event.cancelBubble = true;}
             else {cruSourceEle.parentNode.addEventListener('click',cruStopPropagation,false);}
            }
         else
            {var cruSourceEle = (cruSource.target)
                                    ?cruSource.target
                                    :cruSource.srcElement;

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

         cruTriggerEle = cruSourceEle;

         cruParmActiveToday = true;

         for (var i=0;i<7;i++)
            {cruPassEnabledDay[(i+7-cruWeekStart)%7] = true;
             for (var j=2;j<arguments.length;j++)
                {if (arguments[j]==i)
                    {cruPassEnabledDay[(i+7-cruWeekStart)%7] = false;
                     if (cruDateNow.getDay()==i) {cruParmActiveToday = false;}
                    }
                }
            }

         cruSeedDate = cruDateNow;

         var cruDateValue = '';

         if (cruEle.value) {cruDateValue = cruEle.value.replace(/^\s+/,'').replace(/\s+$/,'');}
         else   {if (typeof cruEle.value == 'undefined')
                    {var cruChildNodes = cruEle.childNodes;
                     for (var i=0;i<cruChildNodes.length;i++)
                        {if (cruChildNodes[i].nodeType == 3)
                            {cruDateValue = cruChildNodes[i].nodeValue.replace(/^\s+/,'').replace(/\s+$/,'');
                             if (cruDateValue.length > 0)
                                {cruTriggerEle.cruTextNode = cruChildNodes[i];
                                 cruTriggerEle.cruLength   = cruChildNodes[i].nodeValue.length;
                                 break;
                                }
                            }
                        }
                    }
                }

         cruSetDefaultLanguage();

         cruID('cruDragText').innerHTML = cruDrag;

         cruID('cruMonths').options.length = 0;
         for (var i=0;i<cruArrMonthNames.length;i++)
            {cruID('cruMonths').options[i] = new Option(cruArrMonthNames[i],cruArrMonthNames[i]);}

         cruID('cruYears').options.length = 0;
         for (var i=0;i<cruDropDownYears;i++)
            {cruID('cruYears').options[i] =  new Option((cruBaseYear+i),(cruBaseYear+i));}

         for (var i=0;i<cruArrWeekInits.length;i++)
            {cruID('cruWeekInit' + i).innerHTML = cruArrWeekInits[(i+cruWeekStart)%cruArrWeekInits.length];}

         if (((new Date(cruBaseYear + cruDropDownYears, 0, 0)) > cruDateNow &&
              (new Date(cruBaseYear, 0, 0))                    < cruDateNow) ||
             (cruClearButton && (cruEle.readOnly || cruEle.disabled))
            )   {cruID('cruFoot').style.display = '';
                 cruID('cruNow').innerHTML = '<p onclick=cruHide()>Kalender ausblenden';
                 cruID('cruClearButton').value = cruClear;
                 if ((new Date(cruBaseYear + cruDropDownYears, 0, 0)) > cruDateNow &&
                     (new Date(cruBaseYear, 0, 0))                    < cruDateNow
                    )   {cruID('cruNow').style.display = '';
                         if (cruClearButton && (cruEle.readOnly || cruEle.disabled))
                                {cruID('cruClear').style.display   = '';
                                 cruID('cruClear').style.textAlign = 'left';
                                 cruID('cruNow').style.textAlign   = 'right';
                                }
                         else   {cruID('cruClear').style.display = 'none';
                                 cruID('cruNow').style.textAlign = 'center';
                                }
                        }
                 else   {cruID('cruClear').style.textAlign = 'center';
                         cruID('cruClear').style.display = '';
                         cruID('cruNow').style.display = 'none';
                        }
                }
         else   {cruID('cruFoot').style.display = 'none';}

         if (cruDateValue.length==0)
            {
             cruBlnFullInputDate=false;

             if ((new Date(cruBaseYear+cruDropDownYears,0,0))<cruSeedDate ||
                 (new Date(cruBaseYear,0,1))                 >cruSeedDate
                )
                {cruSeedDate = new Date(cruBaseYear + Math.floor(cruDropDownYears / 2), 5, 1);}
            }
         else
            {function cruInputFormat()
                {var cruArrSeed = new Array(),
                     cruArrInput = cruDateValue.split(new RegExp('[\\'+cruArrDelimiters.join('\\')+']+','g'));

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

                 cruBlnFullInputDate = false;

                 cruDateOutputFormat = cruDateOutputFormat.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 (cruDateOutputFormat.search(template[i])>-1)
                        {result[cruDateOutputFormat.search(template[i])] = template[i];}
                    }

                 var cruDateSequence = result.join('');

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

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

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

                         if (cruArrInput[0].length==cruDateOutputFormat.length) {cruBlnFullInputDate = true;}
                         break;
                        }
                     case 2:
                        {// Year and Month entry
                         cruArrSeed[0] =
                             parseInt(cruArrInput[cruDateSequence.
                                                    replace(/D/i,'').
                                                    search(/Y/i)],10);  // Year
                         cruArrSeed[1] = cruArrInput[cruDateSequence.
                                                    replace(/D/i,'').
                                                    search(/M/i)];      // Month
                         cruArrSeed[2] = 1;                             // Day
                         break;
                        }
                     case 3:
                        {// Day Month and Year entry

                         cruArrSeed[0] =
                             parseInt(cruArrInput[cruDateSequence.
                                                    search(/Y/i)],10);  // Year
                         cruArrSeed[1] = cruArrInput[cruDateSequence.
                                                    search(/M/i)];      // Month
                         cruArrSeed[2] =
                             parseInt(cruArrInput[cruDateSequence.
                                                    search(/D/i)],10);  // Day

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


                 var cruExpValDay    = new RegExp('^(0?[1-9]|[1-2][0-9]|3[0-1])$'),
                     cruExpValMonth  = new RegExp('^(0?[1-9]|1[0-2]|'        +
                                                  cruArrMonthNames.join('|') +
                                                  ')$','i'),
                     cruExpValYear   = new RegExp('^([0-9]{1,2}|[0-9]{4})$');


                 if (cruExpValYear.exec(cruArrSeed[0])  == null ||
                     cruExpValMonth.exec(cruArrSeed[1]) == null ||
                     cruExpValDay.exec(cruArrSeed[2])   == null
                    )
                    {if (cruShowInvalidDateMsg)
                        {alert(cruInvalidDateMsg  +
                               cruInvalidAlert[0] + cruDateValue +
                               cruInvalidAlert[1]);}
                     cruBlnFullInputDate = false;
                     cruArrSeed[0] = cruBaseYear +
                                     Math.floor(cruDropDownYears/2); // Year
                     cruArrSeed[1] = '6';                            // Month
                     cruArrSeed[2] = 1;                              // Day
                    }


                 return cruArrSeed;
                };


             cruArrSeedDate = cruInputFormat();


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


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

             cruSeedDate = new Date(cruArrSeedDate[0],cruArrSeedDate[1]-1,cruArrSeedDate[2]);
            }

         if (isNaN(cruSeedDate))
            {if (cruShowInvalidDateMsg) {alert(cruInvalidDateMsg + cruInvalidAlert[0] + cruDateValue + cruInvalidAlert[1]);}
             cruSeedDate = new Date(cruBaseYear + Math.floor(cruDropDownYears/2),5,1);
             cruBlnFullInputDate=false;
            }
         else
            {
             if ((new Date(cruBaseYear,0,1)) > cruSeedDate)
                {if (cruBlnStrict && cruShowOutOfRangeMsg) {alert(cruOutOfRangeMsg);}
                 cruSeedDate = new Date(cruBaseYear,0,1);
                 cruBlnFullInputDate=false;
                }
             else
                {if ((new Date(cruBaseYear+cruDropDownYears,0,0))<cruSeedDate)
                    {if (cruBlnStrict && cruShowOutOfRangeMsg) {alert(cruOutOfRangeMsg);}
                     cruSeedDate = new Date(cruBaseYear + Math.floor(cruDropDownYears)-1,11,1);
                     cruBlnFullInputDate=false;
                    }
                 else
                    {if (cruBlnStrict && cruBlnFullInputDate &&
                          (cruSeedDate.getDate()      != cruArrSeedDate[2] ||
                           (cruSeedDate.getMonth()+1) != cruArrSeedDate[1] ||
                           cruSeedDate.getFullYear()  != cruArrSeedDate[0]
                          )
                        )
                        {if (cruShowDoesNotExistMsg) alert(cruDoesNotExistMsg);
                         cruSeedDate = new Date(cruSeedDate.getFullYear(),cruSeedDate.getMonth()-1,1);
                         cruBlnFullInputDate=false;
                        }
                    }
                }
            }


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

                     if (cruDisabledDates[i].length !=2)
                        {if (cruShowRangeDisablingError)
                            {alert(cruRangeDisablingError[0] + cruDisabledDates[i] + cruRangeDisablingError[1]);}
                         cruPass = false;
                        }
                     else
                        {for (var j=0;j<cruDisabledDates[i].length;j++)
                            {if (!((typeof cruDisabledDates[i][j] == 'object') && (cruDisabledDates[i][j].constructor == Date)))
                                {if (cruShowRangeDisablingError)
                                    {alert(  cruDateDisablingError[0] + cruDisabledDates[i][j] + cruDateDisablingError[1]);}
                                 cruPass = false;
                                }
                            }
                        }

                     if (cruPass && (cruDisabledDates[i][0] > cruDisabledDates[i][1])) {cruDisabledDates[i].reverse();}
                    }
                 else
                    {if (cruShowRangeDisablingError) {alert(cruDateDisablingError[0] + cruDisabledDates[i] + cruDateDisablingError[1]);}}
                }
            }

         cruMonthSum =  12*(cruSeedDate.getFullYear()-cruBaseYear)+cruSeedDate.getMonth();

         cruID('cruYears' ).options.selectedIndex = Math.floor(cruMonthSum/12);
         cruID('cruMonths').options.selectedIndex = (cruMonthSum%12);
         cruID('cruDrag').style.display=(cruAllowDrag)?'':'none';

         cruShowMonth(0);

         cruTargetEle=cruEle;

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

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

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

         if (cruAutoPosition)
             {var cruWidth      = parseInt(cruID('cru').offsetWidth, 10),
                  cruHeight     = parseInt(cruID('cru').offsetHeight,10),
                  cruWindowLeft =
                     (document.body && document.body.scrollLeft)
                          ?document.body.scrollLeft                  //DOM compliant
                          :(document.documentElement && document.documentElement.scrollLeft)
                              ?document.documentElement.scrollLeft   //IE6+ standards compliant
                              :0,                                    //Failed
                  cruWindowWidth =
                      (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
                  cruWindowTop =
                      (document.body && document.body.scrollTop)
                          ?document.body.scrollTop                   //DOM compliant
                          :(document.documentElement && document.documentElement.scrollTop)
                              ?document.documentElement.scrollTop    //IE6+ standards compliant
                              :0,                                    //Failed
                  cruWindowHeight =
                      (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 - cruWidth + parseInt(cruTargetEle.offsetWidth,10) >= cruWindowLeft &&
                             offsetLeft + cruWidth > cruWindowLeft + cruWindowWidth
                            )?(cruWidth - parseInt(cruTargetEle.offsetWidth,10)):0;

              offsetTop -= (offsetTop - cruHeight - parseInt(cruTargetEle.offsetHeight,10) >= cruWindowTop &&
                            offsetTop + cruHeight > cruWindowTop + cruWindowHeight
                           )?(cruHeight + parseInt(cruTargetEle.offsetHeight,10)):0;
             }

         cruID('cru').style.top         = offsetTop+'px';
         cruID('cru').style.left        = offsetLeft+'px';
         cruID('cruIframe').style.top   = offsetTop+'px';
         cruID('cruIframe').style.left  = offsetLeft+'px';

         cruID('cruIframe').style.width =(cruID('cru').offsetWidth-(cruID('cruIE')?2:4))+'px';
         cruID('cruIframe').style.height=(cruID('cru').offsetHeight-(cruID('cruIE')?2:4))+'px';
         cruID('cruIframe').style.visibility='inherit';

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

    function cruHide()
        {cruID('cru').style.visibility='hidden';
         cruID('cruIframe').style.visibility='hidden';
         if (typeof cruNextAction!='undefined' && cruNextAction!=null)
             {cruNextActionReturn = cruNextAction();
              // Explicit null set to prevent closure causing memory leak
              cruNextAction = null;
             }
        };

    function cruCancel(cruEvt)
        {if (cruClickToHide) {cruHide();}
         cruStopPropagation(cruEvt);
        };

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

    function cruBeginDrag(event)
        {var elementToDrag = cruID('cru');

         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();
                }

         cruStopPropagation(event);

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

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

             cruID('cruIframe').style.left = (cruEvt.clientX - deltaX) + 'px';
             cruID('cruIframe').style.top  = (cruEvt.clientY - deltaY) + 'px';

             cruStopPropagation(cruEvt);
            };

         function upHandler(cruEvt)
            {if (!cruEvt) cruEvt = 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();
                    }

             cruStopPropagation(cruEvt);
            };
        };

    function cruShowMonth(cruBias)
        {

         var cruShowDate  = new Date(Date.parse(new Date().toDateString())),
             cruStartDate = new Date();

         cruShowDate.setHours(12);

         cruSelYears  = cruID('cruYears');
         cruSelMonths = cruID('cruMonths');

         if (cruSelYears.options.selectedIndex>-1)
            {cruMonthSum=12*(cruSelYears.options.selectedIndex)+cruBias;
             if (cruSelMonths.options.selectedIndex>-1) {cruMonthSum+=cruSelMonths.options.selectedIndex;}
            }
         else
            {if (cruSelMonths.options.selectedIndex>-1) {cruMonthSum+=cruSelMonths.options.selectedIndex;}}

         cruShowDate.setFullYear(cruBaseYear + Math.floor(cruMonthSum/12),(cruMonthSum%12),1);

         cruID('cruWeek_').style.display=(cruWeekNumberDisplay)?'':'none';

         if (window.opera)
            {cruID('cruMonths').style.display = 'inherit';
             cruID('cruYears' ).style.display = 'inherit';
           }

         cruTemp = (12*parseInt((cruShowDate.getFullYear()-cruBaseYear),10)) + parseInt(cruShowDate.getMonth(),10);

         if (cruTemp > -1 && cruTemp < (12*cruDropDownYears))
            {cruSelYears.options.selectedIndex=Math.floor(cruMonthSum/12);
             cruSelMonths.options.selectedIndex=(cruMonthSum%12);

             cruCurMonth = cruShowDate.getMonth();

             cruShowDate.setDate((((cruShowDate.
                                    getDay()-cruWeekStart)<0)?-6:1)+
                                 cruWeekStart-cruShowDate.getDay());

             var cruCompareDateValue = new Date(cruShowDate.getFullYear(),
                                                cruShowDate.getMonth(),
                                                cruShowDate.getDate()).valueOf();

             cruStartDate = new Date(cruShowDate);

             if ((new Date(cruBaseYear + cruDropDownYears, 0, 0)) > cruDateNow &&
                 (new Date(cruBaseYear, 0, 0))                    < cruDateNow)
                {var cruNow = cruID('cruNow');

                 function cruNowOutput() {cruSetOutput(cruDateNow);};

                 if (cruDisabledDates.length==0)
                    {if (cruActiveToday && cruParmActiveToday)
                        {cruNow.onclick     = cruNowOutput;
                         cruNow.className   = 'cruNow';

                         if (cruID('cruIE'))
                            {cruNow.onmouseover  = cruChangeClass;
                             cruNow.onmouseout   = cruChangeClass;
                            }

                        }
                     else
                        {cruNow.onclick     = null;
                         cruNow.className   = 'cruNowDisabled';

                         if (cruID('cruIE'))
                            {cruNow.onmouseover  = null;
                             cruNow.onmouseout   = null;
                            }

                         if (document.addEventListener)
                                {cruNow.addEventListener('click',cruStopPropagation,false);}
                         else   {cruNow.attachEvent('onclick',cruStopPropagation);}
                        }
                    }
                 else
                    {for (var k=0;k<cruDisabledDates.length;k++)
                        {if (!cruActiveToday || !cruParmActiveToday ||
                             ((typeof cruDisabledDates[k] == 'object')                   &&
                                 (((cruDisabledDates[k].constructor == Date)             &&
                                   cruDateNow.valueOf() == cruDisabledDates[k].valueOf()
                                  ) ||
                                  ((cruDisabledDates[k].constructor == Array)               &&
                                   cruDateNow.valueOf() >= cruDisabledDates[k][0].valueOf() &&
                                   cruDateNow.valueOf() <= cruDisabledDates[k][1].valueOf()
                                  )
                                 )
                             )
                            )
                            {cruNow.onclick     = null;
                             cruNow.className   = 'cruNowDisabled';

                             if (cruID('cruIE'))
                                {cruNow.onmouseover  = null;
                                 cruNow.onmouseout   = null;
                                }

                             if (document.addEventListener)
                                    {cruNow.addEventListener('click',cruStopPropagation,false);}
                             else   {cruNow.attachEvent('onclick',cruStopPropagation);}
                             break;
                            }
                         else
                            {cruNow.onclick=cruNowOutput;
                             cruNow.className='cruNow';

                             if (cruID('cruIE'))
                                {cruNow.onmouseover  = cruChangeClass;
                                 cruNow.onmouseout   = cruChangeClass;
                                }
                            }
                        }
                    }
                }

             function cruSetOutput(cruOutputDate)
                {if (typeof cruTargetEle.value == 'undefined')
                      {cruTriggerEle.cruTextNode.replaceData(0,cruTriggerEle.cruLength,cruOutputDate.cruFormat(cruDateOutputFormat));}
                 else {cruTargetEle.value = cruOutputDate.cruFormat(cruDateOutputFormat);}
                 cruHide();
                };

             function cruCellOutput(cruEvt)
                {var cruEle = cruEventTrigger(cruEvt),
                     cruOutputDate = new Date(cruStartDate);

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

                 cruOutputDate.setDate(cruStartDate.getDate() + parseInt(cruEle.id.substr(8),10));

                 cruSetOutput(cruOutputDate);
                };

             function cruChangeClass(cruEvt)
                {var cruEle = cruEventTrigger(cruEvt);

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

                 switch (cruEle.className)
                    {case 'cruCells':
                        cruEle.className = 'cruCellsHover';
                        break;
                     case 'cruCellsHover':
                        cruEle.className = 'cruCells';
                        break;
                     case 'cruCellsExMonth':
                        cruEle.className = 'cruCellsExMonthHover';
                        break;
                     case 'cruCellsExMonthHover':
                        cruEle.className = 'cruCellsExMonth';
                        break;
                     case 'cruCellsWeekend':
                        cruEle.className = 'cruCellsWeekendHover';
                        break;
                     case 'cruCellsWeekendHover':
                        cruEle.className = 'cruCellsWeekend';
                        break;
                     case 'cruNow':
                        cruEle.className = 'cruNowHover';
                        break;
                     case 'cruNowHover':
                        cruEle.className = 'cruNow';
                        break;
                     case 'cruInputDate':
                        cruEle.className = 'cruInputDateHover';
                        break;
                     case 'cruInputDateHover':
                        cruEle.className = 'cruInputDate';
                    }

                 return true;
                }

             function cruEventTrigger(cruEvt)
                {if (!cruEvt) {cruEvt = event;}
                 return cruEvt.target||cruEvt.srcElement;
                };

             function cruWeekNumber(cruInDate)
                {// The base day in the week of the input date
                 var cruInDateWeekBase = new Date(cruInDate);

                 cruInDateWeekBase.setDate(cruInDateWeekBase.getDate()
                                            - cruInDateWeekBase.getDay()
                                            + cruWeekNumberBaseDay
                                            + ((cruInDate.getDay()>
                                                cruWeekNumberBaseDay)?7:0));

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

                 cruFirstBaseDay.setDate(cruFirstBaseDay.getDate()
                                            - cruFirstBaseDay.getDay()
                                            + cruWeekNumberBaseDay
                                        );

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

                 var cruStartWeekOne = new Date(cruFirstBaseDay
                                                - cruWeekNumberBaseDay
                                                + cruInDate.getDay());

                 if (cruStartWeekOne > cruFirstBaseDay)
                    {cruStartWeekOne.setDate(cruStartWeekOne.getDate()-7);}

                 var cruWeekNo = '0' + (Math.round((cruInDateWeekBase - cruFirstBaseDay)/604800000,0) + 1);

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

             var cruCells = cruID('cruCells');

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

                     for (j=1;j<cruRows.childNodes.length;j++)
                        {var cruCols = cruRows.childNodes[j];
                         if (cruCols.nodeType==1 && cruCols.tagName=='TD')
                            {cruRows.childNodes[j].innerHTML=
                                cruShowDate.getDate();
                             var cruCell=cruRows.childNodes[j],
                                 cruDisabled =
                                    ((cruOutOfRangeDisable &&
                                        (cruShowDate <
                                            (new Date(cruBaseYear,0,1,
                                                      cruShowDate.getHours()))
                                         ||
                                         cruShowDate >
                                            (new Date(cruBaseYear+
                                                      cruDropDownYears,0,0,
                                                      cruShowDate.getHours()))
                                        )
                                     ) ||
                                     (cruOutOfMonthDisable &&
                                        (cruShowDate <
                                            (new Date(cruShowDate.getFullYear(),
                                                      cruCurMonth,1,
                                                      cruShowDate.getHours()))
                                         ||
                                         cruShowDate >
                                            (new Date(cruShowDate.getFullYear(),
                                                      cruCurMonth+1,0,
                                                      cruShowDate.getHours()))
                                        )
                                     )
                                    )?true:false;

                             cruCell.style.visibility =
                                (cruOutOfMonthHide &&
                                    (cruShowDate <
                                        (new Date(cruShowDate.getFullYear(),
                                                  cruCurMonth,1,
                                                  cruShowDate.getHours()))
                                     ||
                                     cruShowDate >
                                        (new Date(cruShowDate.getFullYear(),
                                                  cruCurMonth+1,0,
                                                  cruShowDate.getHours()))
                                    )
                                )?'hidden':'inherit';

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

                             if (cruDisabled ||
                                 !cruEnabledDay[j-1+(7*((i*cruCells.childNodes.length)/6))] ||
                                 !cruPassEnabledDay[(j-1+(7*(i*cruCells.childNodes.length/6)))%7]
                                )
                                {cruRows.childNodes[j].onclick = null;

                                 if (cruID('cruIE'))
                                    {cruRows.childNodes[j].onmouseover  = null;
                                     cruRows.childNodes[j].onmouseout   = null;
                                    }

                                 cruCell.className=
                                    (cruShowDate.getMonth()!=cruCurMonth)
                                        ?'cruCellsExMonthDisabled'
                                        :(cruBlnFullInputDate &&
                                          cruShowDate.toDateString()==
                                          cruSeedDate.toDateString())
                                            ?'cruInputDateDisabled'
                                            :(cruShowDate.getDay()%6==0)
                                                ?'cruCellsWeekendDisabled'
                                                :'cruCellsDisabled';

                                 cruCell.style.borderColor =
                                     (cruFormatTodayCell && cruShowDate.toDateString()==cruDateNow.toDateString())
                                        ?cruTodayCellBorderColour
                                        :(cruCell.currentStyle)
                                            ?cruCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(cruCell,null).getPropertyValue('background-color')
                                                :'';
                                }
                             else
                                {cruRows.childNodes[j].onclick=cruCellOutput;

                                 if (cruID('cruIE'))
                                    {cruRows.childNodes[j].onmouseover  = cruChangeClass;
                                     cruRows.childNodes[j].onmouseout   = cruChangeClass;
                                    }

                                 cruCell.className=
                                     (cruShowDate.getMonth()!=cruCurMonth)
                                        ?'cruCellsExMonth'
                                        :(cruBlnFullInputDate &&
                                          cruShowDate.toDateString()==
                                          cruSeedDate.toDateString())
                                            ?'cruInputDate'
                                            :(cruShowDate.getDay()%6==0)
                                                ?'cruCellsWeekend'
                                                :'cruCells';

                                 cruCell.style.borderColor =
                                     (cruFormatTodayCell && cruShowDate.toDateString() == cruDateNow.toDateString())
                                        ?cruTodayCellBorderColour
                                        :(cruCell.currentStyle)
                                            ?cruCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(cruCell,null).getPropertyValue('background-color')
                                                :'';
                               }

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

         if (window.opera)
            {cruID('cruMonths').style.display = 'inline';
             cruID('cruYears' ).style.display = 'inline';
             cruID('cru').style.visibility='hidden';
             cruID('cru').style.visibility='inherit';
           }
        };

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

    document.writeln("<!--[if IE]><div id='cruIE'></div><![endif]-->");
    document.writeln("<!--[if lt IE 7]><div id='cruIElt7'></div><![endif]-->");
    document.write(
     "<iframe class='cru' " + (cruID('cruIElt7')?"src='/crublank.html '":'') +
             "id='cruIframe' name='cruIframe' frameborder='0'>" +
     "</iframe>" +
     "<table id='cru' class='cru'>" +
       "<tr class='cru'>" +
         "<td class='cru'>" +
           "<table class='cruHead' id='cruHead' width='100%' " +
                    "cellspacing='0' cellpadding='0'>" +
            "<tr id='cruDrag' style='display:none;'>" +
                "<td colspan='4' class='cruDrag' " +
                    "onmousedown='cruBeginDrag(event);'>" +
                    "<span id='cruDragText'></span>" +
                "</td>" +
            "</tr>" +
            "<tr class='cruHead' >" +
                 "<td class='cruHead'>" +
                    "<input class='cruHead' id='cruHeadLeft' type='button' value='<' " +
                            "onclick='cruShowMonth(-1);'  /></td>" +
                 "<td class='cruHead'>" +
                    "<select id='cruMonths' class='cruHead' " +
                            "onchange='cruShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='cruHead'>" +
                    "<select id='cruYears' class='cruHead' " +
                            "onchange='cruShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='cruHead'>" +
                    "<input class='cruHead' id='cruHeadRight' type='button' value='>' " +
                            "onclick='cruShowMonth(1);' /></td>" +
                "</tr>" +
              "</table>" +
            "</td>" +
          "</tr>" +
          "<tr class='cru'>" +
            "<td class='cru'>" +
              "<table class='cruCells' align='center'>" +
                "<thead>" +
                  "<tr><td class='cruWeekNumberHead' id='cruWeek_' ></td>");

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

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

    for (i=0;i<6;i++)
        {document.write(
                    "<tr>" +
                      "<td class='cruWeekNo' id='cruWeek_" + i + "'></td>");
         for (j=0;j<7;j++)
            {document.write(
                        "<td class='cruCells' id='cruCell_" + (j+(i*7)) +
                        "'></td>");
            }

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

    document.write(
                "</tbody>" +
                "<tfoot>" +
                  "<tr id='cruFoot'>" +
                    "<td colspan='8' style='padding:0px;'>" +
                      "<table width='100%'>" +
                        "<tr>" +
                          "<td id='cruClear' class='cruClear'>" +
                            "<input type='button' id='cruClearButton' class='cruClear' " +
                                   "onclick='cruTargetEle.value = \"\";cruHide();' />" +
                          "</td>" +
                          "<td class='cruNow' id='cruNow'></td>" +
                        "</tr>" +
                      "</table>" +
                    "</td>" +
                  "</tr>" +
                "</tfoot>" +
              "</table>" +
            "</td>" +
          "</tr>" +
        "</table>");

    if (document.addEventListener)
            {cruID('cru'         ).addEventListener('click',cruCancel,false);
             cruID('cruHeadLeft' ).addEventListener('click',cruStopPropagation,false);
             cruID('cruMonths'   ).addEventListener('click',cruStopPropagation,false);
             cruID('cruMonths'   ).addEventListener('change',cruStopPropagation,false);
             cruID('cruYears'    ).addEventListener('click',cruStopPropagation,false);
             cruID('cruYears'    ).addEventListener('change',cruStopPropagation,false);
             cruID('cruHeadRight').addEventListener('click',cruStopPropagation,false);
            }
    else    {cruID('cru'         ).attachEvent('onclick',cruCancel);
             cruID('cruHeadLeft' ).attachEvent('onclick',cruStopPropagation);
             cruID('cruMonths'   ).attachEvent('onclick',cruStopPropagation);
             cruID('cruMonths'   ).attachEvent('onchange',cruStopPropagation);
             cruID('cruYears'    ).attachEvent('onclick',cruStopPropagation);
             cruID('cruYears'    ).attachEvent('onchange',cruStopPropagation);
             cruID('cruHeadRight').attachEvent('onclick',cruStopPropagation);
            }

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

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

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