var DIR="";

if (location.href.indexOf('sublimemaster')>0) {DIR = "/cdrmedios";}
var imgs=DIR+"/artworks";

function abrirVentana(url, width, height, name) {
	if (name==null) {name='nueva_ventana';}
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	str += ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";

	objwin=window.open(url, name, str);
	objwin.focus();
}
function abrirVentana2(url, width, height, name) {
	if (name==null) {name='nueva_ventana';}
	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if (window.screen) {
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
	}

	str += ",toolbar=yes,location=no,directories=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no";

	objwin=window.open(url, name, str);
	objwin.focus();
}

function getObj(id) {if (document.getElementById) {return document.getElementById(id)}	else if (document.all) {return document.all[id]}	else {return document.all[id]}}

function rnd(max) {
	var x = Math.random() * max;
	x = x + 1;
	return parseInt(x);
}


function goprint(url) {
	abrirVentana(url, 720, 450, "_imprimir")
}

function validar_login(formulario, msg) {
	if (formulario.usuario.value == '' || formulario.clave.value == '') { alert(msg); formulario.usuario.focus(); return false; }
	return true;
}

function validar_olvidemiclave(form) {
	if (form.email.value.indexOf('@') < 0 || form.email.value.indexOf('.') < 0 || form.email.value.indexOf(',') > 0) { alert('Email incorrecto'); form.email.focus(); return false; }
	return true;
}

function unhide_cargando() {
	ly=getObj("layer_cargando_ampliacion");
	ly.style.visibility="hidden";
}
function showfoto(f,d) {
	ly=getObj("layer_cargando_ampliacion");
	ly.style.visibility="visible";
	i=getObj("foto_ampliacion");
	i.src=f;
	if (d!="") {
		d="<table bgcolor='#000000' width='100%' cellspacing='0' cellpadding='0' border='0' height='18'><tr><td width='3'></td><td><font class='verysmalltext'>"+d+"</font></td><td width='3'></td></tr></table>";
	}
	s=getObj("desc_foto");
	s.innerHTML=d;

}

function updown_carrito(despl,id,limit) {
	if (limit==null) {limit=0;}
	var objcant=getObj("cantidad_"+id);
	if (isNaN(objcant.value)) {objcant.value=1;return;}
	var cant=objcant.value;
	cant=parseInt(cant)+despl;
	if (cant<limit) {cant=limit;}
	objcant.value=cant;
}

function set_off_cart() {
	var img=DIR+"/artworks/lab_cart_tucompra.gif";
	obj=window.parent.document.getElementById("icocart");
	if (obj!=null) {obj.src=img;}
	var img=DIR+"/artworks/back_cart.gif";
	obj=window.parent.document.getElementById("background_cart");
	if (obj!=null) {obj.background=img;}
}

function set_on_cart() {
	var img=DIR+"/artworks/lab_cart_tucompra_on.gif";
	obj=window.parent.document.getElementById("icocart");
	if (obj!=null) {if (obj.src.indexOf("_on")==-1) {obj.src=img;}}
	var img=DIR+"/artworks/back_cart_on.gif";
	obj=window.parent.document.getElementById("background_cart");
	if (obj!=null) {obj.background=img;}
}

function check_buscar(obj) {
	if (obj.buscar.value=="" || obj.buscar.value=="Ej. ") {alert("Ingrese las palabras a buscar");obj.buscar.focus();return false;} else {return true;}
}

function open_prod(url,idprod) {
	wname="prod"+rnd(10000);
	obj=getObj("opentype1");
	if (obj==null) {location.href=url;return;}

	if (getObj("opentype1")!=null) {

		if (getObj("opentype1").checked) {
			tipo=1;
		} else if (getObj("opentype2").checked) {
			tipo=2;
		} else {
			tipo=3;
		}

	} else {
		tipo=1;
	}


	if (tipo==1) {
		location.href=url+"&opentype="+tipo;
	} else if (tipo==2) {
		abrirVentana(url+"&opentype="+tipo, 730, 400, wname);
	} else {
		servOC(idprod, url+"&opentype="+tipo);
	}

}

function open_prod_ventana(url) {
	wname="prod"+rnd(10000);
	abrirVentana(url+"&imprimir=ok&opentype=2", 730, 400, wname);
}

function contactar(url) {
	window.close();
	window.opener.location.href=url;
}

function ShowAndCenterLayerParent(id) {

	obj=getObj(id);
	if (obj==null) {obj=window.parent.document.getElementById(id);}
	ancho_layer=obj.style.width;
	ancho_layer=ancho_layer.replace("px","");
	alto_layer=obj.style.height;
	alto_layer=alto_layer.replace("px","");

	var X = ((window.parent.document.body.scrollWidth-alto_layer)/2);
	var Y = ((window.parent.screen.availHeight-alto_layer)/2);

	obj.style.zIndex=1001;
	obj.style.visibility="visible";
	obj.style.left=(window.parent.document.body.scrollLeft+(X))-100;
	obj.style.top =(window.parent.document.body.scrollTop +(Y))-100;

}

function logout(url) {
	if (window.confirm("Usted ha preferido ser recordado en este PC.\nEn caso de continuar, su opción de recordar datos se perderá.\nPara conservarla, simplemente presione cancelar y cierre su navegador de internet.\n¿ desea continuar de todos modos ?")) {
		location.href=url;
	}
}

var altura=300;
var step=altura/5;
var retardo=40;
var smooth_timer;

function servOC(i, href) {

  ifObj=getObj("ihif"+i);
  trObj=getObj("ihtr"+i);

 if (trObj != null) {
    if (trObj.style.display=="none") {
      trObj.style.display="";
      ifObj.src=href;
      smoothHeight('ihif' + i, 0, altura, step, 'o');
    }
    else {
      smoothHeight('ihif' + i, altura, 0, step, 'ihtr' + i);
    }
 }
}

function smoothHeight(id, curH, targetH, stepH, mode) {
  diff = targetH - curH;
  if (diff != 0) {
    newH = (diff > 0) ? curH + stepH : curH - stepH;
    ((document.getElementById) ? document.getElementById(id) : eval("document.all['" + id + "']")).style.height = newH + "px";
    if (smooth_timer) {
    	window.clearTimeout(smooth_timer);
    }
    smooth_timer = window.setTimeout( "smoothHeight('" + id + "'," + newH + "," + targetH + "," + stepH + ",'" + mode + "')", retardo );
  }
  else if (mode != "o") ((document.getElementById) ? document.getElementById(mode) : eval("document.all['" + mode + "']")).style.display="none";
}


function nav(ind,id,navegar,abriendo_init) {

	if (typeof navegar == "undefined") {navegar=true;}
	if (typeof abriendo_init == "undefined") {abriendo_init=false;}

	aux=id.split(".");
	pos=aux.length

	veccat=eval("veccat"+ind);
	vecfound=Array();
	vectodos=Array();
	p=0;
	t=0;

	for (i=0;i<veccat.length;i++) {
		muestra=veccat[i];
		muestra=muestra.substr(0,id.length+1);
		if (id+"."==muestra) {

			found=veccat[i];

			aux=found.split(".");
			ident=aux.length;

			if (ident==(pos+1)) {
				vecfound[p]=found;
				p++;
			}
			vectodos[t]=found;
			t++;

		}
	}


	if (pos>2 && vecfound.length>0) {

		o=getObj("tabla_"+vecfound[0]);
		if (o.style.display=="none") {
			//ABRIR mostrar solo este nivel
			for (i=0;i<vecfound.length;i++) {
				o=getObj("tabla_"+vecfound[i]);
				o.style.display="";
			}


		} else {

			if (!abriendo_init) {
				//CERRAR - ocultar todos los hijos y subhijos
				for (i=0;i<vectodos.length;i++) {
					o=getObj("tabla_"+vectodos[i]);
					o.style.display="none";
				}
			}

		}

	} else {

		if (navegar && vecfound.length==0) {
			var url=DIR+"/productos/resultado.php?n="+ind+"&path="+id;
			//alert(url);
			location.href=url;
		} else {
			//podes aprovechar el else para marcar la categoria o algo
		}

	}

}

function set_cat(ind,path) {

	var vari,aux_path;

	aux_path=path.split(".");
	path_actual=aux_path[0]+"."+aux_path[1]+"."+aux_path[2];
	nav(ind,path_actual,false,true);
	for (vari=3;vari<aux_path.length;vari++) {
		path_actual+="."+aux_path[vari];
		nav(ind,path_actual,false,true);
	}

}


ind_dest=0;

function dest_left() {
	if (ind_dest==0) {ind_dest=vecdest.length-1;} else {ind_dest=ind_dest-1;}
	show_dest();
}

function dest_right() {
	if (ind_dest>=vecdest.length-1) {ind_dest=0;} else {ind_dest++;}
	show_dest();
}

function show_dest() {
	for (var i=0;i<vecdest.length;i++) {
		var n=vecdest[i];
		var o=getObj("superdestacado"+n);
		if (i==ind_dest) {
			o.style.display="";
		} else {
			o.style.display="none";
		}
	}
}

function cat_select(c) {
	alert(c);
}

function select_combo_default(id) {
	cargar_url(DIR+"/productos/productos_destacados_home.php?id_categoria="+id, "destacados_cont", "POST", "Sublime_InitScrollableArea()");
}

function validar_recomendar(form) {

	if (form.miemail.value.indexOf('@') < 0 || form.miemail.value.indexOf('.') < 0 || form.miemail.value.indexOf(',') > 0) { alert('Indique su email'); form.miemail.focus(); return false; }
	if (form.minombre.value == '') { alert('Indique su nombre'); form.minombre.focus(); return false; }
	if (form.tuemail.value.indexOf('@') < 0 || form.tuemail.value.indexOf('.') < 0 || form.tuemail.value.indexOf(',') > 0) { alert('Indique el email de la persona a la cual nos recomienda'); form.tuemail.focus(); return false; }
	if (form.tunombre.value == '') { alert('Indique el nombre de la persona a la cual nos recomienda'); form.tunombre.focus(); return false; }

	return true;
}
