function descobre(T){
	tamanho = T.value.length;
	//alert(tamanho);
	if( tamanho != 0 && tamanho < 11 ){
	alert( "CPF ou CNPJ inválido" )
	T.focus();
	T.style.color = "red";
	T.select();
	return false;
	}
	if( tamanho != 0 && tamanho > 19 ){
	alert( "CPF ou CNPJ inválido" )
	T.focus();
	T.style.color = "red";
	T.select();
	
	return false;
	}

if( tamanho > 10 && tamanho < 15 ){
checa_cpf(T.value, T);
	return false;
}
if( tamanho > 14 ){
 TESTA(T)}
	return false;
}


function isNUMB(c) 
{ 
	 if((cx=c.indexOf(","))!=-1) 
	  { 
	  c = c.substring(0,cx)+"."+c.substring(cx+1); 
	  } 
	 if((parseFloat(c) / c != 1)) 
	  { 
	  if(parseFloat(c) * c == 0) 
		   { 
		   return(1); 
		   } 
			else 
	 		 	{ 
  		 		return(0); 
				} 
	  } 
	  else 
		{ 
		return(1); 
		} 
} 

function LIMP(c) 
{ 
		while((cx=c.indexOf("-"))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf("/"))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf(","))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf("."))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf("("))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf(")"))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
		while((cx=c.indexOf(" "))!=-1) 
		{ 
		c = c.substring(0,cx)+c.substring(cx+1); 
		} 
	return(c); 
} 

function VerifyCNPJ(CNPJ) 
{ 
	CNPJ = LIMP(CNPJ); 
	if(isNUMB(CNPJ) != 1) 
	{ 
	return(0); 
	} 
	else 
		{ 
		if(CNPJ == 0) 
			{ 
			return(0); 
			} 
			else 
				{ 
				g=CNPJ.length-2; 
				if(RealTestaCNPJ(CNPJ,g) == 1) 
					{ 
					g=CNPJ.length-1; 
					if(RealTestaCNPJ(CNPJ,g) == 1) 
						{ 
						return(1); 
						} 
						else 
							{ 
							return(0); 
							} 
					} 
					else 
						{ 
						return(0); 
						} 
				} 
		} 
} 
function RealTestaCNPJ(CNPJ,g) 
{ 
	var VerCNPJ=0; 
	var ind=2; 
	var tam; 
	for(f=g;f>0;f--) 
		{ 
		VerCNPJ+=parseInt(CNPJ.charAt(f-1))*ind; 
		if(ind>8) 
			{ 
			ind=2; 
			} 
			else 
				{ 
				ind++; 
				} 
		} 
	VerCNPJ%=11; 
	if(VerCNPJ==0 || VerCNPJ==1) 
		{ 
		VerCNPJ=0; 
		} 
		else 
			{ 
			VerCNPJ=11-VerCNPJ; 
			} 
			if(VerCNPJ!=parseInt(CNPJ.charAt(g))) 
				{ 
				return(0); 
				} 
				else 
					{ 
					return(1); 
					} 
} 
  

function TESTA(LOCAL) 
{ 

		if(LOCAL.value != "") 
			{
			if(VerifyCNPJ(LOCAL.value) != 1) 
				{ 
				alert("CPF/CNPJ não é válido!"); 
					LOCAL.focus();
					LOCAL.style.color = "red";
					LOCAL.select();
				return false;
				} 
			}

}

//end CPF


function checa_cpf(pcpf,local)
 {
	 pcpf = pcpf.replace( ".", "" );
	 pcpf = pcpf.replace( ".", "" );
	 pcpf = pcpf.replace( ".", "" );
	 pcpf = pcpf.replace( "-", "" );
	 
	 if (pcpf.length != 11) {sim=false}
	 else {sim=true}
	
	  if (sim )  
		  {
		  for (i=0;((i<=(pcpf.length-1))&& sim); i++)
			  {
			   val = pcpf.charAt(i)
			   if
				 ((val!="9")&&(val!="0")&&(val!="1")&&(val!="2")&&(val!="3")&&(val!="4")
				 &&    (val!="5")&&(val!="6")&&(val!="7")&&(val!="8")) {sim=false}
			  }

	   if (sim)
	 		 {
				soma = 0
				for (i=0;i<=8;i++)
					{
					 val = eval(pcpf.charAt(i))
					 soma = soma + (val*(i+1))
					}
				resto = soma % 11
				if (resto>9) dig = resto -10
				else  dig = resto
				if (dig != eval(pcpf.charAt(9))) { sim=false }
			    else   
		           {
					soma = 0
					for (i=0;i<=7;i++)
						{
						 val = eval(pcpf.charAt(i+1))
						 soma = soma + (val*(i+1))
						}
					soma = soma + (dig * 9)
					resto = soma % 11
					if (resto>9) dig = resto -10
					else  dig = resto
   					if (dig != eval(pcpf.charAt(10))) { sim = false }
   						 else sim = true
   					}
  			 }
 		 }
		
			var CPFcnpj = local;
		 if((CPFcnpj.value == '000.000.000-00')||
		  (CPFcnpj.value == '111.111.111-11')||
		  (CPFcnpj.value == "222.222.222-22")||
		  (CPFcnpj.value == "333.333.333-33")||
		  (CPFcnpj.value == "444.444.444-44")||
		  (CPFcnpj.value == "555.555.555-55")||
		  (CPFcnpj.value == "666.666.666-66")||
		  (CPFcnpj.value == "777.777.777-77")||
		  (CPFcnpj.value == "999.999.999-99"))
		  { sim = false }
  
		if(CPFcnpj.value != "")
			{
			 if (!sim) 
				{
					//alert(CPF.value);
				 local.focus();
				 local.style.color='red';
				 local.select(); 	
				 alert("Valor inválido de CPF/CNPJ");
				 return false;
				}
			}
}

function dasabilitarEVENT(event) 
{
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if(keyCode == 13 )
	{ 
		return false;
	}
	if(keyCode == 32 )
	{ 
		return false;
	}
	return keyCode;
}


var menu = {
    exibirDetalhes : function(id){
        // exbide a linha
        var nomeLinha = "sub_grupo_"+id;
		var nomeSpam = "spam_"+id;
        $(nomeLinha).toggle();

		if($(nomeLinha).visible()==false){
			
        	/*    $(nomeSpam).up(1).setStyle({
                backgroundColor : '#3e3c3f'
            });*/			
			
			$(nomeSpam).removeClassName('img_seta_baixo');
			$(nomeSpam).addClassName('img_seta_frente');
		} else {

           /* $(nomeSpam).up(1).setStyle({
                backgroundColor : '#282629'
            });*/
			
			$(nomeSpam).addClassName('img_seta_baixo');
			$(nomeSpam).removeClassName('img_seta_frente');
		}
    },
	
	redirecionarGrupo : function (id) {
	
		location.href='index.php?pg=produtos.htm&grupo='+id;
		
	}
}

var ZebraTable = {
	bgcolor: '',
	classname: '',
	stripe: function(el) {
		if (!$(el)) return;
		var rows = $(el).getElementsByTagName('tr');
		for (var i=1,len=rows.length;i<len;i++) {
			if (i % 2 == 0) rows[i].className = 'alt';
			Event.observe(rows[i],'mouseover',function() { ZebraTable.mouseover(this); });
			Event.observe(rows[i],'mouseout',function() { ZebraTable.mouseout(this); });
		}
	},
	mouseover: function(row) {
		this.bgcolor = row.style.backgroundColor;
		this.classname = row.className;
		row.addClassName('over');
	},
	mouseout: function(row) {
		row.removeClassName('over');
		row.addClassName(this.classname);
		row.style.backgroundColor = this.bgcolor;
	}
}
