// JavaScript Document
	
function nuevoAjax()
{ 
	/* Crea el objeto AJAX. Esta funcion es generica para cualquier utilidad de este tipo, por
	lo que se puede copiar tal como esta aqui */
	var xmlhttp=false; 
	try 
	{ 
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); 
	}
	catch(e)
	{ 
		try
		{ 
			// Creacion del objet AJAX para IE 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} 
		catch(E) { xmlhttp=false; }
	}
	if (!xmlhttp && typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } 

	return xmlhttp; 
}

function buscaKnownAs(input,idPlat,idGame){
	var ajax=nuevoAjax()
	if (input.value!=""){
			ajax.open("POST", "include/Game/buscaKnownAs.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("busqueda="+escape(input.value)+"&idPlat="+idPlat+"&idGame="+idGame);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					if(!ajax.responseText) {
						//divLista.style.display="none";
					} else {
						respuesta=ajax.responseText;
				
						// Si se obtuvieron datos los muestro
						if(respuesta!="") { 
							document.getElementById("divLista").innerHTML=respuesta; 
						}
					}
				}
			}
	} else {
		document.getElementById("divLista").innerHTML=""
	}
}

function asignKnownAs(idGame){
	document.getElementById("knownAs").value=idGame
	document.getElementById("knownAsForm").submit()
}

function addFavGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/addFav.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fav"+capa).innerHTML="<a href=javascript:removeFavGame("+idGame+","+idPlat+","+capa+")><img src=images/fav.png border=0 title='quitar de favoritos' style='opacity:1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("addFav")
				}
			}
	}
}

function removeFavGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/removeFav.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fav"+capa).innerHTML="<a href=javascript:addFavGame("+idGame+","+idPlat+","+capa+")><img src=images/fav.png border=0 title='añadir a favoritos' style='opacity:0.1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("removeFav")
				}
			}
	}
}

function addFav(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/addFav.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fav").innerHTML="<a href=javascript:removeFav("+id+",'"+que+"')><img src=images/fav.png border=0 title='quitar de favoritos' style='opacity:1;' /></a>"; 
					action("addFav")
				}
			}
	}
}

function removeFav(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/removeFav.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fav").innerHTML="<a href=javascript:addFav("+id+",'"+que+"')><img src=images/fav.png border=0 title='añadir a favoritos' style='opacity:0.1;' /></a>";
					action("removeFav")
				}
			}
	}
}

function addCol(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/addCol.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col").innerHTML="<a href=javascript:removeCol("+id+",'"+que+"')><img src=images/collection.png border=0 title='quitar de la colección' style='opacity:1;' /></a>";
					//document.getElementById("col").innerHTML=respuesta;
					action("addCollection")
					
					//Eliminem opció d'afegir a mas deseados si s'afegeix a la colecció
					if(document.getElementById("awa")){
						var menuElem=document.getElementById("awa")
						var menuParent=menuElem.parentNode
						menuParent.removeChild(menuElem)
					}
				}
			}
	}
}

function removeCol(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/removeCol.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col").innerHTML="<a href=javascript:addCol("+id+",'"+que+"')><img src=images/collection.png border=0 title='añadir a colección' style='opacity:0.1;' /></a>";
					action("removeCollection")
					
					var menuElem=document.getElementById("col")
					var menuParent=menuElem.parentNode
					nouLi=document.createElement("li")
					nouLi.setAttribute('id','awa');
					nouText=document.createElement('img');
					nouText.setAttribute('src','images/awaiting.png')
					nouText.setAttribute('style','opacity:0.1;')
					nouText.setAttribute('title','añadir a deseados')
					nouText.setAttribute('border',0)
					nouLink=document.createElement("a")
					nouLink.setAttribute("href","javascript:addPlatAwaiting("+id+",'"+que+"');")
					nouLink.appendChild(nouText)
					nouLi.appendChild(nouLink)
					menuParent.appendChild(nouLi)
				}
			}
	}
}

function addPlatAwaiting(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/addAwaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa").innerHTML="<a href=javascript:removePlatAwaiting("+id+",'"+que+"')><img src=images/awaiting.png border=0 title='quitar de desedos' style='opacity:1;' /></a>";
					//document.getElementById("col").innerHTML=respuesta;
					action("addAwaiting")
				}
			}
	}
}

function removePlatAwaiting(id,que){
	var ajax=nuevoAjax()
	if (id!="" && que!=""){
			ajax.open("POST", "cgi/ajax/removeAwaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			
			ajax.send(que+"="+id);
		
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa").innerHTML="<a href=javascript:addPlatAwaiting("+id+",'"+que+"')><img src=images/awaiting.png border=0 title='añadir a deseados' style='opacity:0.1;' /></a>";
					action("removeAwaiting")
				}
			}
	}
}

function addAwaiting(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/addAwaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa"+capa).innerHTML="<a href=javascript:removeAwaiting("+idGame+","+idPlat+","+capa+")><img src=images/awaiting.png border=0 title='quitar de desedos' style='opacity:1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("addAwaiting")
				}
			}
	}
}

function removeAwaiting(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/removeAwaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa"+capa).innerHTML="<a href=javascript:addAwaiting("+idGame+","+idPlat+","+capa+")><img src=images/awaiting.png border=0 title='añadir a deseados' style='opacity:0.1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("removeAwaiting")
				}
			}
	}
}

function addColGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/addCol.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col"+capa).innerHTML="<a href=javascript:removeColGame("+idGame+","+idPlat+","+capa+")><img src=images/collection.png border=0 title='quitar de colección' style='opacity:1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("addCollection")
					
					//Eliminem opció d'afegir a mas deseados si s'afegeix a la colecció
					if(document.getElementById("awa"+capa)){
						var menuElem=document.getElementById("awa"+capa)
						var menuParent=menuElem.parentNode
						menuParent.removeChild(menuElem)
					}
				}
			}
	}
}

function removeColGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/removeCol.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col"+capa).innerHTML="<a href=javascript:addColGame("+idGame+","+idPlat+","+capa+")><img src=images/collection.png border=0 title='añadir a colección' style='opacity:0.1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("removeCollection")
					
					var menuElem=document.getElementById("col"+capa)
					var menuParent=menuElem.parentNode
					nouLi=document.createElement("li")
					nouLi.setAttribute('id','awa'+capa);
					nouText=document.createElement('img');
					nouText.setAttribute('src','images/awaiting.png')
					nouText.setAttribute('style','opacity:0.1;')
					nouText.setAttribute('title','añadir a deseados')
					nouText.setAttribute('border',0)
					nouLink=document.createElement("a")
					nouLink.setAttribute("href","javascript:addAwaiting("+idGame+","+idPlat+","+capa+");")
					nouLink.appendChild(nouText)
					nouLi.appendChild(nouLink)
					menuParent.appendChild(nouLi)
				}
			}
	}
}

function addFinGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/addFin.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fin"+capa).innerHTML="<a href=javascript:removeFinGame("+idGame+","+idPlat+","+capa+")><img src=images/finished.png border=0 title='quitar de terminados' style='opacity:1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("addFinished")
				}
			}
	}
}

function removeFinGame(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/removeFin.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("fin"+capa).innerHTML="<a href=javascript:addFinGame("+idGame+","+idPlat+","+capa+")><img src=images/notFinished.png border=0 title='añadir a terminados' style='opacity:0.1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("removeFinished")
				}
			}
	}
}

function addNowPlay(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/addNowPlaying.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("nowP"+capa).innerHTML="<a href=javascript:removeNowPlay("+idGame+","+idPlat+","+capa+")><img src=images/nowP.png border=0 title='quitar de jugando' style='opacity:1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("nowPlaying")
				}
			}
	}
}

function removeNowPlay(idGame,idPlat,capa){
	var ajax=nuevoAjax()
	if (idGame.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/removeNowPlaying.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idGame="+idGame+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("nowP"+capa).innerHTML="<a href=javascript:addNowPlay("+idGame+","+idPlat+","+capa+")><img src=images/nowP.png border=0 title='añadir a jugando' style='opacity:0.1;' /></a>";
					//document.getElementById("fav").innerHTML=respuesta;
					action("removeNowPlay")
				}
			}
	}
}

function colPlat(idUser,idPlat){
	var ajax=nuevoAjax()
	if (idUser.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/collection.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idUser="+idUser+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3)	{
					document.getElementById("col").innerHTML="<img src=images/ajax_loader.gif border=0 />";
				}
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col").innerHTML=respuesta;
				}
			}
	}
}

function colAwaiting(idUser,idPlat){
	var ajax=nuevoAjax()
	if (idUser.value!="" && idPlat.value!=""){
			ajax.open("POST", "cgi/ajax/awaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idUser="+idUser+"&idPlat="+idPlat);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3)	{
					document.getElementById("awa").innerHTML="<img src=images/ajax_loader.gif border=0 />";
				}
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa").innerHTML=respuesta;
				}
			}
	}
}

function colAllPlats(idUser){
	var ajax=nuevoAjax()
	if (idUser.value!=""){
			ajax.open("POST", "cgi/ajax/platsCollection.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idUser="+idUser);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3)	{
					document.getElementById("col").innerHTML="<img src=images/ajax_loader.gif border=0 />";
				}
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("col").innerHTML=respuesta;
				}
			}
	}
}

function awaitAllPlats(idUser){
	var ajax=nuevoAjax()
	if (idUser.value!=""){
			ajax.open("POST", "cgi/ajax/platsAwaiting.asp?", true);
			ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			ajax.send("idUser="+idUser);
			ajax.onreadystatechange=function() {	
				if (ajax.readyState==1 || ajax.readyState==2 || ajax.readyState==3)	{
					document.getElementById("awa").innerHTML="<img src=images/ajax_loader.gif border=0 />";
				}
				if (ajax.readyState==4)	{
					respuesta=ajax.responseText;			
					// Si se obtuvieron datos los muestro
					document.getElementById("awa").innerHTML=respuesta;
				}
			}
	}
}

