function busca(){
	palavra = document.getElementById('cp_busca');
	secao = document.getElementById('cp_busca_secao');
	
	if(palavra.value!='' && palavra.value!='buscar'){
		location.href='?pg=14&busca='+palavra.value+'&busca_secao='+secao.value;
		}
	}
	
//////// --------- >

function prod_tipo_view(tipo){
	if(tipo=='tabela'){
		estilo('dv_prod_lista_lista','prod_lista_tabela');
		}
	if(tipo=='lista'){
		estilo('dv_prod_lista_lista','prod_lista_lista');
		}
	cookie('prod_tipo_view',tipo,240);
	}

//////// --------- >

function prod_menu_lateral_floater_exibe(id){
	$('.dv_menu_lateral_floater').css("display", "none");
	$('#dv_menu_lateral_floater_'+id).css("display", "block");
	}

//////// --------- >

function prod_menu_lateral_floater_oculta(){
	$('.dv_menu_lateral_floater').css("display", "none");
	}

//////// --------- >

function prodConfereCPF(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 menu_drop_exibe(j){
	total_menus = document.getElementById('cp_info_total_menus').value;
	for(i=0;i<total_menus;i++){
		if(i!=j){
			ocultaCorte('ul_submenu_'+i);
			}
		}
	exibeCorte('ul_submenu_'+j);
	}

//////// --------- >
	
function menu_drop_oculta(){
	total_menus = document.getElementById('cp_info_total_menus').value;
	for(i=0;i<total_menus;i++){
		ocultaCorte('ul_submenu_'+i);
		}
	ocultaCorte('img_recentes_rotulo');
	}
	
//////// --------- >

function prod_fotos(id_busca,foto_atual){
	fn_ampliar_conteudo('php/prod_fotos.php?id_busca='+id_busca+'&foto_atual='+foto_atual,640,10);
	}
	
//////// --------- >

function prod_fotos_alterna(alvo,lista){

	var array=lista.split(",");
	var total_itens = array.length;

	alvo = document.getElementById(alvo);
	legenda = document.getElementById('prod_fotos_contar');
	
	for(i=0;i<total_itens;i++){
		if(alvo.src==array[i]){
			if(i==(total_itens-1)){
				alvo.src=array[0];
				legenda.innerText = 'Foto 1 de '+total_itens;
				return;
				} else {
				alvo.src=array[i+1];
				legenda.innerText = 'Foto '+(i+2)+' de '+total_itens;
				return;
				}
			} 
		}

	}

//////// --------- >

function prod_comente(id_busca){
	fn_ampliar_conteudo('php/prod_comente.php?id_busca='+id_busca,320,10);
	}
	
//////// --------- >

function prod_comente_listar(id_busca){
	carregaAjax('php/prod_comente_lista.php?id_busca='+id_busca,'dv_item_perguntas_lista','dv_item_perguntas_lista_carregando');
	}
	
//////// --------- >

function prod_comente_insere(id_busca){

	prod_com = document.getElementById('cp_prod_comentario');
	
	if(prod_com.value==""){			
		alert('Preencha seu comentário sobre o produto');
		prod_com.focus();
		return false;
		}
			
	carregaAjax('php/prod_comente_insere.php?id_busca='+id_busca+'&comentario='+escape(prod_com.value),'dv_prod_comente_campos','dv_prod_comente_carregando');

	}
	
//////// --------- >
	
function prod_indicacao(id_busca){
	obj_nome_rem = document.getElementById('nome_remetente_prod');
	obj_email_rem = document.getElementById('email_remetente_prod');
	obj_nome_dest = document.getElementById('nome_destinatario_prod');
	obj_email_dest = document.getElementById('email_destinatario_prod');
	obj_mensagem = document.getElementById('mensagem_prod'); 

	nome = obj_nome_rem.value;
	email = obj_email_rem.value;	
	dest = obj_nome_dest.value;
	dest_email = obj_email_dest.value;
	msg = obj_mensagem.value;		
	
	if(email==""){			
			obj_email_dest.focus();
			alert('Preencha o email do destinatário!');
			return false;
			}

	carregaAjax('php/prod_indique_insere.php?id_busca='+id_busca+'&nome_rem='+nome+'&email_rem='+email+'&nome_dest='+dest+'&email_dest='+dest_email+'&mensagem='+msg,'dv_prod_indique_form');
	
	}
	
//////// --------- >
	
function prod_add(id_add){
	
	var id_opcao=0;
	var total = $(".radio_tamanho").length;
	var msg = 'Selecione um dos modelos disponíveis.';
	
	for(i=0;i<total;i++){
		id = $(".radio_tamanho:eq("+i+")").attr('id');
		alvo = document.getElementById(id);	
		if(alvo.checked==true){
			id_opcao = alvo.value;
			}
		}
	
	if(total>0){
		if(id_opcao==0){
			alert(msg);
			return false;
			}
		}
	id_add = parseInt(id_add);
	location.href='?pg=13&prod_add='+id_add+'&id_opcao='+id_opcao;
	}
	
//////// --------- >
	
function prod_rem(id_rem){
	location.href='?pg=13&prod_rem='+id_rem;
	}
	
//////// --------- >
	
function prod_change_quant(id_item_lista, valor){
	valor = parseInt(valor);
	if(valor>0){
		location.href='?pg=13&change_quant='+id_item_lista+'&unid='+valor;
		}
	}
	
//////// --------- >
	
function carrinho_topo_load(){
	carregaAjax('php/prod_carrinho_topo.php','dv_carrinho');
	}
	
//////// --------- >

function prod_visitados(){
	carregaAjax('php/prod_visitados.php','dv_recentes_palco');
	}
	
//////// --------- >

function prod_visitados_excluir(id_excluir){
	carregaAjax('php/prod_visitados.php?id_excluir='+id_excluir,'dv_recentes_palco');
	}
	
//////// --------- >

function prod_enviar_formulario_pedido(){
	formulario = document.getElementById('form_pedido');
	if(confere_form('form_nome,form_email,form_cpf,form_endereco,form_numero,form_bairro,form_cidade,form_uf,form_cep,form_pais,form_telefone')==false){
		return false;
		}
	
	cpf = document.getElementById('form_cpf');
	if(prodConfereCPF(cpf.value)==false){
		alert('Preencha corretamente seu CPF');
		alternaEstilo('form_cpf','borda_erro');
		cpf.focus();
		return false;
		}
	
	formulario.submit();
	}
	
//////// --------- >

function prod_submit_pagseguro(){
	formulario = document.getElementById('form_pag_seguro');
	formulario.submit();
	setTimeout("prod_submit_redirecionar()",3000);
	}
	
//////// --------- >

function prod_submit_redirecionar(){
	location.href='?pg=20';	
	}
	
//////// --------- >

function prod_redirecionar(url){
	location.href=url;
	}
	
/////////// --------------- >

function prod_pedido_detalhes_amplia(id_busca){
	fn_ampliar_conteudo('php/prod_pedido_detalhes.php?id_busca='+id_busca,900,10);
	}
	
/////////// --------------- >

function prod_frete_selecionar(tipo){
	ocultaCorte('dv_frete_modos_entrega_lista');
	$("#dv_frete_modo_entrega_escolhido").text(tipo);
      $("#dv_frete_modo_entrega_escolhido").animate({ 
        right: "380px"
      }, 1000);
	
	ocultaCorte('barra_sedex');
	ocultaCorte('barra_transportadora');
	ocultaCorte('barra_retirada');
	ocultaCorte('barra_entrega');
	
	if(tipo=='Correios'){
		exibeCorte('barra_sedex');	
		}
	if(tipo=='Transportadora'){
		exibeCorte('barra_transportadora');
		}
	if(tipo=='Retirar'){
		exibeCorte('barra_retirada');
		}
	if(tipo=='Entrega local'){
		exibeCorte('barra_entrega');
		}
	  
	}	
	
/////////// --------------- >	
	
function prod_frete_confirmar(modo,id){
	carregaAjax('php/prod_carrinho_frete_insere.php?id='+id+'&modo='+modo,'','',prod_frete_redirecionar);
	}
	
/////////// --------------- >	
	
function prod_frete_redirecionar(){
	prod_redirecionar('?pg=17');
	}
