//v1.0
//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}

//SyberWorks

var isNav, isIE, theVersion;

if (parseInt(navigator.appVersion) >= 5) {
  theVersion = 5;
}
else {
  theVersion = 4;
}

if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
     isNav = true;
     isIE = false;}
  else {
     isIE = true;
     isNav = false;}
}


function GetBookmark (CourseCode) 
{
	var CookieVal; 
        var slashpos;
        var tempint;
	var level;
	var tmpstr;    
	var cclen=CourseCode.length;

	CookieVal=ReadCookie("BM"+CourseCode); 
	if (!CookieVal) {         
		ResultWin=window.open("", "Bookmark", "menubar=no,resizable=no,scrollbars=no,width=250,height=100");         
		ResultWin=ResultWin.document;         
		ResultWin.write ('<body bgcolor="white" onload="self.focus();">');         
		ResultWin.write ('<center><font face="arial"><b>');         
		ResultWin.write ("<br>Bookmark not found.</b></font></center>");         
		ResultWin.close();     
	}
	else {  
		//alert("Cookie value is " + CookieVal);
                var CookieVal2 = CookieVal.toUpperCase();
                var CourseCode2 = CourseCode.toUpperCase();
		parent.course.location=CookieVal;
		tempint = CookieVal2.indexOf("/" + CourseCode2 + "/");
		//alert("tempint is " + tempint);
		// See if there an extra slash after the CourseCode
		slashpos = CookieVal2.indexOf("/", tempint + cclen + 2)
		//alert("slashpos is " + slashpos);
                if (slashpos < 0) {
		   tmpstr=CookieVal.substring(0, tempint + cclen * 2 + 2)+"nv.htm";
		   //alert("1 " + tmpstr);
		   //parent.navigator.location=tmpstr; 
		}
		else {
		   tmpstr=CookieVal.substring(0, tempint + cclen * 3 + 7)+"nv.htm";
		   //alert("2 " + tmpstr);
		   //parent.navigator.location=tmpstr;
		} 

		//top.frames['navigator'].location = tmpstr;
 
		//alert("tmpstr = " + tmpstr);
   		if(top.frames.length > 2)
   		{
		   top.frames[1].location = tmpstr;
   		}
   		else
   		{
      		   top.frames[0].location = tmpstr;
   		}   
   
	}    
}

function ReadCookie(name){
	var allCookie, CookieVal, length, start, end;
	cookieVal="";
	name=name+"=";
	allCookie=document.cookie;
	length=allCookie.length;
	if (length>0) {
		start=allCookie.indexOf(name,0)
		if (start!=-1) {
			start+=name.length;
			end=allCookie.indexOf(";",start);
			if (end==-1) {end=length;}
			cookieVal=unescape(allCookie.substring(start, end));
		}
	}
  	return (cookieVal);
}
function WriteCookie(name, value, expires, domain, path, secure){
	var CookieVal, CookError;
	var temp;
	CookieVal=CookError="";
	if (name) {
		CookieVal=CookieVal+escape(name)+"=";
		if (value) {
			CookieVal=CookieVal+escape(value);
			if (expires)CookieVal=CookieVal+"; expires="+expires.toGMTString();
			if (domain)	CookieVal=CookieVal+"; domain="+domain;
			if (path) CookieVal=CookieVal+"; path="+path;
			if (secure) CookieVal=CookieVal+"; secure";
		} else {CookError=CookError+"Value failure";}
	} else {CookError=CookError+"Name failure";}
	if (!CookError){
		document.cookie=CookieVal;
		temp=ReadCookie(name);
		if (value!=temp) CookError="<p>Please make sure your browser can accept cookies.";
	
	}
        //The following line was added by David F. on 020320
        CookieVal=unescape(CookieVal);
	return (CookError);
}
			
function SetBookmark (URL, CourseCode) {
	var ErrorCode;
        URL = top.course.location;	
	Expiration = new Date ()
	Expiration.setTime(Expiration.getTime()+ 19440000000);
	ErrorCode=WriteCookie ("BM"+CourseCode, URL, Expiration, "","/");
 	ResultWin=window.open("", "Bookmark", "menubar=no,resizable=no,scrollbars=no,width=250,height=100");
	ResultWin=ResultWin.document;
	ResultWin.write ('<body bgcolor="white" onload="self.focus();">');
	ResultWin.write ('<center><font face="arial"><b>');
	if (ErrorCode) {
		ResultWin.write ('Could not set bookmark.</b>'+ErrorCode+'');
	} else {
		ResultWin.write ('<br>Bookmark set.</b>');
	}		
	ResultWin.write ('</font></center>');
	ResultWin.close();
}	


function SetBookmark2(CourseCode) {
	//alert(" 2 CourseCode is " + CourseCode + "\nLocation is " + top.course.location);
	var ErrorCode;	
	var URL;
	URL = top.course.location;
	var URL2;
	URL2 = URL + "";
	URL2 = URL2.toUpperCase();
	if (URL2.indexOf('CGI-WIN') > -1)
	{
	   ResultWin=window.open("", "Bookmark", "menubar=no,resizable=no,scrollbars=no,width=250,height=100");
	   ResultWin=ResultWin.document;
	   ResultWin.write ('<body bgcolor="white" onload="self.focus();">');
	   ResultWin.write ('<center><font face="arial">');
	   ResultWin.write ('<br><b>Bookmark can not be set here.</b>');
	   ResultWin.write ('</font></center>');
	   ResultWin.close();
	   return;
	}
	Expiration = new Date ()
	Expiration.setTime(Expiration.getTime()+ 19440000000);
	ErrorCode=WriteCookie ("BM"+CourseCode, URL, Expiration, "","/");
 	ResultWin=window.open("", "Bookmark", "menubar=no,resizable=no,scrollbars=no,width=250,height=100");
	ResultWin=ResultWin.document;
	ResultWin.write ('<body bgcolor="white" onload="self.focus();">');
	ResultWin.write ('<center><font face="arial"><b>');
	if (ErrorCode) {
		ResultWin.write ('Could not set bookmark.</b>'+ErrorCode+'');
	} else {
		ResultWin.write ('<br>Bookmark set.</b>');
	}		
	ResultWin.write ('</font></center>');
	ResultWin.close();
}

function SetCurrentLocation() {
  	var MapErrorCode;
	MapErrorCode=WriteCookie("CurrentLocation", CurrentTopicVal, "", "", "/");
}

function GetCurrentLocation() {
	var CurLoc;
	var CurLocCourseCode;
	var CurLocPageName;
        var tmpstr1;
        var tmpstr2;
        var tmpstr3;
        var tmpint1;
        var tmpint2;
	var IIS = "N";
	CurLoc = ReadCookie("CurrentLocation");
        // Must allow for possibility that CurLoc was set in another course
        // so doesn't apply to this course.
        tmpstr1 = String(document.location);
	// find location of last slash
        tmpint1 = tmpstr1.length;
	for (var i = tmpint1; tmpint1 > -1; tmpint1--)
        {
	   if (tmpstr1.substring(tmpint1, tmpint1+1) == "/") break;
	}
	tmpstr2 = tmpstr1.substring(tmpint1+1, tmpint1+5);
	tmpint2 = CurLoc.length
	for (var j = tmpint2; tmpint2 > -1; tmpint2--)
        {
	   if (CurLoc.substring(tmpint2, tmpint2+1) == "/") break;
	}
	if (tmpint2 > -1)
	{
	   CurLocCourseCode = CurLoc.substring(tmpint2+1, tmpint2+5);
	   CurLocPageName = CurLoc.substring(tmpint2+1, CurLoc.length);
	}
	else
	{
	   CurLocCourseCode = CurLoc.substring(0, 4);
	   CurLocPageName = CurLoc;
	}

        tmpstr2 = tmpstr2.toUpperCase();
	CurLocCourseCode = CurLocCourseCode.toUpperCase();
        if (tmpstr2 != CurLocCourseCode)
        { CurLocPageName = ""; }
	if (CurLocPageName != "")
	document.images[CurLocPageName].src="maparrow.gif";
}



	
function QuestionFeedback() {
  var WindowQuestion=window.open("../AnswerWait.htm", "Answer_Feedback", "resizable=yes,scrollbars=yes,width=400,height=350")
}
function Assessment() {
  var WindowAssessment=window.open("../AssessmentWait.htm", "AssessmentWindow", "menubar=yes,resizable=yes,scrollbars=yes,width=550,height=400")
}
function Assessment2() {
  var WindowAssessment=window.open("../AssessmentWait2f.htm", "Assessment2Window", "menubar=yes,resizable=yes,scrollbars=yes,width=550,height=400")
}
function NamedDetailWindow(filename, w, h,name) {
  var WindowDetail=window.open(filename, name, "menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h)
}
function DetailWindow(filename, w, h) {
  var WindowDetail=window.open(filename, "DetailWindow", "menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h)
}
function DetailWindowWithMenu(filename, w, h) {
  var DetailWindowWithMenu=window.open(filename, "DetailWindowWithMenu", "menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h)
}
function AddSpaceInIEOnly()
{
   IElen = "Microsoft Internet Explorer".length;
   Applen = navigator.appName.length;
   if (IElen == Applen)
   {  document.write("<pre>  </pre>");      }
}
function WScreate(filename, w, h, QID){
   var WSwindow=window.open(filename, "WSwindow", "menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h);
}

// Variables and functions used by exhibit questions
var childflag = 0;
var questionid = "none";
var childwin = null;
var browser = "";

if (navigator.appName == "Netscape")
   {browser = "NN";} 
else 
   {browser = "IE";}

function setChildFlag(val){
   childflag = val;
}
function ExhibitWindow(qid, w, h) {
   if (childflag == 0){
      childwin=window.open("/cgi-win/auth/$exhibit.dll/" + qid, "ExhibitWindowName","menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h);
      questionid = qid;
   }
   else {
      if (qid == questionid && browser=="NN") {
         childwin.closer.toTop();
      }
      else {
         childwin=window.open("/cgi-win/auth/$exhibit.dll/" + qid, "ExhibitWindowName","menubar=yes,resizable=yes,scrollbars=yes,width="+w+",height="+h);
         questionid = qid;
      }
   }
}

function AnimationWindow(filename, w, h) {
  window.open(filename, "DetailWindow", "menubar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h)
}

function PopUpWindow(filename, windowname, w, h) {
  window.open(filename, windowname, "menubar=no,resizable=yes,scrollbars=yes,width="+w+",height="+h)
}

function AudioPlay(clip){
  var i;
  var s1;
  var s2;
  i = clip.indexOf('.');
  s1 = clip.substring(0, i);
  s2 = s1 + ".HTM";
  parent.audio.location = s2;
}

function AudioInit(){
  with(parent.audio.document){
  write("<html>\n\r");
  write("<body>\n\r");
  write("</body>\n\r");
  write("</html>\n\r");
  close();
  }
}

function SelectResp(qid, choice, alt){
  QuestionFeedback();
  var obj;
  obj = eval("document." + qid + "form");
  obj.elements[0].value = choice;
  obj.elements[1].value = alt;
  obj.submit();
}

//This is the IIS version.
//It uses codebase.
function playAudio(clipFileName, autoStart, audioBackgroundColor, audioBackgroundImage, courseCode, LessonOrCourse, APWidth, APHeight)
{
   top.audioframe.document.write("<html>\n");

   if (LessonOrCourse == "L")
   {
      top.audioframe.document.write("<body bgcolor=\"" +          audioBackgroundColor + "\" background=\"../" +         audioBackgroundImage + "\" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 rightmargin=0>");
   }
   else
   //LessonOrCourse should equal C
   {
     top.audioframe.document.write("<body bgcolor=\"" +          audioBackgroundColor + "\" background=\"" +          audioBackgroundImage + "\" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 rightmargin=0>");
   }
   if (clipFileName != "") {
      top.audioframe.document.write("<center>\n");
      top.audioframe.document.write("<table height=" + APHeight + " width=" + APWidth + " border=1 cellspacing=0 cellpadding=0><tr><td>");
      top.audioframe.document.write("<applet\n");
      top.audioframe.document.write("align=baseline\n");
      top.audioframe.document.write("archive=SWAudio.jar\n");
      top.audioframe.document.write("code=SWAudio.class\n");
      top.audioframe.document.write("codebase = /Courses/" + courseCode + "/SWAudio\n");
      top.audioframe.document.write("id=SWAudio\n");
      top.audioframe.document.write("height=21\n");
      top.audioframe.document.write("width=102>");
      top.audioframe.document.write("\n");
      top.audioframe.document.write("<PARAM NAME=\"autoplay\" VALUE=\"" + autoStart + "\">\n");
      top.audioframe.document.write("<PARAM NAME=\"controls\" VALUE=\"true\">\n");
      top.audioframe.document.write("<PARAM NAME=\"soundfile\" VALUE=\"" +  clipFileName + "\">\n");
      top.audioframe.document.write("</applet>\n");
      top.audioframe.document.write("</td></tr></table");
      top.audioframe.document.write("</center>\n");
   }
   top.audioframe.document.write("</body>\n");
   top.audioframe.document.write("</html>\n");
   top.audioframe.document.close();
}

function pageCounter(pagenumber, pageframeBackgroundColor, pageframeBackgroundImage, LessonOrCourse, fontface, fontcolor, PCWidth, PCHeight)
{

   top.pageframe.document.write("<html>\n");
   if (LessonOrCourse == "L")
   {
      top.pageframe.document.write("<body bgcolor=\"" +          pageframeBackgroundColor + "\" background=\"../" +         pageframeBackgroundImage + "\" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 rightmargin=0>");
   }
   else
   //LessonOrCourse should equal C
   {
     top.pageframe.document.write("<body bgcolor=\"" +          pageframeBackgroundColor + "\" background=\"" +          pageframeBackgroundImage + "\" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0 rightmargin=0>");
   }

   if (pagenumber != "") {
      //top.pageframe.document.write("<center>\n"); 
      if (fontcolor == ""){
         fontcolor = "black";
      }
      if (fontface == ""){
         fontface = "timesroman";
      }
      top.pageframe.document.write("<table height=" + PCHeight + " width=" + PCWidth + " border=0 cellspacing=0 cellpadding=0><tr><td valign=middle align=center><font face=\"" +  fontface + "\" color=\"" + fontcolor + "\">");
      top.pageframe.document.write("Page " + pagenumber + "</td></tr></table>");
      //top.pageframe.document.write("</center>\n");
   }
  
   top.pageframe.document.write("</body>\n");
   top.pageframe.document.write("</html>\n");
   top.pageframe.document.close();
}


// Variable needed to wait for a questions to be answered in flash
// Could be extended to our questions as well.

var answeredquestion = -1;

//Variable (flag) that is used to force a user to spend a 
//minimum amount of time on a page.  See PageDelay() and added code to
//NextTopic()
var timedelay = 0;


function question_DoFSCommand(command, args) {
  if(command=="changeansweredquestion"){
    changeansweredquestion(args);
  }
}

function changeansweredquestion(val){
  answeredquestion=val;
}

function PageDelay(seconds)
{
   timedelay = 1;
   setTimeout("timedelay=0", seconds * 1000);
}

function NextTopic()
{
   if (NextTopicVal == "")
   {
       alert("Next Topic button is only active\nwithin a lesson.");
       return;
   }
   
   if (answeredquestion == 0)
   {  alert("Please try the question before moving\nto the next topic.");
      return;
   }

   if (timedelay == 1)
   {
      alert("Please listen to the audio before moving \n to the next topic.");
      return;
   }

   NextTopicVal=NextTopicVal.toUpperCase();
   if (NextTopicVal.substring(0, 4) == "/CGI")
   {
      self.document.gotopic.action = NextTopicVal;
      self.document.gotopic.submit();
   }
   else
   {
      top.course.location = NextTopicVal;
   }
}

function PreviousTopic()
{
   if (PreviousTopicVal == "")
   {
      alert("Previous Topic button is only active\nwithin a lesson.");
      return;
   }
   if (PreviousTopicVal == "none")
   {
      alert("There is no previous topic.");
      return;
   }   
   PreviousTopicVal = PreviousTopicVal.toUpperCase();
   if (PreviousTopicVal.substring(0, 4) == "/CGI")
   {
      self.document.gotopic.action = PreviousTopicVal;
      self.document.gotopic.submit();
   }
   else
   {
      top.course.location = PreviousTopicVal;
   }
}

function TopicMenu()
{
   if (TopicMenuVal == "")
   {
      alert("Topic Menu button is only active\nwithin a lesson.");
      return;
   }
   if (answeredquestion == 0)
   {  
      alert("Please try the question before moving\nfrom this topic.");
      return;
   }
   TopicMenuVal=TopicMenuVal.toUpperCase();
   if (TopicMenuVal.substring(0, 4) == "/CGI")
   {
      self.document.gotopic.action = TopicMenuVal;
      self.document.gotopic.submit();
   }
   else
   {
      top.course.location = TopicMenuVal;
   }
}


function GoTopic(CourseCode, URL)
{
   var tmpstr;
   var tmpstr2;
   var tmpstr3;
   var tmpint;
   var tmpint2;
   var slashpos;
   var cclen;
   tmpstr = "" + self.location;
   tmpstr = tmpstr.toUpperCase();
   CourseCode = CourseCode.toUpperCase();
   cclen=CourseCode.length;
   URL = URL.toUpperCase();
   tmpstr2 = tmpstr.substring(0, tmpstr.indexOf("/" + CourseCode + "/", 0) + cclen + 2)

   if (URL.substring(0, 3) == "../")
   {
      tmpstr2 = tmpstr2 + URL.substring(3, cclen+3) + "nv.htm"
      parent.course.location = URL;
   }
   if (URL.substring(0, 4) == "/CGI")
   {
      URL = escape(URL);
      tmpint = URL.indexOf("/" + CourseCode + "/", 0);
      tmpint2 = URL.indexOf("/", tmpint+cclen+2);
      if(tmpint2 < 0)
      {
          tmpstr2 = "/cgi-win/auth/$course.dll/Courses/" + CourseCode + "/" + CourseCode + "nv.htm?Timer=NO";
      }
      if(tmpint2 > -1)
      {
          tmpstr2 = "/cgi-win/auth/$course.dll/Courses" + URL.substring(tmpint, tmpint2+1) + URL.substring(tmpint2+1, tmpint2+cclen+3) + "nv.htm?Timer=NO";
      }
      //alert("tmpstr2" = tmpstr2);
      self.document.gotopic.action = URL;
      self.document.gotopic.submit();
   }
   if (URL.substring(0,3) != "../" && URL.substring(0,4) != "/CGI") 
   { 
      tmpstr2 = tmpstr2 + URL.substring(0, cclen+2) + "/" + URL.substring(0, cclen+2) + "nv.htm";
      parent.course.location = URL;  
   }
   if(top.frames.length > 2)
   {
      tmpstr3 = "" + top.frames[1].location;
      if (tmpstr3.indexOf("nv.htm", 0) > 0)
      {
         top.frames[1].location = tmpstr2;
      }
      else
      {
         top.frames[2].location = tmpstr2;
      }
   }
   else
   {
      alert("nav 0");
      top.frames[0].location = tmpstr2;
   }

}

function PreviewMessage(msgsubject, msgbody, buttonname)
{
   // Creates and populates a window that allows the user
   // to preview a message before sending it.
   //
   // Translate all the \n charcters to <P>
   var tmpstr="";
   for (var i=0; i < msgbody.length; i++) {
      if (msgbody.substring(i,i+2) == "\r\n") {
         if (msgbody.substring(i+2, i+4) == "\r\n")
            { tmpstr = tmpstr + "<P>";
              i = i + 3;}
         else
            { tmpstr = tmpstr + "<br>";
              i = i + 1;}
         }  
      else
         { tmpstr = tmpstr + msgbody.substring(i, i+1); }
   }
   msgbody=tmpstr;

   // Create and populate the preview window
   var w=window.open("","msgprv","menubar=yes,resizable=yes,scrollbars=yes,width=500,height=500");
   w.document.open();
   w.document.write("<html><title>Preview</title>");
   w.document.write("<body bgcolor=white onLoad='top.document.closeform.close.focus();top.document.closeform.close.blur();'>");
   w.document.write("<center><h2>Message Preview</h2></center>");
   w.document.write("<center><form name=closeform><input type=text name=close size=18 value='Click to close -->'>  "); 
   w.document.write("<input type=button value='Close' onClick='top.close();'></form></center>");
   w.document.write("The following shows a preview of your request. ");
   w.document.write("To send the request, close this window, then press the " + buttonname + " button.");
   w.document.write("<br><br>");
   w.document.write("<table width='100%' border=1><tr><td>");
   w.document.write("<table border=0>");
   w.document.write("<tr valign=top><td><b>Subject: </b></td><td>" + msgsubject + "</td></tr>");
   w.document.write("<tr valign=top><td><b>Message:</b></td><td></td></tr>");
   w.document.write("</table><center><table width='90%' border=0>");
   w.document.write("<tr><td>"+msgbody+"</td></tr>");
   w.document.write("</table>");
   w.document.write("</table><br><br>");
   w.document.write("</body></html>");
   w.document.close();
}

function DisplayEssayResponse(courseName, lessonNumber, lessonName, topicName, question, response)
{
   // Creates and populates a window that allows the user
   // in stand alone mode to display an essay question.
   //

   var tmpstr;

   // Translate all the \n charcters to <P>
   //First, do this for question.
   tmpstr="";
   for (var i=0; i < question.length; i++) {
      if (question.substring(i,i+2) == "\r\n") {
         if (question.substring(i+2, i+4) == "\r\n")
            { tmpstr = tmpstr + "<P>";
              i = i + 3;}
         else
            { tmpstr = tmpstr + "<br>";
              i = i + 1;}
         }  
      else
         { tmpstr = tmpstr + question.substring(i, i+1); }
   }
   question=tmpstr;

   //Second, do this for response.
   tmpstr="";
   for (var i=0; i < response.length; i++) {
      if (response.substring(i,i+2) == "\r\n") {
         if (response.substring(i+2, i+4) == "\r\n")
            { tmpstr = tmpstr + "<P>";
              i = i + 3;}
         else
            { tmpstr = tmpstr + "<br>";
              i = i + 1;}
         }  
      else
         { tmpstr = tmpstr + response.substring(i, i+1); }
   }
   response=tmpstr;

   var dayInt;
   var fullYearInt;
   var monthInt;
   var monthStr;

   var today = new Date();
   dayInt = today.getDate();
   fullYearInt = today.getFullYear();
   monthInt = today.getMonth();

   if (monthInt == 0) 
      monthStr = "January";
   else if (monthInt == 1)
      monthStr = "February";
   else if (monthInt == 2)
      monthStr = "March";
   else if (monthInt == 3)
      monthStr = "April";
   else if (monthInt == 4)
      monthStr = "May";
   else if (monthInt == 5)
      monthStr = "June";
   else if (monthInt == 6)
      monthStr = "July";
   else if (monthInt == 7)
      monthStr = "August";
   else if (monthInt == 8)
      monthStr = "September";
   else if (monthInt == 9)
      monthStr = "October";
   else if (monthInt == 10)
      monthStr = "November";
   else if (monthInt == 11)
      monthStr = "December";
   else 
      monthStr = "Month";


   // Create and populate the essay display window
   var w=window.open("","essayDisplay","menubar=yes,resizable=yes,scrollbars=yes,width=600,height=450");
   w.document.open();
   w.document.write("<html><head><title>Your Response</title></head>");
   w.document.write("<body bgcolor=white onLoad='self.focus()'>");
   w.document.write("<center>");
   w.document.write("<h2>" + courseName + "</h2>");
   w.document.write("<font size=4>");
   w.document.write("<b>");
   w.document.write("Lesson " + lessonNumber + ":  " + lessonName);
   w.document.write("<br>");
   w.document.write("Topic:  " + topicName);
   w.document.write("<br>");
   w.document.write("Date:  " + monthStr + " " + dayInt + ", " + fullYearInt);
   w.document.write("</b>");
   w.document.write("</font>");
   w.document.write("</center>");
   w.document.write("<p>");
   w.document.write("Thank you for your thoughtful response.  Print this page for a record of your work by selecting File->Print from the menu.");
   w.document.write("<p>");
   w.document.write("<b>Question:</b>");
   w.document.write("<br>");
   w.document.write(question);
   w.document.write("<p>");
   w.document.write("<b>Response:</b>");
   w.document.write("<br>");
   w.document.write(response);
   w.document.write("</body></html>");
   w.document.close();
}

//Rollover Functions

function showrollover(evt, divname, idname) {
  var obj;
  var id_obj;
  var ScreenX;
  var ScreenY;
  var ObjX;
  var ObjY;
  var ScrollX;
  var ScrollY;
  var cursorX, cursorY;
  ScreenX = getInsideWindowWidth();
  ScreenY = getInsideWindowHeight();
  //alert("ScreenX=" + ScreenX);
  //alert("ScreenY=" + ScreenY);
  ObjX = getwidth(divname);
  ObjY = getheight(divname);
  //alert("ObjX=" + ObjX);
  //alert("ObjY=" + ObjY);

  if (isNav) {
     cursorX = evt.pageX;
     cursorY = evt.pageY;
  }
  else {
     cursorX = window.event.offsetX;
     cursorY = window.event.offsetY;
  }
  //alert("cursorX=" + cursorX);
  //alert("cursorY=" + cursorY);

  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname);
        ScrollX = window.pageXOffset;
        ScrollY = window.pageYOffset;
        //alert("ScrollX=" + ScrollX);
        //alert("ScrollY=" + ScrollY);
        if ((ScreenX - (cursorX + 10)) > ObjX) {
           obj.left = cursorX + 10;
        }
        else {
           obj.left = cursorX - 10 - ObjX;
        }

        if ((ScreenY - (cursorY - ScrollY)) < (ObjY + 10)) {
           obj.top = cursorY -10 - ObjY;
           //alert("should appear above cursor at " + obj.style.top);
        }
        else {
            obj.top = cursorY + 10;
           //alert("should appear below cursor at " + obj.style.top);
        }
     }
     else {
        obj = document.getElementById(divname); 
        ScrollX = document.body.scrollLeft;
        ScrollY = document.body.scrollTop; 
        //alert("ScrollX=" + ScrollX);
        //alert("ScrollY=" + ScrollY);
        if ((ScreenX - (cursorX + 10)) > ObjX) {
           obj.style.left = cursorX + 10;
        }
        else {
           obj.style.left = cursorX - 10 - ObjX;
        }

        if ((ScreenY - (cursorY - ScrollY)) < (ObjY + 10)) {
           obj.style.top = cursorY -10 - ObjY;
           //alert("should appear above cursor at " + obj.style.top);
        }
        else {
           //obj.style.pixelTop = cursorY + 10 + 25;
           obj.style.top = cursorY + 10;
           //alert("should appear below cursor at " + obj.style.top);
        }
     }          

     //alert("obj.style.left=" + obj.style.left);
     //alert("obj.style.top=" + obj.style.top);
  }

  if (isIE) {
     obj = eval("document.all." + divname);
     id_obj = eval("document.all." + idname);
     objname = "" + id_obj.tagName;
     ctr = 1;
     xOffset = 0;
     yOffset =  0;
     tblctr = 0;
     //alert("cursorX=" + cursorX + " cursorY=" + cursorY);
     while (ctr < 20)
     {
        //alert("Object name is " + objname + ". X offset = " + id_obj.offsetLeft + " Y offset = " + id_obj.offsetTop + " ctr = " + ctr);
        if (objname == "BODY"){
 	   break;
        }
        if (objname == "TABLE"){
           tblctr++;
           xOffset = xOffset + id_obj.offsetLeft;
           yOffset = yOffset + id_obj.offsetTop;
        }
        if (objname == "TD"){
           xOffset = xOffset + id_obj.offsetLeft;
           yOffset = yOffset + id_obj.offsetTop;
        }
        id_obj = id_obj.offsetParent;
        objname = "" + id_obj.tagName;
        ctr++;
     }
     //alert ("Total x offset is " + xOffset);
     //alert ("Total y offset is " + yOffset);
     cursorX = cursorX + xOffset;
     cursorY = cursorY + yOffset;
     ScrollX = document.body.scrollLeft;
     ScrollY = document.body.scrollTop;
     if ((ScreenX - (cursorX - ScrollX)) < (ObjX + 10)){
        obj.style.pixelLeft = cursorX - 10 - ObjX;
     }
     else {
        obj.style.pixelLeft = cursorX + 10;
     }
     if ((ScreenY - (cursorY - ScrollY)) < (ObjY + 10)) {
        obj.style.pixelTop = cursorY -10 - ObjY;
     }
     else {
        //obj.style.pixelTop = cursorY + 10 + 25;
        obj.style.pixelTop = cursorY + 10;
     }
  }

  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname); 
        obj.visibility = "visible"; 
     }
     else {      
        obj = document.getElementById(divname);
        obj.style.visibility = "visible";
     }
  }
  else {
     obj = eval("document.all." + divname);
     obj.style.visibility = "visible";
  }
}


function showrollover2(evt, divname, refname) {
  // Not sure what this is used for.
  var obj;
  var ScreenX;
  var ScreenY;
  var ObjX;
  var ObjY;
  var ScrollX;
  var ScrollY;
  var cursorX, cursorY;
  var pictureX, pictureY;
  ScreenX = getInsideWindowWidth();
  ScreenY = getInsideWindowHeight();
  ObjX = getwidth(divname);
  ObjY = getheight(divname);

  if (isNav) {
     cursorX = evt.pageX;
     cursorY = evt.pageY;
  }
  else {
     cursorX = window.event.offsetX;
     cursorY = window.event.offsetY;
  }

  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname);
        ScrollX = window.pageXOffset;
        ScrollY = window.pageYOffset;
        if ((ScreenX - (cursorX + 10)) > ObjX) {
           obj.left = cursorX + 10;
        }
        else {
           obj.left = cursorX - 10 - ObjX;
        }

        if ((ScreenY - (cursorY - ScrollY)) < (ObjY + 10)) {
           obj.top = cursorY -10 - ObjY;
        }
        else {
            obj.top = cursorY + 10;
        }
     }
     else {
        obj = document.getElementById(divname); 
        ScrollX = document.body.scrollLeft;
        ScrollY = document.body.scrollTop; 
        if ((ScreenX - (cursorX + 10)) > ObjX) {
           obj.style.left = cursorX + 10;
        }
        else {
           obj.style.left = cursorX - 10 - ObjX;
        }

        if ((ScreenY - (cursorY - ScrollY)) < (ObjY + 10)) {
           obj.style.top = cursorY -10 - ObjY;
        }
        else {
           obj.style.top = cursorY + 10;
        }
     }          
  }

  if (isIE) {
     obj = eval("document.all." + divname);
     ScrollX = document.body.scrollLeft;
     ScrollY = document.body.scrollTop;
     //picture offsets are required because IE tells you cursor position
     //relative to map, but sets div location relative to page
     pictureX = document.all.table1.offsetLeft;
     if (pictureX < 11){pictureX = 11;}
     //pictureY is also relative to table probably, but table almost at top of page.
     refobj = eval("document.all." + refname);
     pictureY = refobj.offsetTop;
     //There needs to be a correction factor because the cursor position
     //is relative to the picture so we need to add the picture position
     //relative to the page to get the cursor position relative to the page
     if ((ScreenX - ((cursorX + pictureX )- ScrollX)) < (ObjX + 10)){
        obj.style.pixelLeft = (cursorX + pictureX) - (ObjX + 10);
     }
     else {
        obj.style.pixelLeft = (cursorX + pictureX) + 10;
     }
     //The actual position of the cursor relative to the page is the position of
     //cursor relative to the picture + picture position relative to page, is the
     //position of the picture1 div just above the picture and the observation
     //that the picture is 17 pixels below the picture1 div.
     if ((ScreenY - ((cursorY + pictureY + 17) - ScrollY)) < (ObjY + 10)) {
        obj.style.pixelTop = cursorY -10 - ObjY + pictureY + 10;
     }
     else {
        obj.style.pixelTop = cursorY + 10 + 25 + pictureY + 10;
     }
  }

  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname); 
        obj.visibility = "visible"; 
     }
     else {      
        obj = document.getElementById(divname);
        obj.style.visibility = "visible";
     }
  }
  else {
     obj = eval("document.all." + divname);
     obj.style.visibility = "visible";
  }

}

function hiderollover(divname) {
  var obj;
  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname);
        obj.visibility = "hidden";
     }
     else {
        obj = document.getElementById(divname);
        obj.style.visibility = "hidden";
     }
  }
  if (isIE) {
     obj = eval("document.all." + divname);
     obj.style.visibility = "hidden";
  }
}

function handleResize() {
   location.reload();
   return false;
}

if (isNav) {
   window.captureEvents(Event.RESIZE);
   window.onresize = handleResize;
}

function getInsideWindowWidth() {
   if (isNav) {
      return window.innerWidth;
   }
   else {
      return document.body.clientWidth;
   }
}

function getInsideWindowHeight() {
   if (isNav) {
      return window.innerHeight;
   }
   else {
      return document.body.clientHeight;
   }
}


function getheight(divname) {
  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname);
        return obj.clip.height
     }
     else {
        obj = document.getElementById(divname);
        return obj.offsetHeight;
     }
  }
  if (isIE) {
     obj = eval("document.all." + divname);
     return obj.clientHeight; }
}

function getwidth(divname) {
  if (isNav) {
     if (theVersion==4) {
        obj = eval("document." + divname);
        return obj.clip.width;
     }
     else {
        obj = document.getElementById(divname);
        return obj.offsetWidth;
     }
   }
  if (isIE) {
      obj = eval("document.all." + divname);
     return obj.clientWidth; }
}


function donothing() {
  var a;
  a = 1;
}


// Added 021011 to submit test or test report request as Query String
function getTest()
{
	var url = "/cgi-win/auth/$assess.dll?RequestTest=yes";
	url += "&CourseCode=" + document.forms[0].CourseCode.value;
      url += "&LessonNumber=" + document.forms[0].LessonNumber.value;
      url += "&WhereCalledFrom=" + document.forms[0].WhereCalledFrom.value;
      url += "&TestOption=";
      if (document.forms[0].TestOption[0].checked)
	{	url += document.forms[0].TestOption[0].value;   }
	else
	{	url += document.forms[0].TestOption[1].value;  }
 	var WindowAssessment=window.open("../AssessmentWait.htm", "AssessmentWindow", "menubar=yes,resizable=yes,scrollbars=yes,width=550,height=400")
	WindowAssessment.location = url;
}

//Determines how many characters are in a qid.  Assume that 
function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

//Determine the length of QIDs in a form;
function getQIDlength(f)
{
    var i, j=8;
    var name;
    var QIDlength=0;
	
    for(i=0; i<f.elements.length; i++)
    {
	name=f.elements[i].name;
	//Is this a test question?
	if (isLetter(name.substr(0,1)) && 
   	    isLetter(name.substr(1,1)) && 	
	    isDigit(name.substr(2,1)) &&	
	    isDigit(name.substr(3,1)) &&
	    isDigit(name.substr(4,1)) &&
	    isDigit(name.substr(5,1)) &&

	    name.substr(6,2) == "QS"
	)
	{
		//Find how many digits there are
		while(isDigit(name.substr(j, 1)) && j < name.length) 
		{
		    j++;
		}
		return(j);
	}
    }
}	
// Added 5/3/03 to check a test to make sure all questions answered before submitting

function checktest(f)
{
   var i = 0;
   var j = 0;
   var numq = 0;
   var tmpqname = "";
   var questmiss = "";
   var tmpstr = "notblank";
   var tmpchk = "notchecked";
   var foundtest = false;
   var firsthiddenaftertest = true;
   var currtype = "";
   var QIDlength;
   msg = "You have not answered all the questions.  Please\n";
   msg += "check the question numbers listed below and resubmit\n"
   msg += "the test.\n\n";
   var QIDlength;
   QIDlength=getQIDlength(f);

   do
   {


      if (i > 2000)
      {
         alert("Problem in checking program or over 2000 question options.");
         return false;
      }

      if (i >= (f.elements.length - 1))
      {
         // action if increment past last array element

         if (questmiss != "")
         {
            msg += questmiss + "\n";
            alert (msg);
            return false;
         }
         return true;
      }

//      alert(f.elements[i].name + " " + i + " " + f.elements[i].type);

	
      if (f.elements[i].type == "checkbox" || f.elements[i].type == "radio" || 	f.elements[i].type.toString() == "text")
      {
         foundtest = true;

         if (f.elements[i].type == "text")
         {
            // First question element.  Only one for FIB, but multiple for Matching

            currtype = f.elements[i].type;

            if (f.elements[i].name.substr(0,QIDlength) != tmpqname)
            {
               // Different name means new question number.
               // First see how to process old question to see if answered.
               if (numq > 0)
               {
                  if (f.elements[i-1].type == "text")
                  {
                     if (tmpstr == "blank")
                     {
                        questmiss += numq + " ";
                     }
                  }
                  else
                  {
                     if (tmpchk == "notchecked")
                     {
                        questmiss += numq + " ";
                     }
                  }
               }
 
               numq++;
               tmpqname = f.elements[i].name.substr(0,QIDlength);
               tmpstr = "notblank";
               tmpchk = "notchecked";
            } 
  
            //tmpstr = "notblank";
           

            if (f.elements[i].value == "")
            { 
               tmpstr = "blank";
            }

            do
            {
               i++;

               if (i > 2000)
               {
                   alert("Problem in checking program or over 2000 question options.");
                   return false;
               }

               if (i == f.elements.length)
               {
                  // action if increment past last array element
                  if (questmiss != "")
                  {
                     msg += questmiss + "\n";
                     alert (msg);
                     return false;
                  }
                  return true;
               }
               // incrementing i has moved to new question so mark status of previous question.
               if (f.elements[i].name.substr(0,QIDlength) != tmpqname)
               {
                  if (numq > 0)
                  {
                     if (f.elements[i-1].type == "text")
                     {
                        if (tmpstr == "blank")
                        {
                           questmiss += numq + " ";
                        }
                        tmpstr = "notblank";
                     }
                     else
                     {
                        if (tmpchk == "notchecked")
                        {
                           questmiss += numq + " ";
                        }
                        tmpchk = "notchecked";
                     }
                  }
 
                  numq++;
                  tmpqname = f.elements[i].name.substr(0,QIDlength);
                  currtype = f.elements[i].type;
                  if (f.elements[i].type == "text")
                  {
                     if (f.elements[i].value == "")
                     {
                        tmpstr = "blank";
                     }
                  }
                  else
                  {
                     if (f.elements[i].checked)
                     {
                        tmpchk = "checked";
                     }
                  }
                  break;
               } 


               if (f.elements[i].value == "")
               { 
                  tmpstr = "blank";
               }

             
            } while (true);
         }

         if (f.elements[i].type == "radio" || f.elements[i].type == "checkbox")
         {

            currtype = f.elements[i].type;

            if (f.elements[i].name.substr(0,QIDlength) != tmpqname)
            {
               // Different name means new question number.
               // First see how to process old question to see if answered.
               if (numq > 0)
               {
                  if (f.elements[i-1].type == "text")
                  {
                     if (tmpstr == "blank")
                     {
                        questmiss += numq + " ";
                     }
                  }
                  else
                  {
                     if (tmpchk == "notchecked")
                     {
                        questmiss += numq + " ";
                     }
                  }
               }
 
               numq++;
               tmpqname = f.elements[i].name.substr(0,QIDlength);
               tmpchk = "notchecked";
               tmpstr = "notblank";
            } 
  
            //tmpchk = "notchecked"

            if (f.elements[i].checked)
            { tmpchk = "checked"; }

            do
            {

               i++;

               if (i > 2000)
               {
                   alert("Problem in checking program or over 2000 question options.");
                   return false;
               }

               if (i >= f.elements.length)
               {
                  // action if increment past last array element
                  if (questmiss != "")
                  {
                     msg += questmiss + "\n";
                     alert (msg);
                     return false;
                  }
                  return true;
               }

               if (f.elements[i].name.substr(0,QIDlength) != tmpqname)
               {
		

                  if (numq > 0)
                  {
                     if (f.elements[i-1].type == "text")
                     {
                        if (tmpstr == "blank")
                        {
                           questmiss += numq + " ";
                        }
                     }
                     else
                     {
                        if (tmpchk == "notchecked")
                        {
                           questmiss += numq + " ";
                        }
                     }

                     tmpstr = "notblank";
                     tmpchk = "notchecked";
                  }
 
                  numq++;
                  tmpqname = f.elements[i].name.substr(0,QIDlength);
                  currtype = f.elements[i].type;
                  if (f.elements[i].type == "text")
                  {
                     if (f.elements[i].value == "")
                     {
                        tmpstr = "blank";
                     }
                  }
                  else
                  {
                     if (f.elements[i].checked)
                     {
                        tmpchk = "checked";
                     }
                  }
                  break;
               } 

               
               if (f.elements[i].checked)
               { tmpchk = "checked"; }

             } while (true);
         }


      }
      
      i++;
      if (foundtest && f.elements[i].type == "hidden" && firsthiddenaftertest)
      {
         firsthiddenaftertest = false;
         if (f.elements[i-1].type == "text")
         {
            if (tmpstr == "blank")
            {
               questmiss += numq + " ";
            }
         }
         if (f.elements[i-1].type == "checkbox" || f.elements[i-1].type == "radio")
         {
            if (tmpchk == "notchecked")
            {
               questmiss += numq + " ";
            }
         }
       }

   } while (true);

}


