
// - calendar
function validDate(date){
  var re = /^[0-9]{2}[.][0-9]{2}[.][0-9]{4}$/;
  return(re.test(date));
}

var CALENDAR=function(destElementID,pozX,pozY,startDate,selectedMonth,selectedDay){
  this.destElementID=destElementID;
  this.pozX=pozX;
  this.pozY=pozY;


//  if (this.destElementID == 'do' && document.getElementById('do').value == '') {
//	  	var tmp = new Date(document.getElementById('od').value.split("-")[0],document.getElementById('od').value.split("-")[1], document.getElementById('od').value.split("-")[2]);
//		selectedMonth = tmp.getMonth();
//		selectedMonth = 2;
//		//startDate = new Date(tmp.getFullYear(), (tmp.getMonth() <=8 ? '0':'') + (tmp.getMonth() <=10? (tmp.getMonth()+1) : tmp.getMonth()), (tmp.getDate() <= 9? '0'+tmp.getDate() : tmp.getDate()));
//		startDate = new Date(tmp.getFullYear(), tmp.getMonth()-1, (tmp.getDate() <= 9? '0'+tmp.getDate() : tmp.getDate()));
//  }
//
//  if(this.destElementID)
//	selectedMonth = (document.getElementById(this.destElementID).value.split("-")[1] - 1);

  if (this.destElementID && !startDate && document.getElementById(this.destElementID).value != '') {
  	var today = new Date();
    var tmp = new Date(document.getElementById(destElementID).value.split("-")[0],document.getElementById(destElementID).value.split("-")[1], document.getElementById(destElementID).value.split("-")[2]);
	selectedMonth = (tmp.getMonth() - today.getMonth() - 1) + (tmp.getFullYear() > today.getFullYear() ? 12 : 0);
	delete selectedDay;
  }

  if (this.destElementID == 'do' && document.getElementById('do').value == '') {
  	var today = new Date();
    var tmp = new Date(document.getElementById('od').value.split("-")[0],document.getElementById('od').value.split("-")[1], document.getElementById('od').value.split("-")[2]);
	selectedMonth = (tmp.getMonth() - today.getMonth() - 1) + (tmp.getFullYear() > today.getFullYear() ? 12 : 0);
	delete selectedDay;
  }

  if(!startDate){
	this.startDate=new Date();
  }else{
    this.startDate=startDate;
  }
  if(!selectedMonth){
    this.selectedMonth=0;
  }else{
    this.selectedMonth=selectedMonth;
  }

  if(!selectedDay){
    this.selectedDay=1;
  }else{
    this.selectedDay=selectedDay;
  }

  this.startMonth=this.startDate.getMonth();
  this.startYear=this.startDate.getYear();
  this.calendarContainerID="calendar";
  this.monthCount=16;



  if(this.startYear<1000){
    this.startYear=1900+this.startYear;
  }



  this.months=[];
  this.monthsHTML=[];

  this.returnDate=function(elementID,date){
    document.getElementById(elementID).value=date;
  }

  this.showCalendar=function(){
    this.closeCalendar();
    this.generateMonthList();
    this.calendarDiv=document.createElement('div');
    this.calendarDiv.className="calendar";
    this.calendarDiv.id="calendar";
    this.calendarDiv.innerHTML='xxx';
    this.calendarDiv.style.left=pozX+'px';

    this.calendarDiv.style.top=pozY+'px';
    this.calendarDiv.innerHTML=this.HTML;
    document.getElementsByTagName('body')[0].appendChild(this.calendarDiv);
    this.selectMonth(this.selectedMonth);
    //this.setSelects();
  }

  this.returnSelectsDate=function(elementID){
    day=document.getElementById('calendarDay').value;
    monthName=document.getElementById('calendarMonth').options[document.getElementById('calendarMonth').selectedIndex].innerHTML;
    year=document.getElementById('calendarYear').options[document.getElementById('calendarYear').selectedIndex].innerHTML;

    switch(monthName)
    {
    case 'Styczeń':
      month='01';
      break;
    case 'Luty':
      month='02';
      break;
    case 'Marzec':
      month='03';
      break;
    case 'Kwiecień':
      month='04';
      break;
    case 'Maj':
      month='05';
      break;
    case 'Czerwiec':
      month='06';
      break;
    case 'Lipiec':
      month='07';
      break;
    case 'Sierpień':
      month='08';
      break;
    case 'Wrzesień':
      month='09';
      break;
    case 'Październik':
      month='10';
      break;
    case 'Listopad':
      month='11';
      break;
    case 'Grudzień':
      month='12';
      break;
    default:
      month='01';
    }


      if((day*1)<10){
        day='0'+(day*1);
      }

      //var date=day+'.'+month+'.'+year;
	  var date=year+'-'+month+'-'+day;
      document.getElementById(elementID).value=date;
  }

  this.setSelects=function(){
    this.generateMonthList();
    day=this.selectedDay;
    month=this.months[this.selectedMonth].month;
    year=this.months[this.selectedMonth].year;

    startYear=this.months[0].year;
    endYear=this.months[this.monthCount-1].year;

    i=0;
    /* for(s=document.getElementById('calendarYear').length-1;s>=0;s--)
    {
      document.getElementById('calendarYear').remove(s);
    }*/
    document.getElementById('calendarYear').innerHTML='';
    for(y=startYear;y<=endYear;y++){
      if(y==year){
        document.getElementById('calendarYear').options[i++]=new Option(y, y-year, true);
        document.getElementById('calendarYear').options[i-1].setAttribute('selected','selected');
      }else{
        document.getElementById('calendarYear').options[i++]=new Option(y, y-year);
      }
    }


    i=0;
    document.getElementById('calendarMonth').innerHTML='';
    for(m=0;m<this.monthCount;m++){
      if(m==this.selectedMonth){
        if(this.months[m].year==year){
          /* option=document.createElement('option');
          option.innerHTML=this.months[m].monthName;
          option.value=m;
          document.getElementById('calendarMonth').appendChild(option);*/

          document.getElementById('calendarMonth').options[i++]=new Option(this.months[m].monthName, m, true);
          document.getElementById('calendarMonth').options[i-1].setAttribute('selected','selected');
        }
      }else{
        if(this.months[m].year==year){
          /* option=document.createElement('option');
          option.innerHTML=this.months[m].monthName;
          option.value=m;
          document.getElementById('calendarMonth').appendChild(option);*/

          document.getElementById('calendarMonth').options[i++]=new Option(this.months[m].monthName, m);
        }
      }
    }


    i=0;
    daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
      daysInMonths[1] = 29;
    else
      daysInMonths[1] = 28;
    days=daysInMonths[month];

    document.getElementById('calendarDay').innerHTML='';
    for(d=1;d<=days;d++){
      if(d==day){
        document.getElementById('calendarDay').options[i++]=new Option(d, d, true);
        document.getElementById('calendarDay').options[i-1].setAttribute('selected','selected');
      }else{
        document.getElementById('calendarDay').options[i++]=new Option(d, d);
      }
    }

  }

  this.generateMonthList=function(){
    var i;
    var m=this.startMonth;
    var y=this.startYear;
    for(i=0;i<this.monthCount;i++){

      if(m>11){
        m-=12;
        y+=1;
      }

      this.months[i]=new MONTH(this.destElementID,m,y);
      this.monthsHTML[i]=this.months[i].generateTable();

      m+=1;
    }

    this.HTML=	'<iframe frameborder="0" style="border:none;width:380px;height:159px;" src=""></iframe>'+
          '<div style="margin-top:-159px;width:380px;height:159px;overflow:hidden;position:relative;">'+
          '<div id="months" style="overflow:hidden;">'+
          '<div id="calendar_next" onclick="(new CALENDAR(\'\',\'\',\'\',\'\')).nextCalendar()" style="cursor:pointer;position:absolute;right:5px;top:3px;width:14px;height:15px;background: url(/images/wypoczynek.pl/calendar/next.png)">&nbsp;</div>'+
            '<div id="calendar_previous" onclick="(new CALENDAR(\'\',\'\',\'\',\'\')).previousCalendar()" style="display:none;cursor:pointer;position:absolute;left:5px;top:3px;width:14px;height:15px;background: url(/images/wypoczynek.pl/calendar/prev.png)">&nbsp;</div>'+
              '<table style="text-align:center" cellspacing="0" cellpadding="0">'+
                '<tr class="monthNames" style="background-color:#F4F3F0;">';

      for(i=0;i<this.monthCount;i++){
        this.HTML+=			'<td><div style="width:190px;height:24px;font-size:12px;font-weight:bold;color:#83CB04"><div style="padding-top:4px">'+this.months[i].monthName+' '+this.months[i].year+'</div></div></td>';
      }

      this.HTML+=			'</tr>';
      this.HTML+=			'<tr>';


      for(i=0;i<this.monthCount;i++){
        this.HTML+=			'<td style="border-right:1px solid #dcdcdc"><div style="width:190px;height:133px;">'+this.monthsHTML[i]+'</div></td>';
      }

      this.HTML+=			'</tr>'+
              '</table>'+
            '</div>'+
//            '<table cellspacing="0" cellpadding="0" class="last_line">'+
//              '<tr>'+
//                '<td style="text-align:left;vertical-align:bottom;padding-left:5px">'+
//                  'Dzień'+
//                '</td>'+
//                '<td style="text-align:left;vertical-align:bottom;padding-left:5px">'+
//                  'Miesiąc'+
//                '</td>'+
//                '<td style="text-align:left;vertical-align:bottom;padding-left:5px">'+
//                  'Rok'+
//                '</td>'+
//                '<td rowspan="2" style="text-align:right;vertical-align:bottom;padding-left:5px;">'+
//                  '<div style="width:110px;font-size:12px;padding-bottom:5px" >'+
//                    '<span style="font-size:11px;font-weight:normal;color:#003889;cursor:pointer;margin:0 5px 15px 0;" onclick="(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()" onmouseover="this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'"><img style="position:relative;top:1px;margin-right:3px;" src="/images/wypoczynek.pl/calendar/close.png" alt=""/>Zamknij</span>'+
//                  '</div>'+
//                '</td>'+
//              '</tr>'+
//              '<tr>'+
//                '<td style="vertical-align:top;text-align:left;padding-left:5px;padding-bottom:6px">'+
//                  '<select id="calendarDay" style="width:40px;font-size:11px;">'+
//                  '</select>'+
//                '</td>'+
//                '<td style="vertical-align:top;text-align:left;padding-left:5px;padding-bottom:6px">'+
//                  '<select onchange="(new CALENDAR(\'\',\'\',\'\',\'\')).selectMonth(this.value);(new CALENDAR(\''+this.destElementID+'\','+this.pozX+','+this.pozY+',new Date('+this.startYear+','+this.startMonth+','+1+'),this.value,document.getElementById(\'calendarDay\').value)).setSelects();" id="calendarMonth" style="width:85px;font-size:11px;">'+
//                  '</select>'+
//                '</td>'+
//                '<td style="vertical-align:top;text-align:left;padding-left:5px;padding-bottom:6px;white-space:nowrap">'+
//                  '<div style="width:120px"><select onchange="(new CALENDAR(\'\',\'\',\'\',\'\')).selectMonth(Math.max(Math.min(document.getElementById(\'calendarMonth\').value*1+(12*this.value),'+(this.monthCount-1)+'),0));(new CALENDAR(\''+this.destElementID+'\','+this.pozX+','+this.pozY+',new Date('+this.startYear+','+this.startMonth+','+1+'),Math.max(Math.min(document.getElementById(\'calendarMonth\').value*1+(12*this.value),'+(this.monthCount-1)+'),0),document.getElementById(\'calendarDay\').value)).setSelects();" id="calendarYear" style="width:60px;font-size:11px;float:left;margin-right:5px">'+
//                  '</select>'+
//                  '<img src="/images/wypoczynek.pl/calendar/ok.png" onclick="(new CALENDAR(\'\',\'\',\'\',\'\')).returnSelectsDate(\''+this.destElementID+'\');(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"></div></div>'+
//                '</td>'+
//              '</tr>'+
//            '</table>'+

          '</div>'+
        '</div>';
  }


  this.closeCalendar = function(){
    var cal=document.getElementById('calendar');
    if(cal)
      cal.parentNode.removeChild(cal);
  }

  this.previousCalendar = function(){
    var marginLeft=document.getElementById('months').style.marginLeft;
    var ml=marginLeft.slice(0,marginLeft.length-2);
    ml=ml*1;
    document.getElementById('calendar_next').style.display='block';

    if(ml<0){
      document.getElementById('months').style.marginLeft=ml+382+"px";
      /* for(i=12;i<=382;i+=5){
        setTimeout("(new CALENDAR(\'\',\'\',\'\',\'\')).scrollCalendar("+(ml+i)+")",i*2);
      }*/
    }
    if(ml>=(-382)){
      document.getElementById('calendar_previous').style.display='none';
    }
  }

  this.nextCalendar = function(){
    var marginLeft=document.getElementById('months').style.marginLeft;
    var ml=marginLeft.slice(0,marginLeft.length-2);
    ml=ml*1;
    document.getElementById('calendar_previous').style.display='block';

    if(ml>(-(this.monthCount/2-2)*382)){
      document.getElementById('months').style.marginLeft=ml-382+"px";
    }
    if(ml<=(-(this.monthCount/2-3)*382)){
      document.getElementById('calendar_next').style.display='none';
    }
  }

  this.selectMonth = function(monthNumber){
    var marginLeft=document.getElementById('months').style.marginLeft;
    var ml=marginLeft.slice(0,marginLeft.length-2);
    ml=ml*1;

    document.getElementById('calendar_previous').style.display='block';
    document.getElementById('calendar_next').style.display='block';

    if((monthNumber==0)||(monthNumber==1)){
      document.getElementById('calendar_previous').style.display='none';
    }else if((monthNumber==(this.monthCount-1))||(monthNumber==(this.monthCount-2))){
      document.getElementById('calendar_next').style.display='none';
    }

    document.getElementById('months').style.marginLeft=-Math.floor(monthNumber/2)*382+"px";
  }

  this.scrollCalendar = function(px){
    document.getElementById('months').style.marginLeft=px+"px";
  }


}


var MONTH=function(destElementID,month,year){
  this.today=new Date();
  //alert(this.today.getFullYear());
  //alert(this.today.getMonth()+1);
  //alert(this.today.getDate());
  if((this.today.getFullYear()==year)&&(this.today.getMonth()==month)){
    this.currentMonth=true;
  }


  this.destElementID=destElementID;
  this.month=month;
  this.year=year;
  var monthNames = ['Styczeń', 'Luty', 'Marzec', 'Kwiecień', 'Maj', 'Czerwiec', 'Lipiec', 'Sierpień', 'Wrzesień', 'Październik', 'Listopad', 'Grudzień'];
  this.monthName=monthNames[this.month];

  this.daysInMonths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  if (((this.year % 4 == 0) && (this.year % 100 != 0)) || (this.year % 400 == 0))
    this.daysInMonths[1] = 29;
  else
    this.daysInMonths[1] = 28;
  this.days=this.daysInMonths[this.month];

  this.validDate=function(day){
    var m;

    if(((this.month*1)+1)<10){
      m='0'+((this.month*1)+1);
    }else{
      m=(this.month*1)+1;
    }

    if((day*1)<10){
      day='0'+(day*1);
    }


    //var date=day+'.'+m+'.'+this.year;
	var date=this.year+'-'+m+'-'+day;
    return date;
  };

  this.generateTable=function(){
    this.previousMonth=this.month-1;
    this.previousYear=this.year;
    this.nextMonth=(this.month*1)+1;
    this.nextYear=this.year;
    if(this.previousMonth<0){
      this.previousMonth=11;
      this.previousYear--;
      }
    if(this.nextMonth>11){
      this.nextMonth=0;
      this.nextYear++;
      }

    this.previousMonth=new MONTH(this.destElementID,this.previousMonth,this.previousYear);
    this.nextMonth=new MONTH(this.destElementID,this.nextMonth,this.nextYear);

    var firstDay = new Date(this.year,this.month,1);
      var startDay = firstDay.getDay()-1 ;
      if (startDay < 0) startDay = 6;

      this.numberOfWeeks=Math.ceil((this.daysInMonths[this.month]+startDay)/7);

      this.output='<tr>'+
              '<td class="dayName">'+
                'Pn'+
              '</td>'+
              '<td class="dayName">'+
                'Wt'+
              '</td>'+
              '<td class="dayName">'+
                'Śr'+
              '</td>'+
              '<td class="dayName">'+
                'Cz'+
              '</td>'+
              '<td class="dayName">'+
                'Pt'+
              '</td>'+
              '<td class="dayName">'+
                'So'+
              '</td>'+
              '<td class="sunday">'+
                'Ni'+
              '</td>'+
            '</tr>';
      this.day=1;

      for(var i=1;i<=this.numberOfWeeks;i++){
      /*
      if(i%2==0)
        this.output+='<tr class="even">';
      else
      */
        this.output+='<tr>';

        if(i==1){
          this.generateFirstWeek(startDay);
      }else if(i==this.numberOfWeeks){
        this.generateLastWeek();
      }else{
        this.generateWeek();
      }
      this.output+='</tr>';
    }
    return '<table class="monthTable" cellspacing="0" cellpadding="0">'+this.output+'</table>';
  }

  this.generateFirstWeek=function(startDay){
    var z;
    var pastDay=false;
    var currentDay=false;
    for(z=0;z<startDay;z++){
      if((this.currentMonth)&&(this.day<this.today.getDate())){
        pastDay=true;
      }else{
        pastDay=false;
      }



      if((this.currentMonth)&&(this.day==this.today.getDate())){
        currentDay=true;
      }else{
        currentDay=false;
      }


      if(this.month==0){
        if(pastDay){
          this.output+='<td class="disabled past">';
        }else{
          this.output+='<td class="disabled" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.previousMonth.validDate(this.previousMonth.days-(startDay-z)+1)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
        }
      }else{
        if(pastDay){
          this.output+='<td class="disabled past">';
        }else{
          this.output+='<td class="disabled" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.previousMonth.validDate(this.previousMonth.days-(startDay-z)+1)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"     onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
        }
      }
      this.output+=this.previousMonth.days-(startDay-z)+1;
      this.output+='</td>';
    }
    for(z=1;z<=(7-startDay);z++){
      if((this.currentMonth)&&(this.day<this.today.getDate())){
        pastDay=true;
      }else{
        pastDay=false;
      }


      if((this.currentMonth)&&(this.day==this.today.getDate())){
        currentDay=true;
      }else{
        currentDay=false;
      }


      if(z==(7-startDay)){
        if(pastDay){
          this.output+='<td class="sunday past">';
        }else{
          if(currentDay){
            this.output+='<td class="sunday current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }else{
            this.output+='<td class="sunday" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }
      }else{
        if(pastDay){
          this.output+='<td class="past">';
        }else{
          if(currentDay){
            this.output+='<td class="current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }else{
            this.output+='<td onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }
      }

      this.output+=(this.day)++;
      this.output+='</td>';
    }
  };

  this.generateLastWeek=function(){
    var z;
    var m=1;
    var pastDay=false;
    var currentDay=false;
    for(z=1;z<=7;z++){
      if((this.currentMonth)&&(this.day<this.today.getDate())){
        pastDay=true;
      }else{
        pastDay=false;
      }

      if((this.currentMonth)&&(this.day==this.today.getDate())){
        currentDay=true;
      }else{
        currentDay=false;
      }



      if(this.day<=this.daysInMonths[this.month]){
        if(z==7){
          if(pastDay){
            this.output+='<td class="sunday past">';
          }else{
            if(currentDay){
              this.output+='<td class="sunday current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
            }else{
              this.output+='<td class="sunday" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
            }
          }
        }else{
          if(pastDay){
            this.output+='<td class="past">';
          }else{
            if(currentDay){
              this.output+='<td class="current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
            }else{
              this.output+='<td onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
            }
          }
        }

        this.output+=(this.day)++;

      }else{
        if(this.month==11){
          if(pastDay){
            this.output+='<td class="disabled past">';
          }else{
            this.output+='<td class="disabled" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.nextMonth.validDate(m)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }else{
          if(pastDay){
            this.output+='<td class="disabled past">';
          }else{
            this.output+='<td class="disabled" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.nextMonth.validDate(m)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }
        this.output+=m++;
      }

      this.output+='</td>';
    }
  };

  this.generateWeek=function(){
    var z;
    var pastDay=false;
    var currentDay=false;
    for(z=1;z<=7;z++){
      if((this.currentMonth)&&(this.day<this.today.getDate())){
        pastDay=true;
      }else{
        pastDay=false;
      }

      if((this.currentMonth)&&(this.day==this.today.getDate())){
        currentDay=true;
      }else{
        currentDay=false;
      }


      if(z==7){
        if(pastDay){
          this.output+='<td class="sunday past">';
        }else{
          if(currentDay){
            this.output+='<td class="sunday current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }else{
            this.output+='<td class="sunday" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }
      }else{
        if(pastDay){
          this.output+='<td class="past">';
        }else{
          if(currentDay){
            this.output+='<td class="current" onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }else{
            this.output+='<td onclick="document.getElementById(\''+this.destElementID+'\').value=\''+this.validDate(this.day)+'\';(new CALENDAR(\'\',\'\',\'\',\'\')).closeCalendar()"    onmouseover="this.style.backgroundColor=\'#EBFBCF\'" onmouseout="this.style.backgroundColor=\'#ffffff\'">';
          }
        }
      }
      this.output+=(this.day)++;
    }
  };
}


function findPos(obj) {
  var curleft = curtop = 0;
  if (obj.offsetParent) {
    do {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;
    } while (obj = obj.offsetParent);
  }
  return [curleft,curtop];
}


