//DECORACION
function cargaDecoracion(selectACargar)
{
	// Recibo el número correspondiente al combo que se debe llenar de datos
	var selectAnterior=selectACargar-1; // Obtengo el número del combo que activó el evento onChange
	// Extraigo el valor del combo que se ha cambiado
	var valor=document.getElementById("select_"+selectAnterior).options[document.getElementById("select_"+selectAnterior).selectedIndex].value;
	valor = valor.split(";");
	var elemento;
	if(valor[0]!=0)
	{
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
		ajax.open("GET", "/inicio/ajax_decoracion.php?ID="+valor[0]+"&select="+selectACargar, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige" y pongo una que dice "Cargando"
				elemento=document.getElementById("select_"+selectACargar);
				elemento.length=0;
				var opcionCargando=document.createElement("option"); opcionCargando.value=0; opcionCargando.innerHTML="Cargando...";
				elemento.appendChild(opcionCargando); elemento.disabled=true;	
			}
			if (ajax.readyState==4)
			{
				// Coloco en la fila contenedora los datos que recivo del servidor
				document.getElementById("fila_"+selectACargar).innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}
	
	/* Colocamos mediante los whiles los selects en "Selecciona opción..." cuando el select anterior
	ha quedado en estado "Elige" */
	var x=1, y=null;
	while(x<=2)
	{
		valor=document.getElementById("select_"+x).options[document.getElementById("select_"+x).selectedIndex].value;
		valor = valor.split(";");
		if(valor[0]==0)
		{
			while(x<=2) 
			{
				y=x+1;
				elemento=document.getElementById("select_"+y);
				elemento.length=0;
				var opcionSelecciona=document.createElement("option"); opcionSelecciona.value=0; opcionSelecciona.innerHTML="Elige opci&oacute;n...";
				elemento.appendChild(opcionSelecciona); elemento.disabled=true;
				x++;
			}
		}
		x++;
	}
	
}
function cargaDecoracionTienda(selectACargar)
{
	// Recibo el número correspondiente al combo que se debe llenar de datos
	var selectAnterior=selectACargar-1; // Obtengo el número del combo que activó el evento onChange
	// Extraigo el valor del combo que se ha cambiado	
	var valor=document.getElementById("selecttienda_"+selectAnterior).options[document.getElementById("selecttienda_"+selectAnterior).selectedIndex].value;
	var elemento;
	
	if(valor!=0)
	{
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
		ajax.open("GET", "/decoracion/consulta_para_tienda.php?ID="+valor+"&select="+selectACargar, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga elimino la opcion "Elige" y pongo una que dice "Cargando"
				elemento=document.getElementById("selecttienda_"+selectACargar);
				elemento.length=0;
				var opcionCargando=document.createElement("option"); opcionCargando.value=0; opcionCargando.innerHTML="Cargando...";
				elemento.appendChild(opcionCargando); elemento.disabled=true;	
			}
			if (ajax.readyState==4)
			{
				// Coloco en la fila contenedora los datos que recivo del servidor
				document.getElementById("filatienda_"+selectACargar).innerHTML=ajax.responseText;
			} 
		}
		ajax.send(null);
	}
	
	/* Colocamos mediante los whiles los selects en "Selecciona opción..." cuando el select anterior
	ha quedado en estado "Elige" */
	var x=1, y=null;
	while(x<=2)
	{
		valor=document.getElementById("selecttienda_"+x).options[document.getElementById("selecttienda_"+x).selectedIndex].value;
		if(valor==0)
		{
			while(x<=2) 
			{
				y=x+1;
				elemento=document.getElementById("selecttienda_"+y);
				elemento.length=0;
				var opcionSelecciona=document.createElement("option"); opcionSelecciona.value=0; opcionSelecciona.innerHTML="Elige opci&oacute;n...";
				elemento.appendChild(opcionSelecciona); elemento.disabled=true;
				x++;
			}
		}
		x++;
	}
	
}
function buscaDecoracion(pagina){

		ocultos=document.getElementById('resultadoDecoracion');
		var URL = document.fdecoracion.action;
		var PARTIDA = document.fdecoracion.PARTIDA.options[document.fdecoracion.PARTIDA.selectedIndex].value;
		var SECCION = document.fdecoracion.SECCION.options[document.fdecoracion.SECCION.selectedIndex].value;
		var SUBSECCION = document.fdecoracion.SUBSECCION.options[document.fdecoracion.SUBSECCION.selectedIndex].value;
		var ORDEN = document.fdecoracion.ORDEN.options[document.fdecoracion.ORDEN.selectedIndex].value;
		var OFERTA = document.fdecoracion.OFERTA.options[document.fdecoracion.OFERTA.selectedIndex].value;
		var cadenaFormulario = "PARTIDA="+PARTIDA+"&SECCION="+SECCION+"&SUBSECCION="+SUBSECCION+"&ORDEN="+ORDEN+"&OFERTA="+OFERTA+"&pagina="+pagina;		
		
		ajax=nuevoAjax();
		ajax.open("POST", URL, true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga pongo "Cargando"
				ocultos.innerHTML="<table cellspacing='0' cellpadding='0'><tr><td align='center' valign='middle' class='texto1'><img src='/imagenes/progress.gif' width='16' height='16'> Cargando información. Por favor, espera ...</td></tr></table>";
			}
			if (ajax.readyState==4)
			{
				// Coloco en la capa contenedora los datos que recivo del servidor
				ocultos.innerHTML=ajax.responseText;
			}
		}
		ajax.send(cadenaFormulario);
}

function abreArticulo(idArticulo,paginas){
//reconozco si quiero abrir el artículo desde una tienda
if(document.getElementById("FICHATIENDA").style.display=="block"){
	document.getElementById("FICHATIENDA").style.display="none";
	document.getElementById("celdatienda").innerHTML="<a href=javascript:vuelveaTienda();><img src='/decoracion/imagenes/tienda2.gif' width='63' height='22' border='0'></a><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>";
}
document.getElementById("DECORACION1").style.display="none";
document.getElementById("celdaresultado").innerHTML="<a href=javascript:vuelveaDecoracion();><img src='/decoracion/imagenes/decoracion2.gif' width='145' height='22' border='0'></a><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>";
document.getElementById("celdaficha").innerHTML="<img src='/decoracion/imagenes/ficha1.gif' width='114' height='22' border='0'>";
document.getElementById("celdaficha").style.display="block";
document.getElementById("FICHAARTICULO").style.display="block";

ocultos=document.getElementById('FICHAARTICULO');
	
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado
			
		ajax.open("GET", "/decoracion/ficha.php?PAGINAS="+paginas+"&ID="+idArticulo, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga pongo "Cargando"
				ocultos.innerHTML="<span class='texto1'><img src='/imagenes/progress.gif' width='16' height='16'> Cargando información. Por favor, espera ...</span>";
			}
			if (ajax.readyState==4)
			{
				// Coloco en la capa contenedora los datos que recivo del servidor
				ocultos.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
}
function abreTienda(idTienda,pagina){
document.getElementById("DECORACION1").style.display="none";
document.getElementById("celdaresultado").innerHTML="<a href=javascript:vuelveaDecoracion();><img src='/decoracion/imagenes/decoracion2.gif' width='145' height='22' border='0'></a><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>";
document.getElementById("celdaficha").style.display="none";
document.getElementById("celdaficha").innerHTML="";
document.getElementById("FICHAARTICULO").style.display="none";
document.getElementById("FICHAARTICULO").innerHTML="";
document.getElementById("celdatienda").innerHTML="<img src='/decoracion/imagenes/tienda1.gif' width='63' height='22' border='0'><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>";
document.getElementById("celdatienda").style.display="block";
document.getElementById("FICHATIENDA").style.display="block";

ocultos=document.getElementById('FICHATIENDA');
	
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado
			
		ajax.open("GET", "/decoracion/tienda.php?id="+idTienda+"&pagina="+pagina, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga pongo "Cargando"
				ocultos.innerHTML="<span class='texto1'><img src='/imagenes/progress.gif' width='16' height='16'> Cargando información. Por favor, espera ...</span>";
			}
			if (ajax.readyState==4)
			{
				// Coloco en la capa contenedora los datos que recivo del servidor
				ocultos.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
}
function abreTienda2(idTienda,pagina){

		var URL = document.ftienda.action;
		var PARTIDA = document.ftienda.PARTIDA.options[document.ftienda.PARTIDA.selectedIndex].value;
		var SECCION = document.ftienda.SECCION.options[document.ftienda.SECCION.selectedIndex].value;
		var SUBSECCION = document.ftienda.SUBSECCION.options[document.ftienda.SUBSECCION.selectedIndex].value;
		var ORDEN = document.ftienda.ORDEN.options[document.ftienda.ORDEN.selectedIndex].value;
		var OFERTA = document.ftienda.OFERTA.options[document.ftienda.OFERTA.selectedIndex].value;
		var cadenaFormulario = "PARTIDA="+PARTIDA+"&SECCION="+SECCION+"&SUBSECCION="+SUBSECCION+"&ORDEN="+ORDEN+"&OFERTA="+OFERTA+"&id="+idTienda+"&pagina="+pagina;		

		ocultos=document.getElementById('capaBusquedaTienda');
	
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado
			
		ajax.open("POST", URL, true);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=ISO-8859-1');
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga pongo "Cargando"
				ocultos.innerHTML="<span class='texto1'><img src='/imagenes/progress.gif' width='16' height='16'> Cargando información. Por favor, espera ...</span>";
			}
			if (ajax.readyState==4)
			{
				// Coloco en la capa contenedora los datos que recivo del servidor
				ocultos.innerHTML=ajax.responseText;
			}
		}
		ajax.send(cadenaFormulario);
}
function vuelveaDecoracion(){
document.getElementById("celdaficha").style.display="none";
document.getElementById("celdaficha").innerHTML="";
document.getElementById("celdatienda").style.display="none";
document.getElementById("celdatienda").innerHTML="";
document.getElementById("FICHAARTICULO").style.display="none";
document.getElementById("FICHAARTICULO").innerHTML="";
document.getElementById("FICHATIENDA").style.display="none";
document.getElementById("FICHATIENDA").innerHTML="";
document.getElementById("celdaresultado").innerHTML="<img src='/decoracion/imagenes/decoracion1.gif' width='145' height='22' border='0'><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>"
document.getElementById("DECORACION1").style.display="block";
}
function vuelveaTienda(){
document.getElementById("celdaficha").style.display="none";
document.getElementById("celdaficha").innerHTML="";
document.getElementById("FICHAARTICULO").style.display="none";
document.getElementById("FICHAARTICULO").innerHTML="";
document.getElementById("celdatienda").innerHTML="<img src='/decoracion/imagenes/tienda1.gif' width='63' height='22' border='0'><img src='/imagenes/espacio.gif' width='5' height='5' border='0'>";
document.getElementById("FICHATIENDA").style.display="block";
}
function cambiaDestacados(tienda,pagina){
ocultos=document.getElementById('destacados');
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
		ajax.open("GET", "/decoracion/ajax_destacados.php?TIENDA="+tienda+"&pagina="+pagina, true);
		ajax.onreadystatechange=function() 
		{ 
			if (ajax.readyState==1)
			{
				// Mientras carga pongo "Cargando"
				elemento=document.getElementById('destacados');
				elemento.innerHTML="<table class='menu' align='center' width='493'><tr><td height='140' align='center'><img src='/imagenes/progress.gif' width='16' height='16'><br>Se esta procesando tu peticion. Por favor, espera ...</td></tr></table>";
			}
			if (ajax.readyState==4)
			{
				// Coloco en la fila contenedora los datos que recivo del servidor
				ocultos.innerHTML=ajax.responseText;
			}
		}
		ajax.send(null);
}
function abreFoto(foto){
var posx, posy;
e = event;
if (!document.all)
       {
       posy = e.pageY; 
       posx = e.pageX;
       }
else{
       posy = e.clientY +document.body.scrollTop; 
       posx = e.clientX +document.body.scrollLeft;
       }
	ocultos=document.getElementById('capaFoto');
	ocultos.style.left=posx-20;
	ocultos.style.top=posy-20;
	ocultos.style.display="block";
	document.getElementById("celdaFoto").innerHTML="<img src='"+foto+"' alt='Cerrar imagen'>";
}
function cierraFoto(){
	document.getElementById('capaFoto').style.display='none';
}