<!--
	// *********************************************************
	// This code Copyright (c) 2006 Jayisgames.com
	// http://www.jayisgames.com/game-submit/gamesubmit.js
	// License is granted if and only if this entire
	// copyright notice is included. By Jay Bibby.
	// *********************************************************
	// browser detection
	// let's find out what it can do, not what it is...
	var whichBrowser;
	if(navigator.userAgent.indexOf("Opera") > -1) {
		whichBrowser="Opera"
	} else if(document.layers) {
		whichBrowser="NN4";
	} else if(document.all && !document.getElementById) {
		whichBrowser="IE4";
	} else if(document.all) {
		whichBrowser="IE";
		// ok, so it's IE, but is it a Mac? Here's one way to find out
		var isMac = navigator.userAgent.indexOf("Mac") != -1;
		if(isMac) {
			whichBrowser="IEMac";
		}
	} else if(document.getElementById) {
		whichBrowser="w3c";
	} else {
		// something else (???)
		// maybe a future browser, or something currently unknown
	}

	// redirect the older browsers to Mozilla
	if(whichBrowser == "NN4" || whichBrowser == "IE4" || whichBrowser == "IEMac") {
		window.location = "http://www.mozilla.org/products/firefox/";
	}
	
	//////////////////////////////////////////////////////////////
	
	function init() {
		// this function sets up the form and creates the initial select menu
		var formEle = document.createElement('form');
		formEle.setAttribute('action','postgame.php');
		formEle.setAttribute('method','POST');
		formEle.setAttribute('name','reviewSub');
		// set up onsubmit and onreset functions
		var submitFunc = 'return ValidateAll()';
		var resetFunc = 'processSelect("HardwareMenu","skip","1")';
		if(whichBrowser == "IE") {
			// for IE, redefine the functions as anonymous functions
			submitFunc = function() {
				result = ValidateAll();
				return result;
			};
			resetFunc = function() {
				processSelect("HardwareMenu","skip","1");
			};
		}
		formEle.setAttribute('onsubmit',submitFunc);
		formEle.setAttribute('onreset',resetFunc);
		// append the form to the document body (dialog div)
		document.getElementById('dialog').appendChild(formEle);
		// and create the first select menu
		makeSelect(HardwareMenu,HardwareMenu.desc,colorIndex,"-100px")
	}
	
	function makeSelect(menu,menulabel,color,startY) {
		// this function creates a select menu element with all its options
		// first create containing div element
		var divEle = document.createElement('menudiv');
		divEle.setAttribute('class','menucontainer');
		divEle.setAttribute('id',menu.name);
		divEle.setAttribute('name',menu.name);
		if(!startY) startY = TOP_POS_ANI_START + "px";
		divEle.style.top = startY;
		divEle.style.zIndex = Z_INDEX_BOTTOM;
		divEle.style.backgroundColor = "#"+colorArray[parseInt(color)].toString(16);
		
		// more IE custom styles to fix its fugliness
		var borderStyle = " 5px dotted";
		if(whichBrowser == "IE") {
			borderStyle = " 1px solid";
		}
		divEle.style.border = "#"+(parseInt(colorArray[parseInt(color)])-parseInt(0x303030)).toString(16)+borderStyle;
		
		// create the select element
		var selectEle = document.createElement('select');
		// create the attributes
		selectEle.setAttribute('name',menu.name);
		// create onchange attribute to handle user selection
		colorIndex = parseInt(color)+1;
		var thefunc = "processSelect('"+menu.name+"',this.value,"+colorIndex+")";

		if(whichBrowser == "IE") {
			// for IE, redefine the function as an anonymous function
			var theIndex = colorIndex;
			thefunc = function() {
				processSelect(menu.name,this.value,theIndex);
			}
		}
		selectEle.setAttribute('onchange',thefunc);
		
		// create first option -- blank
		// selecting this option will "skip" creating an additional menu
		selectEle.appendChild(makeOption("...","skip"));
		
		// determine how many options this menu object has
		var propCount = 0;
		for(prop in menu) {	
			propCount++;
		}
		// create options for the select element
		for(var i=1;i<=parseInt((propCount-NUM_OBJECT_DESCRIPTORS)/2);i++) {
			selectEle.appendChild(makeOption(menu["label"+i],menu["menu"+i]));
		}
		
		// append select to div
		divEle.appendChild(selectEle);
		
		// append name as text
		var textEle = document.createElement('div');
		textEle.setAttribute('class','righttext');
		textEle.setAttribute('id',menu.name+"text");
		appendTextNode(textEle,menulabel);
		divEle.appendChild(textEle);
		
		// append div to the form
		document.forms[0].appendChild(divEle);
		
		// set up styles for IE
		if(whichBrowser == "IE") {
			document.getElementById(menu.name).className='menucontainer';
			document.getElementById(menu.name+"text").className='righttext';
		}
		
		// animate
		nodes = document.getElementsByTagName('menudiv');
		for(i=0;i<nodes.length;i++) {
			if(nodes[i].getAttribute('name') == menu.name) {
				aniNode = nodes[i];				// store the node reference in a 'global'
				break;
			}
		}
		window.setTimeout('slideDown(aniNode)',NUM_ANIMATE_MS);
	}
	
	function makeOption(label,value) {
		// make an option element using the values passed in
		var optEle = document.createElement('option');
		optEle.setAttribute('value',value);
		appendTextNode(optEle,label);
		return optEle;
	}
	
	function appendTextNode(theNode,theString) {
		// creates a run-of-the-mill all-purpose textNode
		var textEle = document.createTextNode(theString);
		theNode.appendChild(textEle);
	}
	
	function appendLINode(theNode,theString) {
		// create a list item element
		var liEle = document.createElement('li');
		var textEle = document.createTextNode(theString);
		liEle.appendChild(textEle);
		theNode.appendChild(liEle);
	}
	
	function appendBrNode(theNode) {
		// yep, and one for a line break, too
		var brEle = document.createElement('br');
		theNode.appendChild(brEle);
	}
	
	function processSelect(name,choice,color) {
		// this function gets called when the user selects from one of the select menus
		postAniFunction = "";
		// first, sanity check for first menu item
		if(choice && choice == "skip") {
			// if so, skip creating a new select menu
			// yet still remove any nodes that may not be appropriate any longer
			clearNodes(name);
		} else {
			// all other menu choices, including "null" which means done with select menus
			menuChoice = eval(choice);
			if(menuChoice) {
				postAniFunction = "makeSelect(menuChoice,menuChoice.desc,'"+color+"');";
				clearNodes(name);
			} else {
				// end of choices
				clearNodes(name);
				composeForm();
			}
		}			
	}
	
	function clearNodes(theStr) {
		var divNodes = document.getElementsByTagName('menudiv');
		for(i=divNodes.length-1;i>=0;i--) {
			if(divNodes[i].getAttribute('name') != theStr) {
				// before removing this node, check to see if it's in position
				if(parseInt(divNodes[i].style.top) <= TOP_POS_ANI_START) {
					document.forms[0].removeChild(divNodes[i]);
				} else {
					divNodes[i].style.zIndex = Z_INDEX_BOTTOM;
					aniNode = divNodes[i];		// store the reference in a 'global'
					aniName = theStr;
					window.setTimeout('slideUp(aniNode,aniName)',NUM_ANIMATE_MS);
					break;
				}
			} else {
				eval(postAniFunction);
				break;
			}
		}
		// also remove the text display of the user's choice, just in case they went back
		var pNode = document.getElementById('formdiv');
		if(pNode) pNode.parentNode.removeChild(pNode);
	}
	
	function composeForm() {
		var lNode,rNode,sNode,uNode,tNode;
		// form element container divs
		var containDiv = document.createElement('div');
		containDiv.setAttribute('id',"formdiv");
		// left column
		var leftDiv = document.createElement('div');
		leftDiv.setAttribute('id',"leftform");
		// right column
		var rightDiv = document.createElement('div');
		rightDiv.setAttribute('id',"rightform");

		// left column content
		lNode = document.createElement('p');
		sNode = document.createElement('span');
		sNode.setAttribute('class',"description");
		sNode.setAttribute('id',"description");
		appendTextNode(sNode,"The game type you selected to submit/review... ");
		lNode.appendChild(sNode);
		
		// include user select menu choices as text in an unordered list
		uNode = document.createElement('ul');
		var menus = document.getElementById('dialog').getElementsByTagName('select');
		var choiceString = "";   // for sending to php script
		for(i=0;i<menus.length;i++) {
			var index = menus[i].selectedIndex;
			var menuObjName = menus[i].name;
			var menuObj = eval(menuObjName);
			var label = menuObj["label"+index];
			if(i>0) choiceString += " - ";
			choiceString += label;
			appendLINode(uNode,label);
		}
		lNode.appendChild(uNode);

		// create a hidden field with the user's choiceString to send to php script
		tNode = document.createElement('input');
		tNode.setAttribute('type',"hidden");
		tNode.setAttribute('name',"choices");
		tNode.setAttribute('value',choiceString);
		lNode.appendChild(tNode);
		
		leftDiv.appendChild(lNode);			// append left content to left div
		containDiv.appendChild(leftDiv);	// append left div to form container
		
		// right column content
		// name
		rNode = document.createElement('p');
		sNode = document.createElement('span');
		sNode.setAttribute('class',"label");
		sNode.setAttribute('id',"labelname");
		appendTextNode(sNode,"Your name: ");
		rNode.appendChild(sNode);
		appendBrNode(rNode);
		tNode = document.createElement('input');
		tNode.setAttribute('type',"text");
		tNode.setAttribute('name',"username");
		tNode.setAttribute('id','txtusername');

		// check for cookie value
		var theUser = GetJBCookie('username');
		if(theUser) {
			// stuff the value in the text field
			tNode.setAttribute('value',theUser);
		}
		
		rNode.appendChild(tNode);
		appendBrNode(rNode);

		// email
		sNode = document.createElement('span');
		sNode.setAttribute('class',"label");
		sNode.setAttribute('id',"labelemail");
		appendTextNode(sNode,"Email address: ");
		rNode.appendChild(sNode);
		appendBrNode(rNode);
		tNode = document.createElement('input');
		tNode.setAttribute('type',"text");
		tNode.setAttribute('name',"email");
		tNode.setAttribute('id','txtemail');

		// check for cookie value
		var theEmail = GetJBCookie('email');
		if(theEmail) {
			// stuff the value in the text field
			tNode.setAttribute('value',theEmail);
		}

		rNode.appendChild(tNode);
		appendBrNode(rNode);

		// game title
		sNode = document.createElement('span');
		sNode.setAttribute('class',"label");
		sNode.setAttribute('id',"labeltitle");
		appendTextNode(sNode,"Game title: ");
		rNode.appendChild(sNode);
		appendBrNode(rNode);
		tNode = document.createElement('input');
		tNode.setAttribute('type',"text");
		tNode.setAttribute('name',"title");
		tNode.setAttribute('id','txttitle');
		rNode.appendChild(tNode);
		appendBrNode(rNode);

		// game url
		sNode = document.createElement('span');
		sNode.setAttribute('class',"label");
		sNode.setAttribute('id',"labelurl");
		appendTextNode(sNode,"Game URL (link): ");
		rNode.appendChild(sNode);
		appendBrNode(rNode);
		tNode = document.createElement('input');
		tNode.setAttribute('type',"text");
		tNode.setAttribute('name',"url");
		tNode.setAttribute('id','txturl');
		rNode.appendChild(tNode);
		
		// submit button
		sNode = document.createElement('span');
		sNode.setAttribute('class',"button");
		sNode.setAttribute('id',"labelsubmit");
		tNode = document.createElement('input');
		tNode.setAttribute('type',"submit");
		tNode.setAttribute('value',"Submit");
		sNode.appendChild(tNode);
		rNode.appendChild(sNode);
		
		// reset button
		tNode = document.createElement('input');
		tNode.setAttribute('type',"reset");
		rNode.appendChild(tNode);
		
		appendBrNode(rNode);

		// game review text
		sNode = document.createElement('span');
		sNode.setAttribute('class',"label");
		sNode.setAttribute('id',"labelreview");
		appendTextNode(sNode,"Enter a description (or a review) if you wish: ");
		rNode.appendChild(sNode);
		appendBrNode(rNode);
		tNode = document.createElement('textarea');
		tNode.setAttribute('name',"review");
		tNode.setAttribute('id','txtreview');
		tNode.setAttribute('rows',"15");
		tNode.setAttribute('cols',"35");
		rNode.appendChild(tNode);
		rightDiv.appendChild(rNode);

		containDiv.appendChild(rightDiv);

		// create a text node and output the user's choice
		document.forms[0].appendChild(containDiv);

		// set up styles for IE
		if(whichBrowser == "IE") {
			document.getElementById("description").className='description';
			document.getElementById("labelname").className='label';
			document.getElementById("labelemail").className='label';
			document.getElementById("labeltitle").className='label';
			document.getElementById("labelurl").className='label';
			document.getElementById("labelsubmit").className='button';
			document.getElementById("labelreview").className='label';
		}

		document.getElementById('formdiv').style.left = LEFT_POS_ANI_START+"px";
		window.setTimeout('slideIn()',NUM_ANIMATE_MS);
	}
	
	function slideIn() {
		var eleStyle = document.getElementById('formdiv').style;
		var iLeft = parseInt(eleStyle.left);
		if(iLeft < 0) {
			eleStyle.left = (iLeft + ANIMATE_HORIZ_INCR) + "px";
			window.setTimeout('slideIn()',NUM_ANIMATE_MS);
		}
	}
	
	function slideDown(theNode) {
		aniNode = theNode;				// store the reference in a 'global'
		var eleStyle = theNode.style;
		var iTop = parseInt(eleStyle.top);
		if(iTop < 0) {
			eleStyle.top = (iTop + ANIMATE_VERT_INCR) + "px";
			window.setTimeout('slideDown(aniNode)',NUM_ANIMATE_MS);
		} else theNode.style.zIndex = Z_INDEX_TOP;
	}

	function slideUp(theNode,theStr) {
		aniNode = theNode;				// store the reference in a 'global'
		aniName = theStr;
		var eleStyle = theNode.style;
		var iTop = parseInt(eleStyle.top);
		if(iTop > TOP_POS_ANI_START) {
			eleStyle.top = (iTop - ANIMATE_VERT_INCR) + "px";
			window.setTimeout('slideUp(aniNode,aniName)',NUM_ANIMATE_MS);
		} else clearNodes(aniName);
	}
	
	// defined constants
	var Z_INDEX_TOP = "10";
	var Z_INDEX_BOTTOM = "0";
	var LEFT_POS_ANI_START = -1050;
	var TOP_POS_ANI_START = -65;
	var ANIMATE_VERT_INCR = 5;
	var ANIMATE_HORIZ_INCR = 50;
	var NUM_ANIMATE_MS = 25;				// number of milliseconds between timeouts
	var NUM_OBJECT_DESCRIPTORS = 2;			// used when calculating number of menu options
											// allows for multiple object descriptive properties
	var colorArray = new Array(0xed5a79,0xfb6d32,0x74b769,0xffcb48,0x48a4c2,0x8e7ab0);
	var colorIndex = 0;						// used to change the background color of each select
	var timeoutID = 0;
	var aniNode = null;					// for animation, keeps a reference to the animating node
	var aniName = null;					// for deletion, keeps a reference to the animating node name
	var postAniFunction = null;			// stores the function to call following animation
	var menuChoice = null;				// stores reference to the currently selected menu object
	
	// (parseInt(0xafc0f1)-parseInt(0x303030)).toString(16)
	
	var HardwareMenu = new Object();
	var ComputerMenu = new Object();
	var ConsoleMenu = new Object();
	var HandheldMenu = new Object();
	var WebMenu = new Object();
	var NintendoConsoleMenu = new Object();
	var SonyConsoleMenu = new Object();
	var MicrosoftMenu = new Object();
	var NintendoHandheldMenu = new Object();
	var PlatformMenu = new Object();
	var TypeMenu = new Object();
//-->
	