
// research.js
// Class Project for CS193C
// Created by David Trieu

	// Static Professor Array
	var researchArray = new Array(
		{name: "Andersen", chem: "yes", req: "yes", course: "Chem 175 and Comp. Sci. background", phone: "3-2711", place: "M185", email: "HCA@stanford.edu", field: "P"},
		{name: "Boxer", chem: "yes", req: "no", course: "", phone: "3-4482", place: "K325", email: "SBoxer@stanford.edu", field: "P/BP"},
		{name: "Brauman", chem: "yes", req: "no", course: "", phone: "3-3023", place: "M181", email: "Brauman@stanford.edu", field: "P/O"},
		{name: "Chidsey", chem: "yes", req: "no", course: "", phone: "5-1751", place: "S103A", email: "Chidsey@stanford.edu", field: "P/O"},
		{name: "Collman", chem: "yes", req: "no", course: "", phone: "5-0283", place: "SS201", email: "JCP@stanford.edu", field: "I/O"},
		{name: "Dai", chem: "yes", req: "no", course: "", phone: "3-4518", place: "S04", email: "HDai1@stanford.edu", field: "P"},
		{name: "Du Bois", chem: "yes", req: "no", course: "", phone: "4-4557", place: "M191", email: "jdubois@stanford.edu", field: "O"},
		{name: "Fayer", chem: "yes", req: "no", course: "", phone: "3-4446", place: "K113", email: "fayer@stanford.edu", field: "P"},
		{name: "Huestis", chem: "yes", req: "yes", course: "Chem 134", phone: "3-2053", place: "K337", email: "WHH@stanford.edu", field: "BP"},
		{name: "Khosla", chem: "yes", req: "no", course: "", phone: "3-6538", place: "K389", email: "khosla@stanford.edu", field: "BO"},
		{name: "Kohler", chem: "yes", req: "no", course: "", phone: "5-3527", place: "K337", email: "jjkohler@stanford.edu", field: "O"},
		{name: "Kool", chem: "yes", req: "no", course: "", phone: "4-4741", place: "S103", email: "Eric.Kool@stanford.edu", field: "BO"},
		{name: "Moerner", chem: "yes", req: "no", course: "", phone: "3-1727", place: "S15", email: "WMoerner@stanford.edu", field: "P"},
		{name: "Pande", chem: "yes", req: "yes", course: "Chem 175 and Comp. Sci. background", phone: "3-3660", place: "K315", email: "pande@stanford.edu", field: "P/BP"},
		{name: "Pecora", chem: "yes", req: "yes", course: "Chem 171 or 173 or Bio lab experience", phone: "3-0681", place: "SS106", email: "Pecora@stanford.edu", field: "P/BP"},
		{name: "Solomon", chem: "yes", req: "yes", course: "Chem 130", phone: "3-9104", place: "M141", email: "Edward.Solomon@stanford.edu", field: "I/P/BP"},
		{name: "Stack", chem: "yes", req: "yes", course: "Chem 130", phone: "5-8736", place: "SS104", email: "Stack@stanford.edu", field: "I/O"},
		{name: "Trost", chem: "yes", req: "no", course: "", phone: "3-3385", place: "M331", email: "BMTrost@stanford.edu", field: "O"},
		{name: "Waymouth", chem: "yes", req: "yes", course: "Chem 130", phone: "3-4515", place: "M191", email: "Waymouth@stanford.edu", field: "I/O"},
		{name: "Wender", chem: "yes", req: "no", course: "", phone: "3-0208", place: "M391", email: "WenderP@stanford.edu", field: "O"},
		{name: "Yandulov", chem: "yes", req: "no", course: "", phone: "5-9651", place: "SS102", email: "yandulov@stanford.edu", field: "I/P"},
		{name: "Zare", chem: "yes", req: "no", course: "", phone: "3-3062", place: "M133", email: "RNZ@stanford.edu", field: "P/A"},
		{name: "Bent", chem: "no", req: "no", course: "", phone: "3-0385", place: "SSS", email: "bent@chemeng.stanford.edu", field: "P"},
		{name: "Cimprich", chem: "no", req: "no", course: "", phone: "8-4720", place: "Clark W350B", email: "cimprich@stanford.edu", field: "BO"},
		{name: "Frank", chem: "no", req: "no", course: "", phone: "3-4573", place: "SSS", email: "curt@chemeng.stanford.edu", field: "P"},
		{name: "Herschlag", chem: "no", req: "no", course: "", phone: "3-2402", place: "BCB471a", email: "hershla@cmgm.stanford.edu", field: "BO"},
		{name: "Wandless", chem: "no", req: "no", course: "", phone: "3-4005", place: "Clark W350A", email: "wandless@stanford.edu", field: "BO"}
		);
		
	var newArray1 = new Array();
	var tempArray = new Array();
	var finalArray = new Array();
	
function initTable()
{	
	var names = new Array("professor0name","professor1name","professor2name","professor3name","professor4name","professor5name", "professor6name","professor7name","professor8name","professor9name","professor10name","professor11name","professor12name","professor13name","professor14name","professor15name","professor16name","professor17name","professor18name","professor19name","professor20name","professor21name","professor22name","professor23name","professor24name","professor25name","professor26name");
	
	for(var x = 0; x < names.length; x++)
	{
		var elem = new String(names[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].name;
	}
	
	var phonenumber = new Array("phonenum0","phonenum1","phonenum2","phonenum3","phonenum4","phonenum5","phonenum6","phonenum7","phonenum8","phonenum9","phonenum10","phonenum11","phonenum12","phonenum13","phonenum14","phonenum15","phonenum16","phonenum17","phonenum18","phonenum19","phonenum20","phonenum21","phonenum22","phonenum23","phonenum24","phonenum25","phonenum26");
	
	for(var x = 0; x < phonenumber.length; x++)
	{
		var elem = new String(phonenumber[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].phone;
	}
	
	var thelocation = new Array("building0","building1","building2","building3","building4","building5","building6","building7","building8","building9","building10","building11","building12","building13","building14","building15","building16","building17","building18","building19","building20","building21","building22","building23","building24","building25","building26");
	
	for(var x = 0; x < thelocation.length; x++)
	{
		var elem = new String(thelocation[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].place;
	}
	
	var theemail = new Array("email0","email1","email2","email3","email4","email5","email6","email7","email8","email9","email10","email11","email12","email13","email14","email15","email16","email17","email18","email19","email20","email21","email22","email23","email24","email25","email26");
	
	for(var x = 0; x < theemail.length; x++)
	{
		var elem = new String(theemail[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].email;
	}
	
	var thefield = new Array("field0","field1","field2","field3","field4","field5","field6","field7","field8","field9","field10","field11","field12","field13","field14","field15","field16","field17","field18","field19","field20","field21","field22","field23","field24","field25","field26");
	
	for(var x = 0; x < thefield.length; x++)
	{
		var elem = new String(thefield[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].field;
	}
	
	var requirements = new Array("requirements0","requirements1","requirements2","requirements3","requirements4","requirements5","requirements6","requirements7","requirements8","requirements9","requirements10","requirements11","requirements12","requirements13","requirements14","requirements15","requirements16","requirements17","requirements18","requirements19","requirements20","requirements21","requirements22","requirements23","requirements24","requirements25","requirements26");
	
	for(var x = 0; x < requirements.length; x++)
	{
		var elem = new String(requirements[x]);
		var tempname = document.getElementById(elem);
		tempname.innerHTML = researchArray[x].course;
	}
}


function update()
{
	
	var newArray1 = new Array();
	var tempArray = new Array();
	
	
	var cheminfo = document.getElementById("chem");
	var othersinfo = document.getElementById("others");
	var neitherinfo = document.getElementById("zero");
	
	if(cheminfo.checked)
	{
		// Professors under the Chemistry Dept.
		var count = 0;
		for(var a = 0; a < researchArray.length; a++)
		{
			if(researchArray[a].chem == cheminfo.value)
			{
				newArray1[count] = researchArray[a];
				count++;
			}
		}
		
		
		// Specific Field Search
		count = 0;
		
		if(document.getElementById("specific").value != 0)
		{
			var myspecific = new String(document.getElementById("specific").value);
			var specificField = myspecific.toUpperCase();
			
			
			for(var b = 0; b < newArray1.length; b++)
			{
				var thearea = new String(newArray1[b].field);
				var exists = thearea.indexOf(specificField);
				
				if(exists >= 0)
				{
					tempArray[count] = newArray1[b];
					count++;
				}
			}
			
			var newArray1 = tempArray;
		}
		
		
		// Final Array
		count = 0;
		var tempArray = new Array();
		
		finalArray = newArray1;
	}
	
	if(othersinfo.checked)
	{
		// Professors only associated with Chem. Dept.
		var count = 0;
		for(var a = 0; a < researchArray.length; a++)
		{
			if(researchArray[a].chem == othersinfo.value)
			{
				newArray1[count] = researchArray[a];
				count++;
			}
		}
		
		// Specific Field Search
		count = 0;
		
		if(document.getElementById("specific").value != 0)
		{
			var myspecific = new String(document.getElementById("specific").value);
			var specificField = myspecific.toUpperCase();
			
			for(var b = 0; b < newArray1.length; b++)
			{
				var thearea = new String(newArray1[b].field);
				var exists = thearea.indexOf(specificField);
				
				if(exists >= 0)
				{
					tempArray[count] = newArray1[b];
					count++;
				}
			}
			
			var newArray1 = tempArray;
		}
		
		// Final Array
		count = 0;
		var tempArray = new Array();
		
		finalArray = newArray1;
	}
	
	if(neitherinfo.checked || (cheminfo.checked == false && othersinfo.checked == false && neitherinfo.checked == false))
	{
		// Don't Care
		var count = 0;
		
		newArray1 = researchArray;
		
		// Specific Field Search
		count = 0;
		
		if(document.getElementById("specific").value != 0)
		{
			var myspecific = new String(document.getElementById("specific").value);
			var specificField = myspecific.toUpperCase();
			
			for(var b = 0; b < newArray1.length; b++)
			{
				var thearea = new String(newArray1[b].field);
				var exists = thearea.indexOf(specificField);
				
				if(exists >= 0)
				{
					tempArray[count] = newArray1[b];
					count++;
				}
			}
			
			var newArray1 = tempArray;
		}
		
		// Final Array
		count = 0;
		var tempArray = new Array();
		
		finalArray = newArray1;
	}
	
	neitherUpdate();
}


function neitherUpdate()
{
	var contactbox = document.getElementById("contactinfo");
	var fieldbox = document.getElementById("fieldinfo");
	var requirementsbox = document.getElementById("requirementsinfo");
	
		if(contactbox.checked == false && fieldbox.checked == false && requirementsbox.checked == false)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> </tr>";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + "</td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == true && fieldbox.checked == false && requirementsbox.checked == false)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> <th> Phone Number </th> <th> Bldg./Room* </th> <th> Email </th> </tr> ";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].phone + " </td> <td> " + finalArray[a].place + " </td> <td> " + finalArray[a].email + " </td> </tr> "; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == false && fieldbox.checked == true && requirementsbox.checked == false)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Name </th> <th> Field** </th> </tr>";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].field + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == false && fieldbox.checked == false && requirementsbox.checked == true)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Name </th> <th> Course Req. </th> </tr>";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].course + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == true && fieldbox.checked == true && requirementsbox.checked == false)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> <th> Phone Number </th> <th> Bldg./Room* </th> <th> Email </th> <th> Field** </th> </tr> ";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].phone + " </td> <td> " + finalArray[a].place + " </td> <td> " + finalArray[a].email + " </td> <td> " + finalArray[a].field + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == true && fieldbox.checked == false && requirementsbox.checked == true)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> <th> Phone Number </th> <th> Bldg./Room* </th> <th> Email </th> <th> Course Req. </th> </tr> ";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].phone + " </td> <td> " + finalArray[a].place + " </td> <td> " + finalArray[a].email + " </td> <td> " + finalArray[a].course + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == false && fieldbox.checked == true && requirementsbox.checked == true)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> <th> Field** </th> <th> Course Req. </th> </tr> ";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].field + " </td> <td> " + finalArray[a].course + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
		
		if(contactbox.checked == true && fieldbox.checked == true && requirementsbox.checked == true)
		{
			var displayCriteria = "<form id = 'information' action = ''> <table border = 'border' class = 'main'> <tr> <th> Professor </th> <th> Phone Number </th> <th> Bldg./Room* </th> <th> Email </th> <th> Field** </th> <th> Course Req. </th> </tr> ";
			
			for(var a = 0; a < finalArray.length; a++)
			{
				displayCriteria += "<tr> <td> " + finalArray[a].name + " </td> <td> " + finalArray[a].phone + " </td> <td> " + finalArray[a].place + " </td> <td> " + finalArray[a].email + " </td> <td> " + finalArray[a].field + " </td> <td> " + finalArray[a].course + " </td> </tr>"; 
			}
			
			displayCriteria += "</table> </form>";
			
			var updatedTable = document.getElementById("professors");
			updatedTable.innerHTML = displayCriteria;
		}
}

