//Atualiza a aplicação a cada 5min
setTimeout("window.location.reload()", 300000);

// Tenta criar o Objeto de AJAX
try{
	xmlhttp = new XMLHttpRequest();
}catch(err1){
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(err2){
		try{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(err3){
			xmlhttp = false;
			if(err3){
				alert("Desculpe! Mais o seu browser não suporta todas as funcionalidades dessa página.");
			}
		}
	}
}

function validaForm(campo){
	var x = document.getElementById(campo);

	for(var i = 0; i < x.length; i++){
		if(x.elements[i].title != "" && x.elements[i].title.indexOf("Google") == -1){
			if(x.elements[i].name.indexOf("mail") != -1){
				if(x.elements[i].value.indexOf("@") == -1 || x.elements[i].value.indexOf(".") == -1){
					alert("Por favor, preencha o campo " + x.elements[i].title + " corretamente!");
					x.elements[i].focus();
					return false;
				}
			}else if(x.elements[i].value == ""){
				alert("Por favor, preencha o campo " + x.elements[i].title + " corretamente!");
				x.elements[i].focus();
				return false;
			}
		}
	}
	
	for(var i = 0; i < x.length; i++) if(x.elements[i].disabled) x.elements[i].disabled = false;
}
function writePhone(id, nextId){
	var x = document.getElementById(id);
	var y = document.getElementById(nextId);
	
	if(x.value.length == 2 || x.value.length == 7){
		x.value += " ";
	}else if(x.value.length == 12){
		if(nextId != "") y.focus();
	}
}

// Variáveis comuns
var sizeFull = 12;
var actSize = 0;

function abrePop(url){
	window.open(url, "myWindow", "menubar=no,statusbar=no,scrollbars=no,toolbar=no,width=400,height=400,top=10,left=10");
}
function openImg(url){
	window.open(url, "galeria", "menubar=no,statusbar=yes,scrollbars=yes,toolbar=no,resizable=yes,width=700,height=500,top=20,left=20");
}

function validaEnviar(){
	with(document.formEnviar){
		if(txtNome1.value == ""){
			alert("Você deve preencher ao menos um campo referente ao Destinatário!");
			txtNome1.focus();
			return false;			
		}else if(txtNome1.value != "" && txtEmail1.value == ""){
			alert("Preencha os campos corretamente!");
			txtEmail1.focus();
			return false;
		}else if(txtNome1.value != "" && txtEmail1.value.indexOf("@") == -1 || txtNome1.value != "" && txtEmail1.value.indexOf(".") == -1 || txtNome1.value != "" && txtEmail1.value.length < 6){
			alert("Preencha o campo de Email corretamente!");
			txtEmail1.focus();
			return false;
		}
		
		if(txtNome2.value != "" && txtEmail2.value == ""){
			alert("Preencha os campos corretamente!");
			txtEmail2.focus();
			return false;
		}else if(txtNome2.value != "" && txtEmail2.value.indexOf("@") == -1 || txtNome2.value != "" && txtEmail2.value.indexOf(".") == -1 || txtNome2.value != "" && txtEmail2.value.length < 6){
			alert("Preencha o campo de Email corretamente!");
			txtEmail2.focus();
			return false;
		}

		if(txtNome3.value != "" && txtEmail3.value == ""){
			alert("Preencha os campos corretamente!");
			txtEmail3.focus();
			return false;
		}else if(txtNome3.value != "" && txtEmail3.value.indexOf("@") == -1 || txtNome3.value != "" && txtEmail3.value.indexOf(".") == -1 || txtNome3.value != "" && txtEmail3.value.length < 6){
			alert("Preencha o campo de Email corretamente!");
			txtEmail3.focus();
			return false;
		}
		
		if(txtNome.value == ""){
			alert("Por favor, preencha Seu Nome corretamente!");
			txtNome.focus();
			return false;
		}else if(txtEmail.value == "" || txtEmail.value.indexOf("@") == -1 || txtEmail.value.indexOf(".") == -1){
			alert("Por favor, preencha o Seu Email corretamente!");
			txtEmail.focus();
			return false;
		}
	}
}

function changeFont(action){
	var mySize = document.getElementById("dataNoticia").style.fontSize.substr(0, 2);
	if(sizeFull != Math.floor(mySize)){
		sizeFull = Math.floor(mySize);
		actSize = sizeFull - 12;
	}
	if(action == "small"){
		if(actSize > -2){
			actSize--;
			sizeFull--;
			runAjax("fontSize.asp?theSize=" + sizeFull, "fotoAmpl");
			document.getElementById("dataNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("corpoNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("titulo").style.fontSize = (sizeFull + 6) + "px";
		}
	}else{
		if(actSize < 5){
			actSize++;
			sizeFull++;
			runAjax("fontSize.asp?theSize=" + sizeFull, "fotoAmpl");
			document.getElementById("dataNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("corpoNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("titulo").style.fontSize = (sizeFull + 6) + "px";
		}
	}
}

function fndFotoFinal(foto01, foto02, foto03){
	var x = document.getElementById("fundoFoto");
	var y = document.body.offsetHeight;
	
	x.style.height = y;
	
	if(foto01 != "") mostraFundo("foto.asp?id=" + foto01, "justLoad");
	if(foto02 != "") mostraFundo("foto.asp?id=" + foto02, "justLoad");
	if(foto03 != "") mostraFundo("foto.asp?id=" + foto03, "justLoad");
}
function mostraFundo(url, inst){
	var x = document.getElementById("fundoFoto");
	var campoFoto = document.getElementById("fotoAmpl");
	
	xmlhttp.open("GET", url, true);
	if(inst != "justLoad"){
		var myLoading = document.getElementById("load");
		myLoading.style.display = "block";
		myLoading.style.top = document.documentElement.scrollTop + "px";
	}
	
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var retorno = unescape(xmlhttp.responseText.replace(/\+/g, " "));
			campoFoto.innerHTML = retorno;
			if(inst != "justLoad"){
				x.style.display = "block";
				mostraFoto();
			}
		}
	}
	
	xmlhttp.send(null);
}
function fechaFoto(){
	var x = document.getElementById("fundoFoto");
	var campoFoto = document.getElementById("fotoAmpl");
	
	x.style.display = "none";
	campoFoto.style.visibility = "hidden";
}
function mostraFoto(){
	var campoFoto = document.getElementById("fotoAmpl");
	if(document.getElementById("myBigPhoto").complete){
		var bigPhoto = document.getElementById("myBigPhoto");
		
		document.getElementById("legendPhoto").style.width = bigPhoto.width - 20 + "px";
		document.getElementById("upPhoto").style.width = bigPhoto.width + "px";
		var myWidth = Math.floor((775 - (bigPhoto.width + 20)) / 2);
		var myHeight = Math.floor(((screen.height - 170) - (bigPhoto.height + 70)) / 2);
		
		campoFoto.style.width = bigPhoto.width + "px";
		
		var y = document.documentElement.scrollTop;
		campoFoto.style.left = myWidth + "px";
		campoFoto.style.top = y + myHeight + "px";
		campoFoto.style.visibility = "visible";
		
		var myLoading = document.getElementById("load");
		myLoading.style.display = "none";
	}else{
		setTimeout("mostraFoto()", 500);
	}
}
function runAjax(url, campo){
	var x = document.getElementById(campo);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var retorno = unescape(xmlhttp.responseText.replace(/\+/g, " "));
			x.innerHTML = retorno;
		}
	}
	xmlhttp.send(null);
}
function validaEnquete(id, bt){
	var y = document.getElementById(bt);
	var x = document.getElementById(id);
	var myBool = false;
	
	for(var i = 0; i < x.length; i++){
		if(x.elements[i].checked) myBool = true;
	}
	if(!myBool){
		alert("Selecione uma opção para votar!");
		return false;
	}else{
		x.target = "enquete";
		abreEnquete("about:blank");
		y.disabled = true;
	}
}
function abreEnquete(url){
	window.open(url, "enquete", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=250,height=300,left=50,top=50")
}
function abreBanner(banner){
	var x = document.getElementById("rich");
	x.innerHTML = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='392' height='240'><param name='movie' value='" + banner + "'><param name='quality' value='high'><param name='wmode' value='transparent' /><embed src='" + banner + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='392' height='240' wmode='transparent'></embed></object>";
}
function fechaBanner(){
	var x = document.getElementById("rich");
	x.innerHTML = "";
}

function changeSelect(url){
	location.href = url;
}

function openPop(url){
	window.open(url, "aviso", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=300,height=200,left=20,top=20");
}