function favoritos (titulo){
  var url = 'http://' +document.domain;
  
  if (window.sidebar){
	  window.sidebar.addPanel(titulo, url,"");
  } else if( window.external ){ 
	  window.external.AddFavorite( url, title);
  } else if(window.opera && window.print){
  	  var elem = document.createElement('a');
      elem.setAttribute('href',url);
      elem.setAttribute('title',title);
      elem.setAttribute('rel','sidebar');
      elem.click();
      return false;
  }
}

function homepage (site){
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage('http://'+document.domain);
}

function identifica_formulario (frm){
         if (frm == null){ frm = 0;}
         formulario = document.forms[frm];
         return formulario;
}

function focar_campo (frm, campo){
         if (campo == null){ campo = 0;}
         formulario = identifica_formulario (frm);
         if (formulario && formulario[campo] && formulario[campo].type == 'select-one'){ return;}
         if (formulario && formulario[campo] && formulario[campo].style.display != 'none' && formulario[campo].type != 'hidden'){
             formulario[campo].focus();
         }
}

function limite (valor, accao){
         if (event.srcElement.value.length >= valor){
             if (accao == 'colar'){
                 event.srcElement.value = event.srcElement.value.substring(0, valor);
             } else {
                 event.returnValue = false;
             }
         }
}

function teclas(formato){
         switch (formato){
                 case 'numerico':
                       if (window.event.keyCode < 48 || window.event.keyCode > 57){
                           event.returnValue = false;
                       }
                       break;
                 case 'espaco':
                       if (window.event.keyCode == 32){
                           event.returnValue = false;
                       }
                       break;
                 case 'alfabeto':
                       if (window.event.keyCode < 48 || (window.event.keyCode > 57 && window.event.keyCode < 97) || window.event.keyCode > 122){
                           event.returnValue = false;
                       }
                 case 'seguro':
                       if ((window.event.keyCode < 48 && (window.event.keyCode != 13 && window.event.keyCode != 32)) || (window.event.keyCode > 57 && window.event.keyCode < 97 && window.event.keyCode != 95) || window.event.keyCode > 122){
                            event.returnValue = false;
                       } else if (window.event.keyCode == 32){
                            window.event.keyCode = 95;
                       }
                       break;
                 case 'email':
                       if ((window.event.keyCode < 48 && (window.event.keyCode != 13 && window.event.keyCode != 45 && window.event.keyCode != 32 && window.event.keyCode != 46)) || (window.event.keyCode > 57 && window.event.keyCode < 97 && window.event.keyCode != 95 && window.event.keyCode != 64) || window.event.keyCode > 122){
                            event.returnValue = false;
                       } else if (window.event.keyCode == 32){
                            window.event.keyCode = 95;
                       }
                       break;
                 case 'url':
                       if ((window.event.keyCode < 47 && (window.event.keyCode != 13 && window.event.keyCode != 45 && window.event.keyCode != 46 && window.event.keyCode != 38)) || (window.event.keyCode > 57 && window.event.keyCode < 97 && window.event.keyCode != 95 && window.event.keyCode != 61 && window.event.keyCode != 63 && window.event.keyCode != 64) || window.event.keyCode > 122){
                            event.returnValue = false;
                       }
                       break;
                 default: //não permite a tecla enter
                       if (event.keyCode == 32){ event.returnValue = false;}
                       break;
         }
}

function valida_formulario (frm){
         formulario = identifica_formulario (frm);
         for (i = 0; i < formulario.length - 1; i++){
              if (formulario[i].value != ''){
                  activa = true;
              } else {
                  activa = false;
                  break;
              }
         }
         if (activa == true){
             formulario[formulario.length-1].disabled = false;
         } else {
             formulario[formulario.length-1].disabled = true;
         }
}

function marca_itens (id_artigo, cor){
         nform = 0;
         while (!document.forms[nform].checkitem){
                 if (!document.forms[nform].checkitem){
                      nform +=1;
                 } else {
                      exit;
                 }
         }
         var caminho = document.forms[nform];
         if (id_artigo != 'todos'){
             zona = eval ('zona_' + id_artigo);
             if (event.srcElement.checked == true){
                 zona.style.backgroundColor = cor;
             } else {
                 zona.style.backgroundColor = '';
             }
             for (i = 1; i < caminho.checkitem.length; i++){
                  if(caminho.checkitem[i].checked == true){
                     marca = true;
                  } else {
                     marca = false;
                     break;
                  }
             }
             if (marca == true){
                 caminho.checkitem[0].checked = true;
             } else {
                 caminho.checkitem[0].checked = false;
             }
         } else {
             for (i = 1; i < caminho.checkitem.length; i++){
                  zona = eval ('zona_' + i);
                  if (event.srcElement.checked == false){
                      caminho.checkitem[i].checked = false;
                      zona.style.backgroundColor = '';
                  } else {
                      caminho.checkitem[i].checked = true;
                      zona.style.backgroundColor = cor;
                  }
             }
         }
}

function janela (ficheiro, janela, largura, altura){
         var vertical = (screen.height / 2) - (altura / 2);
         var horizontal = (screen.width / 2) - (largura / 2);
         window.open (ficheiro, janela, "width= " +largura+ "px, height= " +altura +"px, left= " +horizontal+", top= " +vertical);
}

function janela_modal (ficheiro, parametros, largura, altura){
         var resultado = showModalDialog (ficheiro, parametros, "dialogWidth: " +largura+ "px; dialogHeight: " +altura +"px; resizable: no; help: no; status: no; scroll: no;");
         return resultado;
}

function janela_topo (ficheiro, parametros, largura, altura){
         var resultado = showModelessDialog (ficheiro, parametros, "dialogWidth: " +largura+ "px; dialogHeight: " +altura +"px; resizable: no; help: no; status: no; scroll: no;");
         return resultado;
}

function confirma (texto){
         confirmacao = confirm (texto);
         if (confirmacao != true){
             event.returnValue = false;
         }
}

function activar_campo (campo, accao){
         obj = document.all[campo];
         if (obj.length){
             for (i=0; i < obj.length; i++){
                  if (accao == 'activar'){
                      obj[i].disabled = false;
                  } else {
                      obj[i].disabled = true;
                  }
             }
         } else {
             if (accao == 'activar'){
                 obj.disabled = false;
             } else {
                 obj.disabled = true;
             }
         }
}

//Fiquei aqui
function arvore (objid, esconde, imgmais, imgmenus){
         var objmenu = document.getElementById(objid);
         if (objmenu == null){ return;}
         var submenu = objmenu.childNodes[2].id;
         
         if (esconde == true && submenu){
             for (i=0; i<submenu.length; i++){
                  submenu[i].style.display = 'none';
                  if(imgmais != ''){ eval(objid)[i].childNodes[0].src = imgmais;}
             }
         }
         
         if (objmenu.childNodes[0].tagName == 'IMG'){
             var imagem = objmenu.childNodes[0];
         } else {
             var imagem = objmenu.childNodes[0].childNodes[0];
         }
         
         if (objmenu.childNodes[4] && objmenu.childNodes[4].id != null && objmenu.childNodes[4].id != ''){
            if (objmenu.childNodes[4] && objmenu.childNodes[4].style.display == 'none'){
                 if (imgmenus != ''){ imagem.src = imgmenus;}
                 objmenu.childNodes[4].style.display = '';
            } else {
                if (imgmais != ''){ imagem.src = imgmais;}
                objmenu.childNodes[4].style.display = 'none';
            }
         }  
}
