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 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(getUrlPrint(url), 630, 500, "_imprimir")
}
function getUrlPrint(url) {
	var aux=url.split("?");
	var dir=aux[0];

	if (aux.length>1) {
		aux=aux[1].split("&");
		n="";
		for (var i=0;i<aux.length;i++) {
			v=aux[i].split("=");
			if (v[0]!="opentype") {
				if (n!="") {n+="&";}
				if (v.length==1) {
					n+=v[0];
				} else {
					n+=v[0]+"="+v[1];
				}
			}
		}
		if (n!="") {dir+="?"+n;}
	}
	return dir;
}

con_actual=1;

function prev_cons() {
	con_actual=con_actual-1;
	if (con_actual<0) {con_actual=consejos.length - 1;}
	show_consejo();
}

function next_cons() {
	con_actual=con_actual+1;
	if (con_actual>consejos.length-1) {con_actual=0;}
	show_consejo();
}

function show_consejo() {

	vec=consejos[con_actual];

	o=getObj("consejo_descripcion");
	o.innerHTML=vec[4];

	o=getObj("consejo_titulo");
	o.innerHTML=vec[3];

	o=getObj("consejo_copete");
	o.innerHTML=vec[2];

	writeflash2("ly_consejos",DIR+"/artworks/flash/consejos_fotos.swf?"+Math.random(),"65","150","DIR="+DIR+"&imgtoload="+vec[1],"obj_consejos");

}

function check_email(form) {
	if (form.email.value.indexOf('@') < 0 || form.email.value.indexOf('.') < 0 || form.email.value.indexOf(',') > 0) { alert('Dirección de correo incorrecta.'); form.email.focus(); return false; }
	return true;
}

function download(id) {
	url=DIR+"/scripts/download.php?id="+id+"&"+Math.random();
	window.open(url);
}

var cargando_pager=false;

function GoPage(url,p,ly) {
	if (cargando_pager) {return;}
	url_pager=DIR+"/ayax/"+url+"pagina="+p
	cargando_pager=true;
	cargar_url(url_pager,ly,"POST","reset_cargando()");
}

function reset_cargando() {
	cargando_pager=false;
}


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 (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) {
			location.href=DIR+"/productos/resultado.php?n="+ind+"&path="+id;
		} 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);
	}

}

function check_buscar(form) {
	if (form.buscar.value=="") {alert("Ingrese el texto a buscar");return false;}
	if (form.buscar.value.length<4) {alert("Texto a buscar muy corto");return false;}
	return true;
}

function validar_recomendar(form) {

	if (form.miemail.value.indexOf('@') < 0 || form.miemail.value.indexOf('.') < 0 || form.miemail.value.indexOf(',') > 0) { alert('Email incorrecto'); form.miemail.focus(); return false; }
	if (form.minombre.value == '') { alert('Faltan datos'); form.minombre.focus(); return false; }
	if (form.tuemail.value.indexOf('@') < 0 || form.tuemail.value.indexOf('.') < 0 || form.tuemail.value.indexOf(',') > 0) { alert('Email incorrecto'); form.tuemail.focus(); return false; }
	if (form.tunombre.value == '') { alert('Faltan datos'); form.tunombre.focus(); return false; }

	var o=getObj("layer_tellafriend");
	o.style.visibility="hidden";

	return true;
}

function add_to_cart(id_variante) {
	var iframe=getObj("carrito_contenido");
	if (iframe!=null)
		iframe.src=DIR+"/productos/layout/cart_content.php?id_variante="+id_variante+"&r="+Math.ceil(100000*Math.random())

}

function add_to_cart_pv(id_variante) {
	var o=getObj("pv"+id_variante);
	if (o==null) return;
	cant=o.value;
	medida=getObj("medida"+id_variante).value;
	if (cant=="" || isNaN(cant)) {
		DHTMLALERT("Ingrese la cantidad de "+medida+", ej: 100 (correcto) - 1,00 (incorrecto)");
		o.focus();
		return;
	}
	var iframe=getObj("carrito_contenido");
	if (iframe!=null)
		iframe.src=DIR+"/productos/layout/cart_content.php?id_variante="+id_variante+"&pv="+cant+"&r="+Math.ceil(100000*Math.random())

}

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;
}


	var abriendo=0;

	function display_undisplay_opciones(id) {
		abriendo=id;
		find_trs(getObj("tabla_opciones"));
	}

	function find_trs(o) {

			var i,childs;

			childs=o.childNodes;
			for (i=0;i<childs.length;i++) {
					if ((typeof childs[i].lang == "string") && (childs[i].lang != "")) {
							if (abriendo==childs[i].lang) {
								if (childs[i].style.display=="none")
									childs[i].style.display="";
								else
									childs[i].style.display="none";
							}
					}
					find_trs(childs[i]);
			}

			return;

	}


function DHTMLALERT(msg)
{
	var dalert_msg = getObj("dhtml_alert_MSG");
	if (!dalert_msg)
		return;
	if (msg!="")
	{
		dalert_msg.innerHTML = msg;
		centerdhtmlalert("dhtml_alert");
	} else {
		var dalert = getObj("dhtml_alert");
		dalert_msg.innerHTML = "";
		dalert.style.display="none";
		try {
			obj_focus.focus();
			obj_focus=null;
		} catch(err) {}

	}

}

function centerdhtmlalert() {

	obj=getObj("dhtml_alert");
	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.display="";
	obj.style.visibility="visible";
	obj.style.left=((window.parent.document.body.scrollLeft+(X))-100)+"px";
	obj.style.top =((window.parent.document.body.scrollTop +(Y))-100)+"px";

}

var win= null;
function openfaq(url,w,h,name){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	settings='height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,toolbar=yes,resizable=yes'
	win=window.open(url,name,settings)
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}


function DHTMLALERT2(msg)
{
	var dalert_msg = getObj("dhtml_alert_MSG2");
	if (!dalert_msg)
		return;
	if (msg!="")
	{
		dalert_msg.innerHTML = msg;
		centerdhtmlalert2("dhtml_alert2");
	} else {
		var dalert = getObj("dhtml_alert2");
		dalert_msg.innerHTML = "";
		dalert.style.display="none";
		try {
			obj_focus.focus();
			obj_focus=null;
		} catch(err) {}

	}

}

function call_reset_prod() {
	document.getElementById("frame_carrito").contentWindow.quitar_producto(); 
	return;
}

function centerdhtmlalert2() {

	obj=getObj("dhtml_alert2");
	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.display="";
	obj.style.visibility="visible";
	obj.style.left=((window.parent.document.body.scrollLeft+(X))-100)+"px";
	obj.style.top =((window.parent.document.body.scrollTop +(Y))-100)+"px";

}

