//Atualiza a aplicação a cada 20min
setTimeout("window.location.reload()", 1200000);

// Variáveis comuns
var sizeFull = 12;
var actSize = 0;

function runAjax(url, campo){
	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.");
				}
			}
		}
	}

	if(campo != null) var x = document.getElementById(campo);
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange = function(){
		if(xmlhttp.readyState == 4){
			var retorno = unescape(xmlhttp.responseText.replace(/\+/g, " "));
			if(campo != null) x.innerHTML = retorno;
		}
	}
	xmlhttp.send(null);
}
function openPhoto(url, width, height){
	window.open(url, "photo", "menubar=no,statusbar=no,scrollbars=no,toolbar=no,width=" + width + ",height=" + height + ",top=10,left=10");
}
function abreEnquete(url){
	window.open(url, "enquete", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=auto,resizable=no,copyhistory=no,width=300,height=300,left=50,top=50")
}
function changeFont(action){
	var mySize = document.getElementById("corpoNoticia").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, null);
			document.getElementById("corpoNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("titulo").style.fontSize = (sizeFull + 8) + "px";
		}
	}else{
		if(actSize < 5){
			actSize++;
			sizeFull++;
			runAjax("fontSize.asp?theSize=" + sizeFull, null);
			document.getElementById("corpoNoticia").style.fontSize = sizeFull + "px";
			document.getElementById("titulo").style.fontSize = (sizeFull + 8) + "px";
		}
	}
}
function changeSelect(url){
	location.href = url;
}
function cleanField(object){
	if(object.value == object.defaultValue){
		object.value = "";
	}
}
function fillField(object){
	if(object.value == ""){
		object.value = object.defaultValue;
	}
}

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 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;
	}
}
