//	$Id: general.js 1337 2007-08-15 15:45:19Z webdev2 $
//	general javascript 

window.onload = function(){
	if(!document.getElementById)
		return;
	// initialiseNavigation();			
	insertButtons();

	if(document.getElementById("loginForm"))
		document.getElementById("Email").focus();
	
	if(this.secondOnload)
		this.secondOnload();		
	if(this.initialiseDataEntry)	
		this.initialiseDataEntry();
}

function getElementList(pParentElement, pTagName) // return real array from tagname query
{
	vFilterList = pParentElement.getElementsByTagName(pTagName);
	vElementList = new Array();
	for(i=0; i < vFilterList.length; i++)
		vElementList.push(vFilterList[i]);
	return vElementList;
}

function initialiseNavigation()
{
	// primary:
	vNavigation = document.getElementById("navigation");

	vAnchorList = getElementList(vNavigation, "a");	
	while(vAnchor = vAnchorList.pop())
	{
		if(vAnchor.className == "noHover")
			continue; 
			
		if(vAnchor.href == window.location.href)
		{
			vAnchor.removeAttribute("href"); // kill link
			vAnchor.className = "current";			
			continue;
		}
	}

	// secondary:
	vAnchorList = getElementList(document.getElementById("secondaryNavigation"), "a");			
	while(vAnchor = vAnchorList.pop())
	{
		if(vAnchor.href == window.location.href)
		{
			vAnchor.className = "current";
			vAnchor.removeAttribute("href"); // kill link
			break;
		}
	}
	
	// hover-activation effect for collapsed navigation:
	if(document.getElementsByTagName("body")[0].className.match(/collapsed/))
	{
		vLIList = getElementList(vNavigation, "li");
		while(vListItem = vLIList.pop())
		{
			if(vListItem.parentNode != vNavigation)
				continue; // immediate children only

			vListItem.onmouseover = function(){
				vSiblingList = getElementList(this.parentNode, "li");
				while(vSibling = vSiblingList.pop())
					vSibling.className = "";
					
				this.className = "activated";
			}
		}		
	}
}

function insertButtons()
{
	vFilterList = document.getElementsByTagName("a");
	vAnchorList = new Array();
	for(i=0; i < vFilterList.length; i++)
		vAnchorList.push(vFilterList[i]);

	while(vAnchor = vAnchorList.shift())
	{
		if(!vAnchor.className.match(/\bbutton\b/))
			continue;
		vButton = document.createElement("input");
		vButton.type = "button";
		vButton.className = vAnchor.className;
		vButton.value = vAnchor.firstChild.nodeValue;
		vButton.href = vAnchor.href; 
		vButton.onclick = linkButtonClick;
		vAnchor.parentNode.replaceChild(vButton, vAnchor);
	}
}

function linkButtonClick()
{
	document.location = this.href;
}

function pad(pNumber) 
{ 
	return (pNumber < 10) ? '0' + pNumber : '' + pNumber; 
}

function arrowClick(obj, img, sect)
{	
	var el = document.getElementById(obj);
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
		el.style.width = '200';
		img.src = "/images/arrows/aro_" + sect + "_r.gif";
	}
	else {
		el.style.display = 'inline';
		el.style.width = '200';
		img.src = "/images/arrows/aro_" + sect + "_d.gif";
	}
}

