function fBlur() {}

function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++) {
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "";
		blink[i].style.color = "RED";
	}
}

function startBlink() {
	if (document.all)
		setInterval("doBlink()",300)
}

function handleSubmit() {
	document.frmDefault.submit();
}

function fNavigator() {
	//alert(navigator.appName);
	//if (navigator.appName.indexOf("Explorer") < 0) {
	//	alert('Navegador incompatível! - É necessário o uso do Internet Explorer 5.0 ou Superior!');
	//	document.location = "history.back()";
	//}
}

function handleOver(lv,tc) {
	document.frmDefault.lv.value = lv;
	document.frmDefault.tc.value = tc;
	document.frmDefault.mt.value = 1;
}

function DivSetVisible(state) {
	var DivRef = document.getElementById('PopupDiv');
	var IfrRef = document.getElementById('DivShim');
	if(state) {
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
	} else {
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
	}
}

function DivSetVisible2(obj, state) {
	var DivRef = document.getElementById('PopupDiv');
	var IfrRef = document.getElementById('DivShim');
	if(state) {
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
		obj.alt = "Aguarde processamento";
		obj.disabled = true;
	} else {
		DivRef.style.display = "none";
		IfrRef.style.display = "none";
	}
}

function diferencaDias(data1, data2){
	var dif =
	    Date.UTC(data1.getYear(),data1.getMonth(),data1.getDate(),0,0,0)
	  - Date.UTC(data2.getYear(),data2.getMonth(),data2.getDate(),0,0,0);
	return Math.abs((dif / 1000 / 60 / 60 / 24));
}

function f_zero_esq(obj, x) {
  	var a = document.getElementById(obj).value;
	if(isNaN(a)) { a = '0000'; }
	var i = a.length;
   	while (a.length < x) { a = '0'+a; }
	document.getElementById(obj).value = a;
}


/*
function protegercodigo() {
    if (event.button==2||event.button==3){
        alert('Opção Inválida!');
	}
}
document.onmousedown=protegercodigo;
*/

function muda_cor(n){
   var celula = document.getElementById(n);
   celula.style.color='#EE0000';
}

function aleatorio(inferior,superior){
    numPosibilidades = superior - inferior
    aleat = Math.random() * numPosibilidades
    aleat = Math.round(aleat)
    return parseInt(inferior) + aleat
}

function fmtRealBR( number, decimals) {
	var dec_point		= '.';
	var thousands_sep	= '';

    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;

    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}

String.prototype.trim = function()
{
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function setVar(s, f, n, v) {
	var e = new Date ();
	e.setTime (e.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
	setCookie(s+f+n, v, e);
}

function getVar(n) {
	return getCookie(n);
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function ieExecWB( intOLEcmd, intOLEparam ) {
	var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';

	document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
	if (!intOLEparam || intOLEparam < -1 || intOLEparam > 1 ) {
		intOLEparam = 1;
	}

	WebBrowser1.ExecWB( intOLEcmd, intOLEparam );
	WebBrowser1.outerHTML = "";
}

function cnpjcpf(CNUMB)
{
	var CTYPE;
	CNUMB=ClearStr(CNUMB,'-');
	CNUMB=ClearStr(CNUMB,'/');
	CNUMB=ClearStr(CNUMB,',');
	CNUMB=ClearStr(CNUMB,'.');
	CNUMB=ClearStr(CNUMB,'(');
	CNUMB=ClearStr(CNUMB,')');
	CNUMB=ClearStr(CNUMB,' ');
	if(CNUMB.length == 11) {
		CTYPE = 'CPF';
	} else {
	  	CTYPE = 'CNPJ';
	}
	if(!cnpjcpfverif(CNUMB, CTYPE))  {
		alert(CTYPE+" inválido!");
		return false;
	}
	return true;
}

function cnpjcpfverif(CNUMB,CTYPE)
{
  CNUMB=cnpjcpfparse(CNUMB)
  if(CNUMB == 0)
  {
    return(false);
  }
  else
  {
    g=CNUMB.length-2;
    if(cnpjcpfteste(CNUMB,CTYPE,g))
    {
      g=CNUMB.length-1;
      if(cnpjcpfteste(CNUMB,CTYPE,g))
      {
        return(true);
      }
      else
      {
        return(false);
      }
    }
    else
    {
      return(false);
    }
  }
}

function ClearStr(str, char)
{
  while((cx=str.indexOf(char))!=-1)
  {
    str = str.substring(0,cx)+str.substring(cx+1);
  }
  return(str);
}

function cnpjcpfparse(c)
{
  c=ClearStr(c,'-');
  c=ClearStr(c,'/');
  c=ClearStr(c,',');
  c=ClearStr(c,'.');
  c=ClearStr(c,'(');
  c=ClearStr(c,')');
  c=ClearStr(c,' ');
  if((parseFloat(c) / c != 1))
  {
    if(parseFloat(c) * c == 0)
    {
      return(c);
    }
    else
    {
      return(0);
    }
  }
  else
  {
    return(c);
  }
}


function cnpjcpfteste(CNUMB,CTYPE,g)
{
  var dig=0;
  var ind=2;
  for(f=g;f>0;f--)
  {
    dig+=parseInt(CNUMB.charAt(f-1))*ind;
    if (CTYPE=='CNPJ')
    { if(ind>8) {ind=2} else {ind++} }
    else
    { ind++ }
  }
  dig%=11;
  if(dig<2)
  {
    dig=0;
  }
  else
  {
    dig=11-dig;
  }
  if(dig!=parseInt(CNUMB.charAt(g)))
  {
    return(false);
  }
  else
  {
    return(true);
  }
}


function LinkCad(sVar) {
   window.open(sVar,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,top=0,left=0,resizable=yes,width=790,innerwidth=790,height=520,innerheight=520');
}

function LinkRpt(sVar) {
   window.open(sVar,'','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,top=0,left=0,resizable=yes,width=660,innerwidth=660,height=520,innerheight=520');
}

function OpenForm(sVar,sName) {
   window.open(sVar,"_parent",'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,top=0,left=0,resizable=yes,width=790,innerwidth=790,height=520,innerheight=520');
}

function OpenForm2(sVar,sName) {
   window.open(sVar,sName,'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,top=0,left=0,resizable=yes,width=790,innerwidth=790,height=520,innerheight=520');
	window.close();
}

function fmtDecimal(sValue){
	sValue = sValue.toString().replace( '.', ',' );
	return sValue;
}

function fmtDecimalEn(sValue){
	sValue = sValue.toString().replace( ',', '.' );
	return sValue;
}

function nvl(num,def) {
	if(num == null) {
		num = def;
	}
	return num;
}

function divide(var1,var2) {
	if(var1 == null) 	{ var1 = 0; }
	if(var2 == null) 	{ var2 = 0; }
	if(var2 == 0)		{ var2 = 1; }
	return (var1 / var2);
}

function roundTo(v, x)
{
   x = (!x ? 2: x);
   v = v*100;
   v = Math.round(v);
   v = v / 100;
   return v;
}

function roundToNPlaces(number, x)
{
   x = (!x ? 2: x);
   return divide(Math.round(number * Math.pow(10, x)), Math.pow(10,x));
}

function roundToCents(number)
{
     // first, round it to 2 places.
     number = roundToNPlaces(number, 2);

     //check to see whether padding of 2 zeros is needed.
     if (number == Math.floor(number))
     {
          number = number+".00";
     }
     else
     {
          //check to see whether padding of 1 zero is needed.
          if (number*10 == Math.floor(number*10))
          {
               number =  number + '0';
          }
     }
     return number;
}

function roundToCents4(number)
{
     // first, round it to 4 places.
     number = roundToNPlaces(number, 4);

     //check to see whether padding of 4 zeros is needed.
     if (number == Math.floor(number))
     {
          number = number+".0000";
     }
     else
     {
          //check to see whether padding of 1 zero is needed.
          if (number*10 == Math.floor(number*10))
          {
               number =  number + '0';
          }
     }
     return number;
}

function setamais() {
	document.frmDefault.seta.value=">>";
	document.frmDefault.submit();
}

function setamenos() {
	document.frmDefault.seta.value="<<";
	document.frmDefault.submit();
}

function popCalInMain(dateCtrl) {
	var w=self.gfPop;
	w.fPopCalendar(dateCtrl,null,'dateCtrl',null,[0,0]);
}

function popCalInMainFrame(dateCtrl) {
	var w=self.gfPop;
	w.fPopCalendar(dateCtrl,null,null,null,[70,0,true]);	// pop calendar at fixed location
}










//---novas mascaras
function fg_mascara(o,f){
    v_obj=o
    v_fun=f
    if(v_obj.readOnly == false) {
    	setTimeout("execfg_mascara()",1)
	}
}

function execfg_mascara(){
    v_obj.value=v_fun(v_obj.value)
}

function fg_leech(v){
    v=v.replace(/o/gi,"0")
    v=v.replace(/i/gi,"1")
    v=v.replace(/z/gi,"2")
    v=v.replace(/e/gi,"3")
    v=v.replace(/a/gi,"4")
    v=v.replace(/s/gi,"5")
    v=v.replace(/t/gi,"7")
    return v
}

function fg_sonumeros(v){
    return v.replace(/\D/g,"")
}

function fg_fone(v){
    v=v.replace(/\D/g,"")                 //Remove tudo o que não é dígito
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")    //Coloca hífen entre o quarto e o quinto dígitos
    return v
}

function fg_cpf(v){
    v=v.replace(/\D/g,"")                    //Remove tudo o que não é dígito
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
    v=v.replace(/(\d{3})(\d)/,"$1.$2")       //Coloca um ponto entre o terceiro e o quarto dígitos
                                             //de novo (para o segundo bloco de números)
    v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos
    return v
}

function fg_real(v){
    v=v.replace(/\D/g,"");                    //Remove tudo o que não é dígito
    l=v.length
    if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 4) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 5) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 9) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{13})(\d)/,"$1.$2")}
    if(l == 16) {v=v.replace(/(\d{14})(\d)/,"$1.$2")}
    if(l == 17) {v=v.replace(/(\d{15})(\d)/,"$1.$2")}
    if(l == 18) {v=v.replace(/(\d{16})(\d)/,"$1.$2")}
    if(l == 19) {v=v.replace(/(\d{17})(\d)/,"$1.$2")}
    if(l == 20) {v=v.replace(/(\d{18})(\d)/,"$1.$2")}
    return v
}

function fg_real_neg(v){
    var v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    var v=v.replace(/[^0123456789]/g,"");   		//Remove tudo o que não está no meio
    var l=v.length;
	if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 4) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 5) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 9) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{13})(\d)/,"$1.$2")}
    if(l == 16) {v=v.replace(/(\d{14})(\d)/,"$1.$2")}
    if(l == 17) {v=v.replace(/(\d{15})(\d)/,"$1.$2")}
    if(l == 18) {v=v.replace(/(\d{16})(\d)/,"$1.$2")}
    if(l == 19) {v=v.replace(/(\d{17})(\d)/,"$1.$2")}
    if(l == 20) {v=v.replace(/(\d{18})(\d)/,"$1.$2")}
    if(s=='-') {
    	return s+v;
	} else {
    	return v;
	}
}

function fg_indice(v){
    var v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    var v=v.replace(/[^0123456789]/g,"");   		//Remove tudo o que não está no meio
    var l=v.length;
    if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v='.'+v}
    if(l == 4) {v='.'+v}
    if(l == 5) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 9) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 16) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(l == 17) {v=v.replace(/(\d{13})(\d)/,"$1.$2")}
    if(l == 18) {v=v.replace(/(\d{14})(\d)/,"$1.$2")}
    if(l == 19) {v=v.replace(/(\d{15})(\d)/,"$1.$2")}
    if(l == 20) {v=v.replace(/(\d{16})(\d)/,"$1.$2")}
    if(s=='-') {
    	return s+v;
	} else {
    	return v;
	}
}

function fg_indice3(v){
    var v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    var v=v.replace(/[^0123456789]/g,"");   		//Remove tudo o que não está no meio
    var l=v.length;
    if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v='.'+v}
    if(l == 4) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 5) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 9) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(l == 16) {v=v.replace(/(\d{13})(\d)/,"$1.$2")}
    if(l == 17) {v=v.replace(/(\d{14})(\d)/,"$1.$2")}
    if(l == 18) {v=v.replace(/(\d{15})(\d)/,"$1.$2")}
    if(l == 19) {v=v.replace(/(\d{16})(\d)/,"$1.$2")}
    if(l == 20) {v=v.replace(/(\d{17})(\d)/,"$1.$2")}
    if(s=='-') {
    	return s+v;
	} else {
    	return v;
	}
}

function fg_indice8(v){
    var v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    var v=v.replace(/[^0123456789]/g,"");   		//Remove tudo o que não está no meio
    var l=v.length;
    if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v='.'+v}
    if(l == 4) {v='.'+v}
    if(l == 5) {v='.'+v}
    if(l == 6) {v='.'+v}
    if(l == 7) {v='.'+v}
    if(l == 8) {v='.'+v}
    if(l == 9) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 16) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 17) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 18) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 19) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 20) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(s=='-') {
    	return s+v;
	} else {
    	return v;
	}
}

function fg_qtd3(v){
    var v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    var v=v.replace(/[^0123456789]/g,"");   		//Remove tudo o que não está no meio
    var l=v.length;
    if(l == 1) {v='.'+v}
    if(l == 2) {v='.'+v}
    if(l == 3) {v='.'+v}
    if(l == 4) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 5) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 9) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 10) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    if(l == 11) {v=v.replace(/(\d{8})(\d)/,"$1.$2")}
    if(l == 12) {v=v.replace(/(\d{9})(\d)/,"$1.$2")}
    if(l == 13) {v=v.replace(/(\d{10})(\d)/,"$1.$2")}
    if(l == 14) {v=v.replace(/(\d{11})(\d)/,"$1.$2")}
    if(l == 15) {v=v.replace(/(\d{12})(\d)/,"$1.$2")}
    if(s=='-') {
    	return s+v;
	} else {
    	return v;
	}
}

function fg_qtd1(v){
    v=v.replace(/\D/g,"");                    //Remove tudo o que não é dígito
    l=v.length
    if(l == 2) {v=v.replace(/(\d{1})(\d)/,"$1.$2")}
    if(l == 3) {v=v.replace(/(\d{2})(\d)/,"$1.$2")}
    if(l == 4) {v=v.replace(/(\d{3})(\d)/,"$1.$2")}
    if(l == 5) {v=v.replace(/(\d{4})(\d)/,"$1.$2")}
    if(l == 6) {v=v.replace(/(\d{5})(\d)/,"$1.$2")}
    if(l == 7) {v=v.replace(/(\d{6})(\d)/,"$1.$2")}
    if(l == 8) {v=v.replace(/(\d{7})(\d)/,"$1.$2")}
    return v
}

function fg_cep(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações
    return v
}

function fg_hora(v){
    v=v.replace(/D/g,"")                //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1:$2") //Esse é tão fácil que não merece explicações
    return v
}

function fg_cnpj(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{3})(\d)/,".$1/$2")           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/(\d{4})(\d)/,"$1-$2")              //Coloca um hífen depois do bloco de quatro dígitos
    return v
}

function moeda(v) {
	var i = parseInt(v);
	var d = parseFloat(v)-i;
	var n = d + 0.000001;
	var s = n+'';

	return(i + '.' + s.substr(2,2));
}

