var SD_ProgramsXmlFilePath = "/programs/browse.xml";
var SD_ProgramOptionsRenderOutput;
var shoreline_data_sb = "";




/* *************************************************************
Name   : LoadShorelineData
Purpose: Look for SHoreline Data elements on page and, if found,
       : run scripts to populate from college data
Inputs : 
Returns: void
Author : Gavin Smith
Created: 08/15/2017
Modified by:
Modification:
************************************************************ */
function LoadShorelineData()
{
	try
	{
		//--- IE StartsWith PolyFill
		if (!String.prototype.startsWith) {
			String.prototype.startsWith = function(searchString, position){
			  position = position || 0;
			  return this.substr(position, searchString.length) === searchString;
		  };
		}

		if ($("#shoreline-data-employee-get-firstname").length) // True if object exists
		{
			var FirstName = $("#shoreline-data-employee-get-firstname").val();
			var LastName = $("#shoreline-data-employee-get-lastname").val();

			$.getJSON('https://app.shoreline.edu/ShorelineWebAPIs/api/employee-from-name/' + FirstName + '/' + LastName)
				.done(function (data) {

				$(".shoreline-data-employee-put-advisorid").html(data.AdvisorID);
				$(".shoreline-data-employee-put-colleges").html(data.Colleges);
				$(".shoreline-data-employee-put-communityinvolvement").html(data.CommunityInvolvement);
				$(".shoreline-data-employee-put-currentquarter").html(data.CurrentQuarterName);
				$(".shoreline-data-employee-put-currentquarterofficehours").html(data.CurrentQuarterOfficeHours);
				$(".shoreline-data-employee-put-degrees").html(data.Degrees);
				$(".shoreline-data-employee-put-division").html(data.Division);
				$(".shoreline-data-employee-put-divisionphone").html(data.DivisionPhone);
				$(".shoreline-data-employee-put-emplid").html(data.EmplID);
				$(".shoreline-data-employee-put-employeestatus").html(data.EmployeeStatus);
				$(".shoreline-data-employee-put-employeetype").html(data.EmployeeType);
				$(".shoreline-data-employee-put-firstname").html(data.FirstName);
				$(".shoreline-data-employee-put-jobtitle").html(data.JobTitle);
				$(".shoreline-data-employee-put-languages").html(data.Languages);
				$(".shoreline-data-employee-put-lastname").html(data.LastName);
				$(".shoreline-data-employee-put-login").html(data.Login);
				$(".shoreline-data-employee-put-name").html(data.Name);
				$(".shoreline-data-employee-put-officehoursfall").html(data.OfficeHoursFall);
				$(".shoreline-data-employee-put-officehoursspring").html(data.OfficeHoursSpring);
				$(".shoreline-data-employee-put-officehourssummer").html(data.OfficeHoursSummer);
				$(".shoreline-data-employee-put-officehourswinter").html(data.OfficeHoursWinter);
				$(".shoreline-data-employee-put-phone").html(data.Phone);
				$(".shoreline-data-employee-put-room").html(data.Room);
				$(".shoreline-data-employee-put-url").html(data.URL);
				$(".shoreline-data-employee-put-workemail").html(data.WorkEmail);
			})           
		}

		if ($("#shoreline-data-employee-2-get-firstname").length) // True if object exists
		{
			var FirstName2 = $("#shoreline-data-employee-2-get-firstname").val();
			var LastName2 = $("#shoreline-data-employee-2-get-lastname").val();

			$.getJSON('https://app.shoreline.edu/ShorelineWebAPIs/api/employee-from-name/' + FirstName2 + '/' + LastName2)
				.done(function (data) {

				$(".shoreline-data-employee-2-put-advisorid").html(data.AdvisorID);
				$(".shoreline-data-employee-2-put-colleges").html(data.Colleges);
				$(".shoreline-data-employee-2-put-communityinvolvement").html(data.CommunityInvolvement);
				$(".shoreline-data-employee-2-put-currentquarter").html(data.CurrentQuarterName);
				$(".shoreline-data-employee-2-put-currentquarterofficehours").html(data.CurrentQuarterOfficeHours);
				$(".shoreline-data-employee-2-put-degrees").html(data.Degrees);
				$(".shoreline-data-employee-2-put-division").html(data.Division);
				$(".shoreline-data-employee-2-put-divisionphone").html(data.DivisionPhone);
				$(".shoreline-data-employee-2-put-emplid").html(data.EmplID);
				$(".shoreline-data-employee-2-put-employeestatus").html(data.EmployeeStatus);
				$(".shoreline-data-employee-2-put-employeetype").html(data.EmployeeType);
				$(".shoreline-data-employee-2-put-firstname").html(data.FirstName);
				$(".shoreline-data-employee-2-put-jobtitle").html(data.JobTitle);
				$(".shoreline-data-employee-2-put-languages").html(data.Languages);
				$(".shoreline-data-employee-2-put-lastname").html(data.LastName);
				$(".shoreline-data-employee-2-put-login").html(data.Login);
				$(".shoreline-data-employee-2-put-name").html(data.Name);
				$(".shoreline-data-employee-2-put-officehoursfall").html(data.OfficeHoursFall);
				$(".shoreline-data-employee-2-put-officehoursspring").html(data.OfficeHoursSpring);
				$(".shoreline-data-employee-2-put-officehourssummer").html(data.OfficeHoursSummer);
				$(".shoreline-data-employee-2-put-officehourswinter").html(data.OfficeHoursWinter);
				$(".shoreline-data-employee-2-put-phone").html(data.Phone);
				$(".shoreline-data-employee-2-put-room").html(data.Room);
				$(".shoreline-data-employee-2-put-url").html(data.URL);
				$(".shoreline-data-employee-2-put-workemail").html(data.WorkEmail);
			})           
		}

		if ($("#shoreline-data-employee-3-get-firstname").length) // True if object exists
		{
			var FirstName3 = $("#shoreline-data-employee-3-get-firstname").val();
			var LastName3 = $("#shoreline-data-employee-3-get-lastname").val();

			$.getJSON('https://app.shoreline.edu/ShorelineWebAPIs/api/employee-from-name/' + FirstName3 + '/' + LastName3)
				.done(function (data) {

				$(".shoreline-data-employee-3-put-advisorid").html(data.AdvisorID);
				$(".shoreline-data-employee-3-put-colleges").html(data.Colleges);
				$(".shoreline-data-employee-3-put-communityinvolvement").html(data.CommunityInvolvement);
				$(".shoreline-data-employee-3-put-currentquarter").html(data.CurrentQuarterName);
				$(".shoreline-data-employee-3-put-currentquarterofficehours").html(data.CurrentQuarterOfficeHours);
				$(".shoreline-data-employee-3-put-degrees").html(data.Degrees);
				$(".shoreline-data-employee-3-put-division").html(data.Division);
				$(".shoreline-data-employee-3-put-divisionphone").html(data.DivisionPhone);
				$(".shoreline-data-employee-3-put-emplid").html(data.EmplID);
				$(".shoreline-data-employee-3-put-employeestatus").html(data.EmployeeStatus);
				$(".shoreline-data-employee-3-put-employeetype").html(data.EmployeeType);
				$(".shoreline-data-employee-3-put-firstname").html(data.FirstName);
				$(".shoreline-data-employee-3-put-jobtitle").html(data.JobTitle);
				$(".shoreline-data-employee-3-put-languages").html(data.Languages);
				$(".shoreline-data-employee-3-put-lastname").html(data.LastName);
				$(".shoreline-data-employee-3-put-login").html(data.Login);
				$(".shoreline-data-employee-3-put-name").html(data.Name);
				$(".shoreline-data-employee-3-put-officehoursfall").html(data.OfficeHoursFall);
				$(".shoreline-data-employee-3-put-officehoursspring").html(data.OfficeHoursSpring);
				$(".shoreline-data-employee-3-put-officehourssummer").html(data.OfficeHoursSummer);
				$(".shoreline-data-employee-3-put-officehourswinter").html(data.OfficeHoursWinter);
				$(".shoreline-data-employee-3-put-phone").html(data.Phone);
				$(".shoreline-data-employee-3-put-room").html(data.Room);
				$(".shoreline-data-employee-3-put-url").html(data.URL);
				$(".shoreline-data-employee-3-put-workemail").html(data.WorkEmail);
			})           
		}

		if ($("#shoreline-data-division-get-id").length) // True if object exists
		{
			var DivisionID = $("#shoreline-data-division-get-id").val();

			$.getJSON('https://app.shoreline.edu/ShorelineWebAPIs/api/division-from-id/' + DivisionID)
				.done(function (data) {

				$(".shoreline-data-division-put-divisionid").html(data.DivisionID);
				$(".shoreline-data-division-put-divisiontext").html(data.DivisionText);
				$(".shoreline-data-division-put-email").html(data.Email);
				$(".shoreline-data-division-put-leadername").html(data.LeaderName);
				$(".shoreline-data-division-put-office").html(data.Office);
				$(".shoreline-data-division-put-phone").html(data.Phone);
				$(".shoreline-data-division-put-title").html(data.Title);
				$(".shoreline-data-division-put-url").html(data.URL);
			})           
		}
		
		//--- Set Find by Name button if present on this page
		if ($("#SD_SearchDirectoryByName").length) // True if object exists
		{
			$("#SD_SearchDirectoryByName").click(function(){ SD_FindName(); });
		}
		//--- Set Find by Name placeholder text if present on this page
		if ($("#shoreline-data-employee-find").length) // True if object exists
		{
			$("#shoreline-data-employee-find").attr('placeholder','First name, last name, both, or keyword')
		}
		
		//--- Load division directory if requested on this page
		if ($("#shoreline-data-employee-find-div").length) // True if object exists
		{
			SD_FindDivision();
		}		
		
		
		//--- Add current page to Ask Us page anchors
		$("a[href$='/ask-us.aspx']").attr("href", 'https://www.shoreline.edu/ask-us.aspx?source_page=' + location.href);
		
		
		//--- Only call Calendar API if there's a calendar request on this page
		if (($('span[class^="shoreline-data-calendar"]')).length)
		{
			$.getJSON('https://app.shoreline.edu/ShorelineWebAPIs/api/college-calendar')
				.done(function(data) {
				$(".shoreline-data-calendar-put-currentquartername").text(data.CurrentQuarterName);
				$(".shoreline-data-calendar-put-currentquarterseason").text(data.CurrentQuarterSeason);
				$(".shoreline-data-calendar-put-currentquarterstart").text(data.CurrentQuarterStart);
				$(".shoreline-data-calendar-put-currentquarter10thday").text(data.CurrentQuarter10thDay);
				$(".shoreline-data-calendar-put-currentquarterlastday").text(data.CurrentQuarterLastDay);

				$(".shoreline-data-calendar-put-nextquartername").text(data.NextQuarterName);
				$(".shoreline-data-calendar-put-nextquarterseason").text(data.NextQuarterSeason);
				$(".shoreline-data-calendar-put-nextquarterstart").text(data.NextQuarterStart);
				$(".shoreline-data-calendar-put-nextquarter10thday").text(data.NextQuarter10thDay);
				$(".shoreline-data-calendar-put-nextquarterlastday").text(data.NextQuarterLastDay);

				$(".shoreline-data-calendar-put-loaded").text(data.Loaded);
			})
		}

		//--- Load department programs if requested on this page
		//if ($(".ou-shoreline-dept-programs").length) // True if object exists
		if ($("#dept-programs-feed").length)
		{
			SD_ProgramOptionsRenderOutput = 
				function(options)
				{
					var lastHeader = "";
					var result = "";

					var department = $(".ou-shoreline-dept-programs tr").eq(1).find('td:eq(0)').text();
					var showDescriptionCheck = $(".ou-shoreline-dept-programs tr").eq(1).find('td:eq(1)').text();
					var showDescription = showDescriptionCheck = null ? false : showDescriptionCheck == "x";		
					var ppElements = [];
					var ppHref = "";

					//--- Filter for specified department
					options = $.grep(options, function(e) { return e["department"] == department } );
					
					options.sort(SD_DynamicSortMultiple("programParent", "completionAwardSort", "title"));
					
					options.forEach( 
						function( option, index ) 
						{
							if (SD_HtmlEncode(option.programParent) != lastHeader)
							{
								//--- Get Program Parent href from first part of URL for program option
								ppElements = option.href.split("/")
								ppHref = "/" + ppElements[1] + "/" + ppElements[2];

								result += "<h2><a href=\"" + ppHref + "\">" + SD_HtmlEncode(option.programParent) + "</a></h2> \r\n";
								result += "<p>" + option.parentDescription + "</p> \r\n";
								lastHeader = SD_HtmlEncode(option.programParent);
							}
					
							result += 
								"<p><a href=\"" + option.href + "\">" + option.title + "</a></p> \r\n";
								//  +
								// "<p>" + $(option.programDescription).text() + " </p>\r\n";
						}               
					)
					
					$("#dept-programs-feed").replaceWith(result);
				};

			SD_LoadProgramOptionsXml();
		}		

		//--- Load program options if requested on this page
		//if ($(".ou-shoreline-program-options").length) // True if object exists
		if ($("#program-options-feed").length)
		{
			SD_ProgramOptionsRenderOutput = 
				function(options)
				{
					var lastHeader = "";
					var result = "";

					var programParent = $(".ou-shoreline-program-options tr").eq(1).find('td:eq(0)').text();
					var showDescriptionCheck = $(".ou-shoreline-program-options tr").eq(1).find('td:eq(1)').text();
					var showDescription = showDescriptionCheck = null ? false : showDescriptionCheck == "x";		
					var ppElements = [];
					var ppHref = "";

					//--- Filter for specified programParent
					options = $.grep(options, function(e) { return e["programParent"] == programParent } );
					
					options.sort(SD_DynamicSortMultiple("completionAwardSort", "title"));
					
					options.forEach( 
						function( option, index ) 
						{
							var progDesc = option.programDescription;
							progDesc = progDesc.replace(/(<([^>]+)>)/ig,"");
							result += 
								"<div class=\"program-option border-around\"> \r\n" +
								"<h3><a href=\"" + option.href + "\">" + option.title + "</a></h3> \r\n" +
								// "<p>" + $(option.programDescription).text() + "</p> \r\n" +  GMS 5/4/19
								"<p>" + progDesc + "</p> \r\n" +
								"<p><a href=\"" + option.href + "\">" + "Learn more about " + option.title + "</a></p> \r\n" +
								"</div> \r\n";
						}               
					)
					
					$("#program-options-feed").replaceWith(result);
				};

			SD_LoadProgramOptionsXml();
		}		


	}
	catch (err)
	{
		alert(err);
	}
}


/* *************************************************************
Name   : SD_FindName
Purpose: Find employees by name user has entered
Inputs : 
Returns: void
Author : Gavin Smith
Created: 08/15/2017
Modified by:
Modification:
************************************************************ */
function SD_FindName() {
	try
	{
		shoreline_data_sb = "";
		$(".shoreline-data-employee-find-put-data").empty();
		
		//--- Show Loading gif since it can take a few seconds
		$(".shoreline-data-employee-find-put-data").prepend('<img src="/_resources/img/shoreline-data-graphics/loading.gif">');

		var EmployeeName = $("#shoreline-data-employee-find").val();
		SD_AddHtml("<h3>Search for \"" + EmployeeName + "\"</h3>\r\n");

		$.getJSON(
			'https://azfunctionssccwebapisdirectory.azurewebsites.net/api/employee-find-name/' + EmployeeName, 
			function (data) 
			{
				SD_DisplayDirectory(data, "shoreline-data-employee-find-put-data");
			}
		)
	}
	catch (err)
	{}
}

/* *************************************************************
Name   : SD_FindDivision
Purpose: Find employees by division
Inputs : 
Returns: void
Author : Gavin Smith
Created: 08/17/2017
Modified by:
Modification:
************************************************************ */
function SD_FindDivision() {
	
	try
	{
		shoreline_data_sb = "";
		$(".shoreline-data-employee-find-div-put-data").empty();
		
		//--- Show Loading gif since it can take a few seconds
		$(".shoreline-data-employee-find-div-put-data").prepend('<img src="/_resources/img/shoreline-data-graphics/loading.gif">');

		var DivisionID = $("#shoreline-data-employee-find-div").val();
		//SD_AddHtml("<h3>Names like \"" + EmployeeName + "\"</h3>\r\n");

 
		$.getJSON(
			'https://azfunctionssccwebapisdirectory.azurewebsites.net/api/employee-find-division/' + DivisionID  ,
			function (data) 
			{
 
				SD_DisplayDirectory(data, "shoreline-data-employee-find-div-put-data");
			}
		)
	}
	catch (err)
	{}
}

/* *************************************************************
Name   : SD_DisplayDirectory
Purpose: Display directory results
Inputs : data
Returns: void
Author : Gavin Smith
Created: 08/16/2017
Modified by:
Modification:
************************************************************ */
function SD_DisplayDirectory(data, target) {
	try {

		var NameID = "";
		var firstName = false;
		var OnlyOneName = data.length == 1;
		var employeePhoto = "";

		// alert(data.length);

		//--- Add custom styles from campus-directory
		SD_AddHtml(
			"<style type=\"text/css\"> \r\n\r\n"  +

			".clearFloat {         \r\n" + 
			"    clear: left;      \r\n" + 
			"}      \r\n\r\n" + 


			"h2       \r\n" + 
			"{      \r\n" + 
			"    margin-bottom: 25px;      \r\n" + 
			"}      \r\n" + 

			"h3      \r\n" + 
			"{      \r\n" + 
			"    color: #111111;      \r\n" + 
			"}      \r\n\r\n" + 
			
			/* Narrow margins from main site default so list of accordion headers looks mor listlike and columns show */
			".accordion-header .btn      \r\n" + 
			"{      \r\n" + 
			"	font-size: 1rem !important;      \r\n" + 
			"	padding: 0.6rem 1rem .4rem !important;      \r\n" + 
			"}      \r\n" + 
			".accordion-header.active span      \r\n" + 
			"{      \r\n" + 
			"	color: #F8F8F8;      \r\n" + 
			"}      \r\n\r\n" + 
				
			".accordion-body p {      \r\n" + 
			"    margin-bottom: 0;      \r\n" + 
			"}      \r\n" + 
			".accordion-handle {      \r\n" + 
			"    padding-top: 12px;      \r\n" + 
			"    padding-bottom: 12px;      \r\n" + 
			"}      \r\n\r\n" + 

			"h3 span      \r\n" + 
			"{      \r\n" + 
			"    color: #444444;      \r\n" + 
			"    margin-top: .1rem;      \r\n" + 
			"}      \r\n\r\n" + 

			".name {      \r\n" + 
			"    display: inline-block;      \r\n" + 
			"    width: 25%;      \r\n" + 
			"    min-width: 185px;      \r\n" + 
			"}      \r\n" + 

			".title {      \r\n" + 
			"    display: inline-block;      \r\n" + 
			"    width: 33%;      \r\n" + 
			"    min-width: 240px;      \r\n" + 
			"    line-height: 140%;      \r\n" + 
			"}      \r\n\r\n" + 

			"@media screen and (max-width: 750px)      \r\n" + 
			"{      \r\n" + 
			"    .td, .bio, .bio h3, strong      \r\n" + 
			"    {      \r\n" + 
			"        font-size: 1rem;      \r\n" + 
			"        line-height: 1.5;      \r\n" + 
			"    }      \r\n" + 
			"}      \r\n\r\n" + 


			"@media screen and (max-width: 450px) {      \r\n" + 
			"    .phone {      \r\n" + 
			"        margin-left: 40px;      \r\n" + 
			"    }      \r\n" + 
			"}      \r\n\r\n" + 

			".bio div {      \r\n" + 
			"    margin-top: 10px;      \r\n" + 
			"}      \r\n\r\n" + 

			".col-12 img      \r\n" + 
			"{      \r\n" + 
			"    width: 150px;      \r\n" + 
			"}      \r\n\r\n" + 

			".table {      \r\n" + 
			"    display: table;      \r\n" + 
			"}      \r\n" + 
			".tr {       \r\n" + 
			"    display: table-row;       \r\n" + 
			"}      \r\n" + 
			".td {       \r\n" + 
			"    display: table-cell;      \r\n" + 
			"    color: #444;      \r\n" + 
			"}      \r\n\r\n" + 

			".officeHoursAlignedCaption      \r\n" + 
			"{      \r\n" + 
			"    display: inline-block;       \r\n" + 
			"    width: 170px;      \r\n" + 
			"}      \r\n\r\n" + 

			".classesTaughtAlignedCaption      \r\n" + 
			"{      \r\n" + 
			"    display: inline-block;       \r\n" + 
			"    width: 170px;      \r\n" + 
			"}      \r\n\r\n" + 

			".classesTaughtAligned      \r\n" + 
			"{      \r\n" + 
			"    font-weight: bold;      \r\n" + 
			"}      \r\n\r\n" + 

			"@media screen and (max-width: 750px)      \r\n" + 
			"{      \r\n" + 
			"    .officeHoursAlignedCaption, classesTaughtAlignedCaption      \r\n" + 
			"    {      \r\n" + 
			"        display: block;      \r\n" + 
			"        width: 100%;      \r\n" + 
			"    }      \r\n\r\n" + 

				".classesTaughtAligned      \r\n" + 
				"{      \r\n" + 
				"    display: block;      \r\n" + 
				"    width: 100%;      \r\n" + 
				"}      \r\n" + 
			"      \r\n\r\n" + 

			"</style>		      \r\n"
		);

		SD_AddHtml("<div class=\"accordion\" id=\"accordionDirectory\">\r\n");
 
 var data2;
 if (typeof data=='string')
 {
data2 = JSON.parse(data);
 }
 else
 {
	 data2 =data;
 }

		$.each(data2.employee, function (key, value) {
 
			var e = value;
 //console.log(JSON.stringify(e))
 if(e.FirstName=== undefined)
	 {}
			else
				{
			//--- KLUDGE - SD_ReplaceAll doesn't work here for some reason, so do the replaces three times to ensure we got all the weird characters
			NameID = (e.FirstName + e.LastName).replace(" ", "").replace("'", "").replace("(", "").replace(")", "").replace(".", "").replace(" ", "").replace(",", "");
			NameID = NameID.replace(" ", "").replace("'", "").replace("(", "").replace(")", "").replace(".", "").replace(" ", "").replace(",", "");
			NameID = NameID.replace(" ", "").replace("'", "").replace("(", "").replace(")", "").replace(".", "").replace(" ", "").replace(",", "");
employeePhoto='';
			if (e.ImageInfo != null)
			{
				 
				
						$.get(
			'https://azfunctionssccwebapisdirectory.azurewebsites.net/api/employee_picture/' + e.ImageInfo  )
				.done(
			function (data) 
			{
			 
 if (data!= null)
	 if(data!='')
		 {
			// console.log(data)
			 
				 $('#img_' +e.ImageInfo).attr('src', 'data:image/jpg;base64,' + data);
 
			 }
			})
			 
					employeePhoto = "<img id=\"img_" +e.ImageInfo +"\" alt=\"Photo of " + e.FirstName + " " + e.LastName + "\" />";
			
			}
					
 
			if (firstName)
				firstName = false;

			SD_AddHtml("<div class=\"accordion-card\"> \r\n");

			if (OnlyOneName)
			{
				SD_AddHtml("  <div class=\"accordion-header active\" id=\"heading" + NameID + "\"> \r\n");

				//if (PermalinkSearch)
				//{
				//	Page.Title = e.FirstName + " " + e.LastName + "  |  Shoreline Community College";
				//}
			}
			else
				SD_AddHtml("  <div class=\"accordion-header\" id=\"heading" + NameID + "\"> \r\n");

			SD_AddHtml("    <h3>\r\n");
			if (OnlyOneName)
				SD_AddHtml("      <button class=\"btn btn-toggle\" type = \"button\" data-toggle = \"collapse\" data-target=\"#collapse" + NameID + "\" aria-expanded=\"true\" aria-controls=\"collapse" + NameID + "\"> \r\n");
			else
				SD_AddHtml("      <button class=\"btn btn-toggle collapsed\" type = \"button\" data-toggle = \"collapse\" data-target=\"#collapse" + NameID + "\" aria-expanded=\"false\" aria-controls=\"collapse" + NameID + "\" onclick=\"SD_ToggleActive('heading" + NameID + "')\")> \r\n");
			SD_AddHtml("        <span class=\"name\">" + e.FirstName + " " + e.LastName + "</span>\r\n");
			SD_AddHtml("        <span class=\"title\">" + SD_Left(e.JobTitle, 30) + "</span>\r\n");
			SD_AddHtml("        <span class=\"phone\" style=\"white-space: nowrap\">" + e.Phone.replace(" ", "&nbsp;") + "</span>\r\n");
			SD_AddHtml("      </button> \r\n");
			SD_AddHtml("    </h3>\r\n");
			SD_AddHtml("  </div>\r\n");

			if (OnlyOneName)
				SD_AddHtml("  <div id=\"collapse" + NameID + "\" class=\"collapse show\" aria-labelledby=\"heading" + NameID + "\" data-parent=\"#accordionDirectory\">\r\n");
			else
				SD_AddHtml("  <div id=\"collapse" + NameID + "\" class=\"collapse\" aria-labelledby=\"heading" + NameID + "\" data-parent=\"#accordionDirectory\">\r\n");

			SD_AddHtml("    <div class=\"accordion-body\"> \r\n");
			SD_AddHtml("      <div class=\"row\"> \r\n");

			if (employeePhoto != '')
			{
				SD_AddHtml("        <div class=\"col-12 col-sm-7\" style=\"margin-bottom: 10px; \"> \r\n");

				SD_AddHtml("          <div class=\"table\"> \r\n");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Name:</div><div class=\"td\" style=\"font-weight: bold\">" + e.FirstName + " " + e.LastName + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Job Title:</div><div class=\"td\" style=\"font-weight: bold\">" + e.JobTitle + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Department:</div><div class=\"td\" style=\"font-weight: bold\">" + e.DivisionTitle + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("          </div> \r\n");

				SD_AddHtml("          <div style=\"margin-top: 16px; \"> \r\n");
				SD_AddHtml("          <div class=\"table\"> \r\n");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Phone:</div><div class=\"td\" style=\"font-weight: bold; white-space: nowrap;\"><a href=\"tel:" + e.Phone.replace("(", "").replace(")", "").replace("-", "").replace(" ", "") + "\">" + e.Phone + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Email:</div><div class=\"td\" style=\"font-weight: bold\"><a href=\"mailto:" + e.WorkEmail + "\">" + e.WorkEmail + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Office:</div><div class=\"td\" style=\"font-weight: bold\"><a href=\"" + e.OfficeUrl + "\" target=\"_blank\">" + e.Room + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("          </div> \r\n");
				SD_AddHtml("          </div>\r\n"); // margin-top 16
				SD_AddHtml("        </div> \r\n");  // col-12 col-sm-6
				SD_AddHtml("        <div class=\"col-12 col-sm-5\" style=\"margin-bottom: 10px; \"> \r\n");
				SD_AddHtml("           " + employeePhoto);
				SD_AddHtml("        </div>\r\n");  // col-12 col-sm-6
			}
			else
			{
				SD_AddHtml("        <div class=\"col-12 col-sm-6\" style=\"margin-bottom: 10px; \"> \r\n");
				SD_AddHtml("          <div class=\"table\"> \r\n");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Name:</div><div class=\"td\" style=\"font-weight: bold\">" + e.FirstName + " " + e.LastName + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Job Title:</div><div class=\"td\" style=\"font-weight: bold\">" + e.JobTitle + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 90px\">Department:</div><div class=\"td\" style=\"font-weight: bold\">" + e.DivisionTitle + "</div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("          </div> \r\n");
				SD_AddHtml("        </div> \r\n");  // col-12 col-sm-6
				SD_AddHtml("        <div class=\"col-12 col-sm-6\" style=\"margin-bottom: 10px; \"> \r\n");
				SD_AddHtml("          <div class=\"table\"> \r\n");
				
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 75px\">Phone:</div><div class=\"td\" style=\"font-weight: bold; white-space: nowrap;\"><a href=\"tel:" + e.Phone.replace("(", "").replace(")", "").replace("-", "").replace(" ", "") + "\">" + e.Phone + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 75px\">Email:</div><div class=\"td\" style=\"font-weight: bold\"><a href=\"mailto:" + e.WorkEmail + "\">" + e.WorkEmail + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("            <div class=\"tr\"> \r\n");
				SD_AddHtml("              <div class=\"td\" style=\"width: 75px\">Office:</div><div class=\"td\" style=\"font-weight: bold\"><a href=\"" + e.OfficeUrl + "\" target=\"_blank\">" + e.Room + "</a></div>\r\n");
				SD_AddHtml("            </div>");
				SD_AddHtml("          </div> \r\n");
				SD_AddHtml("        </div>\r\n");  // col-12 col-sm-6
			}

			if (employeePhoto != '')
				SD_AddHtml("        <div class=\"col-12\">\r\n");
			else
				SD_AddHtml("        <div class=\"col-12\">\r\n");

			if (e.CurrentQuarterOfficeHours != "" && e.Classes != "")
			{
				//--- Line up the rows by using specific spacing for caption, sized to widest quarter name (Summer)
				//officeHoursRow = "          <p><span class=\"officeHoursAlignedCaption\">" + e.CurrentQuarterName + " office hours:</span> <strong>" + e.CurrentQuarterOfficeHours + "</strong></p>";
				//SD_AddHtml(officeHoursRow.replace('Winter office hours', 'Winter office hrs').replace('Spring office hours', 'Spring office hrs'));
				if (e.Classes != "")
					SD_AddHtml("          <p style=\"max-width: 85%; margin-top: 8px;\"><span class=\"classesTaughtAlignedCaption\">Classes taught:</span> <span class=\"classesTaughtAligned\">" + e.Classes + "</span></p>");
			}
			else
			{
				//--- Minimize space after caption of whichever is there
			//	SD_AddHtml("        <p>" + e.CurrentQuarterName + " office hours: <strong>" + e.CurrentQuarterOfficeHours + "</strong></p>");
				if (e.Classes != "")
					SD_AddHtml("        <p style=\"max-width: 85%\">Classes taught: <strong>" + e.Classes + "</strong></p>");
			}
			SD_AddHtml("        </div>\r\n");


			SD_AddHtml("        <div class=\"col-12 bio\">\r\n");
			if (e.Bio != null && e.Bio != "")
			{
				SD_AddHtml("          <h3>Employee Bio</h3> \r\n");
				SD_AddHtml(SD_TextToHtml(e.Bio));
			}
			if (e.Degrees != null && e.Degrees != "")
			{
				SD_AddHtml("<h3>Education &amp; Training</h3> \r\n");
				SD_AddHtml(SD_TextToHtml(e.Degrees).replace("<br /> \r\n<br /> \r\n", "<div></div>"));
			}
		//	SD_AddHtml("<p style=\"margin-top: 20px\">Permalink: <a href=\"" + SD_EmployeePermalink(e.FirstName, e.LastName) + "\">" + SD_EmployeePermalink(e.FirstName, e.LastName) + "</a>");
			SD_AddHtml("        </div>\r\n");


			SD_AddHtml("      </div>\r\n");    // row
			SD_AddHtml("    </div>\r\n");      // accordion-body
			SD_AddHtml("  </div>\r\n");        // collapse
			SD_AddHtml("</div>\r\n");          // acordion-card
					}
		});
			
		SD_AddHtml("</div>\r\n");          // acordion

		//--- Load the built HTML into the placeholder
		$("." + target).html(shoreline_data_sb);
		//$("." + target).replaceWith(shoreline_data_sb);
	}
	catch (err) {
		alert(err)
	}
}

/* *************************************************************
Name   : SD_AddHtml
Purpose: Add one HtmlBlock to schedule placeholder
Inputs : string Html
Returns: void
Author : Gavin Smith
Created: 02/12/2016
Modified by:
Modification:
************************************************************ */
function SD_AddHtml(Html) {
	try
	{
		if (Html != null)
			shoreline_data_sb += Html;
	}
	catch (ex) {}
}

/* *************************************************************
Name   : SD_Left
Purpose: Match Left function used in C# code
Inputs : str, n
Returns: string
Author : Gavin Smith
Created: 08/15/2017
Modified by:
Modification:
************************************************************ */
function SD_Left(str, n) {
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
}


/* *************************************************************
Name   : SD_TextToHtml
Purpose: Converts ntext with carriage returns, etc, into html that
			displays new lines, etc. as intended (New and improved)
Inputs : string strTextToConvert
Returns: string: text converted to html
Author : Gavin Smith
Created: 05/02/2018
Modified by:
Modification:
************************************************************ */
function SD_TextToHtml(str)
{
	// str = SD_HtmlEncode(str);
	// str = str.replace("\r\n", "\r");
	// str = str.replace("\n", "\r");
	// str = str.replace("\r", "<br />\r\n");
	// str = str.replace("  ", " &nbsp;");

	try
	{
		if (str != null)
		{
			str = str.replace(/(\r\n|\n|\r)/g,"<br />");

			//--- Add space before \r's to separate from http:// strings to make
			str = str.replace("\r", " \r");
			//str = Regex.Replace(str, @"\b(?:https?://|www\.)\S+\b", @"<a href=""$0"" Target=""_blank"">$0</a>");
	
			str= str.SD_ReplaceAll("<br /><br />", "<div></div>")
	
	
			str = SD_CreateTextLinks(str); 
			str = str.replace("href=\"www", "href=\"http://www");	
		}
		else
			str = "";
	}
	catch (ex) {}

	return str;
}


/* *************************************************************
Name   : SD_HtmlEncode
Purpose: Encode HTML data
Inputs : 
Returns: void
Author : Gavin Smith
Created: 12/20/2018
Modified by:
Modification:
************************************************************ */
function SD_HtmlEncode(value){
	// Create a in-memory div, set its inner text (which jQuery automatically encodes)
	// Then grab the encoded contents back out. The div never exists on the page.
	return $('<div/>').text(value).html();
  }


/* *************************************************************
Name   : SD_CreateTextLinks
Purpose: Find links and make into urls
Inputs : 
Returns: void
Author : Gavin Smith
Created: 12/20/2018
Modified by:
Modification:
************************************************************ */
function SD_CreateTextLinks(text) {

	return (text || "").replace(
		/([^\S]|^)(((https?\:\/\/)|(www\.))(\S+))/gi,
		function(match, space, url){
		var hyperlink = url;
		if (!hyperlink.match('^https?:\/\/')) {
			hyperlink = 'http://' + hyperlink;
		}
		return space + '<a target=\"_blank\" href="' + hyperlink + '">' + url + '</a>';
		}
	);

}


/* *************************************************************
Name   : SD_EmployeePermalink
Purpose: Employee Permalink
Inputs : 
Returns: void
Author : Gavin Smith
Created: 12/19/2018
Modified by:
Modification:
************************************************************ */
function SD_EmployeePermalink(firstName, lastName)
{
	var name = firstName + " " + lastName;
	var urlSafeName = name.toLowerCase().replace(" ", "-").replace(".", "").replace("\"", "");
	return "https://app.shoreline.edu/campus-directory/name/" + urlSafeName;
}


/* *************************************************************
Name   : SD_ToggleActive
Purpose: KLUDGE to simulate header active toggle that should
       : be happening but for some reason doesn't
Inputs : 
Returns: void
Author : Gavin Smith
Created: 12/20/2018
Modified by:
Modification:
************************************************************ */
function SD_ToggleActive(headerID)
{

	if ($("#" + headerID).hasClass("active"))
	{
		//--- This is the selected one - deactivate it
		$("#" + headerID).removeClass("active");
	}
	else
	{
		//--- This is a new active - first clear all existing actives
		$(".accordion-header").removeClass("active");
		$("#" + headerID).addClass("active");
	}

}


/* *************************************************************
Name   : repaceAll
Purpose: Replace all instances of string
Inputs : 
Returns: void
Author : Gavin Smith
Created: 12/20/2018
Modified by:
Modification:
************************************************************ */
String.prototype.SD_ReplaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};




/* -------------------------------------------------------------------------------------------------- 
*                                PROGRAM OPTIONS XML FUNCTIONS 
---------------------------------------------------------------------------------------------------- */

/* *************************************************************
Name   : SD_LoadProgramOptionsXml
Purpose: Load an array from Program options XML File
Inputs : 
Returns: void
Author : Gavin Smith
Created: 03/01/2019
Modified by:
Modification:
************************************************************ */
function SD_LoadProgramOptionsXml() 
{

	var isIE11 = !!window.MSInputMethodContext && !!document.documentMode;

	$.ajax({
		type: "GET",
		cache: false,
		url: SD_ProgramsXmlFilePath,
		dataType: isIE11 ? 'text' : 'xml', // text for IE, xml for the rest,
		success: SD_ProgramOptionsXmlParser
	});
}

/* *************************************************************
Name   : SD_ProgramOptionsXmlParser
Purpose: XML Parser that run on completion of load of XML
		: data into array. Renders output using function set for
		: SD_ProgramOptionsRenderOutput this run
Inputs : 
Returns: void
Author : Gavin Smith
Created: 03/01/2019
Modified by:
Modification:
************************************************************ */
function SD_ProgramOptionsXmlParser(xml) 
{
	var result = "";
	var tagsText;
	var $tagsXml;
	var department = "";
	var options = [];

	$(xml).find("option").each(
		function () 
		{
			var row = {};
			row["href"] = $(this).attr("href");
			row["programOption"] = SD_OptionValue(this, "program-option");
			row["completionAward"] = SD_OptionValue(this, "completion-award");
			if (row["completionAward"] == "AA-DTA/MRP")
				row["completionAwardSort"] = "AA-DTA";
			else if (row["completionAward"] == "AS-T 2/MRP")
				row["completionAwardSort"] = "AS-T 2";
			else
				row["completionAwardSort"] = row["completionAward"];
			row["programParent"] = SD_OptionValue(this, "program-parent");
			row["programDescription"] = SD_OptionValue(this, "program-description");
			row["completionLength"] = SD_OptionValue(this, "completion-length");
			row["completionLenAddl"] = SD_OptionValue(this, "completion-length-additional");
			row["enrollmentPeriod"] = SD_OptionValue(this, "enrollment-period");
			row["applicationDeadline"] = SD_OptionValue(this, "application-deadline");
			row["areaStudy"] = SD_OptionValue(this, "area-study");
			row["programType"] = SD_OptionValue(this, "program-type");
			row["programFormat"] = SD_OptionValue(this, "program-format");
			row["description"] = SD_OptionValue(this, "description");
			row["title"] = SD_OptionValue(this, "title");
			row["parentDescription"] = SD_OptionValue(this, "parent-description"); 
			row["taggedAs"] = SD_OptionValue(this, "tagged-as");

			row["department"] = ""; 
			tagsText = $.parseXML("<tags>" + row["taggedAs"] + "</tags>");
			$tagsXml = $(tagsText);
			$tagsXml.find("name").each(
				function (index, tag)
				{                         
					if ($(this).text().startsWith("dept-"))
						row["department"] = $(this).text();
						// row["department"] = $(this).text().substring(5, 99);                           
				}
			)

			options.push(row);

		}
	);

	SD_ProgramOptionsRenderOutput(options);
}

/* *************************************************************
Name   : SD_OptionValue
Purpose: Get option value from current xml node, if available, defaulting to ""
Inputs : 
Returns: void
Author : Gavin Smith
Created: 04/29/2019
Modified by:
Modification:
************************************************************ */
function SD_OptionValue(option, key)
{
	var result = $(option).find(key).html();
	if (result == null)
		result = "";
	return result;
}

/* *************************************************************
Name   : SD_DynamicSort
Purpose: Sort function allowing column sort for an array
Inputs : 
Returns: void
Author : Gavin Smith
Created: 03/01/2019
Modified by:
Modification:
************************************************************ */
function SD_DynamicSort(property) 
{
	//alert(property);
	var sortOrder = 1;
	if (property[0] === "-") 
	{
		sortOrder = -1;
		property = property.substr(1);
	}

	return function (a,b) 
	{
		var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
		return result * sortOrder;
	}
}

/* *************************************************************
Name   : SD_DynamicSort
Purpose: Sort function allowing multiple column sort for an array
Inputs : 
Returns: void
Author : Gavin Smith
Created: 03/01/2019
Modified by:
Modification:
************************************************************ */
function SD_DynamicSortMultiple() {
	/*
	* save the arguments object as it will be overwritten
	* note that arguments object is an array-like object
	* consisting of the names of the properties to sort by
	*/
	var props = arguments;
	return function (obj1, obj2) {
		var i = 0, result = 0, numberOfProperties = props.length;
		/* try getting a different result from 0 (equal)
		* as long as we have extra properties to compare
		*/
		while(result === 0 && i < numberOfProperties) {
			result = SD_DynamicSort(props[i])(obj1, obj2);
			i++;
		}
		return result;
	}
}            
