// JavaScript Document

var xmlHttp;

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 loadgame_categories(str,limitstart)
{
	var base_url = document.getElementById('base_url').value;
	
	document.getElementById('gamecat_loader').innerHTML='<div style="clear:both; padding-top:320px; height:320px;" align="center"><img src="'+base_url+'images/loading.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url= base_url+"ajaxfunctions.php";
	url=url+"?page=gamecategories&limitstart="+limitstart;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("gamecat_loader").innerHTML=xmlHttp.responseText;
		
		$(document).ready(function() {
		
			//Select all anchor tag with rel set to tooltip
			$('a[rel=tooltip]').mouseover(function(e) {
				
				//Grab the title attribute's value and assign it to a variable
				var tip = $(this).attr('title');	
				
				//Remove the title attribute's to avoid the native tooltip from the browser
				$(this).attr('title','');
				
				//Append the tooltip template and its value
				$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
						
				//Show the tooltip with faceIn effect
				$('#tooltip').fadeIn('500');
				$('#tooltip').fadeTo('10',0.9);
				
			}).mousemove(function(e) {
			
				//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
				$('#tooltip').css('top', e.pageY + 10 );
				$('#tooltip').css('left', e.pageX + 20 );
				
			}).mouseout(function() {
			
				//Put back the title attribute's value
				$(this).attr('title',$('.tipBody').html());
			
				//Remove the appended tooltip template
				$(this).children('div#tooltip').remove();
				
			});
		
		});
	} 
}


function loadfavorites(str,limitstart)
{
	
	var base_url = document.getElementById('base_url').value;

	document.getElementById('user_favorites').innerHTML='<div style="clear:both; padding-top:50px; height:52px;" align="center"><img src="'+base_url+'images/loading.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}

	var url= base_url+"ajaxfunctions.php";

	url=url+"?page=loadfavorites&str="+str+"&limitstart="+limitstart;

	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged2;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}


function stateChanged2() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("user_favorites").innerHTML=xmlHttp.responseText;
		
		$(document).ready(function() {
		
			//Select all anchor tag with rel set to tooltip
			$('a[rel=tooltip]').mouseover(function(e) {
				
				//Grab the title attribute's value and assign it to a variable
				var tip = $(this).attr('title');	
				
				//Remove the title attribute's to avoid the native tooltip from the browser
				$(this).attr('title','');
				
				//Append the tooltip template and its value
				$(this).append('<div id="tooltip"><div class="tipHeader"></div><div class="tipBody">' + tip + '</div><div class="tipFooter"></div></div>');		
						
				//Show the tooltip with faceIn effect
				$('#tooltip').fadeIn('500');
				$('#tooltip').fadeTo('10',0.9);
				
			}).mousemove(function(e) {
			
				//Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
				$('#tooltip').css('top', e.pageY + 10 );
				$('#tooltip').css('left', e.pageX + 20 );
				
			}).mouseout(function() {
			
				//Put back the title attribute's value
				$(this).attr('title',$('.tipBody').html());
			
				//Remove the appended tooltip template
				$(this).children('div#tooltip').remove();
				
			});
		
		});
	} 
}

function loadusercomments(str,limitstart)
{
	var base_url = document.getElementById('base_url').value;
	
	document.getElementById('user_comments').innerHTML='<div style="clear:both; padding-top:160px; height:160px;" align="center"><img src="'+base_url+'images/loading.gif"></div>';
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");
		return;
	}
	
	var url= base_url+"ajaxfunctions.php";

	url=url+"?page=loadusercomments&str="+str+"&limitstart="+limitstart;

	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged3;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}

function stateChanged3() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("user_comments").innerHTML=xmlHttp.responseText;
	} 
}

function loadgamecomments(str,limitstart)
{
	var base_url = document.getElementById('base_url').value;
	
	document.getElementById('game_comments').innerHTML='<div style="clear:both; padding-top:160px; height:160px;" align="center"><img src="'+base_url+'images/loading.gif"></div>';

	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null)
	{
		alert ("Browser does not support HTTP Request");

		return;
	}

	var url=base_url+"ajaxfunctions.php";

	url=url+"?page=loadgamecomments&str="+str+"&limitstart="+limitstart;

	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged4;

	xmlHttp.open("GET",url,true);

	xmlHttp.send(null);
}

function stateChanged4() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("game_comments").innerHTML=xmlHttp.responseText;
	} 
}

function check_commentform()
{
	if(document.getElementById('newcomment').value == "" || document.getElementById('newcomment').value == "Enter text here")
	{
		alert("Please Enter Comment");
		document.getElementById('newcomment').focus();
		return false;
	}
	else
		return true;
}
