function abrePopup(url, ancho, alto, scrollb) {
	window.open(url,'pop','scrollbars=no,width=' + ancho + ',height=' + alto + ',scrollbars=' + scrollb);
}

function verCamiseta(cual, ancho, alto) {
	open("/camiseta.php?camiseta="+cual, "camiseta", "width="+ancho+",height="+alto+",resizable=0,status=0,menubar=0,scrollbars=0,location=0");
}

function cambiaImagen(cual, imagen) {
	eval("document.img_" + cual + ".src = '" + imagen + "'");
}

function aniadir_carrito() {
	with(document.nuevo_producto) {
		if(!cantidad.value || talla.options[talla.selectedIndex].value == "-") {
			alert("Selecciona talla y número de camisetas");
			return;
		}
		if(isNaN(cantidad.value)) {
			alert("Se requiere un valor numÃ©rico");
			return;
		}
		submit();
	}
}

function aniadir_carrito_iman() {
	with(document.nuevo_producto) {
		if(!cantidad_pomos.value && !cantidad_imanes.value) {
			alert("Selecciona al menos un pomo o un imán");
			return;
		}
		submit();
	}
}

function gestionCarrito(accionV, cualV) {
	with(document.gestion_carrito) {
		accion.value = accionV;
		valor.value = cualV;
		submit();
	}
}

function gestionCheck(nombre, activo) {
	with(document.gestion_carrito) {
		accion.value = "check";
		valor.value = nombre + "|";
		if(activo) {
			valor.value += "si";
		} else {
			valor.value += "no";
		}
		submit();
	}
}

function modificarEntrega() {
	var datos = "";
	with(document.carrito) {
		datos = direccion_entrega.value + "|" + ciudad_entrega.value + "|" + cp_entrega.value + "|" + provincia_entrega.options[provincia_entrega.selectedIndex].value + "|" + pais_entrega.value;
	}
	with(document.gestion_carrito) {
		accion.value = "direccion";
		valor.value = datos;
		submit();
	}
}

function verPedidos() {
	with(document.gestion_carrito) {
		accion.value = "otros";
		submit();
	}
}

function realizarPedido() {
	with(document.carrito) {
		if(prenda.value == 1) {
			if(!tallas.checked) {
				alert("Debes confirmar que has verificado tu talla");
				return;
			}
			if(!recomendaciones.checked) {
				alert("Debes confirmar que has comprobado las recomendaciones para conservar la prenda");
				return;
			}
		}
		document.location = "/tienda/realizar-pedido.php";
	}
}

function nuevoPedido() {
	with(document.gestion_carrito) {
		accion.value = "nuevo";
		submit();
	}
}

function suma(cual, op) {
	var valor = 0;
	var coste = 0;
	with(document.nuevo_producto) {
		if(cual == "pomo") {
			if(op == "sum") {
				valor = parseInt(pomo.value) + 1;
			} else {
				if(pomo.value > 0) {
					valor = parseInt(pomo.value) - 1;
				}
			}
			pomo.value = valor;
		} else {
			if(op == "sum") {
				valor = parseInt(iman.value) + 1;
			} else {
				if(iman.value > 0) {
					valor = parseInt(iman.value) - 1;
				}
			}
			iman.value = valor;
		}
		coste = parseFloat(precio_unitario.value) * (parseInt(iman.value) + parseInt(pomo.value));
		if(isNaN(coste)) {
			coste = 0;
		}
		precio_vis.value = coste;
		cantidad_pomos.value = pomo.value;
		cantidad_imanes.value = iman.value;
	}
}
