/* 
__________________________________________

DESC: symbolCheckPL.js

sendTo a variable: may be a web page, Layer0, string (to show on completion)
__________________________________________

*/

	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) {
checkOpen=true
el=elmt
if (typeof numOfProbs == 'undefined') numOfProbs = 5 
	var n = parseInt(elmt.name); var s = deSpace(elmt.value); 
	s = rewritePLder(s);
	var ss = (document.cookie.indexOf('fontSTARTno')>-1) ? rewriteNoLogicFont(s) : s // rewrites for those w/o Logic Font
	elmt.value = ss;
	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=''
	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 ( !isPLsentence(s) ) {
		if (result.indexOf('NOT')>-1) result += "<p>Go back and reconstruct the answer putting connectives and parentheses in as needed."
		else {
			result = "You need to give a SENTENCE as answer.<p>" + result
			var e = s.indexOf('%' + varFree), u = s.indexOf('%' + varFree)
			if ((u>-1 && u<varFreePos) || (e>-1 && e<varFreePos) ) result+="\n(Try adding parentheses so that \'" + varFree + "\' is bound.)"
			}
		alertX(result)
   		elmt.value+='???'
		foc=n+1
		}
	else {
   		window.status="...thinking...";
	Constant = null; Constant = new Array
	t = null; t = new Array
	branches = '|,0,|'
	arrayNum = 0
	consInTree = ''
	counter = 0
	splitTrack = 1 // counter to keep track of branching for = (which is not finised on a branch until a second node is added
	quit = false
	retry = false 
	opn = false
	result == ''

   if (checkEquiv(s,cor[n])) {
   	window.status=''
   	alertX("CORRECT!  Your answer is equivalent to the expected: <p>\'" + cor[n] + "\'.")
	keepTrack(n)
	foc = numOfProbs
   	if ( n < numOfProbs - 1 ) foc=n+2
	else done()
	}
   else if (quit == false || result == 'open' ) {
		window.status=''
		alertX("Sorry.<P>Your answer is not equivalent to the expected answer.  Please try again.");
		el.value += '???'
		foc=n+1	
	}
	else {
		window.status=''
		alertX("Hmm...your answer may be too difficult for the Cafe to fathom.<P>Can you try a simpler answer?");
		el.value += '???'
		foc=n+1
		}
   }
}

var macIE = (navigator.userAgent.indexOf('Mac')>-1 && navigator.userAgent.indexOf('MSIE') > -1 )
function down() {
	var i = (macIE) ? 0 : 1
if ( navigator.appVersion.indexOf('MSIE 4.')>-1 ) {
	scroll(0,900)
	document.forms[0].elements[i].focus()
	}
else {
	location="#start"
	document.forms[0].elements[i].focus()
	}
}

function downDirect() {
if ( navigator.appVersion.indexOf('MSIE 4.')>-1 ) {
	scroll(0,475)
	}
else {
	
	location="#instructions"
	document.forms[0].elements[1].focus()
	}
}


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

function binaryConn(s) {
mainLO(s)
if ( biC.indexOf(c) > -1 ) return true
else return false
}

function checkEquiv(s1,s2) {
Constant[0] = ''
if ( binaryConn(s1) && !out(s1) ) s1 = '(' + s1 + ')'
if ( binaryConn(s2) && !out(s2) ) s2 = '(' + s2 + ')'
s = new Node('~(' + s1 + '=' + s2 + ')')
for ( var i=1; i<s.sent.length; i++ ) {
   if ( constants.indexOf(s.sent.charAt(i))>-1 ) Constant[0] += s.sent.charAt(i)
}
t[0] = new Array
t[0][0] = s
workTree()
if (branches.indexOf(',')==-1) return true
else return false
}
	var msgWindow=window.open("","alertWindow","resizable,status=yes,width=250,height=250'")
	//msgWindow.moveTo(250,150)
	msgWindow.blur()
function alertX(text) {
if (msgWindow.closed) {
	msgWindow=window.open("","alertWindow","resizable,status=yes,width=250,height=250'")
	msgWindow.blur()
	}
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() {
	if (macIE) foc += -1
	self.focus()
	document.f.elements[foc].focus()
	document.f.elements[foc].select()
}

function unLoader() {
	msgWindow.close()
}

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

function symbolRewrite(s) {
if ((typeof rewriteNoLogicFont == 'function') && document.cookie.indexOf('fontSTARTno')>-1) s = rewriteNoLogicFont(s)
return s
}
