//  ------------------------------------------------------------------------ //
//                 PopCalendar3                  //
//            Copyright (c) 2005 alquanto.de             //
//             <http://www.alquanto.de/>               //
//  ------------------------------------------------------------------------ //
//  This program 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.           //
//                                       //
//  You may not change or alter any portion of this comment or credits     //
//  of supporting developers from this source code or any supporting     //
//  source code which is considered copyrighted (c) material of the      //
//  original comment or credit authors.                    //
//                                       //
//  This program 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 program; if not, write to the Free Software        //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
//
// visit http://www.alquanto.de/goodies/popcalendar for updates
//
// TabSize: 4
//
// HISTORY
// 2005-04-04 Engelke Eschner <tekai at gmx dot li>
//        * popCalendar becomes a selfcontaining Object
//        * bugfix: fixed positioning to work with strict modes
//          in IE/Moz (+'px')
//        * you have to call popCalendar.init() yourself now
//        * init() has new parameter to optionally install event handlers
//          to hide the calendar
// 2005-03-08 ALQUANTO    <info at alquanto dot de>
//        * all IDs in html are now prefixed with "pc"
//        * simplier css, no Font-Tags anymore
//        * no support for NS4 anymore (what the hell is that? :-) )
// 2004-09-03 sanjaya
//        * new Language (no)
//        * new feature: added time-boxes (just add "hh:xx:ss" to your dateformat in Showcalendar)
// 2003-07-30 ALQUANTO    <info at alquanto dot de>
//        * german language included
//        * modified languageLogic with the ISO-2letter-strings
//        * changes in in showCalendar: defaultLanguage is already set...
//        * js and html corrected... more xhtml-compliant... simplier css
// 2003-07-25 PinoToy     <pinotoy at yahoo dot com>
//        * new logic for multiple languages (English, Spanish and ready for more)
//        * changes in popUpMonth & popDownMonth methods for hiding popup
//        * changes in popDownYear & popDownYear methods for hidding popup
//        * new logic for disabling dates in the past
//        * new method showCalendar, dynamic configuration of language, enabling past & position
//        * changes in the styles
// 2001-12-02 Tan Ling Wee  <fuushikaden at yahoo dot com>
//        * initial version, thanx!
//

var popCalendar = {
  language:  'en',  // Default  : en - english ; es - spanish; de - german; no - norwegian
  enablePast:  0,   // 0 - disabled ; 1 - enabled
  fixedX:  -1,    // x position (-1 if to appear below control)
  fixedY:  -1,    // y position (-1 if to appear below control)
  startAt:  1,    // 0 - sunday ; 1 - monday
  showWeekNumber:  0, // 0 - don't show; 1 - show
  showToday:  1,    // 0 - don't show; 1 - show
  imgDir:  'gfx/',  // directory for images ... e.g.   imgDir: "/img/"
  CallbackHandler: '',
  dayName: '',
  gotoString:  new Array(),
  todayString:  new Array(),
  weekString:  new Array(),
  scrollLeftMessage:  new Array(),
  scrollRightMessage:  new Array(),
  selectMonthMessage:  new Array(),
  selectYearMessage:  new Array(),
  selectDateMessage:  new Array(),
  monthName:  new Array(),
  monthName2:  new Array(),

  /*
  @todo TRANSLATE IT!!
  */

  loadArrays: function(){
    popCalendar.gotoString = {
      en : 'Go To Current Month',
      de : 'Gehe zu aktuellem Monat',
      it : 'Vada al mese corrente',
      lt : 'Go To Current Month',
      pt : 'Go To Current Month',
      dk : 'Go To Current Month',
      es : 'Go To Current Month',
      nl : 'Go To Current Month',
      fr : 'Go To Current Month'
    };

    popCalendar.todayString = {
      en : 'Today is',
      de : 'Heute ist',
      it : 'L oggi &egrave;',
      lt : 'Today is',
      pt : 'Today is',
      dk : 'Today is',
      es : 'Today is',
      nl : 'Today is',
      fr : 'Today is'
    };

    popCalendar.weekString = {
      en : 'Wk',
      de : 'KW',
      it : 'Wk',
      lt : 'Wk',
      pt : 'Wk',
      dk : 'Wk',
      es : 'Wk',
      nl : 'Wk',
      fr : 'Wk'
    };

    popCalendar.scrollLeftMessage = {
      en : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      de : 'Klicken um zum vorigen Monat zu gelangen. Gedr&uuml;ckt halten, um automatisch weiter zu scrollen.',
      it : 'Scatto al rotolo al mese precedente. Tenga il tasto di mouse per arrotolare automaticamente.',
      lt : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      pt : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      dk : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      es : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      nl : 'Click to scroll to previous month. Hold mouse button to scroll automatically.',
      fr : 'Click to scroll to previous month. Hold mouse button to scroll automatically.'
    };

    popCalendar.scrollRightMessage = {
      en : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      de : 'Klicken um zum n&auml;chsten Monat zu gelangen. Gedr&uuml;ckt halten, um automatisch weiter zu scrollen.',
      it : 'Scatto al rotolo a il mese prossimo. Tenga il tasto di mouse per arrotolare automaticamente.',
      lt : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      pt : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      dk : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      es : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      nl : 'Click to scroll to next month. Hold mouse button to scroll automatically.',
      fr : 'Click to scroll to next month. Hold mouse button to scroll automatically.'
    };

    popCalendar.selectMonthMessage = {
      en : 'Click to select a month',
      de : 'Klicken um Monat auszuw&auml;hlen',
      en : 'Scatto per selezionare un mese',
      lt : 'Click to select a month',
      pt : 'Click to select a month',
      dk : 'Click to select a month',
      es : 'Click to select a month',
      nl : 'Click to select a month',
      fr : 'Click to select a month'
    };

    popCalendar.selectYearMessage = {
      en : 'Click to select a year.',
      de : 'Klicken um Jahr auszuw&auml;hlen',
      en : 'Scatto per selezionare un anno.',
      lt : 'Click to select a year.',
      pt : 'Click to select a year.',
      dk : 'Click to select a year.',
      es : 'Click to select a year.',
      nl : 'Click to select a year.',
      fr : 'Click to select a year.'
    };

    popCalendar.selectDateMessage = {   // do not replace [date], it will be replaced by date.
      en : 'Select [date] as date.',
      de : 'W&auml;hle [date] als Datum.',
      it : 'Selezioni [date] come data.',
      lt : 'Select [date] as date.',
      pt : 'Select [date] as date.',
      dk : 'Select [date] as date.',
      es : 'Select [date] as date.',
      nl : 'Select [date] as date.',
      fr : 'Select [date] as date.'
    };

    popCalendar.monthName = {
      en : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      de : new Array('Januar','Februar','M&auml;rz','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'),
      it : new Array('gennaio','febbraio','marzo','aprile','maggio','giugno','luglio','agosto','settembre','ottobre','novembre','dicembre'),
      lt : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      pt : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      dk : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      es : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      nl : new Array('January','February','March','April','May','June','July','August','September','October','November','December'),
      fr : new Array('January','February','March','April','May','June','July','August','September','October','November','December')
    };

    popCalendar.monthName2 = {
      en : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      de : new Array('JAN','FEB','MRZ','APR','MAI','JUN','JUL','AUG','SEP','OKT','NOV','DEZ'),
      it : new Array('GEN','FEB','MAR','APR','MAG','GIU','LUG','AGO','SET','OTT','NOV','DIC'),
      lt : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      pt : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      dk : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      es : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      nl : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC'),
      fr : new Array('JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC')
    };

    if (popCalendar.startAt==0) {
      popCalendar.dayName = {
        en : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        de : new Array('So','Mo','Di','Mi','Do','Fr','Sa'),
        it : new Array('Dom','Lun','Mar','Mer','Gio','Ven','Sab'),
        lt : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        pt : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        dk : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        es : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        nl : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat'),
        fr : new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat')
      };
    } else {
      popCalendar.dayName = {
        en : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        de : new Array('Mo','Di','Mi','Do','Fr','Sa','So'),
        it : new Array('Lun','Mar','Wer','Gio','Ven','Sab','Dom'),
        lt : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        pt : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        dk : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        es : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        nl : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'),
        fr : new Array('Mon','Tue','Wed','Thu','Fri','Sat','Sun')
      };
    }
  },

  crossobj: null, crossMonthObj: null, crossYearObj: null, monthSelected: null, yearSelected: null, dateSelected: null, omonthSelected: null, oyearSelected: null, odateSelected: null, monthConstructed: null, yearConstructed: null, intervalID1: null, intervalID2: null, timeoutID1: null, timeoutID2: null, ctlToPlaceValue: null, ctlToPlaceValue2: null, ctlNow: null, dateFormat: null, nStartingYear: null, selDayAction: null, isPast: null,
  visYear :  0,
  visMonth:  0,
  bPageLoaded:  false,
  ie:  document.all,
  opera: (window.opera != 'undefined'),
  dom:  document.getElementById,
  today :  new Date(),
  dateNow :  null,
  monthNow:  null,
  yearNow :  null,
  imgsrc  :  new Array('drop1.gif','drop2.gif','left1.gif','left2.gif','right1.gif','right2.gif'),
  img   :  new Array(),
  bShow :  false,

  hour:  00,
  minute:  00,
  second:  00,
  setHour: function(VHour) {
    if(VHour.length==2) {
      popCalendar.hour = VHour;
    } else if(VHour.length==1) {
      popCalendar.hour ='0'+ VHour;
    }

  },

  setMinute: function(VMinute) {
    if(VMinute.length==2) {
      popCalendar.minute = VMinute;
    }else if(VMinute.length==1) {
      popCalendar.minute = '0' + VMinute;
    }
  },

  setSecond: function(VSecond) {
    if(VSecond.length==2) {
      popCalendar.second = VSecond;
    }else if(VSecond.length==1) {
      popCalendar.second ='0'+ VSecond;
    }
  },



  // hides <select> and <applet> objects (for IE only)
  hideElement: function( elmID, overDiv ) {
    if(popCalendar.ie) {
      for(var i = 0; i < document.all.tags( elmID ).length; i++) {
        var obj = document.all.tags( elmID )[i];
        if(!obj || !obj.offsetParent) continue;

        // Find the element's offsetTop and offsetLeft relative to the BODY tag.
        objLeft   = obj.offsetLeft;
        objTop    = obj.offsetTop;
        objParent = obj.offsetParent;

        while(objParent.tagName.toUpperCase() != 'BODY') {
          objLeft  += objParent.offsetLeft;
          objTop   += objParent.offsetTop;
          objParent = objParent.offsetParent;
        }

        objHeight = obj.offsetHeight;
        objWidth  = obj.offsetWidth;

        if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft);
        else if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop);
        else if(overDiv.offsetTop >= (objTop + objHeight + obj.height));
        else if(overDiv.offsetLeft >= (objLeft + objWidth));
        else {
          obj.style.visibility = 'hidden';
        }
      }
    }
  },

  /**
   * unhides <select> and <applet> objects (for IE only)
   */
  showElement: function(elmID) {
    if (popCalendar.ie) {
      for (var i = 0; i < document.all.tags( elmID ).length; i++) {
        var obj = document.all.tags(elmID)[i];
        if (!obj || !obj.offsetParent) continue;
        obj.style.visibility = '';
      }
    }
  },

  styleAnchor: 'text-decoration:none;color:black;',
  styleLightBorder: 'border:1px solid #a0a0a0;',

  swapImage: function(srcImg, destImg) {
    if (popCalendar.ie)
      document.getElementById(srcImg).setAttribute('src',popCalendar.imgDir + destImg);
  },


  /**
   * Initialize the calendar. This Function must be called before showCalendar()
     *
   * @param boolean installEventHandlers install event handlers to hide the calendar?
   */
  init: function(options) {

    popCalendar.dateNow  = popCalendar.today.getDate();
    popCalendar.monthNow = popCalendar.today.getMonth();
    popCalendar.yearNow  = popCalendar.today.getYear();

    if (popCalendar.dom) {
      for (i=0;i<popCalendar.imgsrc.length;i++) {
        popCalendar.img[i] = new Image;
        popCalendar.img[i].src = popCalendar.imgDir + popCalendar.imgsrc[i];
      }
      //document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body>');
      document.write('<div onclick="popCalendar.bShow=true" id="pccalendar" style="z-index:+999;position:absolute;visibility:hidden;left:0;top:0;"><table style="width:'+((popCalendar.showWeekNumber==1)?250:220)+'px;font:11px Arial;border:1px solid #A0A0A0;background:#fff"><tr style="background-color:#000066;"><td><table width="'+((popCalendar.showWeekNumber==1)?248:218)+'"><tr><td style="padding:2px;font:bold 11px Arial;color:#fff"><span id="pccaption"></span></td><td align="right" style="text-align:right;"><a href="javascript:popCalendar.hideCalendar()"><img src="'+popCalendar.imgDir+'close.gif" width="15" height="13" alt="" /></a></td></tr></table></td></tr><tr><td style="padding:5px;background:#fff"><span id="pccontent"></span></td></tr>');

      if (popCalendar.showToday == 1) {
        document.write ('<tr style="background-color:#f0f0f0;"><td style="padding:5px;text-align:center"><span id="pclblToday"></span></td></tr>');
      }

      document.write('</table></div><div id="pcselectMonth" style="z-index:+999;position:absolute;visibility:hidden;"></div><div id="pcselectYear" style="z-index:+999;position:absolute;visibility:hidden;"></div>');
      //document.write('</html></body>');
    }

    if (popCalendar.yearNow < 999) {
    	popCalendar.yearNow += 1900;
    }

    popCalendar.crossobj=(popCalendar.dom)? document.getElementById('pccalendar').style : popCalendar.ie? document.all.pccalendar : document.pccalendar;
    popCalendar.hideCalendar();

    popCalendar.crossMonthObj = (popCalendar.dom) ? document.getElementById('pcselectMonth').style : popCalendar.ie ? document.all.pcselectMonth : document.pcselectMonth;

    popCalendar.crossYearObj = (popCalendar.dom) ? document.getElementById('pcselectYear').style : popCalendar.ie ? document.all.pcselectYear : document.pcselectYear;

    popCalendar.monthConstructed = false;
    popCalendar.yearConstructed = false;

    var sHTML1  = '<span style="border:1px solid #fff;cursor:pointer" onmouseover="popCalendar.swapImage(\'pcchangeLeft\',\'left2.gif\');this.style.borderColor=\'#8af\';window.status=\''+popCalendar.scrollLeftMessage[popCalendar.language]+'\'" onclick="popCalendar.decMonth()" onmouseout="clearInterval(popCalendar.intervalID1);popCalendar.swapImage(\'pcchangeLeft\',\'left1.gif\');this.style.borderColor=\'#fff\';window.status=\'\'" onmousedown="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.StartDecMonth()\',500)" onmouseup="clearTimeout(popCalendar.timeoutID1);clearInterval(popCalendar.intervalID1)">&nbsp<img id="pcchangeLeft" src="'+popCalendar.imgDir+'left1.gif" width="10" height="11" alt="" />&nbsp</span>&nbsp;';
    sHTML1 += '<span style="border:1px solid #fff;cursor:pointer" onmouseover="popCalendar.swapImage(\'pcchangeRight\',\'right2.gif\');this.style.borderColor=\'#8af\';window.status=\''+popCalendar.scrollRightMessage[popCalendar.language]+'\'" onmouseout="clearInterval(popCalendar.intervalID1);popCalendar.swapImage(\'pcchangeRight\',\'right1.gif\');this.style.borderColor=\'#fff\';window.status=\'\'" onclick="popCalendar.incMonth()" onmousedown="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.StartIncMonth()\',500)" onmouseup="clearTimeout(popCalendar.timeoutID1);clearInterval(popCalendar.intervalID1)">&nbsp<img id="pcchangeRight" src="'+popCalendar.imgDir+'right1.gif" width="10" height="11" alt="" />&nbsp</span>&nbsp;';
    sHTML1 += '<span id="pcspanMonth" style="border:1px solid #fff;cursor:pointer" onmouseover="popCalendar.swapImage(\'pcchangeMonth\',\'drop2.gif\');this.style.borderColor=\'#8af\';window.status=\''+popCalendar.selectMonthMessage[popCalendar.language]+'\'" onmouseout="popCalendar.swapImage(\'pcchangeMonth\',\'drop1.gif\');this.style.borderColor=\'#fff\';window.status=\'\'" onclick="popCalendar.popUpMonth()"></span>&nbsp;';
    sHTML1 += '<span id="pcspanYear" style="border:1px solid #fff;cursor:pointer" onmouseover="popCalendar.swapImage(\'pcchangeYear\',\'drop2.gif\');this.style.borderColor=\'#8af\';window.status=\''+popCalendar.selectYearMessage[popCalendar.language]+'\'" onmouseout="popCalendar.swapImage(\'pcchangeYear\',\'drop1.gif\');this.style.borderColor=\'#fff\';window.status=\'\'" onclick="popCalendar.popUpYear()"></span>&nbsp;';
    document.getElementById('pccaption').innerHTML = sHTML1;

        if (options) {
            if (options.installEventHandlers) {
                // hide calendar when enter has benn pressed
                document.onkeypress = function (event) {
                    if (!event)
                        event = window.event;
                    if (event.keyCode == 27) popCalendar.hideCalendar();
                };
                // hide calendar when ?
                document.onclick = function () {
                    if (!popCalendar.bShow) popCalendar.hideCalendar();
                    popCalendar.bShow = false;
                };
            }

            if (options.makeDraggable) {
                var pcCaption = document.getElementById("pccaption");
                var pcCalendar = document.getElementById('pccalendar');
                pcCaption.onmouseover = function () {pcCaption.parentNode.onmousedown = null;};
                pcCaption.onmouseout = function () {pcCaption.parentNode.onmousedown = function () {popCalendar.dragStart(pcCalendar);};};
                pcCaption.parentNode.onmousedown = function () {popCalendar.dragStart(pcCalendar);};
                popCalendar.dragInit();
            }
        }
    popCalendar.bPageLoaded=true;
  },

  // holidays...
  HolidaysCounter: 0,
  Holidays: new Array(),
  HolidayRec : function(d, m, y, desc) {
    this.d = d;
    this.m = m;
    this.y = y;
    this.desc = desc;
  },
  addHoliday : function(d, m, y, desc) {
    popCalendar.Holidays[HolidaysCounter++] = new HolidayRec (d, m, y, desc);
  },


  hideCalendar: function() {
    popCalendar.crossobj.visibility = 'hidden';
    if (popCalendar.crossMonthObj != null) popCalendar.crossMonthObj.visibility = 'hidden';
    if (popCalendar.crossYearObj  != null) popCalendar.crossYearObj.visibility = 'hidden';
    if(popCalendar.isIE4()){
      popCalendar.showElement('SELECT');
      popCalendar.showElement('APPLET');
    }
  },

  padZero: function(num) {
    return (num < 10) ? '0' + num : num;
  },

  constructDate: function(d,m,y) {
    var sTmp = popCalendar.dateFormat;
    sTmp = sTmp.replace ('dd','<e>');
    sTmp = sTmp.replace ('d','<d>');
    sTmp = sTmp.replace ('<e>',popCalendar.padZero(d));
    sTmp = sTmp.replace ('<d>',d);
    sTmp = sTmp.replace ('mmmm','<p>');
    sTmp = sTmp.replace ('mmm','<o>');
    sTmp = sTmp.replace ('mm','<n>');
    sTmp = sTmp.replace ('m','<m>');
    sTmp = sTmp.replace ('<m>',m+1);
    sTmp = sTmp.replace ('<n>',popCalendar.padZero(m+1));
    sTmp = sTmp.replace ('<o>',popCalendar.monthName[popCalendar.language][m]);
    sTmp = sTmp.replace ('<p>',popCalendar.monthName2[popCalendar.language][m]);
    sTmp = sTmp.replace ('yyyy',y);
    sTmp = sTmp.replace ('yy',popCalendar.padZero(y%100));
    sTmp = sTmp.replace ('hh',popCalendar.hour);
    sTmp = sTmp.replace ('xx',popCalendar.minute);
    sTmp = sTmp.replace ('ss',popCalendar.second);
    return sTmp.replace ('yy',popCalendar.padZero(y%100));
  },

  closeCalendar: function() {
    popCalendar.hideCalendar();
    popCalendar.ctlToPlaceValue.value =
      popCalendar.constructDate(popCalendar.dateSelected,
                    popCalendar.monthSelected,
                    popCalendar.yearSelected);
        if (popCalendar.ctlToPlaceValue2 && popCalendar.ctlToPlaceValue2.value == "") {
      popCalendar.ctlToPlaceValue2.value = popCalendar.ctlToPlaceValue.value;
            popCalendar.ctlToPlaceValue2.focus();
        }



        if (popCalendar.CallbackHandler != '')   {
            eval(popCalendar.CallbackHandler);
        }

        if (document.getElementById('form_changed'))   {
            document.getElementById('form_changed').value=1;
        }
  },

  // Month Pulldown
  StartDecMonth: function() {
    popCalendar.intervalID1 = setInterval("popCalendar.decMonth()",80);
  },

  StartIncMonth: function() {
    popCalendar.intervalID1 = setInterval("popCalendar.incMonth()",80);
  },

  incMonth : function() {
    popCalendar.monthSelected++;
    if (popCalendar.monthSelected > 11) {
      popCalendar.monthSelected = 0;
      popCalendar.yearSelected++;
    }
    popCalendar.constructCalendar();
  },

  decMonth : function() {
    popCalendar.monthSelected--;
    if (popCalendar.monthSelected < 0) {
      popCalendar.monthSelected = 11;
      popCalendar.yearSelected--;
    }
    popCalendar.constructCalendar();
  },

  constructMonth: function() {
    popCalendar.popDownYear()
    if (!popCalendar.monthConstructed) {
      var sHTML = "";
      for (i=0; i<12; i++) {
        var sName = popCalendar.monthName[popCalendar.language][i];
        if (i == popCalendar.monthSelected){
          sName = '<b>' + sName + '</b>';
        }
        sHTML += '<tr><td id="m' + i + '" onmouseover="this.style.backgroundColor=\'#909090\'" onmouseout="this.style.backgroundColor=\'\'" style="cursor:pointer;color:#006" onclick="popCalendar.monthConstructed=false;popCalendar.monthSelected=' + i + ';popCalendar.constructCalendar();popCalendar.popDownMonth();event.cancelBubble=true">&nbsp;' + sName + '&nbsp;</td></tr>';
      }

      document.getElementById('pcselectMonth').innerHTML = '<table style="width:70px;font:11px Arial;border:1px solid #a0a0a0;background-color:#f0f0f0;" cellspacing="0" onmouseover="clearTimeout(popCalendar.timeoutID1)" onmouseout="clearTimeout(popCalendar.timeoutID1);popCalendar.timeoutID1=setTimeout(\'popCalendar.popDownMonth()\',100);event.cancelBubble=true">' + sHTML + '</table>';

      popCalendar.monthConstructed = true;
    }
  },

  popUpMonth: function() {
    if (popCalendar.visMonth == 1) {
      popCalendar.popDownMonth();
      popCalendar.visMonth--;
    } else {
      popCalendar.constructMonth();
      popCalendar.crossMonthObj.visibility = (popCalendar.dom||popCalendar.ie) ? 'visible' : 'show';
      popCalendar.crossMonthObj.left = parseInt(popCalendar.crossobj.left) + 50 + 'px';
      popCalendar.crossMonthObj.top = parseInt(popCalendar.crossobj.top) + 26 + 'px';
      if(popCalendar.isIE4()){
        popCalendar.hideElement('SELECT', document.getElementById('pcselectMonth'));
        popCalendar.hideElement('APPLET', document.getElementById('pcselectMonth'));
      }
      popCalendar.visMonth++;
    }
  },

  popDownMonth: function() {
    popCalendar.crossMonthObj.visibility = 'hidden';
    popCalendar.visMonth = 0;
  },

  // Year Pulldown
  incYear: function() {
    for (var i=0; i<7; i++) {
      var newYear = (i + popCalendar.nStartingYear) + 1;
      if (newYear == popCalendar.yearSelected) {
        var txtYear = '<span style="color:#006;font-weight:bold;">&nbsp;' + newYear + '&nbsp;</span>';
      }
      else {
        var txtYear = '<span style="color:#006">&nbsp;' + newYear + '&nbsp;</span>';
      }
      document.getElementById('y'+i).innerHTML = txtYear;
    }
    popCalendar.nStartingYear++;
    popCalendar.bShow=true;
  },

  decYear: function() {
    for (var i=0; i<7; i++) {
      var newYear = (i + popCalendar.nStartingYear) - 1;
      if (newYear == popCalendar.yearSelected) {
        var txtYear = '<span style="color:#006;font-weight:bold">&nbsp;' + newYear + '&nbsp;</span>';
      }
      else {
        var txtYear = '<span style="color:#006;">&nbsp;' + newYear + '&nbsp;</span>';
      }
      document.getElementById('y'+i).innerHTML = txtYear;
    }
    popCalendar.nStartingYear--;
    popCalendar.bShow=true;
  },

  selectYear: function(nYear) {
    popCalendar.yearSelected = parseInt(nYear + popCalendar.nStartingYear);
    popCalendar.yearConstructed = false;
    popCalendar.constructCalendar();
    popCalendar.popDownYear();
  },

  constructYear: function() {
    popCalendar.popDownMonth();
    var sHTML = '';
    if (!popCalendar.yearConstructed) {
      sHTML = '<tr><td align="center" onmouseover="this.style.backgroundColor=\'#909090\'" onmouseout="clearInterval(popCalendar.intervalID1);this.style.backgroundColor=\'\'" style="cursor:pointer;color:#006" onmousedown="clearInterval(popCalendar.intervalID1);popCalendar.intervalID1=setInterval(\'popCalendar.decYear()\',30)" onmouseup="clearInterval(popCalendar.intervalID1)">-</td></tr>';

      var j = 0;
      popCalendar.nStartingYear = popCalendar.yearSelected - 3;

      for ( var i = (popCalendar.yearSelected-3); i <= (popCalendar.yearSelected+3); i++ ) {
        var sName = i;
        if (i == popCalendar.yearSelected) sName = '<b>' + sName + '</b>';
        sHTML += '<tr><td id="y' + j + '" onmouseover="this.style.backgroundColor=\'#909090\'" onmouseout="this.style.backgroundColor=\'\'" style="cursor:pointer;color:#006" onclick="popCalendar.selectYear('+j+');event.cancelBubble=true">&nbsp;' + sName + '&nbsp;</td></tr>';
        j++;
      }

      sHTML += '<tr><td align="center" onmouseover="this.style.backgroundColor=\'#909090\'" onmouseout="clearInterval(popCalendar.intervalID2);this.style.backgroundColor=\'\'" style="cursor:pointer;color:#006" onmousedown="clearInterval(popCalendar.intervalID2);popCalendar.intervalID2=setInterval(\'popCalendar.incYear()\',30)" onmouseup="clearInterval(popCalendar.intervalID2)">+</td></tr>';

      document.getElementById('pcselectYear').innerHTML = '<table width="44" cellspacing="0" style="font:11px Arial;border:1px solid #a0a0a0;background:#f0f0f0" onmouseover="clearTimeout(popCalendar.timeoutID2)" onmouseout="clearTimeout(popCalendar.timeoutID2);popCalendar.timeoutID2=setTimeout(\'popCalendar.popDownYear()\',100)">' + sHTML + '</table>';

      popCalendar.yearConstructed = true;
    }
  },

  popDownYear: function() {
    clearInterval(popCalendar.intervalID1);
    clearTimeout(popCalendar.timeoutID1);
    clearInterval(popCalendar.intervalID2);
    clearTimeout(popCalendar.timeoutID2);
    popCalendar.crossYearObj.visibility= 'hidden';
    popCalendar.visYear = 0;
  },

  popUpYear: function() {
    var leftOffset;
    if (popCalendar.visYear==1) {
      popCalendar.popDownYear();
      popCalendar.visYear--;
    } else {
      popCalendar.constructYear();
      popCalendar.crossYearObj.visibility = (popCalendar.dom||popCalendar.ie) ? 'visible' : 'show';
      leftOffset = parseInt(popCalendar.crossobj.left) + document.getElementById('pcspanYear').offsetLeft;
      if (popCalendar.ie) leftOffset += 6;
      popCalendar.crossYearObj.left = leftOffset + 'px';
      popCalendar.crossYearObj.top = parseInt(popCalendar.crossobj.top) + 26 + 'px';
      popCalendar.visYear++;
    }
  },

  isIE4: function(){
    var result = false;
    if(!window.XMLHttpRequest && popCalendar.ie){
      result = true;
    }
    return result;
  },

  // calendar
  WeekNbr: function(n) {
    // Algorithm used:
    // From Klaus Tondering's Calendar document (The Authority/Guru)
    // http://www.tondering.dk/claus/calendar.html
    // a = (14-month) / 12
    // y = year + 4800 - a
    // m = month + 12a - 3
    // J = day + (153m + 2) / 5 + 365y + y / 4 - y / 100 + y / 400 - 32045
    // d4 = (J + 31741 - (J mod 7)) mod 146097 mod 36524 mod 1461
    // L = d4 / 1460
    // d1 = ((d4 - L) mod 365) + L
    // WeekNumber = d1 / 7 + 1

    var year = n.getFullYear();
    var month = n.getMonth() + 1;
    if (popCalendar.startAt == 0) {
      var day = n.getDate() + 1;
    } else {
      popCalendar.day = n.getDate();
    }

    var a = Math.floor((14-month) / 12);
    var y = year + 4800 - a;
    var m = month + 12 * a - 3;
    var b = Math.floor(y/4) - Math.floor(y/100) + Math.floor(y/400);
    var J = day + Math.floor((153 * m + 2) / 5) + 365 * y + b - 32045;
    var d4 = (((J + 31741 - (J % 7)) % 146097) % 36524) % 1461;
    var L = Math.floor(d4 / 1460);
    var d1 = ((d4 - L) % 365) + L;
    var week = Math.floor(d1/7) + 1;

    return week;
  },

  constructCalendar : function() {
    var aNumDays = Array (31,0,31,30,31,30,31,31,30,31,30,31);
    var dateMessage;
    var startDate = new Date (popCalendar.yearSelected,popCalendar.monthSelected,1);
    var endDate;

    if (popCalendar.monthSelected==1) {
      endDate = new Date (popCalendar.yearSelected,popCalendar.monthSelected+1,1);
      endDate = new Date (endDate - (24*60*60*1000));
      var numDaysInMonth = endDate.getDate();
    } else {
      var numDaysInMonth = aNumDays[popCalendar.monthSelected];
    }

    var datePointer = 0;
    var dayPointer = startDate.getDay() - popCalendar.startAt;

    if (dayPointer<0) dayPointer = 6;

    var sHTML = '<table style="border:0;font:10px verdana;"><tr>';

    if (popCalendar.showWeekNumber == 1) {
      sHTML += '<td style="width:27px;"><strong>' + popCalendar.weekString[popCalendar.language] + '</strong></td><td rowspan="7" style="width:1px;background:#d0d0d0;padding:0"><img src="'+imgDir+'divider.gif" width="1" alt="" /></td>';
    }

    for (var i = 0; i<7; i++) {
      sHTML += '<td style="width:27px;text-align:right;color:#006;font-weight:bold">' + popCalendar.dayName[popCalendar.language][i] + '</td>';
    }

    sHTML += '</tr><tr>';

    if (popCalendar.showWeekNumber == 1) {
      sHTML += '<td align="right" style="text-align:right;">' + popCalendar.WeekNbr(popCalendar.startDate) + '&nbsp;</td>';
    }

    for (var i=1; i<=dayPointer;i++ ) {
      sHTML += '<td>&nbsp;</td>';
    }

    var sStyle = "";
    for (var datePointer=1; datePointer <= numDaysInMonth; datePointer++ ) {
      dayPointer++;
      sHTML += '<td align="right" style="text-align:right;">';
      sStyle=popCalendar.styleAnchor;
      if ((datePointer == popCalendar.odateSelected) &&
        (popCalendar.monthSelected == popCalendar.omonthSelected) &&
        (popCalendar.yearSelected == popCalendar.oyearSelected)) {
        sStyle+=popCalendar.styleLightBorder;
      }

      var sHint = '';
      for (var k = 0;k < popCalendar.HolidaysCounter; k++) {    // insert holidays
        if ((parseInt(popCalendar.Holidays[k].d) == datePointer) && (parseInt(popCalendar.Holidays[k].m) == (popCalendar.monthSelected+1))) {
          if ((parseInt(popCalendar.Holidays[k].y)==0)||((parseInt(popCalendar.Holidays[k].y)==popCalendar.yearSelected)&&(parseInt(popCalendar.Holidays[k].y)!=0))) {
            sStyle+= 'background-color:#fdd;';
            sHint += sHint=="" ? popCalendar.Holidays[k].desc : "\n" + popCalendar.Holidays[k].desc;
          }
        }
      }

      sHint = sHint.replace('/\"/g', '&quot;');

      dateMessage = 'onmousemove="window.status=\''+popCalendar.selectDateMessage[popCalendar.language].replace('[date]',popCalendar.constructDate(datePointer,popCalendar.monthSelected,popCalendar.yearSelected))+'\'" onmouseout="window.status=\'\'" ';


      //////////////////////////////////////////////
      //////////  Modifications PinoToy  //////////
      //////////////////////////////////////////////
      if (popCalendar.enablePast == 0 &&
        ((popCalendar.yearSelected < popCalendar.yearNow) ||
         (popCalendar.monthSelected < popCalendar.monthNow) &&
         (popCalendar.yearSelected == popCalendar.yearNow) ||
         (datePointer < popCalendar.dateNow) &&
         (popCalendar.monthSelected == popCalendar.monthNow) &&
         (popCalendar.yearSelected == popCalendar.yearNow))) {
        popCalendar.selDayAction = '';
        isPast = 1;
      } else {
        popCalendar.selDayAction = 'href="javascript:popCalendar.dateSelected='+datePointer+';popCalendar.closeCalendar();"';
        isPast = 0;
      }

      sHTML += '<a '+dateMessage+' title="'+sHint+'" style="'+sStyle;

      if ((datePointer == popCalendar.dateNow) &&
        (popCalendar.monthSelected == popCalendar.monthNow) &&
        (popCalendar.yearSelected == popCalendar.yearNow)) {
        sHTML += 'font-weight:bold;color:red;" ';     // today
      } else if (dayPointer % 7 == (popCalendar.startAt * -1)+1) {
        if (isPast==1)                    // sunday
          sHTML += 'color:#909090;" ';
        else
          sHTML += 'color:#54A6E2;" ';
      } else if ((dayPointer % 7 == (popCalendar.startAt * -1)+7 && popCalendar.startAt==1) || (dayPointer % 7 == popCalendar.startAt && popCalendar.startAt==0)) {
        if (isPast==1)                    // saturday
          sHTML += 'color:#909090;" ';
        else
          sHTML += 'color:#54A6E2;" ';
      } else {
        if (isPast==1)                    // all other days
          sHTML += 'color:#909090;" ';
        else
          sHTML += 'color:#006;" ';
      }
      sHTML += popCalendar.selDayAction+'>&nbsp;'+datePointer+'&nbsp;</a>';

      if ((dayPointer+popCalendar.startAt) % 7 == popCalendar.startAt) {
        sHTML += '</tr><tr>';
        if ((popCalendar.showWeekNumber == 1) && (datePointer < numDaysInMonth)) {
          sHTML += '<td align="right" style="text-align:right;">' + (WeekNbr(new Date(popCalendar.yearSelected,popCalendar.monthSelected,datePointer+1))) + '&nbsp;</td>';
        }
      }
    }

    document.getElementById('pccontent').innerHTML   = sHTML;
    document.getElementById('pcspanMonth').innerHTML = '&nbsp;' + popCalendar.monthName[popCalendar.language][popCalendar.monthSelected] + '&nbsp;<img id="pcchangeMonth" src="'+popCalendar.imgDir+'drop1.gif" width="12" height="10" alt="" />';
    document.getElementById('pcspanYear').innerHTML  = '&nbsp;' + popCalendar.yearSelected  + '&nbsp;<img id="pcchangeYear" src="'+popCalendar.imgDir+'drop1.gif" width="12" height="10" alt="" />';
  },

  /**
   * Main function, shows the calendar. Do not forget to call init() beforehand
   *
   * @param ctl1 The "button" which (de-)activates the calendar
   * @param ctl2 The field to receive the selected date
   * @param format Format of the date-string, see constructDate()
   * @param lang Language of the calendar (en, es, de, no, nl)
   * @param past Are dates in the past allowed? yes=1, no=0
   * @param fx x-position of the calendar, -1 for directly below ctl1
   * @param fy y-position of the calendar, -1 for directly below ctl1
   * @param start Start of the week is on Monday (=1) or Sunday (=0)
   */
  showCalendar: function(ctl, ctl2, format, lang, past, fx, fy,start, ctl3) {
    if (start != null && (start==0 || start==1)) popCalendar.startAt = start;
    popCalendar.loadArrays();
    if (lang != null && lang != '') popCalendar.language = lang;

    if (past != null)
      popCalendar.enablePast = past;
    else
      popCalendar.enablePast = 0;
    if (fx != null)
      popCalendar.fixedX = fx;
    else
      popCalendar.fixedX = -1;
    if (fy != null)
      popCalendar.fixedY = fy;
    else
      popCalendar.fixedY = -1;
    if (popCalendar.showToday == 1)
      document.getElementById('pclblToday').innerHTML = popCalendar.todayString[popCalendar.language]+' <a onmousemove="window.status=\''+popCalendar.gotoString[popCalendar.language]+'\'" onmouseout="window.status=\'\'" title="'+popCalendar.gotoString[popCalendar.language]+'" style="'+popCalendar.styleAnchor+'color:#006;" href="javascript:popCalendar.monthSelected=popCalendar.monthNow;popCalendar.yearSelected=popCalendar.yearNow;popCalendar.constructCalendar();">'+popCalendar.dayName[popCalendar.language][(popCalendar.today.getDay()-popCalendar.startAt==-1)?6:(popCalendar.today.getDay()-popCalendar.startAt)]+', '+popCalendar.dateNow+' '+popCalendar.monthName2[popCalendar.language][popCalendar.monthNow].substring(0,3)+' '+popCalendar.yearNow+'</a>';

    popCalendar.popUpCalendar(ctl, ctl2, format, ctl3);
  },

  popUpCalendar: function(ctl, ctl2, format, ctl3) {
    var leftpos = 0;
    var toppos  = 0;
    var formatChar = "";
    var aFormat = new Array();

    if (popCalendar.bPageLoaded) {
      if (popCalendar.crossobj.visibility == 'hidden') {
        popCalendar.ctlToPlaceValue = ctl2;
        popCalendar.ctlToPlaceValue2 = ctl3;
        popCalendar.dateFormat = format;
        formatChar = ' ';
        aFormat = popCalendar.dateFormat.split(formatChar);
        if (aFormat.length < 3) {
          formatChar = '/';
          aFormat = popCalendar.dateFormat.split(formatChar);
          if (aFormat.length < 3) {
            formatChar = '.';
            aFormat = popCalendar.dateFormat.split(formatChar);
            if (aFormat.length < 3) {
              formatChar = '-';
              aFormat = popCalendar.dateFormat.split(formatChar);
              if (aFormat.length < 3) {
                formatChar = '';          // invalid date format
              }
            }
          }
        }

        var tokensChanged = 0;
        var aData;
        if (formatChar != "") {
          aData = ctl2.value.split(formatChar);     // use user's date
          for (var i=0; i<3; i++) {
            if ((aFormat[i] == "d") || (aFormat[i] == "dd")) {
              popCalendar.dateSelected = parseInt(aData[i], 10);
              tokensChanged++;
            } else if ((aFormat[i] == "m") || (aFormat[i] == "mm")) {
              popCalendar.monthSelected = parseInt(aData[i], 10) - 1;
              tokensChanged++;
            } else if (aFormat[i] == "yyyy") {

              popCalendar.yearSelected = parseInt(aData[i], 10);
              tokensChanged++;
            } else if (aFormat[i] == "mmm") {
              for (j=0; j<12; j++) {
                if (aData[i] == popCalendar.monthName[language][j]) {
                  popCalendar.monthSelected=j;
                  tokensChanged++;
                }
              }
            } else if (aFormat[i] == "mmmm") {
              for (j=0; j<12; j++) {
                if (aData[i] == popCalendar.monthName2[language][j]) {
                  popCalendar.monthSelected = j;
                  tokensChanged++;
                }
              }
            }
          }
        }
        var TimeFormatChar = ':';
        var timeString = ctl2.value.split(" ");
        if (timeString[1] !=null) {
          var timeTokens = timeString[1].split(':');
          if(timeTokens[0].length==2) {
            popCalendar.hour = timeTokens[0];
          }
          if (timeTokens[1].length==2) {
            popCalendar.minute = timeTokens[1];
          }
          if (timeTokens[2].length==2) {
            popCalendar.second= timeTokens[2];
          }
        } else {
          popCalendar.hour=00;
          popCalendar.minute=00;
          popCalendar.second=00;
        }


        if ((tokensChanged != 3) ||
          isNaN(popCalendar.dateSelected) ||
          isNaN(popCalendar.monthSelected) ||
          isNaN(popCalendar.yearSelected)) {
          popCalendar.dateSelected  = popCalendar.dateNow;
          popCalendar.monthSelected = popCalendar.monthNow;
          popCalendar.yearSelected  = popCalendar.yearNow;
        }

        popCalendar.odateSelected  = popCalendar.dateSelected;
        popCalendar.omonthSelected = popCalendar.monthSelected;
        popCalendar.oyearSelected  = popCalendar.yearSelected;

        var aTag = ctl;
        try {
          do {
            aTag   = aTag.offsetParent;
            leftpos += aTag.offsetLeft;
            toppos  += aTag.offsetTop;
          } while (aTag.tagName != 'BODY');
       } catch(e){}

        popCalendar.crossobj.left = (popCalendar.fixedX == -1) ? ctl.offsetLeft + leftpos + 'px' : popCalendar.fixedX + 'px' ;
        popCalendar.crossobj.top = (popCalendar.fixedY == -1) ? ctl.offsetTop + toppos + ctl.offsetHeight + 2 + 'px' : popCalendar.fixedY + 'px' ;
        popCalendar.constructCalendar (1, popCalendar.monthSelected, popCalendar.yearSelected);
        popCalendar.crossobj.visibility = (popCalendar.dom||popCalendar.ie) ? "visible" : "show";
        if(popCalendar.isIE4()){
          popCalendar.hideElement('SELECT', document.getElementById('pccalendar'));
          popCalendar.hideElement('APPLET', document.getElementById('pccalendar'));
        }
        popCalendar.zIndex = 9999;
        popCalendar.bShow = true;
      } else {
        popCalendar.hideCalendar();
        if (popCalendar.ctlNow!=ctl) popCalendar.popUpCalendar(ctl, ctl2, format);
      }
      popCalendar.ctlNow = ctl;
    }
  },

    //Das Objekt, das gerade bewegt wird.
    dragObjekt: null,

    // Position, an der das Objekt angeklickt wurde.
    dragX: 0,
    dragY: 0,

    // Mausposition
    posX: 0,
    posY: 0,

    // Initialisierung der ueberwachung der Events
    dragInit: function(obj) {
        document.onmousemove = popCalendar.drag;
        document.onmouseup = popCalendar.dragStop;
    },


    //Wird aufgerufen, wenn ein Objekt bewegt werden soll.
    dragStart: function (element) {
        popCalendar.dragObjekt = element;
        popCalendar.dragX = popCalendar.posX - popCalendar.dragObjekt.offsetLeft;
        popCalendar.dragY = popCalendar.posY - popCalendar.dragObjekt.offsetTop;
    },


    //Wird aufgerufen, wenn ein Objekt nicht mehr bewegt werden soll.
    dragStop: function () {
        popCalendar.dragObjekt=null;
    },

    //Wird aufgerufen, wenn die Maus bewegt wird und bewegt bei Bedarf das Objekt.
    drag: function (ereignis) {

        popCalendar.posX = document.all ? window.event.clientX : ereignis.pageX;
        popCalendar.posY = document.all ? window.event.clientY : ereignis.pageY;
        if(popCalendar.dragObjekt != null) {
            popCalendar.dragObjekt.style.left = (popCalendar.posX - popCalendar.dragX) + "px";
            popCalendar.dragObjekt.style.top = (popCalendar.posY - popCalendar.dragY) + "px";
        }
    }
}


