function Calendario(nome, nomeCampo, nomeCampoDiv) {
	this.nome = nome;
	this.nomeCampo = nomeCampo;
	this.nomeMes = nome + "_Mes";
	this.nomeDiv = nome + "_DIV";
	this.nomeFrame = nome + "_FRAME";
	if (nomeCampoDiv != null) {this.nomeCampoDiv = nomeCampoDiv;}
	else {this.nomeCampoDiv = this.nomeCampo+"_Div";}
//	this.nomeCampoDiv = (nomeCampoDiv != "")?nomeCampoDiv:this.nomeCampo+"Div";
//	this.campo = document.getElementById(this.nomeCampo);
//	this.mes = document.getElementById(this.nomeMes);
//	this.div = document.getElementById(this.nomeDiv);
//	this.frame = document.getElementById(this.nomeFrame);
	
	this.data = new Date();
	this.hoje = new Date();
	
	this.Mon3 = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'];
	this.Day3 = ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'] 
	
	this.Lz = function(x) { return (x<0||x>=10?"":"0") + x /* local */ }
	
	this.ClickDia = function(x) {
		campo = document.getElementById(this.nomeCampo);
		var DV = +x.value; 
		if (DV==0) {return;}
		with (this.data) { 
			setDate(DV);
			campo.value = this.Lz(getDate()) + '/' + this.Lz(getMonth()+1) + '/' + getFullYear();
		}
		x.className = 'btn';
		this.mostraDiv();
	}
	
	this.PreencheDias = function() {
		campo = document.getElementById(this.nomeCampo);
		mes = document.getElementById(this.nomeMes);
		var J, Q, W, EoM, Sp = ' ', 
		W = ( this.data.getDay() - this.data.getDate() + 77 )%7
		with (new Date(+this.data)) { setDate(32) ; EoM = 32-getDate() }
		for (J=0 ; J<42 ; J++) { 
			Q = J-W;
			document.getElementById('BB_' + this.nome + "_" + this.Lz(J)).value = Q<1 || Q>EoM ? '    ' : Sp+Q+Sp
			//deixa azul o dia de hj
			if ((Q == this.hoje.getDate()) && (this.data.getMonth() == this.hoje.getMonth()) && (this.data.getFullYear() == this.hoje.getFullYear())) {
				document.getElementById('BB_' + this.nome + "_" + this.Lz(J)).style.color = '#0000FF';
			}
			else {
				//deixa sábado e domingo vermelho
				if ((J+1)%7 == 0 || J%7 == 0) {
					document.getElementById('BB_' + this.nome + "_" + this.Lz(J)).style.color = '#FF0000';
				}
				else {document.getElementById('BB_' + this.nome + "_" + this.Lz(J)).style.color = '';}
			}
		}
		with (mes) { // focus() // ?
			value = Sp + this.Mon3[this.data.getMonth()] + Sp + this.data.getFullYear() 
		} 
	}

	this.Mes = function(x) {
		with (this.data) {setMonth(getMonth()+x);}
		this.PreencheDias();
	}

	this.Now = function(X) {
		var T = new Date('1 '+X.value);
		if (isNaN(T)) {
			alert('Erro'); 
		} 
		else { 
			this.data = T;
			this.PreencheDias();
		} 
	}

	this.InitCalendario = function() {
		//form = (nomeForm != null)?document.getElementById(nomeForm):document.forms[0];
		campoDiv = document.getElementById(this.nomeCampoDiv);
	
		div = document.createElement("DIV");
		div.name = this.nomeDiv;
		div.id = this.nomeDiv;
		div.style.display = "none";
		div.style.position = "absolute";
		div.style.zIndex = "10";
		div.style.width = "210px";
//		div.style.filter = "wave";
		campoDiv.appendChild(div);

		frame = document.createElement("IFRAME");
		frame.style.display = "none";
		frame.style.position = "absolute";
		frame.style.top = "0";
		frame.style.left = "0";
		frame.name = this.nomeFrame;
		frame.id = this.nomeFrame;
		frame.src = "";
		frame.frameborder = "0";
		frame.scrolling = "no";
		campoDiv.appendChild(frame);
	
//		div = document.getElementById(this.nomeDiv);
//		frame = document.getElementById(this.nomeFrame);

		html = '';
		html += '<input type="button" class="btn" value="<" onClick="'+this.nome+'.Mes(-12)" onMouseOver="this.className=\'btnOver\'" onMouseOut="this.className=\'btn\'">';
		html += '<input type="button" class="btn" value="-" onClick="'+this.nome+'.Mes(-1)" onMouseOver="this.className=\'btnOver\'" onMouseOut="this.className=\'btn\'">';
		html += '<input type="text" name="'+this.nomeMes+'" id="'+this.nomeMes+'" onChange="Now(this)" class="btn" style="width:90;text-align:center;" readonly>';
		html += '<input type="button" class="btn" value="+" onClick="'+this.nome+'.Mes(+1)" onMouseOver="this.className=\'btnOver\'" onMouseOut="this.className=\'btn\'">';
		html += '<input type="button" class="btn" value=">" onClick="'+this.nome+'.Mes(+12)" onMouseOver="this.className=\'btnOver\'" onMouseOut="this.className=\'btn\'">';
		html += '<br>';
		for (x=0; x<this.Day3.length; x++) {
			html += '<input type="button" class="btn" value="' + this.Day3[x] + '">';
		}
		
		html += '<br>';
		for (var J=0 ; J<42 ; J++) {
			html += '<input type="button" class="btn" name="BB_' + this.nome + "_" + this.Lz(J) + '" id="BB_' + this.nome + "_" + this.Lz(J) +'" value=" ?? " onClick="'+this.nome+'.ClickDia(this)" onMouseOver="this.className=\'btnOver\'" onMouseOut="this.className=\'btn\'">';
			if (J%7==6) {html += '<br>';}
		}

		div.innerHTML = html;
//		this.data = new Date(); 
//		this.data.setDate(1); // Create Global
		this.atualizaData();
	//	PreencheDias();
	}

	this.atualizaData = function() {
		campo = document.getElementById(this.nomeCampo);
		if (campo.value != "") {
			var dataAtual = campo.value.split('/');
			this.data.setDate(dataAtual[0]);
			this.data.setMonth(dataAtual[1]-1);
			this.data.setYear(dataAtual[2]);
		}
		this.PreencheDias();
	}

	this.mostraDiv = function() {
		div = document.getElementById(this.nomeDiv);
		frame = document.getElementById(this.nomeFrame);
		campoDiv = document.getElementById(this.nomeCampoDiv);
		if (div.style.display == 'block') {
			div.style.display = 'none';
			frame.style.display = 'none';
		}
		else {
			this.atualizaData();
			div.style.top = campoDiv.style.top+25;
			if (campoDiv.style.left == "") {campoDiv.style.left = 0;}
			div.style.left = campoDiv.style.left;
			div.style.display = 'block';
			frame.width = div.offsetWidth;
			frame.height = div.offsetHeight;
			frame.style.top = div.style.top;
			frame.style.left = div.style.left;
			frame.style.zIndex = div.style.zIndex - 1;
			frame.style.display = '';
		}
	}

}
