/*
	Expandable Listmenu Script
	Author : Daniel Nolan
	http://www.dnolan.com/
*/

document.write('<style type="text/css">li.treenode ul, li.treenode ol {display: none;}</style>');

function initMenus() {
	if (!document.getElementsByTagName) return;
	
	var aMenus = document.getElementsByTagName("LI");
	for (var i = 0; i < aMenus.length; i++) {
		var mclass = aMenus[i].className;
		if (mclass.indexOf("treenode") > -1) {
			var submenu = aMenus[i].childNodes;
			for (var j = 0; j < submenu.length; j++) {
				if (submenu[j].tagName == "A") {
					
					submenu[j].onclick = function() {
						var node = this.nextSibling;
											
						while (1) {
							if (node != null) {
								if ((node.tagName == "UL") || (node.tagName == "OL")) {
									var d = (node.style.display == "none")
									node.style.display = (d) ? "block" : "none";
									this.className = (d) ? "treeopen" : "treeclosed";
									return false;
								}
								node = node.nextSibling;
							} else {
								return false;
							}
						}
						return false;
					}
					
					submenu[j].className = (mclass.indexOf("open") > -1) ? "treeopen" : "treeclosed";
				}
				
				if ((submenu[j].tagName == "UL") || (submenu[j].tagName == "OL"))
					submenu[j].style.display = (mclass.indexOf("open") > -1) ? "block" : "none";
			}
		}
	}
}

// tidy up fonts from JPS and admin tool
faceOff = function() {
	var fontecarlo = document.getElementsByTagName("FONT");
	for (var i=0; i<fontecarlo.length; i++) {
		fontecarlo[i].removeAttribute('face');
		fontecarlo[i].removeAttribute('color');
		fontecarlo[i].removeAttribute('size');
	}
}

// opens up new windows in a marginally nicer way than target attribute
function popup()
{
    if (document.getElementsByTagName) {
    a = document.getElementsByTagName("a");
    for(i=0; i<a.length; i++)
    {
        if(a[i].getAttribute("rel") && a[i].getAttribute("rel") == "external")
        {
            a[i].onclick = function()
            {
                window.open(this.getAttribute('href'));
                return false;
            }
        }
     }
     }
     else return false;
}

// removes the square border that IE
// insists on adding to checkboxes and radio
function removeCheckBoxBorders()
{
var el = document.getElementsByTagName("input");
for (i=0;i<el.length;i++)
  {
  var type = el[i].getAttribute("type");
  if((type=="checkbox")||(type=="radio"))
    {
   el[i].style.border = "none";
    }
  }
}

function focusFields () {
    if (!document.getElementsByTagName) return false;
    var inputfields = document.getElementsByTagName("input");
	var areaFields = document.getElementsByTagName("textarea");
        for (var i=0; i < inputfields.length; i++) {
                inputfields[i].onfocus = function() {
                        this.select();
                }
        }
        for (var i=0; i < areaFields.length; i++) {
                areaFields[i].onfocus = function() {
                        this.select();
                }
        }

}

function addLoadEvent(func) { 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') 
		{ window.onload = func; } 
	else 
		{ window.onload = function() 
			{ oldonload(); func(); } 
		}
	} 

addLoadEvent(initMenus); addLoadEvent(function() { 
	if (window.attachEvent) window.attachEvent("onload", popup);
	if (window.attachEvent) window.attachEvent("onload", focusFields);
	if (window.attachEvent) window.attachEvent("onload", faceOff);
	if (window.attachEvent) window.attachEvent("onload", removeCheckBoxBorders);
 }
);