// ALLFORMATGAMING.COM // FETCH GAMEDATA SCRIPT VER 1.0

var opacity=0, inter;
var game_id;

function afg_window(load_image) {
	if (document.getElementById("gamedata_container")) {return false;}
	var divContainer = document.createElement("div");
	divContainer.id = "gamedata_container";
	divContainer.style.position = "fixed";
	divContainer.style.zIndex = "101";
	divContainer.style.left = "0px";
	divContainer.style.top = "0px";
	divContainer.style.width = "100%";
	divContainer.style.height = "100%";
	divContainer.style.textAlign = "center";
	divContainer.style.opacity = 0; 
	divContainer.style.MozOpacity = 0; 
	divContainer.style.KhtmlOpacity = 0; 
	divContainer.style.filter = "alpha(opacity=0)";	
	var pageHeight = document.documentElement.clientHeight;
	var middleHeight = pageHeight - 100; 
	var container = '<table style="width:100%; height:100%; background-color: #FFFFFF;" cellpadding="0" cellspacing="0" border="0"><tr style="height:50px;"><td style="width: 100%; height: 50px; font: 14pt Tahoma; text-align: center;" id="gameDataTop">';
	if (load_image==1) {
		container += 'Loading...';
		
	}
	container += '</td></tr><tr><td style="width:100%; height: '+middleHeight+'px; background: #000000; text-align: center; display: table-cell;" id="gameDataMiddle"><div style="width: 600px; height: 90%; background-color: #FFFFFF; vertical-align:middle; margin: auto; padding: 10px; ">';
	if (load_image==1) {
		container += '<img src="http://www.allformatgaming.com/images/ajax-loader.gif" />';
		
	}
	container += '</div></td></tr><tr style="height:50px; background-color: #FFFFFF;"><td style="width: 100%; height: 50px; font: 12pt Arial;" id="gameDataBottom"></td></tr></table>';	
	divContainer.innerHTML = container;
	if (load_image==1) {
		
		
	}
	document.body.appendChild(divContainer);

	/*
	if (window.addEventListener) {
		window.addEventListener("scroll", move_game_data, false);
	} else {
		document.body.onscroll = move_game_data;
	}
	*/
	
	//move_game_data();
	inter = window.setInterval("incrementOpacity()", 1);
	return true;
}


function incrementOpacity() {
var gameDataDiv	= document.getElementById("gamedata_container");
	if (opacity<100) {
		opacity+=5; 
		gameDataDiv.style.opacity = (opacity / 100); 
		gameDataDiv.style.MozOpacity = (opacity / 100); 
		gameDataDiv.style.KhtmlOpacity = (opacity / 100); 
		gameDataDiv.style.filter = "alpha(opacity="+opacity+")"; 
	} else {   
		window.clearInterval(inter);
	
	}
}
function decrementOpacity() {
var gameDataDiv	= document.getElementById("gamedata_container");
	alter_close_game_data("disable");
	if (opacity>0) {
		opacity-=5; 
		gameDataDiv.style.opacity = (opacity / 100);  
		gameDataDiv.style.MozOpacity = (opacity / 100); 
		gameDataDiv.style.KhtmlOpacity = (opacity / 100); 
		gameDataDiv.style.filter = "alpha(opacity="+opacity+")"; 
	} else {
		window.clearInterval(inter);
		document.body.removeChild(document.getElementById("gamedata_container"));
	
	}
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e) {
 		//Internet Explorer
 		try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 		catch (e) {
	  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
} 

function game_data(game_id) {
	if (!game_id) {
	return false;		
	}
	 var myWidth = 0, myHeight = 0;
 	 if( typeof( window.innerWidth ) == 'number' ) {
   		 //Non-IE
   		 myWidth = window.innerWidth;
   		 myHeight = window.innerHeight;
 	 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    		//IE 6+ in 'standards compliant mode'
    		myWidth = document.documentElement.clientWidth;
    		myHeight = document.documentElement.clientHeight;
  	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
   		 //IE 4 compatible
    		myWidth = document.body.clientWidth;
    		myHeight = document.body.clientHeight;
  	}
	if (myWidth < 640) {
		window.alert("Your browser width is currently below 640px ("+myWidth+"px), game details may not appear correctly and as they were intended to be viewed. It is adviseable that you either resize your browser or increase your monitors resolution.");
	}
	if (myHeight < 400) {
		window.alert("Your browser height is currently below 430px ("+myHeight+"px), game details may not appear correctly and as they were intended to be viewed. It is adviseable that you either resize your browser or increase your monitors resolution.");
	}
	
	if (!afg_window(1)) {return false;}
	
	if (!game_id) {return false;}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {alert ("Browser does not support HTTP Request"); return false;} 
	try {
	var url="http://www.allformatgaming.com/scripts/game_data.php";
	url=url+"?game="+game_id;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=gameDataLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} catch (error) {
	var url="http://allformatgaming.com/scripts/game_data.php";
	url=url+"?game="+game_id;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=gameDataLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
		
	}
	
}

function gameDataLoaded() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
   		xmlDoc=xmlHttp.responseXML;
		if (xmlDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue=="1") {
			var error_message = xmlDoc.getElementsByTagName("error_message")[0].childNodes[0].nodeValue;
			
			document.getElementById("gameDataTop").innerHTML = '<div style="float:right; padding-right: 10px;"><img src="http://www.allformatgaming.com/images/gamedata_close.png" onmouseover="this.src=\'http://www.allformatgaming.com/images/gamedata_close_hover.png\'" onmouseout="this.src=\'http://www.allformatgaming.com/images/gamedata_close.png\'"  onclick="close_game_data();" id="close_gamedata_container" title="Close Window" /></div>Information<br />';
			
			document.getElementById("gameDataMiddle").innerHTML = '<div style="width: 600px; height: 90%; background-color: #FFFFFF; margin: auto; font: 12pt Arial; text-align: left; padding: 10px; overflow: auto;">'+error_message+'</div>';
			document.getElementById("gameDataMiddle").style.filter = 'alpha(opacity=90)';						
		} else {
			var game_id = xmlDoc.getElementsByTagName("id")[0].childNodes[0].nodeValue;
			var game_name = xmlDoc.getElementsByTagName("name")[0].childNodes[0].nodeValue;
			var game_console = xmlDoc.getElementsByTagName("console")[0].childNodes[0].nodeValue;
			var game_console_colour = xmlDoc.getElementsByTagName("console_colour")[0].childNodes[0].nodeValue;
			var game_developer = xmlDoc.getElementsByTagName("developers")[0].childNodes[0].nodeValue;
			var game_publisher = xmlDoc.getElementsByTagName("publishers")[0].childNodes[0].nodeValue;
			var game_genre = xmlDoc.getElementsByTagName("genres")[0].childNodes[0].nodeValue;
			var game_synopsis = xmlDoc.getElementsByTagName("synopsis")[0].childNodes[0].nodeValue;
			var game_players_off = xmlDoc.getElementsByTagName("players_offline")[0].childNodes[0].nodeValue;
			var game_players_on = xmlDoc.getElementsByTagName("players_online")[0].childNodes[0].nodeValue;
			var game_release_eu = xmlDoc.getElementsByTagName("release_eu")[0].childNodes[0].nodeValue;
			var game_release_us = xmlDoc.getElementsByTagName("release_us")[0].childNodes[0].nodeValue;
			var game_release_jap = xmlDoc.getElementsByTagName("release_jap")[0].childNodes[0].nodeValue;
			var game_multiplayer = xmlDoc.getElementsByTagName("multiplayer_modes")[0].childNodes[0].nodeValue;
			var game_online = xmlDoc.getElementsByTagName("online_modes")[0].childNodes[0].nodeValue;
			var game_features = xmlDoc.getElementsByTagName("features")[0].childNodes[0].nodeValue;
			var game_box_art = xmlDoc.getElementsByTagName("box_art")[0].childNodes[0].nodeValue;
			var game_wish_list = xmlDoc.getElementsByTagName("wish_list")[0].childNodes[0].nodeValue;
			var game_games_list = xmlDoc.getElementsByTagName("games_list")[0].childNodes[0].nodeValue;
			document.getElementById("gameDataMiddle").style.backgroundColor = game_console_colour;
			var lists_append = 'Add to: ';
			var lists;
			switch (game_wish_list) {
				case "add":
							game_wish_list = ' | <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'wish\', \'add\')">Add to Wish List</span>';
							break;
				case "remove":
							game_wish_list = ' | <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'wish\', \'remove\')">Remove from Wish List</span>';
							break;
				case "0":
							game_wish_list = '';
							break;
			}
			switch (game_games_list) {
				case "add":
							game_games_list = ' | <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'games\', \'add\')">Add to Games List</span>';
							break;
				case "remove":
							game_games_list = ' | <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'games\', \'remove\')">Remove from Games List</span>';
							break;
				case "0":
							game_games_list = '';
							break;
			}
			
			
					
			document.getElementById("gameDataTop").innerHTML = '<div style="float:right; padding-right: 10px;"><img src="http://www.allformatgaming.com/images/gamedata_close.png" onmouseover="this.src=\'http://www.allformatgaming.com/images/gamedata_close_hover.png\'" onmouseout="this.src=\'http://www.allformatgaming.com/images/gamedata_close.png\'"  onclick="close_game_data();" id="close_gamedata_container" title="Close Window" /></div><div style="width: 600px; margin: auto;">'+game_name+'<br /><span style="font: 10pt Arial;">'+game_console+'</span></div>';			
					
			document.getElementById("gameDataMiddle").innerHTML = '<div style="width: 600px; height: 90%; background-color: #FFFFFF; margin: auto; font: 12pt Arial; text-align: left; padding: 10px; overflow: auto;"><div id="gamedata_content_details"><div style="float: right; height: 220px; overflow: auto; width: 430px;"><b>Developer(s):</b> '+game_developer+'<br /><b>Publisher(s):</b> '+game_publisher+'<br /><b>Genre(s):</b> '+game_genre+'<br /><b>Release Date(s):</b><div style="padding-left: 10px;">Europe: '+game_release_eu+'<br />USA/North America: '+game_release_us+'<br />Japan/Asia: '+game_release_jap+'</div><b>Players:</b> '+game_players_off+' (offline), '+game_players_on+' (online)<br /><b>Offline Multiplayer Modes:</b> '+game_multiplayer+'<br /><b>Online Multiplayer Modes:</b> '+game_online+'<br /><b>Features:</b> '+game_features+'</div><div style="height: 220px;"><img src="'+game_box_art+'" /></div><b>Synopsis</b><br />'+game_synopsis+'</div><div id="gamedata_content_images" style="height: 280px; width: 600px; display:none; font: 10pt Arial;">No Images have been uploaded for this game.</div><div id="gamedata_content_videos" style="height: 280px; width: 600px; display:none; font: 10pt Arial;">No Videos have been uploaded for this game.</div><div id="gamedata_content_reviews" style="height: 280px; width: 600px; display:none; font: 10pt Arial;">No Reviews have been written for this game.</div><div id="gamedata_content_lists" style="height: 280px; width: 600px; display:none; font: 10pt Arial;"></div></div>';		
			
			document.getElementById("gameDataBottom").innerHTML = '<span id="details_link" style="color:#999999;">Details</span> | <span id="images_link" onclick="change_tab(\'images\')" style="cursor:pointer">Images</span> | <span id="videos_link" onclick="change_tab(\'videos\')" style="cursor:pointer">Videos</span> | <span id="reviews_link" onclick="change_tab(\'reviews\')" style="cursor:pointer">Reviews</span><span id="lists_links">'+game_wish_list+game_games_list+'</span> | <span id="editmode_link" style="cursor: pointer;" onclick="editMode(\''+game_id+'\');">Edit Mode</span>';
		}		
	}
	
}

function alter_close_game_data(which) {
var close_gamedata = document.getElementById("close_gamedata_container");// = "";
	//document.getElementById("close_gamedata_container").title = "You cannot close this window whilst it is loading.";
	switch(which) {
		case "enable":
			document.getElementById("close_gamedata_container").onclick = function() {close_game_data();}
			document.getElementById("close_gamedata_container").title = "Close Window";			
			break;
		case "disable":
			close_gamedata.onclick = "";
			close_gamedata.title = "You cannot close this window whilst it is loading.";
			break;
	}
}


function close_game_data() {
	inter = window.setInterval("decrementOpacity()", 1);

	/*
	if (window.removeEventListener) {
		window.removeEventListener("scroll", move_game_data, false);
	} else {
		document.body.onscroll = '';
	}
	*/
}

function move_game_data() {
	if (document.getElementById("gamedata_container")) {
		if (document.documentElement) {
			document.getElementById("gamedata_container").style.top = document.documentElement.scrollTop + "px";
			document.getElementById("gamedata_container").style.left = document.documentElement.scrollLeft + "px";
		} else if (document.body) {
			document.getElementById("gamedata_container").style.top = document.body.scrollTop + "px";
			document.getElementById("gamedata_container").style.left = document.body.scrollLeft + "px";
		}
	}


}

function search_window(text_only, user_id, list, letter, search_term, console, developer, publisher, genre) {
	

	if (!afg_window(0)) {return false;}
	
	var grid = '';
	
	if (text_only!="auto") {
		grid = 'Display results in text only view: <input id="game_search_form_grid" type="checkbox"';
		if (text_only=="text") {
			grid += ' checked="checked"';
		} else {
			grid += '';
		}
		grid += '><br />';	}
	var list_search = '';
	if (user_id && (list=="wish" || list=="games")) {
		list_search = "Search this users "+list+" list: <input id='game_search_form_list' type='checkbox'><input id='game_search_form_list_user' value='"+user_id+"' type='hidden'><input id='game_search_form_list_list' value='"+list+"' type='hidden'><br />";	
	}	
	if (search_term) {
		search_term = ' value="'+search_term+'"';
	}
	var aselected = (letter=="a") ? " selected" : "";
	var bselected = (letter=="b") ? " selected" : "";
	var cselected = (letter=="c") ? " selected" : "";
	var dselected = (letter=="d") ? " selected" : "";
	var eselected = (letter=="e") ? " selected" : "";
	var fselected = (letter=="f") ? " selected" : "";
	var gselected = (letter=="g") ? " selected" : "";
	var hselected = (letter=="h") ? " selected" : "";
	var iselected = (letter=="i") ? " selected" : "";
	var jselected = (letter=="j") ? " selected" : "";
	var kselected = (letter=="k") ? " selected" : "";
	var lselected = (letter=="l") ? " selected" : "";
	var mselected = (letter=="m") ? " selected" : "";
	var nselected = (letter=="n") ? " selected" : "";
	var oselected = (letter=="o") ? " selected" : "";
	var pselected = (letter=="p") ? " selected" : "";
	var qselected = (letter=="q") ? " selected" : "";
	var rselected = (letter=="r") ? " selected" : "";
	var sselected = (letter=="s") ? " selected" : "";
	var tselected = (letter=="t") ? " selected" : "";
	var uselected = (letter=="u") ? " selected" : "";
	var vselected = (letter=="v") ? " selected" : "";
	var wselected = (letter=="w") ? " selected" : "";
	var xselected = (letter=="x") ? " selected" : "";
	var yselected = (letter=="y") ? " selected" : "";
	var zselected = (letter=="z") ? " selected" : "";
	
			
	document.getElementById("gameDataTop").innerHTML = '<div style="float:right; padding-right: 10px;"><img src="http://www.allformatgaming.com/images/gamedata_close.png" onmouseover="this.src=\'http://www.allformatgaming.com/images/gamedata_close_hover.png\'" onmouseout="this.src=\'http://www.allformatgaming.com/images/gamedata_close.png\'"  onclick="close_game_data();" id="close_gamedata_container" title="Close Window" title="Close Window" /></div>Search<br />';
			
	document.getElementById("gameDataMiddle").innerHTML = '<div style="width: 600px; height: 90%; background-color: #FFFFFF; margin: auto; font: 12pt Arial; text-align: left; padding: 10px; overflow: auto;"><div id="game_search_form" style="display:none;">'+grid+list_search+'By Letter: <select id="game_search_form_letter"><option></option><option value="a" '+aselected+'>A</option><option value="b" '+bselected+'>B</option><option value="c" '+cselected+'>C</option><option value="d" '+dselected+'>D</option><option value="e" '+eselected+'>E</option><option value="f" '+fselected+'>F</option><option value="g" '+gselected+'>G</option><option value="h" '+hselected+'>H</option><option value="i" '+iselected+'>I</option><option value="j" '+jselected+'>J</option><option value="k" '+kselected+'>K</option><option value="l" '+lselected+'>L</option><option value="m" '+mselected+'>M</option><option value="n" '+nselected+'>N</option><option value="o" '+oselected+'>O</option><option value="p" '+pselected+'>P</option><option value="q" '+qselected+'>Q</option><option value="r" '+rselected+'>R</option><option value="s" '+sselected+'>S</option><option value="t" '+tselected+'>T</option><option value="u" '+uselected+'>U</option><option value="v" '+vselected+'>V</option><option value="w" '+wselected+'>W</option><option value="x" '+xselected+'>X</option><option value="y" '+yselected+'>Y</option><option value="z" '+zselected+'>Z</option></select><br />Search Term: <input id="game_search_form_term" type="text" name="search_term"'+search_term+' /><br /></div><div id="game_search_form_hidden">Loading, please wait...</div></div>';
	
	alter_close_game_data("disable");
	try {
	var url="http://www.allformatgaming.com/scripts/devpubgen.php";
	var url_append = "?";
	if (console) {url += url_append+"console="+console; url_append = "&";}
	if (developer) {url += url_append+"developer="+developer; url_append = "&";}
	if (publisher) {url += url_append+"publisher="+publisher; url_append = "&";}
	if (genre) {url += url_append+"genre="+genre; url_append = "&";}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {alert ("Browser does not support HTTP Request"); return false;} 
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=searchFormLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} catch (error) {
	var url="http://allformatgaming.com/scripts/devpubgen.php";
	var url_append = "?";
	if (console) {url += url_append+"console="+console; url_append = "&";}
	if (developer) {url += url_append+"developer="+developer; url_append = "&";}
	if (publisher) {url += url_append+"publisher="+publisher; url_append = "&";}
	if (genre) {url += url_append+"genre="+genre; url_append = "&";}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {alert ("Browser does not support HTTP Request"); return false;} 
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=searchFormLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	
}

function searchFormLoaded() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
   		xmlDoc=xmlHttp.responseXML;
			var consoles = xmlDoc.getElementsByTagName("consoles")[0].childNodes[0].nodeValue-1;
			var console_search = 'Console: <select id="game_search_form_console"><option></option>';
			var opt_group = 1;
			var selected = '';
			for (var a=0; a<=consoles; a++) {
				if (xmlDoc.getElementsByTagName("console_type")[a].childNodes[0].nodeValue=="man") {
					if (opt_group>1) {console_search += '</optgroup>';}
					console_search += '<optgroup label="'+xmlDoc.getElementsByTagName("console_name")[a].childNodes[0].nodeValue+'">';
					opt_group++;
				} else if (xmlDoc.getElementsByTagName("console_type")[a].childNodes[0].nodeValue=="con") {
					selected = (xmlDoc.getElementsByTagName("console_selected")[a].childNodes[0].nodeValue=="1") ? " Selected" : '';
				console_search += '<option value="'+xmlDoc.getElementsByTagName("console_id")[a].childNodes[0].nodeValue+'"'+selected+'>'+xmlDoc.getElementsByTagName("console_name")[a].childNodes[0].nodeValue+'</option>';
				}
			}	
			console_search += '</optgroup></select>';
								
			var developers = xmlDoc.getElementsByTagName("developers")[0].childNodes[0].nodeValue-1;
			var developer_search = 'Developer: <select id="game_search_form_developer"><option></option>';
			var selected = '';
			for (var a=0; a<=developers; a++) {
				selected = (xmlDoc.getElementsByTagName("developer_selected")[a].childNodes[0].nodeValue=="1") ? " Selected" : '';
				developer_search += '<option value="'+xmlDoc.getElementsByTagName("developer_id")[a].childNodes[0].nodeValue+'"'+selected+'>'+xmlDoc.getElementsByTagName("developer_name")[a].childNodes[0].nodeValue+'</option>';
			}	
			developer_search += '</select>';
			
			var publishers = xmlDoc.getElementsByTagName("publishers")[0].childNodes[0].nodeValue-1;
			var publisher_search = 'Publisher: <select id="game_search_form_publisher"><option></option>';
			var selected = '';
			for (var a=0; a<=publishers; a++) {
				selected = (xmlDoc.getElementsByTagName("publisher_selected")[a].childNodes[0].nodeValue=="1") ? " Selected" : '';
				publisher_search += '<option value="'+xmlDoc.getElementsByTagName("publisher_id")[a].childNodes[0].nodeValue+'"'+selected+'>'+xmlDoc.getElementsByTagName("publisher_name")[a].childNodes[0].nodeValue+'</option>';
			}	
			publisher_search += '</select>';
			
			var genres = xmlDoc.getElementsByTagName("genres")[0].childNodes[0].nodeValue-1;
			var genre_search = 'Genre: <select id="game_search_form_genre"><option></option>';
			var selected = '';
			for (var a=0; a<=genres; a++) {
				selected = (xmlDoc.getElementsByTagName("genre_selected")[a].childNodes[0].nodeValue=="1") ? " Selected" : '';
				genre_search += '<option value="'+xmlDoc.getElementsByTagName("genre_id")[a].childNodes[0].nodeValue+'"'+selected+'>'+xmlDoc.getElementsByTagName("genre_name")[a].childNodes[0].nodeValue+'</option>';
			}	
			genre_search += '</select>';
			
			
			document.getElementById("game_search_form").innerHTML += console_search+'<br />'+developer_search+'<br />'+publisher_search+'<br />'+genre_search+'<br /><input type="button" value="Search" onclick="build_search();">';
			
			document.getElementById("game_search_form_hidden").style.display="none";
			document.getElementById("game_search_form").style.display='';
			alter_close_game_data("enable");
	}
	
}

function build_search() {
	
	var url="http://www.allformatgaming.com/videogames/";
	var grid = document.getElementById("game_search_form_grid").checked;
	var letter = document.getElementById("game_search_form_letter").options[document.getElementById("game_search_form_letter").selectedIndex].value;
	var search_term = document.getElementById("game_search_form_term").value;
	
	var console = document.getElementById("game_search_form_console").value;
	var developer = document.getElementById("game_search_form_developer").value;
	var publisher = document.getElementById("game_search_form_publisher").value;
	var genre = document.getElementById("game_search_form_genre").value;
	
	
	var url_append = "?";
	if (document.getElementById("game_search_form_list")) {
		if (document.getElementById("game_search_form_list").checked==true) {
			var user_id = document.getElementById("game_search_form_list_user").value;
			var list = document.getElementById("game_search_form_list_list").value;
			url += url_append+"list="+list+"&user="+user_id;
			url_append = "&";
		}
	}
	if (grid) {
			url += url_append+"grid=text";
			url_append = "&";
	}
	if (letter) {
			url += url_append+"letter="+letter;
			url_append = "&";
	}
	if (search_term) {
			url += url_append+"search="+search_term;
			url_append = "&";
	}
	if (console) {
			url += url_append+"console="+console;
			url_append = "&";
	}
	if (developer) {
			url += url_append+"developer="+developer;
			url_append = "&";
	}
	if (publisher) {
			url += url_append+"publisher="+publisher;
			url_append = "&";
	}
	if (genre) {
			url += url_append+"genre="+genre;
			url_append = "&";
	}
	if (url!="http://www.allformatgaming.com/videogames/") {
		window.open(url, "_top");
	}
}



function resultsLoaded() {
	if (document.getElementById("game_loading_pane")) {
	document.getElementById("game_loading_pane").style.display='none'; 
	}
	if (document.getElementById("game_search_results")) {
	document.getElementById("game_search_results").style.display='';
	}
	reset_recent_games();
}

function reset_recent_games() {
	if (document.getElementById("recent_games")) {
		document.getElementById("recent_games").scrollLeft = 0;
	}
}

var int, scroll_max, scroll_left;
function move(dir) {
scroll_left = document.getElementById("recent_games").scrollLeft;
if (dir=="right") {
if (scroll_left==3200) {
return false;
} else {
document.getElementById("recentgames_move_right").onclick=function() {move('none'); return false;}
scroll_max = scroll_left + 800;
int = setInterval(animate_move_right, 1);
}
} else if (dir=="left") {
if (scroll_left==0) {
return false;
} else {
document.getElementById("recentgames_move_left").onclick=function() {move('none'); return false;}
scroll_max = scroll_left - 800;
int = setInterval(animate_move_left, 1);
}
}

}

function animate_move_right() {
	var scroll_left = document.getElementById("recent_games").scrollLeft;
	var scroll_left = scroll_left + 25;
	document.getElementById("recent_games").scrollLeft=scroll_left;
	
	if (scroll_left==scroll_max) {
		window.clearInterval(int);
		if (scroll_left==3200) {
			document.getElementById("recentgames_right").style.display='none';
		} else {
			document.getElementById("recentgames_right").style.display='';
		}
		if (scroll_left==0) {
			document.getElementById("recentgames_left").style.display='none';
		} else {
			document.getElementById("recentgames_left").style.display='';
		}
		document.getElementById("recentgames_move_right").onclick=function() {move('right'); return false;}
	}
}

function animate_move_left() {
	var scroll_left = document.getElementById("recent_games").scrollLeft;
	var scroll_left = scroll_left - 25;
	document.getElementById("recent_games").scrollLeft=scroll_left;

	if (scroll_left==scroll_max) {
		window.clearInterval(int);
		if (scroll_left==0) {
			document.getElementById("recentgames_left").style.display='none';
		} else {
			document.getElementById("recentgames_left").style.display='';
		}
		if (scroll_left==2000) {
			document.getElementById("recentgames_right").style.display='none';
		} else {
			document.getElementById("recentgames_right").style.display='';
		}
		document.getElementById("recentgames_move_left").onclick=function() {move('left'); return false;}
	}
}

function change_tab(which) {
	if (which=="lists" || which=="show_all") {
	document.getElementById("gamedata_content_lists").style.display="";
	} else {
	document.getElementById("gamedata_content_lists").style.display="none";
	}
	var cycle = new Array("details", "images", "videos", "reviews");//, "editmode");
	for (var a=0; a<= 3; a++) {
		document.getElementById(cycle[a]+"_link").style.color = (which=="lists") ? "#999999" : "#000000";
		document.getElementById(cycle[a]+"_link").style.cursor = (which=="lists") ? "" : "pointer";
		document.getElementById("gamedata_content_"+cycle[a]).style.display="none";
		if (which=="lists") {
			document.getElementById(cycle[a]+"_link").onclick = '';
		} else {
		switch(cycle[a]) {
			case "details":
				document.getElementById(cycle[a]+"_link").onclick = function() {change_tab('details');}
				break;
			case "images":
				document.getElementById(cycle[a]+"_link").onclick = function() {change_tab('images');}
				break;
			case "videos":
				document.getElementById(cycle[a]+"_link").onclick = function() {change_tab('videos');}
				break;
			case "reviews":
				document.getElementById(cycle[a]+"_link").onclick = function() {change_tab('reviews');}
				break;
		}
		}
	}
	if (which!="lists" && which!="show_all") {
	document.getElementById(which+"_link").style.color="#999999";
	document.getElementById(which+"_link").style.cursor="";
	document.getElementById(which+"_link").onclick = '';
	}
	if (which!="show_all") {
	document.getElementById("gamedata_content_"+which).style.display="";
	}
}

function lists(game_id, list, mode) {
	if (!game_id) {
		return false;
	}
	if (list!="games" && list!="wish") {
		return false;
	}
	if (mode!="add" && mode !="remove") {
		return false;
	}	
	change_tab("lists");
	alter_close_game_data("disable");
	document.getElementById("gamedata_content_lists").innerHTML = "Updating list, please wait...";
	document.getElementById("lists_links").innerHTML = "&nbsp;| Updating...";
	
	xmlHttp=GetXmlHttpObject();
	try {
	var url = "http://www.allformatgaming.com/scripts/user_lists.php?game="+game_id+"&mode="+mode+"&list="+list;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=listsUpdated;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} catch (error) {
	var url = "http://allformatgaming.com/scripts/user_lists.php?game="+game_id+"&mode="+mode+"&list="+list;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=listsUpdated;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
	
}
function listsUpdated() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
   		xmlDoc=xmlHttp.responseXML;
		if (xmlDoc.getElementsByTagName("error")[0].childNodes[0].nodeValue=="1") {
			var game_id = xmlDoc.getElementsByTagName("game_id")[0].childNodes[0].nodeValue;
			var message = xmlDoc.getElementsByTagName("error_message")[0].childNodes[0].nodeValue;
			var wish_list = xmlDoc.getElementsByTagName("wish_list")[0].childNodes[0].nodeValue;
			var games_list = xmlDoc.getElementsByTagName("games_list")[0].childNodes[0].nodeValue;
		} else {
			var game_id = xmlDoc.getElementsByTagName("game_id")[0].childNodes[0].nodeValue;
			var message = xmlDoc.getElementsByTagName("success_message")[0].childNodes[0].nodeValue;
			var wish_list = xmlDoc.getElementsByTagName("wish_list")[0].childNodes[0].nodeValue;
			var games_list = xmlDoc.getElementsByTagName("games_list")[0].childNodes[0].nodeValue;
			
			
		}
			switch (wish_list) {
				case "add":
							wish_list_text = '&nbsp;| <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'wish\', \'add\')">Add to Wish List</span>';
							break;
				case "remove":
							wish_list_text = '&nbsp;| <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'wish\', \'remove\')">Remove from Wish List</span>';
							break;
				case "0":
							wish_list_text = '';
							break;
			}
			switch (games_list) {
				case "add":
							games_list_text = '&nbsp;| <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'games\', \'add\')">Add to Games List</span>';
							break;
				case "remove":
							games_list_text = '&nbsp;| <span id="wishlist_link" style="cursor: pointer;" onclick="lists(\''+game_id+'\', \'games\', \'remove\')">Remove from Games List</span>';
							break;
				case "0":
							games_list_text = '';
							break;
			}
			if (games_list=="remove") {
				if (document.getElementById("recent_"+game_id)) {
					document.getElementById("recent_"+game_id).innerHTML = '<img title="This game is on your games list" src="http://www.allformatgaming.com/images/games_list.png" />';
				}
				if (document.getElementById("game_"+game_id)) {
					document.getElementById("game_"+game_id).innerHTML = '<img title="This game is on your games list" src="http://www.allformatgaming.com/images/games_list.png" />';
				}
				if (document.getElementById("selected_"+game_id)) {
					document.getElementById("selected_"+game_id).innerHTML = '<img title="This game is on your games list" src="http://www.allformatgaming.com/images/games_list.png" />';
				}
			} else if (wish_list=="remove") {	
				if (document.getElementById("recent_"+game_id)) {
					document.getElementById("recent_"+game_id).innerHTML = '<img title="This game is on your wish list" src="http://www.allformatgaming.com/images/wish_list.png" />';
				}
				if (document.getElementById("game_"+game_id)) {
					document.getElementById("game_"+game_id).innerHTML = '<img title="This game is on your wish list" src="http://www.allformatgaming.com/images/wish_list.png" />';
				}
				if (document.getElementById("selected_"+game_id)) {
					document.getElementById("selected_"+game_id).innerHTML = '<img title="This game is on your games list" src="http://www.allformatgaming.com/images/games_list.png" />';
				}
			} else {
				if (document.getElementById("recent_"+game_id)) {
					document.getElementById("recent_"+game_id).innerHTML = '';
				}
				if (document.getElementById("game_"+game_id)) {
					document.getElementById("game_"+game_id).innerHTML = '';
				}	
				if (document.getElementById("selected_"+game_id)) {
					document.getElementById("selected_"+game_id).innerHTML = '';
				}			
			}
			alter_close_game_data("enable");
			document.getElementById("gamedata_content_lists").innerHTML = message;
			
			document.getElementById("lists_links").innerHTML = wish_list_text+games_list_text;
			change_tab("show_all");
	}
}

function rss() {
	afg_window(0);
	document.getElementById("gameDataTop").innerHTML = '<div style="float:right; padding-right: 10px;"><img src="http://www.allformatgaming.com/images/gamedata_close.png" onmouseover="this.src=\'http://www.allformatgaming.com/images/gamedata_close_hover.png\'" onmouseout="this.src=\'http://www.allformatgaming.com/images/gamedata_close.png\'"  onclick="close_game_data();" id="close_gamedata_container" title="Close Window" title="Close Window" /></div>Recently Added Games RSS<br />';		
	document.getElementById("gameDataMiddle").innerHTML = '<div style="width: 600px; height: 90%; background-color: #FFFFFF; margin: auto; font: 12pt Arial; text-align: left; padding: 10px; overflow: auto;">Loading...</div>';
	alter_close_game_data("disable");
	try {
	var url="http://www.allformatgaming.com/scripts/devpubgen.php";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {alert ("Browser does not support HTTP Request"); return false;} 
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=rssFormLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	} catch (error) {
	var url="http://allformatgaming.com/scripts/devpubgen.php";
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {alert ("Browser does not support HTTP Request"); return false;} 
	url=url+"?sid="+Math.random();
	xmlHttp.onreadystatechange=rsshFormLoaded;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	}
}
function rssFormLoaded() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
   		xmlDoc=xmlHttp.responseXML;
			var consoles = xmlDoc.getElementsByTagName("consoles")[0].childNodes[0].nodeValue-1;
			var console_search = '<select name="console"><option></option>';
			var opt_group = 1;
			for (var a=0; a<=consoles; a++) {
				if (xmlDoc.getElementsByTagName("console_type")[a].childNodes[0].nodeValue=="man") {
					if (opt_group>1) {console_search += '</optgroup>';}
					console_search += '<optgroup label="'+xmlDoc.getElementsByTagName("console_name")[a].childNodes[0].nodeValue+'">';
					opt_group++;
				} else if (xmlDoc.getElementsByTagName("console_type")[a].childNodes[0].nodeValue=="con") {
				console_search += '<option value="'+xmlDoc.getElementsByTagName("console_id")[a].childNodes[0].nodeValue+'">'+xmlDoc.getElementsByTagName("console_name")[a].childNodes[0].nodeValue+'</option>';
				}
			}	
			console_search += "</optgroup></select>";
	document.getElementById("gameDataMiddle").innerHTML = '<div style="width: 600px; height: 90%; background-color: #FFFFFF; margin: auto; font: 12pt Arial; text-align: left; padding: 10px; overflow: auto;"><input type="button" onclick="window.open(\'http://www.allformatgaming.com/videogames/recently_added.php\', \'_top\')" value="All Consoles" /><br /><br /><form action="http://www.allformatgaming.com/videogames/recently_added.php" method="get">Console Feed: '+console_search+' <input type="submit" value="View Feed" /></form></div>';
	alter_close_game_data("enable");
			
	}	
}

function editMode(game_id) {
	if (typeof editGame == 'function') { 
		editGame(game_id); 
	} else {
		window.alert("Currently Unavailable.");
	}
}
