function validaLogin(){
	nome = document.login.usuario.value;
	senha = document.login.senha.value;
	if (nome == "usuario" || nome == "" || senha == "senha" || senha == "" || nome == "true" || senha == "true"){
		document.getElementById('msgLogin').innerHTML="Dados incorretos.";
		var avisoLogin = setTimeout('limpaAviso("msgLogin")', 3000);
		return false;
	}
	return true;
}
function validaDados(tipoCad){
	if (document.form1.nome.value.length < 8 ){
		document.getElementById('erroContato').innerHTML="Preencha o campo NOME corretamente.";
		document.form1.nome.focus();
		var avisoLogin = setTimeout('limpaAviso("erroContato")', 3000);
		return false;
	}
	if (document.form1.contato.value.length < 2 ){
		document.getElementById('erroContato').innerHTML="Preencha o campo CONTATO corretamente.";
		document.form1.contato.focus();
		var avisoLogin = setTimeout('limpaAviso("erroContato")', 3000);
		return false;
	}
	if(document.form1.email.value=="" || document.form1.email.value.indexOf('@')==-1 || document.form1.email.value.indexOf('.')==-1 ){
		document.getElementById('erroContato').innerHTML="Preencha o campo E-MAIL corretamente.";
		document.form1.email.focus();
		var avisoLogin = setTimeout('limpaAviso("erroContato")', 3000);
		return false;
	}

	if (document.form1.fone.value==""){
		document.getElementById('erroContato').innerHTML="Preencha o campo TELEFONE corretamente.";
		document.form1.fone.focus();
		var avisoLogin = setTimeout('limpaAviso("erroContato")', 3000);
		return false;
	}

	if (document.form1.mensagem.value==""){
		document.getElementById('erroContato').innerHTML="Preencha o campo MENSAGEM corretamente.";
		document.form1.mensagem.focus();
		var avisoLogin = setTimeout('limpaAviso("erroContato")', 3000);
		return false;
	}
	return true;
}

function validaCPF(cpf){
	cpf.value = cpf.value.replace('.', '');   
	cpf.value = cpf.value.replace('.', '');   
	cpf.value = cpf.value.replace('-', ''); 
	if(cpf.value.length < 11 ||
			cpf.value == "00000000000" || cpf.value == "11111111111" ||   
            cpf.value == "22222222222" || cpf.value == "33333333333" ||   
            cpf.value == "44444444444" || cpf.value == "55555555555" ||   
            cpf.value == "66666666666" || cpf.value == "77777777777" ||   
            cpf.value == "88888888888" || cpf.value == "99999999999"){
		if(cpf.value.length == 0){
			cpf.value = "";
		}else{
			cpf.value = cpf.value.substr(0, 3) + '.' + 
    		cpf.value.substr(3, 3) + '.' +   
	   		cpf.value.substr(6, 3) + '-' +   
	    	cpf.value.substr(9, 2);
		}
		document.form1.testeCPF.value = 0;
		alert(unescape("N%FAmero de CPF inv%E1lido. Isso impedir%E1 o cadastramento."));
		return false;
	}else{
	    var a = [];   
        var b = new Number;   
        var c = 11;   
        for (i=0; i<11; i++){   
  	      a[i] = cpf.value.charAt(i);   
          if (i < 9) b += (a[i] * --c);   
        }   
       
        if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }   
    
		b = 0;   
        c = 11;   
       
        for (y=0; y<10; y++) b += (a[y] * c--);   
       
        if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }   
       
        if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])) {   
			cpf.value = cpf.value.substr(0, 3) + '.' + 
		    cpf.value.substr(3, 3) + '.' +   
		   	cpf.value.substr(6, 3) + '-' +   
		    cpf.value.substr(9, 2);
			document.form1.testeCPF.value = 0;
        	alert(unescape("N%FAmero de CPF inv%E1lido. Isso impedir%E1 o cadastramento.")); 
			return false;
        }   

	}
	cpf.value = cpf.value.substr(0, 3) + '.' + 
    cpf.value.substr(3, 3) + '.' +   
   	cpf.value.substr(6, 3) + '-' +   
    cpf.value.substr(9, 2);
	document.form1.testeCPF.value = 1;
	return true;
}

//envento onkeyup do campo CPF  
function maskCPF(CPF) {
    var evt = window.event;   
    kcode=evt.keyCode;   
    if (kcode == 8) return;   
    if (CPF.value.length == 3) { CPF.value = CPF.value + '.'; }   
    if (CPF.value.length == 7) { CPF.value = CPF.value + '.'; }   
    if (CPF.value.length == 11) { CPF.value = CPF.value + '-'; }   
}   

//envento onkeyup do campo Telefone  
function maskFone(fone) {
    var evt = window.event;   
    kcode=evt.keyCode;   
    if (kcode == 8) return;
    if (fone.value.length == 2) {fone.value = '(' + fone.value; }   
	if (fone.value.length == 3) { fone.value = fone.value + ')'; }
    if (fone.value.length == 8) { fone.value = fone.value + '-'; }   
}

//envento onkeyup do campo CEP  
function maskCep(cep) {
    var evt = window.event;   
    kcode=evt.keyCode;   
    if (kcode == 8) return;
    if (cep.value.length == 5) {cep.value = cep.value + '-'; }   
}

function limpaAviso(posicao){
	document.getElementById(posicao).innerHTML="";
}

function geraChave(){
    //gera um número aleatório entre 0 e 10
    var numero = (Math.random() * 11);
	document.writeln(numero);
}

function exibeXML(arquivo){
	if(window.ActiveXObject){
		xmlDoc = new ActiveXObject("Msxml2.DOMdocument.3.0");
	}else if (window.XMLHttpRequest){
		document.getElementById('noticias').innerHTML = "";
		xmlDoc=document.implementation.createDocument("","",null);
	}
	xmlDoc.async = false;
	xmlDoc.validateOnParse = false;
	xmlDoc.preserveWhiteSpace = false;
	xmlDoc.load(arquivo);
	var objNodeList;
	objNodeList = xmlDoc.getElementsByTagName("dados");
	var textos = new Array(objNodeList.length);
	for (var i=0; i<objNodeList.length; i++) {
		textos[i] = "<a href="+objNodeList.item(i).getAttribute('link')+" class='linkNoticias' target=blank>"+objNodeList.item(i).getAttribute('chamada')+"</a>";
	}
	var totalTextos = objNodeList.length;
	if(arquivo=='noticias.xml'){
		document.getElementById('noticias').innerHTML = "Notícias: ("+(parseInt(document.frmNoticias.nrNoticia.value)+1)+" de "+totalTextos+") "+textos[document.frmNoticias.nrNoticia.value];
		var id = window.setInterval(function(){mostraNoticia("Notícias: ("+(parseInt(document.frmNoticias.nrNoticia.value)+1)+" de "+totalTextos+") "+textos[document.frmNoticias.nrNoticia.value], totalTextos)}, 5000);
	};
}

function mostraNoticia(noticia, total) { 
	document.getElementById('noticias').innerHTML = noticia;
	nrNoticia = parseInt(document.frmNoticias.nrNoticia.value);
	nrNoticia += 1;
	if(nrNoticia==total) { 
		nrNoticia=0;
	}
	document.frmNoticias.nrNoticia.value = nrNoticia;
}


function mostraDiv(valor){
	if(valor=="mba"){
		document.getElementById('mba').style.display='block';
		document.getElementById('pos').style.display='none';
		document.getElementById('concurso').style.display='none';
	}else if(valor=="pos"){
		document.getElementById('pos').style.display='block';
		document.getElementById('mba').style.display='none';
		document.getElementById('concurso').style.display='none';
	}else if(valor=="concurso"){
		document.getElementById('concurso').style.display='block';
		document.getElementById('mba').style.display='none';
		document.getElementById('pos').style.display='none';
	}
}
