function ExibeConteudo(nome){
    if(nome.style.display=='inline'){
        nome.style.display='none';
    } else {
        nome.style.display='inline';
    }
}

function abrir(URL,width,height) {

   var left = 100;
   var top = 100;

   window.open(URL,'ds', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no, fullscreen=no');

}

function FormataRg(id,tammax,teclapres) {

if(window.event) { // Internet Explorer
var tecla = teclapres.keyCode; }
else if(teclapres.which) { // Nestcape / firefox
var tecla = teclapres.which;
}

vr = document.getElementById(id).value;
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( "-", "" );
vr = vr.toString().replace( ",", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
tam = vr.length;

if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

if (tecla == 8 ){ tam = tam - 1; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if ( tam <= 2 ){
document.getElementById(id).value = vr; }
if ( (tam > 2) && (tam <= 4) ){
document.getElementById(id).value = vr.substr( 0, tam - 1 ) + '-' + vr.substr( tam - 1, tam ); }
if ( (tam >= 5) && (tam <= 7) ){
document.getElementById(id).value = vr.substr( 0, tam - 4 ) + '.' + vr.substr( tam - 4, 3 ) + '-' + vr.substr( tam - 1, tam ); }
if ( (tam >= 8) && (tam <= 10) ){
document.getElementById(id).value = vr.substr( 0, tam - 7 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + '-' + vr.substr( tam - 1, tam ); }
if ( (tam >= 11) && (tam <= 13) ){
document.getElementById(id).value = vr.substr( 0, tam - 10 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + '-' + vr.substr( tam - 1, tam ); }
if ( (tam >= 14) && (tam <= 16) ){
document.getElementById(id).value = vr.substr( 0, tam - 13 ) + '.' + vr.substr( tam - 13, 3 ) + '.' + vr.substr( tam - 10, 3 ) + '.' + vr.substr( tam - 7, 3 ) + '.' + vr.substr( tam - 4, 3 ) + '-' + vr.substr( tam - 1, tam );}
}
}

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
      var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
    nTecla = evtKeyPress.keyCode;
} else if(document.layers) { // Nestcape
    nTecla = evtKeyPress.which;
} else {
    nTecla = evtKeyPress.which;
    if (nTecla == 8) {
        return true;
    }
}

      sValue = objForm[strField].value;

      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( "-", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( ".", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "/", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( "(", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( ")", "" );
      sValue = sValue.toString().replace( " ", "" );
      sValue = sValue.toString().replace( " ", "" );
      fldLen = sValue.length;
      mskLen = sMask.length;

      i = 0;
      nCount = 0;
      sCod = "";
      mskLen = fldLen;

      while (i <= mskLen) {
        bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
        bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

        if (bolMask) {
          sCod += sMask.charAt(i);
          mskLen++; }
        else {
          sCod += sValue.charAt(nCount);
          nCount++;
        }

        i++;
      }

      objForm[strField].value = sCod;

      if (nTecla != 8) { // backspace
        if (sMask.charAt(i-1) == "9") { // apenas números...
          return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
        else { // qualquer caracter...
          return true;
        } }
      else {
        return true;
      }
}

function FormataValor(id,tammax,teclapres) {

if(window.event) { // Internet Explorer
var tecla = teclapres.keyCode; }
else if(teclapres.which) { // Nestcape / firefox
var tecla = teclapres.which;
}

vr = document.getElementById(id).value;
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( "/", "" );
vr = vr.toString().replace( ",", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
vr = vr.toString().replace( ".", "" );
tam = vr.length;

if (tam < tammax && tecla != 8){ tam = vr.length + 1; }

if (tecla == 8 ){ tam = tam - 1; }

if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
if ( tam <= 2 ){
document.getElementById(id).value = vr; }
if ( (tam > 2) && (tam <= 5) ){
document.getElementById(id).value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 6) && (tam <= 8) ){
document.getElementById(id).value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 9) && (tam <= 11) ){
document.getElementById(id).value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 12) && (tam <= 14) ){
document.getElementById(id).value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
if ( (tam >= 15) && (tam <= 17) ){
document.getElementById(id).value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
}
}

var ns6 = document.getElementById && !document.all


function RestringeInput(maxlength,e,placeholder){
if ( window.event && event.srcElement.value.length >= maxlength ) {
 return false
} else if ( e.target && e.target == eval( placeholder ) && e.target.value.length >= maxlength ) {
 var PressTecla = /[a-zA-Z0-9\.\,\/]/ //detecta caracteres alfanuméricos
 if ( PressTecla.test ( String.fromCharCode ( e.which ) ) ) {
  e.stopPropagation()
 }
}
}

function ContaLimite( maxlength , e , placeholder ) {
var theform = eval( placeholder )
var lengthleft = maxlength-theform.value.length
var placeholderobj = document.all ? document.all[placeholder] : document.getElementById( placeholder )
if ( window.event || e.target&&e.target == eval( placeholder ) ){
 if ( lengthleft < 0 )
  theform.value = theform.value.substring( 0 , maxlength )
  placeholderobj.innerHTML = lengthleft
}
}

function MostraLimite( theform,thelimit ) {
var limit_text = '<span id="'+theform.toString()+'" style="font-family:Tahoma; font-size:11px; color:#990000">'+thelimit+'</span><span style="font-family:Tahoma; font-size:11px; color:#990000"> caracteres restantes.</span>'
 if ( document.all || ns6 )
  document.write( limit_text )
 if ( document.all ) {
  eval( theform ).onkeypress = function(){ return RestringeInput( thelimit,event,theform )}
  eval( theform ).onkeyup = function(){ ContaLimite( thelimit,event,theform ) }
 } else if ( ns6 ) {
  document.body.addEventListener( 'keypress', function( event ) { RestringeInput( thelimit , event , theform ) }, true );
  document.body.addEventListener( 'keyup', function( event ) { ContaLimite( thelimit , event , theform ) }, true );
 }
}



function FormataCampo(Campo,teclapres,mascara){
//pegando o tamanho do texto da caixa de texto com delay de -1 no event
//ou seja o caractere que foi digitado não ser encontado.
strtext = Campo.value
tamtext = strtext.length
//pegando o tamanho da máscara
tammask = mascara.length
//criando um array pa?????a?ra guardar cada caractere da máscara
arrmask = new Array(tammask)
//jogando os caracteres para o vetor
for (var i = 0; i < tammask; i++){
 arrmask[i] = mascara.slice(i,i+1)
}
//alert (teclapres.keyCode)
//começando o trabalho sujo
if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
 if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
  OrganizaCasa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)
 } else {
  DetonaEvent(Campo,strtext)
 }
} else {
 if ((arrmask[tamtext] == "A"))    {
  charupper = event.valueOf()
  //charupper = charupper.toUpperCase()
  DetonaEvent(Campo,strtext)
  masktext = strtext + charupper
  Campo.value = masktext
 }
}
}

//Adiciona todos os caracteres que podem ser usados como máscara
function OrganizaCasa(Campo,arrpos,teclapres_key,strtext){
if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){
 separador = arrpos
 masktext = strtext + separador
 Campo.value = masktext
}
}

function DetonaEvent(Campo,strtext){
event.returnValue = false
if (strtext != "") {
 Campo.value = strtext
}
}

function VerificaForm(){
if (document.frmteste.elements["txt.nome"].value == ""){
 window.alert("O campo Nome não pode ser vazio!");
 document.frmteste.elements["txt.nome"].focus();
 return false;
}
if (document.frmteste.elements["txt.endereco"].value == ""){
 window.alert("O campo Endereço não pode ser vazio!");
 document.frmteste.elements["txt.endereco"].focus();
 return false;
}
if (document.frmteste.elements["txt.moeda"].value.length > "10") {
 window.alert("O campo Moeda não pode ter mais de 10 caracteres!");
 document.frmteste.elements["txt.moeda"].focus();
 return false;
}
}

function NumberOnly() {
if ( event.keyCode < 48 || event.keyCode > 57 ) { //Só aceita caracteres com código ASCII entre 48..57 (números)
 event.returnValue = false;
}
}

// Esta function está configurada para o campo receber duas casas após a vírgula

function currencyFormat(fld, milSep, decSep, e) {
var sep = 0;
var key = '';
var i = j = 0;
var len = len2 = 0;
var strCheck = '0123456789';
var aux = aux2 = '';
var whichCode = (window.Event) ? e.which : e.keyCode;
if (whichCode == 13)
return true;  // Enter
key = String.fromCharCode(whichCode);  // Get key value from key code
if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
len = fld.value.length;
for(i = 0; i < len; i++)
if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break;
aux = '';
for(; i < len; i++)
if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i);
aux += key;
len = aux.length;
if (len == 0) fld.value = '';

// Aqui tem que testar: se $Column->{decimals} for 3 coloca + '0' + '0' + senão, apenas + '0' +
if (len == 1) fld.value = '0' + decSep + '0' + aux; // Alterei coloquei + '0' , decSep = , (vírgula)

// Aqui tem que testar: se $Column->{decimals} for 3 coloca + '0' + senão, não coloca
if (len == 2) fld.value = '0' + decSep + aux; // Alterei coloquei + '0'

// Aqui tem que testar: se $Column->{decimals} for 3 coloca essa linha senão não coloca
//if (len == 3) fld.value = '0' + decSep + aux + aux2; // Adicionei esta linha

// Aqui tem que colocar a variável $decimal
if (len > 2) { // Alterei de 2 para 3
 aux2 = '';

 // A cada três caracteres adiciona um milSep (ponto ".")
 for (j = 0, i = len - 3; i >= 0; i--) {
  if (j == 3) {
   aux2 += milSep;
   j = 0;
  }
  aux2 += aux.charAt(i);
  j++;
 }

 fld.value = '';
 len2 = aux2.length;

 // Aqui tem que testar: se $Column->{decimals} for 3 coloca i > 0 senão coloca i >= 0
 for (i = len2 - 1; i >= 0; i--) // Alterei de i >= 0 para i > 0
 fld.value += aux2.charAt(i);

 // Aqui tem que coloca a variável mo lugar do 3
 fld.value += decSep + aux.substr(len - 2, len); // O número dois é o valor chave (número de casas que vem depois da vírgula)
}
return false;
}

function Limitar (what,limit) {
if (what.value.length>=limit)
return false;
}
