window.onload = function(){
	var hash = window.location.hash;
	if(hash!=null && hash!="" && hash.indexOf("#q")==0){
		var questionAnchor = hash.replace("#","");
		var answerAnchor = hash.replace("#q","a");
		if($(answerAnchor)){
			toggleAnswer(answerAnchor);
			new Effect.ScrollTo(questionAnchor,{duration:0.0,offset:0});
		}
	}
	
	// attach onclick to all "questions"
	var questionLinks = document.getElementsByClassName('question');
	questionLinks.each(
		function(qLink){
			var answerDivId = 'a' + qLink.id.substr(1,qLink.id.length-1); // convert to the Answer ID
			Event.observe(qLink,'click',function(){toggleAnswer(answerDivId);return false;},false);
		}
	);
	
	// attach onclick close to close buttons
	if(document.getElementById('closebutton')){Event.observe($('closebutton'),'click',function(){window.close()},false);}
}

function toggleAnswer(answerID){

	var parentLi = $(answerID).parentNode;
	while (parentLi.tagName.toLowerCase()!="li"){// loop to find LI ancestor element
		if(parentLi.parentNode.nodeType!=1){
			break;
		}
		else {
			parentLi = parentLi.parentNode;
		}
	}
	if(parentLi.nodeType==1 && parentLi.tagName.toLowerCase()=="li"){
		if (Element.hasClassName($(parentLi),"showAnswer")){
			Element.removeClassName($(parentLi),"showAnswer");
		}
		else {
			Element.addClassName($(parentLi),"showAnswer");
		}
	}
	return false;
}

function loadNewOpenerPage (newurl){
	if(window.opener){
		window.opener.location.href = newurl;
		window.opener.focus();
	}
}

function newWindow(URL){
	var newwin = window.open(URL, "helfaq", "height=530,width=700,location=no,scrollbars=yes,menubars=no,toolbar=no,resizable=yes,status=yes");
	newwin.focus();
}
