var winChat = null;
function gameThumbOver(div)
{
	var titleDiv = div.firstChild;
	titleDiv.innerHTML = titleDiv.lang;
	setDivOpacity(titleDiv, .8);
}
function gameThumbOut(div)
{
	var titleDiv = div.firstChild;
	setDivOpacity(titleDiv, 0);

}

function fadeInDiv(div, speed, numTimes)
{
	var timePerCycle = speed / numTimes;
	var id = div.id;
	for(i = 0; i < numTimes; i++)
	{
		var num = (i + 1) / numTimes;
		window.setTimeout("setDivOpacity('" + id + "', '" + num + "')",(timePerCycle * i));
	}
}
function fadeOutDiv(div, speed, numTimes)
{
	var timePerCycle = speed / numTimes;
	var id = div.id;
	for(i = 0; i < numTimes; i++)
	{
		var num = (numTimes - i - 1) / numTimes;
		window.setTimeout("setDivOpacity('" + id + "', '" + num + "')",(timePerCycle * i));
	}
}
function setDivOpacity(div, num)
{
	div.style.opacity = num;
	div.style.MozOpacity = num;
	div.style.filter = 'alpha(opacity=' + (num*100) + ')';
}
function popReportGame(URL)
{
	winpops=window.open(URL,"","width=250,height=225,left=100,top=100,status=0,scrollbars=0,resizable=1,menubar=0,location=0,toolbar=0");
}
function ratingOver(num)
{
	var imageDiv = document.getElementById("ratingTitle");
	var curPosition = imageDiv.style.backgroundPositionY;
	if(curPosition != "94px")
	{
		imageDiv.style.backgroundPositionY = (7 - num) * 94 + "px";
	}
}
function ratingOut(num)
{
	var imageDiv = document.getElementById("ratingTitle");
	var curPosition = imageDiv.style.backgroundPositionY;
	if(curPosition != "94px")
	{
		imageDiv.style.backgroundPositionY = "0px";
	}
}
function ratingDown(num, gameid, baseURL)
{
	var imageDiv = document.getElementById("ratingTitle");
	var curPosition = imageDiv.style.backgroundPositionY;
	if(curPosition != "94px")
	{
		imageDiv.style.backgroundPositionY = "94px";
		makePOSTRequest(baseURL + "includes/rating_process.php?id=" + gameid + "&rating=" + num,"","curRating");
	}
}
function tellAFriend(baseURL, senderName, senderEmail, friendEmail, about, gameName, gameID)
{
	var url = baseURL + "index.php?action=tellafriendajax";
	var poststr = "sendersname=" + encodeURI(senderName) +
					"&sendersemail=" + encodeURI(senderEmail) +
					"&friendsemail=" + encodeURI(friendEmail) +
					"&about=" + encodeURI(about) +
					"&gamename=" + encodeURI(gameName) +
					"&gameid=" + encodeURI(gameID);

	makePOSTRequest(url, poststr, SpanName);
}

/************** AJAX Stuff *****************/

var http_request = false;

function show_hint ( p_hint_text, p_span )
{
	document.getElementById(p_span).innerHTML = p_hint_text ;
}

function makePOSTRequest(url, parameters, SpanName)
{
	http_request = false;
	if (window.XMLHttpRequest) // Mozilla, Safari,...
	{
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType)
		{
			http_request.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) // IE
	{
		try
		{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request)
	{
		alert('Cannot create XMLHTTP instance');
		return false;
	}

	http_request.onreadystatechange = function()
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				result = http_request.responseText;
				document.getElementById(SpanName).innerHTML = result;
			}
			else
			{
				alert('There was a problem with the request.');
			}
		}
	};
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}
function Contact(baseURL, obj,SpanName,DivName)
{
	var curDateTime = new Date(); //For IE

	if(DivName == 'tf')
	{
		var poststr = "sendersname=" + encodeURI( document.getElementById("sendersname").value ) +
						"&sendersemail=" + encodeURI( document.getElementById("sendersemail").value ) +
						"&friendsemail=" + encodeURI( document.getElementById("friendsemail").value ) +
						"&about=" + encodeURI( document.getElementById("about").value ) +
						"&gamename=" + encodeURI( document.getElementById("gamename").value ) +
						"&gameid=" + encodeURI( document.getElementById("gameid").value );
		makePOSTRequest(baseURL + 'index.php?action=tellafriendajax', poststr, SpanName);
	}
	if(DivName == 'tfv')
	{
		var poststr = "sendersname=" + encodeURI( document.getElementById("sendersname").value ) +
						"&sendersemail=" + encodeURI( document.getElementById("sendersemail").value ) +
						"&friendsemail=" + encodeURI( document.getElementById("friendsemail").value ) +
						"&about=" + encodeURI( document.getElementById("about").value ) +
						"&gamename=" + encodeURI( document.getElementById("gamename").value ) +
						"&verifycode=" + encodeURI( document.getElementById("tafverifycode").value ) +
						"&gameid=" + encodeURI( document.getElementById("gameid").value );
		makePOSTRequest(baseURL + 'index.php?action=tellafriendajax', poststr, SpanName);
	}
	if(DivName == 'cf')
	{
		var poststr = "newcomment=" + encodeURI( document.getElementById("newcomment").value ) +
						"&id=" + encodeURI( document.getElementById("gameid").value );
		makePOSTRequest(baseURL + 'index.php?action=addcommentajax', poststr, SpanName);
	}
	if(DivName == 'cfv')
	{
		var poststr = "newcomment=" + encodeURI( document.getElementById("newcomment").value ) +
		"&id=" + encodeURI( document.getElementById("id").value ) +
		"&verifycode=" + encodeURI( document.getElementById("cverifycode").value );

		makePOSTRequest(baseURL + 'index.php?action=addcommentajax', poststr, SpanName);
	}

	document.getElementById(DivName).style.display = 'none';
}


