/*
 * Función que habre un pop up 
 */
  
function openPopUp(url, title, width, height)
{		
	window.open(url, title, 'scrollbars=no,resizable=no,width='+width+',height='+height+'');
}

function openPopUpAmpliacion(url, title)
{
	window.open(url, title, 'scrollbars=no,resizable=no,width=330,height=300');
}

function openPopUpCondiciones()
{
    window.open('condiciones-generales.php', 'CONDICIONES', 'scrollbars=yes,resizable=no,width=400,height=400');
}

function rewriteUrlCestaSabores(idproducto)
{	
	var select = document.getElementById('sabor');
	if(select.value == -1)
	{
		//Mostramos un mensaje de error y ponemos que la cesta no vaya a ningun lado
		alert('Stock agotado para el producto seleccionado.');
		enlace = document.getElementById('anadir_cesta');
		enlace.href="javascript:alert('Debe seleccionar un sabor.');";	
		select.selectedIndex = 0;		
	}
	else if(select.index == 0)
	{
		alert('Debe seleccionar un sabor.');
		//var carrito = new SWFObject("icono-comprar.swf", "icono-comprar.swf", "120", "50", "7");
		//carrito.addVariable("url","javascript:alert('Debe seleccionar un sabor.')");
		//carrito.write("comprar");
		enlace = document.getElementById('anadir_cesta');
		enlace.href="javascript:alert('Debe seleccionar un sabor.');";	
		select.selectedIndex = 0;	
	}
	else
	{			
		var carrito = new SWFObject("icono-comprar.swf", "icono-comprar.swf", "120", "50", "7");		
		url = "idproducto="+idproducto+"-"+select.value;	
		enlace = document.getElementById('anadir_cesta');
		enlace.href="cesta-de-compra-form.php?"+url;
	}
}

function rewriteUrlCestaTallas(idproducto)
{		
	var select = document.getElementById('talla');
	if(select.value == -1)
	{
		//Mostramos un mensaje de error y ponemos que la 
		alert('Stock agotado para el producto seleccionado.');
		//Hacemos que la ceste no apunte a nada
		var carrito = new SWFObject("icono-comprar.swf", "icono-comprar.swf", "120", "50", "7");
		carrito.addVariable("url","javascript:alert('Debe seleccionar una talla.')");
		carrito.write("comprar");
		select.selectedIndex = 0;		
	}
	else if(select.index == 0)
	{
		alert('Debe seleccionar un sabor.');
		var carrito = new SWFObject("icono-comprar.swf", "icono-comprar.swf", "120", "50", "7");
		carrito.addVariable("url","javascript:alert('Debe seleccionar una talla.')");
		carrito.write("comprar");
	}
	else
	{			
		var carrito = new SWFObject("icono-comprar.swf", "icono-comprar.swf", "120", "50", "7");		
		url = "idproducto="+idproducto+"-"+select.value;		
		carrito.addVariable("url","cesta-de-compra-form.php?"+url);
		carrito.write("comprar");
	}
}

//############## NOVEDADES ###################//
var effect;
var alternativos = new Array(6);
var posicion_alt = 0;

alternativos[0] = "Nutricion para el deporte";
alternativos[1] = "Alimentacion deportiva";
alternativos[2] = "Suplementos alimenticios";
alternativos[3] = "Nutricion deportiva";
alternativos[4] = "Tienda de nutricion deportiva online";
alternativos[5] = "Tienda de suplementos de nutrición deportiva";

function avanzaNovedad()
{	
	if(pos_totales > 1)
	{
		var div = document.getElementById('div_imagen');
		div.style.display = "none";	
		effect.cancel();
		clearTimeout(t);
		pos_actual++;
		if(pos_actual == pos_totales) pos_actual = 0;
		loadNovedad(pos_actual);	
	}
}

function retrocedeNovedad()
{	
	if(pos_totales > 1)
	{
		var div = document.getElementById('div_imagen');
		div.style.display = "none";	
		effect.cancel();	
		clearTimeout(t);
		pos_actual--;
		if(pos_actual < 0) pos_actual = (pos_totales-1);		
		loadNovedad(pos_actual);		
	}
}

function loadNovedad(numero)
{		
	//Cambiamos la imagen
	var img = document.getElementById('imagen');
	//var tit = document.getElementById('titulo');
	//var text = document.getElementById('texto');
	//var prod = document.getElementById('producto');
	//var link_prod = document.getElementById('link_producto');
	var link_prod2 = document.getElementById('link_prod2');
	//var fab = document.getElementById('fabricante');
	//var link_fab = document.getElementById('link_fabricante');
	
	img.src = imagen[pos_actual];
	img.alt = alternativos[posicion_alt];
	posicion_alt++;
	if(posicion_alt>5)
		posicion_alt = 0;
	effect = new Effect.Appear('div_imagen', { duration: 0.5 });
	if(pos_totales > 1)
		timeOut();
	//tit.innerHTML = titulo[pos_actual];
	//text.innerHTML = texto[pos_actual];
	//prod.innerHTML = producto[pos_actual];
	//link_prod.href = "producto.html?idproducto="+idproducto[pos_actual];
	link_prod2.href = "producto.php?idproducto="+idproducto[pos_actual];
	//fab.innerHTML = fabricante[pos_actual];
	//link_fab.href = "productos.html?idfab="+idfabricante[pos_actual];	
}

function timeOut()
{
	t = setTimeout("avanzaNovedad()",15000);
}


