        var color;
      
      function notificaErro(idElemento,mensagem){
        var oElemento = document.getElementById(idElemento);
        alert("Campo "+idElemento+" inválido."+mensagem);
        color = oElemento.style.color;
        oElemento.style.color = "#FF0000";
        oElemento.focus();
      }

      function retornaCor(idElemento){
        var oElemento = document.getElementById(idElemento);
        oElemento.style.color = color; 
      }

      function ehCampoVazio(campo){
        if(campo.type == "text" || campo.type =="textarea"){
            if(campo.value == null || campo.value=="" || campo.value.length==0){
                return true;
            }else{
                return false;
            }
        }
      }

      function validaTexto(id){
        var campo = document.getElementById(id);
        if(ehCampoVazio(campo)){
            notificaErro(id,"\nCampo não pode estar vazio.");
            return false;
        }else{
            retornaCor(id);
            return true;
        }
      }

      // verifica se um valor é número ou não
      function ehNumero(numero){
        var valor = parseInt(numero);
        if(isNaN(valor)){
            return false;
        }else{
            return true;
        }
      }

      // verifica se a data está no formato dd/mm/aaaa
      function validaDataSimples(data){
        var reDate = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;
	if (!reDate.test(data)) {
            return false;
	}else{
            return true;
        }
      }

    function marcarTodos(formId){
       theForm = document.getElementById(formId);
       for (var i=0; i<theForm.elements.length; i++){
          if (theForm.elements[i].type == "checkbox"){
            theForm.elements[i].checked = true;
          }
       }
    }

    function desmarcarTodos(formId){
       theForm = document.getElementById(formId);
       for (var i=0; i<theForm.elements.length; i++){
          if (theForm.elements[i].type == "checkbox"){
            theForm.elements[i].checked = false;
          }
       }
    }
    
    function marcarPorParentENome(elementId, name){
       theElement = document.getElementById(elementId);
       for (var i=0; i<theElement.childNodes.length; i++){
          if (theElement.childNodes[i].type == "checkbox" && theElement.childNodes[i].name == name){
            theElement.childNodes[i].checked = true;
          }
       }
    }

    function desmarcarPorParentENome(elementId, name){
       theElement = document.getElementById(elementId);
       for (var i=0; i<theElement.childNodes.length; i++){
          if (theElement.childNodes[i].type == "checkbox" && theElement.childNodes[i].name == name){
            theElement.childNodes[i].checked = false;
          }
       }
    }    

    /*
    function marcarTodos(formId, name){
    	 alert("vou marcar todos com este nome neste form!");
       theForm = document.getElementById(formId);
       for (var i=0; i<theForm.elements.length; i++){
          if (theForm.elements[i].type == "checkbox" && theForm.elements[i].name == name){
            theForm.elements[i].checked = true;
          }
       }
    }

    function desmarcarTodos(formId, name){
    	 alert("vou desmarcar todos com este nome neste form!");
       theForm = document.getElementById(formId);
       for (var i=0; i<theForm.elements.length; i++){
          if (theForm.elements[i].type == "checkbox" && theForm.elements[i].name == name){
            theForm.elements[i].checked = false;
          }
       }
    }    
    */
    
    function mostrarEsconder (elementoId, botao, textoBotao){  
      elemento = document.getElementById(elementoId);
      if (elemento.style.display != "none"){    
        elemento.style.display = "none";  
        botao.innerHTML = "Mostrar "+textoBotao;
      } else {
        elemento.style.display = "";
        botao.innerHTML = "Esconder "+textoBotao;
      }
    }

    function mostrarEsconder (elementoId){  
      elemento = document.getElementById(elementoId);
      if (elemento.style.display != "none"){    
        elemento.style.display = "none";  
      } else {
        elemento.style.display = "";
      }
    }

    function trocaRodape(novo){  
    	var enderecos = document.getElementsByName("endereco");
    	var cidades = document.getElementsByName("cidade");
    	for(i=0; i<enderecos.length; i++){
    		var endereco = enderecos[i];
    		var cidade = cidades[i];
    		if(endereco.id.match(novo)){
    			//endereco.style.display = "inline";
    			cidade.style.color = "#546172";
    		}else{
    		  endereco.style.display = "none";
    			cidade.style.color = "#f78f1e";
    		}
    	}
  	  var enderecoNovo = document.getElementById("endereco" + novo);
  	  enderecoNovo.style.display = "inline";
    }  
    
    function MM_openBrWindow(theURL,winName,features) {
     window.open(theURL,winName,features);
    }
          
		function EnableDisableBotao(checkbox, botao){
 			if(document.getElementById(checkbox).checked == true){
     		document.getElementById(botao).disabled = "disabled"
 			}else if(document.getElementById(checkbox).checked == false){
     		document.getElementById(botao).disabled = ""
 			}
    }    
          
		function desabilitarBotao(botao){
 			if(document.getElementById(botao).disabled == ""){
     		document.getElementById(botao).disabled = "disabled"
 			} else {
        alert("Por favor, aguarde, processo em andamento...");
 			}
    }    
                    