//////////////////////////// objeto ajax
function objetoAjax()
{
	var xmlhttp = false;
	
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)
		{
			xmlhttp = false;
		}
	}
		
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}
	
	return xmlhttp;
}
//////////////////////////// fin objeto ajax

//////////////////////////// compruebo si es explorer o no para crear el evento click
var ie = (document.all) ? true : false;

if (!ie)
{
	HTMLElement.prototype.click = function()
	{
		var evt = this.ownerDocument.createEvent('MouseEvents');
		evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
		this.dispatchEvent(evt);
	}
}
//////////////////////////// fin compruebo si es explorer o no para crear el evento onclick

//////////////////////////// popup muestra condiciones
function MuestraCondiciones()
{
	var ancho = 550;
	var alto = 550;
	
	var posicion_x = (screen.width / 2) - (ancho / 2);
	var posicion_y = (screen.height / 2) - (alto / 2); 
	
	var opciones = "width="+ancho+", height="+alto+", scrollbars=yes, top="+posicion_y+", left="+posicion_x+", resizable=no, directories=no, location=no, menubar=no, status=yes, titlebar=no, toolbar=no";

	window.open("condiciones.html", "Condiciones", opciones);
}
//////////////////////////// fin popup muestra condiciones

//////////////////////////// popup tabla cuotas
function TablaCuotas(usuario)
{
	var ancho = 550;
	var alto = 400;
	
	var posicion_x = (screen.width / 2) - (ancho / 2);
	var posicion_y = (screen.height / 2) - (alto / 2);
	
	var opciones = "width="+ancho+", height="+alto+", scrollbars=yes, top="+posicion_y+", left="+posicion_x+", resizable=no, directories=no, location=no, menubar=no, status=yes, titlebar=no, toolbar=no";

	window.open("tabla_cuotas.php?usuario="+usuario, "TablaCuotas", opciones);
}
//////////////////////////// fin popup tabla cuotas

//////////////////////////// popup formulario asociado
function FormularioAsociado()
{
	var ancho = 700;
	var alto = 500;
	
	var posicion_x = (screen.width / 2) - (ancho / 2);
	var posicion_y = (screen.height / 2) - (alto / 2);
	
	var opciones = "width="+ancho+", height="+alto+", scrollbars=yes, top="+posicion_y+", left="+posicion_x+", resizable=no, directories=no, location=no, menubar=no, status=yes, titlebar=no, toolbar=no";

	window.open("formulario_asociado.php", "FormularioAsociado", opciones);
}
//////////////////////////// fin popup formulario asociado

//////////////////////////// valida email
function validarEmail(valor)
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)) return 1;
	else return 0;
}
//////////////////////////// fin valida email

//////////////////////////// valida login
function CompruebaLogin()
{	
	var divmensajes = document.getElementById("mensajes");

	if (ajax_login.readyState == 4)
	{
		if (ajax_login.responseText == "ok")
		{
			document.acceso_spliterm.submit();
		}
		else if (ajax_login.responseText == "rechazado")
		{
			divmensajes.innerHTML = "";
			
			document.getElementById("abrirPop").click();
		}
		else
		{
			divmensajes.innerHTML = ajax_login.responseText;
		}
	}
	else
	{
		divmensajes.innerHTML = "Cargando...";
	}
}

function Login()
{
	var error = 0;
	
	var aleatorio = Math.random();
	
	var divmensajes = document.getElementById("mensajes");
	
	if (document.acceso_spliterm.email.value == "")
	{
		error++;
		document.getElementById('email_login').className = "input_error";
		divmensajes.innerHTML = "Inserta tu correo el&eacute;ctronico";
		document.acceso_spliterm.email.focus();
	}
	else
	{
		document.getElementById('email_login').className = "input";
	}
	
	if (document.acceso_spliterm.password.value == "")
	{
		document.getElementById('password_login').className = "input_error";
		
		if (error == 0)
		{
			divmensajes.innerHTML = "Inserta tu contrase&ntilde;a";
			document.acceso_spliterm.password.focus();
		}
		
		error++;
	}
	else
	{
		document.getElementById('password_login').className = "input";
	}
	
	if (validarEmail(document.acceso_spliterm.email.value) == 0)
	{
		document.getElementById('email_login').className = "input_error";
		
		if (error == 0)
		{
			divmensajes.innerHTML = "Inserta tu correo el&eacute;ctronico correctamente";
			document.acceso_spliterm.email.focus();
		}
		
		error++;
	}
	else
	{
		document.getElementById('email_login').className = "input";
	}
	
	if (error == 0)
	{
		ajax_login = objetoAjax();

		ajax_login.open("GET", "ajax/comprobar_login.php?aleatorio="+aleatorio+"&email="+document.acceso_spliterm.email.value+"&password="+document.acceso_spliterm.password.value);
		
		ajax_login.onreadystatechange = CompruebaLogin;
		
		ajax_login.send(null);
		
		return false;
	}
	else
	{
		return false;
	}
}
//////////////////////////// fin valida login

//////////////////////////// valida recordar
function CompruebaRecordar()
{	
	var divmensajes = document.getElementById("mensajes");

	if (ajax_recordar.readyState == 4)
	{
		if (ajax_recordar.responseText == "ok") document.recordar_spliterm.submit();
		else divmensajes.innerHTML = ajax_recordar.responseText;
	}
	else
	{
		divmensajes.innerHTML = "Cargando...";
	}
}

function Recordar()
{
	var error = 0;
	
	var aleatorio = Math.random();
	
	var divmensajes = document.getElementById("mensajes");
	
	if (document.recordar_spliterm.email.value == "")
	{
		error++;
		document.getElementById('email_recordar').className = "input_error";
		divmensajes.innerHTML = "Inserta tu correo el&eacute;ctronico";
		document.recordar_spliterm.email.focus();
	}
	else
	{
		document.getElementById('email_recordar').className = "input";
	}
	
	if (validarEmail(document.recordar_spliterm.email.value) == 0)
	{
		document.getElementById('email_recordar').className = "input_error";
		
		if (error == 0)
		{
			divmensajes.innerHTML = "Inserta tu correo el&eacute;ctronico correctamente";
			document.recordar_spliterm.email.focus();
		}
		
		error++;
	}
	else
	{
		document.getElementById('email_recordar').className = "input";
	}
	
	if (error == 0)
	{
		ajax_recordar = objetoAjax();

		ajax_recordar.open("GET", "ajax/comprobar_recordar.php?aleatorio="+aleatorio+"&email="+document.recordar_spliterm.email.value);
		
		ajax_recordar.onreadystatechange = CompruebaRecordar;
		
		ajax_recordar.send(null);
		
		return false;
	}
	else
	{
		return false;
	}
}
//////////////////////////// fin valida recordar

//////////////////////////// valida registro
function CompruebaRegistro()
{	
	var divmensajes = document.getElementById("mensajes");

	if (ajax_registro.readyState == 4)
	{
		if (ajax_registro.responseText == "ok")
		{
			document.registro_spliterm.submit();
		}
		else if (ajax_registro.responseText == "rechazado")
		{
			divmensajes.innerHTML = "";
			
			document.getElementById("abrirPop").click();
		}
		else
		{
			divmensajes.innerHTML = ajax_registro.responseText;
		}
	}
	else
	{
		divmensajes.innerHTML = "Cargando...";
	}
}

function Registro()
{
	var error = 0;
	
	var aleatorio = Math.random();
	
	var divmensajes = document.getElementById("mensajes");
	
	if (document.registro_spliterm.telefono.value == "")
	{
		error++;
		document.getElementById('telefono_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('telefono_registrar').className = "input";
	}
	
	if (document.registro_spliterm.email.value == "")
	{
		error++;
		document.getElementById('email_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('email_registrar').className = "input";
	}
	
	if (validarEmail(document.registro_spliterm.email.value) == 0)
	{
		error++;
		document.getElementById('email_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('email_registrar').className = "input";
	}
	
	if (document.registro_spliterm.conf_email.value == "")
	{
		error++;
		document.getElementById('conf_email_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('conf_email_registrar').className = "input";
	}
	
	if (validarEmail(document.registro_spliterm.conf_email.value) == 0)
	{
		error++;
		document.getElementById('conf_email_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('conf_email_registrar').className = "input";
	}
	
	if (document.registro_spliterm.email.value != "" && document.registro_spliterm.conf_email.value != "" && validarEmail(document.registro_spliterm.conf_email.value) == 0)
	{
		if (document.registro_spliterm.email.value != document.registro_spliterm.conf_email.value)
		{
			error++;
			document.getElementById('conf_email_registrar').className = "input_error";
		}
		else
		{
			document.getElementById('conf_email_registrar').className = "input";
		}
	}
	
	if (document.registro_spliterm.empresa.value == "")
	{
		error++;
		document.getElementById('empresa_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('empresa_registrar').className = "input";
	}
	
	if (document.registro_spliterm.cif.value == "")
	{
		error++;
		document.getElementById('cif_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('cif_registrar').className = "input";
	}
	
	if (document.registro_spliterm.direccion.value == "")
	{
		error++;
		document.getElementById('direccion_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('direccion_registrar').className = "input";
	}
	
	if (document.registro_spliterm.codigo_postal.value == "")
	{
		error++;
		document.getElementById('codigo_postal_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('codigo_postal_registrar').className = "input";
	}
	
	if (document.registro_spliterm.localidad.value == "")
	{
		error++;
		document.getElementById('localidad_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('localidad_registrar').className = "input";
	}
	
	if (document.registro_spliterm.provincia.value == 0)
	{
		error++;
		document.getElementById('provincia_registrar').className = "input_error";
	}
	else
	{
		document.getElementById('provincia_registrar').className = "input";
	}
	
	if (document.registro_spliterm.condiciones.checked == false)
	{
		if (error == 0)
		{
			alert('Has leido y aceptado las condiciones generales?');
			document.registro_spliterm.condiciones.focus();
		}
		
		error++;
	}
	
	if (error == 0)
	{
		ajax_registro = objetoAjax();

		ajax_registro.open("GET", "ajax/comprobar_registro.php?aleatorio="+aleatorio+"&email="+document.registro_spliterm.email.value+"&empresa="+document.registro_spliterm.empresa.value+"&cif="+document.registro_spliterm.cif.value);
		
		ajax_registro.onreadystatechange = CompruebaRegistro;
		
		ajax_registro.send(null);
		
		return false;
	}
	else
	{
		return false;
	}
}
//////////////////////////// fin valida registro

//////////////////////////// valida contacto
function Contacto()
{
	var error = 0;
	
	var divmensajes = document.getElementById("mensajes");
	
	if (document.contactar_spliterm.nombre.value == "")
	{
		error++;
		document.getElementById('nombre_contactar').className = "input_error";
	}
	else
	{
		document.getElementById('nombre_contactar').className = "input";
	}
	
	if (document.contactar_spliterm.telefono.value == "")
	{
		error++;
		document.getElementById('telefono_contactar').className = "input_error";
	}
	else
	{
		document.getElementById('telefono_contactar').className = "input";
	}
	
	if (document.contactar_spliterm.email.value == "")
	{
		error++;
		document.getElementById('email_contactar').className = "input_error";
	}
	else
	{
		document.getElementById('email_contactar').className = "input";
	}
	
	if (validarEmail(document.contactar_spliterm.email.value) == 0)
	{
		error++;
		document.getElementById('email_contactar').className = "input_error";
	}
	else
	{
		document.getElementById('email_contactar').className = "input";
	}
	
	if (document.contactar_spliterm.comentarios.value == "")
	{
		error++;
		document.getElementById('comentarios_contactar').className = "input_error";
	}
	else
	{
		document.getElementById('comentarios_contactar').className = "input";
	}
	
	if (error == 0) return true;
	else return false;
}
//////////////////////////// fin valida contacto

//////////////////////////// muestra categorias
var cate, niv;

function CompruebaCategorias()
{
	var div = document.getElementById("cat"+cate);
	var enlace = document.getElementById("enlace"+cate);
	var imagen = document.getElementById("imagen"+cate);
	
	if (ajax_categorias.readyState == 4)
	{
		if (ajax_categorias.responseText == "fuera")
		{
			window.location.href = window.location.href;
		}
		else
		{
			OcultaMuestraDivAjax(cate);
			OcultaMuestraDivAjaxSeccion(cate);
			
			if (div)
			{
				div.innerHTML = ajax_categorias.responseText;
				div.style.display = "block";
			}
			
			if (imagen)
			{
				if (niv == 0) imagen.src = "img/on.png";
				else if (niv == 1) imagen.src = "img/on_uno.png";
				else if (niv == 2) imagen.src = "img/on_uno.png";
			}
			
			if (enlace) enlace.className = "enlaces";
			
			if (document.getElementById("imagenoutlet"))
			{
				document.getElementById("imagenoutlet").src = "img/off.png";
				document.getElementById("enlaceoutlet").className = "blau";
			}
		}
	}
}


function CompruebaCategoriasCentro()
{
	var div = document.getElementById("divcentro");
	
	if (ajax_categorias_c.readyState == 4)
	{
		if (ajax_categorias_c.responseText == "fuera") window.location.href = window.location.href;
		else div.innerHTML = ajax_categorias_c.responseText;
	}
	else
	{
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	}
}

function carga_categorias(categoria, nivel)
{
	window.location.hash = window.location.hash;
	
	var aleatorio = Math.random();
	
	var div = document.getElementById("divcentro");
	
	div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	
	
	cate = categoria;
	
	niv = nivel;
	
	ajax_categorias = objetoAjax();

	ajax_categorias.open("GET", "ajax/comprobar_categorias.php?aleatorio="+aleatorio+"&categoria="+categoria+"&nivel="+nivel);
	
	ajax_categorias.onreadystatechange = CompruebaCategorias;
	
	ajax_categorias.send(null);
	
	
	ajax_categorias_c = objetoAjax();

	ajax_categorias_c.open("GET", "ajax/comprobar_categorias_centro.php?aleatorio="+aleatorio+"&categoria="+categoria+"&nivel="+nivel);
	
	ajax_categorias_c.onreadystatechange = CompruebaCategoriasCentro;
	
	ajax_categorias_c.send(null);
}


function CompruebaOcultaMuestraDivAjax()
{
	var cats, cate;
	
	if (ajax_oculta.readyState == 4)
	{
		if (ajax_oculta.responseText != "")
		{			
			if (ajax_oculta.responseText == "fuera")
			{
				window.location.href = window.location.href;
			}
			else
			{
				cats = ajax_oculta.responseText.split(',');
				
				for (var i = 0; i < cats.length; i++)
				{
					cate = cats[i].split('*');
					
					if (document.getElementById("cat"+cate[0]))
					{
						document.getElementById("cat"+cate[0]).style.display = "none";
						document.getElementById("enlace"+cate[0]).className = "blau";
						if (cate[1] == 1) document.getElementById("imagen"+cate[0]).src = "img/off.png";
						else if (cate[1] == 2) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
						else if (cate[1] == 3) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
						else if (cate[1] == 4) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
					}
				}
			}
		}
	}
}

function OcultaMuestraDivAjax(id)
{
	var aleatorio = Math.random();
	
	ajax_oculta = objetoAjax();
	
	ajax_oculta.open("GET", "ajax/comprobar_categorias_resto.php?aleatorio="+aleatorio+"&id="+id);
	
	ajax_oculta.onreadystatechange = CompruebaOcultaMuestraDivAjax;
	
	ajax_oculta.send(null);
}
//////////////////////////// fin muestra categorias

//////////////////////////// muestra seccion
var sec;

function CompruebaSeccion()
{
	var div = document.getElementById("divcentro");
	var enlace = document.getElementById("enlace"+sec);
	var imagen = document.getElementById("imagen"+sec);
	
	if (ajax_seccion.readyState == 4)
	{
		if (ajax_seccion.responseText == "fuera")
		{
			window.location.href = window.location.href;
		}
		else
		{
			OcultaMuestraDivAjaxSeccion(sec);
			OcultaMuestraDivAjax(sec);
			
			if (div) div.innerHTML = ajax_seccion.responseText;
			
			if (imagen)
			{
				if (sec == "outlet") imagen.src = "img/on.png";
				else imagen.src = "img/on_uno.png";
			}
			
			if (enlace) enlace.className = "enlaces";
		}
	}
	else
	{
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	}
}

function carga_seccion(seccion, marca)
{
	window.location.hash = window.location.hash;
	
	var aleatorio = Math.random();
	
	var div = document.getElementById("divcentro");
	
	div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	
	
	sec = seccion;
	
	ajax_seccion = objetoAjax();
	
	if (marca == 0 || marca == undefined) ajax_seccion.open("GET", "ajax/comprobar_secciones.php?aleatorio="+aleatorio+"&seccion="+seccion);
	else ajax_seccion.open("GET", "ajax/comprobar_secciones.php?aleatorio="+aleatorio+"&seccion="+seccion+"&marca="+marca);
	
	ajax_seccion.onreadystatechange = CompruebaSeccion;
	
	ajax_seccion.send(null);
}

function CompruebaOcultaMuestraDivAjaxSeccion()
{
	var cats, cate;
	
	if (ajax_oculta_sec.readyState == 4)
	{
		if (ajax_oculta_sec.responseText != "")
		{	
			cats = ajax_oculta_sec.responseText.split(',');
			
			for (var i = 0; i < cats.length; i++)
			{
				cate = cats[i].split('*');
				
				if (document.getElementById("enlace"+cate[0]))
				{
					document.getElementById("enlace"+cate[0]).className = "blau";
				
					if (cate[1] == 1) document.getElementById("imagen"+cate[0]).src = "img/off.png";
					else if (cate[1] == 2) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
					else if (cate[1] == 3) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
					else if (cate[1] == 4) document.getElementById("imagen"+cate[0]).src = "img/off_uno.png";
					
					if (sec != "outlet")
					{
						if (document.getElementById("imagenoutlet"))
						{
							document.getElementById("imagenoutlet").src = "img/off.png";
							document.getElementById("enlaceoutlet").className = "blau";
						}
					}
				}
			}
		}
	}
}

function OcultaMuestraDivAjaxSeccion(id)
{
	var aleatorio = Math.random();
	
	ajax_oculta_sec = objetoAjax();
	
	ajax_oculta_sec.open("GET", "ajax/comprobar_secciones_resto.php?aleatorio="+aleatorio+"&id="+id);
	
	ajax_oculta_sec.onreadystatechange = CompruebaOcultaMuestraDivAjaxSeccion;
	
	ajax_oculta_sec.send(null);
}
//////////////////////////// fin muestra seccion

//////////////////////////// muestra ficha
function CompruebaFicha()
{
	var div = document.getElementById("divcentro");
	
	if (ajax_ficha.readyState == 4)
	{
		if (ajax_ficha.responseText == "fuera") window.location.href = window.location.href;
		else div.innerHTML = ajax_ficha.responseText;
	}
	else
	{
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	}
}

function carga_ficha(id, categoria)
{
	window.location.hash = window.location.hash;
	
	var aleatorio = Math.random();
	
	var div = document.getElementById("divcentro");
	
	div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	
	
	ajax_ficha = objetoAjax();
	
	ajax_ficha.open("GET", "ajax/comprobar_ficha.php?aleatorio="+aleatorio+"&id="+id+"&categoria="+categoria);
	
	ajax_ficha.onreadystatechange = CompruebaFicha;
	
	ajax_ficha.send(null);
}
//////////////////////////// fin muestra ficha

//////////////////////////// buscador
function CompruebaBuscador()
{
	var div = document.getElementById("divcentro");
	
	if (ajax_buscador.readyState == 4)
	{
		if (ajax_buscador.responseText == "fuera") window.location.href = window.location.href;
		else div.innerHTML = ajax_buscador.responseText;
	}
	else
	{
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	}
}

function Buscador(fuera)
{
	if (document.form_buscador.productos.value == "")
	{
		alert('Debes escribir un texto para buscar');
		document.form_buscador.productos.focus();
		return false;
	}
	else if (document.form_buscador.productos.value.length < 3)
	{
		alert('Debes escribir más de 2 letras para buscar');
		document.form_buscador.productos.focus();
		return false;
	}
	else
	{
		window.location.hash = window.location.hash;
		
		var aleatorio = Math.random();
		
		var texto = document.form_buscador.productos.value;
		
		var div = document.getElementById("divcentro");
		
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
		
	
		ajax_buscador = objetoAjax();
		
		ajax_buscador.open("GET", "ajax/comprobar_busqueda.php?aleatorio="+aleatorio+"&texto="+texto);
		
		ajax_buscador.onreadystatechange = CompruebaBuscador;
		
		ajax_buscador.send(null);
		
		return false;
	}
	
	return false;
}

function BuscadorResultados(texto)
{
	var aleatorio = Math.random();

	ajax_buscador = objetoAjax();
	
	ajax_buscador.open("GET", "ajax/comprobar_busqueda.php?aleatorio="+aleatorio+"&texto="+texto);
	
	ajax_buscador.onreadystatechange = CompruebaBuscador;
	
	ajax_buscador.send(null);
}
//////////////////////////// fin buscador

//////////////////////////// comprar
function CompruebaCarrito()
{	
	var popup_carrito = document.getElementById("popup_carrito");
	
	var opacidad = document.getElementById("opacidad");
	
	var div_carrito = document.getElementById("carrito");
	
	var div_importe = document.getElementById("importe_carrito");
	
	var div_productos = document.getElementById("productos_carrito");
	
	var div_titulo_carrito = document.getElementById("titulo_2");
	
	var div_texto_carro_vacio = document.getElementById("texto_carro_vacio");
	
	var div_carro_vacio = document.getElementById("carrito_vacio");
	
	var div_carro_lleno = document.getElementById("carrito_lleno");
	
	if (ajax_consulta.readyState == 4)
	{
		if (ajax_consulta.responseText == "fuera")
		{
			window.location.href = window.location.href;
		}
		else
		{
			var resultado = ajax_consulta.responseText.split("***");
			
			if (navigator.userAgent.indexOf("MSIE") > -1 && navigator.userAgent.substring(navigator.userAgent.indexOf("MSIE") + 5, navigator.userAgent.indexOf("MSIE") + 6) <= 6) // para internex explorer 6 o inferiores
			{
				div_carrito.innerHTML = "<b>"+resultado[0]+"</b> Art&iacute;culo(s)"; // suma de artículos
				
				div_importe.innerHTML = resultado[1]+" &euro;"; // suma de precios
				
				div_titulo_carrito.innerHTML = '<a href="carrito.php" class="ama">Ir al Carro</a>...'; // titulo del carrito;
				
				if (div_texto_carro_vacio) div_texto_carro_vacio.style.display = "none";
				
				if (div_carro_vacio) div_carro_vacio.style.display = "none";
				
				if (div_carro_lleno) div_carro_lleno.style.display = "block";
				
				if (confirm(resultado[2]+". ¿Desea finalizar la compra?"))
				{
					window.location.href = "carrito.php";
				}
			}
			else // para el resto de navegadores
			{
				div_carrito.innerHTML = "<b>"+resultado[0]+"</b> Art&iacute;culo(s)"; // suma de artículos
				
				div_importe.innerHTML = resultado[1]+" &euro;"; // suma de precios
				
				div_productos.innerHTML = resultado[3]; // texto del popup
				
				div_titulo_carrito.innerHTML = '<a href="carrito.php" class="ama">Ir al Carro</a>...'; // titulo del carrito;
				
				if (div_texto_carro_vacio) div_texto_carro_vacio.style.display = "none";
				
				if (div_carro_vacio) div_carro_vacio.style.display = "none";
				
				if (div_carro_lleno) div_carro_lleno.style.display = "block";
				
				popup_carrito.style.display = "block";
				
				opacidad.style.display = "block";
			}
		}
	}
}

function comprar(articulo, categoria, outlet)
{
	var aleatorio = Math.random();
	
	ajax_compra = objetoAjax();
	
	ajax_compra.open("GET", "ajax/comprobar_compra.php?aleatorio="+aleatorio+"&articulo="+articulo+"&categoria="+categoria+"&outlet="+outlet);
	
	ajax_compra.onreadystatechange = function () {
		
		if (ajax_compra.readyState == 4)
		{
			if (ajax_compra.responseText == "fuera")
			{
				window.location.href = window.location.href;
			}
			else if (ajax_compra.responseText == "no existe")
			{
				alert("El artículo no existe");
			}
			else if (ajax_compra.responseText != "ok")
			{
				alert(ajax_compra.responseText);
			}
			else
			{
				var aleatorio_consulta = Math.random();

				ajax_consulta = objetoAjax();
				
				ajax_consulta.open("GET", "ajax/comprobar_carrito.php?aleatorio="+aleatorio_consulta+"&articulo="+articulo+"&categoria="+categoria+"&outlet="+outlet);
				
				ajax_consulta.onreadystatechange = CompruebaCarrito;
				
				ajax_consulta.send(null);
			}
		}
	
	};
	
	ajax_compra.send(null);
}
//////////////////////////// fin comprar

//////////////////////////// seguir comprando
function SeguirComprando()
{
	document.getElementById('popup_carrito').style.display = 'none';
	
	document.getElementById('opacidad').style.display = 'none';
}
//////////////////////////// fin seguir comprando

//////////////////////////// seguir comprando
function FinalizarCompra()
{
	location.href = "carrito.php";
}
//////////////////////////// fin seguir comprando

//////////////////////////// sumar carrito
function SumarP()
{
	if (ajax_sumar.readyState == 4)
	{				
		if (ajax_sumar.responseText == "principal") location.href = "/";
		else if (ajax_sumar.responseText == "ok") location.href = "carrito.php";
		else alert(ajax_sumar.responseText);
	}
}

function suma(lugar, pedido, producto, id)
{
	var numero;
	var cantidad;
	
	var aleatorio = Math.random();
	
	numero = parseFloat(document.getElementById(lugar).value);
	
	if ((numero + 1) < 100) // no le dejo que ponga mas de 99 unidades de un producto (en caso de ser externo)
	{
		cantidad = numero + 1;
		
		document.getElementById(lugar).value = cantidad;
	
		ajax_sumar = objetoAjax();
		
		ajax_sumar.open("GET", "ajax/operaciones_carrito.php?accion=sumar&pedido="+pedido+"&producto="+producto+"&id="+id+"&aleatorio="+aleatorio);
		
		ajax_sumar.onreadystatechange = SumarP;
		
		ajax_sumar.send(null);
		
		document.getElementById(lugar).value = document.getElementById(lugar).value - 1;
	}
}
//////////////////////////// fin sumar carrito

//////////////////////////// restar carrito
function RestarP()
{
	if (ajax_restar.readyState == 4)
	{				
		if (ajax_restar.responseText == "principal") location.href = "/";
		else if (ajax_restar.responseText == "ok") location.href = "carrito.php";
		else alert(ajax_restar.responseText);
	}
}

function resta(lugar, pedido, producto, id)
{
	var numero;
	var cantidad;
	
	var aleatorio = Math.random();
	
	if (document.getElementById(lugar).value > 1)
	{
		numero = parseFloat(document.getElementById(lugar).value);
		
		cantidad = numero - 1;
		document.getElementById(lugar).value = cantidad;
		
		ajax_restar = objetoAjax();
	
		ajax_restar.open("GET", "ajax/operaciones_carrito.php?accion=restar&pedido="+pedido+"&producto="+producto+"&id="+id+"&aleatorio="+aleatorio);
		
		ajax_restar.onreadystatechange = RestarP;
		
		ajax_restar.send(null);
	}
}
//////////////////////////// fin restar carrito

//////////////////////////// quitar carrito
function Quitar()
{
	if (ajax_quitar.readyState == 4)
	{				
		if (ajax_quitar.responseText == "principal") location.href = "/";
		else if (ajax_quitar.responseText == "ok") location.href = "carrito.php";
		else alert(ajax_quitar.responseText);
	}
}

function quitar(pedido, producto, id)
{
	var aleatorio = Math.random();
	
	ajax_quitar = objetoAjax();
	
	ajax_quitar.open("GET", "ajax/quitar_carrito.php?pedido="+pedido+"&producto="+producto+"&id="+id+"&aleatorio="+aleatorio);
	
	ajax_quitar.onreadystatechange = Quitar;
	
	ajax_quitar.send(null);
}
//////////////////////////// fin quitar carrito

//////////////////////////// comprueba cesta
function CompruebaCesta(valor)
{
	if (valor == "importe_bajo") alert('Para finalizar la compra el importe de tu cesta debes superar los 20€.');
	else if (valor == "inicio") document.location.href = "inicio.php";
	else if (valor == 0) document.carrito.submit();
	else alert('No puedes continuar con la compra hasta que no valides la cesta.');
}
//////////////////////////// fin comprueba cesta

//////////////////////////// comprueba forma de envio
function CompruebaFormaEnvio()
{
	var contador = 0;
	
	if (document.forma_envio.envio)
	{
		for (var i = 0; i < document.forma_envio.envio.length; i++)
		{
			if (document.forma_envio.envio[i].checked == true) break;
			else contador++;
		}
		
		if (document.forma_envio.envio.length == contador) alert("Tiene que seleccionar una forma de envío");
		else document.forma_envio.submit();
	}
}
//////////////////////////// fin comprueba forma de envio

//////////////////////////// comprueba forma de pago
function CompruebaFormaPago()
{	
	var contador = 0;
	
	if (document.forma_pago.pago)
	{
		if (document.forma_pago.pago.length == undefined)
		{
			if (document.forma_pago.pago.checked == false) alert("Tiene que seleccionar una forma de pago");
			else document.forma_pago.submit();
		}
		else
		{			
			for (var i = 0; i < document.forma_pago.pago.length; i++)
			{				
				if (document.forma_pago.pago[i].checked == true) break;
				else contador++;
			}
			
			if (document.forma_pago.pago.length == contador) alert("Tiene que seleccionar una forma de pago");
			else document.forma_pago.submit();
		}
	}
}
//////////////////////////// fin comprueba forma de pago

//////////////////////////// envia pedido
function EnviarPedido(tipo)
{
	if (document.getElementById("condiciones_compra").checked)
	{
		if (tipo == "tarjeta")
		{
			var num_ped = document.num_ped.num_pedido.value;
			
			var aleatorio = Math.random();
			
			document.getElementById("botconfirmar").style.display = "none";
			
			document.getElementById("divconfirmar").style.display = "block";
			
			document.getElementById("divconfirmar").style.visibility = "visible";
		
			// guardo el numero pedido puesto por el cliente
			ajax = objetoAjax();
			
			ajax.open("GET", "ajax/num_pedido.php?num_ped="+num_ped+"&aleatorio="+aleatorio);
			
			ajax.send(null)
			
			// compruebo el stock
			ajax_com = objetoAjax();
			
			ajax_com.open("GET", "ajax/comprobar_stock.php?aleatorio="+aleatorio);
			
			ajax_com.onreadystatechange = function() {
				
				if (ajax_com.readyState == 4)
				{		
					if (ajax_com.responseText == "0")
					{
						document.getElementById('tpv').submit();
					}
					else
					{
						alert('Algunos de los productos que ha metido en su cesta acaban de quedarse sin stock.\n\nPóngase en contacto con nuestro departamente de atención al cliente para resolver el problema. Tel: 902 92 92 73\n\nAhora volverá a la cesta. Compruebe los productos.');
						
						location.href = 'carrito.php';
					}
				}
			
			};
			
			ajax_com.send(null);
		}
		else
		{
			var aleatorio = Math.random();
				
			document.getElementById("botconfirmar").style.display = "none";
			
			document.getElementById("divconfirmar").style.display = "block";
			
			document.getElementById("divconfirmar").style.visibility = "visible";
			
			// compruebo el stock
			ajax = objetoAjax();
			
			ajax.open("GET", "ajax/comprobar_stock.php?aleatorio="+aleatorio);
			
			ajax.onreadystatechange = function() {
				
				if (ajax.readyState == 4)
				{					
					if (ajax.responseText == "0")
					{
						document.getElementById('num_ped').submit();
					}
					else
					{
						alert('Algunos de los productos que ha metido en su cesta acaban de quedarse sin stock.\n\nPóngase en contacto con nuestro departamente de atención al cliente para resolver el problema. Tel: 902 92 92 73\n\nAhora volverá a la cesta. Compruebe los productos.');
						
						location.href = 'carrito.php';
					}
				}
			
			};
			
			ajax.send(null);
		}
	}
	else
	{
		alert("Tienes que aceptar las condiciones generales.");
		document.getElementById("condiciones_compra").focus();
	}
}
//////////////////////////// fin envia pedido

//////////////////////////// volver atrás
function VolverAtras()
{
	history.back();
}
//////////////////////////// fin volver atrás

//////////////////////////// comprobar nueva dirección
function ComprobarNuevaDireccion()
{
	if (document.nueva_direccion.nombre.value == "")
	{
		alert('El nombre no puede estar vacio');
		document.nueva_direccion.nombre.focus();
		return false;
	}
	else if (document.nueva_direccion.apellidos.value == "")
	{
		alert('Los apellidos no pueden estar vacios');
		document.nueva_direccion.apellidos.focus();
		return false;
	}
	else if (document.nueva_direccion.telefono.value == "")
	{
		alert('El telefono no puede estar vacio');
		document.nueva_direccion.telefono.focus();
		return false;
	}
	else if (document.nueva_direccion.direccion.value == "")
	{
		alert('La direccion no puede estar vacia');
		document.nueva_direccion.direccion.focus();
		return false;
	}
	else if (document.nueva_direccion.codigo_postal.value == "")
	{
		alert('El codigo postal no puede estar vacio');
		document.nueva_direccion.codigo_postal.focus();
		return false;
	}
	else if (document.nueva_direccion.localidad.value == "")
	{
		alert('La localidad no puede estar vacia');
		document.nueva_direccion.localidad.focus();
		return false;
	}
	else if (document.nueva_direccion.provincia.value == 0)
	{
		alert('La provincia no puede estar vacia');
		document.nueva_direccion.provincia.focus();
		return false;
	}
	else
	{
		return true;
	}
}
//////////////////////////// fin comprobar nueva dirección

//////////////////////////// quitar nueva direccion
function QuitarNuevaDireccion()
{
	if (confirm("¿Estás seguro que quieres quitar la nueva dirección de entrega?")) window.location.href = "resumen.php?opcion=quitarnuevadireccion";
}
//////////////////////////// fin quitar nueva direccion

//////////////////////////// mira stock onchange
function CompruebaMiraStock()
{
	if (ajax_mirastock.readyState == 4)
	{				
		if (ajax_mirastock.responseText == "principal") location.href = "/";
		else if (ajax_mirastock.responseText == "ok") location.href = "carrito.php";
		else alert(ajax_mirastock.responseText);
	}
}

function MiraStock(lugar, pedido, producto, id, valor, anterior, categoria)
{
	if (valor <= 0)
	{
		document.getElementById(lugar).value = anterior;
	}
	else
	{
		var aleatorio = Math.random();
		
		ajax_mirastock = objetoAjax();
		
		ajax_mirastock.open("GET", "ajax/mira_stock.php?aleatorio="+aleatorio+"&lugar="+lugar+"&pedido="+pedido+"&producto="+producto+"&id="+id+"&valor="+valor+"&categoria="+categoria);
		
		ajax_mirastock.onreadystatechange = CompruebaMiraStock;
		
		ajax_mirastock.send(null);
	}
}
//////////////////////////// fin mira stock onchange

//////////////////////////// imprimir ficha
function ImprimirFicha(articulo, categoria)
{
	var ancho = 700;
	var alto = 370;
	
	var posicion_x = (screen.width / 2) - (ancho / 2);
	var posicion_y = (screen.height / 2) - (alto / 2); 
	
	var opciones = "width="+ancho+", height="+alto+", scrollbars=yes, top="+posicion_y+", left="+posicion_x+", resizable=no, directories=no, location=no, menubar=no, status=yes, titlebar=no, toolbar=no";

	window.open("imprimir_ficha.php?articulo="+articulo+"&categoria="+categoria, "Articulo", opciones);
}
//////////////////////////// fin imprimir ficha

//////////////////////////// imprimir pedido
function ImprimirPedido(pedido)
{
	var ancho = 1000;
	var alto = 600;
	
	var posicion_x = (screen.width / 2) - (ancho / 2);
	var posicion_y = (screen.height / 2) - (alto / 2); 
	
	var opciones = "width="+ancho+", height="+alto+", scrollbars=yes, top="+posicion_y+", left="+posicion_x+", resizable=no, directories=no, location=no, menubar=no, status=yes, titlebar=no, toolbar=no";

	window.open("imprimir_pedido.php?pedido="+pedido, "Pedido", opciones);
}
//////////////////////////// fin imprimir pedido

//////////////////////////// pestañas fichas
function PestanasFichas(tipo)
{
	if (tipo == "productos_relacionados")
	{
		document.getElementById("div_productos_relacionados").className = "on";
		document.getElementById("div_caracteristicas_tecnicas").className = "off";
		
		document.getElementById("alternativos").style.display = "block";
		document.getElementById("caracteristicas").style.display = "none";
	}
	else if (tipo == "caracteristicas_tecnicas")
	{
		document.getElementById("div_caracteristicas_tecnicas").className = "on";
		document.getElementById("div_productos_relacionados").className = "off";
		
		document.getElementById("caracteristicas").style.display = "block";
		document.getElementById("alternativos").style.display = "none";
	}
}
//////////////////////////// fin pestañas fichas

//////////////////////////// redimensionar popup de imagen
var ventana;

var cont = 0;

function AmpliarImagen(imagen)
{
	var titulo = "Aire acondicionado";
	
	if (cont == 1)
	{
		ventana.close();
		ventana = null
	}
	
	ventana = window.open('', 'Ventana', 'resizable=yes,scrollbars=no');
	
	ventana.document.write('<html><head><title>' + titulo + '</title></head><body style="overflow:hidden" marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" scroll="no" onunload="opener.cont = 0;"><img src="' + imagen + '" onload="opener.Redimensionar(this.width, this.height);">');
	
	ventana.document.close();
	
	cont++;
}

function Redimensionar(ancho, alto)
{
	ventana.resizeTo(ancho+12, alto+85);
	
	ventana.moveTo((screen.width-ancho) / 2, (screen.height-alto) / 2); //centra la ventana. Eliminar ésta línea si no se quiere centrar el popup
}
//////////////////////////// fin redimensionar popup de imagen

//////////////////////////// activar crédito
function IrActivarCredito()
{
	location.href = "cuenta.php?categoria=credito";
}

function obtenerDigito(valor)
{
	valores = new Array(1, 2, 4, 8, 5, 10, 9, 7, 3, 6);
	control = 0;
	
	for (i = 0; i <= 9; i++)
	{
		control += parseInt(valor.charAt(i)) * valores[i];
	}
	
	control = 11 - (control % 11);
 
	if (control == 11) control = 0;
	else if (control == 10) control = 1;
 
	return control;
}

function numerico(valor)
{
	cad = valor.toString();
	
	for (var i = 0; i < cad.length; i++)
	{
		var caracter = cad.charAt(i);
		
		if (caracter < "0" || caracter > "9") return false;
	}
 
	return true;
}

function CompruebaNumeroCuenta()
{			
	if (document.activar_credito.cif.value == "")
	{
		alert("Tienes que poner tu CIF / NIF");
		document.activar_credito.cif.focus();
		return false;
	}
	else if (document.activar_credito.entidad.value.length != 4 || document.activar_credito.oficina.value.length != 4 || document.activar_credito.dc.value.length != 2 || document.activar_credito.cuenta.value.length != 10)
	{
		alert("Faltan números por rellenar en su cuenta bancaria");
		document.activar_credito.entidad.focus();
		return false;
	}
	else 
	{
		if (!numerico(document.activar_credito.entidad.value) || !numerico(document.activar_credito.oficina.value) || !numerico(document.activar_credito.dc.value) || !numerico(document.activar_credito.cuenta.value))
		{
			alert("Los datos introducidos en la cuenta no son numéricos");
			document.activar_credito.entidad.focus();
			return false;
		}
		else 
		{
			if (!(obtenerDigito("00" + document.activar_credito.entidad.value + document.activar_credito.oficina.value) == parseInt(document.activar_credito.dc.value.charAt(0))) || !(obtenerDigito(document.activar_credito.cuenta.value) == parseInt(document.activar_credito.dc.value.charAt(1))))
			{
				alert("El dígito de control (DC) no corresponde con el núermo de cuenta");
				document.activar_credito.dc.focus();
				return false;
			}
			else
			{
				return true;
			}
		}
	}
	
	return false;
}

function cambia_div_credito(nombre)
{
	if (nombre == "pendientes")
	{
		document.getElementById('pendientes').style.display = "block";
		document.getElementById('divpendientes').className = "offo";
		
		document.getElementById('pagados').style.display = "none";
		document.getElementById('divpagados').className = "ono";
		
		document.getElementById('impagados').style.display = "none";
		document.getElementById('divimpagados').className = "ono";
	}
	else if (nombre == "pagados")
	{
		document.getElementById('pendientes').style.display = "none";
		document.getElementById('divpendientes').className = "ono";
		
		document.getElementById('pagados').style.display = "block";
		document.getElementById('divpagados').className = "offo";
		
		document.getElementById('impagados').style.display = "none";
		document.getElementById('divimpagados').className = "ono";
	}
	else if (nombre == "impagados")
	{
		document.getElementById('pendientes').style.display = "none";
		document.getElementById('divpendientes').className = "ono";
		
		document.getElementById('pagados').style.display = "none";
		document.getElementById('divpagados').className = "ono";
		
		document.getElementById('impagados').style.display = "block";
		document.getElementById('divimpagados').className = "offo";
	}
}
//////////////////////////// fin activar crédito

//////////////////////////// ver promoción
function CompruebaVerPromocion()
{
	var div = document.getElementById("divcentro");
	
	if (ajax_promocion.readyState == 4)
	{
		if (ajax_promocion.responseText == "fuera") window.location.href = window.location.href;
		else div.innerHTML = ajax_promocion.responseText;
	}
	else
	{
		div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	}
}

function VerPromocion(id)
{
	var aleatorio = Math.random();
	
	var div = document.getElementById("divcentro");
	
	div.innerHTML = '<div align="center" style="margin-top:50px;">Cargando...<br /><br /><img src="img/loading.gif" border="0" alt="Cargando..." title="Cargando..." /></div>';
	
		
	ajax_promocion = objetoAjax();
	
	ajax_promocion.open("GET", "ajax/ver_promocion.php?aleatorio="+aleatorio+"&id="+id);
	
	ajax_promocion.onreadystatechange = CompruebaVerPromocion;
	
	ajax_promocion.send(null);
}
//////////////////////////// fin ver promoción

//////////////////////////// cerrar finalizado
function CerrarFinalizado()
{
	document.getElementById('externo_finalizado').style.display = 'none';
	
	document.getElementById('popup_finalizado').style.display = 'none';
}
//////////////////////////// fin cerrar finalizado

//////////////////////////// cambia div cuotas asociados
function cambia_div_asociado(nombre)
{
	if (nombre == "seguimiento")
	{
		document.getElementById('seguimiento').style.display = "block";
		document.getElementById('divseguimiento').className = "offo2";
		
		document.getElementById('pendientes').style.display = "none";
		document.getElementById('divpendientes').className = "ono2";
		
		document.getElementById('pagados').style.display = "none";
		document.getElementById('divpagados').className = "ono2";
	}
	else if (nombre == "pendientes")
	{
		document.getElementById('seguimiento').style.display = "none";
		document.getElementById('divseguimiento').className = "ono2";
		
		document.getElementById('pendientes').style.display = "block";
		document.getElementById('divpendientes').className = "offo2";
		
		document.getElementById('pagados').style.display = "none";
		document.getElementById('divpagados').className = "ono2";
	}
	else if (nombre == "pagados")
	{
		document.getElementById('seguimiento').style.display = "none";
		document.getElementById('divseguimiento').className = "ono2";
		
		document.getElementById('pendientes').style.display = "none";
		document.getElementById('divpendientes').className = "ono2";
		
		document.getElementById('pagados').style.display = "block";
		document.getElementById('divpagados').className = "offo2";
	}
}
//////////////////////////// fin cambia div cuotas asociados

//////////////////////////// cambia div cuenta asociado
function cambia_carpeta_asociado(nombre)
{
	if (nombre == "cuenta")
	{
		document.getElementById('cuenta').style.display = "block";
		document.getElementById('carpetacuenta').className = "offo2";
		
		document.getElementById('news').style.display = "none";
		document.getElementById('carpetanews').className = "ono2";
		
		document.getElementById('productos').style.display = "none";
		document.getElementById('carpetaproductos').className = "ono2";
	}
	else if (nombre == "news")
	{
		document.getElementById('cuenta').style.display = "none";
		document.getElementById('carpetacuenta').className = "ono2";
		
		document.getElementById('news').style.display = "block";
		document.getElementById('carpetanews').className = "offo2";
		
		document.getElementById('productos').style.display = "none";
		document.getElementById('carpetaproductos').className = "ono2";
	}
	else if (nombre == "productos")
	{
		document.getElementById('cuenta').style.display = "none";
		document.getElementById('carpetacuenta').className = "ono2";
		
		document.getElementById('news').style.display = "none";
		document.getElementById('carpetanews').className = "ono2";
		
		document.getElementById('productos').style.display = "block";
		document.getElementById('carpetaproductos').className = "offo2";
	}
}
//////////////////////////// fin cambia div cuenta asociado
