 function emailValido(mail){
	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 {
			alert("O 'E-mail' informado não está em um formato válido!");
		}  
	}else if(typeof(mail) == "object"){
		if(er.test(mail.value)){ 
			return true; 
		}
	}else{
		return false;
	}
 }


 function verificaEmail(){
   if (document.getElementById("emailatual").value=="") {
       alert("O Campo 'E-mail' é de preenchimento obrigatório");
       document.getElementById("emailatual").focus();
   }else if (!emailValido(document.getElementById("emailatual"))){
       alert("O 'E-mail' não está em um formato válido!");
       document.getElementById("emailatual").focus();
   }else {
       document.getElementById("email_formulario_consulta").submit();
   }
 }


 function setLabel(_this) {
 	var id = _this.id;
        var textoSelect = _this.options[_this.selectedIndex].text;
	document.getElementById(id+"_label").value = textoSelect;
 }

  function lowerCase(_thismail) {
    _thismail.value = _thismail.value.toLowerCase();
 }

 function maxlength(_this, event, _max) {
    var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    if (keyCode == 8 ||
        keyCode == 9 ||
        keyCode == 27 ||
        keyCode == 35 ||
        keyCode == 36 ||
        keyCode == 37 ||
        keyCode == 38 || keyCode == 39 || keyCode == 40 || (keyCode == 46)) {
        return true;
    } else {
        if (_this.value.length >= _max) {
            _this.value = _this.value.substring(0, _max);
            return false;
        } else {
            return true;
        }
    }
 }

  function submitForm() {

    if ((qtdEmail == 0 )&&(document.getElementById("emailconfirmado").value=="")) {
       alert("O Campo 'E-mail' é de preenchimento obrigatório");
       document.getElementById("emailconfirmado").focus();
   }else if (!emailValido(document.getElementById("emailconfirmado"))){
       alert("O 'E-mail' informado não está em um formato válido!");
       document.getElementById("emailconfirmado").focus();
    }else if ((qtdEmail == 0 )&&(document.getElementById("confirmaemail").value == "")) {
      alert("O campo 'Confirmação de e-mail' é preenchimento obrigatório");
      document.getElementById("confirmaemail").focus();
    }else if ((qtdEmail == 0 )&&(document.getElementById("emailconfirmado").value.toLowerCase() != document.getElementById("confirmaemail").value.toLowerCase())) {
      alert("O e-mail confirmado não esta igual ao e-mail informado");
      document.getElementById("confirmaemail").focus();
    }else if (document.getElementById("nome").value=="") {
       alert("O Campo 'Nome' é de preenchimento obrigatório");
       document.getElementById("nome").focus();
    }else if (document.getElementById("ddd").value=="") {
      alert("O código da área do telefone é de preenchimento obrigatório!");
      document.getElementById("ddd").focus();    
    }else if (document.getElementById("telefone").value=="") {
      alert("O campo 'Telefone' é de preenchimento obrigatório!");
      document.getElementById("telefone").focus();  
    }else if (document.getElementById("municipio").value=="") {
      alert("O campo 'Município' é de preenchimento obrigatório!");
      document.getElementById("municipio").focus();  
    }else if (document.getElementById("telefone").value=="") {
      alert("O campo 'Telefone' é de preenchimento obrigatório!");
      document.getElementById("telefone").focus();  
    }else if (document.getElementById("categoria").value=="") {
      alert("O campo 'Categoria' é de preenchimento obrigatório!");
      document.getElementById("categoria").focus();  
    }else if (document.getElementById("tema").value=="") {
      alert("O campo 'Tema' é de preenchimento obrigatório!");
      document.getElementById("tema").focus();  
    }else if (document.getElementById("contribuicao").value=="") {
      alert("O campo 'Contribuição' é de preenchimento obrigatório!");
      document.getElementById("contribuicao").focus();  
    }else{
    document.getElementById("formulario_consulta").submit();
    }  
  }
  
 function novoFormulario() {

    document.getElementById("nova_sugestao").submit(); 
 }
