function FaleConosco() {
    document.getElementById("acao").value = "faleconosco";
    document.forms[0].submit();
}

function Termos() {
    document.getElementById("acao").value = "termos";
    document.forms[0].submit();
}

function SiteMap() {
    document.getElementById("acao").value = "sitemap";
    document.forms[0].submit();
}

function Ajuda() {
    document.getElementById("acao").value = "ajuda";
    document.forms[0].submit();
}

function Finaliza() {
    document.getElementById("acao").value = "finaliza";
    document.forms[0].submit();
}

function pesquisa(pg)
{
    request.open("GET", urlpesquisa + "&p=" + pg, true);
    request.onreadystatechange = pesquisax;
    request.send(null);
}

function cancela()
{
    document.getElementById("acao").value = "inicializa";
    document.forms[0].submit();
}

function procura()
{
    document.getElementById("acao").value = "procura";
    document.forms[0].submit();
}

function filtra()
{
    document.getElementById("acao").value = "filtra";
    document.forms[0].submit();
}

function avanca()
{
    document.getElementById("acao").value = "avanca";
    document.forms[0].submit();
}

function voltar()
{
    document.getElementById("acao").value = "voltar";
    document.forms[0].submit();
}

function preupdate(foco)
{
    document.getElementById("acao").value = "preupdate";
    document.getElementById("foco").value = foco;
    document.forms[0].submit();
}

function newreg()
{
    document.getElementById("acao").value = "INS";
    document.forms[0].submit();
}

function confirma()
{
    document.getElementById("acao").value = "confirma";
    document.forms[0].submit();
}

function Menu()
{
    document.getElementById("acao").value = "menu";
    document.forms[0].submit();
}

function gridColor(r, line)
{
    if(r) line.setAttribute('bgcolor', '#E8E8E8');
    if(!r) line.setAttribute('bgcolor', '#FFFFFF');
    r = !r;
    return r;
}

function objeto(ID)
{
    return document.getElementById(ID);
}

function formulario()
{
    return document.forms[0];
}

function pega(ID)
{
    return objeto(ID).value;
}

function seta(ID, val)
{
    objeto(ID).value = val;
}

function seti(ID, val)
{
    objeto(ID).innerHTML = val;
}

function limpa(ID)
{
    objeto(ID).value = "";
}

function limpi(ID)
{
    objeto(ID).innerHTML = "";
}

function atualizando()
{
    seti("message", "Aguarde! Atualizando dados...");
}

function limpando()
{
    seti("message", "Aguarde! Limpando dados...");
}

function Index() {
    location.href="index.jsp";
}

function Exit() {
    location.href="sessionout.jsp";
}

function FGMaiss() {
    location.href="http://www.fgmaiss.com.br";
}

function Prfweb() {
    location.href="http://www.prefeituraweb.com.br";
}

function trataInt(objForm, strField) {
	var sValue = objForm[strField].value;
	var sValuex = '';
	var sValuey = '-0123456789';
	var i = 0;
	var c = 1;

   	while (i <= sValue.length) {
	   	if(c == 1 && sValue.substr(i,1) == '.') {
		   	break;
	   	}
	   	if(sValuey.indexOf(sValue.substr(i,1), 0) >= 0) {
			sValuex += sValue.substr(i,1);
		}
		if(sValue.substr(i,1) == '.') {
			c += 1;
		}
		i++;
	}
	objForm[strField].value = sValuex;

	/*
   	if(	sValue.indexOf(',', 0) >= 0) {
	   	alert('Favor informar somente numeros e (.)');
		objForm[strField].focus();
		objForm[strField].select();
	   	return false;
	}
	*/
	return true;
}

function trataVal(objForm, strField) {
	var sValue = objForm[strField].value;
	var sValuex = '';
	var sValuey = '-0123456789.';
	var i = 0;
	var c = 0;

   	while (i <= sValue.length) {
	   	if(c == 1 && sValue.substr(i,1) == '.') {
		   	break;
	   	}
	   	if(sValuey.indexOf(sValue.substr(i,1), 0) >= 0) {
			sValuex += sValue.substr(i,1);
		}
		if(sValue.substr(i,1) == '.') {
			c += 1;
		}
		i++;
	}
	objForm[strField].value = sValuex;
	return true;
}

function trataData(objForm, strField) {
	var sValue = objForm[strField].value;
   	if(sValue.length == 8) {
	   	if(sValue.substr(6,2) >= '15' && sValue.substr(6,2) <= '99') {
			sValue = sValue.substr(0,6)+'19'+sValue.substr(6,2);
		} else {
			sValue = sValue.substr(0,6)+'20'+sValue.substr(6,2);
		}
		objForm[strField].value = sValue;
	}
}

function fEnd(objForm, strField){
	//document.getElementById(id).value = document.getElementById(id).value;
	objForm[strField].value = objForm[strField].value;
}

function SetEnd(TB) {
	if (TB.createTextRange) {
		var FieldRange = TB.createTextRange();
		FieldRange.moveStart('character', TB.value.length);
		FieldRange.collapse();
		FieldRange.select();
	}
}

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

	if(sMask=="UPPER" || sMask=="LOWER") {
		return true;
	} else {
		// Limpa todos os caracteres de formatação que
		// já estiverem no campo.
		i = 0;
		sValue = objForm[strField].value;
	   	while (i <= sValue.length) {
			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( " ", "" );
			i++;
		}

		fldLen = sValue.length;

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

		//Caso seja pressionado backspace, então ignora a verificação da máscara
		if (nTecla !=8 && nTecla != 37 && nTecla != 38 && nTecla != 39 && nTecla != 40){
			if (mskLen <= sMask.length) {
			   	while (i <= mskLen) {
				  	bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ",") ||  (sMask.charAt(i) == ".") || (sMask.charAt(i) == ":") || (sMask.charAt(i) == "/") || (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;
			}
		}
	}

	return true;
}

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 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){
   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) : "");
}

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

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

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 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
    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")}
    return v
}

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

function fg_indice8(v){
    v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    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){
    v=v.replace(/[^-0123456789]/g,"");   		//Remove tudo o que não está no meio
    var s=v.substr(0,1);
    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
    var 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 fg_classif(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,9);
    v=v.replace(/^(\d{1})(\d)/,"$1.$2");             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{1})\.(\d{1})(\d)/,"$1.$2.$3"); //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{2})(\d)/,".$1.$2");           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/\.(\d{2})\.(\d{2})(\d)/,".$1.$2.$3");           //Coloca uma barra entre o oitavo e o nono dígitos
    return v;
}

function fg_clsdsp(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,12);
    v=v.replace(/^(\d{1})(\d)/,"$1.$2");             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{1})\.(\d{1})(\d)/,"$1.$2.$3"); //Coloca ponto entre o quinto e o sexto dígitos
    v=v.replace(/\.(\d{2})(\d)/,".$1.$2");           //Coloca uma barra entre o oitavo e o nono dígitos
    v=v.replace(/\.(\d{2})\.(\d{2})(\d)/,".$1.$2.$3");           //Coloca uma barra entre o oitavo e o nono dígitos
    return v;
}

function fg_clsuor(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,6);
    v=v.replace(/^(\d{2})(\d)/,"$1.$2");             //Coloca ponto entre o segundo e o terceiro dígitos
    return v;
}

function fg_clssfg(v){
    v=v.replace(/\D/g,"")                           //Remove tudo o que não é dígito
    v=v.substr(0,6);
    v=v.replace(/^(\d{2})(\d)/,"$1.$2")             //Coloca ponto entre o segundo e o terceiro dígitos
    return v;
}

function fg_clsuex(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,12);
    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
    return v;
}

function fg_clsrec(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,9);
    v=v.replace(/^(\d{4})(\d)/,"$1.$2");             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{4})\.(\d{4})(\d)/,"$1.$2.$3"); //Coloca ponto entre o quinto e o sexto dígitos
    return v;
}

function fg_date(v){
    v=v.replace(/\D/g,"");                           //Remove tudo o que não é dígito
    v=v.substr(0,10);
    v=v.replace(/^(\d{2})(\d)/,"$1/$2");             //Coloca ponto entre o segundo e o terceiro dígitos
    v=v.replace(/^(\d{2})\/(\d{2})(\d)/,"$1/$2/$3"); //Coloca ponto entre o quinto e o sexto dígitos
    return v;
}
