function calendario(ano,mes,div){



  this.data = new Date();

  this.dataUm = new Date(ano,mes,1);

  this.dia = ['D','S','T','Q','Q','S','S'];

  this.mes = ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'];

  this.dimMes = [31,28,31,30,31,30,31,31,30,31,30,31];



  this.criarCal = function(links){

  	var conteiner = document.getElementById(div);

		var dInicio = this.dataUm.getDay();

		var iniMes = 42 - dInicio;



		this.dimMes[1] = (this.dataUm.getFullYear()%4 == 0)? 29 : 28 ;

		var folha = '<table><tr id="tD">';

		for(var i = 0; i<this.dia.length; i++){

			folha += '<td>'+this.dia[i]+'</td>';

		}

		folha += '</tr><tr>';

		for (i = 0; i<dInicio; i++){

			folha += '<td>&nbsp;</td>';

		 }

	 	for(i = 1 ; i<=this.dimMes[this.dataUm.getMonth()]; i++){

			td_id = (this.dataUm.getFullYear()).toString();

			td_id += (this.dataUm.getMonth()<9) ? "0"+(this.dataUm.getMonth()+1) : (this.dataUm.getMonth()+1);

			td_id += (i<10) ? "0" + i : i;

			if(typeof(links[td_id]) != "undefined"){

				folha += '<td id="'+ td_id +'" onmouseover="textoCal(\'<b>'+ i +'</b> - '+ links[td_id] +'\');" onmouseout="textoCal(\'&nbsp;\');" class="temCal">'+ i +'</td>';

			}else{

				folha += '<td id="'+ td_id +'">'+ i +'</td>';

			}

			if( (i+dInicio)%7 == 0 ){

				folha +='</tr><tr>';

			}

		}

		folha += '</table>';

		conteiner.innerHTML = folha;

		

		document.calendario_frm.cal_month.options[mes].selected = true;

		document.calendario_frm.cal_year.options[ano-2007].selected = true;

	}

}

function novoCal (ano,mes,links){

	if(ano != "" && mes != ""){

	  cl = new calendario(ano,mes,'calendarioR1');

	  cl.criarCal(eventos,links);

	}

}

function textoCal (conteudo){

	document.getElementById('calTexto').innerHTML = conteudo;

}

