<!--
// *********************************************************
// This code Copyright (c) 2008 Jayisgames.com
// http://www.jayisgames.com/cgdc5/cgdc5-entry.js
// *********************************************************
// 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() {
	var formEle = document.createElement('form');
	formEle.setAttribute('action','postentry.php');
	formEle.setAttribute('method','POST');
	formEle.setAttribute('name','cgdc5Entry');
	// set up onsubmit function
	var submitFunc = 'return ValidateAll()';
	if(whichBrowser == "IE") {
		// for IE, redefine the functions as anonymous functions
		submitFunc = function() {
			result = ValidateAll();
			return result;
		};
	}
	formEle.setAttribute('onsubmit',submitFunc);
	// append the form to the document body (dialog div)
	document.getElementById('dialog').appendChild(formEle);
	// and create the elements
	makeForm();
}

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 appendBrNode(theNode) {
	// yep, and one for a line break, too
	var brEle = document.createElement('br');
	theNode.appendChild(brEle);
}
	
function makeForm() {
	var cNode, hNode, pNode,sNode,uNode,tNode;
	// form element container divs
	var containDiv = document.createElement('div');
	containDiv.setAttribute('id',"formdiv");

	// form content
	// title
	cNode = document.createElement('center');
	sNode = document.createElement('span');
	sNode.setAttribute('class',"title");
	sNode.setAttribute('id',"title");
	appendTextNode(sNode,"Official Entry Form");
	cNode.appendChild(sNode);
	containDiv.appendChild(cNode);

	// description
	pNode = document.createElement('p');
	sNode = document.createElement('span');
	sNode.setAttribute('class',"description");
	sNode.setAttribute('id',"description");
	appendTextNode(sNode,"Please enter all requested information to the best of your ability. We will reply within 24 hours to the email address you provide to confirm your entry. We will also include your customized CGDC5 buttons containing a MochiBot script for your entry. If entering more than once, please fill out the form completely for each game you plan to enter.");
	appendBrNode(sNode);
	appendTextNode(sNode,"Thank you!");
	pNode.appendChild(sNode);
	containDiv.appendChild(pNode);
	
	// name
	pNode = document.createElement('p');
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelname");
	appendTextNode(sNode,"Your name*: ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	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);
	}
	
	sNode = document.createElement('span');
	sNode.setAttribute('class',"note");
	sNode.setAttribute('id',"notename");
	appendTextNode(sNode,"*Please provide only one name under which this entry will be entered into the competition. Any prize(s) won will be awarded to this person only. You are responsible for splitting any prize(s) won between your team members.");
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// email
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelemail");
	appendTextNode(sNode,"Email address: ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	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);
	}

	pNode.appendChild(tNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// shipping address
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelshipping");
	appendTextNode(sNode,"Shipping address (in case you win a prize): ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('textarea');
	tNode.setAttribute('name',"shipping");
	tNode.setAttribute('id','txtshipping');
	tNode.setAttribute('rows',"5");
	tNode.setAttribute('cols',"40");
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// paypal account
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelpaypal");
	appendTextNode(sNode,"PayPal account* (optional): ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('input');
	tNode.setAttribute('type',"text");
	tNode.setAttribute('name',"paypal");
	tNode.setAttribute('id','txtpaypal');

	sNode = document.createElement('span');
	sNode.setAttribute('class',"note");
	sNode.setAttribute('id',"notepaypal");
	appendTextNode(sNode,"*We must have a valid PayPal account to transfer any donations your game may receive during the Audience Prize voting. If you do not provide us with a PayPal account, then you will be responsible for any service charges associated with the transfer of donations to you.");
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	appendBrNode(pNode);
	
	// game entry title
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labeltitle");
	appendTextNode(sNode,"Game entry title: ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('input');
	tNode.setAttribute('type',"text");
	tNode.setAttribute('name',"gametitle");
	tNode.setAttribute('id','txttitle');
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// game byline
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelbyline");
	appendTextNode(sNode,"Game byline*: ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('textarea');
	tNode.setAttribute('name',"byline");
	tNode.setAttribute('id','txtbyline');
	tNode.setAttribute('rows',"3");
	tNode.setAttribute('cols',"40");

	sNode = document.createElement('span');
	sNode.setAttribute('class',"note");
	sNode.setAttribute('id',"notebyline");
	appendTextNode(sNode,"*The team name or author name(s) you enter here will appear (space permitting) on the competition page under the title of your game (e.g., \"By Team JIG\").");
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// game description
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labeldescription");
	appendTextNode(sNode,"Game description* (40 words maximum): ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('textarea');
	tNode.setAttribute('name',"gamedescription");
	tNode.setAttribute('id','txtdescription');
	tNode.setAttribute('rows',"4");
	tNode.setAttribute('cols',"50");

	sNode = document.createElement('span');
	sNode.setAttribute('class',"note");
	sNode.setAttribute('id',"notedescription");
	appendTextNode(sNode,"*Please enter a short description to appear with your game on the competition page.");
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// game url
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelurl");
	appendTextNode(sNode,"Your website link (optional): ");
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	tNode = document.createElement('input');
	tNode.setAttribute('type',"text");
	tNode.setAttribute('name',"url");
	tNode.setAttribute('id','txturl');
	pNode.appendChild(tNode);
	appendBrNode(pNode);
	appendBrNode(pNode);
		
	// create the Actionscript select element
	sNode = document.createElement('span');
	sNode.setAttribute('class',"label");
	sNode.setAttribute('id',"labelactionscript");
	appendTextNode(sNode,ActionScriptMenu.desc);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	var selectEle = document.createElement('select');
	// create the attributes
	selectEle.setAttribute('name',ActionScriptMenu.name);
	// determine how many options this menu object has
	var propCount = 0;
	for(prop in ActionScriptMenu) {	
		propCount++;
	}
	// create options for the select element
	for(var i=1;i<=parseInt(propCount-NUM_OBJECT_DESCRIPTORS);i++) {
		selectEle.appendChild(makeOption(ActionScriptMenu["label"+i],ActionScriptMenu["label"+i]));
	}
	// append select
	sNode = document.createElement('span');
	sNode.setAttribute('class',"note");
	sNode.setAttribute('id',"noteactionscript");
	appendTextNode(sNode,"*Please select the version of Actionscript used in your game. Your customized competition buttons will also use the version you select, so it is important that you select the correct version for compatibility.");
	pNode.appendChild(selectEle);
	appendBrNode(pNode);
	pNode.appendChild(sNode);
	appendBrNode(pNode);
	appendBrNode(pNode);

	// 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);
	pNode.appendChild(sNode);
	
	appendBrNode(pNode);

	containDiv.appendChild(pNode);

	// append the container to the form
	document.forms[0].appendChild(containDiv);

	// set up styles for IE
	if(whichBrowser == "IE") {
		document.getElementById("title").className='title';
		document.getElementById("description").className='description';
		document.getElementById("labelname").className='label';
		document.getElementById("notename").className='note';
		document.getElementById("labelemail").className='label';
		document.getElementById("labelshipping").className='label';
		document.getElementById("labelpaypal").className='label';
		document.getElementById("notepaypal").className='note';
		document.getElementById("labeltitle").className='label';
		document.getElementById("labelbyline").className='label';
		document.getElementById("notebyline").className='note';
		document.getElementById("labeldescription").className='label';
		document.getElementById("notedescription").className='note';
		document.getElementById("labelurl").className='label';
		document.getElementById("labelactionscript").className='label';
		document.getElementById("noteactionscript").className='note';
		document.getElementById("labelsubmit").className='button';
	}
}
var NUM_OBJECT_DESCRIPTORS = 2;			// used when calculating number of menu options
var ActionScriptMenu = new Object();
ActionScriptMenu.name = "actionscript";
ActionScriptMenu.desc = "Actionscript version*:";
ActionScriptMenu.label1 = "1.0";
ActionScriptMenu.label2 = "2.0";
ActionScriptMenu.label3 = "3.0";


$(document).ready(function(){
	init();
});
// -->