// JavaScript Document

function colunas() {
	var topo = document.getElementById('topo');
	var esquerda = document.getElementById('esquerda');
	var direita = document.getElementById('direita');
	var rodape = document.getElementById('rodape');

	if(esquerda.offsetHeight > direita.offsetHeight) {
		rodape.style.top = topo.offsetHeight + esquerda.offsetHeight + 20 + "px";
	} else {
		rodape.style.top = topo.offsetHeight + direita.offsetHeight + 20 + "px";
	}
}

function validanewsletter() {
	var frm = document.formnews;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;	

	if(frm['tmp.email'].value == '') {
		frm['tmp.email'].focus(); alert('É necessário preencher o e-mail.'); return false;
	} else if(!emailRE.test(frm['tmp.email'].value)) {
		frm['tmp.email'].focus(); frm['tmp.email'].select(); alert('Digite um e-mail válido.'); return false;
	}
	
	frm.submit();	
}
function validarcontato() {
	var frm = document.contato;
	var emailRE = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	var catid = document.getElementById('nm_catid');
	catid.value = "";
	
	if(frm['tmp.nome'].value != "" == '') {frm['tmp.nome'].focus(); alert('É necessário preencher o nome.'); return false;}
	if(frm['tmp.email'].value == '') {
		frm['tmp.email'].focus(); alert('É necessário preencher o e-mail.'); return false;
	} else if(!emailRE.test(frm['tmp.email'].value)) {
		frm['tmp.email'].focus();frm['tmp.email'].select(); alert('Digite um e-mail válido.'); return false;
	}
	if(frm['tmp.mensagem'].value == '') {frm['tmp.mensagem'].focus(); alert('É necessário preencher a mensagem.'); return false;}
	if(frm['tmp.usuario'].value == '0') {frm['tmp.usuario'].focus(); alert('É necessário escolher o tipo de usuário.'); return false;
	} else {
		catid.value=frm['tmp.usuario'].value;
	}
	frm.submit();
}

/* FOTOS */

function ampliargaleria(pasta,nome) {
	window.open('pop.wsp?tmp_pasta='+pasta+'&tmp_nome='+nome, 'FOTO', "status=no, width=1, height=1")
}

function resizewindow() {
	
	// VERIFICA NAVEGADOR E SETA CORRECAO
		if (window.navigator.userAgent.indexOf('MSIE 7.0') != -1) {
			fotolargura = 10;
			fotoaltura = 78;
		} else if (window.navigator.userAgent.indexOf('MSIE 6.0') != -1) {
			fotolargura = 16;
			fotoaltura = 37;
		} else if (window.navigator.userAgent.indexOf('Firefox') != -1 || window.navigator.userAgent.indexOf('Mozilla') != -1) {
			fotolargura = 10;
			fotoaltura = 30;
		} 
		
	// RESIZE DA FOTO
	
	var larguratela = screen.width;
	var alturatela = screen.height;
	
	var tamanhofoto = document.images[0];

	var w = tamanhofoto.offsetWidth;
	var h = tamanhofoto.offsetHeight;
	
	if(w>h) {
		tamanhofoto.width = w;
	} else {
		tamanhofoto.width = h;
	}

	
	// RESIZE DA JANELA E SETA FOCUS
	
	window.resizeTo(w+fotolargura, h+fotoaltura);
	self.focus();
	
	// MOVE JANELA
	
	var topo = alturatela/2 - h/2;
	var esquerda = larguratela/2 -w/2;	
	
	window.moveTo(esquerda, topo);
}