// JavaScript Document

window.onload = init;

function init(){
	printLink();
	if(document.getElementById("help")){setupHelp();}	
}

function printLink(){
	var linkEl, pri
	if(pri = document.getElementById("print")){
		linkEl = document.createElement("a");
		linkEl.setAttribute("href","javascript:self.print()");
		linkEl.appendChild(document.createTextNode("Print this page"));
		pri.appendChild(linkEl);
		pri.removeChild(pri.firstChild);
	};
};

// HELP SETUP
function setupHelp(){
	document.getElementById("help").className = "hide";

	var h = new Array();
	var targ = new Array();

	for(i=0;i<help.length;i++){
		j=i+1;
		h[i]=crteHelp(help[i]+"H",j);	
		targ[i] = document.getElementById(help[i]);
		targ[i].appendChild(h[i]);
	};
};


function crteHelp(f,num){
//Grab text from help divs
src = document.getElementById("help"+num+"");
headers = src.getElementsByTagName("h3");
head = headers[0].innerHTML;
paras = src.getElementsByTagName("p");
p = paras[0].innerHTML;

	
//Create Div tag
hT = document.createElement("div");
hT.id = f;
hT.className = "help hide";

//Create H3 tag
hTh = document.createElement("h3");
hTh.innerHTML = head;

//Create P tag
hTp = document.createElement("p");
hTp.appendChild(document.createTextNode(p));

//Create close link
hTu = document.createElement("ul");
hTli = document.createElement("li");
hTa = document.createElement("a");
hTa.appendChild(document.createTextNode("Close"));
hTa.href = "javascript:hideHelp('"+f+"');"
hTli.appendChild(hTa);
hTu.appendChild(hTli);

//Put it all together
hT.appendChild(hTh);
hT.appendChild(hTp);
hT.appendChild(hTu);

return hT;
}

function showHelp(lyr){
for(i=0;i<help.length;i++){hideHelp(help[i]+"H");}
h = document.getElementById(lyr);
if(h){h.className="help"}
}

function hideHelp(lyr){
h = document.getElementById(lyr);
if(h){h.className="help hide"}
}