// *****************************************************************************
//      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 niqDateNow = new Date(2010,3,1);


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

    var niqBaseYear        = 2010;

    var niqDropDownYears   = 1;

    var niqLanguage;

    function niqSetDefaultLanguage()
        {try
            {niqSetLanguage();}
         catch (exception)
            {// Deutsch
             niqToday               = 'Heute:';
             niqClear               = 'Clear';
             niqDrag                = 'click here to drag';
             niqArrMonthNames       = ['Jan','Feb','Mar','Apr','Mai','Jun',
                                       'Jul','Aug','Sep','Okt','Nov','Dez'];
             niqArrWeekInits        = ['So','Mo','Di','Mi','Do','Fr','Sa'];
             niqInvalidDateMsg      = 'Das eigetragene Datum ist ungültig.\n';
             niqOutOfRangeMsg       = 'Das eigetragene Datum ist ausserhalb des möglichen Zeitraums.';
             niqDoesNotExistMsg     = 'Das eigetragene Datum existiert nicht.';
             niqInvalidAlert        = ['Ungültiges Datum (',') ignoriert.'];
             niqDateDisablingError  = ['Fehler ',' ist kein Datum.'];
             niqRangeDisablingError = ['Fehler ',
                                       ' should consist of two elements.'];
            }
        };

    var niqWeekStart       =    1;

    var niqWeekNumberDisplay    = false;

    var niqWeekNumberBaseDay    = 4;

    var niqShowInvalidDateMsg       = false,
        niqShowOutOfRangeMsg        = false,
        niqShowDoesNotExistMsg      = false,
        niqShowInvalidAlert         = false,
        niqShowDateDisablingError   = false,
        niqShowRangeDisablingError  = false;

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

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

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

    var niqZindex          = 1;

    var niqBlnStrict       = false;

    var niqClearButton     = true;

    var niqAutoPosition    = true;

 // If you wish to disable any displayed day, e.g. Every Monday,
    // you can do it by setting the following array.  The array elements
    // match the displayed cells.
    //
    // You could put something like the following in your calling page
    // to disable all weekend days;
    //
    //  for (var i=0;i<scwEnabledDay.length;i++)
    //      {if (i%7%6==0) scwEnabledDay[i] = false;}
    //
    // The above approach will allow you to disable days of the week
    // for the whole of your page easily.  If you need to set different
    // disabled days for a number of date input fields on your page
    // there is an easier way: You can pass additional arguments to
    // scwShow. The syntax is described at the top of this script in
    // the section:
    //    "How to use the Calendar once it is defined for your page:"
    //
    // It is possible to use these two approaches in combination.



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

    niqDisabledDates[1] = [new Date(2010,0,1),new Date(2010,3,20)];
    niqDisabledDates[2] = [new Date(2010,4,1),new Date(2010,7,31)];
    niqDisabledDates[3] = new Date(2010,10,17);




    var niqActiveToday = false;
    var niqOutOfMonthDisable = false;
    var niqOutOfMonthHide    = true;
    var niqOutOfRangeDisable = true;
    var niqFormatTodayCell = true;
    var niqTodayCellBorderColour = 'red';
    var niqAllowDrag = false;
    var niqClickToHide = true;


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

    document.writeln(
        '<style type="text/css">'                                       +
            '/* IMPORTANT:  The niq calendar script requires all '      +
            '               the classes defined here.'                  +
            '*/'                                                        +
            'table.niq      {padding:       1px;'                       +
                            'vertical-align:middle;'                    +
                            'border:        ridge 2px;'                 +
                            'font-size:     10pt;'                      +
                            'font-family:   ' +
                                   'Verdana,Arial,Helvetica,Sans-Serif;'+
                            'font-weight:   bold;}'                     +
            'td.niqDrag,'                                               +
            'td.niqHead                 {padding:       0px 0px;'       +
                                        'text-align:    center;}'       +
            'td.niqDrag                 {font-size:     8pt;}'          +
            'select.niqHead             {margin:        3px 1px;'       +
                                        'text-align:    center;}'       +
            'input.niqHead              {height:        22px;'          +
                                        'width:         22px;'          +
                                        'vertical-align:middle;'        +
                                        'text-align:    center;'        +
                                        'margin:        2px 1px;'       +
                                        'font-weight:   bold;'          +
                                        'font-size:     10pt;'          +
                                        'font-family:   fixedSys;}'     +
            'td.niqWeekNumberHead,'                                     +
            'td.niqWeek                 {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'font-weight:   bold;}'         +
            'td.niqNow,'                                                +
            'td.niqNowHover,'                                           +
            'td.niqNow:hover,'                                          +
            'td.niqNowDisabled          {padding:       0px;'           +
                                        'text-align:    center;'        +
                                        'vertical-align:middle;'        +
                                        'font-weight:   normal;}'       +
            'table.niqCells             {text-align:    right;'         +
                                        'font-size:     8pt;'           +
                                        'width:         96%;}'          +
            'td.niqCells,'                  +
            'td.niqCellsHover,'             +
            'td.niqCells:hover,'            +
            'td.niqCellsDisabled,'          +
            'td.niqCellsExMonth,'           +
            'td.niqCellsExMonthHover,'      +
            'td.niqCellsExMonth:hover,'     +
            'td.niqCellsExMonthDisabled,'   +
            'td.niqCellsWeekend,'           +
            'td.niqCellsWeekendHover,'      +
            'td.niqCellsWeekend:hover,'     +
            'td.niqCellsWeekendDisabled,'   +
            'td.niqInputDate,'              +
            'td.niqInputDateHover,'         +
            'td.niqInputDate:hover,'        +
            'td.niqInputDateDisabled,'      +
            'td.niqWeekNo,'                 +
            'td.niqWeeks                {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.niq                  {background-color:  #0040FF;}'  +
            '/* Drag Handle */'                                         +
            'td.niqDrag                 {background-color:  #9999CC;'   +
                                        'color:             #CCCCFF;}'  +
            '/* Week number heading */'                                 +
            'td.niqWeekNumberHead       {color:             #6666CC;}'  +
            '/* Week day headings */'                                   +
            'td.niqWeek                 {color:             #CCCCCC;}'  +
            '/* Week numbers */'                                        +
            'td.niqWeekNo               {background-color:  #776677;'   +
                                        'color:             #CCCCCC;}'  +
            '/* Enabled Days */'                                        +
            '/* Week Day */'                                            +
            'td.niqCells                {background-color:  #A0FF00;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.niqInputDate            {background-color:  #CC9999;'   +
                                        'color:             #FF0000;}'  +
            '/* Weekend Day */'                                         +
            'td.niqCellsWeekend         {background-color:  #A0FF00;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.niqCellsExMonth         {background-color:  #CCCCCC;'   +
                                        'color:             #666666;}'  +
            '/* Today selector */'                                      +
            'td.niqNow                  {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
            '/* Clear Button */'                                        +
            'td.niqClear                {padding:           0px;}'      +
            'input.niqClear             {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.niqCells:hover,'                                        +
            'td.niqCellsHover           {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day matching the input date */'                         +
            'td.niqInputDate:hover,'                                    +
            'td.niqInputDateHover       {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Weekend cells */'                                       +
            'td.niqCellsWeekend:hover,'                                 +
            'td.niqCellsWeekendHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Day outside the current month */'                       +
            'td.niqCellsExMonth:hover,'                                 +
            'td.niqCellsExMonthHover    {background-color:  #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'color:             #000000;}'  +
            '/* Today selector */'                                      +
            'td.niqNow:hover,'                                          +
            'td.niqNowHover             {color:             #FFFF00;'   +
                                        'cursor:            pointer;'   +
                                        'font-weight:       bold;}'     +
            '/* Disabled cells */'                                      +
            '/* Week Day */'                                            +
            '/* Day matching the input date */'                         +
            'td.niqInputDateDisabled    {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            'td.niqCellsDisabled        {background-color:  #999999;'   +
                                        'color:             #000000;}'  +
            '/* Weekend Day */'                                         +
            'td.niqCellsWeekendDisabled {background-color:  #999999;'   +
                                        'color:             #CC6666;}'  +
            '/* Day outside the current month */'                       +
            'td.niqCellsExMonthDisabled {background-color:  #999999;'   +
                                        'color:             #666666;}'  +
            'td.niqNowDisabled          {background-color:  #6666CC;'   +
                                        'color:             #FFFFFF;}'  +
        '</style>'
                    );

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

    var niqTargetEle,
        niqTriggerEle,
        niqMonthSum            = 0,
        niqBlnFullInputDate    = false,
        niqPassEnabledDay      = new Array(),
        niqSeedDate            = new Date(),
        niqParmActiveToday     = true,
        niqWeekStart           = niqWeekStart%7,
        niqToday,
        niqClear,
        niqDrag,
        niqArrMonthNames,
        niqArrWeekInits,
        niqInvalidDateMsg,
        niqOutOfRangeMsg,
        niqDoesNotExistMsg,
        niqInvalidAlert,
        niqDateDisablingError,
        niqRangeDisablingError;

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

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

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

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

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

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

    Function.prototype.runsAfterniq =
        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()==niqTriggerEle)?func.apply(this, args):null;
                        };
                    };

    function niqID(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( 'niq' +
                                    ' \nCannot uniquely identify element named: ' + id +
                                    '.\nMore than one identical NAME attribute defined' +
                                    '.\nSolution: Assign the required element a unique ID attribute value.');
                            }
                        }
                }
        };

    var niqNextActionReturn, niqNextAction;

    function showCal(niqEle,niqSource) {niqShow(niqEle,niqSource);};
    function niqShow(niqEle,niqSource)
        {if (!niqSource) {niqSource = window.event;}

         if (niqSource.tagName)
            {var niqSourceEle = niqSource;

             if (niqID('niqIE'))  {window.event.cancelBubble = true;}
             else {niqSourceEle.parentNode.addEventListener('click',niqStopPropagation,false);}
            }
         else
            {var niqSourceEle = (niqSource.target)
                                    ?niqSource.target
                                    :niqSource.srcElement;

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

         niqTriggerEle = niqSourceEle;

         niqParmActiveToday = true;

         for (var i=0;i<7;i++)
            {niqPassEnabledDay[(i+7-niqWeekStart)%7] = true;
             for (var j=2;j<arguments.length;j++)
                {if (arguments[j]==i)
                    {niqPassEnabledDay[(i+7-niqWeekStart)%7] = false;
                     if (niqDateNow.getDay()==i) {niqParmActiveToday = false;}
                    }
                }
            }

         niqSeedDate = niqDateNow;

         var niqDateValue = '';

         if (niqEle.value) {niqDateValue = niqEle.value.replace(/^\s+/,'').replace(/\s+$/,'');}
         else   {if (typeof niqEle.value == 'undefined')
                    {var niqChildNodes = niqEle.childNodes;
                     for (var i=0;i<niqChildNodes.length;i++)
                        {if (niqChildNodes[i].nodeType == 3)
                            {niqDateValue = niqChildNodes[i].nodeValue.replace(/^\s+/,'').replace(/\s+$/,'');
                             if (niqDateValue.length > 0)
                                {niqTriggerEle.niqTextNode = niqChildNodes[i];
                                 niqTriggerEle.niqLength   = niqChildNodes[i].nodeValue.length;
                                 break;
                                }
                            }
                        }
                    }
                }

         niqSetDefaultLanguage();

         niqID('niqDragText').innerHTML = niqDrag;

         niqID('niqMonths').options.length = 0;
         for (var i=0;i<niqArrMonthNames.length;i++)
            {niqID('niqMonths').options[i] = new Option(niqArrMonthNames[i],niqArrMonthNames[i]);}

         niqID('niqYears').options.length = 0;
         for (var i=0;i<niqDropDownYears;i++)
            {niqID('niqYears').options[i] =  new Option((niqBaseYear+i),(niqBaseYear+i));}

         for (var i=0;i<niqArrWeekInits.length;i++)
            {niqID('niqWeekInit' + i).innerHTML = niqArrWeekInits[(i+niqWeekStart)%niqArrWeekInits.length];}

         if (((new Date(niqBaseYear + niqDropDownYears, 0, 0)) > niqDateNow &&
              (new Date(niqBaseYear, 0, 0))                    < niqDateNow) ||
             (niqClearButton && (niqEle.readOnly || niqEle.disabled))
            )   {niqID('niqFoot').style.display = '';
                 niqID('niqNow').innerHTML = '<p onclick=niqHide()>Kalender ausblenden';
                 niqID('niqClearButton').value = niqClear;
                 if ((new Date(niqBaseYear + niqDropDownYears, 0, 0)) > niqDateNow &&
                     (new Date(niqBaseYear, 0, 0))                    < niqDateNow
                    )   {niqID('niqNow').style.display = '';
                         if (niqClearButton && (niqEle.readOnly || niqEle.disabled))
                                {niqID('niqClear').style.display   = '';
                                 niqID('niqClear').style.textAlign = 'left';
                                 niqID('niqNow').style.textAlign   = 'right';
                                }
                         else   {niqID('niqClear').style.display = 'none';
                                 niqID('niqNow').style.textAlign = 'center';
                                }
                        }
                 else   {niqID('niqClear').style.textAlign = 'center';
                         niqID('niqClear').style.display = '';
                         niqID('niqNow').style.display = 'none';
                        }
                }
         else   {niqID('niqFoot').style.display = 'none';}

         if (niqDateValue.length==0)
            {
             niqBlnFullInputDate=false;

             if ((new Date(niqBaseYear+niqDropDownYears,0,0))<niqSeedDate ||
                 (new Date(niqBaseYear,0,1))                 >niqSeedDate
                )
                {niqSeedDate = new Date(niqBaseYear + Math.floor(niqDropDownYears / 2), 5, 1);}
            }
         else
            {function niqInputFormat()
                {var niqArrSeed = new Array(),
                     niqArrInput = niqDateValue.split(new RegExp('[\\'+niqArrDelimiters.join('\\')+']+','g'));

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

                 niqBlnFullInputDate = false;

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

                 var niqDateSequence = result.join('');

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

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

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

                         if (niqArrInput[0].length==niqDateOutputFormat.length) {niqBlnFullInputDate = true;}
                         break;
                        }
                     case 2:
                        {// Year and Month entry
                         niqArrSeed[0] =
                             parseInt(niqArrInput[niqDateSequence.
                                                    replace(/D/i,'').
                                                    search(/Y/i)],10);  // Year
                         niqArrSeed[1] = niqArrInput[niqDateSequence.
                                                    replace(/D/i,'').
                                                    search(/M/i)];      // Month
                         niqArrSeed[2] = 1;                             // Day
                         break;
                        }
                     case 3:
                        {// Day Month and Year entry

                         niqArrSeed[0] =
                             parseInt(niqArrInput[niqDateSequence.
                                                    search(/Y/i)],10);  // Year
                         niqArrSeed[1] = niqArrInput[niqDateSequence.
                                                    search(/M/i)];      // Month
                         niqArrSeed[2] =
                             parseInt(niqArrInput[niqDateSequence.
                                                    search(/D/i)],10);  // Day

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


                 var niqExpValDay    = new RegExp('^(0?[1-9]|[1-2][0-9]|3[0-1])$'),
                     niqExpValMonth  = new RegExp('^(0?[1-9]|1[0-2]|'        +
                                                  niqArrMonthNames.join('|') +
                                                  ')$','i'),
                     niqExpValYear   = new RegExp('^([0-9]{1,2}|[0-9]{4})$');


                 if (niqExpValYear.exec(niqArrSeed[0])  == null ||
                     niqExpValMonth.exec(niqArrSeed[1]) == null ||
                     niqExpValDay.exec(niqArrSeed[2])   == null
                    )
                    {if (niqShowInvalidDateMsg)
                        {alert(niqInvalidDateMsg  +
                               niqInvalidAlert[0] + niqDateValue +
                               niqInvalidAlert[1]);}
                     niqBlnFullInputDate = false;
                     niqArrSeed[0] = niqBaseYear +
                                     Math.floor(niqDropDownYears/2); // Year
                     niqArrSeed[1] = '6';                            // Month
                     niqArrSeed[2] = 1;                              // Day
                    }


                 return niqArrSeed;
                };


             niqArrSeedDate = niqInputFormat();


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


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

             niqSeedDate = new Date(niqArrSeedDate[0],niqArrSeedDate[1]-1,niqArrSeedDate[2]);
            }

         if (isNaN(niqSeedDate))
            {if (niqShowInvalidDateMsg) {alert(niqInvalidDateMsg + niqInvalidAlert[0] + niqDateValue + niqInvalidAlert[1]);}
             niqSeedDate = new Date(niqBaseYear + Math.floor(niqDropDownYears/2),5,1);
             niqBlnFullInputDate=false;
            }
         else
            {
             if ((new Date(niqBaseYear,0,1)) > niqSeedDate)
                {if (niqBlnStrict && niqShowOutOfRangeMsg) {alert(niqOutOfRangeMsg);}
                 niqSeedDate = new Date(niqBaseYear,0,1);
                 niqBlnFullInputDate=false;
                }
             else
                {if ((new Date(niqBaseYear+niqDropDownYears,0,0))<niqSeedDate)
                    {if (niqBlnStrict && niqShowOutOfRangeMsg) {alert(niqOutOfRangeMsg);}
                     niqSeedDate = new Date(niqBaseYear + Math.floor(niqDropDownYears)-1,11,1);
                     niqBlnFullInputDate=false;
                    }
                 else
                    {if (niqBlnStrict && niqBlnFullInputDate &&
                          (niqSeedDate.getDate()      != niqArrSeedDate[2] ||
                           (niqSeedDate.getMonth()+1) != niqArrSeedDate[1] ||
                           niqSeedDate.getFullYear()  != niqArrSeedDate[0]
                          )
                        )
                        {if (niqShowDoesNotExistMsg) alert(niqDoesNotExistMsg);
                         niqSeedDate = new Date(niqSeedDate.getFullYear(),niqSeedDate.getMonth()-1,1);
                         niqBlnFullInputDate=false;
                        }
                    }
                }
            }


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

                     if (niqDisabledDates[i].length !=2)
                        {if (niqShowRangeDisablingError)
                            {alert(niqRangeDisablingError[0] + niqDisabledDates[i] + niqRangeDisablingError[1]);}
                         niqPass = false;
                        }
                     else
                        {for (var j=0;j<niqDisabledDates[i].length;j++)
                            {if (!((typeof niqDisabledDates[i][j] == 'object') && (niqDisabledDates[i][j].constructor == Date)))
                                {if (niqShowRangeDisablingError)
                                    {alert(  niqDateDisablingError[0] + niqDisabledDates[i][j] + niqDateDisablingError[1]);}
                                 niqPass = false;
                                }
                            }
                        }

                     if (niqPass && (niqDisabledDates[i][0] > niqDisabledDates[i][1])) {niqDisabledDates[i].reverse();}
                    }
                 else
                    {if (niqShowRangeDisablingError) {alert(niqDateDisablingError[0] + niqDisabledDates[i] + niqDateDisablingError[1]);}}
                }
            }

         niqMonthSum =  12*(niqSeedDate.getFullYear()-niqBaseYear)+niqSeedDate.getMonth();

         niqID('niqYears' ).options.selectedIndex = Math.floor(niqMonthSum/12);
         niqID('niqMonths').options.selectedIndex = (niqMonthSum%12);
         niqID('niqDrag').style.display=(niqAllowDrag)?'':'none';

         niqShowMonth(0);

         niqTargetEle=niqEle;

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

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

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

         if (niqAutoPosition)
             {var niqWidth      = parseInt(niqID('niq').offsetWidth, 10),
                  niqHeight     = parseInt(niqID('niq').offsetHeight,10),
                  niqWindowLeft =
                     (document.body && document.body.scrollLeft)
                          ?document.body.scrollLeft                  //DOM compliant
                          :(document.documentElement && document.documentElement.scrollLeft)
                              ?document.documentElement.scrollLeft   //IE6+ standards compliant
                              :0,                                    //Failed
                  niqWindowWidth =
                      (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
                  niqWindowTop =
                      (document.body && document.body.scrollTop)
                          ?document.body.scrollTop                   //DOM compliant
                          :(document.documentElement && document.documentElement.scrollTop)
                              ?document.documentElement.scrollTop    //IE6+ standards compliant
                              :0,                                    //Failed
                  niqWindowHeight =
                      (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 - niqWidth + parseInt(niqTargetEle.offsetWidth,10) >= niqWindowLeft &&
                             offsetLeft + niqWidth > niqWindowLeft + niqWindowWidth
                            )?(niqWidth - parseInt(niqTargetEle.offsetWidth,10)):0;

              offsetTop -= (offsetTop - niqHeight - parseInt(niqTargetEle.offsetHeight,10) >= niqWindowTop &&
                            offsetTop + niqHeight > niqWindowTop + niqWindowHeight
                           )?(niqHeight + parseInt(niqTargetEle.offsetHeight,10)):0;
             }

         niqID('niq').style.top         = offsetTop+'px';
         niqID('niq').style.left        = offsetLeft+'px';
         niqID('niqIframe').style.top   = offsetTop+'px';
         niqID('niqIframe').style.left  = offsetLeft+'px';

         niqID('niqIframe').style.width =(niqID('niq').offsetWidth-(niqID('niqIE')?2:4))+'px';
         niqID('niqIframe').style.height=(niqID('niq').offsetHeight-(niqID('niqIE')?2:4))+'px';
         niqID('niqIframe').style.visibility='inherit';

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

    function niqHide()
        {niqID('niq').style.visibility='hidden';
         niqID('niqIframe').style.visibility='hidden';
         if (typeof niqNextAction!='undefined' && niqNextAction!=null)
             {niqNextActionReturn = niqNextAction();
              // Explicit null set to prevent closure causing memory leak
              niqNextAction = null;
             }
        };

    function niqCancel(niqEvt)
        {if (niqClickToHide) {niqHide();}
         niqStopPropagation(niqEvt);
        };

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

    function niqBeginDrag(event)
        {var elementToDrag = niqID('niq');

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

         niqStopPropagation(event);

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

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

             niqID('niqIframe').style.left = (niqEvt.clientX - deltaX) + 'px';
             niqID('niqIframe').style.top  = (niqEvt.clientY - deltaY) + 'px';

             niqStopPropagation(niqEvt);
            };

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

             niqStopPropagation(niqEvt);
            };
        };

    function niqShowMonth(niqBias)
        {

         var niqShowDate  = new Date(Date.parse(new Date().toDateString())),
             niqStartDate = new Date();

         niqShowDate.setHours(12);

         niqSelYears  = niqID('niqYears');
         niqSelMonths = niqID('niqMonths');

         if (niqSelYears.options.selectedIndex>-1)
            {niqMonthSum=12*(niqSelYears.options.selectedIndex)+niqBias;
             if (niqSelMonths.options.selectedIndex>-1) {niqMonthSum+=niqSelMonths.options.selectedIndex;}
            }
         else
            {if (niqSelMonths.options.selectedIndex>-1) {niqMonthSum+=niqSelMonths.options.selectedIndex;}}

         niqShowDate.setFullYear(niqBaseYear + Math.floor(niqMonthSum/12),(niqMonthSum%12),1);

         niqID('niqWeek_').style.display=(niqWeekNumberDisplay)?'':'none';

         if (window.opera)
            {niqID('niqMonths').style.display = 'inherit';
             niqID('niqYears' ).style.display = 'inherit';
           }

         niqTemp = (12*parseInt((niqShowDate.getFullYear()-niqBaseYear),10)) + parseInt(niqShowDate.getMonth(),10);

         if (niqTemp > -1 && niqTemp < (12*niqDropDownYears))
            {niqSelYears.options.selectedIndex=Math.floor(niqMonthSum/12);
             niqSelMonths.options.selectedIndex=(niqMonthSum%12);

             niqCurMonth = niqShowDate.getMonth();

             niqShowDate.setDate((((niqShowDate.
                                    getDay()-niqWeekStart)<0)?-6:1)+
                                 niqWeekStart-niqShowDate.getDay());

             var niqCompareDateValue = new Date(niqShowDate.getFullYear(),
                                                niqShowDate.getMonth(),
                                                niqShowDate.getDate()).valueOf();

             niqStartDate = new Date(niqShowDate);

             if ((new Date(niqBaseYear + niqDropDownYears, 0, 0)) > niqDateNow &&
                 (new Date(niqBaseYear, 0, 0))                    < niqDateNow)
                {var niqNow = niqID('niqNow');

                 function niqNowOutput() {niqSetOutput(niqDateNow);};

                 if (niqDisabledDates.length==0)
                    {if (niqActiveToday && niqParmActiveToday)
                        {niqNow.onclick     = niqNowOutput;
                         niqNow.className   = 'niqNow';

                         if (niqID('niqIE'))
                            {niqNow.onmouseover  = niqChangeClass;
                             niqNow.onmouseout   = niqChangeClass;
                            }

                        }
                     else
                        {niqNow.onclick     = null;
                         niqNow.className   = 'niqNowDisabled';

                         if (niqID('niqIE'))
                            {niqNow.onmouseover  = null;
                             niqNow.onmouseout   = null;
                            }

                         if (document.addEventListener)
                                {niqNow.addEventListener('click',niqStopPropagation,false);}
                         else   {niqNow.attachEvent('onclick',niqStopPropagation);}
                        }
                    }
                 else
                    {for (var k=0;k<niqDisabledDates.length;k++)
                        {if (!niqActiveToday || !niqParmActiveToday ||
                             ((typeof niqDisabledDates[k] == 'object')                   &&
                                 (((niqDisabledDates[k].constructor == Date)             &&
                                   niqDateNow.valueOf() == niqDisabledDates[k].valueOf()
                                  ) ||
                                  ((niqDisabledDates[k].constructor == Array)               &&
                                   niqDateNow.valueOf() >= niqDisabledDates[k][0].valueOf() &&
                                   niqDateNow.valueOf() <= niqDisabledDates[k][1].valueOf()
                                  )
                                 )
                             )
                            )
                            {niqNow.onclick     = null;
                             niqNow.className   = 'niqNowDisabled';

                             if (niqID('niqIE'))
                                {niqNow.onmouseover  = null;
                                 niqNow.onmouseout   = null;
                                }

                             if (document.addEventListener)
                                    {niqNow.addEventListener('click',niqStopPropagation,false);}
                             else   {niqNow.attachEvent('onclick',niqStopPropagation);}
                             break;
                            }
                         else
                            {niqNow.onclick=niqNowOutput;
                             niqNow.className='niqNow';

                             if (niqID('niqIE'))
                                {niqNow.onmouseover  = niqChangeClass;
                                 niqNow.onmouseout   = niqChangeClass;
                                }
                            }
                        }
                    }
                }

             function niqSetOutput(niqOutputDate)
                {if (typeof niqTargetEle.value == 'undefined')
                      {niqTriggerEle.niqTextNode.replaceData(0,niqTriggerEle.niqLength,niqOutputDate.niqFormat(niqDateOutputFormat));}
                 else {niqTargetEle.value = niqOutputDate.niqFormat(niqDateOutputFormat);}
                 niqHide();
                };

             function niqCellOutput(niqEvt)
                {var niqEle = niqEventTrigger(niqEvt),
                     niqOutputDate = new Date(niqStartDate);

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

                 niqOutputDate.setDate(niqStartDate.getDate() + parseInt(niqEle.id.substr(8),10));

                 niqSetOutput(niqOutputDate);
                };

             function niqChangeClass(niqEvt)
                {var niqEle = niqEventTrigger(niqEvt);

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

                 switch (niqEle.className)
                    {case 'niqCells':
                        niqEle.className = 'niqCellsHover';
                        break;
                     case 'niqCellsHover':
                        niqEle.className = 'niqCells';
                        break;
                     case 'niqCellsExMonth':
                        niqEle.className = 'niqCellsExMonthHover';
                        break;
                     case 'niqCellsExMonthHover':
                        niqEle.className = 'niqCellsExMonth';
                        break;
                     case 'niqCellsWeekend':
                        niqEle.className = 'niqCellsWeekendHover';
                        break;
                     case 'niqCellsWeekendHover':
                        niqEle.className = 'niqCellsWeekend';
                        break;
                     case 'niqNow':
                        niqEle.className = 'niqNowHover';
                        break;
                     case 'niqNowHover':
                        niqEle.className = 'niqNow';
                        break;
                     case 'niqInputDate':
                        niqEle.className = 'niqInputDateHover';
                        break;
                     case 'niqInputDateHover':
                        niqEle.className = 'niqInputDate';
                    }

                 return true;
                }

             function niqEventTrigger(niqEvt)
                {if (!niqEvt) {niqEvt = event;}
                 return niqEvt.target||niqEvt.srcElement;
                };

             function niqWeekNumber(niqInDate)
                {// The base day in the week of the input date
                 var niqInDateWeekBase = new Date(niqInDate);

                 niqInDateWeekBase.setDate(niqInDateWeekBase.getDate()
                                            - niqInDateWeekBase.getDay()
                                            + niqWeekNumberBaseDay
                                            + ((niqInDate.getDay()>
                                                niqWeekNumberBaseDay)?7:0));

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

                 niqFirstBaseDay.setDate(niqFirstBaseDay.getDate()
                                            - niqFirstBaseDay.getDay()
                                            + niqWeekNumberBaseDay
                                        );

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

                 var niqStartWeekOne = new Date(niqFirstBaseDay
                                                - niqWeekNumberBaseDay
                                                + niqInDate.getDay());

                 if (niqStartWeekOne > niqFirstBaseDay)
                    {niqStartWeekOne.setDate(niqStartWeekOne.getDate()-7);}

                 var niqWeekNo = '0' + (Math.round((niqInDateWeekBase - niqFirstBaseDay)/604800000,0) + 1);

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

             var niqCells = niqID('niqCells');

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

                     for (j=1;j<niqRows.childNodes.length;j++)
                        {var niqCols = niqRows.childNodes[j];
                         if (niqCols.nodeType==1 && niqCols.tagName=='TD')
                            {niqRows.childNodes[j].innerHTML=
                                niqShowDate.getDate();
                             var niqCell=niqRows.childNodes[j],
                                 niqDisabled =
                                    ((niqOutOfRangeDisable &&
                                        (niqShowDate <
                                            (new Date(niqBaseYear,0,1,
                                                      niqShowDate.getHours()))
                                         ||
                                         niqShowDate >
                                            (new Date(niqBaseYear+
                                                      niqDropDownYears,0,0,
                                                      niqShowDate.getHours()))
                                        )
                                     ) ||
                                     (niqOutOfMonthDisable &&
                                        (niqShowDate <
                                            (new Date(niqShowDate.getFullYear(),
                                                      niqCurMonth,1,
                                                      niqShowDate.getHours()))
                                         ||
                                         niqShowDate >
                                            (new Date(niqShowDate.getFullYear(),
                                                      niqCurMonth+1,0,
                                                      niqShowDate.getHours()))
                                        )
                                     )
                                    )?true:false;

                             niqCell.style.visibility =
                                (niqOutOfMonthHide &&
                                    (niqShowDate <
                                        (new Date(niqShowDate.getFullYear(),
                                                  niqCurMonth,1,
                                                  niqShowDate.getHours()))
                                     ||
                                     niqShowDate >
                                        (new Date(niqShowDate.getFullYear(),
                                                  niqCurMonth+1,0,
                                                  niqShowDate.getHours()))
                                    )
                                )?'hidden':'inherit';

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

                             if (niqDisabled ||
                                 !niqEnabledDay[j-1+(7*((i*niqCells.childNodes.length)/6))] ||
                                 !niqPassEnabledDay[(j-1+(7*(i*niqCells.childNodes.length/6)))%7]
                                )
                                {niqRows.childNodes[j].onclick = null;

                                 if (niqID('niqIE'))
                                    {niqRows.childNodes[j].onmouseover  = null;
                                     niqRows.childNodes[j].onmouseout   = null;
                                    }

                                 niqCell.className=
                                    (niqShowDate.getMonth()!=niqCurMonth)
                                        ?'niqCellsExMonthDisabled'
                                        :(niqBlnFullInputDate &&
                                          niqShowDate.toDateString()==
                                          niqSeedDate.toDateString())
                                            ?'niqInputDateDisabled'
                                            :(niqShowDate.getDay()%6==0)
                                                ?'niqCellsWeekendDisabled'
                                                :'niqCellsDisabled';

                                 niqCell.style.borderColor =
                                     (niqFormatTodayCell && niqShowDate.toDateString()==niqDateNow.toDateString())
                                        ?niqTodayCellBorderColour
                                        :(niqCell.currentStyle)
                                            ?niqCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(niqCell,null).getPropertyValue('background-color')
                                                :'';
                                }
                             else
                                {niqRows.childNodes[j].onclick=niqCellOutput;

                                 if (niqID('niqIE'))
                                    {niqRows.childNodes[j].onmouseover  = niqChangeClass;
                                     niqRows.childNodes[j].onmouseout   = niqChangeClass;
                                    }

                                 niqCell.className=
                                     (niqShowDate.getMonth()!=niqCurMonth)
                                        ?'niqCellsExMonth'
                                        :(niqBlnFullInputDate &&
                                          niqShowDate.toDateString()==
                                          niqSeedDate.toDateString())
                                            ?'niqInputDate'
                                            :(niqShowDate.getDay()%6==0)
                                                ?'niqCellsWeekend'
                                                :'niqCells';

                                 niqCell.style.borderColor =
                                     (niqFormatTodayCell && niqShowDate.toDateString() == niqDateNow.toDateString())
                                        ?niqTodayCellBorderColour
                                        :(niqCell.currentStyle)
                                            ?niqCell.currentStyle['backgroundColor']
                                            :(window.getComputedStyle)
                                                ?document.defaultView.getComputedStyle(niqCell,null).getPropertyValue('background-color')
                                                :'';
                               }

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

         if (window.opera)
            {niqID('niqMonths').style.display = 'inline';
             niqID('niqYears' ).style.display = 'inline';
             niqID('niq').style.visibility='hidden';
             niqID('niq').style.visibility='inherit';
           }
        };

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

    document.writeln("<!--[if IE]><div id='niqIE'></div><![endif]-->");
    document.writeln("<!--[if lt IE 7]><div id='niqIElt7'></div><![endif]-->");
    document.write(
     "<iframe class='niq' " + (niqID('niqIElt7')?"src='/niqblank.html '":'') +
             "id='niqIframe' name='niqIframe' frameborder='0'>" +
     "</iframe>" +
     "<table id='niq' class='niq'>" +
       "<tr class='niq'>" +
         "<td class='niq'>" +
           "<table class='niqHead' id='niqHead' width='100%' " +
                    "cellspacing='0' cellpadding='0'>" +
            "<tr id='niqDrag' style='display:none;'>" +
                "<td colspan='4' class='niqDrag' " +
                    "onmousedown='niqBeginDrag(event);'>" +
                    "<span id='niqDragText'></span>" +
                "</td>" +
            "</tr>" +
            "<tr class='niqHead' >" +
                 "<td class='niqHead'>" +
                    "<input class='niqHead' id='niqHeadLeft' type='button' value='<' " +
                            "onclick='niqShowMonth(-1);'  /></td>" +
                 "<td class='niqHead'>" +
                    "<select id='niqMonths' class='niqHead' " +
                            "onchange='niqShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='niqHead'>" +
                    "<select id='niqYears' class='niqHead' " +
                            "onchange='niqShowMonth(0);'>" +
                    "</select>" +
                 "</td>" +
                 "<td class='niqHead'>" +
                    "<input class='niqHead' id='niqHeadRight' type='button' value='>' " +
                            "onclick='niqShowMonth(1);' /></td>" +
                "</tr>" +
              "</table>" +
            "</td>" +
          "</tr>" +
          "<tr class='niq'>" +
            "<td class='niq'>" +
              "<table class='niqCells' align='center'>" +
                "<thead>" +
                  "<tr><td class='niqWeekNumberHead' id='niqWeek_' ></td>");

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

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

    for (i=0;i<6;i++)
        {document.write(
                    "<tr>" +
                      "<td class='niqWeekNo' id='niqWeek_" + i + "'></td>");
         for (j=0;j<7;j++)
            {document.write(
                        "<td class='niqCells' id='niqCell_" + (j+(i*7)) +
                        "'></td>");
            }

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

    document.write(
                "</tbody>" +
                "<tfoot>" +
                  "<tr id='niqFoot'>" +
                    "<td colspan='8' style='padding:0px;'>" +
                      "<table width='100%'>" +
                        "<tr>" +
                          "<td id='niqClear' class='niqClear'>" +
                            "<input type='button' id='niqClearButton' class='niqClear' " +
                                   "onclick='niqTargetEle.value = \"\";niqHide();' />" +
                          "</td>" +
                          "<td class='niqNow' id='niqNow'></td>" +
                        "</tr>" +
                      "</table>" +
                    "</td>" +
                  "</tr>" +
                "</tfoot>" +
              "</table>" +
            "</td>" +
          "</tr>" +
        "</table>");

    if (document.addEventListener)
            {niqID('niq'         ).addEventListener('click',niqCancel,false);
             niqID('niqHeadLeft' ).addEventListener('click',niqStopPropagation,false);
             niqID('niqMonths'   ).addEventListener('click',niqStopPropagation,false);
             niqID('niqMonths'   ).addEventListener('change',niqStopPropagation,false);
             niqID('niqYears'    ).addEventListener('click',niqStopPropagation,false);
             niqID('niqYears'    ).addEventListener('change',niqStopPropagation,false);
             niqID('niqHeadRight').addEventListener('click',niqStopPropagation,false);
            }
    else    {niqID('niq'         ).attachEvent('onclick',niqCancel);
             niqID('niqHeadLeft' ).attachEvent('onclick',niqStopPropagation);
             niqID('niqMonths'   ).attachEvent('onclick',niqStopPropagation);
             niqID('niqMonths'   ).attachEvent('onchange',niqStopPropagation);
             niqID('niqYears'    ).attachEvent('onclick',niqStopPropagation);
             niqID('niqYears'    ).attachEvent('onchange',niqStopPropagation);
             niqID('niqHeadRight').attachEvent('onclick',niqStopPropagation);
            }

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

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

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