var peopleFieldArray = [["sixtyInchRound","*12","499","100001"],["seventyTwoInchRound","*13","499","100001"],["reception","*9.5","499","100001"],["eighteenInchTables","*15","499","100001"],["thirtyInchTables","*18","499","100001"],["theatre","*10","499","100001"],["eightByTenExhibits","*160","159","100001"],["tenByTenExhibits","*200","159","100001"]];		
var squareFeetFieldArray = [["sixtyInchRound","/12","41","8334"],["seventyTwoInchRound","/13","37","7693"],["reception","/9.5","52","10527"],["eighteenInchTables","/15","32","6668"],["thirtyInchTables","/18","27","5557"],["theatre","/10","49","10001"],["eightByTenExhibits","/160","9","626"],["tenByTenExhibits","/200","7","501"]];

function CalculatePeople(field) {
	for(var x=0,y;y=peopleFieldArray[x];x++) {
		eval("function "+y[0]+"() {if(this.field"+y[1]+"<"+y[3]+" && this.field"+y[1]+">"+y[2]+") {return Math.round(this.field"+y[1]+")+\" square feet\";} else {return \"N/A\";}}");
		eval("this."+y[0]+"="+y[0]+";");
	}
	this.field = field.replace(",","");
}

function CalculateSquareFeet(field) {
	for(var x=0,y;y=squareFeetFieldArray[x];x++) {
		eval("function "+y[0]+"() {if(this.field"+y[1]+"<"+y[3]+" && this.field"+y[1]+">"+y[2]+") {return (Math.round(this.field"+y[1]+")+\" occupants\");} else {return \"N/A\";}}");
		eval("this."+y[0]+"="+y[0]+";");
	}
	this.field = field.replace(",","");
}		 

function Main() {	

	var people = document.getElementById("people");
	var squareFeet = document.getElementById("squareFeet");
	
	people.value = "Enter a number";
	squareFeet.value = "Enter a number";
	
	people.onblur = function() {if(people.value=="") {people.value="Enter a number"}}
	people.onfocus = function() {squareFeet.value = "Enter a number"; if(people.value=="Enter a number") {people.value=""}}
	
	squareFeet.onblur = function() {if(squareFeet.value=="") {squareFeet.value="Enter a number"}}
	squareFeet.onfocus = function() {people.value = "Enter a number"; if(squareFeet.value=="Enter a number") {squareFeet.value=""}}
	
	people.onkeyup = function() {
			var calc = new CalculatePeople(this.value);
			for(var x=0,y;y=peopleFieldArray[x];x++) {
				document.getElementById(y[0]).value = eval("calc."+y[0]+"()");
				document.getElementById(y[0]).size = eval("\""+document.getElementById(y[0]).value.length+"\"");
		}
	}

	squareFeet.onkeyup = function() {
			var calc = new CalculateSquareFeet(this.value);
			for(var x=0,y;y=squareFeetFieldArray[x];x++) {
				document.getElementById(y[0]).value = eval("calc."+y[0]+"()");
				document.getElementById(y[0]).size = eval("\""+document.getElementById(y[0]).value.length+"\"");
		}
	}		
}

window.onload = Main;
