// useful utility functions

function email(sz, szDisp, szOrg, szExt)
	{
	// emit a spam-safe email link
	// note the various defaults for missing arguments!
	szDispT = "";
	szOrgT = "giddensschool";
	szExtT = "com";
	switch (arguments.length) {
		case 4: szExtT = szExt; // fall thru
		case 3: szOrgT = szOrg; // fall thru
		case 2:	szDispT = szDisp; // fall thru
		case 1: break; // defaults all set
		default: sz = ""; // unexpected!  emit something.
		}
	if (szOrgT == "giddensschool")
		// special case because of default values
		szExtT = "org";
	sz = sz + "@" + szOrgT + "." + szExtT;
	if (szDispT == "")
		szDispT = sz;
	document.write("<a href=\"mail" + "to:" + sz + "\">" + szDispT + "</a>");
	}
	
function mail2(n)
	{
	// similar to above, but emits only the first part of the tag allowing for 
	// whatever descriptive text to follow.  </a> must be added after!
	document.write("<a href=" + "\"mail" + "to:" + n + "@" + "happymedium.org\">");
	}

function RmvClass(obj, sz)
// Remove a class from an object's class list.
	{
	if (obj != null)
		obj.className = obj.className.replace(new RegExp("\\s*\\b" + sz + "\\b", "g"), "");
	}
	
function AddClass(obj, sz)
// Add a class to the object's class list.  Prevents duplicates.
	{
	if (obj != null)
		{
		RmvClass(obj, sz);
		obj.className += " " + sz;
		}
	}


function ShowHideDefn()
	{
	// show/hide the definition text for this link
	var e = this.parentNode;
	if (e.className == "defn")
		e.className = "defn show";
	else
		e.className = "defn";
	return false;
	}

function InitPage()
// Initialize anything we need to for a web page
	{
	var e;

	// Definition links
	for (var i = 0; i < document.links.length; i++)
		{
		e = document.links[i];
		if (e.parentNode.className.substr(0,4) == "defn")
			{
			e.onclick = ShowHideDefn;
			e.onfocus = function() {this.blur();};
			}
		}
	}

function GetBanner()
// Display random banner image:
    {
    // This is the number of banner images in the "/images" directory, e.g., "banner1.jpg" to "banner6.jpg".
    var NumberOfBannerImages = 6;
    
    var imgno = Math.round((NumberOfBannerImages - 1) * Math.random()) + 1;
    document.write("<img src='/images/banner" + imgno + ".jpg");
    }