var destacados_pag_actual=0;
var hrefs_productos=new Array();
var last_tr_orden="";
function set_precio_variante(id_producto) {
at1 = getObj("id_atributo1"+id_producto);
if (at1==null) return;
at2 = getObj("id_atributo2"+id_producto);
if (at2==null) return;
id_atributo1 = at1.value;
id_atributo2 = at2.value;
if (id_atributo1==0 || id_atributo1=="") return;
if (id_atributo2==0 || id_atributo2=="") return;
pr = getObj("pr_"+id_producto+"_"+id_atributo1+"_"+id_atributo2);
pa = getObj("pa_"+id_producto+"_"+id_atributo1+"_"+id_atributo2);
if (pr==null) return;
if (pa==null) return;
pr = parseFloat(pr.value);
pa = parseFloat(pa.value);
cont_pa = getObj("cont_pa"+id_producto);
str_pa = getObj("str_pa"+id_producto);
str_pa_deci = getObj("str_pa_deci"+id_producto);
str_pr = getObj("str_pr"+id_producto);
str_pr_deci = getObj("str_pr_deci"+id_producto);
cont_sin_pa = getObj("cont_sin_pa"+id_producto);
if (cont_pa == null) return;
if (str_pa == null) return;
if (str_pa_deci == null) return;
if (str_pr == null) return;
if (str_pr_deci == null) return;
if (cont_sin_pa == null) return;
if (pa <= pr) {
cont_pa.style.display="none";
cont_sin_pa.style.display="";
} else {
cont_pa.style.display="";
cont_sin_pa.style.display="none";
}
if (parseInt(pa)!=pa) {
m = (pa + "").split(".");
d = m[1];
if (d.length==1) d+="0";
str_pa_deci.innerHTML=","+d;
str_pa_deci.style.display="";
} else {
str_pa_deci.innerHTML="";
str_pa_deci.style.display="none";
}
m = Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(pa).split(",");
n = m[0];
str_pa.innerHTML = n;
if (parseInt(pr)!=pr) {
m = (pr + "").split(".");
d = m[1];
if (d.length==1) d+="0";
str_pr_deci.innerHTML=","+d;
str_pr_deci.style.display="";
} else {
str_pr_deci.innerHTML="";
str_pr_deci.style.display="none";
}
m = Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(pr).split(",");
n = m[0];
str_pr.innerHTML = n;
cont_dto_esp = getObj("cont_dto_esp_"+id_producto);
dto_esp = getObj("dto_esp_"+id_producto);
if (cont_dto_esp == null) return;
if (dto_esp == null) return;
if ( pa > pr && pa>0 ) {
porc = ((Math.round(pa - pr)) * 100) / pa;
porc = Math.round(Math.abs(porc));
cont_dto_esp.className = "descuento_especial";
dto_esp.innerHTML = porc;
} else {
cont_dto_esp.className = "descuento_especial vh";
}
}
function eliminar_guardado(producto)
{
if (window.confirm(""))
{
url="/productos/cart/includes/eliminar_guardar_para_despues.php?producto="+producto;
crear_script_tag(url,"cart");
}
}
function orden_ver_mas(id_orden)
{
var tr=getObj("tr_orden1"+id_orden);
if (tr.style.display=="")
{
tr.style.display="none";
}
else
{
tr.style.display="";
}
}
function select_marca_alt(id_marca,path)
{
if (id_marca>0)
{
var url=DIR+"/productos/productos.php?secc=productos&id_marca2="+id_marca+"&path="+path;
location.href=url;
}
}
var last_id_superdest=0;
var last_label_superdest="";
function get_superdestacados(id,l)
{
if (last_id_superdest>0) {
var o=getObj("option_cat"+last_id_superdest);
var link=""+last_label_superdest+"";
o.innerHTML=link;
}
var o=getObj("option_cat"+id);
var link=""+l+"";
o.innerHTML=link;
var o=getObj("nombre_cat_seleccionada");
o.innerHTML=l;
last_id_superdest=id;
last_label_superdest=l;
cargar_url_ayax(DIR+"/productos/resumenes/resumen_para_ayax.php?id_categoria="+id, "cont_superdestacados", "POST", "reset_nav_prods()");
}
function reset_nav_prods()
{
var o=getObj("categorias_combo");
if (o!=null) o.style.display="none";
var o=getObj("combo_cat_super");
if (o!=null) o.className="combocont comboseleccionado";
}
function normalizar_nombre_cat(orig)
{
str = new String(orig);
rExp = "/'/g";
rExp = eval(rExp);
newS = String("\\u0027");
str = new String(str.replace(rExp, newS));
return str;
}
function show_list_combo_dinamico()
{
var o=getObj("categorias_combo");
if (o==null) return;
if (o.style.display=="none") o.style.display=""; else o.style.display="none";
}
function checkout_cart(id)
{
var o=getObj("ir_al_final_directo"+id);
if (o!=null) {
o.value=1;
var o=getObj("btn_agregar_cart"+id);
if (o!=null) {
o.click();
}
}
}
var cont_nombre_atributo_marcas=new Array();
function seleccionar_atributo(grupo,id_attr,prod,indice_atr,label,id_categoria_atributo)
{
var o;
for (i=0;i < variantes_activas.length;i++) {
variante=variantes_activas[i];
keyvar=variante[0];
activa=variante[1];
aux=keyvar.split("_");
attr1=aux[0];
attr2=aux[1];
if (grupo==0 && id_attr==attr1) {
//oculto y desoculto al atributo2 si lo hay
if (activa==1) dsp=""; else dsp="none";
o=getObj("div_cont_atributo1"+attr2);
if (o!=null) o.style.display=dsp;
o=getObj("cont_nombre_atributo_1_"+attr2);
if (o!=null) o.style.display=dsp;
o=getObj("id_atributo2"+prod);
if (o!=null) o.value="0";
o=getObj("elemento_sel_atr1");
if (o!=null) {
lbl="";
l=getObj("label_atributo2");
if (l!=null) lbl=l.value;
o.innerHTML=lbl;
}
//recuperar el color que estaba seleccionado
} else if (grupo==1 && id_attr==attr2) {
}
}
if (typeof id_categoria_atributo=="undefined") id_categoria_atributo=0;
for (var i=0;i < atributos.length;i++) {
if (atributos[i][0]==grupo) {
o=getObj("div_cont_atributo"+grupo+atributos[i][1]);
if (o!=null) o.className="item";
}
}
o=getObj("div_cont_atributo"+grupo+id_attr);
if (o!=null) o.className="item seleccionado";
if (grupo==0) {
id_atributo1_preseleccionado=id_attr;
v=getObj("id_atributo1"+prod);
} else {
id_atributo2_preseleccionado=id_attr;
v=getObj("id_atributo2"+prod);
}
if (v!=null) v.value=id_attr;
i=id_atributo1_preseleccionado+"_"+id_atributo2_preseleccionado;
try {
vec_precio=precios_atributos[i];
} catch (e) {
vec_precio=Array(0,0);
}
if (typeof vec_precio!="undefined" && parseFloat(vec_precio[0]) <= 0) {
if (getObj("btn_agregar_cart"+prod)!=null) getObj("btn_agregar_cart"+prod).value="";
if (getObj("producto_agotado")!=null) getObj("producto_agotado").style.display="";
if (getObj("contenedor_precio_anterior")!=null) getObj("contenedor_precio_anterior").style.display="none";
if (getObj("precio_ent_actual")!=null) {getObj("precio_ent_actual").innerHTML="";getObj("precio_dec_actual").innerHTML="";}
}
if (typeof codigos[i] != "undefined") {
o=getObj("codigo_producto0");
if (o!=null) o.innerHTML=codigos[i];
for (ind=1;ind < 10;ind++) {
o=getObj("codigo_producto"+ind);
if (o!=null) o.innerHTML=": "+codigos[i];
}
}
if (typeof vec_precio != "undefined")
{
precio=""+vec_precio[0];
precio_anterior=""+vec_precio[1];
o=getObj("contenedor_precio_anterior");
if (o!=null) {
if (parseFloat(precio_anterior)!=parseFloat(precio) && parseFloat(precio_anterior) > 0 && parseFloat(precio) < parseFloat(precio_anterior)) {
o.style.display="";
} else {
o.style.display="none";
}
}
o=getObj("precio_ent_actual");
if (o!=null) {
aux=precio.split(".");e=aux[0];d=aux[1];
if (typeof d != "undefined") if (d.length==1) d=d+"0";
m = Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(e).split(",");
e = m[0];
getObj("precio_ent_actual").innerHTML=e;
getObj("precio_dec_actual").innerHTML=""+d;
if (precio!=parseInt(precio)) getObj("precio_dec_actual").style.display=""; else getObj("precio_dec_actual").style.display="none";
}
o=getObj("precio_ent_anterior");
if (o!=null) {
aux=precio_anterior.split(".");e=aux[0];d=aux[1];
if (typeof d != "undefined") if (d.length==1) d=d+"0";
m = Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(e).split(",");
e = m[0];
getObj("precio_ent_anterior").innerHTML=e;
getObj("precio_dec_anterior").innerHTML=""+d;
if (precio_anterior!=parseInt(precio_anterior)) getObj("precio_dec_anterior").style.display=""; else getObj("precio_dec_anterior").style.display="none";
}
o=getObj("contenedor_precio_actual");
if (o!=null) {
if (parseFloat(precio) > 0 ) {
o.style.display="";
} else {
o.style.display="none";
}
}
str_dto_especial = getObj("str_dto_especial");
pr = parseFloat(precio);
pa = parseFloat(precio_anterior);
if ( pa > precio && pa>0 ) {
porc = ((Math.round(pa - pr)) * 100) / pa;
porc = Math.round(Math.abs(porc));
if (getObj("descuento_especial")!=null) getObj("descuento_especial").style.display="";
if (str_dto_especial!=null) str_dto_especial.innerHTML=porc;
} else {
if (getObj("descuento_especial")!=null) getObj("descuento_especial").style.display="none";
if (str_dto_especial!=null) str_dto_especial.innerHTML="";
}
o=getObj("frmaddcart"+prod);
if (o!=null) {
if (parseFloat(precio) > 0 ) {
o.style.display="";
} else {
o.style.display="none";
}
}
/*
o=getObj("producto_agotado");
if (o!=null) {
if (parseFloat(precio) > 0 ) {
o.style.display="none";
} else {
o.style.display="";
}
}
*/
}
o=getObj("atributo_navegacion_alternativa"+grupo);
if (o!=null) o.style.display="none";
o=getObj("elemento_sel_atr"+grupo);
if (o!=null) o.innerHTML=label;
o=getObj("atributo_nombre"+id_categoria_atributo);
if (o!=null) o.innerHTML=": "+label;
if (typeof cont_nombre_atributo_marcas[grupo] == "undefined") {
cont_nombre_atributo_marcas[grupo]=id_attr;
}
var id_marcacion_anterior=cont_nombre_atributo_marcas[grupo];
var id_marcacion_actual=id_attr;
o=getObj("cont_nombre_atributo_"+grupo+"_"+id_marcacion_anterior);
if (o!=null) {
el=str_replace(o.innerHTML,"","");
el=str_replace(el,"","");
o.innerHTML=el;
}
o=getObj("cont_nombre_atributo_"+grupo+"_"+id_attr);
if (o!=null) {
o.innerHTML=""+o.innerHTML+"";
}
cont_nombre_atributo_marcas[grupo]=id_attr;
}
function str_replace_on_prods(str, sear, repl)
{
return str.split(sear).join(repl);
}
var cant_cart_alt_anterior=1;
function set_cant_alt(i,id) {
o=getObj("cantidad_"+id);
if (o!=null) o.value=i;
o=getObj("productos_compra_cantidad_selector");
if (o!=null) o.style.display="none";
o=getObj("cant_seleccionada_alt");
if (o!=null) o.innerHTML=i;
o=getObj("cant_cart_alt"+cant_cart_alt_anterior);
if (o!=null) {
el=str_replace(o.innerHTML,"","");
el=str_replace(el,"","");
o.innerHTML=el;
}
o=getObj("cant_cart_alt"+i);
if (o!=null) {
o.innerHTML=""+o.innerHTML+"";
}
cant_cart_alt_anterior=i;
o=getObj("cont_add_unidades");
if (o!=null) {
if (id_unidad_de_medida==1) mult=100; else mult=1;
lbl="" + " " + (unidad_minima_de_medida*i*mult) + " " + nombre_unidad_medida;
o.innerHTML=lbl;
}
}
function check_preguntar(form)
{
if (form.pregunta.value=="") {
DHTMLALERT("");
return false;
}
form.btnpreguntar.disabled=true;
return true;
}
var colores_seleccionados=new Array();
function set_color_producto_foto(id_producto,id_color)
{
var img=getObj("img_producto"+id_producto);
if (img==null) return;
if (typeof array_fotos_colores == "undefined") return;
if (typeof array_fotos_colores[id_producto] == "undefined") return;
var colores=array_fotos_colores[id_producto];
if (typeof colores[id_color] == "undefined") return;
var foto_color=colores[id_color];
var id_foto=foto_color[0];
var ext=foto_color[1]
var src=img.src;
var last_ocurr=src.lastIndexOf("_");
var new_img=src.substring(0,last_ocurr+1)+id_foto+"."+ext;
img.src=new_img;
img.srcset=new_img+" 1x,"+new_img+" 2x,"+new_img+" 3x";
colores_seleccionados[id_producto]=id_color;
}
function nav_prod_masinfo(obj_href,id_producto)
{
if (typeof colores_seleccionados[id_producto] == "undefined")
{
return;
}
var url=obj_href.href;
if (url.indexOf("?")==-1)
{
add_url="?";
} else {
add_url="&";
}
obj_href.href+=add_url+"selcolor="+colores_seleccionados[id_producto];
return;
}
function nav_prod_masinfo_button(url,id_producto)
{
if (typeof colores_seleccionados[id_producto] == "undefined") {
location.href=url;
return;
}
if (url.indexOf("?")==-1) {
add_url="?";
} else {
add_url="&";
}
var new_url=url+add_url+"selcolor="+colores_seleccionados[id_producto];
location.href=new_url;
return;
}
function change_pais(id_pais)
{
var o=getObj("tr_DESTINARIO_id_departamento");
if (o==null) return;
if (id_pais==858) var dsp=""; else var dsp="none";
o.style.display=dsp;
}
function activar_datos_extra(codigo)
{
var o=getObj("datos_CUY");
if (o!=null) {
if (codigo=="CUY") {
url="/productos/cart/includes/calc_peso_cuy.php";
crear_script_tag(url,"cartpeso");
} else {
o.style.display="none";
}
}
}
var flag_dir_cuy_modificada=false;
function cp_cuy_data(direccion,dest) {
var o=getObj(dest);
if (o==null) return;
o.value=direccion;
}
function cp_cuy_dir(direccion)
{
var o=getObj("CUY_calle");
if (o==null) return;
if (o.value=="" || !flag_dir_cuy_modificada) {
o.value=direccion;
}
}
function dir_cuy_modificada()
{
flag_dir_cuy_modificada=true;
}
function check_formas_de_pago(id_envio) {
return;
}
function marcar_pago_envio(contenedor, nom_clase)
{
if (contenedor.split("_").length==1)
return;
var nom_contenedor = contenedor.split("_")[0];
var id_contenedor = parseInt(contenedor.split("_")[1]);
for (var i=0;i < 200;i++)
{
if (getObj(nom_contenedor+"_"+i)!=null)
{
aplicar_quitar_clase(nom_contenedor+"_"+i, nom_clase, 1);
}
}
aplicar_quitar_clase(contenedor,nom_clase);
if (nom_contenedor=="pago")
{
if(getObj("formadepago"+id_contenedor) && !getObj("formadepago"+id_contenedor).checked)
getObj("formadepago"+id_contenedor).click();
}
if (nom_contenedor=="envio")
{
if(getObj("formadeenvio"+id_contenedor) && !getObj("formadeenvio"+id_contenedor).checked)
getObj("formadeenvio"+id_contenedor).click();
}
}
var ultima_vista_producto = -1;
function set_vista_productos(modo, f_forzar)
{
if (!f_forzar && ultima_vista_producto==modo) return;
ultima_vista_producto = modo;
var url="/productos/tools/set_vista_productos.php?ID_SESSION_USR=&modo="+modo;
crear_script_tag(url,"get_vista_productos");
}
function generar_pdf(p)
{
DHTMLALERT('');
url="/productos/scripts/exportar_resultado_pdf.php?"+p;
crear_script_tag(url,"exportar_resultado_pdf");
}
var atr_seleccionados = new Array();
function set_attr_listado(id_producto,id_atributo,nroatr,invertir_atributos) {
if (typeof atr_seleccionados[id_producto]=="undefined") {
atr_seleccionados[id_producto]=new Array();
atr_seleccionados[id_producto][nroatr]=id_atributo;
}
if (invertir_atributos==1) {
if (nroatr==0) {
o=getObj("id_atributo2"+id_producto);
} else {
o=getObj("id_atributo1"+id_producto);
}
} else {
if (nroatr==0) {
o=getObj("id_atributo1"+id_producto);
} else {
o=getObj("id_atributo2"+id_producto);
}
}
if (o==null) return;
anterior = getObj("atributo_"+id_producto+"_"+atr_seleccionados[id_producto][nroatr]+"_"+nroatr);
actual = getObj("atributo_"+id_producto+"_"+id_atributo+"_"+nroatr);
if (anterior!=null) anterior.className="";
if (actual!=null) actual.className="atributo2_seleccionado";
atr_seleccionados[id_producto][nroatr]=id_atributo;
o.value=id_atributo;
o=getObj("str_stocks_atributo_"+id_producto+"_"+id_atributo+"_"+nroatr);
if (o==null) return;
atrstock=o.value.split(",");
for (i=0;i < atrstock.length;i++) {
aux=atrstock[i].split(":");
id_atributo2=aux[0];
stock=aux[1];
nro_atr_dest=aux[2];
if (stock>0) {
dsp="";
} else {
dsp="none";
}
o=getObj("atributo_"+id_producto+"_"+id_atributo2+"_1");
if (o!=null) o.style.display=dsp;
o=getObj("atributo_"+id_producto+"_"+id_atributo2+"_0");
if (o!=null) o.style.display=dsp;
}
set_precio_variante(id_producto);
}
function check_add_producto_listado(id_producto)
{
o=getObj("id_atributo1"+id_producto);
id_atributo1=o.value;
o=getObj("id_atributo2"+id_producto);
id_atributo2=o.value;
mensaje_falta_atributo1=getObj("mensaje_falta_atributo1"+id_producto)
mensaje_falta_atributo2=getObj("mensaje_falta_atributo2"+id_producto)
o=getObj("id_atributo1"+id_producto);
if (o==null || o.value=="0" || o.value=="") {
alerta_agregando_off();
DHTMLALERT(mensaje_falta_atributo1.value);
return false;
}
id_atributo1=o.value;
o=getObj("id_atributo2"+id_producto);
if ((o==null || o.value=="0" || o.value=="") && mensaje_falta_atributo2.value!="") {
alerta_agregando_off();
DHTMLALERT(mensaje_falta_atributo2.value);
return false;
}
id_atributo2=o.value;
return true;
}
function set_label_arribando(i) {
o=getObj("div_stock_arribando");
if (o==null) return;
if (i==0) {
o.innerHTML="";
o.style.display="none";
return;
}
if (typeof stock_proximos_arribos[i] != "undefined") {
s=stock_proximos_arribos[i];
if (s[0]==0) {
o.innerHTML="";
o.style.display="none";
} else {
l="Stock a arribar "+s[0]+" "+s[1];
o.innerHTML=l;
o.style.display="";
o=getObj("divstock2");
if (o!=null) o.style.display="none";
}
}
}