/*  js/multipleChoice.js
REMOVE IE4 REF FOR DOWNLOAD!!
No() in addition to no() 8/6/02
======================================================================
DESC:  

PLATFORMS: 

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

/* ======================================================================
FUNCTION: 	show() used to record cookies for results
====================================================================== */
window.status=''
var stat1 = ''
var count = 0; 
var track = new Array
var report
var perc
var NS6plus=false
if (document.getElementById && navigator.appName.indexOf('Net') > -1) NS6plus=true
var IE4=false
if (navigator.appVersion.indexOf('MSIE 4.')>-1) IE4 = true
if ( IE4 ) setTimeout('ie4prep()',50) // to work around reload problems at each anchor
if ( navigator.appName != 'Netscape' ) { // to add border in IE; Navigator links won't work with these.
	document.write('<style type="text/css">\n<!--')
	document.write('span.margin a {  line-height: 130%; }')
	document.write('-->\n\n</style>')
} 

function ie4prep() {
	ie4read()
	if ( count >= lastP && typeof document.forms[0].elements[0] == 'object') {
   	document.forms[0].elements[0].value = report
		}
}


function yes(n) {
if ( n == 1 ) hide()
stat1 = 'Your last answer, to problem ' + n + ' was CORRECT!';  window.status =stat1;
if ( track[n] == null ) {track[n] = true;count++}
var t = parseInt(total.substring(3));perc = parseInt(count/t * 100)
report = '' + count + total + ' resulting in '  + perc + ' percent of the problems.'
if ( perc == 100 ) report += '\n\nThe answers you gave were:\n' + answers
else {
report += '\n\nYou have finished problems: '
for(var i=1;i<16;i++) {
	if (track[i]== true ) report += ('' + i + ',')
	}
report = report.substring(0,report.length-1)
}
if ( n == lastP ) {
	show()
	}
if (NS6plus) {
	document.forms[0].elements[0].value = report
	setTimeout("scrollBy(0,-17)",1)
	}
else if (navigator.appName.indexOf('Net') > -1) document.Layer1.document.forms[0].elements[0].value = report
else document.forms[0].elements[0].value = report
if ( IE4 ) ie4write()
}

/*function No() added after the original for answer specific alerts
Needs something like:
	var Alerts = new Array
	Alerts[1] = new Array
	Alerts[1][1] = 'The table will only give truth value assignments for the atomic sentences appearing in the argument; not "all" atomic sentences.' No(n,m) for problem n choice m
*/
function No(n,m) { 
	if ( Alerts != null && Alerts[n] != null ) alert(Alerts[n][m])
	no(n,m)
}

function no(n,m) {
	window.status = 'Not Correct'; 
	if ( n == 1 ) hide()
	stat1 = 'Your last answer, to problem ' + n +  ' was NOT correct. Please try again.'
	if ( alerts[n] != null && alerts[n] != '' ) alert(alerts[n])
	else if (m==null) alert(stat1)
	else alert(m)
	if (NS6plus) {
	document.forms[0].elements[0].value = report
	setTimeout("scrollBy(0,-17)",1)
	}
	if ( IE4 ) ie4write()
}

function ie4read() { // so that ie4 memory leaks are plugged as it reloads! values are stored in a cookie on  answer
	var val = getCookie('mtplChoice')
	if ( typeof val =='string' && val.indexOf(document.title) == 0 ) {
   	var start = val.indexOf('tr$') + 3; var stop = val.indexOf('tr#')
   	track=val.substring(start,stop).split(',')
   	start = val.indexOf('rp$') + 3;  stop = val.indexOf('rp#')
   	report = val.substring(start,stop)
   	start = val.indexOf('st$') + 3;  stop = val.indexOf('st#')
   	stat1 = val.substring(start,stop)
   	start = val.indexOf('ct$') + 3;  stop = val.indexOf('ct#')
   	count = parseInt(val.substring(start,stop))
		}
}

function ie4write() { // so that ie4 memory leaks are plugged as it reloads! values are stored in a cookie on  answer
	var val = document.title
	val+= 'tr$' + track.toString() + 'tr#'
	val+= 'rp$' + report + 'rp#'
	val+= 'st$' + stat1 + 'st#'
	val+= 'ct$' + count + 'ct#'
	setCookie('mtplChoice', val, 'now')
}

function silence(n) {
	 window.status = stat1
	 return true
}

function show()  { 
if (document.getElementById) document.getElementById('Layer1').style.visibility="visible"
else if (navigator.appName.indexOf('Net') > -1) document.Layer1.visibility = "visible"
else document.all.Layer1.style.visibility = "visible"
if ( perc == 100 ) {
	var exName = document.title
	var Name = 'Ch' + exName.substring(0,exName.indexOf('.'))
	var exNum = exName.substring(exName.indexOf('.')+1)
	cookie = getCookie(Name)
		if (cookie == null) cookie=exName
		else if ( cookie.indexOf(exName)>=0 ) {
		var l = exName.length
		var c = cookie.charAt(cookie.indexOf(exName) + l)
		cookie+=(c != '' && c != ',' ) ? ',' + exName : ''
	}
	else cookie+= ',' + exName
cookie = cookie.split(',').sort().toString()
setCookie(Name,cookie,'')
stat1=''
}}

function hide()  {
if (document.getElementById) document.getElementById('Layer1').style.visibility='hidden'
else if (navigator.appName.indexOf('Net') > -1) document.Layer1.visibility = "hidden"
else document.all.Layer1.style.visibility = "hidden"
}

function setCookie(name, value, expire) { 
	var today = new Date()  
	var expires = new Date()   
 if (expire == null || expire == '') {
	expires.setTime(today.getTime() + 10000*60*60*24*365)
 	}  
 else {   
	expires.setTime(today.getTime() + 1000*60*60*24*expire)
 }
var g = name + "=" + escape(value)   + ((expire == "now") ? "" : ("; expires=" + expires.toGMTString()))
document.cookie = g
}

function getCookie(Name) {   
var search = Name + "="  
 if (document.cookie.length > 0) { // if there are any cookies      
offset = document.cookie.indexOf(search)      
 if (offset != -1) { // if cookie exists          
offset += search.length          // set index of beginning of value        
 end = document.cookie.indexOf(";", offset)          // set index of end of cookie value         
if (end == -1)             end = document.cookie.length        
 return unescape(document.cookie.substring(offset, end))      }    
}} 

