// JavaScript Document

window.onload = initAll;

function initAll() {
	document.forms[0].onsubmit = getSillyName;
	}
	
function getSillyName() {
	document.getElementById("message").innerHTML = getSillyNameString();
	return false;
	}
	
function getSillyNameString () {
	var firstName = new Array ("Salty","Mugsy","Smokey","Big D","Sparky","Rock","Beauty","Campy","Scoops","Lefty","Happy Jack","Cha-cha","Jocko","Pudge","Lippy","Biscuit Pants","Goofy","Red","Catfish","Rajah","Stonewall","Fergie","Honest Joe","Nap","Cakes","Ducky");
							
	var lastName1 = new Array ("\"The Kid\"","\"The Say Hey Kid\"","\"The Ignitor\"","\"The Man\"","\"The Old Fox\"","\"The Meal Ticket\"","\"The Big Train\"","\"The Beast\"","\"The Big Cat\"","\"The Little Colonel\"","\"The Little General\"","\"The Mahatma\"","\"The Thunderbolt\"","\"The Bambino\"","\"The Silver Fox\"","\"The Wizard\"","\"The Sultan of Swat\"","\"The Boss\"","\"The Flying Dutchman\"","\"The Chief\"","\"The Natural\"","\"El Duque\"","\"The Professor\"","\"The Golden\"","\"Ol' Dirty Right Knee\"","\"Black Cat\"");
	var firstNm = document.getElementById("first_name").value.toUpperCase();
	var lastNm = document.getElementById("mid_name").value.toUpperCase();
	var validName = true;
	
	if (firstNm == "") {
		validName = false;
		}
	else {
		var firstNum = firstNm.charCodeAt(0) - 65;
		if (firstNum < 0 || firstNum > 25) {
			validName = false;
			}
		}
		
	if (!validName) {
		document.getElementById("first_name").focus();
		document.getElementById("first_name").select();
		return "That's not a valid first name.";
		}
		
	if (lastNm == "") {
		validName = false;
		}
		
	else {
		var lastNum1 = lastNm.charCodeAt(0) - 65;
		if (lastNum1 < 0 || lastNum1 > 25) {
			validName = false;
			}
		}
	if (!validName) {
		document.getElementById("mid_name").focus();
		document.getElementById("mid_name").select();
		return "That's not a valid middle name.";
		}
	
	var lastName2 = document.getElementById("last_name").value;
	return "Your Kickball Nickname Is: " + firstName[firstNum] + " " + lastName1[lastNum1] + " " + lastName2;
	}
	
	
