function confereCPF(c){

	c = c.toString()
	c = c.replace(".","")
	c = c.replace(".","")
	c = c.replace(".","")
	c = c.replace("-","")

	var i; 
	s = c;
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(10-i); 
		} 
	
	if (d1 == 0){ 
		v = true; 
		return false; 
		} 

	d1 = 11 - (d1 % 11); 
	if (d1 > 9){
		d1 = 0; 
		}
	if (dv.charAt(0) != d1) { 
		v = true;
		return false; 
		} 

	d1 *= 2; 
	
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(11-i); 
		} 
		
	d1 = 11 - (d1 % 11); 
	
	if (d1 > 9){ 
		d1 = 0; 
		}
		
	if (dv.charAt(1) != d1) { 
		v = true;
		return false; 
		} 
	if (!v) {
		return true
		}
}

////////////////////////////////////////////////////////////////////	

function favoritos_rem(id_produto){
	carregaAjax('php/favoritos.php?id_rem='+id_produto,'dv_prod_favoritos','dv_prod_favoritos_carregando');
	
	palavra = document.getElementById('dv_fav_lista_item_'+id_produto);
	if(palavra){
		oculta('dv_fav_lista_item_'+id_produto);
		}
	
	}

////////////////////////////////////////////////////////////////////	

function favoritos_add(id_produto){
	carregaAjax('php/favoritos.php?id_add='+id_produto,'dv_prod_favoritos','dv_prod_favoritos_carregando');
	mudaImagem('btn_favoritos_topo','imagens/favoritos_topo_on.png');	
	}

////////////////////////////////////////////////////////////////////	

function executarAoEnter(e,funcao,vars){
	
	<!--  onKeyPress="return executarAoEnter(event,funcao,'vars');" !-->
  
  if (e.keyCode) { // IE   
    tecla = e.keyCode;   
  }  else if (e.which) { // Firefox   
    tecla = e.which;   
  }  else { // Sei lá! :P   
    return false;   
  }   
	
	if(tecla==13){
		if(funcao!=undefined){
				exec = funcao;
				exec(vars);
				}
		return false;
		}
}

////////////////////////////////////////////////////////////////////	

function busca(){
	palavra = document.getElementById('cp_busca');
	if(palavra.value!=''){
		location.href='?pg=26&busca='+palavra.value;
		}
	}
	
/////////////////////////////////////////////	
	
function mascara(alvo,formato,e){
		//L = letras
		//9 = números
		//onKeyPress="return mascara('id_campo','LLL-9999',event);"
		
		if (e.keyCode) { 
			 tecla = e.keyCode;   
		  }  else if (e.which) { 
			 tecla = e.which;   
		  }  else {    
			 return false;   
		  }
	
		if(tecla==8 || tecla==9 || tecla==46 || tecla==37 || tecla==39){
			return true;
			}
	
		alvo = document.getElementById(alvo);
		texto = alvo.value;
		
		tamanho_texto = texto.length;
		tamanho_formato = formato.length;
		
		if(tamanho_texto>(tamanho_formato-1)){
			return false;
			}
		
		charAtual = String.fromCharCode(tecla);
		
		i=tamanho_texto;
		formatoAtual = formato.charAt(i);
		formatoProximo = formato.charAt((i+1));
			
			if(formatoAtual!='L' && formatoAtual!='9'){
					alvo.value = texto+formatoAtual;
					formatoAtual = formatoProximo;
					}
			
			if(formatoAtual=='L'){
				
					busca=/[a-zA-Z]/;
					if(charAtual.search(busca)==-1){
						return false;
				  		} 
				
				} else if (formatoAtual=='9'){
				
					busca=/\d/;
					if(charAtual.search(busca)==-1){
						return false;
				  		}
				
				} else {
					return false;
				}
		
		return true
	
	}

////////////////////////////////////////////////////

function confereCaractere(char,campo){
	
	var alvo = document.getElementById(campo);
	var conteudo = alvo.value;
	
		if(conteudo.indexOf(char,0) == -1){
			return false;
			} else {
			return true;
			}
			
	}

/////////////////////////////////////////////////
	
function ocultar_tam_anel(){
		fade(dv_form_tam_anel,1000,0);
		}
	
/////////////////////////////////////////////////

function exibir_tam_anel(){
		exibe('dv_form_tam_anel');
		fade(dv_form_tam_anel,1000,1);
		mudaImagem('foto_produto','imagens/descubra_anel.jpg');
		}
	
/////////////////////////////////////////////////

function focar_campo(campo){
	var alvo = document.getElementById(campo);
	alvo.focus();
	alvo.select();
	return false;
	}

/////////////////////////////////////////////////	

function corrigir_texto_enviar(e,id_campo,tab,id,campo,rotulo,estilo){
	
	<!--  onKeyPress="return somenteNumeros(event);" !-->

	if(e.type=='keypress'){
		  if (e.keyCode) { // IE   
			 tecla = e.keyCode;   
		  }  else if (e.which) { // Firefox   
			 tecla = e.which;   
		  }  else { // Sei lá! :P   
			 return false;   
		  }   
		}

	if((e.type=='blur') || ((e.type=='keypress') && (tecla==13))){

		var texto = document.getElementById('cp_corrigir_'+id_campo);
		var alvo = document.getElementById('dv_editar_campo_'+id_campo);
		var carregando = document.getElementById('dv_editar_campo_'+id_campo+'_carregando');
		carregaAjax('../php/editar_texto_form.php?sit=2&tab='+tab+'&id='+id+'&campo='+campo+'&texto='+escape(texto.value)+'&rotulo='+rotulo+'&estilo='+estilo,alvo,carregando);
		
		}

	}
	
/////////////////////////////////////////////////	

function editar_texto(tab,id,campo,id_campo,rotulo,estilo){
	alvo = document.getElementById('dv_editar_campo_'+id_campo);
	carregando = document.getElementById('dv_editar_campo_'+id_campo+'_carregando');
	carregaAjax('../php/editar_texto_form.php?sit=1&tab='+tab+'&id='+id+'&campo='+campo+'&id_campo='+id_campo+'&rotulo='+rotulo+'&estilo='+estilo,alvo,carregando,focar_campo,'cp_corrigir_'+id_campo);
	}

/////////////////////////////////////////////////	

function envia_aviseme(id_item){

	var alvo=document.getElementById('dv_aviseme_envio_'+id_item);
	var carregando=document.getElementById('dv_aviseme_envio_'+id_item+'_carregando');
	carregaAjax('ger_aviseme_enviar.php?id_busca='+id_item,alvo,carregando);			
	
	}

/////////////////////////////////////////////////////////

function cadastra_aviseme(id_item){
	
	var nome=document.getElementById('aviseme_nome');
	var email=document.getElementById('aviseme_email');
	
	if((nome.value=='Seu nome') || (nome.value=='')){
		alert('Por favor preencha seu nome');
		nome.focus();
		return false;
		}
		
	if((email.value=='Seu email') || (email.value=='')){
		alert('Por favor preencha seu email');
		email.focus();
		return false;
		}
	
	if((nome.value!='Seu nome') && (nome.value!='') && (email.value!='') && (email.value!='Seu email')){
		carregaAjax('php/insere_aviseme.php?id_item='+id_item+'&nome='+nome.value+'&email='+email.value,dv_aviseme,dv_aviseme_carregando);		
		}
	
	}

/////////////////////////////////////////////////////////

function excluir_produtos_carrinho(id){
		carregaAjax('php/produtos_carrinho_lista.php?id_excluir='+id,dv_lista_produtos,dv_lista_produtos_carregando);		
	}

////////////////////////////////////////////////////////

function listar_produtos_carrinho(vars){
		carregaAjax('php/produtos_carrinho_lista.php?'+vars,dv_lista_produtos,dv_lista_produtos_carregando);		
	}

////////////////////////////////////////////////////////

function fechar_carrinho(){
		window.location.href="index.php?pg=3";
	}

///////////////////////////////////////////////////////

function excluir_item_carrinho(id){
		exibe('dv_carrinho_aviso_lista');
		carregaAjax('php/produtos_lista_carrinho.php?excluir=1&id_excluir='+id,dv_carrinho_itens,dv_carrinho_itens_carregando);		
		carregaAjax('php/produtos_info_carrinho.php',dv_carrinho_palco,dv_carrinho_carregando);
	}

///////////////////////////////////////////////////////

function exibir_resumo_carrinho(){
		exibe('dv_carrinho_aviso_lista');
		carregaAjax('php/produtos_lista_carrinho.php',dv_carrinho_itens,dv_carrinho_itens_carregando);		
	}

//////////////////////////////////////////////////////

function adicionar_carrinho(id,anel){
	var quantidade = document.getElementById('cp_quantidade');
	
	if(anel=='s'){
		mudaImagem('foto_produto','../imagens/descubra_anel.jpg');
		
		exibir_tam_anel();
		var tamanho_anel = document.getElementById('cp_tam_anel');
		if(tamanho_anel.value==''){
			if(quantidade.value==1){
				alert('Por favor informe o tamanho do anel para prosseguir com seu pedido.');
				}
			if(quantidade.value>1){
				alert('Por favor informe o tamanho dos anéis para prosseguir com seu pedido.');
				}
			return false;
			}
		
		} else {
		tamanho_anel = '';	
		}
	
	carregaAjax('php/produtos_info_carrinho.php?quant='+quantidade.value+'&id_item='+id+'&add=1&tam_anel='+tamanho_anel.value,dv_carrinho_palco,dv_carrinho_carregando,fechar_carrinho);

	if(anel=='s'){
		ocultar_tam_anel();
		}
	
	oculta('dv_zoom'); 

	}


//////////////////////////////////////////////////////

function trocar_fotos_produtos(imagem){
		
		fade(foto_produto,1000,0);
		window.setTimeout(
								function(){
												mudaImagem('foto_produto',imagem);
												fade(foto_produto,1000,1);
											},1500);
	}

/////////////////////////////////////////////////////

function fade(alvo,velocidade,alpha){
	if(alvo){
		$(alvo).fadeTo(velocidade,alpha);
		}
	}

/////////////////////////////////////////////////////

function carregaAjax(url,alvo,carregando,funcao,vars){

	if(typeof(alvo)=='string'){
		alvo = document.getElementById(alvo);
		}
	if(typeof(carregando)=='string'){
		carregando = document.getElementById(carregando);
		}

	$.ajax(
		{
		  url: url,
		  cache: false,
		  beforeSend: function(){
			  	if((carregando!=undefined) && (carregando!='')){
		  			$(carregando).show();
					}
				if((alvo!=undefined) && (alvo!='')){	
					$(alvo).hide();
					}
		  		},
		  success: function(html){
		  		if((carregando!=undefined) && (carregando!='')){
					$(carregando).hide();
					}
				if((alvo!=undefined) && (alvo!='')){	
					$(alvo).show();
					$(alvo).html(html);
					}
				
				if(funcao!=undefined){
					exec = funcao;
					exec(vars);
					}
				
				}
			}
		);
	}

////////////////////////////////////////////////////

function listar_produtos(id_secao,id_categoria,pag,id_marca){

	//buscando a página atual;
	if(pag==''){
		//buscar da barra
		pag = location.hash;
		pag = pag.replace('#','');
		
		if(pag==''){
			pag=0;
			}	
		} 

	location.hash = pag;

	var url = 'php/produtos_lista.php?id_secao='+id_secao+'&id_categoria='+id_categoria+'&pag='+pag+'&id_marca='+id_marca;
	var alvo = document.getElementById('dv_produtos_palco');
	var carregando = document.getElementById('dv_produtos_carregando');

	
	$(dv_produtos_palco).fadeOut(2000, function(){
										  	
											$(carregando).show();
											
										  	$.ajax({
													  url: url,
													  cache: false,
													  beforeSend: function(){
															},
													  success: function(html){
														  	$(carregando).hide();
															$(alvo).html(html);
															$(dv_produtos_palco).fadeIn(2000);
															}
														});
										  
											});
	}

////////////////////////////////////////////////////

function ocultar_produtos(id_secao){
	$(dv_produtos_palco).fadeOut(2000, function(){
										  listar_produtos(id_secao)
											});
	}

////////////////////////////////////////////////////

function cadastro_newsletter(){
	var nome = document.getElementById('newsletter_nome');
	var email = document.getElementById('newsletter_email');
	
	if(nome.value==''){
		alert('Por favor preencha seu nome');
		nome.focus();
		return false
		}
	if(email.value==''){
		alert('Por favor preencha seu email');
		email.focus();
		return false
		}
	
	carregaAjax('php/newsletter_insere.php?nome_insere='+nome.value+'&email_insere='+email.value,dv_newsletter,dv_newsletter_carregando);

	
	}

////////////////////////////////////////////////////	

function cor_borda(alvo,cor) {
	var alvo = document.getElementById(alvo);
	if(alvo){
		alvo.style.borderColor = cor
		}
}

////////////////////////////////////////////////////	

function confere_form(lista){
	var array=lista.split(",");
	for(i=0;i<array.length;i++){
		var campo=array[i];
		var alvo = document.getElementById(campo);
		if(alvo.value==""){
			alert('Preencha o campo selecionado!');
			alternaEstilo(campo,'borda_erro');
			alvo.focus();
			return false;
			} else {
			alternaEstilo(campo,'');	
			}
		}

	}
	
////////////////////////////////////////////////////	
	
function somenteDecimal(e){
	
	<!--  onKeyPress="return somenteDecimal(event);" !-->
	
  if (e.keyCode) { // IE   
    tecla = e.keyCode;   
  }  else if (e.which) { // Firefox   
    tecla = e.which;   
  }  else { // Sei lá! :P   
    return false;   
  }   

  if(tecla > 45 && tecla < 58) // numeros de 0 a 9
    return true;
  else {
      if (tecla != 8) // backspace
        return false;
      else
        return true;
    }
}


////////////////////////////////////////////////////	
	
function somenteNumeros(e){
	
	<!--  onKeyPress="return somenteNumeros(event);" !-->
	
  if (e.keyCode) { // IE   
    tecla = e.keyCode;   
  }  else if (e.which) { // Firefox   
    tecla = e.which;   
  }  else { // Sei lá! :P   
    return false;   
  }   

  if(tecla > 43 && tecla < 58) // numeros de 0 a 9
    return true;
  else {
      if (tecla != 8) // backspace
        return false;
      else
        return true;
    }
}


/////////////////////////////////////////////////////

function confirma_url(msg,url){
	if(confirm(msg)){
					document.location.href=url;
				  } 
	
	}

/////////////////////////////////////////////////////

function ampliarConteudo(pagina){
	
	pos_zoom = document.getElementById("dv_zoom");
	pos_zoom.style.marginTop=document.body.scrollTop;
	
	exibe("dv_zoom");
	carregaAjax(pagina,dv_palco_zoom,dv_carregando_zoom);
	}

/////////////////////////////////////////////////////

function ampliarFoto(foto,legenda,credito){
	
	pos_zoom = document.getElementById("dv_zoom");
	pos_zoom.style.marginTop=document.body.scrollTop;

	exibe("dv_zoom");
	carregaAjax('php/exibe_foto.php?foto='+foto+'&legenda='+legenda+'&credito='+credito,dv_palco_zoom,dv_carregando_zoom);
	}

/////////////////////////////////////////////////////

function fechar_zoom(){
	oculta("dv_zoom");
	}

/////////////////////////////////////////////////////
	
function cookie(name,value,hours){
	var path='/';
	if (hours){
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		var expires = "";
	}
	document.cookie = name+"="+escape(value)+expires+"; path="+path;
}

/////////////////////////////////////////////////////

function lerCookie(name){   
	var nameEQ = name + "=";
   var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' '){
			c = c.substring(1,c.length);
			}
      if (c.indexOf(nameEQ) == 0){
   		return unescape(c.substring(nameEQ.length,c.length));
   		}
	}
	return null;
}

/////////////////////////////////////////////////////

function limparCookie(name,path){
	var path = '/';
	var mac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;
	if(mac){
		createCookie(name,"",0.001,path);
 	}else{
		createCookie(name,"",-1,path);
	}
}

/////////////////////////////////////////////////////

function mudaImagem(alvo,imagem){
	alvo = document.getElementById(alvo)
	alvo.src=imagem;
	}
	
/////////////////////////////////////////////////////

function alternaImagens(alvo,imagem1,imagem2){
	
	alvo = document.getElementById(alvo);
	if(alvo.src.indexOf(imagem1)!=-1){
		alvo.src=imagem2;
		} else {
		alvo.src=imagem1;
		}
	}
	
/////////////////////////////////////////////////////

function alternaDisplay(alvo,estiloExibe){
	if(estiloExibe==undefined){
		estiloExibe = 'block';
		}
	alvo = document.getElementById(alvo)
	if(alvo.style.display==estiloExibe){
		alvo.style.display="none";
		} else {
		alvo.style.display=estiloExibe;
		}
	}

/////////////////////////////////////////////////////

function alternaEstilo(alvo,estilo1,estilo2){
	alvo = document.getElementById(alvo);
	if(alvo.className==estilo1){
			alvo.className=estilo2;
		} else {
			alvo.className=estilo1;
		}
	}

/////////////////////////////////////////////////////

function estilo(alvo,estilo){
	var alvo = document.getElementById(alvo);
	alvo.className=estilo;
	}
   
/////////////////////////////////////////////////////   

function exibe(alvo){	
	alvo = document.getElementById(alvo)
	alvo.style.display="block"
	}

/////////////////////////////////////////////////////   	

function oculta(alvo){
	alvo = document.getElementById(alvo)
	alvo.style.display="none"
	}
	
/////////////////////////////////////////////////////   	