/*
05/08/2005	RB	Added browser detection to showall function to cope with buggy implemtation of substr in IE.
04/08/2005	RB	Added showall function
*/

var csec = 20;

function startup() {
	if ( document.forms[0] ) {
		document.forms[0].submittedBy.value = "user";
	}
}

function countdown() {
	//Countdown looptime.
	if ( document.forms[0] ) {
		if ( document.forms[0].response ) {
			// only do this if got a form with a response INPUT.  If not then reached the last statement
			window.setTimeout("countdown()",1000);
		}
	} else {
		// reached last statement - blank the timer display
		//displayTimer.innerHTML = "";
	}
	if ( csec == 0 )
	{
		document.forms[0].submittedBy.value = "js";
		document.forms[0].submit();
	} else {
		//if (!document.getElementById(containerId)) return false;
		//var displayTimer = document.getElementById("countdownTimer");
		//displayTimer.innerHTML = "<img src='../images/timer.jpg' alt='Countdown' align='absmiddle' width='16' height='16'> " +csec + " seconds remaining";
		csec--;
	}
}

var openPicture ="../images/minus.gif";
var closePicture ="../images/plus.gif";

function classoggle(tag, classa, classb) {
   if (tag.className==classa){
      tag.className=classb;
   } else {
      tag.className=classa;
}
}
function showall(doc) {
	var alldivs = doc.getElementsByTagName("div");
	for (var i = 0; i < alldivs.length; ++i){
		if ( alldivs[i].className == 'hideMe' | alldivs[i].className == 'showMe' ) {
			var thislink = document.getElementById("toggleAll");
			if ( alldivs[i].className == 'hideMe' ) {
				thislink.innerHTML = "Click here to hide all advice.";
			} else {
				thislink.innerHTML = "Click here to show all advice.";
			}
			// get attrib name of this DIV to use in image name
			var id = alldivs[i].getAttribute("id");
			var startOfAttribName = id.indexOf('attrib_') + 7; 
			var attribName = id.substr(startOfAttribName, id.length - startOfAttribName);
			var imgObj = document.getElementById( "img_attrib_" + attribName);
			visoggle("divDetail_attrib_" + attribName, imgObj);
		}
	}
}
function visoggle(index, me) {
	var d = document.getElementById(index);
	classoggle(d, 'hideMe', 'showMe');
	if (me!=undefined) {
		// src always returns an absolute URL so in order to allow openPicture / closePicture to be defined as relative URLs
		// we need to hack together a relative URL from the absolute URL of src.  Do this by testing the last 9 chars.  (9 because minus.gif = 9 chars)
		var endOfImgSrc = me.src;
		//IE's implementation of substr is different to Mozilla, etc! see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/js56jsmthsubstr.asp
		var browserName=navigator.appName;
		if ( browserName=="Microsoft Internet Explorer") {
			endOfImgSrc = endOfImgSrc.substr(endOfImgSrc.length - 9, 9)
			var endOfClosePicture = closePicture.substr(closePicture.length - 9, 9);
		} else {
			endOfImgSrc= endOfImgSrc.substr(-9);
			var endOfClosePicture = closePicture.substr(-9);
		}
		if (endOfImgSrc == endOfClosePicture){
			 me.src = openPicture; }
		else {
			me.src = closePicture;
		}
	}
}