// JavaScript Document

	// gradStudents.html
	function sortByProgram(profile1, profile2) {
		     var p1 = profile1.program;
			 var p2 = profile2.program;
			 return((p1 < p2) ? -1 : ((p1 > p2) ? 1 : sortByNthYear(profile1, profile2)));
		
	}
	
	function sortByNthYear(profile1, profile2) {
	         var y1 = profile1.nthYear;
			 var y2 = profile2.nthYear;
			 return((y1 < y2) ? -1 : ((y1 > y2) ? 1 : sortByLastFirst(profile1, profile2)));
	}
	
	// gradStudents.html, faculty.html, and facultyAlpha.html
	function sortByLastFirst(profile1, profile2) {
	         var ln1 = profile1.lastName.toLowerCase();
			 var ln2 = profile2.lastName.toLowerCase();
	         return((ln1 < ln2) ? -1 : ((ln1 > ln2) ? 1 : sortByFirstName(profile1, profile2)));  
	}
	function sortByFirstName(profile1, profile2) {
	         var fn1 = profile1.firstName.toLowerCase();
			 var fn2 = profile2.firstName.toLowerCase();
			 return((fn1 < fn2) ? -1 : ((fn1 > fn2) ? 1 : 0 )); 
	}
	
	
	// calendar.html
	
	function sortCalendar(cal1, cal2) {
		     var y1 = cal1.date.year;
		     var y2 = cal2.date.year;
		     return ((y1 < y2) ? -1 : ((y1 > y2) ? 1 : sortByMonth(cal1, cal2)));
	}
	
	function sortByMonth(cal1, cal2) {
		     var m1 = cal1.date.month;
		     var m2 = cal2.date.month;
		     return ((m1 < m2) ? -1 : ((m1 > m2) ? 1 : sortByDay(cal1, cal2)));
	}
	
	function sortByDay(cal1, cal2) {
		     var d1 = parseInt(cal1.date.day);
		     var d2 = parseInt(cal2.date.day);
		     return ((d1 < d2) ? -1 : ((d1 > d2) ? 1 : sortByHour(cal1, cal2)));
	}
	
	function sortByHour(cal1, cal2) {
		     // "10:00pm"
			 // split returns ["10", "00 pm"];
			 
			 var t1 = cal1.date.time;
		     var t2 = cal2.date.time;
			 
			 var h1 = parseInt(t1.split(":")[0]); // returns the hour number to the left of the colon 
			 var h2 = parseInt(t2.split(":")[0]); // 
			 
			 var ampm1 = t1.split(":")[1].split(" ")[1];  // first split returns the minutes mm pm, second split returns --> pm or am"
			 var ampm2 = t1.split(":")[1].split(" ")[1];
			 
			 if (ampm1 == "pm") { h1 += 12; }
			 if (ampm2 == "pm") { h2 += 12; }
			 
		     return ((h1 < h2) ? -1 : ((h1 > h2) ? 1 : 0));
	}
	
