function populateJoshsFields(someForm) {
	//** Figure out what the operating system is **//

	thisFullVersion = navigator.appVersion.toUpperCase();
	
	thisOS = "UNKNOWN";
	if (thisFullVersion.indexOf("WIN95") != -1) { thisOS = "win95"; }
	if (thisFullVersion.indexOf("WIN 95") != -1) { thisOS = "win95"; }
	if (thisFullVersion.indexOf("WINDOWS 95") != -1) { thisOS = "win95"; }
	if (thisFullVersion.indexOf("WIN98") != -1) { thisOS = "win98"; }
	if (thisFullVersion.indexOf("WIN 98") != -1) { thisOS = "win98"; }
	if (thisFullVersion.indexOf("WINDOWS 98") != -1) { thisOS = "win98"; }
	if (thisFullVersion.indexOf("WIN16") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("MAC") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("X11") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("WINNT") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("WIN NT") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("WINDOWS NT") != -1) { thisOS = "other"; }
	if (thisFullVersion.indexOf("WINNT5") != -1) { thisOS = "win2K"; }
	if (thisFullVersion.indexOf("WIN NT 5") != -1) { thisOS = "win2K"; }
	if (thisFullVersion.indexOf("WINDOWS NT 5") != -1) { thisOS = "win2K"; }
	if (thisFullVersion.indexOf("WINXP") != -1) { thisOS = "winXP"; }
	if (thisFullVersion.indexOf("WIN XP") != -1) { thisOS = "winXP"; }
	if (thisFullVersion.indexOf("WINDOWS XP") != -1) { thisOS = "winXP"; }
	if (thisFullVersion.indexOf("WINDOWS 5.1") != -1) { thisOS = "winXP"; }
	if (thisFullVersion.indexOf("WINDOWS NT 5.1") != -1) { thisOS = "winXP"; }
	if (thisFullVersion.indexOf("WINNT5.2") != -1) { thisOS = "win2K3"; }
	if (thisFullVersion.indexOf("WIN NT 5.2") != -1) { thisOS = "win2K3"; }
	if (thisFullVersion.indexOf("WINDOWS NT 5.2") != -1) { thisOS = "win2K3"; }
	
	someForm.winVer.value = thisOS;
	

	//** Figure out the resolution
	myResolution = oClientCaps.width + "x" + oClientCaps.height;

	someForm.monitorResolution.value = myResolution;
	
	
	//** Figure out the color dept
	myColorDepth = oClientCaps.colorDepth;

	someForm.colorDepth.value = myColorDepth;

	
	
	//** Figure out the connection speed
	myConnectionSpeed = oClientCaps.connectionType;
	if (myConnectionSpeed == "lan") {
		someForm.highSpeedInet.value = "1";
	} else {
		someForm.highSpeedInet.value = "0";
	}
	
	//** Figure out the user agent
	someForm.userAgent.value = navigator.userAgent;
}


function getFormElementsFrom(someElement) {
	// create a temporary array to keep the form elements in
	var theFormElements = new Array()
	
	// for each form element in this form
	for (var counter = 0; counter < someElement.length; counter++) {
		// if the required attribute is set to true
//		if (someElement[counter].getAttribute("required") != "brue") {
			// if the field has a type 
			if (someElement[counter].type) {
				// if that type isnt hidden, add the field
				if (someElement[counter].type.toUpperCase() != "HIDDEN") {
					theFormElements[theFormElements.length] = someElement[counter];
				}
			} else { // or if the field has no type
				// add the element to the temporary array
				theFormElements[theFormElements.length] = someElement[counter];
			}
		//}
	}

	// return the array
	return theFormElements;
}

//function to check valid email address 
function isValidEmail(strEmail) { 
   var regNotValid = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid 
   var regValid = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid 


   // search email text for regular exp matches 
    if (regNotValid.test(strEmail) || !regValid.test(strEmail) || strEmail.indexOf(' ') > -1)  
   { 
      return false; 
    } 
    return true; 
} 

function checkRequiredFields(thisForm) {
	// create an array to store the list of required fields
	var childrenToCheck = new Array();
	// populate that array with references to each form field in this form that has required="true"
	childrenToCheck = getFormElementsFrom(thisForm);

	//populate josh's requested fields
	populateJoshsFields(thisForm);

	// loop through the form fields in the array
	for (index = 0; index < childrenToCheck.length; index++) {
		thisElement = childrenToCheck[index];
		// if the current element has no value
		if (thisElement.value == "" || (thisElement.name == "email" && !isValidEmail(thisElement.value))) {
			// alert the error message associated with this field
			if (thisElement.getAttribute("errorMessage")) { 
				alert(thisElement.getAttribute("errorMessage"));
			} else {
				alert("You must provide an answer to all questions.");
			}
			
			// put the cursor into the field
			thisElement.focus();
			
			// dont allow the form to submit
			return false;


		} 
	}
	
	// if its gone through the entire form then allow the form to submit
	return true;
}


/* ############################################################## */
/* ##############           STAGE 1 SPECIFIC        ############# */
/* ############################################################## */

function hideAllDivs() {
	document.getElementById("intro_DIV").style.display = "none";
	document.getElementById("comments_DIV").style.display = "none";
	document.getElementById("gameProblem_DIV").style.display = "none";
	document.getElementById("siteProblem_DIV").style.display = "none";
	document.getElementById("paymentProblem_DIV").style.display = "none";
	document.getElementById("buyingProblem_DIV").style.display = "none";
	document.getElementById("regkeyProblem_DIV").style.display = "none";
	document.getElementById("lostKey_DIV").style.display = "none";
	document.getElementById("refund_DIV").style.display = "none";
	document.getElementById("cdorder_DIV").style.display = "none";
	document.getElementById("lostKey_DIV_ORIGINAL").style.display = "none";
}

function showTheDiv() {
	theSelect = document.getElementById("categorySel");
	divToShow = theSelect.options[theSelect.selectedIndex].value;
	if (! (divToShow == "")) {
		// update the last selected index;
		lastSelectIndex = theSelect.selectedIndex;
	
		// hide all the existing divs
		hideAllDivs();
		
		// show the right div
		if (divToShow == "cdproblem"){ 
			document.getElementById("gameProblem_DIV").style.display = "block";
		} else if (divToShow == "cdnoshow") {
			document.getElementById("buyingProblem_DIV").style.display = "block";
		} else {
			document.getElementById(divToShow + "_DIV").style.display = "block";
		}
		
		// set the correct hidden variables
		setHiddenVariables(divToShow);
		// clear the required fields array and repopulate for this category
		//requiredFields = new Array();
		//setRequiredFields(divToShow);
	} else {
		// reselect the last selected
		if ( ! (lastSelectIndex == -1) ) {
			theSelect.options[lastSelectIndex].selected = true;
		}
	}
}

function setRequiredFields(divToShow) {	
	
	switch(divToShow) {
		case "comments":
			requiredFields[0] = "commentEmail";
			requiredFields[1] = "commentText";
		break;
		
		case "gameProblem":
			requiredFields[0] = "gameProblemEmail";
			requiredFields[1] = "gameProblemGame";
			requiredFields[2] = "gameProblemText";
		break;		
		
		default:
			alert("not comments");
		break;
		
	}
}

// new function added at joshua's request 5-23-2005
function setHiddenVariables(categoryValue) {
	if (categoryValue == "cdproblem") {
		// set the gameProblem hidden field to "cdproblem"
		document.getElementById("gameProblemSubmissionType").value = "cdproblem";
	}
	
	if (categoryValue == "gameProblem") {
		// set the gameProblem hidden field to "gameProblem"
		document.getElementById("gameProblemSubmissionType").value = "gameProblem";
	}

	if (categoryValue == "cdnoshow") {
		// set the buyingProblem hidden field to "cdnoshow"
		document.getElementById("buyingProblemSubmissionType").value = "cdnoshow";
	}

	if (categoryValue == "buyingProblem") {
		// set the buyingProblem hidden field to "buyingProblem"
		document.getElementById("buyingProblemSubmissionType").value = "buyingProblem";
	}
}