// JavaScript Document

//create a global variable that is blank
var letsgoto = "";
function display(q) {
	//set the global variable
	letsgoto = q;
	//display the login box
	var ob = document.getElementById("lbx").style;
	ob.display = (ob.display == 'block')?'none': 'block';
	//display the background
	var ob2 = document.getElementById("gauze").style;
	ob2.display = (ob.display == 'block')?'block': 'none';
}
function clearBox() {
	//reset the contents of the username box
	document.getElementById("username").value = "";
}
function letsGo(to) {
	//change the window location
	window.location=to;
}
function checkUser(n) {
	//create arrays with all possible letters and numbers (in this case, everything)
	var letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
	var numbers = ["0","1","2","3","4","5","6","7","8","9"];
	//set the accessGranted to 0 - anything under 6 is access denied
	var accessGranted = 0;
	//execute only if the length of the username is 6 characters long
	if (n.length==6) {
		//for the first three characters, make sure that it matches something in the letters array
		for (i=0;i<=2;i++) {
			//cross-check the letter with each item in the letters array
			for (j=0;j<=letters.length;j++) {
				//if the character matches an array item, add one point to accessGranted, then break the loop
				if (String(n.substr(i,1).toUpperCase())==String(letters[j])) {
					accessGranted+=1;
					break;
				} 
			}
		}
		//for the last three characters, make sure that it matches something in the numbers array
		for (m=3;m<=6;m++) {
			//cross-check the number with each item in the numbers array
			for (k=0;k<=letters.length;k++) {
				//if the character matches an array item, add one point to accessGranted, then break the loop
				if (String(n.substr(m,1))==String(numbers[k])) {
					accessGranted+=1;
					break;
				}
			}
		}
	} else {
		//otherwise, if the username is left blank, show an error message
		if (n==""){
			alert('Please enter your username');
		}
	}
	//if the accessGranted variable reaches 6, run the letsGo function and redirect the page
	if (accessGranted==6) {
		letsGo(letsgoto+"?u=y");
	} else {
		//otherwise, if the username is not blank and does not have an accessGranted value of 6, show an error message and clear the username box
		if (n!=="") {
			alert('That username is invalid.\nPlease try again.');
			clearBox();
		}
	}
}
