var d=document;
var timer = new Array();
var ajax = 0;
var lock = new Array();
var htaccess = "http://retrogame.gamesource.it/";
var mmorpg = "http://mmorpg.gamesource.it/";
var retro = "http://retrogame.gamesource.it/";
var url = "http://www.gamesource.it/";
var head,nhead,thead,headtime;
//var htaccess = "http://127.0.0.1/Gamesource/Gamesource/";

function locka(arg) {
	if (lock[arg]) return true;
	lock[arg] = 1;
	return false;
}
function unlocka(arg) {
	lock[arg] = 0;
}

function $(ID) { return d.getElementById(ID); }

function $2(ID) { return d.getElementById(ID); }
function setOpacity(val,node) { 
 node = $(node);
 node.style.opacity = val;
 if (node) node.style.filter = 'alpha(opacity=' + val*100 + ')';
 $("boxload").style.display = (val != 1 ? 'block' : '');
}

/*AJAX*/
function AjaxObj() {
 req = null;
 if (window.XMLHttpRequest){
  req = new XMLHttpRequest();
  if (req.overrideMimeType) { req.overrideMimeType('text/xml'); }
 } 
 else if (window.ActiveXObject) {
  try { req = new ActiveXObject("Msxml2.XMLHTTP"); } 
  catch (e){
   try { req = new ActiveXObject("Microsoft.XMLHTTP"); } 
   catch (e) {}
  }
 }
 return req;
}

function AjaxCheck(h) { 
 if (h != 200) { alert('Errore interno al server: '+req.status); return false; } 
 return true; 
}

function AjaxLoad(innerID) {
var node = (arguments[1] ? $(arguments[1]) : $("boxload"));
node.style.top = getElementTop(innerID)+((getElementSize(innerID,'h')/2)-20)+'px';
node.style.width = getElementSize(innerID,'w')+'px';
node.style.left = getElementLeft(innerID)+'px'
setOpacity(0.2,innerID); 
}

function AjaxOff(div,id) {
  	$(div).style.display = 'none'; 
  	setOpacity(1,id);
}

function AjaxGet(page,get,innerID,opacityID) {
	if (!ajax) { 
		ajax = 1; 
		AjaxGetAux(page,get,innerID,opacityID,arguments[4]);
	}
}

function AjaxGetAux(page,get,innerID,opacityID) {
 req = AjaxObj();
 if (get) {
 var a4 = arguments[4];
 req.onreadystatechange = function() {
  if (req.readyState == 0) alert("Richiesta fallita.");
  else if (req.readyState == 1) AjaxLoad(opacityID);
  else if (req.readyState == 4) {
   if (AjaxCheck(req.status) && req.responseText != 'err') { 
	if ($(innerID)) $(innerID).innerHTML = req.responseText; 
	if (innerID == 'bltable') $('sxboxlist').style.height = $('dxboxlist').style.height = $('boxlistAjax').style.height = (getElementTop('blpage')-getElementTop('boxlist'))+'px';	
   }
   $("boxload").style.display = 'none';
	setOpacity(1,opacityID);
	ajax = 0;
	if (innerID == 'boxvotoAjax' && a4 && $('divVote')) AjaxDo('Voto',a4,'1');
  }
 };
 req.open("POST", htaccess+"include/ajax/"+page, true); 
 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
 req.send(get); 
 }
 ajax = 0;
}

function AjaxDo(page) {
	switch (page) {
		case 'Collection':
			AjaxGet('collection.php','mode=Collection&pag=1&lista='+arguments[2]+'&uid='+arguments[3]+'&games='+arguments[4]+'&tipo='+arguments[1]+(arguments[5] != undefined ? '&console='+arguments[5] : '')+'&search='+$('SearchContents').value,(arguments[5] != undefined ?'contenuti' : 'Collection'),'userCollection');
			break;
		case 'commenti':
			AjaxGet('commenti.php','mode=new&threadid='+arguments[2]+'&forumid='+arguments[3]+'&pagetext='+PHPencode($('pagetext').value),'boxCommenti','divCommenti');
			$('butcom').disabled='true';
			$('butcom').style.cursor='default';
			break;
		case 'Updates':
			AjaxGet('ajax.php','mode=tabUpdates&tab='+arguments[2]+'&cid='+arguments[1]+'&head='+arguments[3],'divUpdates','Updates');
			break;
		case 'Voto':
			AjaxGet('ajax.php','mode=tabVoto&tab='+arguments[2]+'&scheda='+arguments[1],'divVote','VoteBox');
			break;
		case 'TopGames':
			AjaxGet('ajax.php','mode=tabTopGames&tab='+arguments[2]+'&cid='+arguments[1],'divTopGames','TopGames');
			break;
		case 'BoxList':
			if (locka('boxlist')) return;
			var n = (arguments[3] ? arguments[3] : $('blscheda').value);
			var pag = (arguments[2] ? arguments[2] : 1);
			if (!n || n.length < 3) alert("Inserire almeno 3 caratteri per la ricerca");
			else AjaxGet('user.php','mode=list&blscheda='+PHPencode(n)+'&pag='+pag+'&lista='+arguments[1],'bltable','boxlist');
			unlocka('boxlist');			
			break;
		case 'viewImg':
			AjaxGet('image.php','mode=viewImg&id='+arguments[1]+'&pag='+arguments[2],'divImg','divImg');
			break;
		default: break;
	}
}

/*GET*/
function getElementLeft(Elem) {
 if(document.getElementById) var elem = document.getElementById(Elem);
 else if (document.all) var elem = document.all[Elem];
 yPos = elem.offsetLeft;
 tempEl = elem.offsetParent;
 while (tempEl != null) {
  yPos += tempEl.offsetLeft;
  tempEl = tempEl.offsetParent;
 }
 return yPos;
}


function getElementTop(Elem) {
 if(document.getElementById) var elem = document.getElementById(Elem);
 else if (document.all) var elem = document.all[Elem];
 yPos = elem.offsetTop;
 tempEl = elem.offsetParent;
 while (tempEl != null) {
  yPos += tempEl.offsetTop;
  tempEl = tempEl.offsetParent;
 }
 return yPos;
}

function getElementSize(Elem,el) {
 if(document.getElementById) var elem = document.getElementById(Elem);
 else if (document.all) var elem = document.all[Elem];
 return (el == 'h' ? elem.offsetHeight : elem.offsetWidth);
}

function getWindowSize(el) {
 if (parseInt(navigator.appVersion)>3) {
  if (navigator.appName=="Netscape") 
   return (el == 'h' ? window.innerHeight : window.innerWidth);
  if (navigator.appName.indexOf("Microsoft")!=-1) 
   return (el == 'h' ? document.body.offsetWidth : document.body.offsetHeight);
 }
}

/*FUNCTION*/
function Register() {
	 location.href = "http://forum.gamesource.it/register.php";
}

function Logout() {
	if (confirm("Sei sicuro di voler effettuare il Logout?")) location.href = htaccess+"login.php?accedi=logout";
}	
function checkLogin() {
	if ($('logname').value)
		if ($('logpass').value) return true;
		else alert("Devi inserire la password");
	else alert("Devi inserire un username");
	return false;
}

function Box(id,i,w,h,reload) {
	var node;
	var empty;
	if (!(node = $(id))) {
		empty = 1;
		node = document.createElement("div");
		node.id = id;
		node.className = 'hiddenbox'; 
		node.style.width = w+"px"
		node.style.height = h+"px";
		node.innerHTML = '<div class="topsx"></div><div class="top" style="width:'+w+'px"></div><div class="topdx"></div><div class="sx" id="sx'+id+'" style="height:'+h+'px"></div><div class="center" id="'+id+'Ajax" style="height:'+(h-18)+'px"></div><div class="dx" id="dx'+id+'" style="height:'+h+'px"></div><div class="bottomsx"></div><div class="bottom" style="width:'+w+'px"></div><div class="bottomdx"></div>';
		$('hiddenbox').appendChild(node);
	}
	else empty = 0;
	if (!node) node = $(id);
	if (i) {
		node.style.display = 'block';
		if (empty || reload) {
			switch(id) {
				case 'boxricerca': AjaxGet('search.php','mode=open',id+'Ajax',id); break;
				case 'boxvoto': AjaxGet('voto.php','mode=open&sid='+arguments[5],id+'Ajax',id); break;
				case 'boxaltro': AjaxGet('box.php','mode=Altro',id+'Ajax',id); break;
				case 'boxf2p': AjaxGet('box.php','mode=F2P',id+'Ajax',id); break;
				case 'boxp2p': AjaxGet('box.php','mode=P2P',id+'Ajax',id); break;
				case 'boxbrowser': AjaxGet('box.php','mode=Browser',id+'Ajax',id); break;
				case 'boxlist': AjaxGet('user.php','mode=open&lista='+arguments[5],id+'Ajax',id); break;
			}
		}
	}
	else if (!lock[id]) node.style.display = 'none';
}

function goPages(tipo,pag) {
	switch(tipo) {
		case 'NewsBox': AjaxGet('ajax.php','mode=NewsBox&pag='+pag+(arguments[3] ? '&cid='+arguments[2]+'&alias='+arguments[3] : ''),'ListaNews','NewsBox');  break;
		case 'News': AjaxGet('search.php','mode=News&pag='+pag+'&cid='+arguments[2]+'&alias='+arguments[3]+(arguments[5] ? '&option='+arguments[5]+'&search='+PHPencode(arguments[6])+'&match='+arguments[6] : ''),'divNews','News');  break;	
		case 'Contenuti_DX': AjaxGet('ajax.php','mode='+arguments[2]+'Box&pag='+pag+(arguments[3] ? '&cid='+arguments[3] : ''),'Lista'+arguments[2],arguments[2]+'Box');  break;
		case 'Commenti': AjaxGet('commenti.php','mode=Paging&threadid='+arguments[2]+'&forumid='+arguments[3]+'&pag='+pag,'boxCommenti','divCommenti');  break;
		case 'Screenshots': AjaxGet('ajax.php','mode=Screenshots&sid='+arguments[2]+'&cid='+arguments[3]+'&pag='+pag,'divScreenshots','Screenshots');  break;
		case 'Ultimissime': AjaxGet('ajax.php','mode=Ultimissime&limit='+arguments[3]+'&cid='+arguments[2]+'&pag='+pag,'divUltimissime','Ultimissime');  break;		case 'Updates': AjaxGet('ajax.php','mode=Updates&cid='+arguments[2]+'&tab='+arguments[3]+'&head='+arguments[4]+'&max='+arguments[5]+'&pag='+pag,'divUpdates','Updates');  break;
		case 'Contents': AjaxGet('search.php','mode=Contents&cid='+arguments[2]+'&dbkey='+arguments[3]+'&pag='+pag+(arguments[6] ? '&match='+arguments[4]+'&option='+arguments[5]+'&search='+PHPencode(arguments[6]) : ''),'divContents','Contents');  break;
		case 'Articolo': AjaxGet('search.php','mode=Articolo&cid='+arguments[2]+'&pag='+pag+(arguments[5] ? '&match='+arguments[3]+'&option='+arguments[4]+'&search='+PHPencode(arguments[5]) : ''),'divContents','Contents');  break;
		case 'Galleria': AjaxGet('search.php','mode=Galleria&cid='+arguments[2]+'&pag='+pag+'&match='+arguments[3]+'&option='+arguments[4]+'&search='+PHPencode(arguments[5]),'divGalleria','Galleria');  break;
		case 'getGalleria': AjaxGet('ajax.php','mode=getGalleria&sid='+arguments[2]+'&pag='+pag+'&alias='+arguments[3],'divImmagini','Immagini');  break;
		case 'Search': AjaxGet('search.php','mode=Search&pag='+pag+'&search='+arguments[4]+'&genre='+arguments[5]+'&letter='+arguments[3]+'&console='+arguments[6],'divRicerca','Ricerca'); break;
		case 'Download': AjaxGet('search.php','mode=Download&pag='+pag+'&match='+arguments[3]+'&option='+arguments[4]+'&search='+PHPencode(arguments[5]),'divDownload','Download'); break;
		case 'Collezione': AjaxGet('user.php','mode=reload&pag='+pag+'&lista='+arguments[2],'divCollezione','Collezione');  break;
		case 'Collection': AjaxGet('collection.php','mode=Collection&pag='+pag+'&lista='+arguments[2]+'&uid='+arguments[3]+'&games='+arguments[4]+'&cons='+arguments[5]+'&search='+$('SearchContents').value,'Collection','userCollection');  break;
		case 'onlineUsers': AjaxGet('user.php','mode=onlineUsers&pag='+pag,'divonlineUsers','onlineUsers');  break;
		case 'imgShots': AjaxGet('image.php','mode=imgShots&pag='+pag+'&id='+arguments[3]+'&sid='+arguments[2],'divScreenshots','divScreenshots');  break;
		case 'TopGames': AjaxGet('search.php','mode=TopGames&pag='+pag+'&cid='+arguments[2]+'&name='+PHPencode(arguments[3])+'&genere='+arguments[4]+'&order='+arguments[5],'divCollection','divCollection');  break;
		case 'NewsScheda': AjaxGet('ajax.php','mode=NewsScheda&pag='+pag+'&id='+arguments[2],'divNews','News');  break;	
		case 'schedaCollection': AjaxGet('ajax.php','mode=schedaCollection&pag='+pag+'&sid='+arguments[2]+'&nav='+arguments[3]+'&div='+arguments[4],'div'+arguments[4],arguments[4]);  break;
		
		}
}

function setVoto(i) {
	if (i && !timer["voto"]) {
		putVoto(i);
		timer["voto"] = setInterval("putVoto("+i+")",150);
	}
	else if (!i && timer["voto"]) {
		clearInterval(timer["voto"]);
		timer["voto"] = 0;
	}
}

function putVoto(i) {
	node = $('numvoto');
	var num = (Number(node.innerHTML)+i).toFixed(1);
	if (num >= 10 || num <= 0) {
		num = (num >= 10 ? 10 : parseFloat(0.0).toFixed(1));
		setVoto(0);
	}
	node.innerHTML = num;
}

function PHPencode(text) {
	if (text) {
		text = escape(text.toString()).replace(/\+/g, "%2B");

		var matches = text.match(/(%([0-9A-F]{2}))/gi);
		if (matches)
		{
			for (var matchid = 0; matchid < matches.length; matchid++)
			{
				var code = matches[matchid].substring(1,3);
				if (parseInt(code, 16) >= 128)
				{
				text = text.replace(matches[matchid], '%u00' + code);
				}
			}
		}

		text = text.replace('%25', '%u0025');
	}
	
	return text;
}

function getSearch(mode) {
	switch (mode) {
		case 'News':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=News&search='+text+'&option='+$('sOption').checked+'&match='+$('sMatch').options[$('sMatch').selectedIndex].value+'&cid='+arguments[1]+'&alias='+arguments[2],'divNews','News');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
			
		case 'Contents':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=Contents&pag=1&dbkey='+arguments[1]+'&search='+text+'&option='+$('sOption').checked+'&match='+$('sMatch').options[$('sMatch').selectedIndex].value+'&cid='+arguments[2],'divContents','divContents');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
		
		case 'Search':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=Search&pag=1&search='+text+'&console='+arguments[1],'divRicerca','divRicerca');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
			
	
		case 'Articolo':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=Articolo&pag=1&search='+text+'&option='+$('sOption').checked+'&match='+$('sMatch').options[$('sMatch').selectedIndex].value+'&cid='+arguments[1],'divContents','divContents');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
			
		case 'Galleria':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=Galleria&pag=1&search='+text+'&option='+$('sOption').checked+'&match='+$('sMatch').options[$('sMatch').selectedIndex].value+'&cid='+arguments[1],'divGalleria','divGalleria');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
			
		case 'Download':
			if ((text = PHPencode($('sText').value)))
				AjaxGet('search.php','mode=Download&pag=1&search='+text+'&option='+$('sOption').checked+'&match='+$('sMatch').options[$('sMatch').selectedIndex].value+'&cid='+arguments[1],'divDownload','divDownload');
			else alert('Non � stato specificato nessun testo di ricerca');
			break;
		default: break;
	}
}

function loadPage() {
	if (node = $('contenuti')) {
		//resizePage(node);
		loadMenu();
		node = $('nomeScheda');
		var n = get_width(node.innerHTML);
		if (n > 360) node.style.fontSize = parseInt((30*330)/n)+"px";
		node.style.display = "block";
		if (node = $('genereScheda')) node.style.display = "block";
	}
	if (arguments[0]) {
		jQuery("body").css({ background: "#111111 url('"+arguments[0]+"') top center fixed no-repeat" });
	}
}
function resizePage(node) {	if ((getElementSize('contenuti','h')+160) < (h = (getElementSize('colonna_dx','h')))) node.style.height = (h -160)+'px'; }
function loadMenu() {
	jQuery('#snavbut > li').hover(
		function() { jQuery(this).find('div').show(); }, 
		function() { jQuery(this).find('div').hide(); }
	);
}

function get_width (str) {
	/*var dummyTable=document.createElement("table");
	dummyTable.style.borderWidth="0";
	dummyTable.style.padding="0";
	document.body.appendChild (dummyTable);
	var row=document.createElement ("tr")
	row.style.borderWidth="0";
	row.style.padding="0";
	dummyTable.appendChild (row);
	var stringCell=document.createElement ("td")
	stringCell.style.borderWidth="0";
	stringCell.style.padding="0";
	stringCell.style.fontSize="30px";
	stringCell.style.fontFamily="Arial";
	stringCell.style.fontWeight="bold";
	stringCell.appendChild (document.createTextNode (str));
	row.appendChild (stringCell);
	var measurementCell=document.createElement ("td")
	measurementCell.style.borderWidth="0";
	measurementCell.style.padding="0";
	row.appendChild (measurementCell);
	*/
	var dummy=document.createElement("span");
	dummy.style.fontSize="30px";
	dummy.style.fontFamily="Arial";
	dummy.style.fontWeight="bold";
	dummy.style.margin="0 0 0 20px";
	dummy.style.padding="10px 0 0";
	dummy.appendChild (document.createTextNode (str));
	$('titolo').appendChild (dummy); 
	var n = dummy.offsetWidth;
	$('titolo').removeChild(dummy);

	return n+5;
}

function boxaddCollection(lista,id,scheda) {
	if (locka('collezione')) return;
	if (confirm("Vuoi aggiungere "+scheda+" alla tua "+lista+"?")) {
		boxaAddCollection("user.php","mode=confirm&id="+id+"&lista="+lista,'confirm',id,lista,scheda);
	}
	unlocka('collezione');
}
function boxaAddCollection(page,get,mode,id,lista,scheda) {
 var res = AjaxObj();
 if (get) {
 res.onreadystatechange = function() {
  if (res.readyState == 0) { 
  	alert("Richiesta fallita.");
  	AjaxOff("boxload","barCollection");
  	unlocka('collezione');
  }
  else if (res.readyState == 1) AjaxLoad("barCollection");
  else if (res.readyState == 4) {
   if (AjaxCheck(res.status)) {
    	var ok = 0;
   	if (mode == 'confirm') {
	  		switch (res.responseText) {
				case '1': if (confirm("La scheda "+scheda+" è gia presente nella tua wishlist, verrà quindi tolta dalla wishlist e aggiunta alla tua collezione. Continuare?")) ok = 'upd';
					break;
				case '2': alert("La scheda "+scheda+" è gia presenta nella tua "+lista); break;
				case '3': if (confirm("La scheda "+scheda+" è gia presente nella tua collezione, verrà quindi tolta dalla collezione e aggiunta alla tua wishlist. Continuare?")) ok = 'upd';
					break;
				case '4': ok = 'add'; break;
				case '5': alert("Impossibile aggiungere la scheda "+scheda+" alla tua "+lista+" poichè hai raggiunto il limite di giochi ammesso (10 giochi disponibili)."); break;
				default: alert("Impossibile aggiungere la scheda "+scheda+" alla tua "+lista+". Riprovare in seguito");
			}
			if (ok) {
				boxaAddCollection("user.php","mode="+ok+"&id="+id+"&lista="+lista,ok,id,lista,scheda);
		   }
		   else {
		   	AjaxOff("boxload","barCollection"); 
		   	unlocka('collezione');
		   }
		}
		if (mode == 'upd' || mode == 'add') {
			switch (res.responseText) {
				case 'add': ok = 'ok'; break;
				case 'upd': ok = 'ok'; break;
				default: alert("Impossibile aggiungere la scheda "+scheda+" alla tua "+lista+". Riprovare in seguito");
			}
			if (ok) {
				alert("La scheda "+scheda+" è stata inserita nella tua "+lista);
				AjaxGet("user.php",'mode=boxload&id='+id+'&scheda='+scheda,'barCollection','barCollection');
		   }
			AjaxOff("boxload","barCollection");
			unlocka('collezione');
		}
	}
	else {
		AjaxOff("boxload","barCollection");
		unlocka('collezione');
	}
  }
 };
 res.open("POST", htaccess+"include/ajax/"+page, true); 
 res.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
 res.send(get); 
 }
}

function boxplayNow(id,value,scheda,mode) {
	if (mode == 'confirm') if (locka('collezione')) return;
	var res = AjaxObj();
	res.onreadystatechange = function() {
	if (res.readyState == 0) { 
		alert("Richiesta fallita.");
		AjaxOff("boxload","barCollection");
		unlocka('collezione');
	}
	else if (res.readyState == 1) AjaxLoad("barCollection");
	else if (res.readyState == 4) {
		var ok = 0;
		if (AjaxCheck(res.status)) {
			if (mode == 'confirm') {
				switch (res.responseText) {
					case '1': alert("La scheda "+scheda+" è gia presente nella tua lista Play Now.");
						break;
					case '2': if (confirm("La scheda "+scheda+" è gia presente nella tua wishlist, verrà quindi tolta dalla wishlist e aggiunta alla tua collezione Play Now. Continuare?")) ok = 'add';
						break;		
					case '3': ok = 'add'; break;
					case '4': ok = 'upd'; break;			
					break;
					default: alert("Impossibile aggiungere la scheda "+scheda+" alla tua lista Play Now. Riprovare in seguito");
				}
				if (ok) boxplayNow(id,value,scheda,ok);
				else {
				 	AjaxOff("boxload","barCollection"); 
			  		unlocka('collezione');
	  			}
			}
			if (mode == 'add' || mode == 'upd') {
	  	 		switch (res.responseText) {
					case 'add': ok = 'ok'; alert("La scheda "+scheda+" è stata aggiunta nella tua lista Play Now"); break;
					case 'rem': ok = 'ok'; alert("La scheda "+scheda+" è stata rimossa nella tua lista Play Now"); break;			
					default: alert("Impossibile "+(value == '1' ? 'aggiungere' : 'rimuovere')+" la scheda "+scheda+" alla tua lista Play Now. Riprovare in seguito"); break;
				}
				if (ok) AjaxGet("user.php",'mode=boxload&id='+id+'&scheda='+scheda,'barCollection','barCollection');
				AjaxOff("boxload","barCollection");
				unlocka('collezione');
			}
		}
	}
 };
 res.open("POST", htaccess+"include/ajax/user.php", true); 
 res.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
 res.send((mode == 'confirm' ? "mode=confirm&id="+id+"&lista=playnow" : "mode=playnow&value="+value+"&id="+id+"&m="+mode)); 
}

function boxdelCollection(lista,id,scheda) {
	if (locka('collezione')) return;
	if (confirm("Vuoi cancellare "+scheda+" dalla tua "+lista+"?")) {
		var res = AjaxObj();
 		res.onreadystatechange = function() {
 			if (res.readyState == 0) { 
  				alert("Richiesta fallita.");
				AjaxOff("boxload","barCollection");
				unlocka('collezione');
 	 	 	}
 		 	else if (res.readyState == 1) AjaxLoad("barCollection");
  		 	else if (res.readyState == 4) {
   			if (AjaxCheck(res.status)) {
    				var ok = 0;
	 	  			switch (res.responseText) {
						case 'rem': ok = 'ok'; alert("La scheda è stata rimossa dalla tua "+lista); break;			
						default: alert("Impossibile rimuovere la scheda dalla tua "+lista+". Riprovare in seguito"); break;
					}
				}			
				if (ok) AjaxGet("user.php",'mode=boxload&id='+id+'&lista='+lista,'barCollection','barCollection');
				AjaxOff("boxload","barCollection");
				unlocka('collezione');
    		}
 		};
 		res.open("POST", htaccess+"include/ajax/user.php", true); 
		res.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
		res.send("mode=del&id="+id); 
	}
	unlocka('collezione');
}

function headIn(e) {
	if (!e) var e = window.event;
	var target = (window.event) ? e.srcElement : e.target;
	var parent = target.parentNode;
	var className = parent.className;
	var text = target.innerHTML;
	if (!nhead) {
		var child = $("navbut").getElementsByTagName("li");
		for (var i = 0; i < child.length; i++) {
			if (child[i].className == "navthis") {
				nhead = head = child[i];
				thead = $('menu_bottom').innerHTML;
				break;
			}
		}
	}
	if (!nhead) nhead = head = child[0];
	try {
	var headchild = nhead.childNodes[0].innerHTML;
	clearInterval(headtime);
	if (headMenu[text]['class'] && headchild != text) {
		parent.style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/navthis3.jpg) repeat-x';
		target.style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/sepnav.jpg) no-repeat';
		$('bmenusx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/left4.jpg) left no-repeat';
		$('bmenudx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/right4.jpg) left no-repeat';
		$('menu_bottom').style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/bg4.jpg) top repeat-x';
		
		var a = (headMenu[headchild]['class'] == 'console' ? 'a' : '');
		nhead.style.background = 'url(http://www.gamesource.it/images/head/bg3'+a+'.jpg) repeat-x';
		nhead.childNodes[0].style.background = 'url(http://www.gamesource.it/images/head/sep3'+a+'.jpg) no-repeat';
		nhead = parent;
		$('menu_bottom').innerHTML = headMenu[text]['text'];
	}
	}
	catch (e) {};
}

function headOut(e) {
	if (!e) var e = window.event;
	e = e.relatedTarget || e.toElement;
	try {
		var parent = e.parentNode;
		var target = parent.parentNode.id;
		if (nhead != head && (target != 'navigation' && target != 'navbut' && target != 'bmenu' && target != 'menu_bottom' || (target != 'navigation' && target != 'bmenu' && target != 'menu_bottom' && parent.className!='console' && e.innerHTML != 'Home'))) {
			headtime = setTimeout("headClear(parent)",1000);
		}
	} catch (e) {};
}

function headClear(parent) {
	var a = (headMenu[nhead.childNodes[0].innerHTML]['class'] == 'console' ? 'a' : '');
	nhead.style.background = 'url(http://www.gamesource.it/images/head/bg3'+a+'.jpg) repeat-x';
	nhead.childNodes[0].style.background = 'url(http://www.gamesource.it/images/head/sep3'+a+'.jpg) no-repeat';
	nhead = head;
	
	var t = head.childNodes[0].innerHTML;
	var a = (headMenu[t]['class'] == 'console' ? 'a' : '');
	head.style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/navthis3.jpg) repeat-x';
	head.childNodes[0].style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/sepnav.jpg) no-repeat';
	$('bmenusx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/left4.jpg) left no-repeat';
	$('bmenudx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/right4.jpg) left no-repeat';
	$('menu_bottom').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/bg4.jpg) top repeat-x';
		
	$('menu_bottom').innerHTML = headMenu[t]['text'];
}
var headMenu = new Array();
headMenu['Home'] = { 'text':'<li><a href="'+url+'News/">News</a></li><li><a href="'+url+'Recensione/">Recensioni</a></li><li><a href="'+url+'Anteprima/">Anteprime</a></li><li><a href="'+url+'FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'Articolo/">Articoli</a></li><li><a href="'+url+'Galleria/">Immagini</a></li><li><a href="'+url+'Video/">Video</a></li><li><a href="'+url+'Download/">Download</a></li><li><a href="'+url+'topgames/">TopGames</a></li>','class':'sezioni','img':'' };
headMenu['X360'] = { 'text':'<li><a href="'+url+'console/xbox360/News/">News</a></li><li><a href="'+url+'console/xbox360/Recensione/">Recensioni</a></li><li><a href="'+url+'console/xbox360/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/xbox360/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/xbox360/Articolo/">Articoli</a></li><li><a href="'+url+'console/xbox360/Galleria/">Immagini</a></li><li><a href="'+url+'console/xbox360/Video/">Video</a></li><li><a href="'+url+'console/xbox360/Download/">Download</a></li><li><a href="'+url+'console/xbox360/topgames/">TopGames</a></li>','class':'console','img':'xbox360/' };
headMenu['PS3'] = { 'text':'<li><a href="'+url+'console/ps3/News/">News</a></li><li><a href="'+url+'console/ps3/Recensione/">Recensioni</a></li><li><a href="'+url+'console/ps3/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/ps3/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/ps3/Articolo/">Articoli</a></li><li><a href="'+url+'console/ps3/Galleria/">Immagini</a></li><li><a href="'+url+'console/ps3/Video/">Video</a></li><li><a href="'+url+'console/ps3/Download/">Download</a></li><li><a href="'+url+'console/ps3/topgames/">TopGames</a></li>','class':'console','img':'ps3/' };
headMenu['PSP'] = { 'text':'<li><a href="'+url+'console/psp/News/">News</a></li><li><a href="'+url+'console/psp/Recensione/">Recensioni</a></li><li><a href="'+url+'console/psp/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/psp/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/psp/Articolo/">Articoli</a></li><li><a href="'+url+'console/psp/Galleria/">Immagini</a></li><li><a href="'+url+'console/psp/Video/">Video</a></li><li><a href="'+url+'console/psp/Download/">Download</a></li><li><a href="'+url+'console/psp/topgames/">TopGames</a></li>','class':'console','img':'ps3/' };
headMenu['PS2'] = { 'text':'<li><a href="'+url+'console/ps2/News/">News</a></li><li><a href="'+url+'console/ps2/Recensione/">Recensioni</a></li><li><a href="'+url+'console/ps2/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/ps2/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/ps2/Articolo/">Articoli</a></li><li><a href="'+url+'console/ps2/Galleria/">Immagini</a></li><li><a href="'+url+'console/ps2/Video/">Video</a></li><li><a href="'+url+'console/ps2/Download/">Download</a></li><li><a href="'+url+'console/ps2/topgames/">TopGames</a></li>','class':'console','img':'ps3/' };
headMenu['Wii'] = { 'text':'<li><a href="'+url+'console/wii/News/">News</a></li><li><a href="'+url+'console/wii/Recensione/">Recensioni</a></li><li><a href="'+url+'console/wii/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/wii/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/wii/Articolo/">Articoli</a></li><li><a href="'+url+'console/wii/Galleria/">Immagini</a></li><li><a href="'+url+'console/wii/Video/">Video</a></li><li><a href="'+url+'console/wii/Download/">Download</a></li><li><a href="'+url+'console/wii/codice-amico/">Codice Amico</a></li><li><a href="'+url+'console/wii/topgames/">TopGames</a></li>','class':'console','img':'wii/' };
headMenu['DS'] = { 'text':'<li><a href="'+url+'console/ds/News/">News</a></li><li><a href="'+url+'console/ds/Recensione/">Recensioni</a></li><li><a href="'+url+'console/ds/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/ds/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/ds/Articolo/">Articoli</a></li><li><a href="'+url+'console/ds/Galleria/">Immagini</a></li><li><a href="'+url+'console/ds/Video/">Video</a></li><li><a href="'+url+'console/ds/Download/">Download</a></li><li><a href="'+url+'console/ds/codice-amico/">Codice Amico</a></li><li><a href="'+url+'console/ds/topgames/">TopGames</a></li>','class':'console','img':'wii/' };
headMenu['PC'] = { 'text':'<li><a href="'+url+'console/pc/News/">News</a></li><li><a href="'+url+'console/pc/Recensione/">Recensioni</a></li><li><a href="'+url+'console/pc/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/pc/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/pc/Articolo/">Articoli</a></li><li><a href="'+url+'console/pc/Galleria/">Immagini</a></li><li><a href="'+url+'console/pc/Video/">Video</a></li><li><a href="'+url+'console/pc/Download/">Download</a></li><li><a href="'+url+'console/pc/topgames/">TopGames</a></li>','class':'console','img':'pc/' };//headMenu['Community'] = { 'text':'<li><a href="'+url+'Community/Utenti/">Utenti</a></li><li><a href="'+url+'Community/Collezione/">Collezione</a></li><li><a href="'+url+'Community/Wishlist/">Wishlist</a></li><li><a href="'+url+'Community/Playnow/">Playnow</a></li><li><a href="'+url+'Community/CodiceAmico/">Codice Amico</a></li>','class':'sezioni','img':'' };
headMenu['iPhone'] = { 'text':'<li><a href="'+url+'console/iphone/News/">News</a></li><li><a href="'+url+'console/iphone/Recensione/">Recensioni</a></li><li><a href="'+url+'console/iphone/Anteprima/">Anteprime</a></li><li><a href="'+url+'console/iphone/FAQ/">Trucchi &amp; Soluzioni</a></li><li><a href="'+url+'console/iphone/Articolo/">Articoli</a></li><li><a href="'+url+'console/iphone/Galleria/">Immagini</a></li><li><a href="'+url+'console/iphone/Video/">Video</a></li><li><a href="'+url+'console/iphone/Download/">Download</a></li><li><a href="'+url+'console/iphone/topgames/">TopGames</a></li>','class':'console','img':'iphone/' };
//headMenu['Community'] = { 'text':'<li><a href="'+url+'Community/Utenti/">Utenti</a></li><li><a href="'+url+'Community/Collezione/">Collezione</a></li><li><a href="'+url+'Community/Wishlist/">Wishlist</a></li><li><a href="'+url+'Community/Playnow/">Playnow</a></li><li><a href="'+url+'Community/CodiceAmico/">Codice Amico</a></li>','class':'sezioni','img':'' };
//headMenu['TopGames'] = { 'text':'<li><a href="'+url+'TopGames/">TopGames</a></li><li><a href="'+url+'Community/Collezione/">Collezione</a></li><li><a href="'+url+'Community/Wishlist/">Wishlist</a></li><li><a href="'+url+'Community/Playnow/">Playnow</a></li><li><a href="'+url+'Community/CodiceAmico/">Codice Amico</a></li>','class':'sezioni','img':'' };
headMenu['Mmorpg'] = { 'text':'<li><a href="http://mmorpg.gamesource.it/lista-mmorpg-gratuiti/">Gratuiti</a></li><li><a href="http://mmorpg.gamesource.it/lista-mmorpg-a-pagamento/">A Pagamento</a></li><li><a href="http://mmorpg.gamesource.it/lista-browser-game/">Browser Games</a></li><li><a href="'+mmorpg+'News/">News</a></li><li><a href="'+mmorpg+'Recensione/">Recensioni</a></li><li><a href="'+mmorpg+'Anteprima/">Anteprime</a></li><li><a href="'+mmorpg+'Articolo/">Articoli</a></li><li><a href="'+mmorpg+'Galleria/">Immagini</a></li>','class':'sezioni','img':'mmorpg/' };
headMenu['Retro'] = { 'text':'<li><a href="'+retro+'console/xbox/">XboX</a></li><li><a href="'+retro+'console/psx/">PSX</a></li><li><a href="'+retro+'console/gbadvance/">GBa</a></li><li><a href="'+retro+'console/gc/">GC</a></li><li><a href="'+retro+'console/n64/">N64</a></li><li><a href="'+retro+'console/snes/">Snes</a></li><li><a href="'+retro+'console/dreamcast/">Dreamcast</a></li>','class':'sezioni','img':'retro/' };
							
function tabCollezione(t,tab) {
	//jQuery.noConflict(); 
	jQuery("#Collezioni > div").css("display","none");
	jQuery("#"+tab+"Collection").css("display","block");
	jQuery("#contenuti .button1").attr("class","button");
	jQuery(t).attr("class","button1");
}
function keygenToggle(t) {
	jQuery("#keygen ul li .intbox").hide();
	jQuery("#keygen ul li .intro").show();
	jQuery(t).hide();
	jQuery(t).parent().find(".intbox").show();
}

function notRegister(what) {
	var q = "";
	if (getLNG() == 'it') {
		switch (what) {
			case 'collezione': q = 'Devi essere registrato per mantenere una collezione di giochi.\nVuoi registrarti ora?'; break;
			case 'keygen': q = 'Devi essere registrato per poter richiedere una Key.\nVuoi registrarti ora?'; break;
			default: break;
		}
	}
	else {
		switch (what) {
			case 'collezione': q = 'You must be register to manage a game collection.\nWould you like to register now?'; break;
			case 'keygen': q = 'You must be register to receive a key.\nWould you like to register now?'; break;
			default: break;
		}
	}
	if (confirm(q)) 
	location.href = 'http://forum.gamesource.it/register.php'+(getLNG() != 'it' ? '?langid=1' : '');
}

function getLNG() { 
	if (navigator.appName == 'Netscape')  var language = navigator.language;
	else var language = navigator.browserLanguage;
	return language.substring(0,2);
}

function showKeygen(t) {
	prompt("La tua chiave per '"+jQuery(t).attr('rel')+"' e':",jQuery(t).find("input").val());
}

function getKeygen(t) {
	var opacityID = "keygen";
	if (locka(opacityID)) return;
	if (confirm((getLNG() == 'it' ? "Vuoi ricevere una Key per" : "Would you like to receive a key for")+" '"+jQuery(t).attr('rel')+"'?")) {
		jQuery.ajax({
			type: "POST",
			dataType : "json",
			url: htaccess+"include/ajax/ajax.php",
			data: 'mode=keygen&id='+jQuery(t).attr('rev'),
			loading: function() { ajaxLoad(opacityID); },
			complete: function () { setOpacity(1,opacityID); unlocka(opacityID); },
			success: function(json) { 
				jQuery.ajax({
					type: "POST",
					url: htaccess+"include/ajax/ajax.php",
					data: 'mode=keyReload&id='+jQuery(t).attr('rev'),
					success: function(html) { jQuery("#"+opacityID).html(html); }
				});
				if (!json['err']) prompt((getLNG() == 'it' ? "Ecco la tua chiave per" : "Here your key for")+" '"+jQuery(t).attr('rel')+"':",json["text"]);
				else alert(json["text"]);
			}		
		});
	}
	else unlocka(opacityID);
}