//onerror=continua
function continua()
{return true;}
//--------
function Ucase(cpo)
{ 
	valor = cpo.value.toUpperCase();
	cpo.value = valor;
}
//--------
var cor_fonte = '#4675B0'; // Cor default da fonte
var cor_fonte_over = '#FFFFFF'; //Cor da fonte qdo o mouse estiver por cima

function onlyOne(obj)
{
	for (i = 0; i < obj.length; i++)
	{
		eval(obj +"[i].checked = false");
	}
}

function foco_site(campo,corfonte,mouse)
{
    campo.style.color= corfonte;
	campo.style.cursor= mouse;
}

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 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).innerHTML = 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 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 ShowHide2(codId)
{
  var M = document.getElementById(codId).style.display;
  var S = 'block';
  var I = 'media/layout/menos.gif';  
  
  if(M == 'block'){S='none';I='media/layout/mais.gif';}
  document.getElementById(codId).style.display = S;
  javascript: TrocaImg('s_'+ codId,I);  
}
//------------------------------------------------------------------------------------------------------------------------
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;
}

function ResetForm(sessao)
{
	if(confirm("Deseja apagar todos dados?")==true)
	{ parent.location = '?Sessao='+ sessao +'&acao=drop' } 
}

function ResetForm2(sessao,codigo)
{
	if(confirm("Deseja apagar todos dados?")==true)
	{ parent.location = '?Sessao='+ sessao +'&acao=drop&codigo='+ codigo } 
}

function SelectCombo(obj)
{
	for(var i = 0; i < obj.options.length; i++)
	{ obj.options[i].selected = true }
}

// validacao para o campo email
function validaEmail(email)
{
	if(email.value=="")
	{
		alert("Por Favor preencha o campo e-Mail");
		email.focus();
		return false;
	}
	else
	{
		if(email.value.indexOf('@',0) == -1 || email.value.indexOf('.',0) == -1)
		{
		alert("O e-mail precisa conter '@' (Arroba) OU '.'(Ponto)");
		email.focus();
		return false;
		}
		else
		{
			//Verifica se começa com arroba ou com ponto
			if((email.value.indexOf('@',0) == 0) || (email.value.indexOf('.',0) == 0))
			{
			alert("O e-mail não pode começar com '@' (Arroba) ou '.' (Ponto)");
			email.focus();
			return false;
			}
			else
			{
				//Verifica se termina com ponto ou com arroba
				if ((email.value.indexOf('@',0) == email.value.length - 1) || (email.value.indexOf('.',0) == email.value.length - 1))
				{
				alert("o e-mail não pode terminar com '@' (Arroba) ou '.' (Ponto)");
				email.focus();
				return false;
				}
				else
				{
					return true;
				}
			}
		}
	}
}