 function validar()
   {
	  //d = document.cadastro;
	  if (document.getElementById("nome").value == "")
	     {
           alert("O campo nome deve ser preenchido!");
           document.getElementById("nome").focus();
           erro = "erro";
		   return false;
         }
	  if (document.getElementById("end").value == "")
	     {
           alert("O campo Endereço deve ser preenchido!");
           document.getElementById("end").focus();
           erro = "erro";
		   return false;
         }
	  if (document.getElementById("cidade").value == "")
	     {
           alert("O campo Cidade deve ser preenchido!");
           document.getElementById("cidade").focus();
           erro = "erro";
		   return false;
         }
	  if (document.getElementById("cep").value == "")
	     {
           alert("O campo Cep deve ser preenchido!");
           document.getElementById("cep").focus();
           erro = "erro";
		   return false;
         }
	  if (document.getElementById("emailcad").value == "")
	     {
           alert("O campo E-mail deve ser preenchido!");
           document.getElementById("emailcad").focus();
           erro = "erro";
		   return false;
         }
	  if (document.getElementById("inst").value == "OUTRA INSTITUIÇÃO")
	     {
           if (document.getElementById("other_inst").value == "") {
				   alert("Campo Outra Instituição é obrigatório");
				   document.getElementById("other_inst").focus();
				   erro = "erro";
				   return false;
			   }
         }
		 
   return true;
 }

enviar = function(){
    $("cadastro").request
    ({
        onLoading: carregando,
        onComplete: completo
    });
}
//essa função é chamando quando o arquivo php estiver sendo executado
carregando = function(){$("contentarea").innerHTML = "Enviando...<br>";}
//essa função é chamada quando o arquivo php terminar sua execução
completo = function(){$("contentarea").innerHTML += "Enviado!";}
//esse $() é a mesma coisa que fazer getElementById();
//o innerHTML insere codigo HTML dentro da div

function cria_objeto(){
	try{
		xmlhttp = new XMLHttpRequest();
		}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}catch(e){
				try{
					xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(E){
					xmlhttp = false;
			}
		}
	}
}
function CarregaArquivo(arquivo){
	objetoHTML=document.getElementById('conteudo');
	objetoHTML.innerHTML='<img src="loading.gif" />';
	url = arquivo; 
	cria_objeto();
    xmlhttp.open("GET",url);
    xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4){
            retorno=unescape(xmlhttp.responseText.replace(/\+/g," "))
			objetoHTML.innerHTML=(retorno);
        }
    }
    xmlhttp.send(null)
}

//formulário de cadastro de participantes
 function so_num(){
   if(event.keyCode<48 || event.keyCode>57)
     event.returnValue=false;
 }

function Mascara (formato, keypress, objeto){
campo = eval (objeto);

// cep
if (formato=='cep')
	{
		separador = '-';
		conjunto1 = 5;
		if (campo.value.length == conjunto1){
		campo.value = campo.value + separador;}
	}

// telefone
if (formato=='telefone'){
separador1 = '(';
separador2 = ')';
separador3 = '-';
conjunto1 = 0;
conjunto2 = 3;
conjunto3 = 8;
if (campo.value.length == conjunto1){
campo.value = campo.value + separador1;
}
if (campo.value.length == conjunto2){
campo.value = campo.value + separador2;
}
if (campo.value.length == conjunto3){
campo.value = campo.value + separador3;
}
}
}

function upper_lower(id){
        var palavras=document.getElementById(id).value;
        palavras=palavras.split("");
        var tmp="";
        for(i=0;i<palavras.length;i++){
            if(palavras[i-1]){
                if(palavras[i-1]==" "){palavras[i]=palavras[i].replace(palavras[i],palavras[i].toUpperCase());}
                else{palavras[i]=palavras[i].replace(palavras[i],palavras[i].toLowerCase());}
            }
            else{palavras[i]=palavras[i].replace(palavras[i],palavras[i].toUpperCase());}
            tmp+=palavras[i];
        }
        document.getElementById(id).value=tmp;
    }

  function Logar()
   {
	  d = document.logon;
	  if (d.email.value == "")
	     {
           alert("Entre com o endereço de e-mail para efetuar o login!");
           d.email.focus();
           return false;
         }
	  if (d.codAcesso.value == "")
	     {
           alert("Por favor digite seu código de Acesso!");
           d.codAcesso.focus();
           return false;
         }
   return true;
 }

 function novocodigo()
   {
	  d = document.cadastro;
	  if (d.email.value == "")
	     {
           alert("O E-mail é obrigatório.");
           d.email.focus();
		   return false;
         }
   return true;
 }
