/**
 * @author simon.gilhooly
 */
window.onload = collapse;

function toggle(secid) {
	var sectionId = document.getElementById(secid);
	if (sectionId != null){
		if (sectionId.style.display == '') 
		{
			sectionId.style.display = 'none';
			var ImgSrc = document.getElementById("i" + secid);
			ImgSrc.src = "images/plus.gif";
		}
		else
		{
			sectionId.style.display = '';
			var ImgSrc = document.getElementById("i" + secid);
			ImgSrc.src = "images/minus.gif";
		}
	} 
}

function hide(obj){
	var oDiv = document.getElementById(obj);
	if(oDiv != null){
		oDiv.style.display = "none";
	}
}

function startA(id){
	document.write('<a href="javascript:toggle(\'' + id + '\')" style="text-decoration:none;">');
}

function endA(){
	document.write('</a>');
}

function writePM(id){
	var isPF = (typeof(IsPrinterFriendly) != "undefined");
	document.write('<a href="javascript:toggle(\'s' + id + '\')"><img border="0" id="is' + id + '" src="images/'+(isPF?'minus':'plus')+'.gif"></a>');
}

function chkHide(id){
	var isPF = (typeof(IsPrinterFriendly) != "undefined");
	if(document.getElementById && !isPF){
		hide(id);
	}
}


function collapse(){
	var count = 0;
	var reports = new Array();
	var myReportText;
	var toggleLinkFrag = document.createDocumentFragment();		//prepare an empty document fragment
	var myAnchor = document.createElement("a");					//create a blank anchor element
	var myImg = document.createElement("img");					//create a blank img element
	myImg.setAttribute("src", "images/plus.gif");				//set the image source for the element
	
	reports = document.getElementsByTagName("div");
	if (reports.length > 0) {
		for (var i = 0; i < reports.length; i++) {
			if (reports[i].className == "report"){
				count++;							//now we know how many reports there are in total we can target them in turn
			}
		}
		for (i = 0; i < count; i++) {
			myReportText = document.getElementById("text"+i);
			myReportText.style.display = "none";
			myAnchor.setAttribute("href", "javascript:toggle('text" + i + "');");
			myImg.setAttribute("id", "itext" + i);
			myAnchor.appendChild(myImg);								//append the image element onto the anchor
			toggleLinkFrag.appendChild(myAnchor);						//append the anchor to the fragment
			var myReport = document.getElementById("intro" + i);		//get the place where we want to add the fragment	
			myReport.appendChild(toggleLinkFrag.cloneNode(true));		//append the fragment into the main document
		}
	}
	// alert("There are " + reports.length + " divs of which " + count + " are reports.");
}
