var d=document;
var obj = null;
var timer = new Array();
var ajax = 0;
var lock = new Array();
var htaccess = "http://www.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 $2(ID) { return d.getElementById(ID); }

function setOpacity(val,node) { 
 node = $2(node);
 node.style.opacity = val;
 if (node) node.style.filter = 'alpha(opacity=' + val*100 + ')';
 $2("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] ? $2(arguments[1]) : $2("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) {
  	$2(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) {
	if (get) {
		AjaxLoad(opacityID); 
		var a4 = arguments[4];
		jQuery.ajax({
			type: "POST",
			url: htaccess+"include/ajax/"+page,
			data: get,
			complete: function() {
				$2("boxload").style.display = 'none';
				setOpacity(1,opacityID);
				ajax = 0;
				if (innerID == 'boxvotoAjax' && a4 && $2('divVote')) AjaxDo('Voto',a4,'1');
			},
			success: function(html) {	
				try {
					if ($2(innerID)) $2(innerID).innerHTML = html; 
				} catch(e) {};
				if (innerID == 'bltable') {
					if ($2('boxlist')) $2('boxlist').style.height = $2('sxboxlist').style.height = $2('dxboxlist').style.height = $2('boxlistAjax').style.height = (getElementTop('blpage')-getElementTop('boxlist')+40)+'px';	
					else if ($2('boxCAadd')) $2('sxboxCAadd').style.height = $2('dxboxCAadd').style.height = $2('boxCAaddAjax').style.height = (getElementTop('blpage')-getElementTop('boxCAadd'))+'px';	
				}
			}
		});
	}
}

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='+$2('SearchContents').value,(arguments[5] != undefined ?'contenuti' : 'Collection'),'userCollection');
			break;
		case 'commenti':
			AjaxGet('commenti.php','mode=new&threadid='+arguments[2]+'&forumid='+arguments[3]+'&pagetext='+PHPencode($2('pagetext').value),'boxCommenti','divCommenti');
			$2('butcom').disabled='true';
			$2('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] : $2('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 'CAadd':
			if (locka('boxCAadd')) return;
			var n = (arguments[2] ? arguments[2] : $2('blscheda').value);
			var pag = (arguments[1] ? arguments[1] : 1);
			if (!n || n.length < 3) alert("Inserire almeno 3 caratteri per la ricerca");
			else AjaxGet('codiceamico.php','mode=CAadd&blscheda='+PHPencode(n)+'&pag='+pag,'bltable','boxCAadd');
			unlocka('boxCAadd');			
			break;
		case 'CAmine':
			var n = (arguments[2] ? arguments[2] : $2('blscheda').value);
			var pag = (arguments[1] ? arguments[1] : 1);
			if (!n || n.length < 3) alert("Inserire almeno 3 caratteri per la ricerca");
			else AjaxGet('codiceamico.php','mode=CAmine&blscheda='+PHPencode(n)+'&pag='+pag,'boxCAmineAjax','boxCAmine');		
			break;
		case 'viewImg':
			AjaxGet('image.php','mode=viewImg&id='+arguments[1]+'&pag='+arguments[2],'divImg','divImg');
			break;
		case 'CodIns':
			var codice = $2('cod1').value+"-"+$2('cod2').value+"-"+$2('cod3').value;
			var codice2 = codice.replace(/\-/g,"");
			var err = 'Errore:';
			if (!isDigit(codice2)) err += "\r\nIl codice inserito non ? valido.";
			if (codice2.length != 12) err += "\r\nIl codice dev'essere di 12 cifre.";
			if (err == 'Errore:') {
				if (confirm("Confermi il seguente codice amico?\r\n"+codice)) {
					AjaxLoad('contenuti');
					$.post("http://www.gamesource.it/include/ajax/codiceamico.php", { mode: "addByScheda", sid: ""+arguments[1]+"", codice: ""+codice2+"" },
					function (html) {
						if (html != 'err') { $("#contenuti").html(html); alert("Operazione effettuata con successo!"); }
						else alert ("Impossibile effettuare l'operazione.");
						setOpacity(1,'contenuti');
					});
				}
			}
			else alert(err);
			break;
		case 'CodDel':
			if (confirm("Sei sicuro di volere cancellare il codice amico per questo gioco?")) {
				AjaxLoad('contenuti');
				$.post("http://www.gamesource.it/include/ajax/codiceamico.php", { mode: "delByScheda", sid: ""+arguments[1]+"" },
				function (html) {
					if (html != 'err') { $("#contenuti").html(html); alert("Operazione effettuata con successo!"); }
					else alert ("Impossibile effettuare l'operazione.");
					setOpacity(1,'contenuti');
				});
			}	
		case 'BoxCollezione':
			var x = $2('collCompl').value; 
			if (x < 0 || x > 100 || (x && isNaN(x))) {
				alert("Percentuale di Completamento non valida!\r\nDev'essere compresa tra 0 e 100"); 
				break;
			}
			AjaxGet('user.php','mode=boxcollezione&id='+arguments[1]+'&perc='+x+'&pagetext='+PHPencode($2('pagetext').value),'boxcollezioneAjax','boxcollezione'); break;
			break;
		case 'topCollections': 
			AjaxGet('ajax.php','mode=tabCollections&t='+arguments[2]+'&m='+arguments[1],'divtopCollections','topCollections');
			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 ($2('logname').value)
		if ($2('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 = $2(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>';
		$2('hiddenbox').appendChild(node);
	}
	else empty = 0;
	if (!node) node = $2(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;
				case 'boxcollezione': AjaxGet('user.php','mode=comment&id='+arguments[5],id+'Ajax',id); break;
				case 'boxCAadd': AjaxGet('codiceamico.php','mode=CAaddOpen',id+'Ajax',id); break;
				case 'boxCAShare':
					var tot = $(arguments[5]).attr("tot");
					var sid = $(arguments[5]).attr("sid");
					AjaxGet('codiceamico.php','mode=user_share&tot='+tot+'&sid='+sid+'&utente='+arguments[6],id+'Ajax',id); break;
				case 'boxCAmine':
					AjaxGet('codiceamico.php','mode=CAmine',id+'Ajax',id); break;
			}
		}
	}
	else if (!lock[id]) node.style.display = 'none';
}
function moreUrl(node) {
	if (!node) return '';
	var more = '';
	for (var i in node) more += "&"+i+"="+node[i];
	return more;
}

function goPages(tipo,pag) {
	var more = "";
	if (arguments[3]) more = moreUrl(arguments[3]);
		
	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 'NewsScheda': AjaxGet('ajax.php','mode=NewsScheda&pag='+pag+'&id='+arguments[2],'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('ajax.php','mode=Collection&pag='+pag+'&lista='+arguments[2]+'&uid='+arguments[3]+'&games='+arguments[4]+'&cons='+arguments[5]+'&search='+$2('SearchContents').value,'Collection','userCollection');  break;
		//case 'Collection': alert('mode=Collection&pag='+pag+'&lista='+arguments[2]+'&uid='+arguments[3]); AjaxGet('ajax.php','mode=Collection&pag='+pag+'&lista='+arguments[2]+'&uid='+arguments[3],'divCollezione','Collezione');  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 'CodiceAmico': AjaxGet('search.php','mode=CodiceAmico&pag='+pag+'&cid='+arguments[2]+(arguments[3] ? '&option='+arguments[3]+'&search='+PHPencode(arguments[4])+'&match='+arguments[5] : ''),'divCodiceAmico','CodiceAmico');  break;	
		case 'CAMy': AjaxGet('codiceamico.php','mode=CAMy&pag='+pag,'divCodiceAmico','CodiceAmico');  break;
		case 'shareCA': AjaxGet('codiceamico.php','mode=sharePag&pag='+pag+'&submode='+arguments[2],'div'+arguments[2]+'CodiceAmico',arguments[2]+'CodiceAmico'); break;
		case 'CAUserShare': AjaxGet('codiceamico.php','mode=user_share&pag='+pag+'&utente='+arguments[2]+'&sid='+arguments[3],'boxCAShareAjax','boxCAShare'); break;
		case 'CAmine': AjaxGet('codiceamico.php','mode=CAmine&blscheda='+PHPencode(arguments[2])+'&pag='+pag,'boxCAmineAjax','boxCAmine');
		case 'schedaCollection': AjaxGet('ajax.php','mode=schedaCollection&pag='+pag+'&sid='+arguments[2]+'&nav='+arguments[3]+'&div='+arguments[4],'div'+arguments[4],arguments[4]);  break;
		case 'ContestUser': AjaxGet('contest.php','mode=ContestUser&pag='+pag+'&id='+arguments[2],'divBox','Box');  break;
		case 'ReleaseDate': AjaxGet('ajax.php','mode=ReleaseDate&pag='+pag+'&cid='+arguments[2]+'&mmorpg='+arguments[3],'divReleaseDate','ReleaseDate');  break;
		//case 'goPages': AjaxGet('ajax.php','mode=go2Pag&pag='+pag+'&ID='+arguments[2]+more,arguments[3],arguments[4]);  break;
		default: AjaxGet('ajax.php','mode=go2Pages&ID='+tipo+'&pag='+pag+more,'div'+arguments[2],arguments[2]);  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 = $2('numvoto');
	var num = (Number(node.innerHTML)+i).toFixed(1);
	if (num >= 10 || num <= 2) { // prima era 0
		num = (num >= 10 ? 10 : parseFloat(2.0).toFixed(1)); //prima era 0.0
		//num = (num <= 2 ? 2 : parseFloat(0.0).toFixed(1)); //esperimento di marco per evitare che si voti meno di 2
		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 'CodiceAmico':
			text = PHPencode($2('sText').value);
			AjaxGet('search.php','mode=CodiceAmico&search='+text+'&option='+$2('sOption').options[$2('sOption').selectedIndex].value+'&match='+$2('sMatch').options[$2('sMatch').selectedIndex].value+'&cid='+arguments[1],'divCodiceAmico','CodiceAmico');
			break;
			
		case 'News':
			if ((text = PHPencode($2('sText').value)))
				AjaxGet('search.php','mode=News&search='+text+'&option='+$2('sOption').checked+'&match='+$2('sMatch').options[$2('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($2('sText').value)))
				AjaxGet('search.php','mode=Contents&pag=1&dbkey='+arguments[1]+'&search='+text+'&option='+$2('sOption').checked+'&match='+$2('sMatch').options[$2('sMatch').selectedIndex].value+'&cid='+arguments[2],'divContents','divContents');
			else alert('Non ? stato specificato nessun testo di ricerca');
			break;
		
		case 'Search':
			if ((text = PHPencode($2('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($2('sText').value)))
				AjaxGet('search.php','mode=Articolo&pag=1&search='+text+'&option='+$2('sOption').checked+'&match='+$2('sMatch').options[$2('sMatch').selectedIndex].value+'&cid='+arguments[1],'divContents','divContents');
			else alert('Non ? stato specificato nessun testo di ricerca');
			break;
			
		case 'Galleria':
			if ((text = PHPencode($2('sText').value)))
				AjaxGet('search.php','mode=Galleria&pag=1&search='+text+'&option='+$2('sOption').checked+'&match='+$2('sMatch').options[$2('sMatch').selectedIndex].value+'&cid='+arguments[1],'divGalleria','divGalleria');
			else alert('Non ? stato specificato nessun testo di ricerca');
			break;
			
		case 'Download':
			if ((text = PHPencode($2('sText').value)))
				AjaxGet('search.php','mode=Download&pag=1&search='+text+'&option='+$2('sOption').checked+'&match='+$2('sMatch').options[$2('sMatch').selectedIndex].value+'&cid='+arguments[1],'divDownload','divDownload');
			else alert('Non ? stato specificato nessun testo di ricerca');
			break;
			
		case 'TopGames':
			try {
				var console = $2('topConsole').options[$2('topConsole').selectedIndex].value;
			}
			catch (e) { var console = arguments[1]; }
			var name = PHPencode($2('topName').value);
			var genere = $2('topTipo').options[$2('topTipo').selectedIndex].value;
			var order = $2('topOrder').options[$2('topOrder').selectedIndex].value;
			if (console || name || genere || order) 
				AjaxGet('search.php','mode=TopGames&pag=1&name='+name+'&console='+console+'&genere='+genere+'&order='+order+'&cid='+arguments[1],'divCollection','divCollection');
			else alert('Non ? stato specificato nessun parametro di ricerca');
			break;
		default: break;
	}
}

function loadPage() {
	if (node = $2('contenuti')) {
		//resizePage(node);
		loadMenu();
		node = $2('nomeScheda');
		var n = get_width(node.innerHTML);
		if (n > 360) node.style.fontSize = parseInt((30*330)/n)+"px";
		node.style.display = "block";
		if (node = $2('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 checkHover() { if (obj) obj.find('div').fadeOut('fast'); }
function loadMenu() {
	$('#snavbut > li').hover(
		function() { $(this).find('div').show(); }, 
		function() { $(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));
	$2('titolo').appendChild (dummy); 
	var n = dummy.offsetWidth;
	$2('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 = $2("navbut").getElementsByTagName("li");
		for (var i = 0; i < child.length; i++) {
			if (child[i].className == "navthis") {
				nhead = head = child[i];
				thead = $2('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';
		$2('bmenusx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/left4.jpg) left no-repeat';
		$2('bmenudx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[text]['img']+'head/right4.jpg) left no-repeat';
		$2('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;
		$2('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';
	$2('bmenusx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/left4.jpg) left no-repeat';
	$2('bmenudx').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/right4.jpg) left no-repeat';
	$2('menu_bottom').style.background = 'url(http://www.gamesource.it/images/'+headMenu[t]['img']+'head/bg4.jpg) top repeat-x';
		
	$2('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['MMO'] = { '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

function isDigit(string) {
	var RegExp = /^(\d*)$/;
	return string.match(RegExp);
}

function setLabel(obj,toggle) {
	var id = $(obj).attr("id");
	if (toggle == 0) $(".label").remove();
	else $("#"+id).append('<td class="label" style="border:0px; position:absolute; margin-top:-1px; margin-left:-10px; width:51px; height:35px; background: transparent url(\'http://www.gamesource.it/images/utente/codamico/label.gif\') no-repeat scroll; padding:9px 0 0 7px;"><a href="#"><b>Invita</b></a></td>');
}

function invitaCodAmico(id,scheda,utente,opId) {
	var mode = $(id).attr("mode");
	var conf;
	switch (mode) {
		case 'ack_new': conf = "Vuoi invitare "+utente+" a condividere il codice amico per il gioco "+scheda+"?"; break;
		case 'ack_renew': conf = "Vuoi re-invitare "+utente+" a condividere il codice amico per il gioco "+scheda+"?"; break;
		case 'ack_yes': conf = "Vuoi annullare l'invito a "+utente+" per condividere il codice amico del gioco "+scheda+"?"; break;
		case 'ack_no': conf = "Vuoi annullare la condivisione con "+utente+" per il codice amico del gioco "+scheda+"?"; break;
		default: break;
	}
	if (conf && confirm(conf)) {
		AjaxLoad(opId);
		$.post("http://www.gamesource.it/include/ajax/codiceamico.php", { mode: ""+mode+"", tuid: ""+$(id).attr("uid")+"", caid: ""+$(id).attr("caid")+"", sid: ""+$(id).attr("sid")+"", box: ""+opId+"", pag: ""+(arguments[4] ? arguments[4] : "")+"", cid: ""+(arguments[5] ? arguments[5] : "")+"" },
		function (html) {
			if (html != 'err') {
				if (html == 'ack') { //invitato dall'altro utente?! Chiede conferma di condivisione. Altrimenti stoppa.
					if (confirm("Sei gi? stato invitato da "+utente+" a condividere il suo codice amico\nVuoi accettare l'invito?")) {
						$.post("http://www.gamesource.it/include/ajax/codiceamico.php", { mode: "ack_ok", tuid: ""+$(id).attr("uid")+"", caid: ""+$(id).attr("caid")+"", sid: ""+$(id).attr("sid")+"", box: ""+opId+"", pag: ""+(arguments[4] ? arguments[4] : "")+"", cid: ""+(arguments[5] ? arguments[5] : "")+"" },
						function (html) {
							if (html != 'err') {
								$("#"+opId).html(html);
								alert("Operazione effettuata con successo!");
							}
							else alert ("Impossibile effettuare l'operazione.");
						});
					}	
				}
				else { //Invita correttamente.
					$("#"+opId).html(html);
					alert("Operazione effettuata con successo!");
				}
			}
			else alert ("Impossibile effettuare l'operazione.");
			setOpacity(1,opId);
		});
	}
}
function tabCollezione(t,tab) {
	$("#Collezioni > div").css("display","none");
	$("#"+tab+"Collection").css("display","block");
	$("#contenuti .button1").attr("class","button");
	$(t).attr("class","button1");
}

function checkContest(f) {
	var i = c = 0;
	$("#contest textarea").each(function() { if (this.value.length > 0) i++; c++; });
	if (i != c) alert("Non hai risposto a tutte le domande!");
	return (i == c && confirm("Confermi l'invio delle risposte? (Non potrai piu cambiarle)"));
}

function keygenToggle(t) {
	$("#keygen ul li .intbox").hide();
	$("#keygen ul li .intro").show();
	$(t).hide();
	$(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 '"+$(t).attr('rel')+"' e':",$(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")+" '"+$(t).attr('rel')+"'?")) {
		$.ajax({
			type: "POST",
			dataType : "json",
			url: htaccess+"include/ajax/ajax.php",
			data: 'mode=keygen&id='+$(t).attr('rev'),
			loading: function() { ajaxLoad(opacityID); },
			complete: function () { setOpacity(1,opacityID); unlocka(opacityID); },
			success: function(json) { 
				$.ajax({
					type: "POST",
					url: htaccess+"include/ajax/ajax.php",
					data: 'mode=keyReload&id='+$(t).attr('rev'),
					success: function(html) { $("#"+opacityID).html(html); }
				});
				if (!json['err']) prompt((getLNG() == 'it' ? "Ecco la tua chiave per" : "Here your key for")+" '"+$(t).attr('rel')+"':",json["text"]);
				else alert(json["text"]);
			}		
		});
	}
	else unlocka(opacityID);
}