// control.js includes general purpose JavaScript routines// which are loaded into the majority of pages// functions are listed first followed by routines that run// when the page loads// Cookie functions - ex Goodman: JavaScript Handbookfunction getCookieVal(offset) {  var endstr = document.cookie.indexOf (";", offset);  if (endstr == -1)    endstr = document.cookie.length;  return unescape(document.cookie.substring(offset, endstr));}function GetCookie(name) {  var arg = name + "=";  var alen = arg.length;  var clen = document.cookie.length;  var i = 0;  while (i < clen) {    var j = i + alen;	   if (document.cookie.substring(i, j) == arg)     return getCookieVal (j);    i = document.cookie.indexOf(" ", i) + 1;    if (i == 0) break;   }  return null;}function SetCookie(name, value) {  var argv = SetCookie.arguments;  var argc = SetCookie.arguments.length;  var expires = (argc > 2) ? argv[2] : null;  var path = (argc > 3) ? argv[3] : null;  var domain = (argc > 4) ? argv[4] : null;  var secure = (argc > 5) ? argv[5] : false;  document.cookie = name + "=" + escape (value) +    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +    ((path == null) ? "" : ("; path=" + path)) +//    ("; path=" + "/") +	((domain == null) ? "" : ("; domain=" + domain)) +    ((secure == true) ? "; secure" : "");}function DeleteCookie(name) {  var exp = new Date();  exp.setTime (exp.getTime() - 1);  // This cookie is history  var cval = GetCookie (name);  if (cval != null)    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();}// end of Goodman's cookie functions// change() accepts a string, a position in the string and// a character to substitute at that position// it returns a string in which the character at position 'pos'// in the input string is replaced by character 'ch'// NB first character in a string is at pos = 0function change(theString, pos, ch) {	frontEnd = theString.substring(0, pos)	backEnd = theString.substring(pos + 1, theString.length)	return frontEnd + ch + backEnd}// stubName() accepts a path and returns the name of the file// stripped of the extension (usually '.htm')// a variation using '\' rather than '/' as delimiter is// required to accommodate MSIE for Windowsfunction stubName(theFile) {	if (theFile.lastIndexOf("/") > 1) {		return theFile.substring(theFile.lastIndexOf("/") + 1, theFile.lastIndexOf("."))	} else {		return theFile.substring(theFile.lastIndexOf("\\") + 1, theFile.lastIndexOf("."))	}	}// allowAccess() changes characters in a string from '0' to '1'// to indicate that the user is permitted to access resources// the result is stored in the major cookie// access is released progressively as the user movesfunction allowAccess(collection,n1,n2) {	for (var n = n1; n <= n2; n++) {		collection = change(collection,n,"1")	}	return collection}// function to flash JPEG images for email// used rather than animated GIFs to preserve image qualityfunction flash() {	if (flashState == 1) {		document.images[0].src = flashOff.src		flashState = 0	} else {		document.images[0].src = flashOn.src		flashState = 1	}	timerID = setTimeout("flash()",500)}// ---- functions above// ---- from here down is actionfunction checkLocation() {	// first set an expiry date for the persistent cookie	expdate = new Date()	expdate.setTime(expdate.getTime() + (30 * 24 * 60 * 60 * 1000))	// 30 days from now	// now see who we are and how far we have come in the materials	cookieName = GetCookie("currentUser")	// if the currentUser cookie is not null the user has logged in	// so we need to read and update the tracking cookie	// the variables stored are:	// resourceAccess 41 characters to progressively release resources	// consultAccess 24 characters to release feedback	// expand 16 characters to control pop-down menu lists	// emailStatus 1 character for tracking progress in problem 3	// resumePath variable length path for resuming position	if (cookieName != null) { 		cookieValue = GetCookie(cookieName)		resourceAccess = cookieValue.substring(0,41)		consultAccess = cookieValue.substring(41,65)		expand = cookieValue.substring(65,81)		emailStatus = cookieValue.substring(81,82)		resumePath = cookieValue.substring(82,cookieValue.length)		//		alert(location.href + "\n" + resourceAccess + "\n" + consultAccess + "\n" + expand)			// grab the location of the current page		shortName = stubName(window.location.pathname)			// test first for a feedback page after completion of a task	// if so adjust record of completed tasks	// and adjust consultant access to match		// feedback page names are coded to support access control	// more than one task may be completed at a time			if (shortName.length == 4 && shortName.substring(0,2) == "fb") {				n1 = (parseInt(shortName.charAt(2)) - 1) * 6			n2 = (parseInt(shortName.charAt(2)) - 1) * 6 + parseInt(shortName.charAt(3)) - 1			consultAccess = allowAccess(consultAccess,n1,n2)		}	// next test if we are at a desk location and	// if so adjust record of resources	// n1 is problem number, n2 is desk number in problem		if (shortName.substring(0,4) == "desk") {			if (shortName.charAt(4) == "0") { // home location '00'				n1 = 0				n2 = 0			} else {				n1 = (parseInt(shortName.charAt(4)) - 1) * 10 + 1				n2 = (parseInt(shortName.charAt(4)) - 1) * 10 + parseInt(shortName.charAt(5))			}			resourceAccess = allowAccess(resourceAccess,n1,n2)	// if the page is of form 'desknn' this is a frameset definition	// so mark it as the resume location 						if (shortName.length == 6) {				resumePath = document.location.href			}				// problems 3 & 4 include some framesets of form 'desknna'	// so check for those in addition						if (shortName.length > 6) {				if(shortName.charAt(6) == "a" && shortName.charAt(7) != "t" && shortName.charAt(7) != "b") {					resumePath = document.location.href				}			}		}	// now that variables have been updated write the values back	// to the main cookie which is used to track the user	  SetCookie(cookieName, resourceAccess + consultAccess + expand + emailStatus + resumePath,expdate,"/")		  	// this cookie is used to locate the correct help screen	// store the current page location every time it runs	// except when this is the help page	// it is need only after login since prior pages call the help contents		if (shortName.indexOf("help") == -1) {			SetCookie("PBLtemp",location.href,null,"/")		}	}}// Macromedia Fireworks functions to handle rolloversfunction MM_swapImgRestore() { //v2.0  if (document.MM_swapImgData != null)    for (var i=0; i<(document.MM_swapImgData.length-1); i+=2)      document.MM_swapImgData[i].src = document.MM_swapImgData[i+1];}function MM_preloadImages() { //v2.0  if (document.images) {    var imgFiles = MM_preloadImages.arguments;    if (document.preloadArray==null) document.preloadArray = new Array();    var i = document.preloadArray.length;    with (document) for (var j=0; j<imgFiles.length; j++) if (imgFiles[j].charAt(0)!="#"){      preloadArray[i] = new Image;      preloadArray[i++].src = imgFiles[j];  } }}function MM_swapImage() { //v2.0  var i,j=0,objStr,obj,swapArray=new Array,oldArray=document.MM_swapImgData;  for (i=0; i < (MM_swapImage.arguments.length-2); i+=3) {    objStr = MM_swapImage.arguments[(navigator.appName == 'Netscape')?i:i+1];    if ((objStr.indexOf('document.layers[')==0 && document.layers==null) ||        (objStr.indexOf('document.all[')   ==0 && document.all   ==null))      objStr = 'document'+objStr.substring(objStr.lastIndexOf('.'),objStr.length);    obj = eval(objStr);    if (obj != null) {      swapArray[j++] = obj;      swapArray[j++] = (oldArray==null || oldArray[j-1]!=obj)?obj.src:oldArray[j];      obj.src = MM_swapImage.arguments[i+2];  } }  document.MM_swapImgData = swapArray; //used for restore}