function MM_swapImage() { //v3.0
   var i,j=0,x,a=MM_swapImage.arguments; 
   document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; 
   if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { 
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
        if ( (obj=MM_findObj(args[i]) )!=null) { 
                v=args[i+2];
                if (obj.style) { 
                        obj=obj.style; 
                        v=(v=='show')?'visible':(v='hide')?'hidden':v; 
                }
                obj.visibility=v;
        }
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  
  if(!d) 
        d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; 
        n=n.substring(0,p);
  }
  if(!(x=d[n])&&d.all) x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
        x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
        x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) 
        x=document.getElementById(n); 
  return x;
}


//funcao para criar cookie
function createCookie(name, value, domain) {  
   var argv = createCookie.arguments;  
   var argc = createCookie.arguments.length;  
   var expires = (argc > 2) ? argv[2] : null;  
   var path = (argc > 3) ? argv[3] : null;  
   var secure = (argc > 5) ? argv[5] : false;  
   document.cookie = name + "=" + escape (value) + 
   ((path == null) ? "" : ("; path=" + path)) +  
   ((domain == null) ? "" : ("; domain=" + domain)) +    
   ((secure == true) ? "; secure" : "");
}

//funcao para esconder e mostrar 
//opcao = 1 => mostrar
//opcao = 2 => esconder
function ElementShowHidden_chk(destino, opcao){ 
   if (document.getElementById(destino)) {
      doc = document.getElementById(destino);
      if (opcao == '1') {
   	   doc.style.display = '';
         doc.focus();
      } else {
   	   doc.style.display = 'none';
      }
   }
}

//funcao para esconder e mostrar automaticamente
function ElementShowHidden(destino, option){ 
   if (document.getElementById(destino)) {
      doc = document.getElementById(destino);
      if (option == 'show' || option == '1') {
         doc.style.display = '';
      } else {
         doc.style.display = 'none';
      }
   }
}

//para um valor para outro txt
function retornar(nome, valor, salto) {
   if (valor) {
      if (document.getElementById(nome).value)
         if (salto==1)
            //concatenar e saltar linha
            document.getElementById(nome).value+='\n'+valor;
         else
            //nao concatenar e nao saltar linha
            document.getElementById(nome).value=valor;
      else 
         document.getElementById(nome).value=valor;
   }
   document.getElementById(nome).selected;
}

//valida email
function validaemail() {
        if (document.bibinserir.bibema.value.indexOf ('@',0) == -1 || document.bibinserir.bibema.value.indexOf ('.',0) == -1){
                alert('Campo E-mail invÃ¡lido.')
        }
}

//valida se o campo eh numerico ou nao
function camponumero(nome) {
   if (isNaN(nome.value)) {
      nome.value=''; 
   }
}

<!-- funcao para autotab -->
//ex. autoTab(this, 11, event)
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
   var keyCode = (isNN) ? e.which : e.keyCode; 
   var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
   if((input.value.length >= len) && !(containsElement(filter,keyCode))) {
      input.value = input.value.slice(0, len);
      input.form[(getIndex(input)+1) % input.form.length].focus();
   }
   function containsElement(arr, ele) {
      var found = false, index = 0;
      while(!found && index < arr.length)
         if(arr[index] == ele)
            found = true;
         else
            index++;
         return found;
   }
   function getIndex(input) {
      var index = -1, i = 0, found = false;
      while (i < input.form.length && index == -1)
         if (input.form[i] == input)index = i;
         else i++;
         return index;
   }
   return true;
}

//esconder mensagem de carregar
function espera() {
   carrega.style.display = "none";
}

//redirecionar pagina com mensagens
function redirect_pag(opcao) {
   location.href='?acao=me&opcao='+opcao;
}

function reload_pag(acao) {
   doc = document.form1;
   doc.acao.value = acao;
   doc.submit();
}
//animacao em barra inferior
function scrollit(seed) {
   var msg = "";        //mensagem
   var out = " ";
   var c   = 1;
   if (seed > 100) {    //para tempo maior que 100
      seed--;
      cmd="scrollit("+seed+")";
      timerTwo=window.setTimeout(cmd,100);
   } else               //para tempo menor ou igual a 100
      if (seed <= 100 && seed > 0) {      //para tempo maior ou igual a 100 e maior que 0
         for (c=0 ; c < seed ; c++) {
            out+=" ";
         }
         out+=msg;
         seed--;
         window.status=out;
         cmd="scrollit("+seed+")";
         timerTwo=window.setTimeout(cmd,100);
      } else 
         if (seed <= 0) {
            if (-seed < msg.length) {
               out+=msg.substring(-seed,msg.length);
               seed--;
               window.status=out;
               cmd="scrollit("+seed+")";
               timerTwo=window.setTimeout(cmd,100);
            } else {
               window.status=" ";
               timerTwo=window.setTimeout("scrollit(100)",75);
            }
         }
}

//exibir mensagens em barra inferior
function barrasmsg(msn, opcao) {
   if (opcao == 1) {
      window.status = msn;
   } else {
      window.status = "";
   }
   return true;
}

//funcao para redimensionar janela
function resizeWindow(p_width, p_height) {
	self.resizeTo(p_width, p_height);
   if(window.navigator.userAgent.indexOf("SV1") != -1){
	   window.resizeBy(0, 30);
   }
}

function validacaoLogin() {
   doc = document.login;
   if (doc.ntemail.value == '') {
         alert('Campo E-Mail(Login) inválido.');
         doc.ntemail.focus();
         return false;
   }
   if (doc.ntsenha.value == '') {
         alert('Campo Senha inválido.');
         doc.ntsenha.focus();
         return false;
   }
   return true;
}
function validacaoForm1(op) {
   doc=document.form1;
   switch(op) {
      case '1':case 'ad':
         //adicionar
         //if (confirm('Adicionar?')) {
            doc.retorno.value = '';
            doc.acao.value = 'ad';
         //   return true;
         //} else {
         //   return false;
         //}
      break;
      case '2':case 'ed':
         //editar
         //if (confirm('Editar?')) {
            doc.retorno.value = '';
            doc.acao.value = 'ed';
         //   return true;
         //} else {
         //   return false;
         //}
      break;
      case '3':case 'ex':
         //excluir
         if (confirm('Excluir?')) {
            doc.acao.value = 'ex';
            return true;
         } else {
            return false;
         }
      break;
      case '4':case 'li':
         //liberar
         if (confirm('Liberar?')) {
            doc.acao.value = 'li';
            return true;
         } else {
            return false;
         }
      break;
      case '5':case 'bl':
         //bloquear
         if (confirm('Bloquear?')) {
            doc.acao.value = 'bl';
            return true;
         } else {
            return false;
         }
      break;
      case '6':case 'bu':
         //buscar
         doc.acao.value='bu';
      break;
      case '7': case 'em':
         //email
         if (confirm('Enviar E-mail?')) {
            doc.acao.value='em';
            return true;
         } else {
            return false;
         }
      break;
      case '8':case 'ge':
         //gerar planilha
         if (confirm('Gerar planilha?')) {
               doc.acao.value='ge';
            return true;
         } else {
            return false;
         }
      break;
      case '9':case 'en':
         //enviar
          if (confirm('Enviar?')) {
             doc.acao.value='en';
            return true;
         } else {
            return false;
         }  
      break;
      case '':
         doc.acao.value='';
      break;
   }
}

function validacaoBusca() {
   doc=document.formBusca;
   if (doc.textSearch.value == '') {
      alert('Campo Busca inválido');
      doc.textSearch.focus();
      return false;
   }
   return true;
}

function validacaoEnquete() {
   doc=document.enquetes;
   cont1 = doc.resposta1.length; 
   cont2 = doc.resposta2.length; 
   var chk1 = false;
   var chk2 = false;
   //valida pergunta1
   for (i=0; i<cont1; i++) {
      if (doc.resposta1[i].checked == true) chk1 = true;
   }
   //valida pergunta2
   for (i=0; i<cont2; i++) {
      if (doc.resposta2[i].checked == true) chk2 = true;
   }
   if (chk1 != true || chk2 != true) {
      alert('Selecione opções do enquete.');
      return false;
   }
   
   doc.acao.value = 'ad';
}

function contarCaracteres(doc, valor) {
   num = doc.value.length;
   if (num >= valor) {
      alert('Campo já está com número máximo de caracteres.');
      doc.value = doc.value.substr(0, valor-1);
   }
}

//funcao para verificar se eh numero ou nao
function autoNum(nome) {
   var num = nome.value.length;
   var newNum = '';
   for (var i=0; i<num; i++) {
      if ( (!(isNaN(nome.value.substr(i,1))) &&  (nome.value.substr(i,1) != ' ')) || (nome.value.substr(i,1) == '.') || (nome.value.substr(i,1) == ',') ) {
         newNum = newNum + nome.value.substr(i,1);
      }
   }
   nome.value = newNum;
}

function formatNumber(field,dec) {
	   var numCaract = 0;
	   var newNum = '';
	   var jn = /[^[0-9]]*/gi;
	
	   var num = field.value.replace(jn,'').replace(/^0/,'');
	   if(num.length <= dec)
		   for(var cont = 0; num.length <= dec; cont++)
			   num = '0' + num;
	   for(cont = num.length - 1; cont >= 0; cont--) {
		   newNum = num.substr(cont,1) + newNum;
		   if(dec > 0 && numCaract == dec - 1)
			   newNum = ',' + newNum;
         else if(((numCaract - dec) % 3 == 2) && (numCaract < num.length-1))
			   newNum = '.' + newNum;
         numCaract++;
      }
	   if(newNum.substr(0,1) == ',')
		   newNum = '0' + newNum;
      field.value = newNum;
}

function campoApagar(doc) {
   doc.value = '';
}
function openPopup(url) {
   window.open(url, "popup", "location=0,status=0,scrollbars=1, width=100, height=100");
}
function openPopup2(url) {
   window.open(url, "", "location=0,status=1,scrollbars=1, width=800, height=500, locationbar = 0, directories = 0, resizable = 0, statusbar = 1, toolbar = 1, left=0, top=0");
}
function fontsizeup() {
   if (parseInt(document.getElementById('idTexto').style.fontSize) <= 22 ) document.getElementById('idTexto').style.fontSize=parseInt(document.getElementById('idTexto').style.fontSize)+2;
   else document.getElementById('idTexto').style.fontSize=11;
}
function fontsizedown() {
   if (parseInt(document.getElementById('idTexto').style.fontSize) >= 8 ) document.getElementById('idTexto').style.fontSize=parseInt(document.getElementById('idTexto').style.fontSize)-2;
   else document.getElementById('idTexto').style.fontSize=11;
}