function cambiarVisibilidad(activo, capa) {
	if (activo) {
		document.getElementById(capa).style.display='block';
	} else {
		document.getElementById(capa).style.display='none';
	}
}

function compruebaFormularioTengoJuego(formu) {

	if (formu.precioVenta!=null) {
		while (formu.precioVenta.value.indexOf('€')>=0)
			formu.precioVenta.value = formu.precioVenta.value.replace('€','&euro;');
	}

	if (formu.estadoVenta!=null) {
		while (formu.estadoVenta.value.indexOf('€')>=0)
			formu.estadoVenta.value = formu.estadoVenta.value.replace('€','&euro;');
	}

	if (formu.precioCompra!=null) {
		while (formu.precioCompra.value.indexOf('€')>=0)
			formu.precioCompra.value = formu.precioCompra.value.replace('€','&euro;');
	}

	return true;
}

function pintar_capas_tengo_juego(color) {
	with (document) {
		write('<div id="capaAñadirJuego" style="position:absolute;top:0px;left:245px;width:350px;height:300px;visibility:hidden;background-color:' + color + ';opacity:0.7;filter:alpha(opacity=70)" align="center"><table height="100%" cellspacing="0" cellpadding="0"><tr><td height="100%" align="center"></td></tr></table></div>');
		write('<div id="capaInternaAñadirJuego" style="position:absolute;top:25px;left:270px;width:300px;height:250px;visibility:hidden;background-color:white;padding:10px">');
		write('	<form action="/tengoJuego.jsp" target="destino" id="formuAñadirJuego" onSubmit="compruebaFormularioTengoJuego(this);">');
		write('	<input type="hidden" name="idJuego" id="idJuegoAñadir" value="">');
		write('	<input checked type="radio" id="radioComprado" name="comprado" value="true" onClick="cambiarVisibilidad(this.checked,\'enVenta\');cambiarVisibilidad(!this.checked,\'compro\');"> ¿Lo tienes ORIGINAL?<br>');
		write('	<input type="radio" id="radioDeseo" name="comprado" value="false" onClick="cambiarVisibilidad(this.checked,\'compro\');cambiarVisibilidad(!this.checked,\'enVenta\');"> ¿O lo quieres en la Lista de Deseos?<br>');
		write('	<input type="checkbox" name="notificar" checked class="formulario"> ¿Te avisamos cuando salga algo nuevo de él?<br>');
		write('	<input type="checkbox" name="favorito" class="formulario"> ¿Es uno de tus favoritos?<br>');
		write('	<span id="enVenta" style="display:block">');
		write('		<input type="checkbox" name="enVenta" value="true" onClick="cambiarVisibilidad(this.checked,\'enVentaDetalles\');" class="formulario"> ¿Lo quieres poner a la venta?<br>');
		write('		<span id="enVentaDetalles" style="display:none">');
		write(' 		<input type="text" size="10" name="precioVenta" class="formulario"> ¿Por cuánto?<br>');
		write('  		<textarea name="estadoVenta" rows="3" cols="40" class="formulario"></textarea><br>');
		write('  		¿Algún comentario (estado, condiciones, etc.)?');
		write('  	</span>');
		write('	</span>');
		write('	<span id="compro" style="display:none">');
		write('		<input type="checkbox" name="compro" value="true" onClick="cambiarVisibilidad(this.checked,\'comproDetalles\');" class="formulario"> ¿Quieres comprárselo a alguien?<br>');
		write('		<span id="comproDetalles" style="display:none">');
		write('  		<input type="text" rows="3" cols="30" name="precioCompra" class="formulario"> ¿Por cuánto?<br>');
		write('  	</span>');
		write('	</span>');
		write('	<input type="button" class="formularioBoton" value="<< VOLVER" onClick="ocultarCapasUsuariosJuego();">');
		write('	<input type="submit" class="formularioBoton" value="OK >>" onClick="ocultarCapasUsuariosJuego();">');
		write('	</form>');
		write('</div>');
	}
}

function ocultarCapasUsuariosJuego() {
  document.getElementById('capaAñadirJuego').style.visibility='hidden';
  document.getElementById('capaInternaAñadirJuego').style.visibility='hidden';
}

function tengoJuego(comprado, idJuego) {
	
	document.getElementById('formuAñadirJuego').idJuegoAñadir.value=idJuego;
	
	var scrolleando = scroll_top();
	
	document.getElementById('capaInternaAñadirJuego').style.top = 25 + scrolleando;
	document.getElementById('capaAñadirJuego').style.top = scrolleando;

  document.getElementById('capaAñadirJuego').style.visibility='visible';
  document.getElementById('capaInternaAñadirJuego').style.visibility='visible';
  if (!comprado) {
  	document.getElementById('radioDeseo').click();
  } else {
  	document.getElementById('radioComprado').click();
  }
}

function scroll_top(){
	if(window.pageYOffset){
		return window.pageYOffset;
	 }
	 else {
		return Math.max(top.document.body.scrollTop,top.document.documentElement.scrollTop);
	 }
}
