// JavaScript Document



// CONTROLE DE JANELA *******************************************************************************************************
// Funcoes de apoio para pegar as configuracoes da janela do navegador

function alturaPagina()
{
	if (document.body.scrollHeight > document.body.offsetHeight) return document.body.scrollHeight;
	else return document.body.offsetHeight;
}

function larguraPagina()
{
	if (document.body.scrollWidth > document.body.offsetWidth) return document.body.scrollWidth;
	else return document.body.offsetWidth;
}

function alturaJanela()
{
	if (window.innerHeight) return window.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) return document.documentElement.clientHeight;
	else return document.body.clientHeight;
}

function larguraJanela()
{
	if (window.innerWidth) return self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else return document.body.clientWidth;
}

function posicaoVertical()
{
	if (window.pageYOffset) return window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop) return document.documentElement.scrollTop;
	else return document.body.scrollTop;
}

function posicaoHorizontal()
{
	if (window.pageXOffset) return window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;
	else return document.body.scrollLeft;
}




// CONTROLE DE OBJETOS *******************************************************************************************************
// Funcoes de apoio para ligar, desligar, esconder e mostrar objetos (divs, imagens, etc.)

function posicaoY(objeto)
{
	o = document.getElementById(objeto);
	oTop = o.offsetTop;
	while(o.offsetParent!=null)
	{
		oParent = o.offsetParent;
		oTop += oParent.offsetTop;
		o = oParent;
	}
	return oTop;
}

function posicaoX(objeto)
{
	o = document.getElementById(objeto);
	oLeft = o.offsetLeft;
	while(o.offsetParent!=null)
	{
		oParent = o.offsetParent;
		oLeft += oParent.offsetLeft;
		o = oParent;
	}
	return oLeft;
}

function liga(objeto)
{
	document.getElementById(objeto).style.display = 'block';
}

function desliga(objeto)
{
	document.getElementById(objeto).style.display = 'none';
}

function mostra(objeto,opacidade)
{
	document.getElementById(objeto).style.visibility = 'visible';
	if (opacidade)
	{
		opacidade = (opacidade == 100)?99.999:opacidade;
		document.getElementById(objeto).style.filter = "alpha(opacity:"+opacidade+")";
		document.getElementById(objeto).style.opacity = opacidade/100;
		document.getElementById(objeto).style.MozOpacity = opacidade/100;
		document.getElementById(objeto).style.KHTMLOpacity = opacidade/100;
	}
}

function esconde(objeto)
{
	document.getElementById(objeto).style.visibility = 'hidden';
}

//*****************************************************************************************************************************

function ajustaJanela()
{
	posicionaCortina();
	centraliza('suporte');
}

function ligaCortina()
{
	liga('cortina');
	esconde('cortina');
	posicionaCortina();
	mostra('cortina', 60);
}

function posicionaCortina()
{
	document.getElementById('cortina').style.left = '0px';
	document.getElementById('cortina').style.top = '0px';
	document.getElementById('cortina').style.width = larguraPagina() + 'px';

	if (alturaPagina() < ( document.getElementById('suporte').offsetHeight + posicaoY('suporte') ))
		document.getElementById('cortina').style.height = document.getElementById('suporte').offsetHeight + posicaoY('suporte') + 'px';
	else
		document.getElementById('cortina').style.height = alturaPagina() + 'px';

	if (larguraPagina() < ( document.getElementById('suporte').offsetWidth + posicaoX('suporte') ))
		document.getElementById('cortina').style.width = document.getElementById('suporte').offsetWidth + posicaoX('suporte') + 'px';
	else
		document.getElementById('cortina').style.width = larguraPagina() + 'px';
}

function fechaFoto()
{
	desliga('suporte');
	desliga('cortina');
	document.getElementById('foto').src = 'imagens/carregando.gif';
}

function centraliza(objeto)
{
	var x = (larguraPagina() - document.getElementById(objeto).offsetWidth)/2 + posicaoHorizontal();
	var y = (alturaJanela() - document.getElementById(objeto).offsetHeight)/2 + posicaoVertical();

	if (x < posicaoHorizontal()) x = posicaoHorizontal();
	if (y < posicaoVertical()) y = posicaoVertical();

	document.getElementById(objeto).style.left = parseInt(x) + 'px';
	document.getElementById(objeto).style.top = parseInt(y+5) + 'px';
}

function abreFoto(foto)
{
	carregaFoto(foto);
	liga('suporte');
	esconde('suporte');
	centraliza('suporte');
	ligaCortina();
	mostra('suporte');
}

function carregaFoto(foto)
{
	document.getElementById('foto').src = 'fotos/' + foto + '.jpg';
	document.getElementById('botao').src = 'imagens/bt-fechar.gif';
	//document.getElementById('foto').innerHTML = carregaHTML('fotos/' + foto + '.jpg');
	posicionaCortina();
}

function carregaHTML(url)
{
   var xmlHttp = XmlHttp.create();
   var async = false;
   xmlHttp.open("GET", url, false);
   xmlHttp.send(null);
   return xmlHttp.responseText;
}

function aviso()
{
	document.getElementById('foto').src = 'imagens/aviso.gif';
	document.getElementById('botao').src = 'imagens/bt-fechar.gif';
	liga('suporte');
	esconde('suporte');
	centraliza('suporte');
	ligaCortina();
	mostra('suporte');
}