﻿function EncontrarObjetoID(sObjID, sTipo){
   var sArrLista = document.getElementsByTagName(sTipo);               
   for (var x = 0; x < sArrLista.length; x++){
      if (sArrLista[x].id.indexOf(sObjID) != -1 ){
         return sArrLista[x];
      }
   }
}

function PTAEncontraObj(NomeObj, d) {
	var p,i,x;
	if(!d) d=document;
	if((p=NomeObj.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[NomeObj.substring(p+1)].document;
		NomeObj=NomeObj.substring(0,p);
	}
	if(!(x=d[NomeObj])&&d.all) x=d.all[NomeObj];
	for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][NomeObj];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=PTAEncontraObj(NomeObj,d.layers[i].document);
	if(!x && document.getElementById) x=document.getElementById(NomeObj); return x;
}

//DISPLAY
function AbrirMenuHorizontal(sUrl, sTarget, nNrWidth, nNrHeight){
    try {
        nWidth  = ( nNrWidth!="" ) ? nNrWidth: 600;
        nHeight = ( nNrHeight!="" ) ? nNrHeight: 550;
        switch (sTarget){
            case "1":
                AbrirJanela(sUrl,nNrHeight, nNrWidth, true, true, '', false,true);
                break;            
            case "2":
                AbrirJanela(sUrl,100,100,true, true, '',true,true);
                break;
            default:
                top.location = sUrl;
                break;
        }
    } 
    catch (e){
        alert(e.message);
        return false;
    }
}

function AbrirJanela(sUrl, nLargura, nAltura, bCentralizado, bScroll, sNomeJanela, bMaximizado, bRedimencionavel){

    var sParametros = '';
    sParametros += 'location=no,directories=no,status=no,menubar=no,toolbar=no,';
    
    if (bRedimencionavel) {
        sParametros += 'resizable=yes,';
    } else {
       sParametros += 'resizable=no,';
    }
    
    if (bMaximizado) {
        sParametros += 'width=' + (screen.availWidth -10) + ', height=' + (screen.availHeight - 20) + ', top=0, left=0';
    } 
    else 
    {
        sParametros += 'width=' + nLargura + ', height=' + nAltura;
        if (bCentralizado){
            nPosLeft = (screen.width) ? (screen.width - nLargura) / 2 : 100;
		    nPosTop  = (screen.height) ? (screen.height - nAltura) / 2 - 50 : 100;
    		
		    sParametros += ', top=' + nPosTop + ', left=' + nPosLeft;
        } 
    }
    
    
    if (bScroll){ 
        sParametros += ', scrollbars=1';
    } else { 
        sParametros += ', scrollbars=0';
    }
    
    if (sNomeJanela == "" || sNomeJanela == null)
    {
        sNomeJanela = "WBCPOPUP";
    }
	var NovaJanela = window.open(sUrl, sNomeJanela, sParametros);
	NovaJanela.focus();
	
	/*
	if (bMaximizado) {
        NovaJanela.moveTo(0,0);
        NovaJanela.resizeTo(screen.availWidth, screen.availHeight);	    
    }
    */
    return NovaJanela;
}
function AbrirJanelaDialogo(sUrl, objDialogParametro, nWidth, nHeight, bCentralizado, bScroll){
    AbrirJanelaDlg(sUrl, objDialogParametro, nWidth, nHeight, bCentralizado, bScroll);    
}
function AbrirJanelaDlg(sUrl, objDialogParametro, nWidth, nHeight, bCentralizado, bScroll){
    var sParametro = "";
    if (window.showModalDialog) {
        sParametro = "help:0; status:0;unadorned:1;";
        if (nHeight){ sParametro += "dialogHeight:" + nHeight + "px;"; } else { sParametro += "dialogHeight:350px;"; }
        if (nWidth){ sParametro += "dialogWidth:" + nWidth + "px;"; } else { sParametro += "dialogWidth:500px;"; }
        if (bCentralizado){ sParametro += "center:1;"; } else { sParametro += "center:0;"; }
        if (bScroll){ sParametro += "scroll:1"; } else { sParametro += "scroll:0;"; }
        return window.showModalDialog(sUrl, objDialogParametro,sParametro);
    } else {
        sParametro = "toolbar=no, directories=no, status=no, menubar=no, resizable=no, modal=yes, dependent=yes, dialog=yes";
        if (nHeight){ sParametro += ",height=" + nHeight; } else { sParametro += ",height=350"; }
        if (nWidth){ sParametro += ",width=" + nWidth; } else { sParametro += ",width=500"; }
        if (bScroll){ sParametro += ",scrollbars=yes"; } else { sParametro += ",scrollbars=no"; }
        
        if (bCentralizado) {
            sParametro += "screenY="+((screen.availHeight-nHeight)/2)+",";
            sParametro += "screenX="+((screen.availWidth-nWidth)/2)+",";
        }
        
        return window.open(sUrl, "PTADialog", sParametro);
    }
}

function RetornarParentDocument() {
    var bw = new PTADetectorBrowser();
	
    if (bw.ie) {
        return window.dialogArguments;   
    }
    else {
        return window.opener;
    }
}

function AbrirMenu(sUrl, sTarget, sTituloPagina){
    try {
        var d = top.frames["main"].document.getElementById("frmConteudo");
        switch (sTarget){
            case "novoleilao":
                AbrirJanela(sUrl, 600, 550, true, false);
                break;
            case "novacotacao":
                AbrirJanela(sUrl, 600, 550, true, false);
                break;              
            case "novarequisicao":
                AbrirJanela(sUrl, 600, 550, true, false);
                break;
            case "novabolsa":
                AbrirJanela(sUrl, 600, 550, true, false);
                break;
            case "meusdados":
                AbrirJanela(sUrl, 600, 550, true, false);
                break;
            case "minhaempresa":
                AbrirJanela(sUrl, 700, 550, true, false, 'EmpresaManutencao');
                break;
            case "sobre":
                AbrirJanelaDialogo(sUrl, '',500, 335, true, false);
                break;
            case "imprimir":
                var bw = new PTADetectorBrowser();
                x = top.frames["main"];
                
                if (bw.ie) {
                    x.frmConteudo.focus();
                    x.frmConteudo.print();
                } else {
                    x = top.frames["main"];
                    var y = x.document.getElementsByTagName("IFRAME");
                    for (x=0;x<y.length;x++){
                        if (y[x].id == "frmConteudo"){
                            y[x].focus();
                            print();
                            break;
                        }
                    }                    
                }
                break;
            case "ajuda":
                AbrirJanela(sUrl, 650, 520, true, false);
                break;
            case "desconectar":
                window.open(PTA_sProjeto + 'default.aspx?q=UeCWORgSscUGVpt0Uvz09Q==','','width=780, height=560,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1');
                top.close();
                break;
            case "sair":
                top.close();
                break;
            default:
                d.src = sUrl;
                SetarTituloPagina(sTituloPagina);
                break;
        }
        
        //return false;
    } 
    catch (e){
        alert(e.message);
        return false;
    }
}

function ProcurarPai(obj, sElemento){
	var o = obj;
	while (o.tagName != sElemento)
	{
		o = o.parentNode;
		if (o == null) return; 	// ignore the dragged cursor command
	}			
	return o;
}

function AplicarEstilo(obj, Estilo){
	obj.className = Estilo;
}

function TamanhoDocumento(){
	var bw = new PTADetectorBrowser();
	
	if (bw.ie) {
		this.width  = document.body.offsetWidth;
		this.height = document.body.offsetHeight;
	} else {
		this.width  = innerWidth;
		this.height = innerHeight;
	}
	
	return this;
}

function PTADetectorBrowser(){
	this.ver    = navigator.appVersion
	this.agent  = navigator.userAgent
	this.dom    = document.getElementById?1:0
	this.opera5 = this.agent.indexOf("Opera 5")>-1
	this.ie4    = (document.all && !this.dom && !this.opera5)                 ? 1 : 0;
	this.ie5    = (this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5) ? 1 : 0; 
	this.ie6    = (this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie7 = (this.ver.indexOf("MSIE 7") > -1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie8 = (this.ver.indexOf("MSIE 8") > -1 && this.dom && !this.opera5) ? 1 : 0;
	this.ie = (this.ie4 || this.ie5 || this.ie6 || this.ie7 || this.ie8)
	this.mac    = this.agent.indexOf("Mac")>-1
	this.ns4    = (document.layers && !this.dom)        ? 1 : 0;
	this.ns6    = (this.dom && parseInt(this.ver) >= 5) ? 1 : 0; 
	this.bw     = (this.ie8 || this.ie7 || this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

function ReturnComboValue(objCombo){
	if (objCombo.selectedIndex > -1)
		return objCombo.options[objCombo.selectedIndex].value;
	else
		return("");
}

function ReturnRadioValue(objRadio){
	var strReturn="";
	
	if (objRadio.length){
		for (var i = 0; i < objRadio.length; i++){
			if (objRadio[i].checked){
				strReturn = objRadio[i].value;
				break;
			}
		}
	}
	else{
		if (objRadio.checked)
			strReturn = objRadio.value;
	}	
	return(strReturn);
}                                                               

function ReturnCheckValue(objCheckbox, strSeparador)
{
	if (!strSeparador)
		strSeparador = ',';
		
	var strReturn="";
	
	if (objCheckbox.length){
		for (var i = 0; i < objCheckbox.length; i++){
			if (objCheckbox[i].checked){
				strReturn += strSeparador + objCheckbox[i].value;
				//break;
			}
		}
		
		if (strReturn.length > 0)
		{
			strReturn = strReturn.substr(strSeparador.length);
		}
	}
	else{
		if (objCheckbox.checked)
			strReturn = objCheckbox.value;
	}	
	return(strReturn);
}                                                               

function ReturnComboText(objCombo){
	if (objCombo.selectedIndex > -1)
		return objCombo.options[objCombo.selectedIndex].text;
	else
		return("");
}

function SetComboOption(objCombo, strValue) {
    for (i=0;i<objCombo.length;i++) {
        if (objCombo.options[i].value == strValue) {
            objCombo.selectedIndex = i;
            break;
         }
    }
}

function SetRadioListOption(objRadio, strValue) {
    for (i=0;i<objRadio.length;i++) {
        if (objRadio[i].value == strValue) {
            objRadio[i].checked = true;
            break;
        }
    }
}

function setValidatorState(id, enabled){
	var oBrowser = new PTADetectorBrowser();
	if (oBrowser.ie){		
		var ctrl = PTAEncontraObj(id);		
		if(ctrl){		
		    ctrl.isvalid = enabled;		
		}
	}
}

function Trim(s)
{
	return s.replace(/^\s+|\s+$/g,'');
}
function UnicodeToUTF8(s)
{
	if (!s)
	{
		return "";
	}

	s = escape(s);

	s = s.replace(/%20/g, " ");
	s = s.replace(/%u(\w{4})/g,	"&#x$1;");
	s = s.replace(/%(\w{2})/g,	"&#x$1;");

	return s;
}


// Funcoes para Legenda
function Legenda(o, sCssClass){
    try {
		AplicarEstilo(o, sCssClass);
		
		var oImg = document.getElementById("imgIcoLegenda");
		var oLay = document.getElementById("layLegendaBody");
		
		if (sCssClass == 'tdLegendaOver'){ //mouseover
		    if (oLay.style.display != 'block')//não está mostrando legendas
		        MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_b_legenda2.gif");
		    else
		        MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_c_legenda2.gif");
		} else {//mouseout
		    if (oLay.style.display != 'block')//não está mostrando legenda
		        MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_b_legenda_off2.gif");
		    else
		        MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_c_legenda_off2.gif");
		}
		
    } 
    catch (e){
    }
}

function LegendaClick(o){
    try {
        var obj = document.getElementById(o);
        var oImg = document.getElementById("imgIcoLegenda");
        if (obj) {
            //var oT = new TamanhoDocumento();        
            if (obj.style.display != 'block') {
                obj.style.display = 'block';
                MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_c_legenda_off2.gif");                
                
            } else {
                obj.style.display = 'none';
                MudaImagem(oImg, oImg.src.substr(0, oImg.src.lastIndexOf("/")) + "/ic_b_legenda_off2.gif");
            }
        }
        
        if (window.AjustarTela){
            window.AjustarTela();
        }
        
    } 
    catch (e){
    }
}

function MudaImagem(oImg, sImgNome){    
    if (oImg) {
        oImg.src = sImgNome;
    }
}

//Nome do txt que eh passado no strMessage = txt_msg_ck_ex_Sel 
//Menssagem do txt_msg_ck_ex_Sel = 'Erro: Nenhum item selecionado.'
//Nome do txt que eh passado no strMessageconfirm = txt_msg_ck_ex_Sel_confirm 
//Menssagem do txt_msg_ck_ex_Sel_confirm = ' item(ns) selecionado(s).\nContinuar ?'
function excluirSelecionados(strFormName, strCheckName,strMessage,strMessageconfirm)
{
	if (strFormName == null || strFormName == "" || strFormName == "undefined")
	{
		OK("Aviso", strMessage);
		return false
	}
	
	if (strCheckName == null || strCheckName == "" || strCheckName == "undefined")
	{
		OK("Aviso", strMessage);
		return false
	}
	
	var blFound = false
	var count   = 0;
	
	for (var x = 0; x < strFormName.length; x++)
	{
		if (strCheckName.length > 1)
		{
			if ( strCheckName[0].name.indexOf(strFormName.elements[x].name) != -1 )
			{				
				if (strFormName.elements[x].checked)
				{
					blFound = true
					count++
				}
			}
		}
		else
		{
			if ( strCheckName.name.indexOf(strFormName.elements[x].name) != -1 )
			{
				if (strFormName.elements[x].checked)
				{
					blFound = true
					count++
				}
			}
		}
	}
	
	if (blFound)
	{
		if (strMessageconfirm != '')
		{
			if (SimNao("Aviso", strMessageconfirm))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		OK("Aviso", strMessage);
	}
	
	return (blFound)
}

function excluirSelecionados2(strFormName, strCheckName,objOk,objConfirme)
{
	if (strFormName == null || strFormName == "" || strFormName == "undefined")
	{
		objOk.show();
		return false
	}
	
	if (strCheckName == null || strCheckName == "" || strCheckName == "undefined")
	{
		objOk.show();
		return false
	}
	
	var blFound = false
	var count   = 0;
	
	for (var x = 0; x < strFormName.length; x++)
	{
		if (strCheckName.length > 1)
		{
			if ( strCheckName[0].name.indexOf(strFormName.elements[x].name) != -1 )
			{				
				if (strFormName.elements[x].checked)
				{
					blFound = true
					count++
				}
			}
		}
		else
		{
			if ( strCheckName.name.indexOf(strFormName.elements[x].name) != -1 )
			{
				if (strFormName.elements[x].checked)
				{
					blFound = true
					count++
				}
			}
		}
	}	
	if (blFound)
	{
		if(objConfirme){
		   return objConfirme.show();		
		}
	}
	else
	{
		objOk.show();
	}	
	return (blFound)
}

//Nome do txt que eh passado no strMessage = txt_msg_confirmarExclusao 
//Messagem do txt = 'Você tem certeza que deseja excluir o registro ?'
function confirmarExclusao(strMessage) {
	return SimNao("Aviso", strMessage);
}

function PopulaCombo(Valor, aCombo){
	oBrowser = new PTADetectorBrowser();

	var elem;
	var matriz = new Array();
	var matTMP = Valor.split(':-:');
	for (i=0;i<matTMP.length;i++){
		elem = matTMP[i].split("-:-");
		matriz[i] = new Array(elem[0],elem[1]);
	}
	if (oBrowser.ns4 || oBrowser.ns6){
		for (i = aCombo.length; i>=0; i--)
			aCombo.options[i] = null;
		for (i=0; i < matriz.length; i++){
			var elemento = new Option();
			elemento.text  = matriz[i][1];
			elemento.value = matriz[i][0];
			if (i==0) {elemento.defaultSelected = true;elemento.Selected = true;}
			aCombo.options[i] = elemento;
		}
		aCombo.selectedIndex = 0;
	}
	else {
		for (i = aCombo.length-1; i>=0; i--)
			aCombo.remove(i);
		for (i=0; i < matriz.length; i++){
			var elemento = document.createElement("OPTION");
			elemento.text = matriz[i][1];
			elemento.value = matriz[i][0];
			aCombo.add(elemento);
		}
	}
}

// Função que retorna o valor dos objetos passados no parâmetro
function retornaValor(o){   
   var sValor = '';   
   switch (o.type){
      case "text" :
         sValor = o.value;
         break;
      case "radio" :
         sValor = ReturnRadioValue(o);
         break;
      case "hidden" :
         sValor = o.value;
         break;
      case "select-one" :
         sValor = ReturnComboValue(o);
         break;
      case "checkbox":
         if(o.checked){
            sValor = o.value;
         }
         break;
      case "password":         
            sValor = o.value;
            break;
      default:               
         sValor = o.value;
         break;
   }
   return sValor;
}
//

function EncontrarObjeto(sNomeObjeto, d){
    if(!d) d=document.forms[0];
    for (var x = 0; x < d.elements.length; x++){
        if (d.elements[x].id.indexOf(sNomeObjeto) != -1 ){         
            return d.elements[x];
        }
    }
}

function rv(NomeObj,d){   
   if(!d) d=document.forms[0];
   for (var x = 0; x < d.elements.length; x++){
      if (d.elements[x].id.indexOf(NomeObj) != -1 ){         
         return retornaValor(d.elements[x]);
      }
   }
}
function recarregarGrid(){
   if (window.opener){
       try {
           f = window.opener.document.forms[0];
           for (x=0;x<f.length;x++){
               if (f[x].id.indexOf('btnPesquisar') > -1){
                   f[x].click();
                   break;
               }
           }
       } catch(e) {}       
   }
}

function ChecaCNPJ(source, objCNPJ) 
{
	var strCNPJ = objCNPJ;
	var NewCNPJ = "";
	var DV = "";
	var DVCNPJ;
	var s1 = 0;
	var s2 = 0;
	var NewDV;
	
	//Verifica tamanho do CNPJ
	if ((strCNPJ.Value.length != 14) || (isNaN(strCNPJ.Value)))
	{
		objCNPJ.IsValid = false;
		return false;
	}
	
	//Calcula os dígitos verificadores
	//Guarda os 12 primeiros digitos
	DVCNPJ = strCNPJ.Value.substring(0,12);
	
	//calcula o primeiro digito verificador
	for (i=1;i<=4;i++)
		s1 = s1 + (parseInt(DVCNPJ.charAt(i-1))*(6-i));

	for (i=5;i<=12;i++)
		s1 = s1 + (parseInt(DVCNPJ.charAt(i-1))*(14-i));
	
	r1 = s1 % 11;
	if (r1 < 2)
		dv1 = 0;
	else 
		dv1 = 11 - r1;
	
	//calcula o segundo digito verificador
	s2 = dv1 * 2;
	
	for (i=1;i<=5;i++)
		s2 = s2 + (parseInt(DVCNPJ.charAt(i-1))*(7-i));
	for (i=6;i<=12;i++)
		s2 = s2 + (parseInt(DVCNPJ.charAt(i-1))*(15-i));
	r2 = s2 % 11;
	if (r2 < 2)
		dv2 = 0;
	else
		dv2 = 11 - r2;
	
	//junta os digitos verificadores
	DV = DV + dv1 + dv2;
	//guarda os digitos verificadores do CNPJ digitado (últimas duas posições no string)
	NewDV = strCNPJ.Value.substring(12,14)
	if (NewDV == DV)
	{ //se o DV calculado for igual ao digitado, retorna true
		objCNPJ.IsValid = true;
		return true
	}
	else
	{
		objCNPJ.IsValid = false;
		return false;
	}
}

/////////////////////////////////////////////////////////////////////////////////
//Verifica se o argumento é um CPF válido
function ChecaCPF (source, objCPF)
{
	var CPF = objCPF;
	var NewCPF = "";
	//Verifica tamanho do CPF

	if (CPF.Value.length!=11) 
	{
		objCPF.IsValid = false;
		return false;
	}

	//Calcula os dÃ­gitos verificadores
	//Guarda os 09 primeiros digitos
	var DVCPF = CPF.Value.substring(0,9);
	var s1 = 0;
	for (i=1;i<=9;i++) s1 = s1 + (parseInt(DVCPF.charAt(i-1))*(11-i));
	r1 = s1 % 11;
	if (r1<2) dv1 = 0;
	else dv1 = 11 - r1;
	var s2 = dv1 * 2;
	for (i=1;i<=9;i++) s2 = s2 + (parseInt(DVCPF.charAt(i-1))*(12-i));
	r2 = s2 % 11;
	if (r2<2) dv2 = 0;
	else dv2 = 11 - r2;
	var DV = "";
	DV = DV + dv1 + dv2;
	var NewDV = CPF.Value.substring(9,11);
	
	if (NewDV==DV) 
	{
		objCPF.IsValid = true
		return true
	}
	else
	{
		objCPF.IsValid = false;
		return false
	}
}
//---------------------

function VerificaEspacoTrim(source, s) {    
   s.IsValid = (s.Value.indexOf(" ") == -1);
}

//PTATextBox id="tbxTexto" textmode="MultiLine" rows="3" runat="server" 
//onkeypress="return checkMaxLength(event,this)" TAMaxLength="200" width="100%" cssclass="tar"
function checkMaxLength(e,el) {
   switch(e.keyCode) {
      case 37:
      return true;
      case 38:
      return true;
      case 40:
      return true;
      case 8:
      return true;
      case 27: //esc
         el.value='';
      return true;
   }
   return (el.value.length < el.getAttribute("TAMaxLength"));
 }
 
function disableCtrlKeyCombination(e)
{
     //list all CTRL + key combinations you want to disable
     var forbiddenKeys = new Array('86', '78', '67'); //ctrl+c, 
     var key;
     var isCtrl;

     if(window.event)
     {
       key = window.event.keyCode; //IE
       if(window.event.ctrlKey)
          isCtrl = true;
       else
          isCtrl = false;
     }
     else
     {
       key = e.which; //firefox
       if(e.ctrlKey)
          isCtrl = true;
       else
          isCtrl = false;
     }

     //if ctrl is pressed check if other key is in forbidenKeys array
     if(isCtrl)
     {
       for(i=0; i<forbiddenKeys.length; i++)
       {
         //case-insensitive comparation
         if(forbiddenKeys[i].toLowerCase() == key)
         {
            window.event.returnValue = false;
         }
       }
     }
     return true;
}

function formataValorSoma(dblValor){
  while (dblValor.indexOf('.') != -1){ 
      dblValor = dblValor.replace('.','');
  } 
  dblValor = parseFloat(dblValor.replace(',','.'));
  return dblValor;
}

function TrimJava(str)
/*Utilizada para tirar brancos de uma string
Parâmetros: Nome da string que poderá ser um campo*/
{               
  var strTrim = new String(str)
  while (strTrim.substr(0,1) == ' ')
  {
     strTrim = strTrim.substr(1,strTrim.length-1);
  }
  while (strTrim.substr(strTrim.length-1,1) == ' ')
  {
     strTrim = strTrim.substr(0,strTrim.length-2);
  }
  return strTrim;
}
function Arredonda(dblNumero, intCasas){
  if ((intCasas < 0) || isNaN(intCasas)) {
     return(dblNumero);
  }
  var intQtde = Math.pow(10,intCasas);        	
  dblNumero = dblNumero * intQtde;        	
  dblNumero = (Math.round(dblNumero)/intQtde);        	
  return(dblNumero);
}
function FormataFloat( dblValor, SepMilhar, SepDecimal, CasasDecimais ){
    var CASA_DECIMAL = CasasDecimais;
    var strInteiro = '';
    var strDecimal = '';
    var strValorFinal = '';
    
    var strValorOriginal = String( Arredonda(dblValor,CASA_DECIMAL) );
    var intPos = 0;
    var intTam = 0;
    var intContador1 = 0;
    var intContador2 = 0;
    var Num1 = '';
    var Num2 = '';
	  
    intPos = strValorOriginal.indexOf('.');
    if( intPos >= 0 )
    {
      strInteiro = strValorOriginal.substring( 0, intPos );
      strDecimal = strValorOriginal.substr( intPos + 1, strValorOriginal.length-1);
    }
    else
    {
      strInteiro = strValorOriginal;
    }
   while ( strDecimal.length < CASA_DECIMAL ) 
    {
      strDecimal = strDecimal + '0';
    }
    intTam = strInteiro.length;
    while ( ( intTam % 3 ) != 0  )
    {
      strInteiro = ' ' + strInteiro;
      intTam = strInteiro.length;
    }
    for ( intContador1 = 1; intContador1 <= ( intTam / 3 ); intContador1++ )
    {
      if( strValorFinal != '' )
      {
         strValorFinal = strValorFinal + SepMilhar;
      }
      strValorFinal = strValorFinal + strInteiro.substr( intContador2, 3 );
      intContador2 = intContador2 + 3;
    }
    if ( strDecimal.length > 0 ) 
    {
      strValorFinal = strValorFinal + SepDecimal + strDecimal;
   }
   return(TrimJava(strValorFinal));
} 

function SetValidatorsAllEnable(bolEnable) {
  for (i=0; i<Page_Validators.length; i++) {
     Page_Validators[i].isvalid = !bolEnable;
  }
}