// Basic Javascript Fuctions
function getElement(element) {
	if (document.getElementById) {
		return document.getElementById(element);
	}	
	else if (document.all) {
		return document.all(element);
	}
	else if (document.layers){
		return document.layers[element];
	}
	else {
		return null;
	}
}

function findAllTags(tagName) {
totalTags = document.getElementsByTagName(tagName);
	for (i = 0; i < totalTags.length; i++) {
		tagElem = totalTags[i];
		tagElem.id  = 'li'+i;
		if (tagElem.parentNode.className == 'qList' && tagElem.className != 'noRadio') {
			tagElem.setAttribute("onmouseover", "highlightOver(this.id);");
			tagElem.setAttribute("onmouseout", "highlightOut(this.id);");
			tagElem.setAttribute("onmousedown", "selectRadio(this.id);");
			}
		}
	}

function setExamTextSize(id) {
getElement(id).style.fontSize = '12px';
//getElement("arrowDown").src="/i/arrowDown_blue";
}

function textUp(id) {
var obj = getElement(id).style.fontSize;
	if (parseInt(obj) < 18) {
		getElement(id).style.fontSize = (parseInt(obj) + 2) + 'px'; 
		/*var legitimate = getElement(id).children.length;
		for(i=0; i<legitimate; i++) {
			//var obja = getElement(id).children[i].style.fontSize;
			getElement(id).children[i].style.fontSize = (parseInt(obj) + 2) + 'px'; 
		}*/
		getElement(id).style.fontSize = (parseInt(obj) + 2) + 'px'; 
	}
	/*if (parseInt(obj) >= 15) {
		getElement("arrowUp").src="/i/arrowUp_blue";
	}
	else { getElement("arrowUp").src="/i/arrowUp_wt"; } 
	if (parseInt(obj) < 11) {
		getElement("arrowDown").src="/i/arrowDown_blue";
	}
	else { getElement("arrowDown").src="/i/arrowDown_wt"; } 
	*/
	return true;
	}
	
function textDown(id) {
var obj = getElement(id).style.fontSize;
	if (parseInt(obj) > 12) {
		getElement(id).style.fontSize = (parseInt(obj) - 2) + 'px'; 
	}
	/*
	if (parseInt(obj) <= 13) {
		getElement("arrowDown").src="/i/arrowDown_blue";
	}
	else { getElement("arrowDown").src="/i/arrowDown_wt"; } 
	if (parseInt(obj) > 17) {
		getElement("arrowUp").src="/i/arrowUp_blue";
	}
	else { getElement("arrowUp").src="/i/arrowUp_wt"; } 
	*/
	return true;
	}

function highlightOver(id) {
	var colItem = getElement(id);
	//alert(colItem.parentElement.className);
	colItem.style.backgroundColor='#cceeff';
	return true;
	} 

function highlightOut(id) {
	var colItem = getElement(id);
	if (colItem.firstChild.checked) { colItem.style.backgroundColor='#eeeeee'; }
	
	
	else { colItem.style.backgroundColor='transparent'; }
	

	return true;
	}

function selectRadio(id) {
	var colItem = getElement(id);
	colItem.firstChild.checked=true;
	var currentQ = colItem.firstChild.name;
	var currentParent = colItem.parentNode.children;
	for (i=0; i<currentParent.length; i++) {
			
			if(currentParent[i].tagName == 'INPUT') {
				
				if (!currentParent[i].checked) {
					//alert('change');
				currentParent[i].parentNode.style.backgroundColor='transparent';
				//allInputs[allInputs.length+1] = currentParent.sourceIndex;
				}
			}
	}
	//alert(currentParent[0].tagName);
	return true;
	}

function highlightOutFaded(id) {
	var colItem = getElement(id);
	

	return true;
	}

function initializeTimer(timeOut, relocate, submitIt)
{	
	if(timeOut){
	
	timerID = null
	timerRunning = false
	delay = 1000;
	secs = timeOut;
	newLocation = relocate;
	submitName = submitIt;
    // Set the length of the timer, in seconds
	
    StopTheClock();
    StartTheTimer();
	}
}

function StopTheClock(){
    if(timerRunning){ clearTimeout(timerID); }
    timerRunning = false
}

function StartTheTimer(){
	if (secs==300 || secs==60){
	//creates an empty 200x120 window 
	sWidth = screen.width;
	sHeight = screen.height;
	boxWidth = 420;
	boxHeight = 130;
	xPos = (sWidth - boxWidth)/2;
	yPos = (sHeight - boxHeight)/2;
	//alertWin = window.open("/alert"+(secs/60)+"min.htm", "alertWindow", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+boxWidth+",height="+boxHeight+",left="+xPos+",top = "+yPos);
	//alertWin.document.write('poop');
	//alertWin.document.getElementById('title').innerText = 'poop';
	//var sendMsg = alertWin.msgDiv;
	if(secs>60){ 
	alert('You only have 5 minutes left');
	//alertWin = window.open("/alert5min.htm", "alertWindow", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+boxWidth+",height="+boxHeight+",left="+xPos+",top = "+yPos); 
	}
	else if(secs<=60){ 
	alert('You only have 1 minute left');
	//alertWin = window.open("/alert1min.htm", "alertWindow", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+boxWidth+",height="+boxHeight+",left="+xPos+",top = "+yPos); 
	}
	
	/*alertWin.document.write("<html><head><title>Alert</title>");
	alertWin.document.write("<style>.alertWin_tab { background:url(/i/lineBg.gif) repeat top left; font-family:\'Trebuchet MS\', Lucida Grande, Geneva, Arial, Verdana, sans-serif; color: #000;} \n .alertWin_msg { font-size:12px; font-weight:bold; } \n .alertWin_btn { text-align:right; }</style>");
	alertWin.document.write("</head><body><table class=\"alertWin_tab\" cellpadding=\"0\" cellspacing=\"0\"><tr><td rowspan=\"2\" width=\"90\"><img src=\"/i/clock.png\" alt=\"clock\" /></td><td class=\"alertWin_msg\" width=\"330\">");
	if(secs>60){ alertWin.document.write("You have "+Math.floor(secs/60)+" minutes left."); }
	else if(secs<=60){ alertWin.document.write("You have "+Math.floor(secs/60)+" minute left."); }
	alertWin.document.write("</td></tr><tr><td class=\"alertWin_btn\"><input type=\"submit\" value=\"OK\" onclick=\"window.close();\"/></td></tr></table></body></html>");*/
	//alertWin.focus(); //bring awin to the foreground
	}
    if (secs==0)
    {
        StopTheClock();
        // Here's where you put something useful that's
        // supposed to happen after the allotted time.
        // For example, you could display a message:
        alert("Your time has expired. Your current answers will be submited and the testing will be paused.");
		if(newLocation != ''){
		window.location.href = newLocation;
		}
		if(submitName != ''){
		
		}
		//document.exam.submitBtn.value = 'Submit';
		//document.exam.submit();
    	document.exam.submitBtn.click();
	}
    else
    {
		hours = Math.floor((secs/60)/60);
		minutes = Math.floor(secs/60);
		seconds = secs-(minutes*60);
		if(hours < 10){
			hours = '0'+hours	
		}
		if(minutes < 10){
			minutes = '0'+minutes	
		}
		if(seconds < 10){
			seconds = '0'+seconds	
		}
		phaseBar = getElement('phaseBarDiv');
		clockElement = getElement('timeRemaining');
		clockElement.innerHTML = 'Time Remaining - '+hours+':'+minutes+':'+seconds;
        self.status = hours+':'+minutes+':'+seconds;
        secs = secs - 1;
        timerRunning = true
        timerID = self.setTimeout("StartTheTimer()", delay);
    }
}

function getInfo(newURL) {
if(confirm("Are you sure you want to take this assesment now? \n\nIf you exit the exam page without submitting, your answers will NOT be saved. \n\nIf your time expires, your answers will be submitted and you will be returned to this page. \n\nYou will be given 45 minutes to complete this test.")){ window.location.replace( newURL ); } //If your question is answered Yes.
//else{ window.location.replace('/registration/step3/poop.php'); }
}

function getInfo2(newURL) {
if(confirm("Have you finished downloading and printing all of the required forms?")){ window.location.replace( newURL ); } //If your question is answered Yes.
}

function showErrors(id) {


}

function checkRegistration(){
	if (perInfoForm.email.value == '') {
		alert('poop');
		getElement('td_email').style.color = 'ff0000'; 
		return false;
	}
	return true;
}

function shiftFocus(curLen, len, field){
	if(curLen>=len){ 
	var shifter = 'document.perInfoForm.'+field+'.focus()';
	eval(shifter);
	}
}
function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}

function describe(x) {
	//alert(x.parentNode.style.backgroundColor);
	var firstCell = x.parentNode.parentNode.childNodes[0];
	var secondCell = x.parentNode.parentNode.childNodes[1];
	if (!x.parentNode.parentNode.childNodes[0].className) {
		firstCell = x.parentNode.parentNode.childNodes[1];
		secondCell = x.parentNode.parentNode.childNodes[3];
	}
	var description;
	for (i = 0; i < x.parentNode.childNodes.length; i++) {
		if (x.parentNode.childNodes[i].className == "description") {
			description = x.parentNode.childNodes[i];
			break;
		}
	}
	if (description.style.display == 'block') {
		description.style.display = 'none';
		x.parentNode.style.backgroundColor = "#fff";
		firstCell.className = 'start';
		secondCell.className = 'end';

	} else {
		description.style.display = 'block';
		x.parentNode.style.backgroundColor = "#f3f3f3";
		categoryColor = description.childNodes[description.childNodes.length - 1].className;
		firstCell.className = categoryColor;
		//firstCell.style.backgroundColor = '#dfe9cc';
		firstCell.style.color = '#000000';
		secondCell.className = categoryColor;
		//secondCell.style.backgroundColor = '#dfe9cc';
		secondCell.style.color = '#000000';
	}
}
function parEnter(e, area){
var key;

     if(window.event){ key = window.event.keyCode; }    //IE
     else { key = e.which; }     //firefox
	 
	 if(key == 13 || key == 3){ 
	 obj = area.value;
	 area.value = obj.substr(0, area.selectionStart)+'\r'+obj.substr(area.selectionStart, obj.length);
	 area.setSelectionRange(area.selectionStart+2, area.selectionStart+2);
	return false;  	
	}

		  
}
