//maked all added functions work onload. at the end of each function you want to work onload add addLoadEvent(function); to the end of the function.
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// The following two functions make it possible to have web standard popups
window.onload = function() {
  if (!document.getElementsByTagName) return false;
  var lnks = document.getElementsByTagName("a");
  for (var i=0; i<lnks.length; i++) {
    if (lnks[i].className == "popup") {
      lnks[i].onclick = function() {
        popUp(this.getAttribute("href"));
        return false;
      }
    }
    else if (lnks[i].className == "configurator") {
      lnks[i].onclick = function() {
        configUrator(this.getAttribute("href"));
        return false;
      }
    }
  }
}

function popUp(winURL) {
  window.open(winURL,"popup");
}
function configUrator(winURL) {
  window.open(winURL,"configurator","width=556,height=520,scrollbars=yes");
}

//scrolling on interior pages
function hideScrollBar() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById('cntntcpy')) return false;
	var cpyHght = document.getElementById("cntntcpy").offsetHeight;
	if (cpyHght > 219) {
		document.getElementById("scrllbr").style.display = 'block';
	}
}
addLoadEvent(hideScrollBar);

var timerID = null;
var pos = 0;
function sliderUp() {
	if ((pos * -1) > 0) {
		pos = eval(pos + 14);
	}
	if (document.getElementById) {
		document.getElementById("cntntcpy").style.top =	pos+"px";
	}
	timerID = window.setTimeout('sliderUp()',100);
}

function sliderDn() {
	if ((pos * -1) < (document.getElementById("cntntcpy").offsetHeight - 150)) {
		pos = eval(pos - 14);
	}
	if (document.getElementById) {
		document.getElementById("cntntcpy").style.top = pos+"px";
	}
	timerID = window.setTimeout('sliderDn()',100);
}


function terminateTimer() {
    window.clearTimeout(timerID);
}

//set graphical radio buttons
//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '../configurator/images/false.gif';
var imgTrue = '../configurator/images/true.gif';

//this function runs when the page is loaded, put all your other onload stuff in here too.
function init() {
    replaceSelected();
}
function replaceSelected() {    
	//get all the input fields on the page
	inputs = document.getElementsByTagName('input');
	//cycle trough the input fields
	for(var i=0; i < inputs.length; i++) {
		//check if the input is a radio button
		if(inputs[i].getAttribute('type') == 'radio') {
			//create a new image
			var img = document.createElement('img');
			//set radio button to false
			img.src = imgFalse;
			//set image ID and onclick action
			img.id = 'checkImage'+i;
			//set image
			img.onclick = new Function('radioChange('+i+')');
			//place image in front of the radio button
			inputs[i].parentNode.insertBefore(img, inputs[i]);
			//hide the radio button
			inputs[i].style.display='none';
		}
	}
}
//change the checkbox status and the replacement image
function radioChange(i) {
	//set all images to false
	inputs = document.getElementsByTagName('input');
	for(var j=0; j < inputs.length; j++) {
		document.getElementById('checkImage'+j).src=imgFalse;
	}
	//set image to true when a radio button is selected
	inputs[i].checked = 'checked';
	document.getElementById('checkImage'+i).src=imgTrue;
}
addLoadEvent(init);

//show and hide admissions faqs
function showHideFaqs() {
	if (!document.getElementById('faqsList')) return false;
	questions = document.getElementById('faqsList').getElementsByTagName('h5');
	answers = document.getElementById('faqsList').getElementsByTagName('p');
	showAll = document.getElementById('showallfaq');
	for (var i=0; i<answers.length; i++) {
		answers[i].style.display = 'none';
	}
	for (var i=0; i<questions.length; i++) {
		questions[i].onclick=function() {
			answ = getNextElement(this.nextSibling);
			if (answ.style.display != 'block') {
				for (var i=0; i<answers.length; i++) {
					answers[i].style.display = 'none';
				}
				answ.style.display = 'block';
			} else {
				answ.style.display = "none";
			}		
		}
	}
	toggleAll();
}
addLoadEvent(showHideFaqs);

function getNextElement(node) {
	if(node.nodeType == 1) {
	return node;
	}
	if (node.nextSibling) {
		return getNextElement(node.nextSibling);
	}
	return null;
}

function toggleAll() {
	answers = document.getElementById('faqsList').getElementsByTagName('p');
	showAll.onclick=function() {
		if (showAll.innerHTML != 'Hide All Answers') {
			for (var i=0; i<answers.length; i++) {
				answers[i].style.display = 'block';
			}
			showAll.innerHTML = 'Hide All Answers';
		} else {
			for (var i=0; i<answers.length; i++) {
				answers[i].style.display = 'none';
			}
			showAll.innerHTML = 'Show All Answers';	
		}
	}
}