// Verifica se o navegador suporta ajax, se sim retorna objeto do tipo ajax.
function openAjax() {
	var ajax;
	try {
		ajax = new XMLHttpRequest();
	} catch(ee) {
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(E) {
				ajax = false;				
			}
		}
	}
	return ajax;
}

function chama_resultado(id) {		
		// Inicia o Ajax, através da variável Ajax		
		var ajax = openAjax();		
		// Div onde o retorno do ajax sera carregado		
		var recipiente = document.getElementById('enquete');
		
		// Informamos o método e a página que será requisitada
		ajax.open('GET', 'resultado.php?id='+id, true); 

		ajax.onreadystatechange = function() {
			if (ajax.readyState == 1) {
				// Cria o efeito de loading
				//loading(true);	
			} // if->readyState->1
			if (ajax.readyState == 4) {
				if (ajax.status == 200) {
					
					// Pega o conteúdo - HTML - da página requisitada: e coloca dentra da div definida na variável recipiente					
					recipiente.innerHTML = ajax.responseText;								
				} // if-status->200				
			} // if->readyState->4
		} // ajax->onreadystatechange
		// Envia a requisição
		ajax.send(null);
		// Evita o reload da página
		return false;	
}





function open_url(url){
			
	if ( url != "" ){
		if ( url.substring( 0, 4 ) != "http" ){
			window.open(url,"_self");
		}
		else{
			window.open(url);
		}
	}
}


function checkcontato() {
	
	var nome = document.getElementById('nome');
	var email = document.getElementById('email');
	var assunto_combo = document.getElementById('assunto_combo');
	var setor_combo = document.getElementById('setor_combo');
	var numero = document.getElementById('numero');
	var ddd = document.getElementById('ddd');
	var cidade = document.getElementById('cidade');	
	
	if (nome.value==""){
		alert("Por favor, informe seu nome.");		
		nome.focus();
		return false;
	}
	if (email.value=="") {
		alert("Por favor digite um email.");
		email.focus();
		return false;
	}
	if (cidade.value=="") {
		alert("Por favor digite uma Cidade.");
		cidade.focus();
		return false;
	}
	if (ddd.value=="") {
		alert("Por favor digite o DDD do Telefone.");
		ddd.focus();
		return false;
	}
	if (isNaN(ddd.value)){
        alert ("DDD inválido");
        ddd.focus();
        return false;
    }
	if (isNaN(numero.value)){
        alert ("Telefone inválido");
        numero.focus();
        return false;
    }
	if (numero.value=="") {
		alert("Por favor digite o Telefone.");
		numero.focus();
		return false;
	}
	
	/*
	 var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
        if(typeof(mail) == "string"){
                if(er.test(mail)){ return true; }
        }else if(typeof(mail) == "object"){
                if(er.test(mail.value)){ 
                                        return true; 
	*/
	
	var campo_email = email.value;
		
	//Checando se o endereço de e-mail é válido
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo_email))) {
		alert("É necessário o preenchimento de um endereço de e-mail válido.");		
		return false;
	}
	
	if (setor_combo.value=="") {
		alert("Por favor digite um Setor.");		
		return false;
	}
	if (assunto_combo.value=="") {
		alert("Por favor digite um Assunto.");		
		return false;
	}	
	return true;	
}


function buscar_noticia(){
	var mes = document.getElementById('acesso_mes');
	var ano = document.getElementById('acesso_ano');
	
	if ( mes.value == "" ){
		alert("Selecione um mês válido");
	}
	else if ( ano.value == "" ){
		alert("Selecione um ano válido");
	}
	else{
		window.open("noticias_principal.php?ano="+ano.value+"&mes="+mes.value,"_self");		
	}	
}

function buscar(){
	var termo = document.getElementById('buscar');	
		
	if ( termo.value == "Busca" || termo.value == "" ){
		alert("Digite um termo para a busca.");
	}
	else
		window.open("busca.php?termo="+termo.value,"_self");			
}

function verificar_voto(){		
	var i;
    for (i=0;i<document.form_enquete.enq.length;i++){
       if (document.form_enquete.enq[i].checked)
          return true;
    }
	
	alert("É necessário selecionar uma opção.");
	return false;
	/*
    document.bgColor = document.fcores.colorin[i].value 

	var termo = document.getElementById('enq').selected;
	alert(termo);
	*/
	
	/*
	if ( valor == "" ){
		alert("É necessário selecionar uma opção");
		return false;
	}	
	return true;
	*/
}