function AreaTotal(){
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // todos menos Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...funcionaria tb no Explorer 6 modo Strict, Mozilla e Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// todos menos Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 modo Strict 
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // outros Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	if (yScroll < windowHeight){
		AlturaTotal = windowHeight;
	} else {
		AlturaTotal = yScroll;
	}
	if (xScroll < windowWidth){
		LarguraTotal = windowWidth;
	} else {
		LarguraTotal = xScroll;
	}

	return [LarguraTotal,AlturaTotal,windowWidth,windowHeight];
}
function Overlay(modo,uri,w,h) {
	var objBody = document.getElementsByTagName('body').item(0);
	var Area = AreaTotal();
	var Largura = Area[0];
	var Altura = Area[1];
	var LarguraTela = Area[2];
	var AlturaTela = Area[3];
	var bodyOverlay = document.createElement("div");
	bodyOverlay.setAttribute('id','bodyOverlay');
	bodyOverlay.style.height = Altura + 'px'; // fundo com o tamanho total da página.
	if (!document.getElementById('bodyOverlay')) {
		objBody.insertBefore(bodyOverlay, objBody.firstChild);
	}
	if (modo=="img"){
		var bed = document.createElement("div");
		bed.setAttribute('id','bedOverlay');
		bed.style.width = '100%';
		bed.style.height = Altura + 'px';
		bed.style.top = ((AlturaTela/2)-(h/2)) + "px";
		bed.style.left = ((LarguraTela/2)-(w/2)) + "px";
		objBody.insertBefore(bed, objBody.firstChild);
		
		var fechar = document.createElement("a");
		fechar.setAttribute('id','fechar');
		fechar.innerHTML = "fechar";
		fechar.setAttribute('href','javascript:removerOverlay("img")');
		fechar.style.width = (w-28) + "px";
		bed.appendChild(fechar);
		var imagem = document.createElement("img");
		imagem.setAttribute('id','imgOverlay');
		imagem.setAttribute('src',uri);
		bed.appendChild(imagem);
	}
}
function removerOverlay(modo) {
	var bodyOverlay = document.getElementById('bodyOverlay');
	if (bodyOverlay) {
		bodyOverlay.parentNode.removeChild(bodyOverlay);
	}
	if (modo=="img"){
		document.getElementById('bedOverlay').parentNode.removeChild(document.getElementById('bedOverlay'));
	}
}

function TipValor(elem,foco,tip) {
	if (foco == 1 && elem.value==tip){//entrafoco
		elem.value='';
	} else {//saifoco
		if (elem.value=='') elem.value=tip;
	}
}

function LinkInterno(pag){
	document.location.href = pag+".mestri";
}
function SubMenu(num){
	var divs = document.getElementById("menu").getElementsByTagName("div");
	var x = false;
	
	for (var d=0; d<divs.length ;d++){
		if (divs[d].id.substr(5)==num){
			var dd = divs[d].style.display;
			if (dd=="none" || !dd){
				if (!x) x="block"; 
				divs[d].style.display=x;
			} else {
				if (!x) x="none"; 
				divs[d].style.display=x;
			}
		}
	}
}
function menuTroca(elem,acao){
	if (acao==1){
		document.getElementById("menunivel1_"+elem).src = 'material/estilo/ht_menu_' + elem + '_on.gif';
	} else {
		document.getElementById("menunivel1_"+elem).src = 'material/estilo/ht_menu_' + elem + '.gif';
	}
}

function ValidaComTip(elem,tipo){
	if (tipo=="busca") var tip = 'busca';
	else if (tipo=="buscahome") var tip = 'digite palavra-chave';
	else if (tipo=="cadastronome") var tip = 'seu nome';
	else if (tipo=="cadastroemail") var tip = 'seu e-mail';
	
	if (elem.value==''||elem.value==tip){
		alert("Preencha este campo");
		return false;
	} else {
		return true;
	}
}