//use these arrays to help validate data.
var numbers = "0123456789";
var lowerCase = 'abcdefghijklmnopqrstuvwxyz';
var upperCase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

//some validation functions.
function isValid(param, val)
{
	if(param == "") return true;
	for(i=0; i<param.length; ++i)
	{
		if(val.indexOf(param.charAt(i), 0) == -1) return false;
	}
	return true;
}

function isDigit(param) 
{
	return isValid(param, numbers);
}

function isAlpha(param) 
{
	return isValid(param, lowerCase+upperCase+numbers);
}

//check to make sure that all of the data is filled out before we submit
function ValidateUserData(form)
{
	var canSubmit = true;
	var misMatchedEmail = false;
	var isAgeDigits = true;
	
	//check to make sure all the blanks are filled.
	if(document.downloadForm.firstName.value == "") { canSubmit = false; }
	if(document.downloadForm.lastName.value == "") { canSubmit = false; }
	if(document.downloadForm.age.value == "") { canSubmit = false; }
	if(document.downloadForm.email.value == "") { canSubmit = false; }
	if(document.downloadForm.emailverify.value == "") { canSubmit = false; }
	
	//check to see if the digits in the zipcode are all digits.

	var age = document.downloadForm.age.value;	
	if(!isDigit(age))
	{
		isAgeDigits = false;
	}
	
	//check to make sure that the password and the re-entered password are the same.
	if(document.downloadForm.email.value != document.downloadForm.emailverify.value)
	{
		misMatchedEmail = true;
	}
	
	if(misMatchedEmail == true)
	{
		alert("ERROR: Cannont submit form. Your e-mail address is incorrect.");
	}
	else if(isAgeDigits == false)
	{
		alert("ERROR: Cannot submit form. Please enter a valid age.");	
	}
	else if(canSubmit == false)
	{
		alert("ERROR: Cannot submit form. Please fill in all of the data before submitting");
	}
	else if((canSubmit == true) && (misMatchedEmail == false))
	{
		//store the "how did you find out about this game" info encoded as one word.
		document.downloadForm.findoutvar.value = document.downloadForm.findout.value;

		//store a 1 or 0 for recieving updates.
		if(document.downloadForm.getupdates.checked)
			document.downloadForm.bgetupdates.value='t';
		else
			document.downloadForm.bgetupdates.value='f';
		
		form.submit();
	}
}

