//These are the global variables
var timerID = null;
var timerRunning = false;
var keycode
var spacebar 
var lastspace = new Array(100);
var EnterKey = 13;
var SpaceBarKey = 32;
var BackSpaceKey = 8;
var DeleteKey = 46;
//Purpose:  This section passes the cookie
  // Global variables 
  var cv                               // Value of my cookie
  var myCookie                         // Name of my cookie
  var allCookies                       // Gets all cookies 
  var NULL
  NULL = " ";
spacebar = 0;

// This will initialize all activities
function initializeActivity() {
	// Make sure the clock is stopped
	stopclock();
	showtime();
	rightClickOff();
	initArray(1, lastspace, 100);
}

// Set values in an array for initialization purposes
function initArray(elementValue, arrayName, numOfElements) {
for(i = 0; i< numOfElements; i++) {
	arrayName[i] = elementValue;
   }
}

// This checks the Regmem for the level
function checklevel() {
	var level = cookiedata(2,'Regmem', NULL);

	if (level == 1) { //goes to student
		window.navigate('students/student.htm')
	}
	else if (level == 2) { //goes to teacher
		window.navigate('teachers/teacher.htm')
	}
	else if (level == 3) { //goes to administrator
		window.navigate('admin/admin.htm')
	}
}

// This writes the header table
function writeHeaderTable(courseUnit) {
     var firstName = cookiedata(2,'FName', NULL);
     var lastName = cookiedata(2,'LName', NULL);
     var grade = cookiedata(2,'Grade', NULL);
     var school = cookiedata(2,'School', NULL);
     var studentID = cookiedata(2,'StdntID', NULL);
     var today = new Date();

     document.write("<table border='0' width='100%' cellspacing='1'>");
     document.write("<tr><td width='20%'><img src='../../../../images/grad.gif' alt='Welcome to Cyber High!' width='120' height='60'></td>");
     document.write("<td width='20%' align='right'>");
     document.write("<img src='../../../../images/fcoebldg.gif' alt='Fresno County Office of Education' width='70' height='62'></td>");
     document.write("<td width='40%'><font face='American-Uncial-Normal'>");
     document.write("Fresno County<br />Office of Education</font></td>");
     document.write("<td width='20%' align='right'>");
     document.write("<img alt='Cyber High Announces the Next Generation in Education' src='../../../../images/change.gif' width='100' height='80'>");
     document.write("</td></tr>");
     document.write("<tr><td colspan='2'><b>" + courseUnit + "</b></td>");
     document.write("<td colspan='2' align='right'><b>Name:</b> ");
     document.write(firstName + ' ' + lastName);
     document.write("&nbsp;&nbsp;&nbsp;&nbsp; <b>Grade:</b> ");
     document.write(grade);
     document.write("</td></tr>");
     document.write("<tr><td colspan='2'><b>School:</b> ");
     document.write(school);
     document.write("</td>");
     document.write("<td colspan='2' align='right'><b>Date:</b> ");
     document.write(today.toLocaleString());
     document.write("</td></tr>");
     document.write("<tr><td colspan='2'><b>Student ID:</b> ");
     document.write(studentID);
     document.write("</td>");
     document.write("<td colspan='2' align='right'><b>Current Time:</b> ");
     document.write("<input type='text' name='face' size='13' value readonly></td>");
     document.write("</tr>");
     document.write("</table>");
}

// This writes the header table for the answer key
function writeAnswerHeader(courseNameUnit) {
     var today = new Date();

     document.write("<table border='0' width='100%' cellspacing='1'>");
     document.write("<tr><td width='20%'><img src='../../../../images/grad.gif' alt='Welcome to Cyber High!' width='120' height='60'></td>");
     document.write("<td width='20%' align='right'>");
     document.write("<img src='../../../../images/fcoebldg.gif' alt='Fresno County Office of Education' width='70' height='62'></td>");
     document.write("<td width='40%'><font face='American-Uncial-Normal'>");
     document.write("Fresno County<br />Office of Education</font></td>");
     document.write("<td width='20%' align='right'>");
     document.write("<img alt='Cyber High Announces the Next Generation in Education' src='../../../../images/change.gif' width='100' height='80'>");
     document.write("</td></tr>");
     document.write("<tr><td colspan='2'><b>" + courseNameUnit + "</b></td>");
     document.write("<td colspan='2' align='right'><b>Date:</b> ");
     document.write(today.toLocaleString());
     document.write("</td></tr>");
     document.write("</table>");
}

// This writes the disclaimer on the unit starting page
function writeDisclaimer() {

     document.write("<h6 align='center'>California Content Standards, Assessments, and Frameworks");
     document.write("have been followed for this course<br />");
     document.write("© 1996-2002&nbsp; Fresno County Office of Education.&nbsp; All rights reserved.<br />");
     document.write("No part of this curriculum may be reproduced in any form, or by any electronic,");
     document.write("mechanical, or other means, without written permission from the Fresno County");
     document.write("Office of Education.<br />");
     document.write("The Fresno County Office of Education does not endorse nor assume responsibility");
     document.write("for any content from sites that are visited through this course.</h6>");
}

// This writes the instructions for all the activities
function writeGlossary(number) {

     document.write("<p align='center'><img src='../../../../images/divider.jpg' width='400' height='5'></p>");
     document.write("<h3 align='center'>Glossary of Terms Used in Unit " + number + "</h3>");
     document.write("<p align='center'><img src='../../../../images/divider.jpg' width='400' height='5'></p>");
     document.write("<div align='center'><center>");
     
}

// This writes the instructions for all the activities
function writeActivity(number,name) {

     document.write("<h6><i>You have 3 choices in which to complete this " +
"activity:<br />" +
"1.&nbsp; Copy all work on a separate sheet of paper and complete the " +
"activity.<br />" +
"2.&nbsp; Click on the print icon to print out a worksheet and then " +
"complete it.<br />" +
"3.&nbsp; Complete your work on the computer and then print it out.</i></h6>"+
"<h3 align='center'><font face='Crillee'>" +
"<img src='../../../../images/pencil.gif' border='0' width='20' " +
"height='18'>&nbsp;" +
" ACTIVITY " + number + " &#150; " + name + "</font><br />" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for all the activities
function writeActivitySp(name) {

     document.write("<h6><i>You have 3 choices in which to complete this " +
"activity:<br />" +
"1.&nbsp; Copy all work on a separate sheet of paper and complete the " +
"activity.<br />" +
"2.&nbsp; Click on the print icon to print out a worksheet and then "+
"complete it.<br />" +
"3.&nbsp; Complete your work on the computer and then print it out.</i></h6>"+
"<h3 align='center'><font face='Crillee'>" +
"<img src='../../../../images/pencil.gif' border='0' width='20' " +
"height='18'>&nbsp;" + name + "</font><br />" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for all the activities
function writeWWWActivity(number,name) {

     document.write("<h6><i>You have 3 choices in which to complete this " +
"activity:<br />" +
"1.&nbsp; Copy all work on a separate sheet of paper and complete the " +
"activity.<br />" +
"2.&nbsp; Click on the print icon to print out a worksheet and then " +
"complete it.<br />" +
"3.&nbsp; Complete your work on the computer and then print it out.</i></h6>"+
"<h3 align='center'><font face='Crillee'>" +
"<img src='../../../images/wwwearth.gif' border='0' width='20' " +
"height='20'>&nbsp;" +
" WWW ACTIVITY " + number + " &#150; " + name + "</font><br />" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for all the activities
function writeAnsActivity(number,name) {

     document.write("<h3 align='center'><font face='Crillee'>" +
"ACTIVITY " + number + " &#150; " + name + "</font><br />Answer Key<br>" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for all the activities
function writeAnsActivitySp(name) {

     document.write("<h3 align='center'><font face='Crillee'>" +
name + "</font><br />Answer Key<br>" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for all the activities
function writeAnsWWWActivity(number,name) {

     document.write("<h3 align='center'><font face='Crillee'>" +
" WWW ACTIVITY " + number + " &#150; " + name + "</font><br />Answer Key<br>" +
"<img src='../../../../images/divider.jpg' width='400' height='5'></h3>");
}

// This writes the instructions for the progress reports
function writeProgRpt(unit) {

     document.write(
"<h6><i>This is used to keep track of the work you have completed.&nbsp; " +
"Print this page.<br />" +
"As you complete an activity, print it out, check it off, and attach it to " +
"this page.<br />" +
"Once all activities are completed and checked off, see your Contact Person " +
"who will then give you directions on how to take the unit test.</i></h6>" +
"<h3 align='center'><font face='Crillee'>" +
"<img src='../../../../images/pencil.gif' border='0' width='20' " +
"height='18'>&nbsp;" +
" Unit " + unit + " Progress Report</font></h3>");
}

// This writes the header for the Bibliography
function writeBiblio(unit) {

     document.write("<p align='center'><img "+
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<h3 align='center'>Unit " + unit + " Bibliography</h3>" +
"<p align='center'><img src='../../../../images/divider.jpg' width='400' " +
"height='5'></p>");
}

// This writes the header for the Bibliography
function writeStory(name) {

     document.write("<p align='center'><img " +
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<h3 align='center'> " + name + "</h3>" +
"<p align='center'><img src='../../../../images/divider.jpg' width='400' " +
"height='5'></p>");
}

// This writes the back and next buttons
function writeBackNext(back,backref,next,nextref) {

     document.write("<p align='center'><img " +
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<p align='center'><a href='" + back + "'>" +
"<img src='../../../../images/back.gif' alt='Go to " + backref + "' " +
"border='0' width='64' height='20'></a>&nbsp;" +
" <a href='" + next + "'>" +
"<img src='../../../../images/next.gif' alt='Go to " + nextref + "' " +
"border='0' width='61' height='20'>" +
"</p></a>");
}

// This writes the back and next buttons
function writeBackNextBib(back,backref,next,nextref) {

     document.write("<p align='center'><img " +
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<p align='center'><a href='" + back + "'>" +
"<img src='../../../../images/back.gif' alt='Go to " + backref + "' " +
"border='0' width='64' height='20'></a>&nbsp; " +
"<a href='http://www.cyberhigh.fcoe.k12.ca.us/chdata/forms/students/curr/" +
next + "?FName=" + cookiedata(2,'FName', NULL) + "&LName=" +
cookiedata(2,'LName', NULL) + "&School=" + cookiedata(2,'School', NULL) +
"&StdntID=" + cookiedata(2,'StdntID', NULL) + "'>" +
"<img src='../../../../images/next.gif' alt='Go to " + nextref + "' " +
"border='0' width='61' height='20'>" +
"</p></a>");
}

// This writes the next button only
function writeNext(next,nextref) {

     document.write("<p align='center'><img " +
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<p align='center'><a href='" + next + "'>" +
"<img src='../../../../images/next.gif' alt='Go to " + nextref + "' " +
"border='0' width='61' height='20'>" +
"</p></a>");
}

// This writes the back button only
function writeBack(back,backref) {

     document.write("<p align='center'><img " +
"src='../../../../images/divider.jpg' width='400' height='5'></p>" +
"<p align='center'><a href='" + back + "'>" +
"<img src='../../../../images/back.gif' alt='Go to " + backref + "' " +
"border='0' width='64' height='20'>" +
"</p></a>");
}

// This disables the right click
function rightClickOff() {
if (navigator.appName == "Microsoft Internet Explorer") {
     function click() {
     if (event.button==2) {
     alert('© Fresno County Office of Education: Cyber High\n'+
'Material is protected under copyright laws of the\n'+
'United States and International Agreements');
     }
     }
     document.onmousedown=click
     }
}

// This will enable the clock
function stopclock(){
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

function showtime() {
        var now = new Date();
        var hours = now.getHours();
        var minutes = now.getMinutes();
        var seconds = now.getSeconds()
        var timeValue = "" + ((hours >12) ? hours -12 :hours)
        timeValue += ((minutes < 10) ? ":0" : ":") + minutes
        timeValue += ((seconds < 10) ? ":0" : ":") + seconds
        timeValue += (hours >= 12) ? " P.M." : " A.M."
        document.clock.face.value = timeValue;
        // you could replace the above with this
        // and have a clock on the status bar:
        // window.status = timeValue;
        timerID = setTimeout("showtime()",1000);
        timerRunning = true;
}

//Written by David Hurth, June 1999
//Contact: deh@softwaredesigners.com
//This section passes the cookie
//Function Name: expireDate()

  function expireDate( nDays ) {
     // nDays                          // No. of days in future to expire 
     var one_second = 1000             // 1 sec = 1000 milliseconds
     var one_hour   = 3600 * one_second
     var one_day    = 24 * one_hour
     var expire     = new Date( (new Date()).getTime() + nDays*one_day) 
     return           expire.toGMTString()    // Time to expire cookie
  }

  // Extracts 1st substring in 'myString' bounded by 'delim1' and 'delim2'
  // It is OK if the 'delim2' is missing
  function extractSubstring(myString, delim1, delim2) {
      var substr1 = myString.split( delim1 )
          if ( substr1 == myString ) return -1     // delim1 not found
      var substr2 = substr1[1].split( delim2 )
      var len1 = substr1[0].length + delim1.length
      var len2 = substr2[0].length
      return myString.substring( len1, len1+len2 )
  }

  function storeCookie(t) {
     var cookie = myCookie + cv + '; expires=' + expireDate(t) 
     document.cookie = cookie
  }  

  function cookiedata(store, name, data) {
     allCookies = document.cookie
     if ( name != '' ) myCookie = name
     if ( myCookie == null ) myCookie = 'NoName_for_this_cookie'
     if ( store == 1 ) { //write the cookie
          cv = ( data == '' ) ? 'small_cookie' : data
          storeCookie(10) //cookie expires in 10 days
     } else if (store == 2) { //read the cookie
          cv = extractSubstring(allCookies, myCookie)
          return cv;
     } 
  }

   function writeallcookies(school, fname, lname, grade, stdntid){
      cookiedata( 1, "School", school + "School" + "FName" + fname + "FName" + "LName" + lname
      + "LName" + "Grade" + grade + "Grade" + "StdntID" + stdntid +"StdntID");
   }

// This will pass the cookies to the evaluation forms
function passcurrcookie(address){
     parent.right.navigate('http://www.cyberhigh.fcoe.k12.ca.us/chdata/forms/students/curr/' + address + '?FName=' + cookiedata(2,'FName', NULL) + '&LName=' + cookiedata(2,'LName', NULL) + '&School=' + cookiedata(2,'School', NULL) + '&StdntID=' + cookiedata(2,'StdntID', NULL))
}
function passtestcookie(address){
     parent.right.navigate('http://www.cyberhigh.fcoe.k12.ca.us/chdata/forms/students/tests/' + address + '?FName=' + cookiedata(2,'FName', NULL) + '&LName=' + cookiedata(2,'LName', NULL) + '&School=' + cookiedata(2,'School', NULL) + '&StdntID=' + cookiedata(2,'StdntID', NULL))
}
function passtroublecookie(address){
     parent.right.navigate('http://www.cyberhigh.fcoe.k12.ca.us/chdata/forms/students/trouble/' + address + '?FName=' + cookiedata(2,'FName', NULL) + '&LName=' + cookiedata(2,'LName', NULL) + '&School=' + cookiedata(2,'School', NULL) + '&StdntID=' + cookiedata(2,'StdntID', NULL))
}

//this takes care of the rest of the keyboard
function Changbox(textbox, rowsize){
     keycode=window.event.keyCode;
//this gets the Enter key 
     if(keycode==EnterKey){
          rowsize.size = 1;
          window.event.keyCode = 8;
     }
     else{
          textbox.cols = textbox.cols + 1;
     }
     if(textbox.cols == 80){
          alert('Warning: You have reached the maximum number of characters!\n' + '                If you continue to type your answer will not print correctly.');
     }
}

// This is for the one line text box
function Changbox2(textbox, rowsize){
     keycode=window.event.keyCode;
//This gets the backspace
     if(keycode==BackSpaceKey){
          if(textbox.cols>1){
               textbox.cols = textbox.cols - 1;
          }
     }
//This gets the delete
     if(keycode==DeleteKey){
          rowsize.size = 1;
          textbox.value="";
          textbox.cols = 1;
     }
}

//Creates resizable textboxes in rows
function Changrows(textbox, rowsize){
     keycode=window.event.keyCode;
     rowsize.size = rowsize.size + 1;
//     alert('rowsize.size' + rowsize.size);
//this gets the space key
     if(keycode==SpaceBarKey){
          spacebar = 0;
     }
     else{
          spacebar = spacebar + 1;
     }
//this gets the Enter key 
     if(keycode==EnterKey){
          lastspace[textbox.rows] = rowsize.size - 1;
          textbox.rows = textbox.rows + 1;
          rowsize.size = 1;
          lastspace[textbox.rows] = 1;
     }
//This checks to see if you reach the end of a line
     if(rowsize.size > textbox.cols){
          lastspace[textbox.rows] = rowsize.size - 1;
          textbox.rows = textbox.rows + 1;
          rowsize.size = 1 + spacebar;
          lastspace[textbox.rows] = rowsize.size;
     }
}

// This is for the multi line text box
function Changrows2(textbox, rowsize){
     keycode=window.event.keyCode;
//This gets the backspace
     if(keycode==BackSpaceKey){ // backspace
          if(textbox.value!=""){
               if(rowsize.size <= 1){
                    textbox.rows = textbox.rows - 1;
                    rowsize.size = lastspace[textbox.rows];
               }
               else{
                    rowsize.size = rowsize.size - 1;
               }
          }
     }
//This gets the delete
     if(keycode==DeleteKey){
     rowsize.size = 1;
     textbox.value= "";
     textbox.rows = 1;
     }
}

// This writes the single line textboxes
function singleLine(value) {
     document.write("<textarea onkeydown='Changbox2(q" + value + ", T" + value + ")' onkeypress='Changbox(q" + value + ", T" + value + ")' Name='q" + value + "' rows='1' cols='1'></textarea>");
}

// This writes the multi line textboxes only
function multiLine(value) {
     document.write("<textarea onkeydown='Changrows2(q" + value + ", T" + value + ")' onkeypress='Changrows(q" + value + ", T" + value + ")' Name='q" + value + "' rows='1' cols='53'></textarea>");
}

// This writes the multi line textboxes with size specification
function multiLineSp(value,col) {
     document.write("<textarea onkeydown='Changrows2(q" + value + ", T" + value + ")' onkeypress='Changrows(q" + value + ", T" + value + ")' Name='q" + value + "' rows='1' cols='" + col + "'></textarea>");
}

// Open an unadorned window showing a URL
function openURLWindow(url,boxWidth,boxHeight,left,top,resize) {
    View=window.open(url,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable="+resize+",width="+boxWidth+"height="+boxHeight+",left="+left+",top="+top)
}

// This opens windows for pictures
function openWindow(title,message,scroll,resize,boxWidth,boxHeight,left,top,imageWidth,imageHeight,imageSource,timeOut) {
     View = window.open("","","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scroll+",resizable="+resize+",copyhistory=0,width="+boxWidth+",height="+boxHeight+",left="+left+",top="+top);
     View.document.open();
     View.document.write("<html><head><title>" + title + "</title>" +
"</head><body onBlur = setTimeout(window.close," + timeOut + 
") background='../../../../images/bkg1.jpg'>" +
"<center><img hspace=0 vspace=0 width=" + imageWidth + " height=" + 
imageHeight + " src=" + imageSource + " alt="+message+'  ' +
"<p><hr noshade><input type='button' value='Close'" + 
"onClick='window.close()'></center></p></body></html>");
     View.document.close();
}

// This opens Glossary windows
function openGlossary(location,width,height,left,top) 
{
     View = window.open(location,"","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,copyhistory=0,width="+width+",height="+height+",left="+left+",top="+top);
}

// This will write the answer table for 1 answer box
function writeAnswerTable1(colSize,part1Header,notGraded) {

     document.write("<div align='center'><center><table border='1' " +
"bgcolor='#00FFFF'>" +
"<tr><td>Your percentage is: <input type='text' name='percent' size='3' "+
"readonly>%<br />" +
"You answered <input type='text' name='questions' size='2' readonly> " +
"questions.<br />" +
"Correct answers: <input type='text' name='correct' size='2' readonly><br />"+
"Incorrect answers: <input type='text' name='incorrect' size='2' " +
"readonly></td><td>These answers are incorrect:<br />");
     if (part1Header!=""){
          document.write(part1Header + ": <input type='text' name='results' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results' readonly><br />");
          }
     if (notGraded!=""){
          document.write(notGraded + " not graded</td>");
     }
     document.write("</tr></table></center></div>");
     document.clock.results.size=colSize;
}

// This will write the answer table for 2 answers box
function writeAnswerTable2(colSize,part1Header,part2Header,notGraded) {

     document.write("<div align='center'><center><table border='1' " +
"bgcolor='#00FFFF'>" +
"<tr><td>Your percentage is: <input type='text' name='percent' size='3' " +
"readonly>%<br />" +
"You answered <input type='text' name='questions' size='2' readonly> " +
"questions.<br />" +
"Correct answers: <input type='text' name='correct' size='2' readonly><br />"+
"Incorrect answers: <input type='text' name='incorrect' size='2' " +
"readonly></td>" +
"<td>These answers are incorrect:<br />");
     if (part1Header!=""){
          document.write(part1Header + ": <input type='text' name='results1' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results1' readonly><br />");
          }
     if (part2Header!=""){
          document.write(part2Header + ": <input type='text' name='results2' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results2' readonly><br />");
          }
     if (notGraded!=""){
          document.write(notGraded + " not graded</td>");
     }
     document.write("</tr></table></center></div>");
     document.clock.results1.size=colSize;
     document.clock.results2.size=colSize;
}

// This will write the answer table for 3 answers box
function writeAnswerTable3(colSize,part1Header,part2Header,part3Header,notGraded) {

     document.write("<div align='center'><center><table border='1' " +
"bgcolor='#00FFFF'>" +
"<tr><td>Your percentage is: <input type='text' name='percent' size='3' " +
"readonly>%<br />" +
"You answered <input type='text' name='questions' size='2' readonly> " +
"questions.<br />" +
"Correct answers: <input type='text' name='correct' size='2' readonly><br />"+
"Incorrect answers: <input type='text' name='incorrect' size='2' " +
"readonly></td>" +
"<td>These answers are incorrect:<br />");
     if (part1Header!=""){
          document.write(part1Header + ": <input type='text' name='results1' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results1' readonly><br />");
          }
     if (part2Header!=""){
          document.write(part2Header + ": <input type='text' name='results2' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results2' readonly><br />");
          }
     if (part3Header!=""){
          document.write(part3Header + ": <input type='text' name='results3' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results3' readonly><br />");
          }
     if (notGraded!=""){
          document.write(notGraded + " not graded</td>");
     }
     document.write("</tr></table></center></div>");
     document.clock.results1.size=colSize;
     document.clock.results2.size=colSize;
     document.clock.results3.size=colSize;
}

// This will write the answer table for 4 answers box
function writeAnswerTable4(colSize,part1Header,part2Header,part3Header,part4Header,notGraded) {

     document.write("<div align='center'><center><table border='1' " +
"bgcolor='#00FFFF'>" +
"<tr><td>Your percentage is: <input type='text' name='percent' size='3' " +
"readonly>%<br />" +
"You answered <input type='text' name='questions' size='2' readonly> " +
"questions.<br />" +
"Correct answers: <input type='text' name='correct' size='2' readonly><br />"+
"Incorrect answers: <input type='text' name='incorrect' size='2' " +
"readonly></td>" +
"<td>These answers are incorrect:<br />");
     if (part1Header!=""){
          document.write(part1Header + ": <input type='text' name='results1' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results1' readonly><br />");
          }
     if (part2Header!=""){
          document.write(part2Header + ": <input type='text' name='results2' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results2' readonly><br />");
          }
     if (part3Header!=""){
          document.write(part3Header + ": <input type='text' name='results3' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results3' readonly><br />");
          }
     if (part4Header!=""){
          document.write(part4Header + ": <input type='text' name='results4' readonly><br />");
     }
          else {
               document.write("<input type='text' name='results4' readonly><br />");
          }
     if (notGraded!=""){
          document.write(notGraded + " not graded</td>");
     }
     document.write("</tr></table></center></div>");
     document.clock.results1.size=colSize;
     document.clock.results2.size=colSize;
     document.clock.results3.size=colSize;
     document.clock.results4.size=colSize;
}

// This is used to do the hover buttons
isamap = new Object();
isamap[0] = "_df"
isamap[1] = "_ov"
isamap[2] = "_ot"

function isimgact(id, act)
{
	if(document.images) document.images[id].src = eval( "isimages." + id + isamap[act] + ".src");
}

if (document.images) { // ensure browser can do rollovers.
isimages = new Object();
isimages.page1_df = new Image();
isimages.page1_df.src = "../../../images/but1a.jpg";

isimages.page1_ov = new Image();
isimages.page1_ov.src = "../../../images/but1b.jpg";

isimages.page1_ot = new Image();
isimages.page1_ot.src = "../../../images/but1a.jpg";

isimages.page2_df = new Image();
isimages.page2_df.src = "../../../images/but2a.jpg";

isimages.page2_ov = new Image();
isimages.page2_ov.src = "../../../images/but2b.jpg";

isimages.page2_ot = new Image();
isimages.page2_ot.src = "../../../images/but2a.jpg";

isimages.page3_df = new Image();
isimages.page3_df.src = "../../../images/but3a.jpg";

isimages.page3_ov = new Image();
isimages.page3_ov.src = "../../../images/but3b.jpg";

isimages.page3_ot = new Image();
isimages.page3_ot.src = "../../../images/but3a.jpg";

isimages.page4_df = new Image();
isimages.page4_df.src = "../../../images/but4a.jpg";

isimages.page4_ov = new Image();
isimages.page4_ov.src = "../../../images/but4b.jpg";

isimages.page4_ot = new Image();
isimages.page4_ot.src = "../../../images/but4a.jpg";

isimages.page5_df = new Image();
isimages.page5_df.src = "../../../images/but5a.jpg";

isimages.page5_ov = new Image();
isimages.page5_ov.src = "../../../images/but5b.jpg";

isimages.page5_ot = new Image();
isimages.page5_ot.src = "../../../images/but5a.jpg";

isimages.page6_df = new Image();
isimages.page6_df.src = "../../../images/but6a.jpg";

isimages.page6_ov = new Image();
isimages.page6_ov.src = "../../../images/but6b.jpg";

isimages.page6_ot = new Image();
isimages.page6_ot.src = "../../../images/but6a.jpg";
}

// This is used to check for answers on one-line text boxes
function checkAnswer(question,answer) {
     if (question.value == answer) {
          alert("Nice job.")
	}
	else {alert("Please try again.");
	     question.value = "";
             question.cols = 1;		
      };
}

// This is used to check for answers on one-line text boxes
// if there are two right answers using OR
function checkAnswer2or(question,answer1,answer2) {
     if (question.value == answer1 || question.value == answer2) {
          alert("Nice job.")
	}
          else {alert("Please try again.");
               question.value = "";
               question.cols = 1;		
          };
}

// This is used to check for answers on one-line text boxes
// if there are two right answers using AND
function checkAnswer2and(question1,answer1,question2,answer2) {
     if (question1.value == answer1 && question2.value == answer2) {
          alert("Nice job.")
	}
          else {alert("Please try again.");
               question1.value = "";
               question1.cols = 1;		
	       question2.value = "";
               question2.cols = 1;
          };
}

// This is used to check for answers on one-line text boxes
// if there are three right answers using AND
function checkAnswer3and(question1,answer1,question2,answer2,question3,answer3) {
     if (question1.value == answer1 && question2.value == answer2 && question3.value == answer3) {
          alert("Nice job.")
	}
          else {alert("Please try again.");
               question1.value = "";
               question1.cols = 1;		
	       question2.value = "";
               question2.cols = 1;
	       question3.value = "";
               question3.cols = 1;
          };
}

// This is used to check for answers on one-line text boxes
// if there are four right answers using AND
function checkAnswer4and(question1,answer1,question2,answer2,question3,answer3,question4,answer4) {
     if (question1.value == answer1 && question2.value == answer2 && question3.value == answer3 && question4.value == answer4) {
          alert("Nice job.")
	}
          else {alert("Please try again.");
               question1.value = "";
               question1.cols = 1;		
	       question2.value = "";
               question2.cols = 1;
	       question3.value = "";
               question3.cols = 1;
	       question4.value = "";
               question4.cols = 1;
          };
}

// This is used to show the answers on one-line text boxes
function showAnswer(question,answer,cols) {
     question.value = answer;
     question.cols = cols;
}

function stretchTextArea(ta,wid) {
    if (ta.rows>=20) {
            alert("You have used up all the space available for this box.  Can you write a shorter answer?");
            ta.rows= ta.rows - 5;
            ta.value = ta.value.slice(0,-(wid*2));
    }
    else {
            var txtLength=ta.value.length;
            var numRows="0";
            var arrNewLines= ta.value.split("\n");
            for(var i=0; i<=arrNewLines.length-1; i++) {
                  numRows++;
                  if (arrNewLines[i].length > (wid-5)) {
                       numRows += Math.floor(arrNewLines[i].length/wid)
                  }
            }
            if (txtLength==0){ta.rows=1}
            else {ta.rows=numRows > 20 ? 20 : numRows+1}
    }
}
