// start by getting all the questions and answers
// these will be put into arrays

var titles = document.getElementsByTagName('dt');
var texts = document.getElementsByTagName('dd');


// function for the link that turns them all off
function toggleAllOff(){
	for (var i = 0; i < texts.length; i++) { 
		texts[i].className = 'hide';
	}
}

// function for the link that turns them all on
function toggleAllOn(){
	for (var i = 0; i < texts.length; i++) { 
		texts[i].className = 'show';
	}

}


function toggleNext(el) {
 var next=el.nextSibling;

 next.style.display=((next.style.display=="none") ? "block" : "none");
}


//makes the definition lists click-able
function displayToggle(){
	
	toggleAllOff(); // calls the toggle all off function to turn all the texts off when the page is loaded	
	 
	 for (i=0; i<titles.length; i++) { // loops through the titles a
		 titles[i].onclick=function() { // shows the texts onclick
		 	var next = this.nextSibling;
			while(next.nodeType != 1) next=next.nextSibling; // if it gets to a non-element node, go to the next one
			next.className=((next.className=="hide") ? "show" : "hide");
		}
	 }
}

// initiates the click-able dt's when the page loads
window.onload=function() {
	displayToggle();
	toggleAllOn()
	}

/* Alternate hide/show function (Jelle Aret <jelle.aret@hinttech.com>) */
function toggleDisplayElement(id) {
	element = document.getElementById(id);
	if (element != null) {
		if (isElementHidden(element)) {
			showElement(element);
		}
		else {
			hideElement(element);
		}
	}
}

function isElementHidden(element) {
	if (element != null && (element.style.display == 'none' || element.style.display == 'hidden')) {
		return true;
	}
	return false;
}

function showElement(element) {
	if (element != null) {
		element.style.display = ''; // Default for every browser
	}
}

function hideElement(element) {
	if (element != null) {
		element.style.display = 'none';
	}
}

function showClassName(id) {
	element = document.getElementById(id);
	if (element != null) {
		element.className = 'open';
	}
}
    
var ShowOrCollapseIds_Status = true;

function ShowOrCollapseIds(list) {
	if (!ShowOrCollapseIds_Status) {
		for (id in list) {
			showClassName(list[id]);
		}
		ShowOrCollapseIds_Status = true;
	}
	else {
		for (id in list) {
			hideClassName(list[id]);
		}
		ShowOrCollapseIds_Status = false;
	}
}

function ExpandOrCollapseAll(id, strExpand, strCollapse) {
	element = document.getElementById(id);
	if (element != null) {
		if (!ShowOrCollapseIds_Status) {
				element.innerHTML = strCollapse;
				element.className = 'open';
		} else {
				element.innerHTML = strExpand;
				element.className = 'closed';
		}
	}
}

function hideClassName(id) {
	element = document.getElementById(id);
	if (element != null) {
		element.className = 'closed';
	}
}
    
function toggleClassName(id, className1, className2) {
	element = document.getElementById(id);
	if (element != null && className1 != null && className2 != null) {
		if (element.className == className1) {
			element.className = className2;
		}
		else {
			element.className = className1;
		}
	}
}

function toggleIdName(idName1, idName2) {
	if (idName1 != null && idName2 != null) {
		element = document.getElementById(idName1);
		if (element == null) {
			element = document.getElementById(idName2);
			if (element != null) {
				element.id = idName1;
			}
		}
		else {
			element.id = idName2;
		}
	}
}

//Function for iguana stock images
function ShowStocks()
{

//Set vars used
var stock = document.formstock.stock.value;
var stockdate = document.formstockdate.stockdate.value;
var iof_title = document.getElementById("iof_title");
var iof_intro = document.getElementById("iof_intro");
var iif_title = document.getElementById("iif_title");
var iif_intro = document.getElementById("iif_intro");
var ilf_title = document.getElementById("ilf_title");
var ilf_intro = document.getElementById("ilf_intro");
var ief_title = document.getElementById("ief_title");
var ief_intro = document.getElementById("ief_intro");
var ihf_title = document.getElementById("ihf_title");
var ihf_intro = document.getElementById("ihf_intro");

//Change the stock table with selected stock
var stockimg = document.getElementById("stockimg");
stockimg.setAttribute("src", "http://charts.iguana2.com/ing/quote/" + stock);
stockimg.setAttribute("alt", stock + " Quotes");

//Change the interactive chart with selected stock and date
var stockdateimg = document.getElementById("stockdateimg");
stockdateimg.setAttribute("src", "http://charts.iguana2.com/ing/chart/" + stock + "/" + stockdate);
stockdateimg.setAttribute("alt", stock + " Interactive Chart");


//Change title and intro text
if (stock == "iof"){ 
  iof_title.style.display='inline';
  iof_intro.style.display='inline';
  iif_title.style.display='none';
  iif_intro.style.display='none';
  ilf_title.style.display='none';
  ilf_intro.style.display='none';
  ief_title.style.display='none';
  ief_intro.style.display='none';
  ihf_title.style.display='none';
  ihf_intro.style.display='none';
}
if (stock == "iif"){ 
  iof_title.style.display='none';
  iof_intro.style.display='none';
  iif_title.style.display='inline';
  iif_intro.style.display='inline';
  ilf_title.style.display='none';
  ilf_intro.style.display='none';
  ief_title.style.display='none';
  ief_intro.style.display='none';
  ihf_title.style.display='none';
  ihf_intro.style.display='none';
}
if (stock == "ilf"){ 
  iof_title.style.display='none';
  iof_intro.style.display='none';
  iif_title.style.display='none';
  iif_intro.style.display='none';
  ilf_title.style.display='inline';
  ilf_intro.style.display='inline';
  ief_title.style.display='none';
  ief_intro.style.display='none';
  ihf_title.style.display='none';
  ihf_intro.style.display='none';
}
if (stock == "ief"){ 
  iof_title.style.display='none';
  iof_intro.style.display='none';
  iif_title.style.display='none';
  iif_intro.style.display='none';
  ilf_title.style.display='none';
  ilf_intro.style.display='none';
  ief_title.style.display='inline';
  ief_intro.style.display='inline';
  ihf_title.style.display='none';
  ihf_intro.style.display='none';
}
if (stock == "ihf"){ 
  iof_title.style.display='none';
  iof_intro.style.display='none';
  iif_title.style.display='none';
  iif_intro.style.display='none';
  ilf_title.style.display='none';
  ilf_intro.style.display='none';
  ief_title.style.display='none';
  ief_intro.style.display='none';
  ihf_title.style.display='inline';
  ihf_intro.style.display='inline';
 }
}