// envia form por submit
function linkSubmit(var_value){
	var frm_hidden = document.getElementById("frm_hidden");
	frm_hidden.id_mensagem.value = var_value;
	frm_hidden.submit();
}


function poup(URL, opcao, nome){
	if (nome == null) nome = "janela01"
   window.open(URL,nome, opcao);
}

function sf() {	
	contador_caracteres('texto_conteudo', 'contador', 255);
      document.getElementById('texto_conteudo').focus();  
}

function contador_caracteres(opt_texto_conteudo, opt_contador, opt_maxSize) {
  var texto_conteudo = opt_texto_conteudo ?
    opt_texto_conteudo : "texto_conteudo";
  var contador = opt_contador ? opt_contador : "contador";
  var maxSize = opt_maxSize ? opt_maxSize : 255;
    
  var field = document.getElementById(texto_conteudo);
  if (field && field.value.length >= maxSize) {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(contador);
  if (txtField) {  
    txtField.innerHTML = field.value.length;
  }
}

function trocaClass(c1, c2, id) {
    var ob = document.getElementById(id);
    
    if(ob.className == c1) {
        ob.className = c2;
    } else {
        ob.className = c1;
    }
}

//MASCARA DE VALORES
function txtBoxFormat(objeto, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;
	

	if (evtKeyPress.charCode) nTecla = evtKeyPress.charCode; // Mozilla  
	else if (evtKeyPress.which) nTecla = evtKeyPress.which; // Netscape 4.?  
	else if (evtKeyPress.keyCode) nTecla = evtKeyPress.keyCode;      

	/*if(document.all) { alert('aqui');
		// Internet Explorer
		nTecla = evtKeyPress.keyCode; }
	else {
		 alert('aqu22');
		if(document.layers) {
			// Nestcape
			nTecla = evtKeyPress.which;
		}
	}*/
	
	sValue = objeto.value;
	
	// Limpa todos os caracteres de formatação que já estiverem no campo.
	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( ")", "" );
	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) == "/") || (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++;
	}

	objeto.value = sCod;
	if (nTecla != 8 || nTecla != 37) { 
		// 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;
	}
}

/*
FUNÇÃO DE FORMATAÇÃO DE CAMPO
PARA CHAMÁ-LA, TEM-SE Q PASSAR 3 PARÂMETROS: CAMPO, MÁSCARA, EVENTO
OS PARÂMETROS TÊM QUE SER PASSADOS ATRAVÉS DO EVENTO onKeyPress

EX:  <input type="text" name="cep" id="telefone" onKeyPress="return formata(this, '§§§.§§§.§§§-§§', event)"> // formata o campo para cep

O CARACTER '§' DEFINE QUE SÓ SERÁ PERMITIDO NÚMEROS
O CARACTER '!' DEFINE QUE É PERMITIDO QUALQUER CARACTER

OBS: COM ESSA FUNÇÃO, NÃO É NECESSÁRIO COLOCAR A PROPRIEDADE 'MAXLENGTH' NO CAMPO

PRODUZIDO POR Tales<tales_augusto@hotmail.com>
*/
function formata(campo, mask, evt) {
 
if (evt.charCode) key = evt.charCode; // Mozilla  
else if (evt.which) key = evt.which; // Netscape 4.?  
else if (evt.keyCode) key = evt.keyCode; 
 
/* if(document.all) { // Internet Explorer
    key = evt.keyCode; }
    else{ // Nestcape
       key = evt.which;
     }
*/
 string = campo.value;  
 i = string.length;

 if (i <= mask.length) { 

	  if (key == 8 || key == 37 || key == 39 || key == 36) {
       return true;
      }

  if (mask.charAt(i) == '§') {
       return (key > 47 && key < 58);
      } else {
       if (mask.charAt(i) == '!') {  return true;  }
   for (c = i; c < mask.length; c++) {
         if (mask.charAt(c) != '§' && mask.charAt(c) != '!')
         campo.value = campo.value + mask.charAt(c);
      else if (mask.charAt(c) == '!'){
                return true;
       } else {
         return (key > 47 && key < 58);
          }
       }
    }
  } else return false;
}

//funcao que imprime a pagina
function imprimirHTML(){
	if (!window.print){
		alert("Use o Firefox ou Internet Explorer \n nas versões 4.0 ou superior!")
		return false;
	}
	window.print();
}
