<!--

/**
 *
 */
function soNumero(event){
   var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
   var caract = new RegExp(/^[0-9]+$/i);
   var caract = caract.test(String.fromCharCode(keyCode));

   if(keyCode != 8)
   if(keyCode != 46)
   if(!caract){
	  event.keyCode=0;
	  return false;
   }
}

/**
 *
 */
function limpa() {
    var listElementos  = document.forms[0].elements;
    var totalElementos = document.forms[0].elements.length;

    for (i=0; i<totalElementos; i++) {
         elemento = listElementos[i];
	     if (elemento.type == "text" || elemento.type == "textarea") {
		 	 elemento.value = "";
	     }
    }
}

/**
 *
 */
function mostrar(obj) {
   document.getElementById(obj).style.visibility = "visible";
}

/**
 *
 */
function ocultar(obj) {
   document.getElementById(obj).style.visibility = "hidden";
}

/**
 *
 */
function acender( linha ) {
	if ( navigator.appName == "Netscape" ) linha.bgColor = "#FAFAEF"
	else linha.style.backgroundColor = "#FAFAEF";
}

/**
 *
 */
function apagar( linha ) {
    if ( navigator.appName == "Netscape" ) linha.bgColor = "#f5f5f5"
	else linha.style.backgroundColor = "#f5f5f5";
}

/**
 *
 */
function abrePopUp(url, width, height, scrollbars) {
	var w = width;
	var h = height;
	var lado = (screen.width - w) / 2;
	var topo = (screen.height - h) / 2;
	janela	= window.open(url, "",'height='+h+',width='+w+',top='+topo+',left='+lado+',scrollbars='+scrollbars);
	janela.focus();
}

/**
 *
 */
function fechar() {
   window.close();
}


/**
 * Função usada para limitar a quantidade
 * de caracteres de um determinado campo.
 **/
function limite(campo, size)
{   if (campo.value.length > size)
   	{   event.keyCode=0;
        campo.value = campo.value.substring(0, size);
    }
    return;
}

/**
 * Função que formata um campo do formulário de
 * acordo com a máscara informada...
 *
 * Parâmetros:
 *  => objForm (o Objeto Form);
 *  => strField (string contendo o nome do textbox);
 *  => sMask (mascara que define o formato que o dado será apresentado,
 *            usando o algarismo "9" para definir números e o símbolo "!" para
 *            qualquer caracter...
 *  => evtKeyPress (evento);
 *
 * Uso..: <input type="textbox" name="xxx"
 * onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);">
 *
 * Observação: As máscaras podem ser representadas como os exemplos abaixo:
 * CEP -> 99.999-999
 * CPF -> 999.999.999-99
 * RG -> 99.999.999-9
 * CNPJ -> 99.999.999/9999-99
 * Data -> 99/99/9999
 * Tel Resid -> (99) 999-9999
 * Tel Cel -> (99) 9999-9999
 * Processo -> 99.999999999/999-99
 * Inscrição Estadual -> 999.999.999-9999
 * C/C -> 999999-!
 * E por aí vai...
 **/
function format(field, sMask, evtKeyPress)
{
   var i;
   var nCount;
   var sValue;
   var fldLen;
   var mskLen;
   var bolMask;
   var sCod;
   var nTecla;

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

   sValue = field.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( " ", "" );

   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++;
   }

   field.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 redirect(url) {
	document.location.href = url;
}

/* url encode */
function urlencode(obj) {
	var unencoded = obj;
	return encodeURIComponent(unencoded);
}
/* url decode */
function urldecode(obj) {
	var encoded = obj;
	return decodeURIComponent(encoded.replace(/\+/g,  " "));
}

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;
 var t = new String(fld.value);
 if (whichCode == 8){
	fld.value = t.substring(0, t.length-1);
 } 
 key = String.fromCharCode(whichCode);
 if (strCheck.indexOf(key) == -1) return false;
 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 = '';
 if (len == 1) fld.value = '0' + decSep + '0' + aux;
 if (len == 2) fld.value = '0' + decSep + aux;
 // Se 3 for 3 coloca essa linha senão não coloca
 if (len == 3) fld.value = '0' + decSep + aux + aux2;
 if (len > 3) {
	  aux2 = '';

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

  // Se 3 for 3 coloca > senão coloca >=
  for (i = len2 - 1; i > 0; i--) // Alterei de i >= 0 para i > 0
  fld.value += aux2.charAt(i);
  fld.value += decSep + aux.substr(len - 2, len); // Número de casas após a vírgula
 }
 return false;

}


//-->
