var frm, numTries, numQuestions, isLoaded
function openLink(docLink){
	var x,y,w,h,l,t,strSettings
	x=screen.width;
	y=screen.height;
	w=0.8*x;
	h=0.7*y;
	l=.9*(x-w);
	t=.9*(y-h);
	strSettings = "scrollbars=yes, resizable=yes, status=yes, toolbar=yes, menubar=yes, toolbar=yes,width=" + w + ",height=" + h + ",left=" + l + ",screenX=" + w + "top=" + t + ",alwaysRaised='yes'"
	//alert(strSettings);
	alert('After you click the OK button on this message, a new window will open.\n\nThis may take some time.\n\nClose the new window to return to the orientation.\n\nPlease click OK now and wait for the window to open.')
	W=window.open(docLink,"_new",strSettings);
	W.focus();
}
function openVideo(docLink){
	var x,y,w,h,l,t,strSettings
	x=screen.width;
	y=screen.height;
	w=0.8*x;
	h=0.7*y;
	l=.9*(x-w);
	t=.9*(y-h);
	strSettings = "scrollbars=yes, resizable=yes, status=yes, toolbar=yes, menubar=yes, toolbar=yes,width=" + w + ",height=" + h + ",left=" + l + ",screenX=" + w + "top=" + t + ",alwaysRaised='yes'"
	//alert(strSettings);
	alert('After you click the OK button on this message, a video will load.\n\nThis may take some time.\n\nClose the video window to return to the orientation.\n\nPlease click OK now and wait for the video.')
	W=window.open(docLink,"_new",strSettings);
	W.focus();
}
function getScore(){
	var obj, question
	obj = top.frames.vars.document.varsForm
	numTries = Math.floor(0)
	numQuestions = Math.floor(0)
	for (i=0; i < obj.length; i++) {
		if (obj.elements[i].name.charAt(0) == "q") {
			numTries -= Math.floor(obj.elements[i].value)
			numQuestions += 1
		}
	}
}
function onlineLogin() {
	obj = top.frames.vars.document.varsForm
	if (document.all) {
		frmObj = loginForm;
		}
	else {
		frmObj = document.loginForm;
		}
	obj.stuID.value = frmObj.stuID.value
	obj.dob.value = frmObj.dob.value
}
function setUserType(userType) {
	obj = top.frames.vars.document.varsForm
	obj.userType.value = userType //0=student required, 1=student-not required, 2=guest
}
function openWindow(URL) {
	//W=window.open('','_new','toolbar=yes,scrollbars=yes,resizable=yes,status=yes,menubar=yes,location=no');
	W=window.open(URL,'_new','width=500,height=400,toolbar=yes,scrollbars=yes,resizable=yes,status=yes,menubar=yes,location=no');
	//W.dcoument.writeln("Hello")
}
function displayMsg(message){
	//document.getElementById('msg').value = "Video loading . . ."
	//openWindow('')
}
function displayVideoMsg(){
	alert('After you click the OK button on this message, a video will load.\n\nThis may take some time.\n\nClose the video window to return to the orientation.\n\nPlease click OK now and wait for the video.')
}
function onLoadEventHandler(pageNum) { 
	if (document.all) {
		frm = orientForm
		}
	else {
		frm = top.frames.content.document.orientForm
	}
	setRadioButton(pageNum);
	isLoaded = true
	loadIndicatorOn()
}

function reviewPg(page) {
	msg = "You are about to review a previous page\n\n"
	msg += "When you are finished, click the back button\n\n"
	msg += "on your browser.\n\n"
	msg += "Click OK now and wait for the page to load."
	alert(msg)
	location=page;
}
function prevPg(page) {
	if (location.search.indexOf('1-11.htm') != -1) { //if reviewing from pg 11, go back
		page = '1-11.htm'
	}
	location=page;
}
function nextPg(ans, page, pageNum) {
	if (!isLoaded) {
		location.reload()
	}
	else {
		if (ans != 999) { //!=999 means there is a question
			isCorrect = submitAnswer(ans, pageNum) //check ans, inc tries, and record if correct
			if (!isCorrect) { //if ans not correct, do not go to next page
				return
			}
		}
		obj = top.frames.vars.document.varsForm
		stuID = obj.stuID.value
		if (location.search.indexOf('1-11.htm') != -1) { //if reviewing from pg 11, go back
			page = '1-11.htm'
		}
		if (page.toLowerCase().indexOf('.asp') > 0) { //if next page is asp, pass vars to it
			if (stuID.toLowerCase() == 'guest') {
				msg = 'Thank you for taking the SMC Orientation.  We hope the information was useful.\n\n'
				msg = msg + 'Since you logged in as a guest, this does not satisfy the orientation requirement.\n'
				msg = msg + 'In order to complete the orientation requirement, students must sign on\n'
				msg = msg + 'using their assigned Student ID number and password, and complete the \n'
				msg = msg + 'orientation during the orientation period for the term for which\n'
				msg = msg + 'they are applying.'
				alert(msg)
				top.location = "http://www.smc.edu"
			}
			else {
				dob = obj.dob.value
				page += "?stuID=" + stuID 
				page += "&dob=" + dob
				getScore() //calc numTries and numQuestions
				page += "&numTries=" + numTries
				page += "&numQuestions=" + numQuestions
			}
		}
		location = page
	}
}
function makeReadOnly(){
	top.frames.categories.document.vars.readOnly.focus();
}
function incQuestion(qNum) { //add -1 to counter each time question is answered
	var obj, question
//alert("incQuestion()")
	obj = top.frames.vars.document.varsForm
//alert(obj.length)
	question = "q" + qNum
//	alert(question)
	n = 0;
	for (i=0; i < obj.length; i++) {
		if (obj.elements[i].name == question) {
//			alert(obj.elements[i].name)
			break;
			//n = i;
		}
	}
	if (obj.elements[i+1].value=="0") { //if question has not been answered correctly yet
		obj = obj.elements[i];
		obj.value = Math.floor(obj.value) - 1;
	}
}
function recordAnswer(ans, pageNum) {
	var obj, answerElement
	obj = top.frames.vars.document.varsForm
	answerElement = "a" + pageNum
	//n = 0;
	for (i=0; i < obj.length; i++) {
		if (obj.elements[i].name == answerElement) {
			break;
		}
	} 
	obj = obj.elements[i];
	obj.value = String.fromCharCode(ans);
}
function submitAnswer(ans, pageNum) {
	var obj
	ansIndex = ans - 97; //subtract ascii("a") to get index of correct answer
	incQuestion(pageNum); //increment the number of tries to answer this question
	if (frm.answer[ansIndex].checked==true) {//if student selected correct answer
		recordAnswer(ans, pageNum);
		alert(String.fromCharCode(ans) + " is correct!\n\nClick OK and wait for the next page to load.");
		return true
		}
	else {
		alert("That is not correct.  Please select another answer.");
		return false
		}
}
function setRadioButton(pageNum) {
	var obj, answerElement
	obj = top.frames.vars.document.varsForm
	answerElement = "a" + pageNum
	for (i=0; i < obj.length; i++) {//find answer user chose for this page
		if (obj.elements[i].name == answerElement) {
			break;
		}
	} 
	obj = obj.elements[i]
	if (obj) {
		ans = obj.value
		if (ans!="0") { //ans=="0" until question has been correctly answered
			index = ans.charCodeAt(0) - 97
			frm.answer[index].checked = true
		}
	}
}
function loadIndicatorOn() {
//	alert("loadIndicatorOn()")
//	alert(frm.loadIndicator.value)
//	frm.loadIndicator.value="loaded"
}