function query_search()
{
	var cont = 1;
	if(document.frm_busca.busca.value == '')
	{ sErr = cont +'º Preencha o campo com o termo desejado\n'; cont += 1; }

	if(sErr != '')
	{
		alert('Ocorreram os seguintes erros:\n\n'+ sErr);
		document.frm_busca.busca.focus();
		return false
	}
}

var cor_fonte = '#FFFFFF'; // Cor default da fonte
var cor_fonte_over = '#000000'; //Cor da fonte qdo o mouse estiver por cima
function foco_site(campo,corfonte,mouse)
{
    campo.style.color= corfonte;
	campo.style.cursor= mouse;
}

function pubFile(sLayer_visible,sLayer_invisible,sCmb_Check,frm_cpo,sCpo_focus)
{
	var cpo = eval(frm_cpo+"["+ sCmb_Check +"].checked = true")
	document.getElementById(sLayer_visible).style.display = "block";
	document.getElementById(sLayer_invisible).style.display = "none";
	eval(sCpo_focus+".focus()")
}
function viewBanners(cpo)
{
	with(document.frm)
	{
		var tamanho_banner = eval(cpo +'.value');
		if(tamanho_banner == '')
		{ alert('Escolha uma medida');eval(cpo +'.focus()') }
		else
		{ generico('./ibanner_list.asp?b_tam='+ tamanho_banner +'&Cpo='+ cpo ,'lb',200,200,0,0,'yes','no') }	
	}
}

function excApresentacao(msg,strUrl)
{
 if(confirm('Deseja excluir o Setor '+ msg +'?')==true)
 { parent.location = strUrl}

}

function editApresentacao(Id,zerar)
{
 with(document.frm)
 {
	if(!zerar)
	{
		eval('dt'+Id).disabled = zerar;
		eval('hr'+Id).disabled = zerar;
		eval('vl'+Id).disabled = zerar;
		alerta('Modo Edição')
		acao.value	= 'up'
		btnInfo.value 	= 'Salvar Alterações'
	}
	else
	{
		alerta('  ');
		acao.value	= 'ins';
		document.frm.reset();
		btnInfo.value 	= 'Cadastrar'
	}
 }
}
function alerta(msg)
{ document.getElementById('aviso').innerText = msg; }

function admin(strElemento)
{
  var cpo = document.getElementById("i"+strElemento).style.display
  if(cpo == 'none') {document.getElementById("i"+strElemento).style.display = 'block';}
  else {document.getElementById("i"+strElemento).style.display = 'none';}
}

function setCookie(nome_do_cookie, value, expiredays) 
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = nome_do_cookie + "=" + escape(value) + 
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function getCookie(nome_do_cookie)
			{ if (document.cookie.length > 0) 
			{ begin = document.cookie.indexOf(nome_do_cookie +"="); 
			if (begin != -1) 
			{
			begin += nome_do_cookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); } 
			}
			return null; 
			} 



function tab(max,cpo,cpo1)
{
  if(cpo.value.length == max)
  { cpo1.focus(); }
}

function validaNumero(e){
if (document.all) // Internet Explorer
var tecla = event.keyCode;
else if(document.layers) // Nestcape
var tecla = e.which;
if (tecla > 47 && tecla < 58) // numeros de 0 a 9
// if (tecla < 47 || tecla > 58) // letras de A a Z
return true;
else{
if (tecla != 8) // backspace
event.keyCode = 0;//return false;
else return true;
}
}

var tooltip_window = null;
function tooltip(titulo,mensagem, status)
{
	if(status != 0)
	{
		if(tooltip != null) tooltip.focus();
		else
		{
		var tooltip = open('', 'Tooltip', 'width=350,height=250,resizable=yes');
		tooltip_window = tooltip;
		tooltip.document.open();
		tooltip.document.writeln('<html>\n<head>\n<title>'+ titulo +'</title>\n</head>\n<body scroll=auto onblur="window.close()">');
		tooltip.document.writeln('<script>\nself.moveTo((screen.width-300)/2, (screen.height-300)/2)\n</script>');
		tooltip.document.writeln('<font face=arial size=2>\n' + mensagem + '\n</font>');
		tooltip.document.writeln('</body>\n</html>');
		tooltip.document.close();
		}
	}
}

function pegaLink(link)
{
	window.clipboardData.setData("Text",link);
	//alert("Referência copiada com sucesso!!\n\n"+link);
}

function msg(strMsg)
{ window.status = strMsg;return true}

function TrocaImg(strImage,strSRC)
{
 var doc = eval("document.images."+ strImage); 
 doc.src = strSRC;
}

function statusCpo(strForm,strCpo,strBool)
{
  var cpo = eval(strForm+"."+strCpo)
  cpo.disabled = strBool
  if(strBool == false){cpo.focus();}else{cpo.value='';}
}


function confSenha(frm,cpo,cpo1)
{
 var doc = eval("document."+ frm)
  with(doc)
  {
    var cpoV = eval(cpo + ".value")
    var cpoV1 = eval(cpo1 + ".value")
    if(cpoV == "" || cpoV1 == "")
    {
      alert('A senha e/ou a confirmação não pode ser nula\n\nDigite novamente');
      senha.value ='';
      csenha.value ='';
      senha.focus();     
      return false;
    }

    if(cpoV != cpoV1)
    {
      alert('As senhas digitadas não conferem\n\nDigite novamente');
      senha.value ='';
      csenha.value ='';
      senha.focus();     
      return false;
    }
  }
}

function checkerStart(saida,max)
{ document.getElementById(saida).innerText = max }

function maXCaract(fd,max,saida)
{
(fd.value.length>max) ? fd.value=fd.value.substring(0,max) : document.getElementById(saida).innerText=(max-fd.value.length);
}

function site(strUlr){parent.location = strUlr;}

function foco(form,campo,bg,corfonte)
{
 var doc = eval("document."+form)
  with(doc)
  {	
    campo.style.backgroundColor= bg;
    campo.style.color= corfonte;
  }
}


function Impressao(strUrl)
{
	generico('impressao.asp?Origem='+strUrl,'impressao',500,300,0,0,'yes','no')
}

function generico(URL,NOME,LARG,ALT,T,L,R,S)
{
var op ; 
op =window.open(URL,NOME,'width='+LARG+',height='+ALT+',top='+T+',left='+L+',resizable='+R+',scrollbars='+S)
op.focus();
}

function click() 
{
	if (event.button==2||event.button==3) { oncontextmenu='return false'; }
}
/*
document.onmousedown=click
document.oncontextmenu = new Function("return false;")
*/

/* -----------------------------------------------------------------------
Função trocaCampos(boxE, boxD, controle, tudo, mover)
boxE		= box da Esquerda
boxD		= box da Direita
controle	= campo que armazena o valor para armazenar a selecao
tudo		= true / false (para mover todos os campos independente de selecionar o campo)
mover		= 0 / 1 (quando voltar o valor da Dir para Esq, limpa o campo de controle, evitando duplicidade)
 ----------------------------------------------------------------------- */
function trocaCampos(boxE, boxD, controle, tudo, mover)
{
	var remove = new Array;
	var indice = "";

	for(var i = 0; i < boxE.options.length; i++)
	{
		if(!tudo)
		{
			var praDestaque_p = new Option();
			praDestaque_p.value = boxE.options[i].value;
			praDestaque_p.text  = boxE.options[i].text;
			
			boxDSize = boxD.options.length;
			boxD.options[boxDSize] = new Option();
			boxD.options[boxDSize].value = praDestaque_p.value;

			if(mover == 0)
			{ if(boxDSize > 0){ controle.value += praDestaque_p.value + "," ; }
			  else { controle.value = praDestaque_p.value + ","; }
			} else { var str = controle.value; controle.value = str.replace(praDestaque_p.value + ",",''); }

			boxD.options[boxDSize].text  = praDestaque_p.text;
			boxD.options[boxDSize].selected = true ;
			// INDICE PARA REMOCAO
			if(indice == ""){indice = 0;}
			remove[indice] = i;
			indice += 1;
		}
		else
		{
	             	if (boxE.options[i].selected)
		     	{
				var praDestaque_p = new Option();
				praDestaque_p.value = boxE.options[i].value;
				praDestaque_p.text  = boxE.options[i].text;
				
				boxDSize = boxD.options.length;
				boxD.options[boxDSize] = new Option();
				boxD.options[boxDSize].value = praDestaque_p.value;

			if(mover == 0)
			{ if(controle.value != "") { controle.value += praDestaque_p.value + ","; }
			  else { controle.value = praDestaque_p.value + ","; }
			} else { var str = controle.value; controle.value = str.replace(praDestaque_p.value + ",",''); }

				boxD.options[boxDSize].text  = praDestaque_p.text;
				boxD.options[boxDSize].selected = true ;
				// INDICE PARA REMOCAO
				if(indice == ""){indice = 0;}
				remove[indice] = i;
				indice += 1;
			}
		}
	}

	if(indice > 0)
	{
		for(x=indice; x >= 0; x--)
		{
		  a = remove[x];
	     	  boxE.options[a] = null;
		}
	}
}


function range(campo)
{
  for(var i=0; i<=(eval(campo.value.length)-1); i++)
    {
      var c = campo.value.charAt(i);
        if(campo.value.charAt(i)!='0' && campo.value.charAt(i)!='1' && campo.value.charAt(i)!='2'
           && campo.value.charAt(i)!='3' && campo.value.charAt(i)!='4' && campo.value.charAt(i)!='5'
           && campo.value.charAt(i)!='6' && campo.value.charAt(i)!='7' && campo.value.charAt(i)!='8'
           && campo.value.charAt(i)!='9' && campo.value.charAt(i)!=',')
        {
            alert("Caracter Inválido encontrado.");
            campo.value=0;
        }
    }
}


function formata(valor)
{
  var str="";
  var j=0;
  range(valor);
  for(var i=0; (i<=valor.value.length-1)&&(valor.value.charAt(i)=='0');i++) j++;
  if (j>0)
    {
      for(var i=j; (i<=valor.value.length-1); i++)
        str = str + valor.value.charAt(i);
      valor.value=str;
      str="";
    }
  j=0;
  if (valor.value=="")
    valor.value="0";
  if(verifica(valor)==0)
    {
      if (valor.value.length<=2)
        {
          if (valor.value.length==1)
            str=",0" + valor.value
          else
            str="," + valor.value;
          valor.value=str;
          arredonda(valor);
          str=valor.value;
        }
      else
        {
          for(var i=0; (i<=valor.value.length-1);i++)
            {
              if (i==valor.value.length-2)
                str=str+",";
              str=str+valor.value.charAt(i); // procura ","
              j++;
            }
          valor.value=str;
        }
    }
  else
    arredonda(valor);

  if(valor.value=="")
    {
      alert("Valor Inválido.");
      valor.focus();
    }
}

function formataint (valor, len)
{
  range(valor);

  if (len > 0)
    while (valor.value.length < len)
      valor.value = '0' + valor.value;
}

function Nro(d)
{ if (d < '0' || d > '9')
    return(0);
  return(1);
}

function desformata (valor)
{
  var s = "";
  for (var i=0; i < valor.value.length; i++)
  {
    var c = valor.value.charAt (i);
    if (Nro (c))
      s = s + valor.value.charAt (i);
  }
  valor.value = s;
  valor.select();
}

function arredonda(valor)
{
    var j=0, str="";
    for(var i=0; (i<=valor.value.length-1)&&(valor.value.charAt(i)!=',');i++)
    {
        str=str+valor.value.charAt(i);
        j++;
    }
    if(valor.value.charAt(0)==',')
        str=str+"0";
    str=str + ",";
    j++;
    if(valor.value.charAt(j)=='')
        str=str+0;
    else
        str=str+valor.value.charAt(j);
    if(valor.value.charAt(j+1)=='')
        str=str+0;
    else
        str=str+valor.value.charAt(j+1);
    valor.value=str;
    str="";
    str=str+valor.value;
    valor.value=str;

}

function verifica(valor)
{
    var j=0;
    for(var i=0; i<=valor.value.length-1; i++)
        if(valor.value.charAt(i)==',')
            j=1;
    return(j);
}


function banco(intQ)
{
  for(i=1;i<4;i++)
  {
    if(i==intQ){document.getElementById('B'+i).style.display = 'block';}
    else{document.getElementById('B'+i).style.display = 'none';}
  }
}

function numeros()
{
if (!(event.keyCode > 45 && event.keyCode < 58)){event.returnValue = false;} 
}


function ShowHide(codId,S)
{
  var M = document.getElementById(codId).style.display;
  document.getElementById(codId).style.display = S;
}

function openHTML()
{
	var w = screen.width;
	var h = screen.height-50;
	resizeTo(w,h)
}

function eXplodePop()
{
	var w = 470;
	var h = 500;
	resizeTo(w,h)
}

function logoSite()
{
	var nav = navigator.appName;
	if(nav == "Netscape")
	{ document.writeln('<div id="logo" style="position:absolute; left:31px; top:20px; width:26px; height:25px; z-index:1" class="email"><img src="media/layout/logo.jpg" width="135" height="133"></div>'); }
	else
	{ document.writeln('<div id="logo" style="position:absolute; left:31px; top:27px; width:26px; height:25px; z-index:1" class="email"><img src="media/layout/logo.jpg" width="135" height="133"></div>'); }
}