// *************************************************************************
//	######  #    #  #    #   ####    #####     #     ####   #    #   ####
//	#       #    #  ##   #  #    #     #       #    #    #  ##   #  #
//	#####   #    #  # #  #  #          #       #    #    #  # #  #   ####
//	#       #    #  #  # #  #          #       #    #    #  #  # #       #
//	#       #    #  #   ##  #    #     #       #    #    #  #   ##  #    #
//	#        ####   #    #   ####      #       #     ####   #    #   ####
// *************************************************************************

// GLOBAL VARIABLES:

// These variables can be overriden anywhere within the calling document
// as long as they're set before calling the function that uses the variable(s):

var css = 0;

// I use webHome to give a stable/static URL to the HTML and CSS validators.
var webHome = "http://hypert.info/";

// *************************************************************************
function Refresh(timer) {
  alert(timer);
}

// *************************************************************************
function GetTopLevel(levelsDeep) {
  var topLevel = "";
  for (var i = 0; i < levelsDeep; i=i+1) {
    topLevel = "../" + topLevel;
  }
  //alert(topLevel);
  return(topLevel);
}

// *************************************************************************
function GetPath(levelsDeep) {
  var path = "";
  var pathArray = location.pathname.split('/');
  for (var i = (pathArray.length - levelsDeep - 1); i < pathArray.length; i=i+1) {
    path = path + "/" + pathArray[i];
  }
  // The above algorithm always leaves a "/" at the beginning of path,
  // so remove the first character, since the "topLevel" will always end
  // with a "/"
  path = path.substring(1);
  //alert(path);
  return(path);
}

// *************************************************************************
function GetFilename() {
  // Process twice to handle normal path delimiters ('/') and Windows' ones ('\\'):
  var fileName = location.pathname.substring(location.pathname.lastIndexOf('/')+1);
  fileName = fileName.substring(fileName.lastIndexOf('\\')+1);
  //alert(fileName);
  return(fileName);
}

// *************************************************************************
function GetFilenameNoExtension() {
  var fileName = GetFilename();
  fileName = fileName.substring(0,fileName.lastIndexOf('.'));
  //alert(fileName);
  return(fileName);
}

// *************************************************************************
function DisplayModified() {

// This script and many more are available free online at
// The JavaScript Source!! http://javascript.internet.com

	var days = new Array(7)
	days[0] = "Sunday"
	days[1] = "Monday"
	days[2] = "Tuesday"
	days[3] = "Wednesday"
	days[4] = "Thursday"
	days[5] = "Friday"
	days[6] = "Saturday"

	var months = new Array(13)
	months[1] = "January"
	months[2] = "February"
	months[3] = "March"
	months[4] = "April"
	months[5] = "May"
	months[6] = "June"
	months[7] = "July"
	months[8] = "August"
	months[9] = "September"
	months[10] = "October"
	months[11] = "November"
	months[12] = "December"

	var dateObj = new Date(document.lastModified)
	var wday = days[dateObj.getDay()]
	var lmonth = months[dateObj.getMonth() + 1]
	var date = dateObj.getDate()
	var fyear = dateObj.getFullYear()
	// getHours returns a time 4 hours EARLIER on my Mac (in IE only)
	var hours = dateObj.getHours()
	var minutes = dateObj.getMinutes()
	var am_pm = " am"
	if (hours > 11) {
	  if (hours != 12) {
	    hours = hours - 12
	  }
	  am_pm = " pm"
	}
	else if (hours == 0) {
	  hours = 12
	}

	if (minutes < 10) {
	  minutes = "0" + minutes
	}

	document.write("<br clear=all><hr>Last Updated: " + wday + ", " + lmonth + " " + date + ", " + fyear + ", " + hours + ":" + minutes + am_pm)
}

// *************************************************************************
function DisplayValidHTML(topLevel) {

  // Show "Valid HTML" logo.  Use the local validator if we're on Silverfox,
  // otherwise use the one at the W3C.
  if (top.location.host.match(/^hypert$/i)) {
    document.write("<a target=\"_top\" href=\"/validator/check?uri=referer\"><img align=right border=0 alt=\"Valid HTML\" width=88 height=31 src=\"" + topLevel + "pics/valid-html-401.png\"></a>");
  }
  else {
    document.write("<a target=\"_top\" href=\"http://validator.w3.org/check?uri=referer\"><img align=right border=0 alt=\"Valid HTML\" width=88 height=31 src=\"" + topLevel + "pics/valid-html-401.png\"></a>");
  }
}

// *************************************************************************
function DisplayValidCSS(topLevel, path) {

  // Show "Valid CSS" logo:
  document.write("<a target=\"_top\" href=\"http://jigsaw.w3.org/css-validator/validator?uri=" + webHome + path + "&amp;charset=%28detect+automatically%29\"><img align=right border=0 alt=\"Valid CSS\" width=88 height=31 src=\"" + topLevel + "pics/valid-css.gif\"></a>")
}

// *************************************************************************
function CheckFrames(topFrame) {
  if (top.location == self.location) {
    document.write('<br clear=all><hr><a href=' + topFrame + ' target="_top">Load navigation frames!</a>');
  }
}

// *************************************************************************
function DisplayFooter(levelsDeep) {

	// Set topLevel:
	if (!levelsDeep) {
	  levelsDeep = "0";
	}
	
	var topLevel = GetTopLevel(levelsDeep);
	var path = GetPath(levelsDeep);
	//alert("levelsDeep: " + levelsDeep);
	//alert("topLevel: " + topLevel);
	//alert("path: " + path);
	
	DisplayModified();
	document.write("<br clear=all><hr>");
	DisplayValidHTML(topLevel);

	if (css) {
	  DisplayValidCSS(topLevel, path);
	}
	
	// Show email icon:
	var linktext = "<img alt=email border=0 hspace=10 height=34 width=62 src=\"" + topLevel + "pics/email.gif\">";
	var email1 = "hypert";
	var email2 = "verizon.net";
	document.write("<a href="+ "mail" + "to:" + email1 + "@" + email2 + ">" + linktext + "</a>");
	
	// Show home icon:
	document.write("<a target=\"_top\" href=\"" + topLevel + "index.html\"><img alt=\"home\" border=0 hspace=10 height=34 width=62 src=\"" + topLevel + "pics/home.gif\"></a>");
}

// *************************************************************************
function NMC_Artist(name, id) {
    //document.write("<li><A HREF=\"http://www.newmusiccanada.com/genres/artist.cfm?Band_Id=" + id + "\">" + name + "<\/A> (<A target=\"_blank\" HREF=\"javascript:resizeTo(600,500);location.href='http://www.newmusiccanada.com/player/player.cfm?All_Tracks=1&Band_Id=" + id + "';\">play all<\/A>)");
    document.write("<li><A HREF=\"http://www.newmusiccanada.com/genres/artist.cfm?Band_Id=" + id + "\">" + name + "<\/A>");
}

// *************************************************************************
function NMC_Subgenre(subgenre, id, parent_id) {
    document.write("<li><A HREF=\"http://www.newmusiccanada.com/genres/subgenre.cfm?Genre_Id=" + id + "&PartOf_Genre_Id=" + parent_id + "\">" + subgenre + "<\/A> (<A target=\"_blank\" HREF=\"javascript:resizeTo(600,500);location.href='http://www.newmusiccanada.com/player/player.cfm?All_Tracks_GenreTop10=1&Genre_Id=" + id + "&PartOf_Genre_ID=" + parent_id + "';\">play all<\/A>)");
}

// *************************************************************************
function AutoLinks() {
  // The element with id="autoLinks" will be replaced with these links
  // to all named anchors (<a name="...") on the current page.
  var autoLinks = document.getElementById("autoLinks");
  var links = new Array();

  var allTags = document.getElementsByTagName("A");
  for (var i=0; i<allTags.length; i++) {
    // If this <a> has a "name:, add it to the links array.
    if (allTags[i].name) {
      // "Push" this one into links (is there a better "push" in Javascript?)
      links[links.length] = allTags[i].name;
    }
  }

  var linkText = "Jump To:<br>";
  for (var i=0; i<links.length; i++) {
    if (i>0) {
      linkText = linkText + " - ";
    }
    linkText = linkText + '<a href="#' + links[i] + '">' + links[i] + '</a>';
  }
  autoLinks.innerHTML = linkText;
}
