﻿function clearall(checkBoxListId, chk)
{
    objCtrl = document.getElementById(checkBoxListId);
    
    if(objCtrl == null)
    {
        return;
    }

    var i = 0;
    var objItem = null;


    
    for(i = 0; document.getElementById(checkBoxListId + '_' + i) != null; i++)
    {
        objItem = document.getElementById(checkBoxListId + '_' + i);

     if(i!=chk)
             objItem.checked = false;
    }
}

function FormataCNPJ(Campo, teclapres)
{

    
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    { 
        if(window.event)
        {
            var tecla = teclapres.keyCode;
        }
        else  tecla = teclapres.which;

       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);
      }
   }
   else 
        window.event.keyCode = 0; 
}

function FormataIE(Campo, teclapres)
{

    
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    { 
        if(window.event)
        {
            var tecla = teclapres.keyCode;
        }
        else  tecla = teclapres.which;

       var vr = new String(Campo.value);
       vr = vr.replace(".", "");
       vr = vr.replace(".", "");
       vr = vr.replace(".", "");

       tam = vr.length + 1;

   
       if (tecla != 9 && tecla != 8)
       {
          if (tam > 3 && tam < 7)
            Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
          if (tam >= 7 && tam < 10)
            Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
          if (tam >= 10 && tam < 13)
            Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '.' + vr.substr(9,tam-9);
      }
   }
   else 
        window.event.keyCode = 0; 
}

function FormataCCM(Campo, teclapres)
{

    
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    { 
        if(window.event)
        {
            var tecla = teclapres.keyCode;
        }
        else  tecla = teclapres.which;

       var vr = new String(Campo.value);
       vr = vr.replace(".", "");
       vr = vr.replace(".", "");
       vr = vr.replace("-", "");

       tam = vr.length + 1;

   
       if (tecla != 9 && tecla != 8)
       {
          if (tam > 1 && tam < 4)
            Campo.value = vr.substr(0, 1) + '.' + vr.substr(1, tam);
          if (tam >= 5 && tam < 7)
            Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,tam-4);
          if (tam >= 8 && tam < 10)
            Campo.value = vr.substr(0,1) + '.' + vr.substr(1,3) + '.' + vr.substr(4,3) + '-' + vr.substr(7,tam-7);
      }
   }
   else 
        window.event.keyCode = 0; 
}



function Mascaras(formato, objeto)
{ 
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    { 
        var campo = document.getElementById(objeto); 

        if (formato == 'DATA')
        { 
            separador = '/'; 
            conjunto1 = 2; 
            conjunto2 = 5; 
            
            if (campo.value.length == conjunto1) 
                campo.value = campo.value + separador; 

            if (campo.value.length == conjunto2) 
                campo.value = campo.value + separador; 
        } 
        
        if (formato == 'HORA')
        { 
            separador = ':'; 
            conjunto1 = 2; 
            if (campo.value.length == conjunto1) 
                campo.value = campo.value + separador; 
        } 

        if (formato == 'CEP')
        { 
            separador = '-'; 
            conjunto1 = 5; 
            if (campo.value.length == conjunto1) 
                campo.value = campo.value + separador; 
        } 

        if (formato == 'CPF')
        { 
            separador = '.'; 
            separador1 = '-'; 
            conjunto1 = 3; 
            conjunto2 = 7; 
            conjunto3 = 11; 
            
            if (campo.value.length == conjunto1) 
                campo.value = campo.value + separador; 

            if (campo.value.length == conjunto2) 
                campo.value = campo.value + separador; 

            if (campo.value.length == conjunto3) 
                campo.value = campo.value + separador1; 
        } 
        
        if (formato == 'MOEDA')
        { 
            campo.value = campo.value.replace(",", "");
            if (campo.value.length > 1) 
            {
//                if(campo.value.length == 8)
//                    campo.value = campo.value.substr(0,campo.value.length-2) + ',' + campo.value.substr(campo.value.length-2,campo.value.length)
//                else
                    campo.value = campo.value.substr(0,campo.value.length-1) + ',' + campo.value.substr(campo.value.length-1,campo.value.length)
            }
            
        }
    }
    else 
        window.event.keyCode = 0; 
} 


function MascaraTelefone(e,obj)
{
	var key = '';
	var strCheck = '0123456789';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	key = String.fromCharCode(whichCode);
	if (strCheck.indexOf(key) == -1) 
		return false; 
	
	else
	{
		switch (obj.value.length)
		{
	    	case 1:
    	    	obj.value = "(" + obj.value;
        		break;
		    case 3:	
		        obj.value = obj.value + ") ";
    		    break;    
		    case 9:
    		    obj.value = obj.value + "-";
	    	    break;    
	    	/*case 14:
    	    	document.getElementById("telefone1").focus();
        		break;*/

		}
	}
}

function FormataCNPJ(Campo, teclapres){
    if (window.event.keyCode >= 48 && window.event.keyCode <= 57)
    { 

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   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);
      }
    }
    else 
        window.event.keyCode = 0; 
}

function apenasNum(e)
{
	var key = '';
	var strCheck = '0123456789,';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13 || whichCode == 8)  
		return true;
	key = String.fromCharCode(whichCode);  // Valor para o c?digo da Chave
	if (strCheck.indexOf(key) == -1) 
		return false;  // Chave inv?lida
}

