var clicktimer

var filename = location.pathname.split("/")
var listid = stringFilter(filename[filename.length-1])


// Special cases
// Home finder
if ( listid.indexOf("AGEDCARE") >= 0 ) listid = "AGEDCAREHOMES"
if ( listid.indexOf("MATCHINGHOMES") == 0 ) listid = "AGEDCAREHOMES"
// Common questions
x = listid.indexOf("SUMMARY")
if ( x >= 0 ) {
	z = listid.substr(0,x)
	listid = z
}
x = listid.indexOf("ALL")
if ( x == 0 ) {
	z = listid.substr(3,listid.length-1)
	listid = z
}

var openCats
openCats = readCookie("opencat"+listid)
var fullCatList = "--"
var newOpenCats = "--"

window.onunload = function() { 

createCookie("opencat"+listid, openCats) 

}

function stringFilter (input) {
	acceptableValues = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
	var i
	var returnString = ""
	for (i=0; i < input.length; i++) {
		var c = input.charAt(i)
		if (acceptableValues.indexOf(c) >= 0) returnString += c
	}
	return returnString.toUpperCase()
}

function toggleCategory (arg) {
	var obj = arg = arg.parentNode
	var catName = ""
	var newOpenCats = ""
	var img = "../AttachmentsByTitle/close/$file/close.gif", disp = "block", imt
	while ( obj.tagName != "DIV" ) {
		obj = obj.nextSibling	
	}
	if ( obj.style.display == "block" || !obj.style.display) {
		disp = "none"
		img = "../AttachmentsByTitle/expand/$file/expand.gif"
	}
	obj.style.display = disp
	arg.getElementsByTagName("img")[0].src = img
	catName = stringFilter(arg.getElementsByTagName('A')[1].innerHTML)
	n = openCats.indexOf("--" + catName + "--")
	if ( disp == "none" ) {
		if (n >= 0) {
			newOpenCats = openCats.replace("--"+catName+"--", "--")
		}
	} else {
		if ( n < 0 ) {
			newOpenCats = openCats + catName + "--"
		}
	}
	if ( newOpenCats == "" ) {
		newOpenCats = openCats
	}
	openCats = newOpenCats
	return false
}

function expCon(arg, act) {
	var disp = "none", img = "../AttachmentsByTitle/expand/$file/expand.gif";
	if ( act == "e" ) {
		disp = "block";
		img = "../AttachmentsByTitle/close/$file/close.gif";
		openCats = fullCatList
	} else {
		openCats = "--"
	}
	
	var obj = arg.parentNode.parentNode.firstChild;
	while ( obj ) {
		if ( obj.tagName == "DIV" ) {
			obj.style.display = disp;
		}
		if ( obj.className == "catHead" ) {
			obj.getElementsByTagName("IMG")[0].src = img;
		}
		obj = obj.nextSibling;
	}
	return false;
}

function catlnks() {
	var open = 0
	if ( !openCats ) {
		openCats = "--"
	}

	dgei('expcon').innerHTML = '<p>Click a category to view its details.</p><a href="#" onclick="return expCon(this, \'e\')">Open all<\/a> | <a href="#" onclick="return expCon(this)">close all<\/a><br>';

	var togstt = '<a href="#" onclick="if (!clicktimer) { toggleCategory(this); clicktimer=setTimeout(\'clicktimer = null\',300)}; return false">';
	
	var obj = dgei('catlst').firstChild;
	
	while ( obj ) {
		if ( obj.className == "catHead" ) {
			var k = stringFilter(obj.innerHTML)
			if ( openCats.indexOf("--"+k+"--") > -1 ) {
				open = 1;
			} else {
				open = 0;
			}
			fullCatList = fullCatList + k + "--"
			obj.innerHTML = togstt + '<img src="../AttachmentsByTitle/' + (open?'close/$file/close.gif':'expand/$file/expand.gif') + '"></a>' + "&nbsp;" + togstt + obj.innerHTML + '</a>';
		}
		if ((obj.className == "tableOuter" || obj.className == "tableService") && open == 0 ) {
			obj.style.display = "none";
		}
		obj = obj.nextSibling;
	}

	return  false;
}