/**********************
* (c) Gaming All Night
*    by Fg Designs
*  www.FgDesigns.net
***********************/

// Clear Form
function clearForm(field) {
	if(field.value == "Search Games...") {
		field.value = "";
	}
	else if(field.value == "") {
		field.value = "Search Games...";
	}
}

// Tabbed Forms
function tabSwitch(new_tab, new_content) {  
	document.getElementById('content_1').style.display = 'none';  
	document.getElementById('content_2').style.display = 'none';  
	document.getElementById(new_content).style.display = 'block';     
  
	document.getElementById('tab_1').className = 'tab';  
	document.getElementById('tab_2').className = 'tab';  
	document.getElementById(new_tab).className = 'tabSelected';          
}

// Favorite Game
function fav(itemID, type, user) {
	// Create object for request
	if (window.XMLHttpRequest) {
 		xmlhttp = new XMLHttpRequest();
	} else {
  		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	// Get Posts
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			// Checks to see if it was posted
			if(xmlhttp.responseText == 'faved') {
				document.getElementById('fav').className = 'faved';
				document.getElementById('fav').href = 'javascript:faved(\''+itemID+'\', \''+type+'\', \''+user+'\');';
				document.getElementById('fav').innerHTML = 'un-favorite';
				document.getElementById('fav1').className = 'faved';
				document.getElementById('fav1').href = 'javascript:faved(\''+itemID+'\', \''+type+'\', \''+user+'\');';
				document.getElementById('fav1').innerHTML = 'un-favorite';
			}
		}
	}
	
	xmlhttp.open("GET","/fav.php?i="+itemID+"&u="+user+"&type="+type,true);
	xmlhttp.send();
}
// Favorite Game
function faved(itemID, type, user) {
	// Create object for request
	if (window.XMLHttpRequest) {
 		xmlhttp = new XMLHttpRequest();
	} else {
  		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	// Get Posts
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			// Checks to see if it was posted
			if(xmlhttp.responseText == 'un') {
				document.getElementById('fav').className = 'fav';
				document.getElementById('fav').href = 'javascript:fav(\''+itemID+'\', \''+type+'\', \''+user+'\');';
				document.getElementById('fav').innerHTML = 'favorite game';
				document.getElementById('fav1').className = 'fav';
				document.getElementById('fav1').href = 'javascript:fav(\''+itemID+'\', \''+type+'\', \''+user+'\');';
				document.getElementById('fav1').innerText = 'favorite game';
			}
		}
	}
	
	xmlhttp.open("GET","/fav.php?i="+itemID+"&u="+user+"&type="+type+"&s=un",true);
	xmlhttp.send();
}

// Comment / Tips
function comment(itemID, type, gType, user) {
	
	// The comment or Tip
	if(type == 'comment') {
		comment = document.getElementById('comText').value;
	}
	else {
		comment = document.getElementById('tipText').value;
	}
	
	// Create object for request
	if (window.XMLHttpRequest) {
 		xmlhttp=new XMLHttpRequest();
	} else {
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  	}
	
	// Get Posts
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			// Checks to see if it was posted
			if(xmlhttp.reponseText == 'posted') {
				
			}
		}
	}
	
}

// Show Com
function showCom(type) {
	document.getElementById('add_'+ type).style.display = 'block';	
}
function closeCom(type) {
	document.getElementById('add_'+ type).style.display = 'none';
}

// Show Video
function showVideo() {
	document.getElementById('vPlayer').style.display = 'block';
}
function closeVideo() {
	document.getElementById('vPlayer').style.display = 'none';
}

// Sort By
function sortBy(menuObj, catI)
{
   var i = menuObj.selectedIndex;

   if(i > 0)
   {
      window.location = "http://www.gamingallnight.com/games.php?cat="+catI+"&s="+menuObj.options[i].value;
   }
}

// Sort By - Download Games
function sortByPC(menuObj, catI)
{
   var i = menuObj.selectedIndex;

   if(i > 0)
   {
      window.location = "http://www.gamingallnight.com/download_games.php?cat="+catI+"&s="+menuObj.options[i].value;
   }
}

// Mochi Bridge Scores
function bridge(gameID, uID, uName, profile, avatar) {
// Mochi Bridge
var options = {partnerID: "7db0aef89f57f5fc", id: "leaderboard_bridge"};
// User ID
options.userID = uID;
// Username
options.username = uName;
// Game ID
options.sessionID = gameID;
// Sends scores to
options.gateway = "http://www.gamingallnight.com/includes/bridge.php";
// User profile
options.profileURL = "http://www.gamingallnight.com/"+profile;
// User avatar image
options.thumbURL = "http://www.gamingallnight.com/forums/download/file.php?avatar="+avatar;
//options.postMedals = true;
// GAN logo 16x16 jpg
options.logoURL = "http://www.gamingallnight.com/template/images/mochi_icon.jpg";
// GAN URL
options.siteURL = "http://www.gamingallnight.com/";
// GAN site name
options.siteName = "Gaming All Night";
Mochi.addLeaderboardIntegration(options);
}
