var ImagemCarregada = false;
var ImagemCarregando = false;
var objMyImage = null;
var agt=navigator.userAgent.toLowerCase();
var ie = (agt.indexOf("msie") != -1);
var carregando_pagina = false;
function resetLayers()
{
	if (ImagemCarregada)
	{
	    document.getElementById('div_foto').style.left = parseInt((document.body.clientWidth-foto_width)/2);
	    document.getElementById('div_foto').style.top = parseInt((document.body.clientHeight-foto_height)/2)+document.body.scrollTop;
	}
	if (ImagemCarregando)
	{
		document.getElementById('div_carregando').style.left = parseInt((document.body.clientWidth-140)/2);
		document.getElementById('div_carregando').style.top = parseInt((document.body.clientHeight-100)/2)+document.body.scrollTop;
	}
}

function setLayers()
{
	var foto = document.getElementById('foto');
	foto_width = foto.width;
	foto_height = foto.height;
	document.getElementById('div_foto').style.left = parseInt((document.body.clientWidth-foto_width)/2);
	document.getElementById('div_foto').style.top = parseInt((document.body.clientHeight-foto_height)/2)+document.body.scrollTop;
}

function Load(img)
{
	document.getElementById('div_foto').style.display = 'none';
	document.getElementById('div_foto').style.left = '-1220';
	document.getElementById('div_foto').style.top = '-1220';
	ImagemCarregando = true;
	document.getElementById('div_carregando').style.left = parseInt((document.body.clientWidth-140)/2);
	document.getElementById('div_carregando').style.top = parseInt((document.body.clientHeight-100)/2)+document.body.scrollTop;
	document.getElementById('div_carregando').style.display = '';
	LoadImage(img);
}

function LoadImage(img)
{
	if (isLowRes)
		path_foto = 'img/'+img+'_800.jpg';
	else
		path_foto = 'img/'+img+'.jpg';
	var foto = document.getElementById('foto');
	foto.src = path_foto;
	if (ie)
	{
		foto.onreadystatechange = function () {
			if (foto.readyState == 'complete')
			{
				ImagemCarregando = false;
				ImagemCarregada = true;
				setTimeout("setLayers();",100);
				document.getElementById('div_carregando').style.display = 'none';			
				document.getElementById('div_foto').style.display = '';
			}
		}
	}
	else
	{
		foto.onload = function () {
			ImagemCarregando = false;
			ImagemCarregada = true;
			document.getElementById('div_carregando').style.display = 'none';
			setLayers();
			document.getElementById('div_foto').style.display = '';
		}
	}
}

function UnloadImage()
{
	ImagemCarregada = false;
	document.getElementById('div_foto').style.display = 'none';
	document.getElementById('div_foto').style.left = '-1220';
	document.getElementById('div_foto').style.top = '-1220';
	document.getElementById('div_carregando').style.left = '-1220';
	document.getElementById('div_carregando').style.top = '-1220';
}

function get_conteudo(id_conteudo)
{
	if (!carregando_pagina)
	{
		document.getElementById('div_carregando_pagina').style.display = '';
		document.getElementById('div_conteudo').innerHTML = "";
		url = 'inc/php/get_conteudo.inc.php?id_conteudo='+id_conteudo;
		carregando_pagina = true;
		ajax(url);
	}
}
function RefreshList(combo)
{
	removeAllOptions(combo);
	var elOptNew = null;
	for(x=0; x<id.length; x++)
	{
		elOptNew = document.createElement('option');
		elOptNew.text = name[x];
		elOptNew.value = id[x];
		var elSel = document.getElementById(combo);
		try {
			elSel.add(elOptNew, null);
		}
		catch(ex) {
			elSel.add(elOptNew);
		}
	}
}
function removeAllOptions(combo)
{
	var elSel = document.getElementById(combo);
	while (elSel.length > 0)
	{
		elSel.remove(elSel.length - 1);
	}
}
function SoNumeros(myfield, e, dec){
	var key;
	var keychar;
	if (window.event) {
		key = window.event.keyCode;
	} else if (e) {
		key = e.which;
	} else {
		return true;
	}
	keychar = String.fromCharCode(key);
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) {
		return true;
	} else if ( ("0123456789").indexOf(keychar) > -1 ) {
		return true;
	} else if (dec && (dec.indexOf(keychar) > -1)){
		return true;
	} else
		return false;
}
window.onscroll = resetLayers;
