var ItemsGrid;
var PlaygroundId;
var GameId;
var CharacterVar;
var DeliverDate;
var FirstName;
var LastName;
var Email;
var Address;
var City;
var Region;
var State;
var StateName;
var Country;
var CountryCode;
var ZipCode;
var AreaCode;
var Phone;
var CountryName;
var DeliverTimeDetail;
var Data = 0;
var LanguageId;
var CurrencyId;
var ProductType;
var SubmitedAmmount;
var PaymentType = 1;
var NewsValue;
var UserDetails;
var NotificationDetails;
var CustomerDetails;
var UserOrdersGrid;
var CustomerOrdersGrid;
var TestimonialsGrid;
var OrderID;
var ServerId;
var Amount;
var Price;
var OrderId;
var OrderDetailsGrid;
var ServerName;
var RegExpr;
var MatchingMessage = '';
var PlayName;

var PlacementFlow;

var SelectedAmountId;

var SellCurrencyPlayground;
var PlaygroundName;
var GameCommissionId;

var SellOrderMessage;
var SellingCharacter;
var SellingOrderId;

var USid = 223;

var PageWidth;
var PageHeight;

var LoadingMessageCount = 0;

var AccountsForSaleGrid;

var CDate = new Date();

var MouseX = 0;
var MouseY = 0;
var IE = Prototype.Browser.IE;
var UserOrdersInterval = 0;

var CustomerSupportSubjects = Array();

var HideLoadingInterval;

Blocks = Array();
Blocks[103] = Array("Maximum of 100 gold", "Maximum of 500 gold", "Maximum of 1000 gold", "Maximum of 2000 gold", "More than 2000 gold");
Blocks[104] = Array("Maximum of 100 gold", "Maximum of 500 gold", "Maximum of 1000 gold", "Maximum of 2000 gold", "More than 2000 gold");
Blocks[63] = Array("Maximum of 1000K PP", "Maximum of 3000K PP", "Maximum of 5000K PP", "Maximum of 10000K PP", "Above 10000K PP");
Blocks[64] = Array("100 to 500 plat", "501 to 1000 plat", "1001 to 2000 plat", "2001 to 4000 plat", "Above 4001 plat");
Blocks[49] = Array("1m-5m gil", "5m-10m gil", "10-20m gil", "20m-30m gil", "30m + gil");
Blocks[91] = Array("100m - 500m adena", "500m - 1b adena", "1b - 4b adena", "5b - 10b adena", "10b and up");
Blocks[83] = Array( "Maximum of 5000 gold", "Maximum of 10000 gold", "Maximum of 20000 gold", "Maximum of 40000 gold", "Above 40000 gold");
Blocks[105] = Array("Maximum of 10000 gold", "Maximum of 20000 gold", "Maximum of 50000 gold", "Above 50000 gold");
Blocks[106] = Array("Maximum of 10000 gold", "Maximum of 20000 gold", "Maximum of 50000 gold", "Above 50000 gold");
Blocks[65] = Array("1k-5k gold", "5k-10k gold", "10k-20k gold", "20k-30k gold", "30k and up");
Blocks[66] = Array("1k-5k gold", "5k-10k gold", "10k-20k gold", "20k-30k gold", "30k and up");
DefaultAmount = Array("1000 to 5000", "5001 to 10000", "10001 to 50000", "Above 50000");

Event.observe(window, 'load', Initialize, false);

function Initialize()
{
	window.historyStorage.init();
	window.dhtmlHistory.create();
	dhtmlHistory.initialize();
	dhtmlHistory.addListener(HistoryEvent);

	document.onmousemove = GetMousePosition;

	CurrentLocation = dhtmlHistory.getCurrentLocation();

	LoadUserDiv();

	if (AutoLoad != 0)
	{
		HistoryEvent(CurrentLocation);
	}
}

function HistoryEvent(NewLocation)
{
	if (NewLocation)
	{
		Location = NewLocation.split(';');
		GoTo = Location[0];
	}
	else
		GoTo = '';

	switch(GoTo)
	{
		case 'servers':
			LoadPlaygroundsPage(Location[1].match(/[0-9|_]{1,}/));
		break;

		case 'items':
			LoadItemsPage(Location[1].match(/[0-9|_]{1,}/));
		break;

		case 'checkout':
			if (ReadCookie('CartItems'))
			{
				if (Location[1].match(/[0-9|_]{1,}/))
					LoadPlaygrounds(Location[1].match(/[0-9|_]{1,}/), 0);
				else
					LoadGames();

				LoadCheckout();
			}
			else
			{
				LoadFirstPage();
			}

			if ($('UserDiv').innerHTML == '')
				LoadUserDiv();
		break;

		case 'sellcurrency':
			LoadSellCurrency();
			LoadGames();
			ReloadCart();
		break;

		case 'deliveryperformance':
			LoadDeliveryPerformance();
			LoadGames();
		break;

		case 'myorders':

			if (ReadCookie('User'))
			{
				LoadUserDiv();
				LoadMyOrders();
			}
			else
				LoadCustomerOrders();

			LoadGames();
		break;

		case 'testimonials':
			LoadTestimonials();
			LoadGames();
		break;

		case 'termsofservice':
			LoadTermsOfService();
			LoadGames();
		break;

		case 'faq':
			LoadFAQPage();
			LoadGames();
		break;

		case 'buyaccounts':
			LoadGames();
			LoadAccountsPage(Location[1].match(/[0-9|_]{1,}/));
		break;

		case 'CustomerSupport':
		case 'NewOrderConfirmation':
		case 'ExistingOrder':
		case 'ContactUs':
			LoadGames();
			LoadUserDiv();
			CustomerSupport('', GoTo);
		break;

		default:
			if (NewLocation.length > 0)
			{
				GetParameters(NewLocation);
			}
			else if (Redirect)
			{
				LoadWhyRedirected();
			}
			else if (DefaultGame)
			{
				LoadPlaygroundsPage(DefaultGame, DefaultUrl);
			}
			else
			{
				LoadFirstPage();
			}
	}

	$('dialog').style.display = 'none';
}

function LoadWhyRedirected()
{
	if ((ReadCookie('Redirect') == 1) && (ReadCookie('HideRedirect') == 0 || !ReadCookie('HideRedirect')))
	{
		window.location = RedirectUrl;
	}
	else
	{
		LoadFirstPage();
	}
}

function HideWhyRedirected()
{
	if (ReadCookie('HideRedirect'))
	{
		$('RedirectCustomer').style.display = 'none';
	}
}

function ShowRedirect()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/Redirect.php',
		{
			method: 'post',
			parameters: '',
			onSuccess: RedirectLoaded,
			onFailure: HandleFailure
		}
	);
}

function RedirectLoaded(Response)
{
	$('RedirectCustomer').innerHTML = Response.responseText;
}

function HideGreetingMessageDiv()
{
	if ($('GreetingDIV'))
	{
		$('GreetingDIV').style.display = 'none';
	}
}

function NeverRedirectMe()
{
	if (ReadCookie('User'))
	{
		document.cookie = 'UserOption=' + 1 + '; expires=Fri, 22 Jun ' + (CDate.getFullYear() + 2) + ' ' + CDate.getHours() + ':00:00 UTC; path=/';
	}
	else
	{
		document.cookie = 'CustomerOption=' + 1 + '; expires=Fri, 22 Jun ' + (CDate.getFullYear() + 2) + ' ' + CDate.getHours() + ':00:00 UTC; path=/';
	}

	HideMessageDiv();
}

function HideMessageDiv()
{
	HideWhyRedirected();

	if (ReadCookie('User'))
	{
		document.cookie = 'UserDismisses=' + 1 + '; path=/';
	}
	else
	{
		document.cookie = 'CustomerDismisses=' + 1 + '; path=/';
	}
}

function GetParameters(Url)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsUrls.php',
		{
			method: 'post',
			parameters: 'op=loaddata&url=' + encodeURIComponent(Url),
			onSuccess: PageParametersLoaded,
			onFailure: HandleFailure
		}
	);
}

function PageParametersLoaded(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		HistoryEvent(Result.Page);
	}
	else
	{
		return false;
	}
}

function CheckWhoIs()
{
	if(ReadCookie('CustomerId') && !ReadCookie('User'))
	{
		$('CustomerMyOrders').style.display = 'block';
	}
	else
	{
		$('CustomerMyOrders').style.display = 'none';
	}
}

// Data Grids
function InitGrid()
{
	ShowTableMessage(LoadingItemsText, 'Wait');

	var Opts =
	{
		PageScript: '/Ajax/GetGameMoney.php?playid=' + PlaygroundId,
		RowsPerPage: 99,
		HasHeader: true,
		HasFooter: true,
		FooterWhenNeeded: true,
		OddClass: 'OddCell',
		EvenClass: 'EvenCell',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		GlobalCallBack: TableCallback,
		Columns :
			[
				['name', true],
				['price', true],
				['ignore', false]
			]
	}

	ItemsGrid = new AbScript.AbGrid('ItemsGrid', Opts);
}

function InitCustomerOrdersGrid()
{
	var Opts =
	{
		PageScript: '/Ajax/GetCustomerOrders.php',
		RowsPerPage: 20,
		HasHeader: true,
		HasFooter: true,
		OddClass: 'OddCell',
		EvenClass: 'EvenCell',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		FooterWhenNeeded: true,
		Columns :
			[
				['Id', false],
				['server', false],
				['character', false],
				['price', false],
				['Status', true]
			]
	}

	UserOrdersGrid = new AbScript.AbGrid('UserOrders', Opts);

	if (!UserOrdersInterval)
		UserOrdersInterval = window.setInterval("CheckAndReloadOrders()", 25 * 1000);
}

function InitTestimonialsGrid()
{
	var Opts =
	{
		PageScript: '/Ajax/GetTestimonialsData.php',
		RowsPerPage: 10,
		HasHeader: true,
		HasFooter: true,
		FooterWhenNeeded: true,
		OddClass: 'content light',
		EvenClass: 'content dark',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		GlobalCallBack: TableCallback,
		Columns :
			[
				['ignore', false]
			]
	}

	TestimonialsGrid = new AbScript.AbGrid('Testimonials', Opts);
}

function InitRahanCurrencyNeeded(GameId)
{
	var Opts =
	{
		PageScript: '/Ajax/GetRahanCurrencyNeeded.php?gameid=' + GameId,
		RowsPerPage: 100,
		HasHeader: true,
		HasFooter: true,
		FooterWhenNeeded: true,
		OddClass: 'content light',
		EvenClass: 'content dark',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		Columns :
			[
				['server', true],
				['amount', true],
				['unitprice', true]
			]
	}

	CurrencyNeededGrid = new AbScript.AbGrid('TableCurrencyNeeded', Opts);
}

function InitDeliveryPerformance(Id)
{
	var Opts =
	{
		PageScript: '/Ajax/GetDeliveryPerformance.php?gameid=' + Id,
		RowsPerPage: 100,
		HasHeader: true,
		HasFooter: true,
		OddClass: 'content light',
		EvenClass: 'content dark',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		Columns :
			[
				['playground', true],
				['int1', true],
				['int2', true],
				['int3', true],
				['int4', true]
			]
	}

	DeliveryPerformanceGrid = new AbScript.AbGrid('TableDeliveryPerformance', Opts);
}

function InitAccountsForSaleGrid()
{
	var Opts =
	{
		PageScript: '/Ajax/GetAccountsForSale.php?gameid=' + GameId + '&sid=' + $F('ServerSelect'),
		RowsPerPage: 25,
		HasHeader: true,
		HasFooter: true,
		FooterWhenNeeded: true,
		OddClass: 'OddCell',
		EvenClass: 'EvenCell',
		ColumnPrefixClass: 'Col',
		FooterClass: 'FooterClass',
		FooterAClass: 'FooterAClass',
		Columns :
			[
				['ignore', false],
				['level', true],
				['race', true],
				['class', true],
				['gender', true],
				['price', true]
			]
	}

	AccountsForSaleGrid = new AbScript.AbGrid('Accounts', Opts);
}

function LoadFirstPage()
{
	document.location = '/#';
	ShowExpressCheckout();
	HideWhyRedirected();
	LoadGames();
	LoadFeaturedGames();
	LoadGreetings();
	LoadPageTitle();
	LoadGameNews('-1');

	if ($('UserDiv'))
	{
		LoadUserDiv();
	}

	ReloadCart();
}

function LoadItemsPage(Data)
{
	HideGreetings();
	HideExpressCheckout();
	HideWhyRedirected();

	Data = Data.toString();
	var Var = Data.split('_');

	if (ReadCookie('HideRedirect'))
	{
		HideWhyRedirected();
	}

	if (ReadCookie('Redirect'))
	{
		ShowRedirect();
	}

	GameId = Var[0];
	PlaygroundId = Var[1];

	if (Data)
	{
		new Ajax.Request
		(
			'/Ajax/ActionsUrls.php',
			{
				method: 'post',
				parameters: 'op=get' +
							 '&server=' + PlaygroundId,
				onSuccess: PlayUrlLoaded,
				onFailure: HandleFailure
			}
		);
	}
	else
		LoadGames();
}

function PlayUrlLoaded(response)
{
	eval("var Response=" + response.responseText);

	if (Response.Success && Response.Url)
	{
		LoadPlaygrounds(GameId, Response.Url);
		LoadGrid(PlaygroundId, Response.Url);
	}
	else
	{
		LoadPlaygrounds(GameId, 'items;' + GameId + '_' + PlaygroundId);
		LoadGrid(PlaygroundId, 'items;' + GameId + '_' + PlaygroundId);
	}

	ReloadCart();

	if ($('UserDiv').innerHTML == '')
		LoadUserDiv();
}

function LoadServersPerformance(Id)
{
	if (Id && ($('DivDeliveryPerformance').style.display == 'none'))
	{
		$('DivDeliveryPerformance').style.display = 'block';
	}
	if (!Id && ($('DivDeliveryPerformance').style.display == 'block'))
	{
		$('DivDeliveryPerformance').style.display = 'none';
	}

	ShowLoadingMessage();
	InitDeliveryPerformance(Id);
}

function LoadDeliveryPerformance()
{
	HideGreetings();
	HideExpressCheckout();
	HideWhyRedirected();
	dhtmlHistory.add("deliveryperformance");

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/DeliveryPerformance.php',
		{
			method: 'get',
			parameters: '',
			onSuccess: DeliveryPerformanceLoaded,
			onFailure: HandleFailure
		}
	);

	ReloadCart();
	LoadUserDiv();
}

function DeliveryPerformanceLoaded(Response)
{
	$('PageContent').innerHTML = Response.responseText;
	$('FeaturedGamesDiv').style.display = 'none';
}

function LoadTestimonials()
{
	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();
	dhtmlHistory.add("testimonials");

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetTestimonials.php',
		{
			method: 'get',
			parameters: '',
			onSuccess: TestimonialsLoaded,
			onFailure: HandleFailure
		}
	);

	ReloadCart();
	LoadUserDiv();
}

function TestimonialsLoaded(Response)
{
	$('PageContent').innerHTML = Response.responseText;
	InitTestimonialsGrid();
	$('FeaturedGamesDiv').style.display = 'none';
}

function LoadTermsOfService()
{
	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();
	dhtmlHistory.add("termsofservice");

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetTermsOfService.php',
		{
			method: 'get',
			parameters: '',
			onSuccess: TermsOfServiceLoaded,
			onFailure: HandleFailure
		}
	);

	ReloadCart();
	LoadUserDiv();
}

function TermsOfServiceLoaded(Response)
{
	$('PageContent').innerHTML = Response.responseText;
	$('FeaturedGamesDiv').style.display = 'none';
}

function LoadFAQPage()
{
	dhtmlHistory.add("faq");

	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFAQPage.php',
		{
			method: 'get',
			parameters: '',
			onSuccess: FAQPageLoaded,
			onFailure: HandleFailure
		}
	);

	ReloadCart();
	LoadUserDiv();
}

function FAQPageLoaded(Response)
{
	$('PageContent').innerHTML = Response.responseText;
	$('FeaturedGamesDiv').style.display = 'none';
}

function LoadPageTitle()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: 'action=loadfronttitle',
			onSuccess: PageTitleLoaded,
			onFailure: HandleFailure
		}
	);
}

function PageTitleLoaded(Response)
{
	eval("Result=" + Response.responseText);

	if (Result.Success)
	{
		if (Result.Data)
		{
			document.title = Result.Data;
		}
	}
	else
		HandleFailure(Response);
}

function LoadPlaygroundsPage(Game, UrlHash)
{
	if (!IsIndex)
	{

		document.location = '/#' + (UrlHash ? UrlHash : 'servers;' + Game);
		return;
	}

	HideGreetings();
	HideWhyRedirected();

	if (typeof UrlHash != 'string')
		UrlHash = document.location.hash;

	if (!UrlHash)
		UrlHash = 'Default';

	LoadPlaygrounds(Game, UrlHash);
	ReloadCart();

	if ($('BuyAccountsDiv'))
	{
		LoadAccountsPage(Game);
	}
	else
	{
		LoadGameNews(Game);
	}

	LoadGameTitle(Game);

	if ($('UserDiv').innerHTML == '')
		LoadUserDiv();
}

function LoadGameTitle(Game)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: 'action=loadtitle&id=' + Game,
			onSuccess: GameTitleLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function GameTitleLoaded(Response)
{
	CheckAndHideLoading();
	eval('Result=' + Response.responseText);

	if (Result.Success)
	{
		if (Result.Data.Title)
			document.title = Result.Data.Title;

		if (Result.Data.Description)
		{
			var MetaDescription = document.getElementsByName('description')[0];
			MetaDescription.content = Result.Data.Description;
		}

		if (Result.Data.Keywords)
		{
			var MetaKeywords = document.getElementsByName('keywords')[0];
			MetaKeywords.content = Result.Data.Keywords;
		}
	}
	else
		HandleFailure(Response);
}

function LoadFeaturedGames()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFeaturedGames.php',
		{
			method: 'post',
			onSuccess: FeaturedGamesLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function FeaturedGamesLoaded(Response)
{
	CheckAndHideLoading();

	if (Response.responseText.length > 1)
	{
		$('FeaturedGamesDiv').innerHTML = Response.responseText;
		$('FeaturedGamesDiv').style.display = 'block';
	}
	else
		$('FeaturedGamesDiv').style.display = 'none';
}

function LoadGreetings()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetGreeting.php',
		{
			method: 'post',
			onSuccess: GreetingsLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function GreetingsLoaded(Response)
{
	CheckAndHideLoading();

	if (Response.responseText.length > 1)
	{
		$('CustomerGreeting').innerHTML = Response.responseText;
		$('CustomerGreeting').style.display = 'block';
	}
	else
		$('CustomerGreeting').style.display = 'none';
}

function HideFeaturedGames()
{
	$('FeaturedGamesDiv').style.display = 'none';
}

function LoadUserDiv()
{
	HideGreetings();
	if (ReadCookie('User'))
	{
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/ActionsUsers.php',
			{
				method: 'post',
				parameters: 'op=checkuser',
				onSuccess: CheckUserResponse,
				onFailure: HandleFailure
			});
	}
	else
	{
		if ($('UserEmail') && $('UserPassword'))
			return;

		var AjaxRq = new Ajax.Request
		(
			'/Ajax/GetFile.php',
			{
				method: 'post',
				parameters: 'id=userlogin',
				onSuccess: LoginDivLoaded,
				onFailure: HandleFailure
		});
	}

	ShowLoadingMessage();
}

function LoginDivLoaded(Response)
{
	CheckAndHideLoading();
	$('UserDiv').innerHTML = Response.responseText;
}

function CheckUserResponse(Response)
{
	eval("var Response = " + Response.responseText);

	if (Response.Success)
	{
		UserDetails = Response.UserDetails;
		NotificationDetails = Response.NotificationDetails;
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/GetFile.php',
			{
				method: 'post',
				parameters: 'id=usermenu',
				onSuccess: UserMenuLoaded,
				onFailure: HandleFailure
			});
	}
	else
	{
		LogoutUser();

		var AjaxRq = new Ajax.Request
		(
			'/Ajax/GetFile.php',
			{
				method: 'post',
				params: 'id=userlogin',
				onSuccess: LoginDivLoaded,
				onFailure: HandleFailure
			}
		);
	}
}

function LoadPlaygrounds(Game, UrlHash)
{
	HideGreetings();
	HideWhyRedirected();
	if (typeof UrlHash == 'string')
	{
		dhtmlHistory.add(UrlHash);
	}
	else
	{
		dhtmlHistory.add(document.location.hash);
	}

	ShowLoadingMessage();

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetPlaygrounds.php',
		{
			method: 'post',
			parameters: 'gameid=' + Game,
			onSuccess: PlaygroundsLoaded,
			onFailure: HandleFailure
		}
	);

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: 'action=language&gameid=' + Game,
			onSuccess: LanguageResponseLoaded,
			onFailure: HandleFailure
		}
	);

	GameId = Game;
}

function PlaygroundsLoaded(Response)
{
	CheckAndHideLoading();

	$('GameList').innerHTML = Response.responseText;

	HideFeaturedGames();
	HideExpressCheckout();

	if ($('GameSelect'))
	{
		$('GameSelect').value = GameId;
	}
}

function LanguageResponseLoaded(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		if (Result.ChangeCurrency)
		{
			ChangeCurrency(Result.CurrencyId);
		}
	}
	else
	{
		HandleFailure(Response);
	}
}

function LoadGameNews(Game)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetGameNews.php',
		{
			method: 'post',
			parameters: 'gameid=' + Game,
			onSuccess: GameNewsLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function GameNewsLoaded(Response)
{
	CheckAndHideLoading();
	$('PageContent').innerHTML = Response.responseText;
}

function LoadUrl(Playground)
{
	PlaygroundId = Playground;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsUrls.php',
		{
			method: 'post',
			parameters: 'op=get&server=' + PlaygroundId,
			onSuccess: PageUrlLoaded,
			onFailure: HandleFailure
		}
	);
}

function PageUrlLoaded(Response)
{
	eval("var Result =" + Response.responseText);

	var GoToUrl = '';

	if (Result.Success)
	{
		GoToUrl = Result.Url;
	}
	else
		GoToUrl = 'items;' + GameId + '_' + PlaygroundId;

	LoadGrid(PlaygroundId, GoToUrl);
}

function LoadGrid(Playground, UrlHash)
{
	if (!IsIndex)
	{
		document.location = '/#' + UrlHash;
		return;
	}

	HideWhyRedirected();

	if (typeof UrlHash == 'string')
		CurrentUrl = UrlHash;
	else
		CurrentUrl = document.location.hash;

	PlaygroundId = Playground;
	window.scrollTo(0,0);

	AddClass('highlight' + PlaygroundId, 'light');

	if ($('BuyAccountsDiv'))
	{
		LoadAccountsPage();
		return;
	}

	if(Playground)
	{
		if (!$('ItemsGrid'))
		{
			var AjaxRq = new Ajax.Request
			(
				'/Ajax/GetFile.php',
				{
					method: 'post',
					parameters: 'id=itemsgrid',
					onSuccess: ItemsGridLoaded,
					onFailure: HandleFailure
				}
			);

			ShowLoadingMessage();
		}
		else
		{
			CheckAndHideLoading(1);
			dhtmlHistory.add(CurrentUrl);
			InitGrid();
			ReloadCart();
			GetServerName(PlaygroundId);
		}
	}
	else
	{
		$GameId = $('GameSelect').options[$('GameSelect').selectedIndex].value;
		LoadPlaygroundsPage($GameId, 'servers;' + $GameId);
	}
}

function ItemsGridLoaded(Response)
{
	CheckAndHideLoading(1);

	if (typeof CurrentUrl == 'string')
	{
		dhtmlHistory.add(CurrentUrl);
	}
	else
	{
		dhtmlHistory.add(document.location.hash);
	}
	MatchingMessage = '';
	HideGreetingMessageDiv();
	$('FeaturedGamesDiv').style.display = 'none';
	$('PageContent').innerHTML = Response.responseText;

	InitGrid();
	ReloadCart();
	GetServerName(PlaygroundId);
}

function AddClass(Id, ClassName)
{
	var Highlighted = document.getElementsByName('highlight');

	for (var i=0; i < Highlighted.length; i++)
	{
		if(Element.hasClassName(Highlighted[i], ClassName))
		{
			Element.removeClassName(document.getElementById(Highlighted[i].id), ClassName);
		}
	}

	Element.addClassName($(Id), ClassName);
}

function GetServerName(Id)
{
	if ($('PlaygroundSelect'))
		$('PlaygroundSelect').value = 'selected' + Id;

	new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: '&action=servername&id=' + Id +
						'&gameid=' + GameId,
			onSuccess: ServerNameLoaded,
			onFailure: HandleFailure
		}
	);
}

function ServerNameLoaded(response)
{
	eval('var Response = ' + response.responseText);

	if (Response.Success)
	{
		$('ServerName').innerHTML = Response.Data;

		$('ChangeFromCurrency').innerHTML = Response.CurrencyFrom;
		$('ChangeToCurrency').innerHTML = Response.CurrencyTo;

		if (Response.ShowCurrencyInfo)
			$('CurrencyInfo').style.display = 'block';
		else
			$('CurrencyInfo').style.display = 'none';
	}
	else
		HandleFailure(Response);
}

function ChangeLanguage(LangId)
{
	document.location = 'index.php?lang=' + LangId;
}

function ChangeCurrency(Currency)
{
	CurrencyId = Currency;
	document.cookie = 'Currency=' + CurrencyId + '; expires=Fri, 22 Jun ' + (CDate.getFullYear() + 2) + ' ' + CDate.getHours() + ':00:00 UTC; path=/';
	CurrentLocation = dhtmlHistory.getCurrentLocation();
	HistoryEvent(CurrentLocation);
}

function LoadItems()
{
	ShowTableMessage(LoadingItemsText, 'Wait');
	ItemsGrid.Options.PageScript = '/Ajax/GetItems.php?playid=' + PlaygroundId;
	ItemsGrid.Reload();

}

function LoadCurrency()
{
	ShowTableMessage(LoadingItemsText, 'Wait');
	ItemsGrid.Options.PageScript = '/Ajax/GetGameMoney.php?playid=' + PlaygroundId;
	ItemsGrid.Options.RowsPerPage = 99;
	ItemsGrid.Reload();

}

function AddAccount(Id)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=addacc&id=' + Id + '&server=' + PlaygroundId + '&type=3',
			onSuccess: ItemAddSuccess,
			onFailure: HandleFailure
		}
	);
}

function AddItem(Id)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=additem&id=' + Id + '&server=' + PlaygroundId + '&type=2',
			onSuccess: ItemAddSuccess,
			onFailure: HandleFailure
		}
	);
}

function ItemAddSuccess(Response)
{
	eval('var Result = ' + Response.responseText);

	if (Result.Success)
		ReloadCart();
	else
		HandleFailure(Response);
}

function AddGameMoney(Name, Id)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=addgmoney&id=' + Id + '&name=' + Name + '&server=' + PlaygroundId + '&type=1&directbuy=0',
			onSuccess: ItemAddSuccess,
			onFailure: HandleFailure
		}
	);

}

function ReloadCart()
{
	if (ReadCookie('CartItems'))
	{
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/GetCart.php',
			{
				method: 'post',
				parameters: '',
				onSuccess: CartLoadSuccess,
				onFailure: HandleFailure
			}
		);

		ShowLoadingMessage();
	}
	else
	{
		CheckAndHideLoading();
		$('ShoppingCart').style.display = 'none';
		$('ShoppingCartDiv').innerHTML = '';
	}
}

function CartLoadSuccess(Response)
{
	CheckAndHideLoading(1);

	if ($('ShoppingCart') && ReadCookie('CartItems'))
	{
		$('ShoppingCartDiv').innerHTML = Response.responseText;
		$('ShoppingCart').style.display = 'block';
		$('ShoppingCartDiv').style.display = 'block';
	}
}

function ShowItemData(ItemId)
{
	Item = ItemId;
	TimerId = setTimeout('LoadItemData()', 750);
}

function MouseOut()
{
	clearTimeout(TimerId);
	$('ItemDataDiv').style.display = 'none';
}

function LoadItemData()
{
	$('ItemDataDiv').style.left = MouseX + 15 + 'px';
	$('ItemDataDiv').style.top = MouseY + 15 + 'px';
	$('ItemDataDiv').style.display = 'block';
	$('ItemDataDiv').innerHTML = InfoLoadingItemDetails;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=loaditem&id=' + Item,
			onSuccess: ItemLoadSuccess,
			onFailure: HandleFailure
		}
	);
}

function ItemLoadSuccess(Response)
{
	eval('var Response = ' + Response.responseText);

	if (Response.Success)
	{
		if (!Response.Description)
			$('ItemDataDiv').innerHTML = InfoNoDescription;
		else
			$('ItemDataDiv').innerHTML = Response.Description;
	}
	else
		$('ItemDataDiv').innerHTML = Response.Message;
}

function HandleFailure(Response)
{
	eval("var Result=" + Response.responseText);
	DisplayMessage('TableProgress', Result.Message + '\n Error: ' + Result.ErrorCode, 3);
}

function GetMousePosition(e)
{
	if (IE)
	{
		MouseX = window.event.x + document.body.scrollLeft;
		MouseY = window.event.y + document.body.scrollTop;
	}
	else if (e)
	{
		MouseX = Event.pointerX(e);
		MouseY = Event.pointerY(e);
	}
	else
	{
		return;
	}

	if (MouseX < 0)
		MouseX = 0;

	if (MouseY < 0)
		MouseY = 0;

	if ($('ItemDataDiv') && $('ItemDataDiv').style.display == 'block')
	{
		$('ItemDataDiv').style.left = MouseX + 15 + 'px';
		$('ItemDataDiv').style.top = MouseY + 15 + 'px';
	}

	if ($('AccountData') && $('AccountData').style.display == 'block')
	{
		$('AccountData').style.left = MouseX + 15 + 'px';
		$('AccountData').style.top = MouseY + 15 + 'px';
	}
}

function HideShowAccount()
{
	UnHideAllSelects();
	$('dialog').style.display = 'none';
	$('AccountDetailDiv').style.display = 'none';
	$('AccountDetailsFrame').src = '';

	if ($('OrderDetailDiv'))
		$('OrderDetailDiv').style.display = 'none';
}

function CloseBackground()
{
	if($('AccountDetailDiv'))
		HideShowAccount();
	if($('DivGetQuote'))
		HideQuoteDiv();
}
function ShowAccount(AccountId)
{
	GetPageSize();
	$('dialog').style.height = PageHeight + 'px';
	$('AccountDetailDiv').style.left = (PageWidth - 250) / 2;
	$('AccountDetailDiv').style.top = 250 + yScroll;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=loadaccount&id=' + AccountId,
			onSuccess: AccountLoadSuccess,
			onFailure: HandleFailure
		}
	);
}

function AccountLoadSuccess(Response)
{
	eval('var Result = ' + Response.responseText);

	if (Result.Success)
	{
		$('AccountDescription').innerHTML = Result.Details.Description;
		$('AccountDescription').innerHTML += Result.Details.Details;
		$('AccountDetailsFrame').src = Result.Details.Link;
		$('SellPriceProfiled').innerHTML = Result.Details.Price;
		HideAllSelects();
		ShowBackground('dialog');

		$('AccountDetailDiv').style.display = 'block';
	}
	else
		HandleFailure(Response);
}

function UpdateCart()
{
	RequestString = '';
	Elements = $('ShoppingCart').getElementsByTagName('input');

	for (i = 0; i < Elements.length; i++)
	{
		RequestString += Elements[i].id + '_' + Elements[i].value + '*';
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsCart.php',
		{
			method: 'post',
			parameters: 'op=update&string=' + RequestString,
			onSuccess: CartUpdated,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function CartUpdated(Response)
{
	CheckAndHideLoading();
	ReloadCart();
}

function EmptyCart()
{
	if (!confirm(PromptEmptyCart))
		return;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsCart.php',
		{
			method: 'post',
			parameters: 'op=empty',
			onSuccess: ReloadCart,
			onFailure: HandleFailure
		}
	);
}

function Placement(Val)
{
	var MyDate = new Date();
	MyDate.setTime(MyDate.getTime() + 30*24*3600*1000);
	document.cookie = 'PlacementFlow=' + Val +'; expires=' + MyDate.toUTCString() + '; path=/';

}

function LoadCheckout()
{
	HideGreetings();
	HideExpressCheckout();
	HideWhyRedirected();

	if (!window.GetCheckoutIncluded)
	{
		include('GetCheckout');
	}

	$('ShoppingCart').style.display = 'none';
	$('FeaturedGamesDiv').style.display = 'none';

	Data = 0;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetCheckout.php',
		{
			method: 'get',
			onSuccess: CheckoutLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function CheckoutLoaded(Response)
{
	CheckAndHideLoading();

	if (!GameId)
	{
		GameId = '';
	}

	dhtmlHistory.add("checkout;" + GameId);

	$('PageContent').innerHTML = Response.responseText;

	GetRegExpr($('HiddenGame').value);

	if (ReadCookie('User'))
	{
		$('GenerateUserAccountCheckout').style.display = 'none';
	}

	if (MatchingMessage)
	{
		$('MatchingDiv').style.display = 'block';
		$('MatchingDiv').innerHTML = MatchingMessage;
		$('CheckoutErorSpan').style.display = 'none';
	}
	else
	{
		$('MatchingDiv').style.display = 'none';
		$('CheckoutErorSpan').style.display = 'none';
	}

	if (UserDetails)
	{
		$('FirstName').value = UserDetails.FirstName;
		$('LastName').value = UserDetails.LastName;
		$('Email').value = UserDetails.Email;
		$('Address').value = UserDetails.Address;
		$('City').value = UserDetails.City;
		$('State').value = UserDetails.State ? UserDetails.State : '';
		$('Country').value = UserDetails.Country;
		$('CountryCode').innerHTML = $(UserDetails.Country).title;
		$('ZipCode').value = UserDetails.Zip;
		$('Phone').value = UserDetails.Phone;
		$('AreaCode').value = UserDetails.AreaCode;
		$('PhoneType').value = UserDetails.PhoneType;
	}

	if(!UserDetails)
	{
		LoadCustomer();
	}

	if (Data)
	{
		if($('Character'))
		{
			$('Character').value = CharacterVar;
		}

		if($('DeliverTime'))
		{
			$('DeliverTime').value = DeliverDate;
		}

		$('FirstName').value = FirstName;
		$('LastName').value = LastName;
		$('Email').value = Email;
		$('Address').value = Address;
		$('City').value = City;
		$('State').value = State ? State : '';
		$('Country').value = Country;
		$('CountryCode').innerHTML = $(Country).title;
		$('ZipCode').value = ZipCode;
		$('AreaCode').value = AreaCode;
		$('Phone').value = Phone;
		$('PhoneType').value = PhoneTypeValue;
	}

	InitializeSuggester();
}

function InitializeSuggester()
{
	var Options =
	{
		TargetElement: 'ServerConfirmInput',
		DataSource: 'Ajax/SuggestServer.php',
		LettersToSuggestion: 2,
		Suggestions: 10,
		DivClass: 'SuggestPane',
		ListItemClass: 'SuggestionItem',
		ListItemHover: 'SuggestionItemHover'
	}

	SuggesterObj = new Suggester();

	SuggesterObj.Initialize(Options);
}

function AddCupon()
{
	if ($F('CuponId') == '')
	{
		alert(PromptCuponCode);
		$('CuponId').focus();
		return;
	}

	CharacterVar = $('Character') ? $F('Character') : '';
	DeliverDate = $('DeliverTime') ? $F('DeliverTime') : '';
	FirstName = $F('FirstName');
	LastName = $F('LastName');
	Email = $F('Email');
	Address = $F('Address');
	City = $F('City');
	State = $F('State');
	Country = $F('Country');
	ZipCode = $F('ZipCode');
	Phone = $F('Phone');
	AreaCode = $F('AreaCode');
	Data = 1;

	document.cookie = 'CuponId=' + $F('CuponId') + '; expires=Fri, 22 Jun ' + (CDate.getFullYear() + 2) + ' ' + CDate.getHours() + ':00:00 UTC; path=/';
	LoadCheckout();
}

function RemoveCupon()
{
	CharacterVar = $('Character') ? $F('Character') : '';
	DeliverDate = $('DeliverTime') ? $F('DeliverTime') : '';
	FirstName = $F('FirstName');
	LastName = $F('LastName');
	Email = $F('Email');
	Address = $F('Address');
	City = $F('City');
	State = $F('State');
	Country = $F('Country');
	ZipCode = $F('ZipCode');
	Phone = $F('Phone');
	AreaCode = $F('AreaCode');
	Data = 1;

	document.cookie = 'CuponId=; expires=Fri, 22 Jun 2001 20:47:11 UTC; path=/';
	LoadCheckout();
}

function SetNonUS()
{
	if($F('Country') != 223)
	{
		$('State').value = '';
	}

	$('CountryCode').innerHTML = $($('Country').value).title;
}

 /********************************** Express Checkout Begin ********************************/
function HideExpressCheckout()
{
	$('ExpressCheckoutDiv').style.display = 'none';
}

function ShowExpressCheckout()
{
	if ($('ExpressCheckoutDiv').innerHTML != '')
	{
		$('ExpressCheckoutDiv').style.display = 'block';
	}
}

function CleanAll()
{
		$('ExpressPlaygroundSelect').length = 0;
		$('ExpressPlaygroundSelect').options[0] = new Option(EXCheckoutSelectServer, '' );

		$('ExpressAmountSelect').length = 0;
		$('ExpressAmountSelect').options[0] = new Option(EXCheckoutSelectAmount, '' )

		$('ExpressCheckoutPrice').innerHTML = '&nbsp;';
		SelectedAmountId = '';
}

function SelectGame()
{
	CleanAll();
	GameId = $('ExpressGameSelect').value;
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionExpressCheckout.php',
		{
			method: 'post',
			parameters: 'op=loadservers' + '&gameid=' + GameId,
			onSuccess: ServersLoaded,
			onFailure: HandleFailure
		}
	);
}

function ServersLoaded(response)
{
	eval('var Response=' + response.responseText);

	if ($('ExpressPlaygroundSelect').length != 1)
	{
		$('ExpressPlaygroundSelect').length = 0;
		$('ExpressPlaygroundSelect').options[0] = new Option(EXCheckoutSelectServer, '' );
	}

	SelectedAmountId = '';

	if (Response.Success)
	{
		for (i = 0; i < Response.Servers.length; i++)
		{
			$('ExpressPlaygroundSelect').options[i] = new Option(Response.Servers[i].Name, Response.Servers[i].Id );
		}
	}
}

function SelectServer()
{
	$('ExpressCheckoutPrice').innerHTML = '&nbsp;';
	SelectedAmountId = '';

	PlaygroundId = $('ExpressPlaygroundSelect').value;
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionExpressCheckout.php',
		{
			method: 'post',
			parameters: 'op=loadamount' + '&playid=' + PlaygroundId + '&gameid=' + GameId,
			onSuccess: AmountLoaded,
			onFailure: HandleFailure
		}
	);
}

function AmountLoaded(response)
{
	eval("var Response = " + response.responseText);

	if ($('ExpressAmountSelect').length != 1)
	{
		$('ExpressAmountSelect').length = 0;
		$('ExpressAmountSelect').options[0] = new Option(EXCheckoutSelectAmount, '' );
	}

	SelectedAmountId = '';

	if (Response.Success)
	{
		if (Response.Amount)
		{
			$('ExpressAmountSelect').length = 0;
			$('ExpressAmountSelect').options[0] = new Option(EXCheckoutSelectAmount, '' );

			for (i = 1; i < Response.Amount.length; i++)
			{
				$('ExpressAmountSelect').options[i] = new Option(Response.Amount[i].Value, Response.Amount[i].Id );
			}
		}
		else
		{
			$('ExpressAmountSelect').length = 0;
			$('ExpressAmountSelect').options[0] = new Option(EXCheckoutNoStock, '' );
		}
	}
}

function SelectAmount()
{
	SelectedAmount = $('ExpressAmountSelect').value;
	SelectedAmount = SelectedAmount.split("-");
	SelectedAmountId = SelectedAmount[0];
	SelectedAmountPrice = SelectedAmount[1];

	if (SelectedAmount == '')
	{
		$('ExpressCheckoutPrice').innerHTML = '';
	}
	else
	{
		$('ExpressCheckoutPrice').innerHTML = '<b> ' + EXCheckoutPrice + ' : ' + SelectedAmountPrice + '</b>';
	}
}

function ExpressCheckoutBuy()
{
	BlockValue = $('ExpressAmountSelect').options[$('ExpressAmountSelect').selectedIndex].innerHTML;
	BlockValue = BlockValue.split(" ");

	if (SelectedAmountId && BlockValue[0] && PlaygroundId)
	{
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/ActionsServer.php',
			{
				method: 'post',
				parameters: 'op=addgmoney&id=' + SelectedAmountId + '&name=' + BlockValue[0] + '&server=' + PlaygroundId + '&type=1&directbuy=1',
				onSuccess: LoadCartSuccess,
				onFailure: HandleFailure
			}
		);
	}
}

function DirectCheckoutBuy(Name, Id)
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=addgmoney&id=' + Id + '&name=' + Name + '&server=' + PlaygroundId + '&type=1&directbuy=1',
			onSuccess: LoadCartSuccess,
			onFailure: HandleFailure
		}
	);
}

function LoadCartSuccess(Response)
{
	eval('var Result = ' + Response.responseText);

	if (Result.Success)
	{
		if (ReadCookie('CartItems'))
		{
			var AjaxRq = new Ajax.Request
			(
				'/Ajax/GetCart.php',
				{
					method: 'post',
					parameters: '',
					onFailure: HandleFailure
				}
			);

			ShowLoadingMessage();
		}

		CheckAndHideLoading();
		$('ShoppingCart').style.display = 'none';
		$('ShoppingCartDiv').innerHTML = '';
		LoadCheckout();
	}
	else
		HandleFailure(Response);
}

function LoadGames()
{
	HideGreetings();
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ExpressCheckout.php',
		{
			method: 'post',
			parameters: '',
			onSuccess: ExpressCheckoutLoaded,
			onFailure: HandleFailure
		}
	);

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetGames.php',
		{
			method: 'post',
			parameters: '',
			onSuccess: GamesLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function ExpressCheckoutLoaded(Response)
{
	if (Response.responseText != '')
	{
		$('ExpressCheckoutDiv').innerHTML = Response.responseText;
	}

	ShowExpressCheckout();
}

function GamesLoaded(Response)
{
	CheckAndHideLoading();
	$('GameList').innerHTML = Response.responseText;
}
//******************************************** End express checkout ************************************************


 /********************************** Sell page Begin ********************************/

function CheckEmail2(value)
{
	var Email = value.trim();
	Email = Email.match(/\b(^(\S+@).+((\..{2,3}))$)\b/gi);

	if (Email)
	   Good = true;
	else
	   Good = false;

	return Good;
}


function CleanAllSell()
{
		$('SellPlaygroundSelect').length = 0;
		$('SellPlaygroundSelect').options[0] = new Option(EXCheckoutSelectServer, '' );

		$('SellAmountSelect').length = 0;
		$('SellAmountSelect').options[0] = new Option(EXCheckoutSelectAmount, '' )
}

function LoadSellGames()
{
	CleanAllSell();
	$('SellGameSelect').options[0] = new Option('Select game', -1 );
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency2.php',
		{
			method: 'post',
			parameters: 'op=loadgames',
			onSuccess: SellGamesLoaded,
			onFailure: HandleFailure
		}
	);
}

function SellGamesLoaded(response)
{
	eval('var Response=' + response.responseText);

	if ($('SellGameSelect').length != 1)
	{
		$('SellGameSelect').length = 0;
		$('SellGameSelect').options[0] = new Option(EXCheckoutSelectServer, '' );
	}

	if (Response.Success)
	{
		for (i = 1; i <= Response.Games.length; i++)
		{
			$('SellGameSelect').options[i] = new Option(Response.Games[i-1].Name, Response.Games[i-1].Id );
		}
	}
}

function SelectSellGame()
{
	CleanAllSell();
	SellGameId = $('SellGameSelect').value;
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency2.php',
		{
			method: 'post',
			parameters: 'op=loadservers' + '&gameid=' + SellGameId,
			onSuccess: SellServersLoaded,
			onFailure: HandleFailure
		}
	);
}

function SellServersLoaded(response)
{
	eval('var Response=' + response.responseText);

	$('SellPlaygroundSelect').options[0] = new Option('Select server', -1 );
	if ($('SellPlaygroundSelect').length != 1)
	{
		$('SellPlaygroundSelect').length = 0;
		$('SellPlaygroundSelect').options[0] = new Option(EXCheckoutSelectServer, '' );
	}

	if (Response.Success)
	{
		for (i = 1; i <= Response.Servers.length; i++)
		{
			$('SellPlaygroundSelect').options[i] = new Option(Response.Servers[i-1].Name, Response.Servers[i-1].Id );
		}
	}
}



function SelectSellServer()
{
	Game = $('SellGameSelect').value;
	if (Blocks[Game])
	{
		var i, NoOptions, NewOption, Select = $('SellAmountSelect');
		while (Select.options.length > 1)
			Select.removeChild(Select.options[Select.options.length - 1]);

		for (i = 0; i < Blocks[Game].length; i++)
		{
			NewOption = document.createElement('OPTION');
			NewOption.value = Blocks[Game][i];
			NewOption.innerHTML = Blocks[Game][i];

			Select.appendChild(NewOption);
		}
	}
	else
	{
		var i, NoOptions, NewOption, Select = $('SellAmountSelect');
		while (Select.options.length > 1)
			Select.removeChild(Select.options[Select.options.length - 1]);
			
		for (i = 0; i < DefaultAmount.length; i++)
		{
			NewOption = document.createElement('OPTION');
			NewOption.value = DefaultAmount[i];
			NewOption.innerHTML = DefaultAmount[i];

			Select.appendChild(NewOption);
		}
	}
}


function Sell()
{
	var msgType = 'N/A';

	for( i = 0; i < document.SellForm.contactMess.length; i++ )
	{
		if( document.SellForm.contactMess[i].checked == true )
		{
			msgType = document.SellForm.contactMess[i].value;
			break;
		}
	}
	GameId = $('SellGameSelect').options[$('SellGameSelect').selectedIndex].innerHTML;
	PlaygroundId = $('SellPlaygroundSelect').options[$('SellPlaygroundSelect').selectedIndex].innerHTML;
	BlockValue = $('SellAmountSelect').options[$('SellAmountSelect').selectedIndex].innerHTML;
	
	$('emailErr').style.visibility = (($F('emailAddr') == '') || !CheckEmail2($F('emailAddr')))? 'visible': 'hidden';
	$('messErr').style.visibility = ($F('messId') && (msgType == 'N/A'))? 'visible': 'hidden';
	$('gameErr').style.visibility = ($('SellGameSelect').selectedIndex <= 0)? 'visible': 'hidden';
	$('serverErr').style.visibility = ($('SellPlaygroundSelect').selectedIndex <= 0)? 'visible': 'hidden';
	$('amountErr').style.visibility = ($('SellAmountSelect').selectedIndex <= 0)? 'visible': 'hidden';

	if ($F('emailAddr') == '') 
	{
		$('emailErr').innerHTML = 'Please enter your email address';
		return false;
	}

	if (!CheckEmail2($F('emailAddr')))
	{
		$('emailErr').innerHTML = 'Invalid address';
		return false;
	}
	if ($F('messId') && ($F('messId') != 'Type your Messenger ID here') && (msgType == 'N/A'))
	{
		$('messErr').innerHTML = 'Please select messenger type';
		return false;
	}
	if ($('SellGameSelect').selectedIndex <= 0)
	{
		$('gameErr').innerHTML = 'Please select a game';
		return false;
	}
	if ($('SellPlaygroundSelect').selectedIndex <= 0)
	{
		$('serverErr').innerHTML = 'Please select a server';
		return false;
	}
	if ($('SellAmountSelect').selectedIndex <= 0)
	{
		$('amountErr').innerHTML = 'Please select the amount';
		return false;
	}

	if (BlockValue && PlaygroundId)
	{
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/ActionsSellCurrency2.php',
			{
				method: 'post',
				parameters: 'op=sell&block=' + BlockValue + '&server=' + PlaygroundId + '&emailAddr=' + $F('emailAddr') + '&messId=' + $F('messId') + '&contactMess=' + msgType + '&comments=' + escape($F('comments')) + '&gameId=' + GameId,
				onSuccess: SellSuccess,
				onFailure: HandleFailure
			}
		);
	}
}

function SellSuccess(Response)
{
	eval('var Result = ' + Response.responseText);

	if (Result.Success)
	{
		alert(Result.Message);
		 window.setTimeout('window.location="/"; ',5000);

	}
	else
		HandleFailure(Response);
}


//******************************************** End Sell Page ******************************************************
function GoBack()
{
	history.go(-1);
}

function RemoveCartItem(ItemId)
{
	if (!confirm(PromptRemoveItem))
		return;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsCart.php',
		{
			method: 'post',
			parameters: 'op=remove&id=' + ItemId,
			onSuccess: ItemRemoved,
			onFailure: HandleFailure
		}
	);
}

function ItemRemoved(Response)
{
	eval('var Result = ' + Response.responseText);

	if (Result.Success)
		ReloadCart();
	else
		HandleFailure(Response);
}

function LoadSellCurrency()
{
	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();
	dhtmlHistory.add("sellcurrency");

	if ($('UserDiv').innerHTML == '')
		LoadUserDiv();

	HideFeaturedGames();

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetSellCurrency.php',
		{
			method: 'get',
			parameters: '',
			onSuccess: SellCurrencyLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function SellCurrencyLoaded(Response)
{
	CheckAndHideLoading();
	$('PageContent').innerHTML = Response.responseText;
	LoadSellGames();

/*
	if (GameId)
	{
		$('GameSelect').value = GameId;
		CurrencyLoadServers(GameId);
	}
*/
}

function CurrencyLoadServers(GameId)
{
	ShowLoadingMessage();
	InitRahanCurrencyNeeded(GameId);
}

function GetCurrencyName(Playground, IdGame, Name)
{
	SellCurrencyPlayground = Playground;
	GameCommissionId = IdGame;
	PlaygroundName = Name;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters: 'op=getcurrencyname&gameid=' + IdGame,
			onSuccess: CurrencyNameLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function ShowQuoteDiv()
{
	ShowBackground('dialog');
	SetDivPosition('DivGetQuote');
	SetDivPosition('DivLoadingMessage');
	$('DivGetQuote').style.display = 'inline';
}

function ClearQuoteDivValues()
{
	SellCurrencyPlayground = 0;
	$('CurrencyMessage').innerHTML = '';
	$('CurrencyDiv').style.display = 'none';
}

function HideQuoteDiv()
{
	ClearQuoteDivValues();
	$('DivLoadingMessage').style.top = '40%';
	$('DivGetQuote').style.display = 'none';
	$('dialog').style.display = 'none';
}

function SetDivPosition(Div)
{
	var ScrollHeight = IE ? document.documentElement.clientHeight : document.body.scrollHeight;
	var ScrollTop = (document.documentElement.scrollTop || document.body.scrollTop);
	$(Div).style.top = (ScrollTop + (ScrollHeight / 3)) + 'px';
}

function CurrencyNameLoaded(Response)
{
	CheckAndHideLoading();
	ShowQuoteDiv();
	eval('var Response = ' + Response.responseText);

	$('CurrencyAmm').value = '';

	if (Response.Success)
	{
		if (Response.CurrencyMax == 0)
		{
			$('CurrencySubmitBtn').disabled = true;
		}
		else
		{
			$('CurrencyName').innerHTML = Response.CurrencyName;
			$('PlaygroundName').innerHTML = PlaygroundName;
		}
	}
	else
	{
		$('CurrencySubmitBtn').disabled = true;
	}
}

function SubmitCurrency()
{
	if (!GameCommissionId)
	{
		alert(PromptSelectAGame);
		return;
	}

	CurrencyAmmount = parseInt($('CurrencyAmm').value);

	if (CurrencyAmmount < 1 || !CurrencyAmmount)
	{
		alert(PromptEnterCurrencyAmmount);
		$('CurrencyAmm').focus();
		return;
	}

	$('CurrencyAmm').value = CurrencyAmmount;
	PlaygroundId = SellCurrencyPlayground;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters: 'op=getvalue&amount=' + $F('CurrencyAmm') + '&serverid=' + SellCurrencyPlayground + '&gameid=' + GameCommissionId,
			onSuccess: CurrencyValueLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage(1);
}

function CurrencyValueLoaded(Response)
{
	CheckAndHideLoading(1);
	eval('var Response = ' + Response.responseText);

	$('CurrencyMessage').innerHTML = Response.Message;
	$('CurrencyDiv').style.display = 'inline';

	if (Response.Success)
	{
		ServerId = Response.Value.ServerId;
		Price = Response.Value.Price;
		$('GetSellerDetails').disabled = false;
	}
	else
		$('GetSellerDetails').disabled = true;
}

function GetUserDetails()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=userdetails',
			onSuccess: UserDetailsLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function UserDetailsLoaded(Response)
{
	CheckAndHideLoading();
	window.scrollTo(0,0);
	$('PageContent').innerHTML = Response.responseText;

	if (UserDetails)
	{
		$('SellerName').value = UserDetails.FirstName + ' ' + UserDetails.LastName;
		$('SellerEmail').value = UserDetails.Email;
	}
}

function SubmitSellerData()
{
	if (!($F('SellerName').trim()))
	{
		alert(PromptEnterName);
		$('SellerName').focus();
		return;
	}

	if (!($F('SellerCharName').trim()))
	{
		alert(PromptCharacterName);
		$('SellerCharName').focus();
		return;
	}

	if(!$('SellerCharName').value.match(/^[a-zA-Z]+$/))
	{
		alert(ErrorCharacterName);
		$('SellerCharName').focus();
		return;
	}

	if (!CheckEmail($('SellerEmail')))
		return;

	if ($('PayPalPayment').checked)
	{
		if (!CheckEmail($('PayPalEmail')))
			return;
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters: 'op=addorder&playground=' + PlaygroundId + '&name=' + $F('SellerName') + '&charname=' + $F('SellerCharName') +
						'&ammount=' + SubmitedAmmount + '&deliver=' + ( $('DeliverTime') ? $F('DeliverTime') : '') + '&paypal=' + $F('PayPalEmail') +
						'&bfullname=' + $F('BankFullName') + '&bname=' + $F('BankName') + '&baddress=' + $F('BankAddress') +
						'&bcountry=' + $F('BankCountry') + '&broutingno=' + $F('BankRoutingNumber') + '&baccountno=' + $F('BankAccountNumber') +
						'&type=' + PaymentType + '&serverid=' + ServerId + '&price=' + Price + '&gameid=' + GameCommissionId,
			onSuccess: OrderSaved,
			onFailure: HandleFailure
		}
	);

	$('LoadingMessage').innerHTML = InfoWaitForCharacterName;
	ShowBackground('dialog');
	ShowLoadingMessage(1);
}

function OrderSaved(Response)
{
	eval("var Response = " + Response.responseText);

	if (Response.Success == 2)
	{
		if(confirm(Response.Message))
		{
			var AjaxRq = new Ajax.Request
			(
				'/Ajax/ActionsSellCurrency.php',
				{
					method: 'post',
					parameters: 'op=addorder&playground=' + PlaygroundId + '&name=' + $F('SellerName') + '&charname=' + $F('SellerCharName') +
								'&ammount=' + Response.Value.Amount + '&deliver=' + ($('DeliverTime') ? $F('DeliverTime') : '' ) + '&paypal=' + $F('PayPalEmail') +
								'&bfullname=' + $F('BankFullName') + '&bname=' + $F('BankName') + '&baddress=' + $F('BankAddress') +
								'&bcountry=' + $F('BankCountry') + '&broutingno=' + $F('BankRoutingNumber') + '&baccountno=' + $F('BankAccountNumber') +
								'&type=' + PaymentType + '&serverid=' + ServerId + '&price=' + Response.Value.Price + '&gameid=' + GameCommissionId,
					onSuccess: OrderSaved,
					onFailure: HandleFailure
				}
			);
			$('LoadingMessage').innerHTML = InfoWaitForCharacterName;
			ShowBackground('dialog');
			ShowLoadingMessage(1);
		}
		else
			LoadSellCurrency();
	}
	else
	{
		if (Response.Success == 1)
		{
			SellOrderInsertedId = Response.Value;
			CheckOrderStatusInterval = setInterval('CheckSellOrderStatus()', 10000);
		}
		else
		{
			alert(Response.Message);
			CheckAndHideLoading(1);
			$('LoadingMessage').innerHTML = InfoLoading;
			$('dialog').style.display = 'none';
			LoadSellCurrency();
		}
	}
}

function CheckSellOrderStatus()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters:'op=checkstatus&id=' + SellOrderInsertedId,
			onSuccess: CheckSellOrderStatusResponse,
			onFailure: HandleFailure
		}
	);
}

function CheckSellOrderStatusResponse(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		if (Result.Value == 1)
		{
			window.clearInterval(CheckOrderStatusInterval);

			SellingCharacter = Result.Message['char'];
			SellingOrderId = Result.Message['orderid'];

			var AjaxRq = new Ajax.Request
			(
				'/Ajax/GetFile.php',
				{
					method: 'post',
					parameters:'id=sellcurrencyresponse',
					onSuccess: SellCurrencyResponse,
					onFailure: HandleFailure
				}
			);

			CheckAndHideLoading(1);
			$('LoadingMessage').innerHTML = InfoLoading;
		}
	}
	else
		HandleFailure(Response);
}

function SellCurrencyResponse(Response)
{
	$('dialog').style.display = 'none';
	$('PageContent').innerHTML = Response.responseText;
	$('MeetWith').innerHTML = SellingCharacter;
	$('SellingOrderId').value = SellingOrderId;
	$('LoadingMessage').innerHTML = InfoLoading;
}

function DeliverOrder()
{
	ShowLoadingMessage();
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters: 'op=deliverorder&orderid=' + $F('SellingOrderId'),
			onSuccess: DeliverOrderSuccess,
			onFailure: HandleFailure
		}
	);
}

function DeliverOrderSuccess(Response)
{
	CheckAndHideLoading();
	eval("var Response = " + Response.responseText);

	if(Response.Success)
	{
		$('PageContent').innerHTML = '<div class="content light"><p>' + Response.Message + '</p></div>';
	}
	else
		HandleFailure(Response);
}

function PaymentChange(Value)
{
	switch (Value)
	{
		case 1:
			$('PayPalDiv').style.display = 'block';
			$('BankTransferDiv').style.display = 'none';
		break;

		case 2:
			$('PayPalDiv').style.display = 'none';
			$('BankTransferDiv').style.display = 'block';
		break;
	}

	PaymentType = Value;
}

function LoadRegisterUser()
{
	include('RegisterUser');
	HideGreetings();

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetRegisterUser.php',
		{
			method: 'get',
			onSuccess: UserRegisterLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();

	return false;
}

function UserRegisterLoaded(Response)
{
	CheckAndHideLoading();

	$('FeaturedGamesDiv').style.display = 'none';

	if ($('ShoppingCart') && $('ShoppingCartDiv').innerHTML != '')
	{
		$('ShoppingCart').style.display = 'block';
		$('ShoppingCartDiv').style.display = 'block';
	}

	$('PageContent').innerHTML = Response.responseText;
}

function DoLoginUser()
{
	if (!CheckEmail($('UserEmail')))
		return;

	if (!$F('UserPassword'))
	{
		alert(PromptEnterPassword);
		$('UserPassword').focus();
		return;
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsUsers.php',
		{
			method: 'post',
			parameters: 'op=login&email=' + $F('UserEmail') + '&password=' + $F('UserPassword') + '&rememberme=' + ($('RememberUser').checked ? 1 : 0),
			onSuccess: UserLoginResponse,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function UserLoginResponse(Response)
{
	CheckAndHideLoading();
	eval("var Response = " + Response.responseText);

	if (Response.Success)
	{
		$('CustomerMyOrders').style.display = 'none';
		UserDetails = Response.UserDetails;
		/*
		if ($('UserOrders'))
		{
			InitOrdersGrid();
		}*/
		if($('DetailsInput'))
		{
			LoadCheckout();
		}

		HideGreetings();

		var AjaxRq = new Ajax.Request
		(
			'/Ajax/GetFile.php',
			{
				method: 'post',
				parameters: 'id=usermenu',
				onSuccess: UserMenuLoaded,
				onFailure: HandleFailure
			}
		);

		ShowLoadingMessage();
	}
	else
	{
		DisplayMessage('BadLoginMsg', Response.Message, 3);
	}
}

function UserMenuLoaded(Response)
{
	CheckAndHideLoading();
	$('UserDiv').innerHTML = Response.responseText;
	$('UserEmailSpan').innerHTML = UserDetails.Email;

}

function LogoutUser()
{
	UserDetails = '';
	HideGreetings();
	document.cookie = 'User=; expires=Fri, 22 Jun 2001 20:47:11 UTC; path=/; domain=.' + location.hostname.replace('www.', '');
	CheckWhoIs();
	LoadFirstPage();
	LoadUserDiv();
}

function CheckAndReloadOrders()
{
	if ($('UserOrders'))
		UserOrdersGrid.Reload();
	else
	{
		window.clearInterval(UserOrdersInterval);
		UserOrdersInterval = 0;
	}
}

function LoadMyOrders()
{
	HideGreetings();
	HideExpressCheckout();
	HideWhyRedirected();
	HideFeaturedGames();
	ReloadCart();

	if (!window.MyOrdersIncluded)
		include('MyOrders');

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=userordersgrid',
			onSuccess: MyOrdersLoaded,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function MyOrdersLoaded(Response)
{
	CheckAndHideLoading();
	dhtmlHistory.add("myorders");
	$('PageContent').innerHTML = Response.responseText;
	InitOrdersGrid();
}

function LoadCustomerOrders()
{
	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();

	if (!ReadCookie('CustomerId'))
	{
		LoadFirstPage();
		return;
	}

	if ($('UserDiv').innerHTML == '')
		LoadUserDiv();

	HideFeaturedGames();
	ReloadCart();

	if (!window.MyOrdersIncluded)
		include('MyOrders');

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=userordersgrid',
			onSuccess: CustomerOrdersResponse,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function CustomerOrdersResponse(Response)
{
	dhtmlHistory.add("myorders");
	CheckAndHideLoading();
	$('PageContent').innerHTML = Response.responseText;
	InitCustomerOrdersGrid();
}

function ChangePassword()
{
	if (!UserDetails)
	{
		LoadFirstPage();
		return;
	}

	if ($('ShoppingCart') && $('ShoppingCartDiv').innerHTML != '')
	{
		$('ShoppingCart').style.display = 'block';
		$('ShoppingCartDiv').style.display = 'block';
	}

	HideExpressCheckout();
	HideFeaturedGames();
	ShowLoadingMessage();

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=userchangepass',
			onSuccess: ChangePasswordLoaded,
			onFailure: HandleFailure
		}
	);
}

function ChangePasswordLoaded(Response)
{
	CheckAndHideLoading();
	dhtmlHistory.add("changepassword");
	$('PageContent').innerHTML = Response.responseText;
}

function DoChangePassword()
{
	if ($F('OldPassword').length < 1)
	{
		alert(PromptOldPassword);
		$('OldPassword').focus();
		return;
	}

	if ($F('NewPassword').length < 1)
	{
		alert(PromptNewPassword);
		$('NewPassword').focus();
		return;
	}

	if ($F('ReNewPassword').length < 1)
	{
		alert(PromptRetypePassword);
		$('ReNewPassword').focus();
		return;
	}

	if ($F('NewPassword') != $F('ReNewPassword'))
	{
		alert(PromptPasswordsAreDifferent);
		return;
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsUsers.php',
		{
			method: 'post',
			parameters: 'op=changepass&user=' + UserDetails.Id + '&oldpass=' + $F('OldPassword') + '&newpass=' + $F('NewPassword'),
			onSuccess: ChangePasswordResponse,
			onFailure: HandleFailure
		}
	);
}

function ChangePasswordResponse(Response)
{
	eval ("var Response = " + Response.responseText);

	if (Response.Success)
		$('PageContent').innerHTML = Response.Message;
	else
		$('ChangePasswordMsg').innerHTML = Response.Message;
}

function LoadUserProfile()
{
	if (!window.UserProfileIncluded)
		include('UserProfile');

	if (!UserDetails)
	{
		LoadFirstPage();
		return;
	}
	HideExpressCheckout();
	HideFeaturedGames();
	ShowLoadingMessage();

	if ($('ShoppingCart') && $('ShoppingCartDiv').innerHTML != '')
	{
		$('ShoppingCart').style.display = 'block';
		$('ShoppingCartDiv').style.display = 'block';
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetUserProfile.php',
		{
			method: 'post',
			onSuccess: UserProfileLoaded,
			onFailure: HandleFailure
		}
	);
}

function UserProfileLoaded(Response)
{
	CheckAndHideLoading();
	dhtmlHistory.add("profile");
	$('PageContent').innerHTML = Response.responseText;
	$('UpdFirstName').value = UserDetails.FirstName;
	$('UpdLastName').value = UserDetails.LastName;
	$('UpdAddress').value = UserDetails.Address;
	$('UpdCity').value = UserDetails.City;
	$('UpdState').value = UserDetails.State;
	$('UpdZipCode').value = UserDetails.Zip;
	$('UpdPhoneType').value = UserDetails.PhoneType;

	for (i = 0; i < NotificationDetails.length; i++)
	{
		if (NotificationDetails[i].Id == 3 && NotificationDetails[i].Details)
		{
			var PhoneValue = NotificationDetails[i].Details.split('|');

			$('UpdCountry').value = PhoneValue[0];
			$('UpdAreaCode').value = PhoneValue[1];
			$('UpdPhone').value = PhoneValue[2];
		}
		else
		{
			$('UpdCountry').value = UserDetails.Country;
			$('UpdPhone').value = UserDetails.Phone;
			$('UpdAreaCode').value = UserDetails.AreaCode;
		}
	}
	if (UserDetails.NoNewsletter == 0)
	{
		$('SubscribeNews').checked = false;
	}
	else
	{
		$('SubscribeNews').checked = true;
	}

	$('SubscribeNews').value = UserDetails.NoNewsletter;

	NewsValue = UserDetails.NoNewsletter;
}

/************************************ Forgot Password Menu *********************************/
function LoadForgotPassword()
{
	ShowLoadingMessage();

	HideGreetings();

	include('UserForgotPassword');

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=userforgotpass',
			onSuccess: ForgotPasswordLoaded,
			onFailure: HandleFailure
		}
	);
}

function ForgotPasswordLoaded(Response)
{
	CheckAndHideLoading();
	$('FeaturedGamesDiv').style.display = 'none';
	$('PageContent').innerHTML = Response.responseText;
}

/************************************ /Forgot Password Menu *********************************/

function ToggleCuponDiv()
{
	if ($('CuponDiv').style.display == 'inline')
		$('CuponDiv').style.display = 'none';
	else
		$('CuponDiv').style.display = 'inline';
}

function ShowLoadingMessage(Force)
{
	if (Force == 1)
		LoadingMessageCount += 5;

	LoadingMessageCount++;
	$('DivLoadingMessage').style.display = 'block';

	if (!HideLoadingInterval)
		HideLoadingInterval = window.setInterval("HideLoading()", 3000);
}

function CheckAndHideLoading(Force)
{
	LoadingMessageCount--;

	if (Force == 1)
		LoadingMessageCount = 0;

	if (LoadingMessageCount < 1)
	{
		$('DivLoadingMessage').style.display = 'none';
		LoadingMessageCount = 0;
	}

	return false;
}

function HideLoading()
{
	if (LoadingMessageCount < 2)
	{
		$('DivLoadingMessage').style.display = 'none';
		LoadingMessageCount = 0;
	}
}

function LoadCustomer()
{
	if(ReadCookie('CustomerId'))
	{
		new Ajax.Request
		(
			'/Ajax/ActionsUsers.php',
			{
				method: 'post',
				parameters: 'op=loadcustomer',
				onSuccess: LoadCustomerResponse,
				onFailure: HandleFailure
			}
	   );
	}
}

function LoadCustomerResponse(response)
{
	eval("var Response = " + response.responseText);

	if (Response.Success)
	{
		$('FirstName').value = Response.CustomerDetails.FirstName;
		$('LastName').value = Response.CustomerDetails.LastName;
		$('Email').value = Response.CustomerDetails.Email;
		$('Address').value = Response.CustomerDetails.Address;
		$('City').value = Response.CustomerDetails.City;
		$('Country').value = Response.CustomerDetails.CountryId;
		$('CountryCode').innerHTML = $(Response.CustomerDetails.CountryId).title;
		$('State').value = Response.CustomerDetails.State ? Response.CustomerDetails.State : '';
		$('ZipCode').value = Response.CustomerDetails.Zip;
		$('Phone').value = Response.CustomerDetails.Phone;
		$('AreaCode').value = Response.CustomerDetails.AreaCode;
		$('PhoneType').value = Response.CustomerDetails.PhoneType;
	}
	else
	{
		HandleFailure(response);
	}
}

function ShowAccountName(AccountId)
{
	DisplayAccountId = AccountId;
	AccountTimerId = setTimeout('LoadAccountData()', 750);
}

function AccountDetailMouseOut()
{
	clearTimeout(AccountTimerId);
	$('AccountData').style.display = 'none';
}

function LoadAccountData()
{
	$('AccountData').style.left = MouseX + 15 + 'px';
	$('AccountData').style.top = MouseY + 15 + 'px';
	$('AccountData').style.display = 'block';
	$('AccountData').innerHTML = InfoLoadingAccountDetails;

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsServer.php',
		{
			method: 'post',
			parameters: 'op=loadaccount&id=' + DisplayAccountId,
			onSuccess: AccountDataLoaded,
			onFailure: HandleFailure
		}
	);
}

function AccountDataLoaded(Response)
{
	eval ("var Result =" + Response.responseText);

	if (Result.Success)
	{
		$('AccountData').innerHTML = Result.Details.Description;
	}
	else
	{
		HandleFailure(Response);
	}
}
//******************************************************************

function CheckSellerIp()
{
	 new Ajax.Request
	(
		'/Ajax/ActionsSellCurrency.php',
		{
			method: 'post',
			parameters: 'op=checksellerip',
			onSuccess: SellerIpChecked,
			onFailure: HandleFailure
		}
	);
}

function SellerIpChecked(response)
{
	eval("var Response = " + response.responseText);

	if (Response.Success)
	{
		$('CurrencyMessage').innerHTML = Response.Message;
	}
	else
	{
		SubmitedAmmount = $F('CurrencyAmm');
		HideQuoteDiv();
		GetUserDetails();
	}
}
//***************************************************************************************

function WriteTestimonial()
{
	if (!$F('TestimonialOrderId') || isNaN(parseInt($F('TestimonialOrderId'))) || parseInt($F('TestimonialOrderId')) <= 0)
	{
		alert(TestimonialProvideOrderId);
		$('TestimonialOrderId').focus();
		return;
	}

	new Ajax.Request
	(
		'/Ajax/ActionsTestimonial.php',
		{
			method: 'post',
			parameters: 'action=checkforduplicate' +
						 '&orderid=' + $F('TestimonialOrderId'),
			onSuccess: TestimonialChecked,
			onFailure: HandleFailure
		}
	);
}

function TestimonialChecked(Response)
{
	eval("var Result = " + Response.responseText);
	if (Result.Success && !Result.HasTestimonial)
	{
		document.location = 'Testimonials.php?x=' + parseInt($F('TestimonialOrderId'));
	}
	else
	{
		DisplayMessage('TestimonialMessage', Result.Message.fontcolor('red'), 6);
	}
}

function ShowKey(Key)
{
    if (!Key )
    {
		Key = event.keyCode;//IE
    }
	if(Key == 13)
	{
		DoLoginUser();
	}
}

//Accounts Selling page
function LoadAccountsPage(CurrentGameId)
{
	HideGreetings();
	ShowExpressCheckout();
	HideWhyRedirected();

	if (CurrentGameId > 0)
	{
		GameId = CurrentGameId;
	}

	dhtmlHistory.add("buyaccounts;" + (GameId ? GameId : ''));
	ShowLoadingMessage();
	LoadUserDiv();

	new Ajax.Request
	(
		'/Ajax/GetBuyAccounts.php',
		{
			method: 'post',
			parameters: 'gameid=' + GameId,
			onSuccess: AccountsPageLoaded,
			onFailure: HandleFailure
		}
	);
}

function AccountsPageLoaded(Response)
{
	CheckAndHideLoading();
	$('FeaturedGamesDiv').style.display = 'none';
	$('PageContent').innerHTML = Response.responseText;
	$('ServerSelect').value = PlaygroundId ? PlaygroundId : '';
	$('BuyAccountGameSelect').value = GameId;
	ShowServerName();
	InitAccountsForSaleGrid();
}

function ReloadAccounts()
{
	AccountsForSaleGrid.Options.PageScript = '/Ajax/GetAccountsForSale.php?gameid=' + $F('BuyAccountGameSelect') + '&sid=' + $F('ServerSelect')
											 + '&levellimit=' + $F('LevelLimitSelect') + '&level=' + $F('CharacterLevel')
											 + '&class=' + $F('ClassSelect') + '&race=' + $F('RaceSelect')
											 + '&gender=' + $F('GenderSelect');
	AccountsForSaleGrid.CurrentPage = 0;
	AccountsForSaleGrid.Reload();
}

function BuyAccountsGameSelected()
{
	GameId = $F('BuyAccountsGameSelect');

	LoadPlaygrounds(GameId);
	ReloadCart();
	LoadGameTitle(GameId);

	if ($('UserDiv').innerHTML == '')
	{
		LoadUserDiv();
	}

	LoadAccountsPage(GameId);
}

function GoBuyCurrency()
{
	if (!$F('ServerSelect'))
	{
		$('PageContent').innerHTML = '';

		new Ajax.Request
		(
			'/Ajax/ActionsUrls.php',
			{
				method: 'post',
				parameters: 'op=getpageurl' +
							 '&gameid=' + GameId,
				onSuccess: UrlLoaded,
				onFailure: HandleFailure
			}
		);
	}
	else
	{
		var Location = GameId + "_" + $F('ServerSelect');
		$('PageContent').innerHTML = '';
		LoadItemsPage(Location);
	}
}

function UrlLoaded(response)
{
	eval("var Response =" + response.responseText);

	if (Response.Success)
	{
		LoadPlaygroundsPage(GameId, Response.Url);
	}
	else
	{
		LoadPlaygroundsPage(GameId, 'servers;' + GameId);
	}
}

function ShowServerName()
{
	if ($F('ServerSelect'))
	{
		$('PlaygroundSelect').value = 'selected' + $F('ServerSelect')
		AddClass('highlight' + $F('ServerSelect'), 'light');
	}

	if ($F('ServerSelect') == '')
		$('BuyAccountsServerName').innerHTML = ' game';
	else
		$('BuyAccountsServerName').innerHTML = ' server';
}

function SearchForServer(SearchString)
{
	var Links = $('ServersListDiv').getElementsByTagName('a');
	var SearchString = SearchString.toLowerCase();
	var LinksLength = Links.length;
	var SSL = SearchString.length;

	for (i = 0; i < LinksLength;i++)
	{
		if (Links[i].innerHTML.substr(0, SSL).toLowerCase() == SearchString)
		{
			if (Links[i].style.display != 'block')
				Links[i].style.display = 'block';
		}
		else
		{
			if (Links[i].style.display != 'none')
				Links[i].style.display = 'none';
		}
	}
}

//Subscribe to newsletter
function SubscribeToNewsletter()
{
	var Email = $F('NewsletterEmail').trim();

	if (!Email)
	{
		alert(PromptEmailAddress);
		$('NewsletterEmail').focus();
		return;
	}

	if (!CheckEmail($('NewsletterEmail')))
		return;

	new Ajax.Request
	(
		'/Ajax/ActionsNewsletter.php',
		{
			method: 'post',
			parameters: 'action=subscribe&email=' + Email,
			onSuccess: SubscriptionSaved,
			onFailure: HandleFailure
		}
	);

	ShowLoadingMessage();
}

function SubscriptionSaved(Response)
{
	eval("var Result =" + Response.responseText);
	CheckAndHideLoading(1);

	if (Result.Success)
	{
		DisplayMessage('NewsletterMessage', Result.Message, 10);
	}
	else
	{
		HandleFailure(Response);
	}
}

function HideCurrencyInfoMessage()
{
	new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: 'action=disablemessage',
			onSuccess: HideCurrencyMessageResponse,
			onFailure: HandleFailure
		}
	);
}

function HideCurrencyMessageResponse(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		$('CurrencyInfo').style.display = 'none';
	}
	else
	{
		HandleFailure(Response);
	}
}

function ChangeToGameCurrency()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsGames.php',
		{
			method: 'post',
			parameters: 'action=getgamelanguage&gameid=' + GameId,
			onSuccess: ChangeToGameCurrencyLoaded,
			onFailure: HandleFailure
		}
	);
}

function ChangeToGameCurrencyLoaded(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		ChangeCurrency(Result.CurrencyId);
	}
	else
	{
		HandleFailure(Response);
	}
}

function include(File)
{
	var Script = document.createElement('script');
	Script.type = 'text/javascript';
	Script.src = '/Js/' + File + '.js';
	document.getElementsByTagName('head')[0].appendChild(Script);
}

/*************************** Customer Support *******************/

var CurrentCSType = 1;
var ContinueWithMail = 0;
var CustomerSupportLink = '';
var CSCurrentOrderId = 0;
var CustomerSupportNewLocation = '';

function CustomerSupport(CSLink, NewLocation)
{
	$('dialog').style.display = 'none';

	HideGreetings();
	HideExpressCheckout();
	CurrentCSType = 1;
	ContinueWithMail = 0;
	CustomerSupportLink = CSLink;

	CustomerSupportNewLocation = NewLocation;

	dhtmlHistory.add("CustomerSupport");

	if ($('FeaturedGamesDiv'))
	{
		$('FeaturedGamesDiv').style.display = 'none';
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/GetFile.php',
		{
			method: 'post',
			parameters: 'id=customersupport',
			onSuccess: CustomerSupportLoaded,
			onFailure: HandleFailure
		}
	);
}

function CustomerSupportLoaded(Response)
{
	//moved here by M.
	if ($('FeaturedGamesDiv'))
	{
		$('FeaturedGamesDiv').style.display = 'none';
	}

	$('PageContent').innerHTML = Response.responseText;

	switch (CustomerSupportNewLocation)
	{
		case 'NewOrderConfirmation':
			ShowNewOrderConfirmation();
		break;

		case 'ExistingOrder':
			ShowExistingOrderPane();
		break;

		case 'ContactUs':
			ShowContactForm();
		break;

		case 'CustomerSupport':
		default:
	}
}

function ClearInquiryData()
{
	$('CSName').value = '';
	$('CSEmail').value = '';
	$('CSInquiry').value = '';
	$('CSSecurityImage').value = '';
}

function SubmitInquiry()
{
	if (!CheckEmail($('CSEmail')))
	{
		return;
	}

	if ($F('CSName').trim() == '')
	{
		alert(CSTypeName);
		$('CSName').focus();
		return;
	}

	if ($F('CSInquiry').trim() == '')
	{
		alert(CSTypeEnquiry);
		$('CSInquiry').focus();
		return;
	}

	if ($F('CSSecurityImage').trim() == '')
	{
		alert(CSSecurityImageType);
		$('CSSecurityImage').focus();
		return;
	}

	SaveInquiry();
}

function SaveInquiry()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsCustomerSupport.php',
		{
			method: 'post',
			parameters: 'action=submit' +
						'&scid=' + $F('SecurityCodeId') +
						'&securitycode=' + $F('CSSecurityImage') +
						'&name=' + $F('CSName') +
						'&email=' + $F('CSEmail') +
						'&question=' + encodeURIComponent($F('CSInquiry')) +
						'&subject=' + $F('CSSubjects') +
						'&orderid=' + CSCurrentOrderId,
			onSuccess: InquirySaved,
			onFailure: HandleFailure
		}
	);
}

function InquirySaved(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		$('CSSupportDiv').innerHTML = Result.Message.fontcolor('white');
		ContinueWithMail = 0;
	}
	else
	{
		$('CSInfoMessage').innerHTML = Result.Message.fontcolor('red');
	}
}

function ShowSelectedInquiryType()
{
	if ($('CheckBoxCSNewOrder').checked)
	{
		if (ReadCookie('Order'))
		{
			ShowNewOrderConfirmation();
		}
		else
		{
			ShowLiveChat();
		}
	}
	else if ($('CheckBoxCSExistingOrder').checked)
	{
		ShowExistingOrderPane();
	}
	else if ($('CheckBoxCSOther').checked)
	{
		ShowContactForm(1);
	}
	else if ($('CheckBoxCSSellOrder').checked)
	{
		document.location = "mailto:vendors@readyclickpay.com?Subject=Sell%20Currency&body=Hello%2c%0A%0A%0A%0AThanks%20for%20letting%20us%20know%20you%27re%20looking%20to%20sell%2e%20Please%20fill%20out%20the%20below%20information%20as%20accurate%20as%20possible%2e%20If%20you%20have%20a%20very%20large%20supply%2c%20please%20just%20say%20%22Large%20Supply%2e%22%20We%20will%20get%20back%20to%20you%20ASAP!%0A%0A%0A%0AGame%28s%29%3A%0A%0A%0A%0AServer%28s%29%3A%0A%0A%0A%0AAmount%28s%29%20%28per%20server%29%3A%0A%0A%0A%0AAdditional%20contact%20info%3A%0A%0A";
		//ShowLiveChat();
		return false;
	}
	else
	{
		alert(CSSelectEnquiry);
		return;
	}

	$('CSProblemType').style.display = 'none';
}

function ShowNewOrderConfirmation()
{
	if (!ReadCookie('Order'))
		ShowLiveChat();

	dhtmlHistory.add("NewOrderConfirmation");
	$('CSProblemType').style.display = 'none';
	$('ConfirmNewOrder').style.display = 'block';
}

function ShowExistingOrderPane()
{
	dhtmlHistory.add("ExistingOrder");

	$('CSProblemType').style.display = 'none';
	$('ConfirmNewOrder').style.display = 'none';

	if (UserDetails)
	{
		var AjaxRq = new Ajax.Request
		(
			'/Ajax/ActionsCustomerSupport.php',
			{
				method: 'post',
				parameters: 'action=getorder',
				onSuccess: CSOrderDetailsLoaded,
				onFailure: HandleFailure
			}
		);
	}
	else
	{
		ShowOrderIdentification();
	}
}

function CSOrderDetailsLoaded(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		ShowOrderDetailsPane(Result.Data);
	}
	else
	{
		if (Result.NoOrder)
			$('NoOrderFound').style.display = 'block';
	}
}

function ShowOrderIdentification()
{
	$('CSOrderDetailsPane').style.display = 'none';
	$('NoOrderFound').style.display = 'none';
	$('CSRequireOrderId').style.display = 'block';
}

function ShowContactForm(Other)
{
	dhtmlHistory.add("ContactUs");

	if (Other)
		CSCurrentOrderId = 0;

	$('CSProblemType').style.display = 'none';
	$('CSRequireOrderId').style.display = 'none';
	$('CSOrderDetailsPane').style.display = 'none';

	if (UserDetails)
	{
		$('CSName').value = UserDetails.FirstName + ' ' + UserDetails.LastName;
		$('CSEmail').value = UserDetails.Email;
	}

	$('EmailSending').style.display = 'block';
}

function ShowLiveChat()
{
	$('ConfirmNewOrder').style.display = 'none';
	$('LiveChatOpenInfo').style.display = 'block';
	window.open(CustomerSupportLink, 'custclient', 'width=600,height=400,scrollbars=0');
}

function CSSearchForOrder()
{
	if ($F('CSUserOrderIdent').trim() == '')
	{
		alert(CSTypeOrderId);
		$('CSUserOrderIdent').focus();
		return;
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsCustomerSupport.php',
		{
			method: 'post',
			parameters: 'action=ordersearch' +
						'&ident=' + $F('CSUserOrderIdent'),
			onSuccess: OrderSearchedFinished,
			onFailure: HandleFailure
		}
	);
}

function OrderSearchedFinished(Response)
{
	eval("var Result =" + Response.responseText);

	if (Result.Success)
	{
		ShowOrderDetailsPane(Result.Data);
	}
	else
	{
		$('CSOrderSearchMessage').innerHTML = Result.Message;
	}
}

function ShowOrderDetailsPane(OrderData)
{
	CSCurrentOrderId = OrderData['OrderId'];

	$('CSRequireOrderId').style.display = 'none';
	$('LiveChatOpenInfo').style.display = 'none';

	$('CSDetailsOrderId').innerHTML = OrderData['OrderId'];
	$('CSDetailsTransactionId').innerHTML = OrderData['TransactionId'];
	$('CSDetailsOrderDate').innerHTML = OrderData['OrderDate'];
	$('CSDetailsOrderItems').innerHTML = OrderData['OrderItems'];
	$('CSDetailsGame').innerHTML = OrderData['Game'];
	$('CSDetailsServer').innerHTML = OrderData['Server'];
	$('CSDetailsFaction').innerHTML = OrderData['Faction'];
	$('CSDetailsCharacter').innerHTML = OrderData['Character'];
	$('CSDetailsPayment').innerHTML = OrderData['Payment'];
	$('CSDetailsDeliveryStatus').innerHTML = OrderData['DeliveryStatus'];
	$('CSDetailsQueuePosition').innerHTML = OrderData['QueuePosition'];

/*
	if (OrderData.OnlineNow)
	{
		$('ContactUsCustomerOnline').style.display = 'block';
		$('CSOnlineNowLarge').style.display = 'inline';
	}
	else
	{
		$('ContactUsCustomerOnline').style.display = 'none';
		$('CSOnlineNowLarge').style.display = 'none';

	}
*/
	$('ContactUsCustomerOnline').style.display = 'none';
        $('CSOnlineNowLarge').style.display = 'none';

	$('CSOrderDetailsPane').style.display = 'block';
}

function RefreshSecurityImage()
{
	var NewNumber = Math.round(32768 * Math.random());

	$('SecurityImageObject').src = '/GetImage.php?rand=' + NewNumber;
	$('SecurityCodeId').value = NewNumber;
}

function ShowCSOnlineNow()
{
	ShowBackground('dialog');

	GetPageSize();

	$('DivGetInfo').style.left = (PageWidth - 400) / 2;
	$('DivGetInfo').style.display = 'block';
}

function SubmitContactInfo()
{
	if ($('OnlineNowCode').value.strip() == '')
	{
		alert(OnlineNowSecurityCode);
		$('OnlineNowCode').focus();
		return;
	}

	var AjaxRq = new Ajax.Request
	(
		'/Ajax/SendContactInfo.php',
		{
			method: 'post',
			parameters: 'id=' + CSCurrentOrderId + '&scodeid=' + $F('OnlineNowSecurityCodeId') +
						'&ucode=' + $F('OnlineNowCode'),
			onSuccess: LoadContactInfoResponse,
			onFailure: HandleFailure
		}
	);

	$('OnlineInfoMessage').innerHTML = OnlineNowSendingData;
}

function LoadContactInfoResponse(Response)
{
	var Response = Response.responseText.evalJSON();

	RefreshOnlineNowImage();
	$('OnlineNowCode').value = '';

	if (Response.Success)
	{
		$('CSDetailsDeliveryStatus').innerHTML = 'Processing';
		DisplayMessage('OnlineInfoMessage', Response.Message, 3600);
	}
	else
	{
		DisplayMessage('OnlineInfoMessage', Response.Message.fontcolor('red'), 5);
	}
}

function HideContactInfo()
{
	$('DivGetInfo').style.display = 'none';
	$('dialog').style.display = 'none';
	$('OnlineInfoMessage').innerHTML = '';
}

function RefreshOnlineNowImage()
{
	var NewNumber = Math.round(32768 * Math.random());

	$('OnlineNowSecurityImage').src = 'GetImage.php?rand=' + NewNumber;
	$('OnlineNowSecurityCodeId').value = NewNumber;
}

var PrivateTime;

function CheckForPromotion()
{
	var AjaxRq = new Ajax.Request
	(
		'/Ajax/ActionsPromotion.php',
		{
			method: 'post',
			parameters: 'action=check',
			onSuccess: StartPromotionResponse,
			onFailure: HandleFailure
		}
	);
}

function StartPromotionResponse(Response)
{
	var Result = Response.responseText.evalJSON();

	if (Result.Success)
	{
		$('GeneratedCouponDiscountSpan').innerHTML = Result.Discount;
		$('GeneratedCouponCodeSpan').innerHTML = Result.Code;
		$('PromotionCouponDiv').style.display = 'block';

		PrivateTime = Result.TimeToLive;
		CountDown();
	}
	else
	{
		$('PromotionCouponDiv').style.display = 'none';
	}
}

function CountDown()
{
	var Seconds = PrivateTime % 60;
	var Minutes = Math.floor(PrivateTime / 60);

	if (PrivateTime >= 0)
	{
		setTimeout('CountDown()', 1000);
		document.getElementById('CouponCountdownDisplay').innerHTML = (Minutes + ':' + (Seconds < 10 ? '0' + Seconds : Seconds)).fontcolor(PrivateTime <= 30 ? 'red' : 'white');
		PrivateTime--;
	}
	else
	{
		document.getElementById('CouponPromotionTimer').innerHTML = 'Promotion ended !';
		DismissCouponPromotion();
	}
}

function DismissCouponPromotion()
{
	$('PromotionCouponDiv').style.display = 'none';

	return false;
}

function Subscribed()
{
}

function LoadToCart(Val)
{
	ToCartVal = Val;
	Params = ToCartVal.split(',');
	PlaygroundId = Params[2];
	AddGameMoney(Params[0], Params[1]);
}

function HideGreetings()
{
	if ($('CustomerGreeting'))
	{
		$('CustomerGreeting').style.display = 'none';
	}
}

function LoadAddToCart()
{
	ToCart = $F('QuantitiesTotal');
	Params = ToCart.split(',');
	PlaygroundId = Params[2];
	AddGameMoney(Params[0], Params[1]);
}

function GetRegExpr(Id)
{
	new Ajax.Request
	(
		'/Ajax/GetGamesRE.php',
		{
			method: 'post',
			parameters: 'gameid=' + Id,
			onSuccess: LoadRESuccess,
			onFailure: HandleFailure
		}
	);
}

function LoadRESuccess(response)
{
	eval("var Response =" + response.responseText);

	if (Response.Success)
	{
		RegExpr = Response.RE;
	}
	else
	{
		HandleFailure(response);
	}
}

function ChangePlayground(PlayId)
{
	new Ajax.Request
	(
		'/Ajax/ChangePlayground.php',
		{
			method: 'post',
			parameters: 'playid=' + PlayId,
			onSuccess: PlaygroundChanged,
			onFailure: HandleFailure
		}
	);
}

function PlaygroundChanged(response)
{
	eval("var Response =" + response.responseText);

	if(Response.Success)
	{
		MatchingMessage = Response.Message;
		LoadCheckout();

		$('MatchingDiv').style.display = 'block';
		$('CheckoutErorSpan').style.display = 'none';
	}
	else
	{
		$('MatchingDiv').innerHTML = Response.Message;
		$('CheckoutErorSpan').style.display = 'none';
	}
}

function LoadCSSubjects(Id)
{
	$('CSInquiry').value = '';

	if (Id == 6)
	{
		$('CSInquiry').value = 'Hello,\n\nThanks for letting us know you\'re looking to sell. Please fill out the below information as accurate as possible. If you have a very large supply, please just say "Large Supply."  We will get back to you ASAP!\n\n\nGame(s):\n\n\nServer(s):\n\n\nAmount(s) (per server):\n\n\nAdditional contact info:\n\n';
	}
}

function IEFixImageLabel(Obj)
{
	var o = Obj.parentNode
	var e = document.getElementById(o.htmlFor);
	switch(e.type)
	{
		case "radio":
			e.checked |=1;
			break;
		case "checkbox":
			e.checked = !e.checked;
			break;
		case "text":
		case "password":
		case "textarea":
			e.focus();
			break;
	}
	return false;
}

