// JavaScript Document

function alteraCalendario(mes,ano) {
	AjaxRequest();
	if(!Ajax) {
		alert("Erro na chamada");
		return;
	}
	document.getElementById('calendario').innerHTML='<center><font size="1" face="verdana" color="#666"><br /><br /><br /><img src="images/internas/carregando.gif" /><br />Carregando...<br /><br /><br /></font></center>';
	AjaxRequest();
	Ajax.onreadystatechange = CalendarioProcessaResultado;
	Ajax.open('GET', 'calendario/calendario.php?mes='+mes+'&ano='+ano+'&ajaxOn=1', true);
	Ajax.send(null);
}
function CalendarioProcessaResultado() {
	if(Ajax.readyState == 4) {
		if(Ajax.status == 200) {
			var respo = Ajax.responseText;
			document.getElementById("calendario").innerHTML=respo;
		} else {
			alert("Erro: "+Ajax.statusText);
		}
	}
}

function calendarioMov(acao) {
	var aMes = eval(document.getElementById('calSelMes').value);
	var aAno = eval(document.getElementById('calSelAno').value);
	if(acao=="anterior") {
		nMes = aMes-1;
		if(nMes<=0) {
			nMes = 12;
			nAno = aAno-1;
		} else {
			nAno = aAno;
		}
	} else {
		nMes = aMes+1;
		if(nMes>=13) {
			nMes = 1;
			nAno = aAno+1;
		} else {
			nAno = aAno;
		}
	}
	alteraCalendario(nMes,nAno);
}

function _Legend() {
	_Legend.defaultX = 20;
	_Legend.defaultY = 0;

	_Legend.x = 0;
	_Legend.y = 0;

	this.show = function(text, pX, pY){
		$('#calendarioLegenda').fadeIn(200);
		_Legend.x = (pX === undefined)?_Legend.defaultX:pX;
		_Legend.y = (pY === undefined)?_Legend.defaultY:pY;
		document.getElementById('calendarioLegenda').innerHTML = text;
		document.getElementById('calendarioLegenda').style.width = '400px';

		document.getElementById('calendarioLegenda').style.backgroundColor = '#e5e5e5';
		document.getElementById('calendarioLegenda').style.color = '#333333';
		document.getElementById('calendarioLegenda').style.border = '1px solid #5256a6';
		
		document.onmousemove = this.mouseMoving;
	};


	this.hide = function(){
		//_Legend.setVisible(false);
		$('#calendarioLegenda').fadeOut(200);
	};

	_Legend.setVisible = function(pBool){
		if (pBool){
			document.getElementById('calendarioLegenda').style.visibility = "visible";
		} else {
			document.getElementById('calendarioLegenda').style.left = 0;
			document.getElementById('calendarioLegenda').style.top = 0;
			document.getElementById('calendarioLegenda').style.visibility = "hidden";
			document.onmousemove = null;
		}
	};

	// movimento do mouse
	this.mouseMoving = function(e) {
		var posx = 0;
		var posy = 0; 
		if (!e){
			var e = window.event;
		}
		if (e.pageX || e.pageY) 	{ 
			posx = e.pageX; 
			posy = e.pageY; 
		} else if (e.clientX || e.clientY) { 
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		_Legend.setVisible(true);

		_Legend.setMove(posx + _Legend.x, posy + _Legend.y);
	};

	_Legend.setMove = function(pLeft, pTop){
		document.getElementById('calendarioLegenda').style.left = pLeft+'px';
		document.getElementById('calendarioLegenda').style.top = pTop+'px';
	};
}
function _Legend2() {
	_Legend2.defaultX = 20;
	_Legend2.defaultY = 0;

	_Legend2.x = 0;
	_Legend2.y = 0;

	this.show = function(text, pX, pY){
		$('#legend').fadeIn(200);
		_Legend2.x = (pX === undefined)?_Legend2.defaultX:pX;
		_Legend2.y = (pY === undefined)?_Legend2.defaultY:pY;
		document.getElementById('legend').innerHTML = text;
		document.getElementById('legend').style.width = 'auto';

		document.getElementById('legend').style.backgroundColor = '#F1EFE7';
		document.getElementById('legend').style.color = '#333333';
		document.getElementById('legend').style.border = '1px solid #D8D0B8';
		
		document.onmousemove = this.mouseMoving;
	};


	this.hide = function(){
		//_Legend2.setVisible(false);
		$('#legend').fadeOut(200);
	};

	_Legend2.setVisible = function(pBool){
		if (pBool){
			document.getElementById('legend').style.visibility = "visible";
		} else {
			document.getElementById('legend').style.left = 0;
			document.getElementById('legend').style.top = 0;
			document.getElementById('legend').style.visibility = "hidden";
			document.onmousemove = null;
		}
	};

	// movimento do mouse
	this.mouseMoving = function(e) {
		var posx = 0;
		var posy = 0; 
		if (!e){
			var e = window.event;
		}
		if (e.pageX || e.pageY) 	{ 
			posx = e.pageX; 
			posy = e.pageY; 
		} else if (e.clientX || e.clientY) { 
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}

		_Legend2.setVisible(true);

		_Legend2.setMove(posx + _Legend2.x, posy + _Legend2.y);
	};

	_Legend2.setMove = function(pLeft, pTop){
		document.getElementById('legend').style.left = pLeft+'px';
		document.getElementById('legend').style.top = pTop+'px';
	};
}
var Legend = new _Legend();
var Legend2 = new _Legend2();

