// JavaScript Document
var ns=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);
var calunit=ns? "" : "px"

function trim(texto){
	while(texto.indexOf(" ") != -1){
		texto = texto.replace(" ","");
	}
	return texto;
}


function openPage(div, alink){
	enviaRequisicao(div, alink, 'Carregando...');
}

function submeterContato(){
	var nome = document.getElementById('nome');
	var email = document.getElementById('email');
	var assunto = document.getElementById('assunto');
	var mensagem = document.getElementById('mensagem');
	
	if(trim(nome.value) == ""){
		alert('O campo nome é obrigatório.');
		nome.focus();
		return;
	}
	
	if(trim(email.value) == ""){
		alert('O campo e-mail é obrigatório.');
		email.focus();
		return;
	}
	
	if(trim(assunto.value) == ""){
		alert('O campo assunto é obrigatório.');
		assunto.focus();
		return;
	}
	
	if(trim(mensagem.value) == ""){
		alert('O campo mensagem é obrigatório.');
		mensagem.focus();
		return;
	}
	
	var destino = "controlador.php?page=enviaContato&nome="+encodeURI(nome.value)+"&email="+encodeURI(email.value)+"&assunto="+encodeURI(assunto.value)+"&mensagem="+encodeURI(mensagem.value);
	enviaRequisicao('dinamico', destino, 'Enviando...');
}



// Indica site
function openBoxTransmissao(){
	// Esconde o topo
	if(document.getElementById('topo') != null){
		document.getElementById('topo').style.display = 'none'; 
	}

	varRand = Math.ceil(Math.random()*2);
	frameSelecionado = 'document.all.boxTransmissao.style';
	tamanho = screen.height;
	posicaoCaixa = parseInt(document.body.offsetWidth/2) - 310;
	
	if(tamanho < document.body.offsetHeight){
		tamanho = document.body.offsetHeight;
	}
	
	document.getElementById('boxTransmissao').style.height = tamanho + 'px';
	document.getElementById('carregandoTransmissao').style.left = posicaoCaixa + 'px';
	
	if(!ns && !ie && !w3){
		return;
	}
	
	if(ie){
		adDiv2 = eval(frameSelecionado);
	}else if(ns){
		adDiv2 = eval('document.layers["boxTransmissao"]');
	}else if(w3){
		adDiv2 = eval('document.getElementById("boxTransmissao").style');
	}
	
	if(ie || w3){
		document.getElementById('carregandoTransmissao').style.display = 'block';
		document.getElementById('carregandoTransmissao').style.visibility = 'visible';
		document.getElementById('boxTransmissao').style.display = 'block';
		document.getElementById('boxTransmissao').style.visibility = 'visible';
	}else{
		document.layers['boxTransmissao'].visibility = 'hide';
		document.getElementById('carregandoIndicaSite').style.visibility = 'show';
	}
}

function fecharBoxTransmissao(){
	if(ie || w3){
		document.getElementById('carregandoTransmissao').style.display = 'none';
		document.getElementById('boxTransmissao').style.display = 'none';
	}else{
		document.layers['boxTransmissao'].visibility = 'hide';
		document.getElementById('carregandoTransmissao').visibility = 'hide';
	}
	
	// Exibe o topo novamente
	document.getElementById('topo').style.display = 'block';
	document.getElementById('topo').style.visibility = 'visible';
}

function submeterComentario(){
	var nome = document.getElementById('com_nome');
	var email = document.getElementById('com_email');
	var mensagem = document.getElementById('com_mensagem');
	
	if(trim(nome.value) == ""){
		alert('O campo nome é obrigatório.');
		nome.focus();
		return;
	}
	
	if(trim(email.value) == ""){
		alert('O campo e-mail é obrigatório.');
		email.focus();
		return;
	}
	
	if(trim(mensagem.value) == ""){
		alert('O campo mensagem é obrigatório.');
		mensagem.focus();
		return;
	}
	
	var destino = "controlador.php?page=enviaComentario&nome="+encodeURI(nome.value)+"&email="+encodeURI(email.value)+"&mensagem="+encodeURI(mensagem.value);
	enviaRequisicao('dinamicoTransmissao', destino, 'Enviando...');
}