function clickAll(cont){
    for (i=0;i<=cont-1;i++)
    {
        var objDivMsgErro = document.getElementById('ctl00_conteudo_msgErro');
        objDivMsgErro.style.display = 'none';
        
        var objmarcar = document.getElementById('ctl00_conteudo_chk'+i);
        var objdesmarcar = document.getElementById('Checkbox1');
        
        if (objdesmarcar.checked == true)
            objmarcar.checked = true
        else
            objmarcar.checked = false;
    }
}

// --------------------------------------------------------------------*

function mostraTabBen(){
        var objRadioNao = document.getElementById('ctl00_conteudo_RadioNao');
        var objDivBen = document.getElementById('ctl00_conteudo_DivBeneficio');
        var objDivMsgErro2 = document.getElementById('ctl00_conteudo_msgErro2');
        var objDivMsgErro = document.getElementById('ctl00_conteudo_msgErro');
        if (objRadioNao.checked == true){
            objDivBen.style.display = 'none';
            objDivMsgErro.style.display = 'none';
            objDivMsgErro2.style.display = 'none';
        }
        else
            objDivBen.style.display = 'block';
}
// ------------------------------------------------------------------


function DesmarcaAll(obj){
        var objDivMsgErro = document.getElementById('ctl00_conteudo_msgErro');
        objDivMsgErro.style.display = 'none';
        var objCheckAll = document.getElementById('Checkbox1');
        if (obj.checked == false){
            objCheckAll.checked = false;
        }
}

function TestaCNPJ(cgc) 
{
    var CGC1, CGC2, Matriz; 
    var Soma, Digito;
    var i , j; 
    var ContIni , ContFim;
    var controle;
	cgc  = RetiraCaracteresInvalidos(cgc,14);
	if  (cgc == "00000000000000") 
		return false;	 
    CGC1 = cgc.substring(0,12);
    CGC2 = cgc.substring(12,14);
    controle = "";
    ContIni = 1;
    ContFim = 12;
    K = 0;
    for (j = 1; j <= 2; j++)
    {
	Soma = 0;
        	for (i = ContIni; i <=ContFim; i++)
	{
		Mult = (ContFim + 1 + j - i);
		 if (Mult > 9) Mult = Mult - 8;
          		 Soma = Soma + (parseInt(CGC1.substring(i - j, i-K)) * Mult);
        	}
        	 if (j == 2) Soma = Soma + (2 * Digito);
	 			Digito = (Soma * 10) % 11;
       	 if (Digito == 10) Digito = 0;
        	 controle = controle + Digito;
         	 ContIni = 2;
	 K=1;
        	 ContFim = 13;
      } 
      if (controle != CGC2) return false; return true;
}

// --------------------------------------------------------------------*

function RetiraCaracteresInvalidos(strCampo,tam)
{
	nTamanho = strCampo.length;
	szCampo = "";
	j=0;
	
	if (nTamanho=="")
		return szCampo;
	
	for (i = nTamanho-1;i>=0;i--) 
	{
		if (isDigit(strCampo.charAt(i)))	{
			szCampo = strCampo.charAt(i) + szCampo;
			j++;
			if (j > tam) break;
		}
	}
	if (szCampo.length < tam) {
		for (i = szCampo.length;i<tam;i++) 
		{
			szCampo = "0" + szCampo;
		}
	}
    return szCampo;
}

// -------------------------------------------------------------------

function isDigit (c)
{     
   return ((c >= "0") && (c <= "9"))
}  


// -------------------------------------------------------------------


 function formataCNPJ(cnpj) {
    var cnpjFormatado = "";
    if (cnpj.length > 0) {
     cnpjFormatado = RetiraCaracteresInvalidos(cnpj,14);
     cnpjFormatado = cnpjFormatado.substring(0,2) + "."
                 + cnpjFormatado.substring(2,5) + "."
                 + cnpjFormatado.substring(5,8) + "/"
                 + cnpjFormatado.substring(8,12)+ "-"
                 + cnpjFormatado.substring(12,14);
    }
    
    return cnpjFormatado;
  }
  
 // -------------------------------------------------------------------
  
 function EditaData(dt)
 {
    var dtAtual = dt;
    dtAtual = dtAtual.replace("/", "");
    dtAtual = dtAtual.replace("/", "");
    
    var tam = dtAtual.length;
    var saida = null;

    if (tam <= 2) 
    {
        dt = dtAtual;
    }

    else if (tam <= 4) {
        dt = dtAtual.substr(0, 2) + "/" + dtAtual.substr(2);
    }
    else if (tam <= 8) {
        dt = dtAtual.substr(0, 2) + "/" + dtAtual.substr(2,2) + "/" + dtAtual.substr(4);
    }
    return dt;
}

// -------------------------------------------------------------------

function validarData (dt) {

  	var d, dia, mes, ano ;
  	
  	var dataInformada = dt;
  	
  	dia = dt.substr(0, 2);
  	mes = dt.substr(3, 2);
	ano = dt.substr(6, 4);

    var intAno = parseFloat(ano);
    var intMes = parseFloat(mes);
    var intDia = parseFloat(dia);
	   
    if (isEmpty(ano) && isEmpty(mes) && isEmpty(dia)) 
    {
        alert("Data invalida - Formato DDMMAAAA");
        return dt;
    }

    if (!(isAno(ano) && isMes(mes) && isDia(dia))) 
    {
        alert("Data invalida - Formato DDMMAAAA");
        return dt;
    }

    dias = new Array(13);
    dias[1] = 31;
    if (((intAno % 4) == 0 && (intAno % 100) !=0) || (intAno % 400) == 0)
    	dias[2] = 29;   // must programmatically check this
	 else
	    dias[2] = 28;

    dias[3] = 31;
    dias[4] = 30;
    dias[5] = 31;
    dias[6] = 30;
    dias[7] = 31;
    dias[8] = 31;
    dias[9] = 30;
    dias[10] = 31;
    dias[11] = 30;
    dias[12] = 31;
	
    if (intDia > dias[intMes]) 
    {
        alert("Data invalida - Formato DDMMAAAA");
        return dt;
    } 

    if ((intMes == 2) && (intDia > diasInFevereiro(intAno)))
    {
        alert("Data invalida - Formato DDMMAAAA");
        return dt;
    }

  	return dt;
}

 // ------------------------------------------------------------------- 
 
function isAno (s) {

    if (isEmpty(s)) return false;
    if (!isInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4));
}

 // ------------------------------------------------------------------- 
 
function isMes (s) {
   if (isEmpty(s)) return false;
   return isIntegerInRange (s, 1, 12);
}

// ------------------------------------------------------------------- 
 
function isDia (s) {

    if (isEmpty(s)) return false;
    return isIntegerInRange (s, 1, 31);
}

// ------------------------------------------------------------------- 
 
function diasInFevereiro (ano){

    return (  ((ano % 4 == 0) && ( (!(ano % 100 == 0)) || (ano % 400 == 0) ) ) ? 29 : 28 );
}

// ------------------------------------------------------------------- 
 
function isEmpty(s)
   {
    return ((s == null) || (s.length == 0))
   }
   
   function isInteger (s) {

    var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return false;
     
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (!isDigit(c)) return false;
    }
    return true;
}

// ------------------------------------------------------------------- 

function isIntegerInRange (s, a, b)
{    
   if (isEmpty(s)) return false;

    if (!isInteger(s)) return false;

    var num = (s);
    
    return ((num >= a) && (num <= b));
}

//---------------------------------------------------------------------
function TrataTeclaNum( obj , e )
{
    var tecla = ( window.event ) ? e.keyCode : e.which;
   
    if ( tecla == 8 || tecla == 0 ){
        return true;
    }
    else {
        if ( tecla < 48 || tecla > 57 ){
            return false;
        }
        else {
            return true;
        }
    }
    
}

function LimpaMsg (Texto){
    var divMsgErro = document.getElementById('ctl00_conteudo_divMsgErro');
    if(Texto.length < 1){
        divMsgErro.style.display = 'none';
        return true;
    }
    return true;
}

function AbreManual(){
    window.open('pdf/Manual_do_PGMEI_06_06_2011.pdf','_blank')
}
