
$(document).ready(function(){

	  $(".calendarTable tr:even").css("background-color", "#DDDDDD");
	  $(".calendarTable tr:odd").css("background-color", "#FFFFFF");
	  
	  //make it pretty code for the catalogTable
	  $(".catalogTable tr:even").css("background-color", "#DDDDDD");
	  $(".catalogTable tr:odd").css("background-color", "#FFFFFF");
	  $(".catalogTable tr td:nth-child(3)").css("text-align", "center");
	  $(".catalogTable tr:contains('Total') td").css("font-weight","bold");
	  
	  $("th[scope='row']").css({'background-color' : '#e0e0fF', 'color' : '#000'});
	  $("th[scope='row'] a").css({'color' : '#00F', 'text-decoration' : 'underline'});

});

$("document").ready(function() {
	buildCourseLinks();
	buildFootnoteLinks();
});

//$("document").ready(function() {
//testingCode
//$(".catalogTable tr td:nth-child(2)").each(function(){
//	var foo=$(this).html().indexOf("<sup>");
//	if(foo>0){
//  alert(foo);
//	var bar= $(this).text().substring(0, foo);
//	alert(bar);
//	};
//	
//	});
//});
	

function buildCourseLinks() {
    var semesterCode = "201180";
		$(".catalogTable tr td:first-child").each(function() {
			//exclude totals and electives
			if ($(this).text().indexOf("****") < 0 && $(this).text() != "Total") {
			
			var findSup = $(this).parent().children(':nth-child(2)').html().indexOf("<sup>")
			
			//we need to reconstruct the course ruberic in such a way that it can be passed in ID's cleanly and picked back appart later "__" starts it and "_" is in the middle when we pass it
			var spacePosition = $(this).text().indexOf(" ")
			//alert(spacePosition)
			var ruberic = $(this).text().substring(0, spacePosition)
			//alert(ruberic)
			var courseNumber = $(this).text().substring(spacePosition+1)
			//alert(courseNumber)
			//var cnReconstructed = ruberic +"_"+ courseNumber
			var cnReconstructed = "https://sigmasun.southwest.tn.edu/pls/PROD/bwckctlg.p_disp_course_detail?cat_term_in="+semesterCode+"&subj_code_in="+ ruberic +"&crse_numb_in="+ courseNumber                
			
			if(findSup>0){
			var wilma=$(this).parent().children(':nth-child(2)').html().length;
			var fred= $(this).parent().children(':nth-child(2)').html().substring(findSup, wilma);
			//alert(fred);
			var bar= $(this).parent().children(':nth-child(2)').text().substring(0, findSup);
			$(this).parent().children(':nth-child(2)').html("<a class='courseDescriptionLink' id='CourseLink__" + cnReconstructed +  "' href=" + cnReconstructed +  ">" + bar + "</a>" + fred + "<div id='courseDescription"+cnReconstructed+"'></div>");
			} else {
			$(this).parent().children(':nth-child(2)').html("<a class='courseDescriptionLink' id='CourseLink__" + cnReconstructed +  "' href=" + cnReconstructed +  ">" + $(this).parent().children(':nth-child(2)').html() + "</a><div id='courseDescription"+cnReconstructed+"'></div>");
			}
			
			};
	 });
}

function buildFootnoteLinks(){
	$(".catalogTable tr td sup").each(function(){
		var cleanHtml = $(this).html().replace(/,/g,'');
		$(this).html("<a href=\"#ftnref" + cleanHtml + "\">" + $(this).html() + "</a>")
		});
	}
	
function buildBookmarksList(strWhichTag, sBookMarkNode) {
    var i;
    var cAnchorCount = 0;
    // create the list that will hold the bookmark links
    var oList = $("<ul id='bookmarksList'>");
    // for each one of the header tags, create a new named anchor and insert it into
    // the header tag. Then add a new link to the list that points to the named anchor
    $("div:not([id=header]) " + strWhichTag).each(function() {
    $(this).html("<a name='bookmark" + cAnchorCount + "'></a>" + $(this).html());
	if (cAnchorCount != 0) {$(this).before("<p>[<a href=\"#top\">back to top</a>]</p>")};
           oList.append($("<li><a href='#bookmark" + cAnchorCount++ + "'> " + $(this).text() + "</a></li>"));
    });
   // now find the ID of the bookmark container and append it
   $("#" + sBookMarkNode).append(oList);
   //$("#mainContent").append("<p>[<a href=\"#top\">back to top</a>]</p>");   
 }
 
 function buildBookmarksNav(strWhichTag, sBookMarkNode) {
    var i;
    var cAnchorCount = 0;
    // create the list that will hold the bookmark links
    var oList = $("<div id='bookmarksList'>");
    // for each one of the header tags, create a new named anchor and insert it into
    // the header tag. Then add a new link to the list that points to the named anchor
    $("div:not([id=header]) " + strWhichTag).each(function() {
    $(this).html("<a name='bookmark" + cAnchorCount + "'></a>" + $(this).html());
	if (cAnchorCount != 0) {$(this).before("<p>[<a href=\"#top\">back to top</a>]</p>")};
           oList.append($("<a href='#bookmark" + cAnchorCount++ + "'> " + $(this).text() + "</a>"));
    });
   // now find the ID of the bookmark container and append it
   $("#" + sBookMarkNode).append(oList);
 }		
