var theImages = new Array() 
var isGame = false;
var isVoice = false;
var isWeb = false;

theImages[0] = 'images/header01.jpg'
theImages[1] = 'images/header02.jpg'
theImages[2] = 'images/header03.jpg'
theImages[3] = 'images/header04.jpg'
theImages[4] = 'images/header05.jpg'
 
 
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}
 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

/* 0-Game, 1-Min#, 2-Max#, 3-MinPrice, 4-SlotPrice */
var gamedata = new Array();
var c = 0;
gamedata[c++] = new Array("BattleField 2 (Unranked)",			12,	64,		21.00,	1.50);
gamedata[c++] = new Array("BattleField 1942 (Unranked)",		12,	64,		24.00,	1.50);
gamedata[c++] = new Array("BattleField 2142 (Unranked)",		12,	64,		24.00,	1.50);
gamedata[c++] = new Array("Call of Duty: United Offensive",		12,	64,		24.00,	1.50);
gamedata[c++] = new Array("Call of Duty",						12,	64,		24.00,	1.50);
gamedata[c++] = new Array("Call of Duty 2",						12,	64,		24.00,	1.50);
gamedata[c++] = new Array("Call of Duty 4",						12,	48,		24.00,	1.50);
gamedata[c++] = new Array("Call of Duty: World at War",			12,	48,		24.00,	1.50);
gamedata[c++] = new Array("Counter Strike",						10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Counter Strike: Source",				10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Crysis",								10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Crysis Wars",						10,	48,		15.00,	1.50);
gamedata[c++] = new Array("D.I.P.R.I.P.",						10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Day of Defeat",						10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Day of Defeat: Source",				10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Doom",								10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Doom 3",								10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Enemy Territory: Quake Wars",		10,	48,		15.00,	1.75);
gamedata[c++] = new Array("F.E.A.R.",							10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Garry's Mod",						10,	48,		15.00,	3.50);
gamedata[c++] = new Array("Half-Life: Deathmatch",				10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Half-Life 2: Deathmatch",			10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Halo",								10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Insurgency",							10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Jedi Knight 2",						12,	48,		15.00,	1.00);
gamedata[c++] = new Array("Killing Floor",						10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Left 4 Dead",						8,	8,		18.00,	0.00);
gamedata[c++] = new Array("Medal of Honor: Airborne",			10,	48,		15.00,	1.25);
gamedata[c++] = new Array("Medal of Honor: Allied Assault",		10,	48,		15.00,	1.25);
gamedata[c++] = new Array("Medal of Honor: Pacific Assault",	10,	48,		15.00,	1.25);
gamedata[c++] = new Array("Open Arena",							10,	48,		15.00,	1.25);
gamedata[c++] = new Array("Operation Flashpoint",				10,	48,		15.00,	2.00);
gamedata[c++] = new Array("Quake II",							10,	48,		15.00,	0.25);
gamedata[c++] = new Array("Quake III Arena",					10,	48,		15.00,	0.25);
gamedata[c++] = new Array("Quake III - GTV",					10,	48,		15.00,	0.25);
gamedata[c++] = new Array("Quake 4",							10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Rainbow Six 3 - Raven Shield",		10,	48,		15.00,	2.00);
gamedata[c++] = new Array("Rainbow Six Vegas",					10,	48,		15.00,	3.25);
gamedata[c++] = new Array("Rainbow Six Vegas 2",				10,	48,		15.00,	3.25);
gamedata[c++] = new Array("Return to Castle Wolfenstein",		10,	48,		15.00,	1.40);
gamedata[c++] = new Array("Return to Castle Wolfenstein - GTV",	10,	48,		15.00,	1.40);
gamedata[c++] = new Array("San Andreas: Multiplayer",			10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Soldier of Fortune 2",				10,	48,		15.00,	1.40);
gamedata[c++] = new Array("The Specialists",					10,	48,		15.00,	2.00);
gamedata[c++] = new Array("SWAT 4",								10,	48,		15.00,	2.50);
gamedata[c++] = new Array("SWAT 4: The Stetchkov Syndicate",	10,	48,		15.00,	2.50);
gamedata[c++] = new Array("Synergy",							10,	48,		15.00,	2.00);
gamedata[c++] = new Array("Team Fortress 2",					10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Tremulous",							10,	48,		15.00,	0.25);
gamedata[c++] = new Array("Tribes",								10,	48,		15.00,	1.25);
gamedata[c++] = new Array("Unreal Tournament",					10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Unreal Tournament - Demo",			10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Unreal Tournament 2004",				10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Unreal Tournament 3",				10,	48,		15.00,	1.50);
gamedata[c++] = new Array("Urban Terror",						10,	48,		15.00,	0.75);
gamedata[c++] = new Array("Warsow",								10,	48,		15.00,	2.00);
gamedata[c++] = new Array("Wolfenstein - Enemy Territory",		10,	48,		15.00,	1.40);

/* 0-#Users, 1-Price */
var voicedata = new Array();
voicedata[0] = new Array("0 ", 0.00);
voicedata[1] = new Array("10 Teamspeak ", 3.95);
voicedata[2] = new Array("15 Teamspeak ", 4.95);
voicedata[3] = new Array("25 Teamspeak ", 7.95);
voicedata[4] = new Array("50 Teamspeak ", 14.95);
voicedata[5] = new Array("100 Teamspeak ", 24.95);
voicedata[6] = new Array("150 Teamspeak ", 34.95);
voicedata[7] = new Array("200 Teamspeak ", 44.95);
voicedata[8] = new Array("250 Teamspeak ", 59.95);
voicedata[9] = new Array("10 Ventrilo ", 3.95);
voicedata[10] = new Array("15 Ventrilo ", 4.95);
voicedata[11] = new Array("25 Ventrilo ", 7.95);
voicedata[12] = new Array("50 Ventrilo ", 14.95);
voicedata[13] = new Array("100 Ventrilo ", 24.95);
voicedata[14] = new Array("150 Ventrilo ", 34.95);
voicedata[15] = new Array("200 Ventrilo ", 44.95);
voicedata[16] = new Array("250 Ventrilo ", 59.95);
voicedata[17] = new Array("10 Mumble ", 3.95);
voicedata[18] = new Array("15 Mumble ", 4.95);
voicedata[19] = new Array("25 Mumble ", 7.95);
voicedata[20] = new Array("50 Mumble ", 14.95);
voicedata[21] = new Array("100 Mumble ", 24.95);
voicedata[22] = new Array("150 Mumble ", 34.95);
voicedata[23] = new Array("200 Mumble ", 44.95);
voicedata[24] = new Array("250 Mumble ", 59.95);

/* 0-Package, 1-Price */
var webdata = new Array();
webdata[0] = new Array("Package 1", 3.00);
webdata[1] = new Array("Package 2", 5.00);
webdata[2] = new Array("Package 3", 10.00);

var servers = new Array(
	"San Jose, California, USA",
	"Dallas, Texas, USA",
	"Chicago, Illinois, USA",
	"New York City, New York, USA",
	"London, England, United Kingdom",
	"Amsterdam, Netherlands",
	"Frankfurt, Germany");

function FillGames() {
	while(document.form1.gamename.length != 0) {
		document.form1.gamename.options[document.form1.gamename.length-1] = null;
	}
	for (i=0; i < gamedata.length; i++) {
		theOption = new Option(gamedata[i][0], i, false, false);
		document.form1.gamename.options[document.form1.gamename.length] = theOption;		
		document.form1.gamename.selectedIndex = 0;
	}
}

function FillNumPlayers() {
	while(document.form1.numplayers.length != 0) {
		document.form1.numplayers.options[document.form1.numplayers.length-1] = null;
	}
	var game = document.form1.gamename.options[document.form1.gamename.selectedIndex].value;
	var minplayers = gamedata[game][1];
	var maxplayers = gamedata[game][2];
	for (i=minplayers; i < maxplayers+1; i++) {
		theOption = new Option(i, i, false, false);
		document.form1.numplayers.options[document.form1.numplayers.length] = theOption;		
		document.form1.numplayers.selectedIndex = 0;
	}
}

function FillLocations() {
	while(document.form1.location.length != 0) {
		document.form1.location.options[document.form1.location.length-1] = null;
	}
	for (i=0; i < servers.length; i++) {
		theOption = new Option(servers[i], servers[i], false, false);
		document.form1.location.options[document.form1.location.length] = theOption;		
		document.form1.location.selectedIndex = 0;
	}
}

function FillVoice() {
	while(document.form1.voice.length != 0) {
		document.form1.voice.options[document.form1.voice.length-1] = null;
	}
	for (i=0; i < voicedata.length; i++) {
		var show = voicedata[i][0] + "users +$" + voicedata[i][1].toFixed(2);
		theOption = new Option(show, i, false, false);
		document.form1.voice.options[document.form1.voice.length] = theOption;		
		document.form1.voice.selectedIndex = 0;
	}
}

function FillWeb() {
	while(document.form1.web.length != 0) {
		document.form1.web.options[document.form1.web.length-1] = null;
	}
	for (i=0; i < webdata.length; i++) {
		theOption = new Option(webdata[i][0], i, false, false);
		document.form1.web.options[document.form1.web.length] = theOption;		
		document.form1.web.selectedIndex = 0;
	}
}

function ChangeGame(igame) {
	for (i=0; i < gamedata.length; i++) {
		if (gamedata[i][0] === igame.value) {
			document.form1.gamename.selectedIndex = i;
			FillNumPlayers(); 
			CalculatePrice();
			break;
		}
	}
}

function ChangeVoice(ivoice) {
	for (i=0; i < voicedata.length; i++) {
		if (voicedata[i][0] == ivoice.value) {
			document.form1.voice.selectedIndex = i;
			CalculatePrice();
			break;
		}
	}
}

function ChangeWeb(iweb) {
	for (i=0; i < webdata.length; i++) {
		if (webdata[i][0] == iweb.value) {
			document.form1.web.selectedIndex = i;
			CalculatePrice();
			break;
		}
	}
}

function UpdateCustom() {
	var custom = 
		"username=" + document.form1.username.value
		+ "&password=" + document.form1.password.value
		+ "&fullname=" + document.form1.fullname.value
		+ "&email=" + document.form1.email.value
		+ "&phone=" + document.form1.phone.value;
	document.form1.custom.value = custom;
}

function SetItemName() {
	var item = "";
	
	if (isGame) {
		var game = document.form1.gamename.options[document.form1.gamename.selectedIndex].value;
		var players = document.form1.numplayers.options[document.form1.numplayers.selectedIndex].value;
	
		item += gamedata[game][0] + " (" + players + "players).  ";
	}
	
	if (isGame || isVoice) {
		var voice = document.form1.voice.options[document.form1.voice.selectedIndex].value;
		if ( voice > 0 ) {
			item += "Teamspeak (" + voicedata[voice][0] + "users).  ";
		}
	}
	
	if (isWeb) {
		var web = document.form1.web.options[document.form1.web.selectedIndex].value;
	
		item += webdata[web][0] + ".  ";
	}
	
	var place = document.form1.location.options[document.form1.location.selectedIndex].value;
	item += "Server in " + place + ".";
	
	//item_name cannot exceed 127 chars including spaces or it cuts off
	document.form1.item_name.value = item;
}

function CalculatePrice() {
	var total = 0;
	
	if (isGame) {
		var game = document.form1.gamename.options[document.form1.gamename.selectedIndex].value;
		var players = document.form1.numplayers.options[document.form1.numplayers.selectedIndex].value;
		total += gamedata[game][3] + gamedata[game][4] * (players - gamedata[game][1]);
		
		document.form1.slot.value = "$" + gamedata[game][4].toFixed(2) + " per extra slot";
	}
	
	if (isVoice || isGame) {
		var speak = document.form1.voice.options[document.form1.voice.selectedIndex].value;
		total += voicedata[speak][1];
	}
	
	if (isWeb) {
		var web = document.form1.web.options[document.form1.web.selectedIndex].value;
		total += webdata[web][1];
	}
	
	document.form1.total.value = "$" + total.toFixed(2);
	document.form1.a3.value = total;
	SetItemName();
}

function Initialize() {
	if (isGame) {
		gamedata.sort();
		FillGames();
		FillNumPlayers();
	}
	if (isVoice || isGame) {
		FillVoice();
	}
	if (isWeb) {
		FillWeb();
	}
	FillLocations();
	CalculatePrice(); 
}

function GameInit() {
	isGame = true;
	Initialize();
}	

function VoiceInit() {
	isVoice = true;
	Initialize();
}

function WebInit() {
	isWeb = true;
	Initialize();
}

function ValidateForm() {
	var valid = false;
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if ( document.form1.username.value == "" ) {
		alert ("Please enter a user name in the text field provided.");
    }
	else if ( document.form1.password.value == "" ) {
		alert ("Please enter a password in the text field provided.");
    }
	else if ( document.form1.fullname.value == "" ) {
		alert ("Please enter your full name in the text field provided.");
    }
	else if ( document.form1.email.value == "" ) {
		alert ("Please enter your email in the text field provided.");
    }
	else if ( reg.test(document.form1.email.value) == false ) {
		alert("Please enter a valid email address");
    }
	else if ( document.form1.phone.value == "" ) {
		alert ("Please enter your phone number in the text field provided.");
    }
	
	else if ( document.form1.agecheck.checked == false ) {
		alert ("You must verify that you are 18 years or older in order to continue.");
	}
	else if ( document.form1.toscheck.checked == false ) {
		alert ("You must agree to the terms of service in order to continue.");
	}
	else {
		valid = true;
	}

	
	return valid;
}

	function MM_swapImgRestore() { //v3.0
  		var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
	}

	function MM_preloadImages() { //v3.0
  		var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
	}

	function MM_findObj(n, d) { //v4.01
		var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  		if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
		for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
		if(!x && d.getElementById) x=d.getElementById(n); return x;
	}

	function MM_swapImage() { //v3.0
  		var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   		if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
	}