/* ======================================================================
DESC: symbolCheck.js

PLATFORMS: 

USAGE NOTES: 
====================================================================== */

/* ==================================================================""sendTo" is a variable which may contain an href (must include ".htm") or is seen as an alert message.				
====================================================================== */
var ans; var a= new Array;  var sent = new Array; var l; var p;var atomComp = new Array;
var el // ie5 complication:we need to have a global variable refering to the element just changed...
	var foc = 1 // sets the focus
function check(elmt) {
el=elmt
if (typeof numOfProbs == 'undefined') numOfProbs = 5
	var n = parseInt(elmt.name); var s = deSpace(elmt.value); 
	s = rewrite(s.toUpperCase());
	elmt.value = s;
	var h = s.charAt(0);	
	if ( h == '?' || h == '/') {
   		alertX("The expected answer is <P>\'" + cor[n] + "\'.<p>Please think about the answer, then <i>hide</i> this box and try again.")
		elmt.value='' // setTimeout("el.focus(); el.select();",1)
		foc=n+1
		}
	else if ( s == '' || s.charAt(s.length-1)=='?' ) {
		foc = '' + (n+1)
		setFocus()
		}
	else if ( s == cor[n] ) {
   		alertX("CORRECT! <p> \'" + s + "\' is the expected answer.");
		keepTrack(n)
		foc = numOfProbs
   		if ( n < numOfProbs - 1 ) foc=n+2
		else done() // just below for this function
		}
	else if ( !structureSL(s) ) {
   		alertX("\'" + s + "\' is not a sentence of SL.")
		el.value += '???'
		}

	else {
   window.status="...thinking...";
   sent[0] = s; 
   structureSL(cor[n]);
	sent[1] = cor[n];
   if (SLequiv()) {
   	window.status=''
   	alertX("CORRECT!  Your answer is equivalent to the expected:<p>\'" + cor[n] + "\'.")
	keepTrack(n)
   	if ( n < numOfProbs - 1 ) foc=n+2
	else done()
	}
	else {
		window.status=''
		alertX("Sorry.<p>Your answer is not equivalent to the expected answer.  Please try again.");
		el.value += '???'
		foc=n+1
		}
	}
}

function done() {
if (typeof sendTo == 'undefined') {}
else if (sendTo.indexOf('.htm')>-1) location = sendTo
else if (sendTo == 'Layer0') {	
	window.scroll(0,5000)
	MM_showHideLayers('Layer0','','show')
	}
else alertX(sendTo)
}

	var msgWindow=window.open("","alertWindow","resizable,status=yes,width=250,height=200")
	msgWindow.blur();self.focus()
function alertX(text) {
if (msgWindow.closed) {
	msgWindow=window.open("","alertWindow","resizable,status=yes,width=250,height=200")
	}
msgWindow.document.open()
msgWindow.document.write("<html><HEAD><TITLE>Message window</TITLE><style type='text/css'><!--a {  text-decoration: none}--></style>") 
msgWindow.document.writeln("</HEAD><body onLoad=\"opener.navKeypress()\" onkeydown=\"opener.setFocus()\">")
msgWindow.document.writeln("<font face='Logic'><a href='#' onmouseover='opener.setFocus()'>" + text  + "</a>")
msgWindow.document.writeln("<p><small>(Press any key to continue.)</small></font>")
msgWindow.document.write("</body></html>")
msgWindow.document.close()
setTimeout('msgWindow.focus()',1)
}

function setFocus() {
	self.focus()
	document.f.elements[foc].focus()
	document.f.elements[foc].select()
}

function unLoader() {
	msgWindow.close()
	window.status=''
}

function navKeypress() {
if (navigator.appName.indexOf('Nets')>-1) {
	msgWindow.document.captureEvents(Event.KEYPRESS)
	msgWindow.document.onkeypress = setFocus
	}
}

function strt() {
if (navigator.appName.indexOf('Net')>-1) location="#start"
else {
	if (typeof document.forms[0].elements[4] == 'object') document.forms[0].elements[4].focus()
	document.forms[0].elements[1].focus()
	}
}
