//	common.js	Shared JS routines
//
//	(c) Andy Belcher 2006
//
//	Global Variable Definitions
//
var domName		= "dandylife.org";
var wwwName		= "web."+domName;
var DHTML		= 1;
var dhtmlTest	= getObjectByAnyMeans('frame');
//
//	Object acquisition
//
function getObjectByAnyMeans(objId) {
	if(document.getElementById) {return document.getElementById(objId);}
	if(document.all)            {return eval("document.all." +objId);}
	if(document.layers)         {return eval("document.layers[" +objId+ "]");}
	DHTML	= 0;
	return false;
	}
//
//	Simple DHTML functions
//
function switchClass(lmtId,newClass)
	{if(DHTML) {getObjectByAnyMeans(lmtId).className = newClass;}}
//
function switchText(lmtId,newText)
	{if(DHTML) {getObjectByAnyMeans(lmtId).innerHTML = newText;}}
//
//	Short-cut aliases...
//
function dw(dwStr) {document.write(dwStr);}
//
//	Cloaked email mailto: link
//
function aSMT(tN,tD,dA,sU) {
	var aS = "&#64;";if(!tN) {tN = "webmaster";}
	var mT = "ma"+"ilt"+"o:";if(!tD) {tD = domName;}
	var tA = tN+"@"+tD;if(!dA) {dA = tN+aS+tD;}
	if(sU) {sU = "?s"+"ub"+"ject="+sU;} else {sU = "";}
	dw("<a href=\""+mT+tA+sU+"\" title=\"Send ema"+"il...\">"+dA+"</a>");
	}
//
//	COOKIE STUFF, read and write 'em
//
function writeCookie(ckName,ckVal,ckDays) {
	if(!ckName) {return;}
	if(!ckVal) {ckVal = "";}
	if(!ckDays) {ckDays = 1;}
	var expDate = new Date();
	var numDate = expDate.getTime();
	numDate += eval(3600000 * 24 * ckDays);
	expDate.setTime(numDate);
	var ckStr = ckName+"="+ckVal+"; path=/; expires="+expDate.toGMTString()+";";
	document.cookie = ckStr;
	}
//
function readCookie(ckName) {
	if(document.cookie.length > 0) 
		{ckStart = document.cookie.indexOf(ckName+"="); 
		if(ckStart != -1)
			{ckStart += ckName.length+1; 
			ckEnd = document.cookie.indexOf(";", ckStart);
			if(ckEnd == -1) {ckEnd = document.cookie.length;}
			return unescape(document.cookie.substring(ckStart,ckEnd));
			}
		}
	return "";
	}
//
//	Temporary warning of construction in progress/missing link
//
function ny() {
	alert('Not yet!\nBut very soon...\n');
	return false;
	}
//
//	Website specific page construction functions
//
function browserUpgradeWarning() {
	dw("<div id=\"upgrade\"> "
		+ "Sorry, but your browser is either very old or not configured correctly, "
		+ "we shall assume the former! "
		+ "Some of the styling features within this site will not render "
		+ "correctly on your <strong>obsolete</strong> browser. You will still be "
		+ "able to use the site but it won't look as good. "
		+ "In the meantime you are strongly advised to upgrade your browser to "
		+ "<cite>at least</cite> <strong>Internet Explorer 6</strong>, <strong>Netscape6</strong>, "
		+ "or one of the other standards compliant browsers such as FireFox, "
		+ "Mozilla or Opera, these are fully compliant and will work correctly. "
		+ "<br />Try these links for more information: "
		+ "<a href=\"http://webstandards.org/act/campaign/buc/\" target=\"_blank\" "
		+ "title=\"The Browser Upgrade Campaign...\">&raquo;Browser Upgrade Campaign</a> "
		+ "&#8212;<a href=\"http://www.w3.org/QA/\" target=\"_blank\" "
		+ "title=\"Find out more about web standards QA from the W3C...\""
		+ ">&raquo;W3C QA</a></div>");
	dhtmlSupportTest();
	cookieSupportTest();
	}
//
function dhtmlSupportTest() {
	if(DHTML) {return "";}
	dw("<div class=\"noscript\"><strong>Unable to verify DHTML support!</strong> DHTML "
		+ "does not appear to be supported on your browser, without it you "
		+ "will not be able to view this site as it was intended. Please "
		+ "update your browser and/or settings...</div>");
	}
//
function cookieSupportTest() {
	var cval = 'abc';writeCookie('suptest',cval,1);
	var ncval = readCookie('suptest');
	if(ncval != cval)
		{dw("<div class=\"noscript\"><strong>Unable to write and retrieve "
			+ "cookies!</strong> These are either unsupported by your PC/Browser, "
			+ "blocked by a firewall or perhaps you have disallowed them in "
			+ "your browser configuration. Without cookies you may not be "
			+ "able to use this site as it was intended. Please "
			+ "update your browser and/or settings...</div>");
		}
	}
//
//	Pathbar functions...
//
function drawPathBar(a1,u1,t1,a2,u2,t2,a3,u3,t3,a4,u4,t4,a5,u5,t5)	{
	var hdr = "http:// "+wwwName;if(a4) {hdr = "..";}
	if(!a5) {dw("<a href=\"/index.shtml\" title=\"To the site index page...\">"+hdr+"</a>");}
	var tA = a1;if(!tA) {tA = "";}
	var tU = u1;if(!tU) {tU = "";}
	var tT = t1;if(!tT) {tT = "";}
	plotPathSegment(tU,tT,tA);
	if(a2) {plotPathSegment(u2,t2,a2);}
	if(a3) {plotPathSegment(u3,t3,a3);}
	if(a4) {plotPathSegment(u4,t4,a4);}
	if(a5) {plotPathSegment(u5,t5,a5);}
	}
//
function plotPathSegment(u,t,a) {
	if(!a) {return;}
	var tit = "";if(t) {tit = " title=\""+t+"\"";}
	if(u) {dw(" / <a href=\""+u+"\""+tit+">"+a+"</a>");}
	else {dw(" / <strong>"+a+"</strong>");}
	}
//
//	Load related links data
//
var othLinks = new Array();
var ctr = 0;
//
function loadLink(linkid,linkurl,linktitle,linktext,linkblurb)	{
	this.linkid		= linkid;
	this.linkurl	= linkurl;
	this.linktitle	= linktitle;
	this.linktext	= linktext;
	if(!linkblurb)	{linkblurb = linktitle;}
	this.linkblurb	= linkblurb;
	}
//
function getNextLink(thislink) {
	for(var q=0;q<othLinks.length;q++)
		{if(othLinks[q].linkid == thislink)
			{var nq = eval(q+1);
			if((nq<othLinks.length) && (othLinks[nq].linkurl))
				{return "<a href=\""+othLinks[nq].linkurl+"\" "
					+ "title=\""+othLinks[nq].linktitle+"\""
					+ ">&raquo; NEXT &raquo; "+othLinks[nq].linktext+" &raquo;</a>";
				}
			}
		}
	return "";
	}
//
function doRelatedLinks(thislink) {
	loadRelatedLinks();
	if(getObjectByAnyMeans(thislink)) {switchClass(thislink,'thispage');}
	if(!othLinks.length) {return;}
	var nextLink = getNextLink(thislink);
	switchText('nextlink',nextLink);
	dw("<ul class=\"links\">\n<li><strong>Related articles,</strong> "
		+ "keep on reading...<br />"+nextLink+"</li>");
	var nlim = othLinks.length - 1;
	for(var q=0;q<=nlim;q++)
		{if(othLinks[q].linkid == thislink)
			{dw("<li><span class=\"grey\"><strong>This page:</strong><br />"
				+ othLinks[q].linktext+" - "+othLinks[q].linkblurb
				+ "</span></li>");
			continue;
			}
		var nextArt = "";
		if(q == nlim) {nextArt = "<strong>Next section...</strong><br />";}
		dw("<li>"+nextArt+"<a href=\""+othLinks[q].linkurl+"\" "
			+ "title=\""+othLinks[q].linktitle+"\" "
			+ ">"+othLinks[q].linktext+"</a> - "
			+ othLinks[q].linkblurb+"</li>");
		}
	dw("</ul>");
	}
//
//	Sliding lefthand navigation/links pane
//	(c) Andy Belcher 2006
//
var lBar;
var lBarId		= 'navbar';
var wrapId		= 'frame';
var topMarg		= 5;
var mvDelay		= 10;
var oldVPosn	= topMarg;
//
function initMvBar() {lBar = getObjectByAnyMeans(lBarId);mvLBar();}
//
function getScrollOffset() {
	if(window.innerHeight) {return window.pageYOffset;}
	if(document.documentElement && document.documentElement.scrollTop)
		{return document.documentElement.scrollTop;}
	if(document.body) {return document.body.scrollTop;}
	return 0;
	}
//
function mvLBar() {
	if(!lBar) {return;}
	var vPosn	= getScrollOffset();
	var lBarHgt	= getObjectByAnyMeans(lBarId).offsetHeight;
	var wrapHgt	= getObjectByAnyMeans(wrapId).offsetHeight;
	var maxPosn	= eval(wrapHgt - lBarHgt);
	//
	//	vPosn		is the vertical displacement of the screen, and therefore
	//				the amount by which the object must be moved up by.
	//
	//	lBarHgt	is the height of the object.
	//
	//	wrapHgt	is the Height of the main page container DIV
	//
	//	RULES:
	//	1:	vPosn always less than wrapHgt - lBarHgt
	//		prevents over-lap at the bottom
	//	2:	if lBarHgt > wrapHgt then NO Scroll
	//
	if(lBarHgt > wrapHgt)	{return;}
	if(vPosn < topMarg)		{vPosn = topMarg;} else {vPosn += topMarg;}
	if(vPosn > maxPosn)		{vPosn = maxPosn;}
	if(vPosn == oldVPosn)	{lBar.style.top = vPosn+"px";}
	oldVPosn = vPosn;temp = setTimeout('mvLBar()',mvDelay);
	}
//
function zeroScrollOffset() {
	if(window.innerHeight) {window.pageYOffset = "0px";}
	if(document.documentElement && document.documentElement.scrollTop)
		{document.documentElement.scrollTop = "0px";}
	if(document.body) {document.body.scrollTop = "0px";}
	return false;
	}
//
//	EOF
//
