

function verificaPermissoesMenus(menuAdm, menuDis, menuLic, menuCap, menuNot, menuRelSoc, menuRelCap, menuRelPer, menuAvi, menuLin, menuPer)
{
    //alert('teste');
    
    if(menuAdm == '1')
        document.getElementById('liAdm').style.display = '';
    else
        document.getElementById('liAdm').style.display = 'none';
        
    if(menuDis == '1')
        document.getElementById('liDis').style.display = '';
    else
        document.getElementById('liDis').style.display = 'none';

    if(menuLic == '1')
    {
        document.getElementById('liSol').style.display = '';
        document.getElementById('ulSol').style.display = '';
    }
    else
    {
        document.getElementById('liSol').style.display = 'none';
        document.getElementById('ulSol').style.display = 'none';
    }
    
    if(menuCap == '1')
    {
        document.getElementById('liCap').style.display = '';
        document.getElementById('ulCap').style.display = '';
    }
    else
    {
        document.getElementById('liCap').style.display = 'none';
        document.getElementById('ulCap').style.display = 'none';
    }
    
    if(menuNot == '1')
        document.getElementById('liNot').style.display = '';
    else
        document.getElementById('liNot').style.display = 'none';
        
    if(menuRelSoc == '1' || menuRelCap == '1' || menuRelPer == '1')
    {
        document.getElementById('liRel').style.display = '';
        document.getElementById('ulRel').style.display = '';
    }
    else
    {
        document.getElementById('liRel').style.display = 'none';
        document.getElementById('ulRel').style.display = 'none';
    }
    
    if(menuRelSoc == '1')
        document.getElementById('liRelSol').style.display = '';
    else
        document.getElementById('liRelSol').style.display = 'none';
        
    if(menuRelCap == '1')
        document.getElementById('liRelCap').style.display = '';
    else
        document.getElementById('liRelCap').style.display = 'none';
        
    if(menuRelPer == '1')
        document.getElementById('liRelPer').style.display = '';
    else
        document.getElementById('liRelPer').style.display = 'none';
        
    if(menuAvi == '1')
        document.getElementById('liAvi').style.display = '';
    else
        document.getElementById('liAvi').style.display = 'none';
        
    if(menuLin == '1')
        document.getElementById('liLin').style.display = '';
    else
        document.getElementById('liLin').style.display = 'none';
        
    if(menuPer == '1')
        document.getElementById('liGrupo').style.display = '';
    else
        document.getElementById('liGrupo').style.display = 'none';
}

//TESTE

function replaceAll(string, token, newtoken) {
	while (string.indexOf(token) != -1) {
 		string = string.replace(token, newtoken);
	}
	return string;
}

function ValidaCNPJ(sender, e)
{
    var cnpj, nCNPJ;

    var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
    
    cnpj = e.Value;
    
    //alert('CNPJ antes: ' + cnpj);
    
    //Elimina caracteres que não sejam numéricos
    cnpj = replaceAll(cnpj, '.', '');
    cnpj = replaceAll(cnpj, '/', '');
    cnpj = replaceAll(cnpj, '-', '');
    
    digitos_iguais = 1;
    
    //alert('CNPJ depois: ' + cnpj);
    
    if (cnpj.length < 14 && cnpj.length < 15)
    {
        //alert('INVALIDO: ' + cnpj.length);
        return e.IsValid = false;
    }
    
    for (i = 0; i < cnpj.length - 1; i++)
        if (cnpj.charAt(i) != cnpj.charAt(i + 1))
              {
              digitos_iguais = 0;
              break;
              }
    if (!digitos_iguais)
        {
        tamanho = cnpj.length - 2
        numeros = cnpj.substring(0,tamanho);
        digitos = cnpj.substring(tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(0))
        {
            //alert('INVALIDO 1: ' + resultado + ' != ' + digitos.charAt(0));
            return e.IsValid = false;
        }
        
        tamanho = tamanho + 1;
        numeros = cnpj.substring(0,tamanho);
        soma = 0;
        pos = tamanho - 7;
        for (i = tamanho; i >= 1; i--)
              {
              soma += numeros.charAt(tamanho - i) * pos--;
              if (pos < 2)
                    pos = 9;
              }
        resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
        if (resultado != digitos.charAt(1))
        {
            //alert('INVALIDO 2: ' + resultado + ' != ' + digitos.charAt(1));
            return e.IsValid = false;
        }
        
        return e.IsValid = true;
        }
    else
    {
        //alert('INVALIDO: ' + digitos_iguais);
        return e.IsValid = false;
    }
} 
      
      

//
function ValidaCNPJ_ORIGINAL(sender, e)
{
    var cnpj = e.Value;
    
    alert('cnpj: ' + cnpj);
    
	var nCNPJ = "";
	var cCNPJ = "";
	var strBase = "23456789";
	var intDigito = 0;
	var intPosBase = 0;
	
	//Elimina caracteres que não sejam numéricos
	for( i=0; i<cnpj.length; i++ )
		if( parseInt(cnpj.substr(i,1)) == cnpj.substr(i,1) )	
			nCNPJ += cnpj.substr(i,1);
	
	alert('nCNPJ so Numeros : ' + nCNPJ);
	
	//Verificação inicial
	if( nCNPJ.length != 14 ) 
	{
	    alert('INVALIDO: nCNPJ.length != 14');
		return e.IsValid = false;
	}
	
	//Retira os digitios verificadores
	cCNPJ = nCNPJ.substr(0,12);
	
	//Calcula os 2 digitos verificadores
	for( d=0; d<2; d++ )
	{
		//Calcula o valor para obter um digito
		for( i=cCNPJ.length-1; i>=0; i-- )
		{
			intDigito += parseInt(cCNPJ.substr(i,1) * strBase.substr(intPosBase,1));
			intPosBase = intPosBase < 7 ? intPosBase + 1 : 0;
		}
		intDigito = parseInt(intDigito % 11);
		cCNPJ += intDigito > 2 ? (11 - intDigito) : 0; 
		intPosBase = 0;
		intDigito = 0;
	}
	
	//Comparação final
	if( nCNPJ != cCNPJ )
	{
	    alert('INVALIDO: ' + nCNPJ + ' != ' + cCNPJ);
		return e.IsValid = false;
	}
}

// Início ------------------------------------------------------------------------- 
// Formata o campo CNPJ 
function formataCNPJ(campo, evt) 
{ 
    //99.999.999/9999-99 
    evt = getEvent(evt); 
    var tecla = getKeyCode(evt); 
    
    if (!teclaValida(tecla)) 
    return; 
    vr = campo.value = filtraNumeros(filtraCampo(campo)); 
    tam = vr.length; 
    if (tam <= 2) { 
    campo.value = vr; 
    } 
    if ((tam > 2) && (tam <= 6)) { 
    campo.value = vr.substr(0, tam - 2) + '-' + vr.substr(tam - 2, tam); 
    } 
    if ((tam >= 7) && (tam <= 9)) { 
    campo.value = vr.substr(0, tam - 6) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
    } 
    if ((tam >= 10) && (tam <= 12)) { 
    campo.value = vr.substr(0, tam - 9) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
    } 
    if ((tam >= 13) && (tam <= 14)) { 
    campo.value = vr.substr(0, tam - 12) + '.' + vr.substr(tam - 12, 3) + '.' + vr.substr(tam - 9, 3) + '/' + vr.substr(tam - 6, 4) + '-' + vr.substr(tam - 2, tam); 
    } 
    if ((tam >= 15) && (tam <= 17)) { 
    campo.value = vr.substr(0, tam - 14) + '.' + vr.substr(tam - 14, 3) + '.' + vr.substr(tam - 11, 3) + '.' + vr.substr(tam - 8, 3) + '.' + vr.substr(tam - 5, 3) + '-' + vr.substr(tam - 2, tam); 
    } 
} 

//recupera tecla 
//evita criar mascara quando as teclas são pressionadas 
function teclaValida(tecla) 
{ 
    if (tecla == 8 //backspace 
    || tecla == 45 //insert 
    || tecla == 46 //delete 
    || tecla == 36 //home 
    || tecla == 37 //esquerda 
    || tecla == 38 //cima 
    || tecla == 39 //direita 
    || tecla == 40)//baixo 
    return false; 
    else 
    return true; 
} 

// recupera o evento do form 
function getEvent(evt) 
{ 
    if (!evt) evt = window.event; //IE 
    return evt; 
    } 
    //Recupera o código da tecla que foi pressionado 
    function getKeyCode(evt) { 
    var code; 
    if (typeof (evt.keyCode) == 'number') 
    code = evt.keyCode; 
    else if (typeof (evt.which) == 'number') 
    code = evt.which; 
    else if (typeof (evt.charCode) == 'number') 
    code = evt.charCode; 
    else 
    return 0; 
    return code; 
}

// limpa todos caracteres que não são números 
function filtraNumeros(campo) 
{ 
    var s = ""; 
    var cp = ""; 
    vr = campo; 
    tam = vr.length; 
    for (i = 0; i < tam; i++) { 
    if (vr.substring(i, i + 1) == "0" || 
    vr.substring(i, i + 1) == "1" || 
    vr.substring(i, i + 1) == "2" || 
    vr.substring(i, i + 1) == "3" || 
    vr.substring(i, i + 1) == "4" || 
    vr.substring(i, i + 1) == "5" || 
    vr.substring(i, i + 1) == "6" || 
    vr.substring(i, i + 1) == "7" || 
    vr.substring(i, i + 1) == "8" || 
    vr.substring(i, i + 1) == "9") { 
    s = s + vr.substring(i, i + 1); 
    } 
    } 
    return s; 
} 

// limpa todos os caracteres especiais do campo solicitado 
function filtraCampo(campo)
{ 
    var s = ""; 
    var cp = ""; 
    vr = campo.value; 
    tam = vr.length; 
    for (i = 0; i < tam; i++) { 
    if (vr.substring(i, i + 1) != "/" 
    && vr.substring(i, i + 1) != "-" 
    && vr.substring(i, i + 1) != "." 
    && vr.substring(i, i + 1) != ":" 
    && vr.substring(i, i + 1) != ",") { 
    s = s + vr.substring(i, i + 1); 
    } 
    } 
    return s;
} 


// Fim ------------------------------------------------------------------------- 




function ValidaDataDigitada(source, args, p_obj, p_span)
{
    var obj = document.getElementById(p_obj);
    var span = document.getElementById(p_span);

    re = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    
    if(obj.value == '')
    {
        span.innerHTML = 'Preencha a Data!';
        args.IsValid = false;
        return;
    }
    else
    {
        if ( re.exec(obj.value) != null )
        {
            var str1  = obj.value;
           
           var dt1   = parseInt(str1.substring(0,2),10); 
           var mon1  = parseInt(str1.substring(3,5),10)-1;
           var yr1   = parseInt(str1.substring(6,10),10); 
           
           var date1 = new Date(yr1, mon1, dt1); 
           var date2 = new Date(); 
           
           if( (date1 > date2) )
           {
              span.innerHTML = 'Data deve ser inferior a Hoje!';
                args.IsValid = false;
                return;
           } 
           
            args.IsValid = true;
            return;
        }
        else
        {
            span.innerHTML = 'Data Inválida!';
            args.IsValid = false;
            return;
        }
    }
}

function ValidaMascara(src, validator, maxLength)
{
    if(src.value.length == maxLength || src.value.length == 0)
    {
        validator.style.display = "none";
        validator.isValid = true;
    }
    else
    {
        validator.style.display = "inline";
        validator.isValid = false;
    }
}

function FormataCNPJ(Campo, teclapres){

var tecla = teclapres.keyCode;

var vr = new String(Campo.value);

vr = vr.replace(".", "");

vr = vr.replace(".", "");

vr = vr.replace("/", "");

vr = vr.replace("-", "");

tam = vr.length + 1 ;

if (tecla != 9 && tecla !=8){

if (tam > 2 && tam < 6)

Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);

if (tam >= 6 && tam < 9)

Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);

if (tam >= 9 && tam < 13)

Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);

if (tam >= 13 && tam < 15)

Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);

}

} 

function RodarFlash(path,variaveis,_width,_height)
{
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+_width+'" height="'+_height+'">')
		document.write('<param name="movie" value="'+path+'?'+variaveis+'">')
		document.write('<param name="quality" value="high">')
		document.write('<param name="wmode" value="transparent">')
		document.write('<embed src="'+path+'?'+variaveis+'" width="'+_width+'" height="'+_height+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>')
	document.write('</object>')
}
//====================================================================================================
//Formatar CEP
//====================================================================================================
function FormatarCEP(Campo)//onKeyUp
{
   var vr = new String(Campo.value);
   vr = vr.substr(0, 9);
   vr = vr.replace("-", "");

   tam = vr.length + 1 ;

  if (tam > 3 && tam < 6)
	 Campo.value = vr.substr(0,tam);
  if (tam >= 6 && tam < 9)
	 Campo.value = vr.substr(0,5) + '-' + vr.substr(5,tam-5);
};
//====================================================================================================


//====================================================================================================
//Formatar Data
//====================================================================================================
function FormatarData(Campo)//onKeyUp
{
   var vr = new String(Campo.value);
   vr = vr.substr(0, 10);
   vr = vr.replace("/", "");
   vr = vr.replace("/", "");

   tam = vr.length + 1 ;

  if (tam > 2 && tam < 3)
	 Campo.value = vr.substr(0,tam);
  if (tam >= 3 && tam < 5)
	 Campo.value = vr.substr(0,2) + '/' + vr.substr(2,tam-2);
  if (tam >= 5 && tam < 9)
	 Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam-4);
}
//====================================================================================================
// Somente Numérico
//====================================================================================================
function SomenteNumerico()//onKeyDown
{
	if(window.event.srcElement.readOnly) return false;
	if(window.event.srcElement.value.length > window.event.srcElement.maxLength) return false;

	//alert("down: " + String.fromCharCode(window.event.keyCode) + "|" + window.event.keyCode + "|" + window.event.srcElement.name)
	var keyCode = window.event.keyCode;  
	var oElement = window.event.srcElement;
	
	// teclas de controle
	if (( keyCode == null) || (keyCode == 0) || (keyCode == 8) || (keyCode == 9) || (keyCode == 13) || (keyCode == 27) || (keyCode > 34 && keyCode < 41) || (keyCode == 45) || (keyCode == 46))
		window.event.returnValue = true;

	// validação somente para numéricos
	else if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey)
	{
		if ((keyCode > 47 && keyCode < 58) || (keyCode > 95 && keyCode < 106))
		{
			if (keyCode > 95)
			{
				keyCode -= (95-47);
			}
		
			window.event.returnValue = true;
		}
		else
		{
			window.event.returnValue = false;
		}
	}

	// qualquer outra tecla
	else
	{
		window.event.returnValue = false;
	}
}
//====================================================================================================
// Somente Alfanumérico
//====================================================================================================
function SomenteAlfaNumerico()//onKeyDown
{
	if(window.event.srcElement.readOnly) return false;
	if(window.event.srcElement.value.length > window.event.srcElement.maxLength) return false;

	//alert("down: " + String.fromCharCode(window.event.keyCode) + "|" + window.event.keyCode + "|" + window.event.srcElement.name)
	var keyCode = window.event.keyCode;  
	var oElement = window.event.srcElement;
	
	// teclas de controle
	if (( keyCode == null) || (keyCode == 0) || (keyCode == 8) || (keyCode == 9) || (keyCode == 13) || (keyCode == 27) || (keyCode > 34 && keyCode < 41) || (keyCode == 45) || (keyCode == 46))
		window.event.returnValue = true;

	// validação somente para numéricos
	else if (!window.event.shiftKey && !window.event.ctrlKey && !window.event.altKey)
	{
		if ((keyCode > 47 && keyCode < 58) || (keyCode > 64 && keyCode < 91) || (keyCode > 96 && keyCode < 123))
		{
			window.event.returnValue = true;
		}
		else
		{
			window.event.returnValue = false;
		}
	}

	// qualquer outra tecla
	else
	{
		window.event.returnValue = false;
	}
}
//------------------------------------------------------
// 	Formata TELEFONE
//	Rodrigo S. Brito (05/07/2006)
//------------------------------------------------------
function FormataTelefone(Campo) 
{
	   var vr = new String(Campo.value);
	   vr = vr.substr(0,14);
	   vr = vr.replace("-", "");
	   
	   var aux1;
	   var aux2;	
		
	   tam = vr.length + 1 ;
	
	  if(tam == 1)
		Campo.value = '(' + vr.substr(0,1);
	  
	  if(tam == 4)
		Campo.value = vr.substr(0,3) + ') ';

	  if(tam > 9 & tam < 15)
	  {
		aux1 = vr.substr(0,9);
		aux2 = vr.substr(9,tam-9);
		Campo.value = aux1 + '-' + aux2;
	  }

}

function isData(data)
{
	if ((data == null) || (data.length < 10) || data.substring(2,3) != '/' || data.substring(5,6) != '/' )
		return false;
	
	var jsDia = data.substring(0,2)-0;
	var jsMes = data.substring(3,5)-1;
	var jsAno = data.substring(6,10)-0;
	var oData = new Date(jsAno, jsMes, jsDia);
	
	if(jsDia != oData.getDate())
		return false;
	
	if(jsMes != oData.getMonth())
		return false;
	
	if (jsAno != oData.getFullYear())
		return false;
	
	if (jsAno < 1900)
		return false;
		
	if(data.length > 10)
	{
        if (data.substring(11,13) < 00 || data.substring(11,13) > 23)	
            return false;
            
        if (data.substring(14,16) < 00 || data.substring(14,16) > 59)	
            return false;
	}
	return true;
}

function isDataAtual(data)
{
	if ((data == null) || (data.length < 10) || data.substring(2,3) != '/' || data.substring(5,6) != '/' )
		return false;
	
	var jsDia = data.substring(0,2)-0;
	var jsMes = data.substring(3,5)-1;
	var jsAno = data.substring(6,10)-0;
	var oData = new Date(jsAno, jsMes, jsDia);
	
	if(jsDia != oData.getDate())
		return false;
	
	if(jsMes != oData.getMonth())
		return false;
	
	if (jsAno != oData.getFullYear())
		return false;
	
	if (jsAno < 1900)
		return false;
		
	if(data.length > 10)
	{
        if (data.substring(11,13) < 00 || data.substring(11,13) > 23)	
            return false;
            
        if (data.substring(14,16) < 00 || data.substring(14,16) > 59)	
            return false;
	}
	
	var dttAtual = new Date();
	var dtDiaAtual = dttAtual.getDate();
	var dtMesAtual = dttAtual.getMonth();
	var dtAnoAtual = dttAtual.getFullYear();
	
	var agora = new Date(dtAnoAtual, dtMesAtual, dtDiaAtual);
	
	if (agora > oData)
    {
        return false;
    }
        
        
	return true;
}

function ValidarData(Campo) //onBlur
{
	if(Campo.value.length > 0)
		if(!isData(Campo.value))
		{
			alert("Data Invalida.");
			Campo.value = "";
			Campo.focus();
		}
}

function CustomValidarData(scr, args)
{
	if(args.Value.length == 0)
	{
	    args.IsValid = false;
        return;
	}

	if(!isData(args.Value))
	{
		args.IsValid = false;
        return;
	}
	
	args.IsValid = true;
	
}

function CustomValidarDataAtual(scr, args)
{
	if(args.Value.length == 0)
	{
	    args.IsValid = false;
        return;
	}

	if(!isDataAtual(args.Value))
	{
		args.IsValid = false;
        return;
	}
	
	args.IsValid = true;
	
}

function ValidarDataHora(Campo) //onBlur
{
	if(Campo.value.length > 0)
		if(!isData(Campo.value) || Campo.value.length != 16)
		{
			alert("Data inválida.");
			Campo.value = "";
			Campo.focus();
		}
}

function FtrataBackSpace(dado)
{
   NumDig = dado.value;
   TamDig = NumDig.length;
   TamDig--;
   Contador = 0;

   if ((TamDig >= 0) && (event.keyCode == 8))
    { numer = "";
      for (i = TamDig; (i >= 0); i--){
          if ((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
            {
             Contador++;
			 /*alert(NumDig.substr(i, 1) + " Contador " + Contador+ " numer "+ numer+ " TamDig " +TamDig + " i " + i );*/
             if ((Contador == 4) && ((TamDig -i) < 5))
              {numer = ","+numer;
               Contador = 0;
               }
             else if ((Contador == 3) && ((numer.length) > 4))  
              {numer = numer;
               Contador = 0;
              }
			  
             numer = NumDig.substr(i, 1)+numer;
			
            }
			}
			if (numer == "001" || numer == "000" || numer == "002" || numer == "003" || numer == "004" || numer == "005" || numer == "006" || numer == "007" || numer == "008" || numer == "009") 
			    numer="";		
			if ((numer.length) == 3 )
			    numer= "0," + numer;

		dado.value = numer;
      };

}

function TiraZerosEsquerda(dado) 
{
   NumDig = dado.value;
   PosVirg = NumDig.indexOf(",");
   if (NumDig.charAt(0) == "0" && PosVirg != 1) {
   for (var i = 0; i < PosVirg - 1; i = i + 1) {
	  if (NumDig.charAt(i) == "0" || NumDig.charAt(i) == ".") {
		 numer = NumDig.substring(i+1, NumDig.length);
	  }
	  else {
		 numer = NumDig.substring(i, NumDig.length);
		 break;
	  }   
   }
   }
   else numer = NumDig;
   dado.value = numer;
}
//Função Obsoleta (Favor Utilizar FormataValor())
/////////////////////////////////////////////////
function FormatarValorCurrency(ConteudoCampo) 
{
    if(ConteudoCampo.value.length < 12)
    { 
        if (((event.keyCode) > 47) && ((event.keyCode) < 58))
        { 
            NumDig = ConteudoCampo.value; TamDig = NumDig.length; Contador = 0; 
            if (TamDig > 1) { numer = ''; 
                for (i = TamDig; (i >= 0); i--) 
                    { 
                        if((parseInt(NumDig.substr(i,1))>=0) && (parseInt(NumDig.substr(i, 1))<=9))
                        { Contador++; 
                            if ((Contador == 2) && ((TamDig -i) < 4)) 
                            {
                                numer = ','+numer; 
                                Contador = 0;
                             } 
                             else if (Contador == 3) 
                             {
                                numer = numer; 
                                Contador = 0;
                             } 
                             numer = NumDig.substr(i, 1)+numer;
                          }
                       } 
                       ConteudoCampo.value = numer;
                   }; 
            return(true)
       } 
     else 
    return(false)
  }
}
/////////////////////////////////////////////////

function fWindowOpen(pagina,nome,largura,altura,scroll)
{
		window.open(pagina,nome,'toolbar=no,scrollbars='+scroll+',resizable=no,location=no,directories=no,status=yes,menubar=no,width='+largura+',height='+altura+',left=20,top=100');
}
	
function FechaJanela()
{
	window.close();
}

function RecarregarPaginaPai()
{
    //window.opener.document.forms[0].ctl00_ContentPlaceHolder1_hndAtualiza.value = "X";
    window.opener.document.forms[0].submit();
}

function RecarregarPaginaPaiDoPostBack()
{
    window.opener.__doPostBack('null', 'null');
}

//Formata Valores Monetarios
function FormataValor(campo) {
	var tecla = event.keyCode;
	vr = document.all[campo.id].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.all[campo.id].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	}
		
}

//Formata Valores de Porcentagem
function FormataPorcentagem(campo) {
	var tecla = event.keyCode;
	vr = document.all[campo.id].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;
    


	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.all[campo.id].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.all[campo.id].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	}

}

function LimparSelecao(strTagName,strID){
    Tag = document.getElementsByTagName(strTagName);

    for (i = 0; i < Tag.length; i++){
        if (Tag[i].type == strID){
            if (Tag[i].checked){
                if (confirm("Deseja mesmo limpar a seleção?")){
                    Tag[i].checked = false;
                }
            }
        }
    }   
}

function MascaraGeral(src,mask){
    var i       = src.value.length;
    var saida   = mask.substring(0,1);
    var texto   = mask.substring(i)
    
    if(texto.substring(0,1) != saida){
        src.value += texto.substring(0,1);
    }
}

function validaMascara(src, args)
{
     args.IsValid = (args.Value.length == src.MaxLength);
}

function ValidateFile(source, args)
{
    try
    {
        var fileAndPath         = document.getElementById(source.controltovalidate).value;
        var lastPathDelimiter   = fileAndPath.lastIndexOf("\\");
        var fileNameOnly        = fileAndPath.substring(lastPathDelimiter+1);
        var file_extDelimiter   = fileNameOnly.lastIndexOf(".");
        var file_ext            = fileNameOnly.substring(file_extDelimiter+1).toLowerCase();
        
        if(file_ext != "jpg")
        {
            args.IsValid = false;
            
            if(file_ext != "gif")
            {
                args.IsValid = false;
            
                if(file_ext != "png")
                {
                    args.IsValid = false;
                    return;
                }
            }
        }
    }
    catch(err)
    {
        txt =   "There was an error on this page.\n\n";
        txt +=  "Error description: " + err.description + "\n\n";
        txt +=  "Click OK to continue.\n\n";
        txt +=  document.getElementById(source.controltovalidate).value;
        alert(txt);
    }
    
    args.IsValid = true;
}



function CarregarDescarregarImagem(strIDColuna, strIDFileUpload, strIDCustomValidator, strIDImage)
{
    if(document.getElementById(strIDCustomValidator).style.display == "none")
    {
        document.getElementById(strIDColuna).style.visibility   = "visible";
        document.getElementById(strIDImage).src                 = strIDFileUpload;
    }
    else
    {
        document.getElementById(strIDColuna).style.visibility   = "hidden";
        document.getElementById(strIDImage).src                 = "";
    }
    
}

function AjustaImagem(obj, intWidthMax, intHeightMax)
{
    if(obj.width > intWidthMax){
        obj.width = intWidthMax
    }
    
    if(obj.height > intHeightMax){
        obj.height = intHeightMax
    }
}


function AbrirPopUp(pagina,nome,largura,altura,scroll, status)
{
    var intLeft = ((screen.availWidth/2)-(largura/2));
    var intTop = ((screen.availHeight/2)-(altura/2))-20;
    
	window.open(pagina,nome,'toolbar=no,scrollbars='+scroll+',resizable=no,location=no,directories=no,status='+status+',menubar=no,width='+largura+',height='+altura+',left='+intLeft+',top='+intTop+'');
}

function AbrirPopUpResize(pagina,nome,largura,altura,scroll, status)
{
    var intLeft = ((screen.availWidth/2)-(largura/2));
    var intTop = ((screen.availHeight/2)-(altura/2))-20;
    
	window.open(pagina,nome,'toolbar=no,scrollbars='+scroll+',resizable=yes,location=no,directories=no,status='+status+',menubar=no,width='+largura+',height='+altura+',left='+intLeft+',top='+intTop+'');
}


//Funcao para retornar valor de acordo com a mascara informada
//Exemplo: Para ver "(11) 5090-1000" utilize OnKeyPress=Mascara(this, "(__) ____-____");
var fmLenAnterior = 0;
function Mascara(obj, strMascara)
{
	var i = 0;
	while( strMascara.substr(obj.value.length, 1) != "_" && ( obj.value.length > fmLenAnterior || obj.value.length == 0 ) && i < 5 ) 
	{
		obj.value += strMascara.substr(obj.value.length, 1);
		i++;
	}
	fmLenAnterior = obj.value.length
}


function ValidaHora(scr, args)
{ 
    if (args.Value == "")
    { 
       args.IsValid = false;
       return; 
    }
    
    hrs = (args.Value.substring(0,2)); 
    min = (args.Value.substring(3,5)); 
                    
    if ((hrs < 00 ) || (hrs > 23) || ( min < 00) ||( min > 59))
    { 
        args.IsValid = false;
        return; 
    }
    
    args.IsValid = true;           
    
} 


function TopoDiv()
{
	if( document.getElementById("dvConteudo") )
		document.getElementById("dvConteudo").scrollTop = 0;
}

function VerificaErros_TopoDiv()
{
		TopoDiv();
}


function voltar()
{
    history.back();
}

function PrintElementID(id, pg) {
	var oPrint, oJan;
	
	window.document.getElementById("printContent").innerHTML = "<div class='printCopiedContent' style='padding:10px; font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#333'>" + window.document.getElementById(id).innerHTML + "</div>";
	//$("#printContent .tbl_legenda").attr("style","display:none");
	//$("#printContent .icons").attr("style","display:none");
	//$("#printContent table tr td").attr("style","font-size:12px; color:#333;");
	oPrint  = window.document.getElementById("printContent").innerHTML;
	oJan    = window.open(pg,null,'width=800,height=600,scrollbars=yes,resize=yes');
	oJan.document.write("<link href='../css/css.css' rel='stylesheet' type='text/css' media='screen'/>" + oPrint);
	oJan.history.go();
	oJan.window.print();
}
