
function productos(categoria,nombre){
	document.formulario.id_categoria.value=categoria;
	document.formulario.nombre.value=nombre;
	document.formulario.action="/tienda-buceo/productos.php";
	document.formulario.submit();
}
function marcas(marca,nombre){
	document.formulario.id_marca.value=marca;
	document.formulario.nombre.value=nombre;
	document.formulario.action="/tienda-buceo/productos.php";
	document.formulario.submit();
	}
	
function producto(producto){
	document.formulario.id_producto.value=producto;
	document.formulario.action="producto.php";
	document.formulario.submit();
	}
	
function comprar(producto,precio,peso,iva){
	document.formulario.id_producto.value=producto;
	document.formulario.precio.value=precio;
	document.formulario.peso.value=peso;
	document.formulario.iva.value=iva;
	document.formulario.action="/tienda-buceo/comprar.php";
	document.formulario.submit();
}
function carrito(){
	document.formulario.accion.value="comprobar";
	document.formulario.que.value="carrito";
	document.formulario.action="/tienda-buceo/comprar.php";
	document.formulario.submit();
	}
	
function registrarse(producto){
	document.formulario.action="/tienda-buceo/registro.php";
	document.formulario.submit();
	}

function datos(producto){
	document.formulario.accion.value="comprobar";
	document.formulario.que.value="datos";
	document.formulario.action="/tienda-buceo/comprar.php";
	document.formulario.submit();
}

function validar2(){
	document.formulario2.accion.value="comprobar";
	document.formulario2.action="/tienda-buceo/comprar.php";
	document.formulario2.submit();
	}
function registrarse2(producto){
	document.formulario2.action="/tienda-buceo/registro.php";
	document.formulario2.submit();
	}

function datos2(producto){
	document.formulario2.accion.value="comprobar";
	document.formulario2.que.value="datos";
	document.formulario2.action="/tienda-buceo/comprar.php";
	document.formulario2.submit();
}
function gestionaCarrito(producto) {
	var id = producto.value;
	if(producto.checked) {
		aniadirProducto(id);
	} else {
		eliminarProducto(id);
	}
}
function aniadirProducto(id) {
	var pr_id = "|" + id + "|";
	var productos = document.carrito.productos.value;
	if(productos == "") {
		productos = pr_id;
	} else if(productos.indexOf(pr_id) < 0) {
		productos += pr_id;
	}
	document.carrito.productos.value = productos;
	//alert(productos);
}
function eliminarProducto(id) {
	var pr_id = "|" + id + "|";
	var productos = document.carrito.productos.value;
	var donde = productos.indexOf(pr_id);
	if(productos == pr_id) {
		document.carrito.productos.value = "";
	} else if(donde > -1) {
		document.carrito.productos.value = productos.substring(0, donde) + productos.substring(donde + pr_id.length);
	}
}
function comprarProductosBajoelagua() {
	if(document.carrito.productos.value == "") {
		alert("Debes seleccionar al menos un producto");
		return;
	}
	document.carrito.action = '/libros-guias-buceo/ver_carrito.php';
	document.carrito.submit();
}
function cambiarPagina(elformulario, pagina) {
	document.carrito.pagina.value = pagina;
	document.carrito.action = "index.php";
	document.carrito.submit();
}
function comprarProducto(cual) {
	alert("ID: " + cual);
}
function NOcomprarProducto(cual) {
	/*
	document.carrito.action = "ver_carrito.php";
	document.carrito.productos.value = "|" + id + "|";
	document.carrito.submit();
	*/
	alert("hola karakola");
}
function cambiarPaginaGuias(pagina, valor) {
	urlFormulario = pagina;
	if(valor == 1) {
		urlFormulario += "/" + document.carrito.productos.value;
	} else {
		urlFormulario += "&productos=" + document.carrito.productos.value;
	}
	document.location = urlFormulario;
}

function gestionCarrito(accion, numero, id, precio) {
	if(document.frm_registro.usuario_registrado.value == 1) {
		var url="/libros-guias-buceo/gestionCarrito.php";
		url=url+"?accion="+accion;
		url=url+"&id="+id;
		url=url+"&precio="+precio;
		url=url+"&numero="+numero;
		url=url+"&sid="+Math.random();


		var http = GetXmlHttpObject();
		http.open('get', url);
		http.onreadystatechange = function () {
			if(http.readyState == 4){
				if (http.responseText) {
					document.getElementById("carrito").innerHTML=http.responseText;
				} else {
					document.getElementById("carrito").innerHTML=url;
				}
			}
		};
		http.send(null);

	} else {
		alert("Debes estar registrado para comprar");
	}
}

