// JavaScript Document

    function Student(firstName, lastName, email, program, studentStatus, project, nthYear) {
		this.firstName = firstName;
		this.lastName = lastName;
		this.email = email;
		this.program = program;
		this.studentStatus = studentStatus;
		this.project = project;
		this.nthYear = nthYear;
		// this.website = website;
    }
	
	function Project(type, title) {
		this.type = type;
		this.title = title;
	}


    function getProgramDescription(desc) {
		
        switch (desc) {
			 case "a-mstMasters":  return("M.A. in Music, Science, & Technology");
			 case "phdMusico":  return("Ph.D. in Musicology");
			 case "phdCBMTA": return("Ph.D. in Computer-Based Music Theory and Acoustics");
			 case "compDMA": return("D.M.A. in Composition");
			 case "z-alum": return("Recent Music Department Alums") ;
			
		}
	}

    function createGradDirectory(dir) {
		initProgram = "";
		
		document.writeln('<table cellspacing="0" border="1" cellpadding="0" style="clear: left;">');
		for (var i = 0; i < dir.length; i++) {
			var currProgram = dir[i].program;
			if (currProgram != initProgram) {
				document.writeln('<tr><th colspan="4" class="head"><h2>' + getProgramDescription(dir[i].program) + '</h2></th></tr>')
				
				if (currProgram == "z-alum") { 
				    document.writeln('<tr><th>student</th>' + '<th>email</th>' + '<th width="20">&nbsp;</th>' + '<th>project</th>');
				} else {
				    document.writeln('<tr><th>student</th>' + '<th>email</th>' + '<th width="20" style="text-align: center;">status</th>' + '<th>project</th>');
				}
				initProgram = currProgram;
			}
			
			if (i % 2 == 0) { document.writeln('<tr style="background-color: #D7C39A;">');
			} else { document.writeln('<tr style="background-color: #EBE6D2;">'); }
			
			document.writeln('<td>');
			document.writeln(dir[i].firstName + ' ' + dir[i].lastName);
			document.writeln('</td><td>');
			(dir[i].email != "") ? document.writeln('<a href="mailto:' + dir[i].email + '"' + ' title="' + dir[i].email + '">' + getEmailString(dir[i].email) + '</a>') : document.write('&nbsp');
			document.writeln('</td><td style="text-align: center;">');
			(dir[i].studentStatus != "") ? document.write(dir[i].studentStatus) : document.write('&nbsp;');
			document.writeln('</td><td>');
			(dir[i].project != "") ? document.write('<b>' + dir[i].project.type + '</b> &ndash; ' + dir[i].project.title) : document.write('&nbsp;');
			document.writeln('</td></tr>');

		}
		document.writeln('</table>');
	}


	function getEmailString(email) {
		     
			 var ccrmaSuffix = email.search(/@ccrma\.stanford\.edu/);
			 var stanfordSuffix = email.search(/@stanford\.edu/);

			 if (ccrmaSuffix > 0) {
				 return (email.replace(/@ccrma\.stanford\.edu/, "@ccrma"));
			 } else if (stanfordSuffix > 0) {
		         return (email.replace(/@stanford\.edu/, "@stanford"));
			 } else {
			   return (email);
			 }
		
	}