function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consetrimive spaces and replaces it with one space.
   var returnValues = inputString;
   var ch = returnValues.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
	  returnValues = returnValues.substring(1, returnValues.length);
	  ch = returnValues.substring(0, 1);
   }
   ch = returnValues.substring(returnValues.length-1, returnValues.length);
   while (ch == " ") { // Check for spaces at the end of the string
	  returnValues = returnValues.substring(0, returnValues.length-1);
	  ch = returnValues.substring(returnValues.length-1, returnValues.length);
   }
   while (returnValues.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
	  returnValues = returnValues.substring(0, returnValues.indexOf("  ")) + returnValues.substring(returnValues.indexOf("  ")+1, returnValues.length);
   }
   return returnValues; // Return the trimmed string back to the user
}

function validateForm(theForm){
	if(theForm.console){
		//validate the sate
		if(theForm.console.selectedIndex=="0"){
			alert("Please Select a Console.");
			theForm.console.focus();
			return false;
		}
	}

	if(theForm.title){
		if(trim(theForm.title.value) == ""){
			alert("Please Enter a Game Title.");
			theForm.title.focus();
			return false;
		}else{
			theForm.title.value = trim(theForm.title.value);
		}
	}

	/*
	if(theForm.publisher){
		if(trim(theForm.publisher.value) == ""){
			alert("Please Enter a Publisher Name.");
			theForm.publisher.focus();
			return false;
		}else{
			theForm.publisher.value = trim(theForm.publisher.value);
		}
	}
	*/
	
	if(theForm.genre){
		if(trim(theForm.genre.value) == ""){
			alert("Please Enter a Genre.");
			theForm.genre.focus();
			return false;
		}else{
			theForm.genre.value = trim(theForm.genre.value);
		}
	}
	
	if(theForm.searchFor){
		if(trim(theForm.searchFor.value) == ""){
			alert("Please Enter a Search Term.");
			theForm.searchFor.focus();
			return false;
		}else{
			theForm.searchFor.value = trim(theForm.searchFor.value);
		}
	}
	
	if(theForm.releaseYear){
		if(trim(theForm.releaseYear.length) != 4){
			alert("Please Enter a Release Year.");
			theForm.releaseYear.focus();
			return false;
		}else{
			theForm.releaseYear.value = trim(theForm.releaseYear.value);
		}
	}
	
	if(theForm.toChange){
		if(trim(theForm.toChange.value) == ""){
			alert("Please tell us what is wrong with the current entry data.");
			theForm.toChange.focus();
			return false;
		}else{
			theForm.toChange.value = trim(theForm.toChange.value);
		}
	}
	
	if(theForm.ReviewTitle){
		if(trim(theForm.ReviewTitle.value) == ""){
			alert("Please enter a title for your review.");
			theForm.ReviewTitle.focus();
			return false;
		}else if(trim(theForm.ReviewTitle.length) > 50){
			alert("Please limit the length of your review title to 50 characters.");
			theForm.ReviewTitle.focus();
			return false;
		}else{
			theForm.ReviewTitle.value = trim(theForm.ReviewTitle.value);
		}
	}
	
	if(theForm.ReviewText){
		if(trim(theForm.ReviewText.value) == ""){
			alert("Please enter the text for your review.");
			theForm.ReviewText.focus();
			return false;
		}else if(trim(theForm.ReviewText.length) > 10000){
			alert("Please limit the length of your review text to 10,0000 characters.");
			theForm.ReviewText.focus();
			return false;
		}else{
			theForm.ReviewText.value = trim(theForm.ReviewText.value);
		}
	}
	
	if(theForm.ReviewScore){
		if(trim(theForm.ReviewScore.value) == ""){
			alert("Please enter a score, it can be in any format you wish.");
			theForm.ReviewScore.focus();
			return false;
		}else{
			theForm.ReviewScore.value = trim(theForm.ReviewScore.value);
		}
	}
	
	if(theForm.ReviewScore2){
		if(trim(theForm.ReviewScore2.value) == ""){
			alert("Please enter a score, it can be in any format you wish.");
			theForm.ReviewScore2.focus();
			return false;
		}else{
			theForm.ReviewScore2.value = trim(theForm.ReviewScore2.value);
		}
	}
	
	return true;
}


//Status Bar 

function clearLoginUsername(loginForm){
	if (loginForm.value == 'username'){
		loginForm.value = '';
	}
}

function restoreLoginUsername(loginForm){
	if (loginForm.value == ''){
		loginForm.value = 'username';
	}
}
/*

function clearLoginPassword(loginForm){			
	if (loginForm.value == 'password'){
		loginForm.value = '';
		loginForm.type = "password";
	}
}
function restoreLoginPassword(loginForm){
	if (loginForm.value == ''){
		loginForm.value = 'password';
		loginForm.type = "input";
	}
}
*/
//Status Bar End
