function desabilitar(){ 
    //return false;
} 
document.oncontextmenu=desabilitar;

function catalogo(id, foto, ref, lang){
	desmonta_itens();
	
	if(id!=undefined){
		
		document.getElementById('catalogo').style.display='block';	
		document.getElementById('fundo_catalogo').style.display='block';	
		
		document.foto_catalogo.src = "catalogo/ouro/"+foto+".jpg";	

		document.form.id.value = id;
		document.form.foto.value = document.foto_catalogo.src;
		reff.innerHTML = ref;
		document.form.referencia.value = ref;
		 document.form.obs.value = "";
		
		//
		if(lang==1){
			t_referencia.innerHTML = "Refer&ecirc;ncia";

			t_tamanho.innerHTML = "Tam.";
			t_quantidade.innerHTML = "Qtde.";
			t_pedra.innerHTML = "Pedra";
			t_valor.innerHTML = "Valor";
			t_adicionar.innerHTML = "Adicionar";
			t_fechar.innerHTML = "Fechar";
			t_tarracha_infantil = "Com tarracha Infantil: ";
			t_aproveite = "Aproveite Também";
			t_apartir_de = "A partir de";
			t_ver = "Ver";
			document.form.compra_ok.value = "Produto Incluso com Sucesso!";
		}else if(lang==2){
			t_referencia.innerHTML = "Reference";
			t_banho.innerHTML = "Banho";
			t_tamanho.innerHTML = "Size";
			t_quantidade.innerHTML = "Qty";
			t_pedra.innerHTML = "Stone";
			t_valor.innerHTML = "Amount";
			t_adicionar.innerHTML = "Add";
			t_fechar.innerHTML = "Close";
			t_tarracha_infantil = "Tarracha Infantil: ";
			t_aproveite = "Aproveite Tamb&eacute;m";
			t_apartir_de = "A partir de";
			t_ver = "Ver";
			document.form.compra_ok.value = "Produto Incluso com Sucesso!";
		}else if(lang==3){
			t_referencia.innerHTML = "Referencia";
			t_banho.innerHTML = "Banho";
			t_tamanho.innerHTML = "Tama&ntilde;o";
			t_quantidade.innerHTML = "Cantidad";
			t_pedra.innerHTML = "Piedra";
			t_valor.innerHTML = "Valor";
			t_adicionar.innerHTML = "Agregar";
			t_fechar.innerHTML = "Fechar";
			t_tarracha_infantil = "Tarracha Infantil: ";
			t_aproveite = "Aproveite Tamb&eacute;m";
			t_apartir_de = "A partir de";
			t_ver = "Ver";
			document.form.compra_ok.value = "Produto Incluso com Sucesso!";
		}
		
		//
		
		$.ajax({
		   type: "POST",
		   url: "response.php?acao=detalhes&id="+id+"&idioma="+lang,
		   data: "",
		   success: function(msg){
				a = msg.split("@@@");
				
				descricao = a[2].split("@");				
				
				document.form.id_tamanho.value = a[1];								
				valor = a[3].split("@");


				cifrao = a[13];
				obst.innerHTML = a[15];
				t_material.innerHTML = a[14];
				
				document.form.cifrao.value = cifrao;
				
				document.form.qtd.value = 1;

				
				//TAMANHO
				document.form.tamanho.options.length = 0;
				for(i=1;i<descricao.length;i++){
					var novo = document.createElement("option");
					novo.setAttribute("id", "opcoes");
					novo.value = i;
					novo.text  = descricao[i];
					document.form.tamanho.options.add(novo);
				}	
				
				document.form.tamanho.selectedIndex = 0;
							
				//CORES
				id_cor = a[11].split("@");
				nome_cor = a[12].split("@");
				document.form.cor.options.length = 0;
				for(i=1;i<id_cor.length;i++){
					var novo = document.createElement("option");
					novo.setAttribute("id", "opcoes");
					novo.value = id_cor[i];
					novo.text  = nome_cor[i];
					document.form.cor.options.add(novo);
				}
				document.form.cor.selectedIndex = 0;

				
				muda_propriedades();
				//ASSOCIAÇÕES
				
				id_ass = a[7].split("@");
				foto_ass = a[8].split("@");
				prata_ass = a[9].split("@");
				referencia = a[10].split("@");
				
				
				if(id_ass.length>1){
					var row = table.insertRow(0);
					var c1 = row.insertCell(0);	
					c1.colSpan = "3";
					c1.setAttribute('height', '10');
					c1.setAttribute('align', 'center');
					var hr = document.createElement("hr"); 
					hr.setAttribute('width', '310');
					hr.setAttribute('size', '2');
					hr.setAttribute('color', '#FFFFFF');
					c1.setAttribute('align', 'left');
					c1.appendChild(hr);
					
					var row = table.insertRow(1);
					var c1 = row.insertCell(0);	
					c1.setAttribute('height', '20');
					c1.setAttribute('className', 'texto_destaque_g');
					c1.setAttribute('vAlign', 'top');
					var texto1 = document.createTextNode("Aproveite Também");
					c1.colSpan = "3";
					c1.appendChild(texto1);
				}
				u = 2;
				for(i=1;i<id_ass.length;i++){
					
					var row = table.insertRow(u);
					u++;
					
					///////////////
					var c1 = row.insertCell(0);					
					c1.setAttribute('width', '42');
					c1.setAttribute('height', '47');
					var link1 = document.createElement("a");
					var img = document.createElement("img"); 
					img.setAttribute("src","thumb.php?tam=40&foto=catalogo/ouro/"+foto_ass[i]+".jpg");
					img.setAttribute("border",0);
					link1.setAttribute("href","javascript:catalogo('"+id_ass[i]+"','"+foto_ass[i]+"','"+referencia[i]+"','"+lang+"')");
					link1.appendChild(img); 					
					c1.appendChild(link1);
					
					//				
					var c2 = row.insertCell(1);
					c2.setAttribute('width', '165');
					c2.setAttribute('height', '10');
					c2.setAttribute('align', 'left');
					c2.setAttribute('vAlign', 'top');
					
					refer = referencia[i];
					valor = t_apartir_de+" "+cifrao+" "+prata_ass[i];
					
					var texto2 = document.createTextNode(refer);
					c2.appendChild(texto2);	
					
					
					var c3 = row.insertCell(2);					
					c3.setAttribute('width', '70');	
					c3.setAttribute('align', 'center');	
					var link1 = document.createElement("a");					
					var texto1 = document.createTextNode(t_ver);					
					link1.setAttribute("href","javascript:catalogo('"+id_ass[i]+"','"+foto_ass[i]+"','"+referencia[i]+"','"+lang+"')");
					link1.appendChild(texto1); 	
					link1.setAttribute('className', 'botao_ver');
					c3.appendChild(link1);
					
					
					var row = table.insertRow(u);
					u++;				
					var c22 = row.insertCell(0);		
					c22.setAttribute('height', '31');
					c22.setAttribute('vAlign', 'top');
					c22.setAttribute('className', 'apartir_de');
					var texto3 = document.createTextNode(valor);					
					c22.appendChild(texto3);

					
					c1.rowSpan = "2";
					c3.rowSpan = "2";
					//	
				}
				
		   }
		 });
		
	}else{
		document.getElementById('catalogo').style.display='none';
		document.getElementById('fundo_catalogo').style.display='none';
	}	
}
function aparece_foto(){
	document.foto_catalogo.src = document.form.foto.value;
}

function muda_propriedades(){
	
	tamanho = document.form.tamanho.value;

	
	ref = document.form.referencia.value.split(".");	
	tamanho_selecionado = document.form['tamanho'].options[document.form.tamanho.selectedIndex].text;

	valorr.innerHTML = document.form.cifrao.value+" "+valor[tamanho];
}

function comprar(){
		id = document.form.id.value;
		tamanho = document.form.tamanho.value;
		qtd = document.form.qtd.value;
		cor = document.form.cor.value;

		obs = document.form.obs.value;
		id_tamanho = document.form.id_tamanho.value.split("@");		
		tamanho = id_tamanho[tamanho];
		
	
		
		if(qtd==0){
			qtd = 1;
		}else if(qtd==""){
			qtd = 1;
		}
		
		$.ajax({
		   type: "POST",
		   url: "incluir.php",
		   data: "id="+id+"&tamanho="+tamanho+"&qtd="+qtd+"&cor="+cor+"&obs="+obs,
		   success: function(msg){
			   certo(document.form.compra_ok.value);
		   }
		 });
		catalogo();
			
}

function somente_numero(campo){   
	var digits="0123456789"; 
	var campo_temp;
    for (var i=0;i<campo.value.length;i++){   
        campo_temp=campo.value.substring(i,i+1)   
        if (digits.indexOf(campo_temp)==-1){   
            campo.value = campo.value.substring(0,i);   
        }   
    }   
}  
function desmonta_itens(){
	var linhas = document.getElementById('table').rows;   
    var i = 0;   
    for (i= linhas.length-1; i>=0; i--){
		document.getElementById('table').deleteRow(i);   
	}
}
function imageExists(url){
	var tmp=new Image;
	tmp.src=url;
	if(tmp.height>0){
		return true;
	}else{
		return false;
	}
 }
 
