/* Início função para limitar quantidade de caracteres no textArea */
function max(txarea){
 total = 300;
 tam = txarea.value.length;
 str="";
 str=str+tam;
 Digitado.innerHTML = str;
 Restante.innerHTML = total - str;
 if (tam > total){
  aux = txarea.value;
  txarea.value = aux.substring(0,total);
  Digitado.innerHTML = total
  Restante.innerHTML = 0
 }
}
/* Fim função para limitar quantidade de caracteres no textArea */

/* Início função para só aceitar números inteiros no input */
function SoNum(e){
 if (e.keyCode)  var tecla = e.keyCode; // internet
 else if (e.which)    var tecla = e.which; // Netscape 4.?
 else if (e.charCode) var tecla = e.charCode; // Mozilla

 if(tecla > 47 && tecla < 58){
  return true;
 }else{
  if(tecla == 8){ // backspace
    return true;
  }else{
   return false;
  }
 }
}
/* Fim função para só aceitar números inteiros no input */

function confExclusao(url){
 if (confirm("Confirmar exclusão?")){
  window.location.href=url;
 }else{
  return false;
 }
}

String.prototype.currencyFormat = function (f, d, t) {
    var n = (n = this.match(/\d/g)) ? n.join('').replace(/^0+/,'') : '0', f = (f) ? f : 2, d = (d) ? d : ',', t = (t) ? t : '.';
    if (n.length < f + 1) return '0' + d + ((n.length < f) ? new Array(f - n.length + 1).join('0') + n : n)
    else return n.substr(0, n.length - f).split('').reverse().join('').match(/\d{1,3}/g).join(t).split('').reverse().join('') + d + n.substr(n.length - f)
}

/* Inicio função abrir janelas */
var win = null;
function NovaJanela(pagina,nome,w,h,scroll){
 LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
 TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
 settings = 'height='+h+', width='+w+', top='+TopPosition+', left='+LeftPosition+', scrollbars='+scroll+', resizable=0';
 win = window.open(pagina,nome,settings);
}
