/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var dhtmlgoodies_slideSpeed = 10;	// Higher value = faster
var dhtmlgoodies_timer = 7;	// Lower value = faster

var objectIdToSlideDown = false;
var dhtmlgoodies_activeId = false;
var dhtmlgoodies_slideInProgress = false;
var divCounter = 0;
var expand_status_1 = "0";
var expand_status_2 = "0";
var expand_status_3 = "0";

var num_datapoint_1 = "0";
var num_datapoint_2 = "0";
var num_datapoint_3 = "0";


function initShowHideDivs()
{
	var divs = document.getElementsByTagName('DIV');
	
	for(var no=0;no<divs.length;no++){
		//alert(divs[no].className);
		if(divs[no].className=='dhtmlgoodies_question'){
			divCounter++;
			divs[no].onclick = showHideContent;
			divs[no].id = 'dhtmlgoodies_q'+divCounter;
			var answer = divs[no].nextSibling;
			while(answer && answer.tagName!='DIV'){
				answer = answer.nextSibling;
			}
			answer.id = 'dhtmlgoodies_a'+divCounter;	
			contentDiv = answer.getElementsByTagName('DIV')[0];
			contentDiv.style.top = 0 - contentDiv.offsetHeight + 'px'; 	
			contentDiv.className='dhtmlgoodies_answer_content';
			contentDiv.id = 'dhtmlgoodies_ac' + divCounter;
			//alert(contentDiv.id)
			answer.style.display='none';
			answer.style.height='1px';
			
		}		
	}
	//document.getElementById('expand').style.display = "block";
	//document.getElementById('collapse').style.display = "none";
	expand_collapse('collapsed', 1);
	//expand_collapse('collapsed', 2);
	//expand_collapse('collapsed', 3);
}

function showHideContent(e,inputId)
{
	//alert(e+" "+inputId)
	if(dhtmlgoodies_slideInProgress)return;
	dhtmlgoodies_slideInProgress = true;
	if(!inputId)inputId = this.id;
	inputId = inputId + '';
	var numericId = inputId.replace(/[^0-9]/g,'');
	var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);

	objectIdToSlideDown = false;
	//alert(answerDiv);
	if(!answerDiv.style.display || answerDiv.style.display=='none'){		
		if(dhtmlgoodies_activeId &&  dhtmlgoodies_activeId!=numericId){			
			objectIdToSlideDown = numericId;
			slideContent(dhtmlgoodies_activeId,(dhtmlgoodies_slideSpeed*-1));
			//alert(dhtmlgoodies_activeId+" "+numericId);
		}else{
			
			answerDiv.style.display='block';
			answerDiv.style.visibility = 'visible';
			//alert(dhtmlgoodies_activeId+" "+numericId);
			slideContent(numericId,dhtmlgoodies_slideSpeed);
		}
	}else{
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));
		dhtmlgoodies_activeId = false;
	}	
}

function slideContent(inputId,direction)
{
	
	var obj = document.getElementById('dhtmlgoodies_a' + inputId);
	var contentObj = document.getElementById('dhtmlgoodies_ac' + inputId);
	height = obj.clientHeight;
	if(height==0)height = obj.offsetHeight;
	height = height + direction;
	rerunFunction = true;
	if(height>contentObj.offsetHeight){
		height = contentObj.offsetHeight;
		rerunFunction = false;
	}
	if(height<=1){
		height = 1;
		rerunFunction = false;
	}

	obj.style.height = height + 'px';
	var topPos = height - contentObj.offsetHeight;
	if(topPos>0)topPos=0;
	contentObj.style.top = topPos + 'px';
	if(rerunFunction){
		setTimeout('slideContent(' + inputId + ',' + direction + ')',dhtmlgoodies_timer);
	}else{
		if(height<=1){
			obj.style.display='none'; 
			if(objectIdToSlideDown && objectIdToSlideDown!=inputId){
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.display='block';
				document.getElementById('dhtmlgoodies_a' + objectIdToSlideDown).style.visibility='visible';
				slideContent(objectIdToSlideDown,dhtmlgoodies_slideSpeed);				
			}else{
				dhtmlgoodies_slideInProgress = false;
			}
		}else{
			dhtmlgoodies_activeId = inputId;
			dhtmlgoodies_slideInProgress = false;
		}
	}
}

// Added by Dibyendu
function showAll(st)
{
	//alert(divCounter)
	//alert(e+" "+inputId)
	var inputId = 1;
	for(var s=0; s<divCounter; s++)
	{
		//if(dhtmlgoodies_slideInProgress)return;
		//dhtmlgoodies_slideInProgress = true;
		if(!inputId)inputId = this.id;
		inputId = inputId + '';
		var numericId = inputId.replace(/[^0-9]/g,'');
		//alert(numericId)
		var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
		objectIdToSlideDown = false;
		
		answerDiv.style.display='block';
		answerDiv.style.visibility = 'visible';
		//alert(dhtmlgoodies_activeId+" "+numericId);
		slideContent(numericId,dhtmlgoodies_slideSpeed);
		
		inputId++;
		
		
	
	}
	
	expand_collapse('expanded', st);
}

// Added by Dibyendu

function hideAll(st)
{
	//alert(e+" "+inputId)
	var inputId = 1;
	for(var s=0; s<divCounter; s++)
	{
		//if(dhtmlgoodies_slideInProgress)return;
		//dhtmlgoodies_slideInProgress = true;
		if(!inputId)inputId = this.id;
		inputId = inputId + '';
		var numericId = inputId.replace(/[^0-9]/g,'');
		//alert(numericId)
		var answerDiv = document.getElementById('dhtmlgoodies_a' + numericId);
	
		objectIdToSlideDown = false;
		slideContent(numericId,(dhtmlgoodies_slideSpeed*-1));

		dhtmlgoodies_activeId = false;
		inputId++;
	
	}	

	expand_collapse('collapsed', st);
}

function expand_collapse(cs, st)
{
	//alert(cs+' '+st)
	for(var p=1; p<=3; p++)
	{
		var eid = 'expand_'+p;
		var cid = 'collapse_'+p;
		
		if(cs == 'collapsed')
		{
			if(eid != null)
				document.getElementById(eid).style.display = "block";
			if(cid != null)
				document.getElementById(cid).style.display = "none";
		}
		else
		{
			if(st == p)
			{
				if(eid != null)
					document.getElementById(eid).style.display = "none";
				if(cid != null)
					document.getElementById(cid).style.display = "block";
			}
			else
			{
				if(eid != null)
					document.getElementById(eid).style.display = "block";
				if(cid != null)
					document.getElementById(cid).style.display = "none";
			}
			
		}

	}	
}

window.onload = initShowHideDivs;

