


function pgss(ssid)
{
	$('[id^="GUID"]').hide();
	$('[id="' + ssid + '"]').show();
	$('[id="pbsspopup"]').appendTo("body");
	var offset = $('#pbsspopup').offset();
	$('#pbsspopup').css("top", ($(window).height() - $('#pbsspopup').height()) / 2 + $(window).scrollTop() + "px");
	$('#pbsspopup').css("left", ($(window).width() - $('#pbsspopup').width() ) / 2 + $(window).scrollLeft() + "px");
	$('[id="pbsspopup"]').show();
}



//TRACK MOUSE POSITION
var globalMouseX;
var globalMouseY;
$(document).ready(function()
{
	$("body").mousemove(
		function(e)
		{
			globalMouseX = e.pageX;
			globalMouseY = e.pageY;
		}
	);


	/*
	$('body').click(
		function(e)
		{
			if((e.target).tagName=='BODY')
			{
				window.open('http://www.gameservers.com/game_servers/battlefield_3.php');
			}
		}
	);*/


	
	
	
	$("span.siteheadmenu_itembox").mousemove(
		function(e)
		{
			$(this).css("background-color", '#3E0300');
		}
	);
	$("span.siteheadmenu_itembox").mouseout(
		function(e)
		{
			$(this).css("background-color", '#4E1301');
		}
	);
	//GT CLIENT PAGE
	$('.faqcollapsable').children().hide();
	$('.faqcollapsable').click(function(e)
	{
		if($(this).children().css('display') == 'block')
		{
			$(this).children().hide();
			$(this).css('background-image', 'url(/images/global/ico_16_expand.png)');
		}
		else
		{
			$(this).children().show();
			$(this).css('background-image', 'url(/images/global/ico_16_collapse.png)');
		}
	});

	chromeFixes();
	ieFixes();
});
//*******************************************************************************************
function ieFixes()
{
	if($.browser.msie && parseInt($.browser.version) == 8)
	{
		$(":checkbox").each(
			function()
			{
				$(this).css("margin-top", "-2px");
				$(this).css("top", "3px");
			}
		);
		$(":radio").each(
			function()
			{
				$(this).css("margin-top", "-2px");
				$(this).css("top", "3px");
			}
		);
		$(".table_lst tr td:last-child").css('border-right-width', '1px');
	}
	if($.browser.msie && parseInt($.browser.version) == 7)
	{
		$(":checkbox").each(
			function()
			{
				$(this).css("top", "-1px");
			}
		);
		$(":radio").each(
			function()
			{
				$(this).css("top", "-1px");
			}
		);
		$(".table_lst").attr('cellspacing', '0px');
		$(".table_frm").attr('cellspacing', '0px');
		$(".table_lst tr td:last-child").css('border-right-width', '1px');
	}
	if($.browser.msie && parseInt($.browser.version) == 6)
	{
		$(".table_frm").attr("cellspacing", '0px');
		$(".table_frm tr:first-child td").css('border-top-width', '1px');
		$(".table_frm tr td:first-child").css('border-left-width', '1px');
		$(".table_lst").attr('cellspacing', '0px');
		$(".table_lst tr:first-child td").css('border-top-width', '1px');
		$(".table_lst tr td:last-child").css('border-right-width', '1px');
		$(".table_lst tr td:first-child").css('border-left-width', '1px');
	}
}
//*******************************************************************************************
function chromeFixes()
{
	var is_chrome = /applewebkit/.test( navigator.userAgent.toLowerCase() );
	if(is_chrome)
	{
		$(":checkbox").each(
			function()
			{
				$(this).css("top", "3px");
			}
		);
		$(":radio").each(
			function()
			{
				$(this).css("top", "3px");
			}
		);
		$(".table_lst td").each(
			function()
			{
				var width = $(this).css("width");
				width = width.substring(0, width.length - 2);
				width = parseInt(width);
				var pad = 0;
				var temp = '';
				temp = $(this).css("padding-left");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("padding-right");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("border-left-width");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("border-right-width");
				pad += parseInt(temp.substring(0, temp.length - 2));
				if($(this).is(":visible") != true)
				{
					$(this).css("width", width + ((pad)) + 'px');
					return;
				}
				$(this).css("width", width + ((pad)*2) + 'px');
			}
		);
		$(".table_frm td").each(
			function()
			{
				var width = $(this).css("width");
				width = width.substring(0, width.length - 2);
				width = parseInt(width);
				var pad = 0;
				var temp = '';
				temp = $(this).css("padding-left");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("padding-right");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("border-left-width");
				pad += parseInt(temp.substring(0, temp.length - 2));
				temp = $(this).css("border-right-width");
				pad += parseInt(temp.substring(0, temp.length - 2));
				$(this).css("width", width + ((pad)*2) + 'px');
			}
		);
	}
}
function openInvoice(URL)
{
	var load = window.open(URL,'','scrollbars=yes, menubar=no,height=470,width=740,resizable=no,toolbar=no,location=no,status=no');
}
//*****************************************
//*****************************************
function numbersonly(event)
{
	var unicode = event.charCode ? event.charCode : event.keyCode;
	//alert(unicode);
	if (unicode == 8)
		return true;
	if (unicode == 9)
		return true;	
	if (unicode == 46)
		return true;	
	if (unicode >= 48 && unicode <= 57)
		return true;
	return false;
}


//*******************************************************************************************
function rgbFromHTML(html)
{
	return [parseInt('0x' + html.substring(0, 2)), parseInt('0x' + html.substring(2, 4)), parseInt('0x' + html.substring(4, 6))];
}
//*******************************************************************************************
function hexColor_GetLuminosity(hexColor)
{
	var rgbColor1 = rgbFromHTML(hexColor);
	return Math.round((rgbColor1[0] + rgbColor1[1] + rgbColor1[2]) / 3);
}
//*******************************************************************************************
function hexColor_GetFromRgbColor(rgb)
{
	rgb[0] = Math.round(rgb[0]);
	rgb[1] = Math.round(rgb[1]);
	rgb[2] = Math.round(rgb[2]);
	return (rgb[0] < 16 ? '0' : '') + rgb[0].toString(16) + (rgb[1] < 16 ? '0' : '') + rgb[1].toString(16) + (rgb[2] < 16 ? '0' : '') + rgb[2].toString(16);
}
//*******************************************************************************************
function hexColor_GetOffset(hexColor, offset)
{
	rgbColor = rgbFromHTML(hexColor);
	for(i=0; i < 3; ++i)
	{
		rgbColor[i] += offset;
		rgbColor[i] = Math.round(rgbColor[i]);
		if(rgbColor[i]<0)
			rgbColor[i] = 0;
		else if(rgbColor[i]>255)
			rgbColor[i] = 255;
	}
	return hexColor_GetFromRgbColor(rgbColor);
}
//*******************************************************************************************
function hexColor_GetBlend(hexColor1, hexColor2, color1Percentage)
{
	var rgbColor1 = rgbFromHTML(hexColor1);
	var rgbColor2 = rgbFromHTML(hexColor2);
	var rgbColor = [];
	for(var i=0; i < 3; ++i)
	{
		rgbColor[i] = rgbColor1[i]*color1Percentage + rgbColor2[i]*(1-color1Percentage);
		rgbColor[i] = Math.round(rgbColor[i]);
		if(rgbColor[i]<0)
			rgbColor[i] = 0;
		else if(rgbColor[i]>255)
			rgbColor[i] = 255;
	}
	return hexColor_GetFromRgbColor(rgbColor);
}
//*******************************************************************************************
function colorInputFormat(colorInput)
{
	color = colorInput.value.replace('#', '');
	color = color.toUpperCase();
	if(color.length != 6)
		color = '000000';
	colorInput.value = color;
	colorInput.style.backgroundColor = '#' + color;
	var lum = hexColor_GetLuminosity(color);
	if(lum > 128)
		colorInput.style.color = '#000000';
	else
		colorInput.style.color = '#FFFFFF';
}
//*******************************************************************************************
function colorInputOn(item)
{
	selectedColorInput = item;
	document.getElementById('colorpicker').style.display = 'block';
	var objPos = $(selectedColorInput).offset();
	var posTop = objPos.top + ($(selectedColorInput).height()/2) - ($('#colorpicker').height()/2);
	var posLeft = objPos.left + $(selectedColorInput).width() + 20;
	$('#colorpicker').css(
	{
		top: posTop,
		left: posLeft
	});
	farbPicker.setColor('#' + selectedColorInput.value);
	$(".color_sel").each(
		function()
		{
			if($(this).get(0) != selectedColorInput)
			{
				$(this).css("opacity",		0.15);
				$(this).css("MozOpacity",	0.15);
				$(this).css("filter",		'alpha(opacity=15)');
			}
		}
	);
}
//*******************************************************************************************
function colorInputOff()
{
	if(selectedColorInput == null)
		return;
	colorInputFormat(selectedColorInput)
	selectedColorInput = null;
	document.getElementById('colorpicker').style.display = 'none';
	$(".color_sel").each(
		function()
		{
			if($(this).get(0) != selectedColorInput)
			{
				$(this).css("opacity",		1);
				$(this).css("MozOpacity",	1);
				$(this).css("filter",		'alpha(opacity=100)');
			}
		}
	);
}
//*******************************************************************************************
function farbCallback(color)
{
	if(selectedColorInput == null)
		return;
	color = color.replace('#', '');
	color = color.toUpperCase();
	if(color.length != 6)
	{
		color = '000000'
	}
	selectedColorInput.value = color;
	colorInputFormat(selectedColorInput);
}
//*******************************************************************************************
function createCookie(name,value,hours) {
	if(hours) {
		var date = new Date();
		date.setTime(date.getTime()+(hours*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
//*******************************************************************************************
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if(c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
//*******************************************************************************************
function eraseCookie(name) {
	createCookie(name,"",-1);
}
//*******************************************************************************************
function addGameFavorite(GMID)
{
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'addGameFavorite=1&GMID=' + GMID,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#addGameFavorite' + GMID).hide();
				$('#delGameFavorite' + GMID).show();
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}
//*******************************************************************************************
function delGameFavorite(GMID)
{
	if(!confirm('Are you sure you want to remove this game from your favorites?'))
		return;
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'delGameFavorite=1&GMID=' + GMID,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#addGameFavorite' + GMID).show();
				$('#delGameFavorite' + GMID).hide();
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}


//*******************************************************************************************
function processAjaxRequest(e)
{
	var functionname = '';
	var id = '';
	var data1 = '';
	var data2 = '';
	$(e).children('input').each(
		function()
		{
			var name = $(this).attr('name');
			if(name=='')
			{
			}
			else if(name=='id')
			{
				id = $(this).val();
			}
			else if(name=='functionname')
			{
				functionname = $(this).val();
				data1 = functionname + '=';
			}
			else
			{
				data2 += '&' + name + '=' + $(this).val();
			}
		}
	);
	$.ajax
	({
		type:			"POST",
		url:			location,
		processData:	false,
		cache:			false,
		data:			data1 + data2,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#' + id).replaceWith(Base64.decode(resp_xml.getElementsByTagName('result_html').item(0).firstChild.data));
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return false;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return false;
		}
	});
	return false;
}




//*******************************************************************************************
function addAccountCompSpecsJS(e)
{
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'addAccountCompSpecs=1&type=' + e.type.value + '&description=' + e.description.value,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				document.getElementById("devicerows").innerHTML	= Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data);
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}
//*******************************************************************************************
function delAccountCompSpecsJS(e)
{
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'delAccountCompSpecs=1&id=' + e.id.value,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				document.getElementById("devicerows").innerHTML	= Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data);
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}
//*******************************************************************************************
function setAccountCompSpecsJS(e)
{
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'setAccountCompSpecs=1&id=' + e.id.value + '&description=' + e.description.value,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				document.getElementById("devicerows").innerHTML	= Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data);
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			$(e).show();
			return;
		}
	});
}
//*******************************************************************************************
function addAccountFavoriteServer(GAMESERVERID)
{
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'addAccountFavoriteServer=1&GAMESERVERID=' + GAMESERVERID,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#delAccountFavoriteServer' + GAMESERVERID).show();
				$('#addAccountFavoriteServer' + GAMESERVERID).hide();
				var message = '\
					<div class="blocknew blocknew980 blockthm_msg">\
						<div class="blocknewcnt">\
							You added this server to your <a href="/servers/">favorite servers</a>\
						</div>\
					</div>';
					$('#globalMessageDiv').html(message);
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}
//*******************************************************************************************
function delAccountFavoriteServer(GAMESERVERID)
{
	if(!confirm('Are you sure you want to remove this server from your favorites?'))
		return;
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'delAccountFavoriteServer=1&GAMESERVERID=' + GAMESERVERID,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#delAccountFavoriteServer' + GAMESERVERID).hide();
				$('#addAccountFavoriteServer' + GAMESERVERID).show();
				var message = '\
					<div class="blocknew blocknew980 blockthm_msg">\
						<div class="blocknewcnt">\
							You removed this server from your <a href="/servers/">favorite servers</a>\
						</div>\
					</div>';
					$('#globalMessageDiv').html(message);
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(jqXHR, textStatus, errorThrown)
		{
			alert('GameTracker could not process your request at this time. (' + textStatus + ' - ' + errorThrown.toString() + ')');
			return;
		}
	});
}
//*******************************************************************************************
function getAccountEventsForAccount()
{
	offset = $('#moreeventsbtn').attr('offset');
	if(offset==undefined)
		offset=30;
	else
		offset = parseInt(offset);
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'getAccountEventsForAccount=1&offset=' + offset,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#moreevents').append(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
				$('#moreeventsbtn').attr('offset', offset+30);
				if(resp_xml.getElementsByTagName('show_more').item(0).firstChild.data==0)
					$('#moreeventsbtn').hide();
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(jqXHR, textStatus, errorThrown)
		{
			alert('GameTracker could not process your request at this time. (' + textStatus + ' - ' + errorThrown.toString() + ')');
			return;
		}
	});
}
//*******************************************************************************************
function getAccountEventsForProfile(ACCTID)
{
	offset = $('#moreeventsbtn').attr('offset');
	if(offset==undefined)
		offset=20;
	else
		offset = parseInt(offset);
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'getAccountEventsForProfile=1&ACCTID=' + ACCTID + '&offset=' + offset,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				$('#moreevents').append(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
				$('#moreeventsbtn').attr('offset', offset+20);
				if(resp_xml.getElementsByTagName('show_more').item(0).firstChild.data==0)
					$('#moreeventsbtn').hide();
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(jqXHR, textStatus, errorThrown)
		{
			alert('GameTracker could not process your request at this time. (' + textStatus + ' - ' + errorThrown.toString() + ')');
			return;
		}
	});
}
//*******************************************************************************************
function addAbuseReport(type, BLOGPOSTID, note)
{
	$('#GTPOPUP').hide();
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'addAbuseReport=1&type=' + type + '&BLOGPOSTID=' + BLOGPOSTID + '&note=' + note,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				alert('Report submitted');
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
			return;
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
			return;
		}
	});
}



//*******************************************************************************************
function messageBoxConfirmSubmit(formName, msg)
{
	if(confirm(msg))
		document.getElementById(formName).submit();
}
//*******************************************************************************************
function toggleVisibility(id1, id2)
{
	$('#' + id1).hide();
	$('#' + id2).show();
}
//*******************************************************************************************
function showForm2(formElement)
{
	$('#' + formElement).show();
}
//*******************************************************************************************
function hideForm(formElement)
{
	$('#' + formElement).hide();
}
//*******************************************************************************************
function processTabClick(element)
{	
	var count = 0;
	var selected = null;
	var lastElem = null;
	$(element.parentNode).children('.blocknewtaboff, .blocknewtabon').each(
		function()
		{
			if(element == $(this).get(0))
			{
				selected = count;
				$(this).removeClass('blocknewtaboff');
				$(this).addClass('blocknewtabon');
				
			}
			else
			{
				$(this).addClass('blocknewtaboff');
				$(this).removeClass('blocknewtabon');
			}
			++count;
			lastElem = this;
		}
	);
	

	count=0;
	$(lastElem).nextAll().each(
		function()
		{
			if(count == selected)
				$(this).show();
			else
				$(this).hide();
			++count;
		}
	);
	return;
}



function scrolltoNext(element)
{
	element.style.display='none';
	$(element).next().show();
}
function scrolltoPrev(element)
{
	element.style.display='none';
	$(element).prev().show();
}


//*******************************************************************************************
function rowSelectAll()
{
	$(":checkbox").attr("checked", true);
	$(":checkbox").closest("tr").children().css("background-color", "#8E770B");
}
//*******************************************************************************************
function rowSelectNone()
{
	$(":checkbox").attr("checked", false);
	$(":checkbox").closest("tr").children().css("background-color", "");
}
//*******************************************************************************************
function rowSelectClickCheckbox(element)
{
	if($(element).attr("checked"))
		$(element).closest("tr").children().css("background-color", "#8E770B");
	else
		$(element).closest("tr").children().css("background-color", "");
}
//*******************************************************************************************
function rowSelectClickRow(element)
{
	if($(element).children("td:first-child").children(":checkbox").attr("checked"))
	{
		$(element).children().css("background-color", "");
		$(element).children("td:first-child").children(":checkbox").attr("checked", "");
	}
	else
	{
		$(element).children().css("background-color", "#8E770B");
		$(element).children("td:first-child").children(":checkbox").attr("checked", "checked");
	}
}
//*******************************************************************************************
function setGraphStart(unit)
{
	$('.button_t4_on').toggleClass('button_t4_on button_t4_off');
	$('#range_' + unit).toggleClass('button_t4_on button_t4_off');
	var srcSuffix = "&start=-1" + unit + "&request=" + Math.random().toString().replace(".", "");
	if(document.getElementById('graph_player_score')!=null)
		document.getElementById("graph_player_score").src = document.getElementById("graph_player_score").src.replace(/&start.*/, "") + srcSuffix;
	if(document.getElementById('graph_player_time')!=null)
		document.getElementById("graph_player_time").src = document.getElementById("graph_player_time").src.replace(/&start.*/, "") + srcSuffix;
	if(document.getElementById('graph_players')!=null)
		document.getElementById("graph_players").src = document.getElementById("graph_players").src.replace(/&start.*/, "") + srcSuffix;
}
//*******************************************************************************************
function stopPropagation(event)
{
	if($.browser.msie)
		window.event.cancelBubble = true
	else
		event.stopPropagation();
}
//*******************************************************************************************
function inputHintHide(element, event, hint)
{
	if(element.value == hint)
		element.value = "";
}




//*******************************************************************************************
//*******************************************************************************************
function hoverPopupShow(element, event, content)
{
	var popup = document.getElementById("HOVERPOPUP");
	if(popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "HOVERPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.zIndex = 1000;
		e.className = "popup";
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while (n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		popup = document.getElementById("HOVERPOPUP");
	}
	//DISPLAY
	if(popup.style.display == "none")
		popup.innerHTML = decodeURIComponent(unescape(content));
	popup.style.top = globalMouseY + 5 + "px";
	popup.style.left = globalMouseX + 5 + "px";
	popup.style.display = "block";
}
function hoverPopupHide()
{
	var popup = document.getElementById("HOVERPOPUP");
	if(popup != null)
		document.getElementById("HOVERPOPUP").style.display = "none";
}
//*******************************************************************************************
//*******************************************************************************************
function popupLoginShow(element, redirectURL)
{
	if(redirectURL == null)
		redirectURL = '';

	var popup = document.getElementById("LOGINPOPUP");
	if(popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "LOGINPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.top = "0px";
		e.style.left = "0px";
		e.style.zIndex = 1000;
		e.innerHTML = '\n\
			<div id="LOGINPOPUPWIDTH" class="blockthm_pop">\
				<div class="blocknew">\
					<div class="blocknewhdr item_text_aligncenter">\
						<div class="item_float_left">\
							<img style="padding-top:8px;" src="/images/global/ico_16_gt.png" alt="" />\
						</div>\
						&nbsp;GAMETRACKER&nbsp;\
						<div class="item_float_right">\
							<img id="LOGINPOPUPHIDE" class="item_color_link" style="padding-top:6px;" src="/images/global/ico_20_close.png" alt="Close" />\n\
						</div>\
						<div class="item_float_clear">\
						</div>\
					</div>\
					<div class="blocknewcnt item_text_aligncenter">\
						<form id="LOGINPOPUPFORM" method="post" action="' + redirectURL + '">\n\
									Username:&nbsp;&nbsp;\n\
									<input id="LOGINPOPUPUSERNAME" type="text" class="text" name="username" value=""/>\n\
									<div class="item_h05"></div>\
									Password:&nbsp;&nbsp;\n\
									<input id="LOGINPOPUPPASSWORD" type="password" class="text" name="password" value=""/>\n\
									<div class="item_h05"></div>\
									Remember&nbsp;Me:\n\
									<input type="checkbox" name="cookieuser" value="1">\n\
									<input type="submit" class="submit" name="loginfrompopup" value="LOGIN" />\n\
						</form>\n\
						<div class="item_h10">\
						</div>\n\
						<a href="/account/create/">Need an account?</a>\
						<br/>\
						<a href="/account/forgot_password/">Forgot Password?</a>\n\
					</div>\
				</div>\
			</div>';
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while(n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		//BIND EVENTS TO POPUP
		$('#LOGINPOPUPHIDE').click(function(e)
		{
			document.getElementById("LOGINPOPUP").style.display = 'none';
		});
		$('#LOGINPOPUPPASSWORD').keyup(function(e)
		{
			if(e.keyCode == 13)
				document.getElementById('LOGINPOPUPFORM').submit();
		});
		$('#LOGINPOPUPUSERNAME').keyup(function(e)
		{
			if(e.keyCode == 13)
				document.getElementById('LOGINPOPUPFORM').submit();
		});
		popup = document.getElementById("LOGINPOPUP");
	}
	//POSITION
	$('#LOGINPOPUP').css("top", ($(window).height() - $('#LOGINPOPUP').height()) / 2 + $(window).scrollTop() + "px");
	$('#LOGINPOPUP').css("left", ($(window).width() - $('#LOGINPOPUP').width() ) / 2 + $(window).scrollLeft() + "px");
	$('#LOGINPOPUP').css('display', 'block');
	$('#LOGINPOPUPUSERNAME').focus();
}
//*******************************************************************************************
//*******************************************************************************************
function popupShow(element, content, halign, valign)
{
	var popup = document.getElementById("GTPOPUP");
	if(popup == null)
	{
		//CREATE POPUP
		e = document.createElement("div");
		e.id = "GTPOPUP";
		e.style.display = "none";
		e.style.position = "absolute";
		e.style.top = "0px";
		e.style.left = "0px";
		e.style.zIndex = 1000;
		e.style.color = "white";
		e.style.fontSize = "8pt";
		e.innerHTML = '\n\
			<div id="GTPOPUPWIDTH" class="blockthm_pop">\
				<div class="blocknew">\
					<div class="blocknewhdr item_text_aligncenter">\
						<div class="item_float_left">\
							<img style="padding-top:8px;" src="/images/global/ico_16_gt.png" alt="" />\
						</div>\
						&nbsp;GAMETRACKER&nbsp;\
						<div class="item_float_right">\
							<img id="GTPOPUPCLOSE" class="item_color_link" style="padding-top:6px;" src="/images/global/ico_20_close.png" alt="Close" />\
						</div>\
						<div class="item_float_clear">\
						</div>\
					</div>\
					<div class="blocknewcnt" id="GTPOPUPCONTENT">\
					</div>\
				</div>\
			</div>';
		//INSERT POPUP INTO DOM
		n1 = document.body.firstChild;
		while (n1.nodeType != 1)
			n1 = n1.nextSibling;
		document.body.insertBefore(e, n1);
		//BIND EVENTS TO POPUP
		$("#GTPOPUPCLOSE").click(function(e)
		{
			$('#GTPOPUP').css('display', 'none');
		});
		popup = document.getElementById("GTPOPUP");
	}
	//if(popup.style.display == "none")
		$('#GTPOPUPCONTENT').html(decodeURIComponent(content));

	//POSITION
	var offset = $(element).offset();
	$('#GTPOPUP').css('display', 'block');
	if(valign == 'top')
		$('#GTPOPUP').css('top', offset.top + $(element).height() - $('#GTPOPUPWIDTH').height());
	else if(valign == 'center')
		$('#GTPOPUP').css('top', offset.top + $(element).height() - ($('#GTPOPUPWIDTH').height()/2));
	else if(valign == 'pagecenter')
		$('#GTPOPUP').css("top", ($(window).height() - $('#GTPOPUP').height()) / 2 + $(window).scrollTop() + "px");
	else
		$('#GTPOPUP').css('top', offset.top);


	if(halign == 'pagecenter')
		$('#GTPOPUP').css("left", ($(window).width() - $('#GTPOPUP').width() ) / 2 + $(window).scrollLeft() + "px");
	else if(halign == 'left')
		$('#GTPOPUP').css('left', offset.left);
	else if(halign == 'center')
		$('#GTPOPUP').css('left', offset.left + ($(element).width()/2) - ($('#GTPOPUPWIDTH').width()/2));
	else
		$('#GTPOPUP').css('left', offset.left + $(element).width());
};


function onsubmit_setAccountUsernameCheck(form)
{
	username = form.username.value;
	$.ajax
	({
		type:			"POST",
		url:			'/ajax_requests.php',
		processData:	false,
		cache:			false,
		data:			'setAccountUsernameCheck=1&username=' + username,
		dataType:		'xml',
		success: function(resp_xml)
		{
			if(resp_xml.normalize)
				resp_xml.normalize();
			if(resp_xml.getElementsByTagName('result').item(0).firstChild.data == 'SUCCESS')
			{
				if(confirm('"' + username + '" is available. Do you want to change your username now? You will be unable to change usernames for another week once you proceed.'))
					form.submit();
			}
			else
			{
				alert(Base64.decode(resp_xml.getElementsByTagName('result_string').item(0).firstChild.data));
			}
		},
		error: function(resp_xml)
		{
			alert('GameTracker could not process your request at this time.');
		}
	});
	return false;
}



//*******************************************************************************************
//*******************************************************************************************
function onsubmit_accountcreate()
{
	document.getElementById('ca_check_on').style.display = 'block';
	document.getElementById('ca_check_off').style.display = 'none';
	var dataString = '';
	dataString += 'username='	+ Base64.encode(document.signup.newAccountUsername.value);
	dataString += '&email='		+ Base64.encode(document.signup.email.value);
	dataString += '&password='	+ Base64.encode(document.signup.newAccountPassword.value);
	dataString += '&verify='	+ Base64.encode(document.signup.verify.value);
	dataString += '&over_13='	+ Base64.encode(document.signup.over_13.checked==true?'y':'n');
	dataString += '&tos='		+ Base64.encode(document.signup.tos.checked==true?'y':'n');
	dataString += '&action=check_account_username';
	$.ajax(
	{
		type: 'POST',
		url: '/ajax_requests.php?rnd=' + Math.round(Math.random() * 10000000),
		processData: false,
		data: dataString,
		dataType: 'html',
		success: function(html)
		{
			resultCode		= html.toString().substring(0, 1);
			resultString	= html.toString().substring(1);
			if(resultCode == 0)
			{
				document.getElementById('submit_error').style.display = 'none';
				document.getElementById('error_block').style.display = 'block';
				document.getElementById('error_block_content').innerHTML = resultString;
				document.getElementById('ca_check_on').style.display = 'none';
				document.getElementById('ca_check_off').style.display = 'block';
				return;
			}
			document.signup.submit();
			return;
		},
		error: function(html)
		{
			document.signup.submit();
			return;
		}
	});
}
function setClanCalenderDayData(element2)
{
	$(".calenderHideAll").hide();
	for(x in element2)
		document.getElementById('calenderDayData' + element2[x]).style.display = "inline-table";
}
function calenderHide(element2)
{
	document.getElementById('calenderDayData' + element2).style.display = "none";
}


//*******************************************************************************************
//*******************************************************************************************
function setSearchBy(val)
{
	$('form[name="name_ip"]').hide();
	$('form[name="map"]').hide();
	$('form[name="server_variable"]').hide();
	$('form[name="online_player"]').hide();
	$('form[name="online_offline_player"]').hide();
	$('form[name="player_bc2"]').hide();
	$('form[name="player_moh"]').hide();
	$('form[name="clan"]').hide();
	$('form[name="profile_username"]').hide();
	$('form[name="profile_lastname"]').hide();
	$('form[name="profile_email"]').hide();
	$('form[name=' + val + ']').show();
}
//*******************************************************************************************
//*******************************************************************************************
function searchFormSubmit(e)
{
	//SUBMIT
	var searchBy = $(e).attr('name');
	if(searchBy == "name_ip" || searchBy == "map" || searchBy == "online_player" || searchBy == "clan")
	{
		//GAME/LOCATION
		var loc = $(e).find('select[name="loc"]').val();
		var game = $(e).find('select[name="game"]').val();
		if(game != "_all" && loc != "_all")
			$(e).attr('action', '/search/' + game + '/' + loc + '/');
		else if(game != "_all")
			$(e).attr('action', '/search/' + game + '/');
		else if(loc != "_all")
			$(e).attr('action', '/search/_all/' + loc + '/');
		$(e).find('select[name="loc"]').attr('disabled', 'disabled');
		$(e).find('select[name="game"]').attr('disabled', 'disabled');
		//SEARCH BY
		if(searchBy == "name_ip")
			$(e).find('input[name="search_by"]').attr('disabled', 'disabled');
		//QUERY
		var query = $(e).find('input[name="query"]').val();
		if(query == "")
			$(e).find('input[name="query"]').attr('disabled', 'disabled');
		//SORT
		var sort = $(e).find('input[name="sort"]').val();
		var order = $(e).find('input[name="order"]').val();
		if(sort == "" || sort == "rank" && order == "asc")
		{
			$(e).find('input[name="sort"]').attr('disabled', 'disabled');
			$(e).find('input[name="order"]').attr('disabled', 'disabled');
		}
		return true;
	}
	if(searchBy == "server_variable")
	{
		//GAME
		var game = $(e).find('select[name="game"]').val();
		if(game != "_all")
			$(e).attr('action', '/search/' + game + '/');
		$(e).find('select[name="game"]').attr('disabled', 'disabled');
		//SEARCH BY 2
		var searchBy2 = $(e).find('input[name="search_by2"]').val();
		if(searchBy2.length < 3)
		{
			alert('The server variable must be at least 3 characters in length.');
			return false;
		}
		return true;
	}
	if(searchBy == "online_offline_player")
	{
		//QUERY
		var query = $(e).find('input[name="query"]').val();
		if(query.length < 3)
		{
			alert('Your query must be at least 3 characters in length.');
			return false;
		}
		//SORT
		var sort = $(e).find('input[name="sort"]').val();
		var order = $(e).find('input[name="order"]').val();
		if(sort == "")
		{
			$(e).find('input[name="sort"]').attr('disabled', 'disabled');
			$(e).find('input[name="order"]').attr('disabled', 'disabled');
		}
		return true;
	}
	if(searchBy == 'player_bc2')
	{
		var query = $(e).find('input[name="query"]').val();
		if(query.length < 3)
		{
			alert('Your query must be at least 3 characters in length.');
			return false;
		}
		$(e).find('input[name="query"]').attr('disabled', 'disabled');
		$(e).attr('action', '/games/bc2/stats/' + query + '/');
		return true;
	}
	if(searchBy == 'player_moh')
	{
		var query = $(e).find('input[name="query"]').val();
		if(query.length < 3)
		{
			alert('Your query must be at least 3 characters in length.');
			return false;
		}
		$(e).find('input[name="query"]').attr('disabled', 'disabled');
		$(e).attr('action', '/games/moh/stats/' + query + '/');
		return true;
	}
	if(searchBy == 'profile_username' || searchBy == 'profile_lastname' || searchBy == 'profile_email')
	{
		//LOCATION
		var loc = $(e).find('select[name="loc"]').val();
		if(loc != "_all")
			$(e).attr('action', '/search/_all/' + loc + '/');
		$(e).find('select[name="loc"]').attr('disabled', 'disabled');
		//SORT
		var sort = $(e).find('input[name="sort"]').val();
		var order = $(e).find('input[name="order"]').val();
		if(sort == "")
		{
			$(e).find('input[name="sort"]').attr('disabled', 'disabled');
			$(e).find('input[name="order"]').attr('disabled', 'disabled');
		}
		return true;
	}
	return false;
}


//*******************************************************************************************
//*******************************************************************************************
function installSearchEngine()
{
	var noncompat_msg = "The browser you are using does not have compatible search engine support. GameTracker in-browser search is currently only supported by Firefox 1.5+ and MSIE 7.";
	if(window.external && ("AddSearchProvider" in window.external))
	{
		// Firefox 2 and IE 7, OpenSearch
		window.external.AddSearchProvider("http://www.gametracker.com/xml/search/opensearch/gt_server.xml");
	}
	else if(window.sidebar && ("addSearchEngine" in window.sidebar))
	{
		// Firefox <= 1.5, Sherlock
		window.sidebar.addSearchEngine("http://www.gametracker.com/search/sherlock/gt_server.src", "http://www.gametracker.com/search/sherlock/gt_server.gif", "GameTracker.com Server Search", "");
	}
	else
	{
		// No search engine support (IE 6, Opera, etc).
		alert(noncompat_msg);
	}
}

/**
*
* Base64 encode / decode
* http://www.webtoolkit.info/
*
**/
var Base64 = {
	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;
		//input = Base64._utf8_encode(input);
		while (i < input.length) {
			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);
			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;
			if(isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if(isNaN(chr3)) {
				enc4 = 64;
			}
			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
		}
		return output;
	},
	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;
		//input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
		while (i < input.length) {
			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));
			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;
			output = output + String.fromCharCode(chr1);
			if(enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if(enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}
		}
		//output = Base64._utf8_decode(output);
		return output;
	},
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
		for (var n = 0; n < string.length; n++) {
			var c = string.charCodeAt(n);
			if(c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
		}
		return utftext;
	},
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
		while ( i < utftext.length ) {
			c = utftext.charCodeAt(i);
			if(c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
		}
		return string;
	}
}
