function Calendar() {

   // Properties
   this.date            = new Date() 
	this.calendarNode    = null
	this.repository      = new Array()
		
	this.highLightToDay  = true	
	this.showControls    = true
	this.showYear        = true
   this.activeLinkDay   = true
	this.daysToActive    = new Array()
	
	this.tableBorder      = 1
	this.tableBorderColor = '#ACACAC'
   this.tableBgColor	    = '#C1C1C1'
	
   // Methods
   this.setCssCalendar = function() {
		if ( this.setCustomCssCalendar ) {
			this.setCustomCssCalendar()
		} else {
			document.write('<style>')
			document.write('   .toDay              { color: #C1C1C1; font-family: verdana; font-size: 8pt; font-weight: bold; background-color: #666666; text-align: right}')
			document.write('   .day                { color: #666666; font-family: verdana; font-size: 8pt; text-align: right }')
			document.write('   .daysWeek           { color: #666666; font-family: verdana; font-size: 9pt; font-weight: bold}')
			document.write('   .monthName          { color: #666666; font-family: verdana; font-size: 9pt; font-weight: bold; text-align: center}')          		
			document.write('   .calendarLinkToDay	{ color: #C1C1C1; font-family: verdana; font-size: 8pt; font-weight: bold; background-color: #666666; text-align: right; text-decoration: none;}')		
			document.write('	 a.controls:link     { font-family: Verdana;	font-size: 9pt; color: #666666; text-decoration: none; padding-top: 2pt; padding-bottom: 2pt; }')
			document.write('	 a.controls:visited  { font-family: Verdana;	font-size: 9pt; color: #666666; text-decoration: none; padding-top: 2pt; padding-bottom: 2pt; }')			
			document.write('</style>')
		}
   }   
   //
   
   this.create = function() {
      var now      = new Date( this.date.getFullYear(), this.date.getMonth(), this.date.getDate())
      var toDay    = now.getDate()
      var arResult = new Array()
      //
      var firstDay = 1
      //  
      now.setMonth( now.getMonth() + 1 )
      now.setDate(1)
      now.setDate( now.getDate() - 1 )
      var lastDay = now.getDate()
      	
	   // Cria o node do calendário
		arResult.push('<div id="divCalendar">')
		
      // Monta calendário
      arResult.push('<table bgcolor="' + this.tableBgColor + '" border="' + this.tableBorder + '" bordercolor="' + this.tableBorderColor + '" width="100%">')
      //
      var monthName = new Array('Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro')
      var month     = this.date.getMonth()

      // Ano e controles de navegação
		if ( this.showControls && this.showYear) {
			arResult.push('<tr>')
			arResult.push('   <td><a href="javascript:void(0)" onClick="calendar.previousMonth()" class="controls">&lt;&lt;</a></td>')				
			arResult.push('   <td colspan="5" class="monthName">' + this.date.getFullYear() + '</td>')
			arResult.push('   <td><a href="javascript:void(0)" onClick="calendar.nextMonth()" class="controls">&gt;&gt;</a></td>')					
			arResult.push('</tr>')   		
			
			arResult.push('<tr>')		
			arResult.push('   <td colspan="7" class="monthName">' + monthName[month] + '</td>')
			arResult.push('</tr>')   							
		} else {
		   if ( this.showYear) {
				arResult.push('<tr>')
				arResult.push('   <td colspan="7" class="monthName">' + this.date.getFullYear() + '</td>')
				arResult.push('</tr>')   				
			} else {
				if ( this.showControls) {			
					arResult.push('   <td class="controls"><a href="javascript:void(0)" onClick="calendar.previousMonth()" class="controls">&lt;&lt;</a></td>')				
					arResult.push('   <td colspan="5" class="monthName">' + monthName[month] + '</td>')
					arResult.push('   <td class="controls"><a href="javascript:void(0)" onClick="calendar.nextMonth()" class="controls">&gt;&gt;</a></td>')								
				} else {
					arResult.push('<tr>')
					arResult.push('   <td colspan="7" class="monthName">' + monthName[month] + '</td>')
					arResult.push('</tr>')   								
				}
			}	
		}
		
      //  
      arResult.push('<tr>')
      arResult.push('   <td class="daysWeek">D</td>')
      arResult.push('   <td class="daysWeek">S</td>')
      arResult.push('   <td class="daysWeek">T</td>')
      arResult.push('   <td class="daysWeek">Q</td>')
      arResult.push('   <td class="daysWeek">Q</td>')
      arResult.push('   <td class="daysWeek">S</td>')
      arResult.push('   <td class="daysWeek">S</td>')
      arResult.push('</tr>')
      //
      now.setDate(1)
      var weekDays = now.getDay() + 1
      var day      = firstDay
      //
		tempDate = new Date( now.getFullYear(), now.getMonth(), now.getDate())
      while ( day <= lastDay ) {
         //
         arResult.push('<tr>')
         //
         if ( weekDays != 1 && day == 1 ) {
            arResult.push('<td colspan="' + ( weekDays - 1 ) + '" class="day">&nbsp;</td>')
         }       
         while ( weekDays <= 7 && day <= lastDay ) {
			   // Quanto for disponibilizado a mudança de mÊs
				// se preocuopar com a mudança do mes tb
			   tempDate.setDate( day)
            if ( this.highLightToDay && day == toDay ) {
   				if ( this.activeLinkDay && ( this.daysToActive.length == 0 || this.daysToActive.indexOf( getDateString( tempDate)) >= 0 ) ) {				
                  arResult.push('<td class="toDay"><a href="javascript:void(0)" onClick="calendar.onClickDay( this)" day="' + getDateString( tempDate) + '" class="calendarLinkToDay">' + day + '</a></td>')
					} else {
                  arResult.push('<td class="toDay">' + day + '</td>')					
					}	
            } else {			
   				if ( this.activeLinkDay && ( this.daysToActive.length == 0 || this.daysToActive.indexOf( getDateString( tempDate)) >= 0 ) ) {				
                  arResult.push('<td class="day"><a href="javascript:void(0)" onClick="calendar.onClickDay( this)" day="' + getDateString( tempDate) + '" class="calendarLink">' + day + '</a></td>')        
					} else {
                  arResult.push('<td class="day">' + day + '</td>')					
					}						
            }  
            weekDays++
            day++             
         }
         weekDays = 1
         //
         arResult.push('</tr>')
         //
      }
      arResult.push('</table>')
		
	   // Finaliza o node do calendário
		arResult.push('</div>')

		return arResult.join('')
   }   
	
	this.onClickDay = function () {
	   void(0)
	}
	/*
	function ( value) {
	   if ( this.targetInput ) {
   	   this.targetInput.value = value
		} 	
	}*/
	
	this.refresh = function () {
	   this.calendarNode.innerHTML = this.create()
	}
	
	this.nextMonth = function () {
	   this.date.setDate(1)
		this.date.setDate(45)
		this.date.setDate(1)
		this.refresh()
	}
	
	this.previousMonth = function () {
	   this.date.setDate(1)
		this.date.setDate(45)
		this.date.setDate(1)
		
		this.date.setDate(-45)
		this.date.setDate(1)
		this.refresh()		
	}	
	
}


// Instancia o objeto calendar
var calendar = new Calendar()

/*
// Mostra na tela o mes corrente
calendar.create()

// Monta todos os meses do ano
for ( var i = 0; i < 12; i++ ) {
   // Especifica o a database e monta o caledário
   calendar.date = new Date( 2002, i, 1 )
   calendar.create()
   //
}

*/