// -------------------------------------------------------------------
// Switch Content Script- By Dynamic Drive, available at: http://www.dynamicdrive.com
// -------------------------------------------------------------------

function switchcontent(className, filtertag){
	this.className=className;
	this.collapsePrev=false;
	this.filter_content_tag=(typeof filtertag!="undefined")? filtertag.toLowerCase() : "";
}

switchcontent.prototype.setStatus=function(openHTML, closeHTML){ 
	this.statusOpen=openHTML;
	this.statusClosed=closeHTML;
}

switchcontent.prototype.collapsePrevious=function(bool){ 
	this.collapsePrev=bool;
}

switchcontent.prototype.togglestatus=function(header, status){
	if (typeof this.statusOpen!="undefined")
		header.firstChild.innerHTML=status;
}


switchcontent.prototype.contractcontent=function(header){
	var innercontent=document.getElementById(header.id.replace("-title", ""));
	innercontent.style.display="none";
	this.togglestatus(header, this.statusClosed);
}


switchcontent.prototype.expandcontent=function(header){
	var innercontent=document.getElementById(header.id.replace("-title", ""));
	innercontent.style.display="block";
	this.togglestatus(header, this.statusOpen);
}


switchcontent.prototype.toggledisplay=function(header){
	var innercontent=document.getElementById(header.id.replace("-title", ""));
	if (innercontent.style.display=="block"){
		this.contractcontent(header);
	}else{
		this.expandcontent(header);		

		var id=header.id.replace("faqtable_", "");
		id=id.replace("-title", "");
		returnreply('replyview_'+id, id);
		
		if (this.collapsePrev && typeof this.prevHeader!="undefined" && this.prevHeader.id!=header.id)
			this.contractcontent(this.prevHeader);
	}
	if (this.collapsePrev)
		this.prevHeader=header;
}


switchcontent.prototype.collectElementbyClass=function(classname){ 
	var classnameRE=new RegExp("(^|\\s+)"+classname+"($|\\s+)", "i");
	this.headers=[], this.innercontents=[];
	if (this.filter_content_tag!="")
		var allelements=document.getElementsByTagName(this.filter_content_tag);
	else 
		var allelements=document.all? document.all : document.getElementsByTagName("*");
	for (var i=0; i<allelements.length; i++){
		if (typeof allelements[i].className=="string" && allelements[i].className.search(classnameRE)!=-1){
			if (document.getElementById(allelements[i].id+"-title")!=null){ 
				this.headers[this.headers.length]=document.getElementById(allelements[i].id+"-title"); 
				this.innercontents[this.innercontents.length]=allelements[i]; 
			}
		}
	}
}

switchcontent.prototype.init=function(){
	var instanceOf=this;
	this.collectElementbyClass(this.className);
	if (this.headers.length==0) 
		return;
	
	for (var i=0; i<this.headers.length; i++){
			this.contractcontent(this.headers[i]);
			this.headers[i].onclick=function(){instanceOf.toggledisplay(this)}
	}

}
