/*
Name: start.js
Author: Jared Butterfield
Purpose: The start.js file is used as a general global javascript 
resource for all Independent Study web courses and provides the 
behavioral portion of the student's interactive learning experience 
on the web.
*/

/*------------------Global variables-----------------*/
var newwin; //Name of all popup windows.

/*------------------loadFunctions--------------------
Completes all of the javascript initialization when a page is loaded.
loadFunctions is called in the ONLOAD event of the body tag.
---------------------------------------------------*/

function loadFunctions()
{
	/*Sizes the image divs to allow for formatting of images and associated divs on the page.*/
	for( i=0; i < document.images.length; i++)
	{
		var imgwidth = document.images[i].width;
		var thumbwidth = imgwidth + 60;
		var imgclass = document.images[i].parentNode.className;
		var thumbclass = document.images[i].parentNode.parentNode.className;
		
		/*If image is media, then causes the encasing div to have its width, 
		thus making the caption/credit be the same width as the image.*/
		if(imgclass.substr((imgclass.length-5),5) == "image" || imgclass.substr((imgclass.length-11),5) == "image"){
			document.images[i].parentNode.style.width = (imgwidth + "px");
		}
		
		if(thumbclass == "divimage"){
			document.images[i].parentNode.parentNode.style.width = (thumbwidth + "px");
		}
		
		
		if(imgclass.substr((imgclass.length-11),5) == "image"){
			var divNode = document.images[i].nextSibling.nextSibling.firstChild;
			if(divNode.innerHTML == ''){
				divNode.style.display = "none";
			}
			divNode = divNode.nextSibling;
			if(divNode.innerHTML == ''){
				divNode.style.display = "none";
			}
		}
	}
	
	/*Sizing for Flash objects embedded inside the page*/
	if(document.getElementsByTagName('object') != null){
		var flasharray = document.getElementsByTagName('object');
		var divimage = null; 
		var flashwidth = 0;
		for (i=0; i < flasharray.length; i++){
			flashwidth = flasharray[i].getAttribute('width');
			flashwidth = parseInt(flashwidth) + 60;
			divimage = flasharray[i].parentNode;
			divimage.style.width = (flashwidth + "px");
		}		
	}	
	/*Runs functions for mastery check page*/
	if(document.getElementById("mcbuttons_top") != null){
		initializePage();
	}
	
	/*Initializes the user preferences cookie*/
	if(window.name != "print"){
		setOptions(null,null,null);
	}
	
	/*Detects if the window name is print. If so, inserts an overriding stylesheet and does
	other operations specific to the print version of the web course.
	Otherwise, declares the name of "parentWin" for the search tool.*/
	if(window.name == "print"){
		var headnode = document.getElementsByTagName('head')[0];
		var newcss = document.createElement("link");
		newcss.setAttribute("rel", "stylesheet");
		newcss.setAttribute("type", "text/css");
		newcss.setAttribute("media", "all");
		newcss.setAttribute("href", "/is/global/css/print.css");
		headnode.appendChild(newcss);
		
		//Removes the A tag from the course title
		var hometitle = document.getElementsByTagName('h1')[0];
		var hometag = null;
		for (var i=0; i<hometitle.childNodes.length; i++){
			if(hometitle.childNodes[i].nodeType == 1) {
				hometag = hometitle.childNodes[i];
				break;
			}
		}
		var homespan = null;
		for (i=0; i<hometag.childNodes.length; i++){
			if(hometag.childNodes[i].nodeType == 1) {
				homespan = hometag.childNodes[i];
				break;
			}
		}
		hometitle.appendChild(homespan);
		hometag = hometitle.removeChild(hometag);
		
		//Wait for window to load before displaying print dialogue
		setTimeout("window.print()",1300);
	}
	else{
		window.name="parentWin";
	}
}
//------------------End loadFunctions---------------

/*------------------Search Javascript----*/

function openSearch(){
	var w = window.open('../search/search.html?zoom_query='+document.getElementById('searchfield').value.replace(' ','+'),'searchWindow','width=560, height=600, locationbar=no, menubar=no, toolbar=no, scrollbars=yes, resizable=yes, screenX='+(screen.width - 560)/2+', screenY='+((screen.height - 600)/2 - 20)+', left='+(screen.width - 560)/2+', top='+((screen.height - 600)/2 - 20)); 
	w.focus();
	return false;
}


//------------------Search Feedback-----------


/*------------------Feedback Javascript----*/

function validateForm(){
	var field;
	var notvalid = false;
	var missing = "Please fill in:\n"
	field = document.FeedbackForm.Name.value;
	if(field==''){notvalid=true; missing+="Full Name\n"}
	field = document.FeedbackForm.email.value;
	if(field==''){notvalid=true; missing+="Email Address\n"}
	field = document.FeedbackForm.Course_Access_Code.value;
	if(field==''){notvalid=true; missing+="Course Access Code\n"}
	field = document.FeedbackForm.comments.value;
	if(field==''){notvalid=true; missing+="Comments\n"}
	if(notvalid){alert(missing); return false; }	
	else{return true;}
}

function loadLocation()
{
	//Changes input Location to have the location of the window that called Feedback
	document.FeedbackForm.Location.value = opener.location;
}


//------------------End Feedback-----------



/*------------------Course Open Window---------------
Opens a window to the given url and centers it in the screen.
url    - URL to link to
width  - width of the window
height - height of the window
---------------------------------------------------*/
function openWindow(url,width,height)
{
	if(width == null) width = 560;
	if(height == null) height = 500;
	var topedge = (screen.height - height)/2 - 20;
	var leftedge = (screen.width - width)/2;

	newwin = window.open(url,"","width="+width+", height="+height+", scrollbars=yes, resizable=yes, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
	newwin.focus();
}
//------------------End Course Open Window-----------


/*------------------Open Popup Window---------------
Opens a window to the given url and centers it in the screen. There are NO scrollbars for the WINDOW.
url    - URL to link to
width  - width of the window
height - height of the window
---------------------------------------------------*/
function openPopup(url,width,height)
{
	if(width == null) width = 560;
	if(height == null) height = 500;
	var topedge = (screen.height - height)/2 - 20;
	var leftedge = (screen.width - width)/2;

	newwin = window.open(url,"","width="+width+", height="+height+", scrollbars=no, resizable=yes, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
	newwin.focus();
}
//------------------End Open Popup Window-----------

/*------------------Open Info Window---------------
Opens a small window with preset dimensions and no scrollbars. Used for orientation popups.
url    - URL to link to
width  - width of the window
height - height of the window
---------------------------------------------------*/
function openInfo(url)
{
	var width = 550;
	var height = 250;
	var topedge = (screen.height - height)/2 - 20;
	var leftedge = (screen.width - width)/2;

	//test if the window has been opened
	if (newwin)
	{newwin.close();}

	//open window
	newwin = window.open(url,"infowindow","width="+width+", height="+height+", scrollbars=no, resizable=yes, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
	newwin.focus();
}
//------------------End Open Info Window-----------

/*------------------printVersion---------------------
When the user wants a printer version of the html page, this method its called.  
It opens up a new window with the same page and calls the window "print".  When
the loadFunctions function is called in the onload, it looks to see if the name
of the window is "print". If it is, the style sheet is changed to "print.css".
---------------------------------------------------*/
function printVersion()
{
	var win = window.open(location,"print","width=800,height=600,menubar,scrollbars,toolbar");
	win.focus();
}

/*------------------submitEmail---------------------deprecated
On instructor graded assignments that need to be submitted by email, this function is called to append
the student's barcode to the subject line of the email that is then opened to go to Independant Study.
---------------------------------------------------*/
function submitEmail(course,section,lesson)
{
	var barcode = document.getElementById("studentid").value;
	parent.location="mailto:is_lesson@byu.edu?subject="+course+", Section "+section+", Lesson "+lesson+", Barcode "+barcode;	
}


/*------------------setOptions--------------------------
Anytime the font or size or scrollmenu is changed, this function needs to be called to change
styles on the page and store it to the cookie.  If a null is passed into one of
the values, the needed value will be taken from the cookie.  If it isn't in the
cookie, then it is set to the default of "Verdana" for the font family and 12 for
the size.  This function should not be called directly from the html.  Please use
changeFont and changeSize instead.
font - The new font family.  Pass in null to use the stored cookie value.
size - The new font size.  Pass in null to use the stored cookie value.
nav - Toggle for scrollable navigation. Pass in null to use the stored cookie value.
---------------------------------------------------*/
//Size of the font
var fontSize = null;
var fontFamily = null;
var navToggle = null;
var tablearray = null;

function setOptions(font,size,nav)
{
	var cookie = fontCookie();
	if(font == null && cookie != "none") {font = cookie.substring(cookie.indexOf("font:")+5,cookie.indexOf(",size:"));}
	else if(font == null && cookie == "none") {font = "Verdana";}
	if(size == null && cookie != "none"){
		size = parseInt(cookie.substring(cookie.indexOf("size:")+5,cookie.indexOf(",nav:")));
		if(isNaN(size)) {size = 14;}
	}
	else if(size == null && cookie == "none") {size = 14;}
	if(nav == null && cookie != "none") {
		nav = cookie.substring(cookie.indexOf("nav:")+4,cookie.length);
		if (nav != "false" && nav != "true") {nav = false;}
		else if(nav == "true") {nav=true;}
		else {nav=false;}
	}
	else if(nav == null && cookie == "none") {nav = false;}
	
	fontFamily = font;
	fontSize = size;
	navToggle = nav;
	//alert(fontFamily);
	var element = document.getElementById("fontfamily");
	if(!element) return;
	if(fontFamily == "Verdana") element.selectedIndex = 0;
	else if(fontFamily == "Arial") element.selectedIndex = 1;
	else if(fontFamily == "Times") element.selectedIndex = 2;
	else element.selectedIndex = 1;
	fontCookie("font:" + font + ",size:" + size + ",nav:" + nav);
	document.getElementById("contentbody").style.fontFamily = font;
	document.getElementById("contentbody").style.fontSize = (size + "px");
	tablearray = document.getElementById("contentbody").getElementsByTagName("table");
	for (var t=0; t<tablearray.length; t++){
		tablearray[t].style.fontSize = (size + "px");
	}
	document.getElementById("scrollbox").checked = navToggle;
	toggleScroll(navToggle, true);
}
//------------------End setOptions----------------------





/*------------------changeFont-----------------------
Changes the font family of the page and stores it in a cookie to be used on
every page.
newFamily - The name of the new font family.
---------------------------------------------------*/
function changeFont(newFamily){
	setOptions(newFamily,fontSize,navToggle);
}
//------------------End changeFont-------------------





/*------------------changeSize-----------------------
Changes the size of the font and stores it in a cookie to be used on every page.
direction - either "increase" to increase font size by one or "decrease" to
	decrease font size by one.
---------------------------------------------------*/


function changeSize(direction){
	if (direction == "increase") fontSize += 1;
	else 
	{
		if (fontSize > 8) fontSize -= 1;
		else fontSize = 8;
	}
	setOptions(fontFamily,fontSize,navToggle)
}
/*------------------end of changeSize-----------------------*/

var autoScroll;
var held=false;
/*------------------NavScrolling---------------------*/
function toTop(){
	document.getElementById("navlist").scrollTop = 0;	
}

function toBottom(){
	document.getElementById("navlist").scrollTop = document.getElementById("navlist").scrollHeight;
}

function scrollUp(){
	if(!held){
	document.getElementById("navlist").scrollTop -= 30;
	}
	held=false;
}

function scrollDown(){
	if(!held){
	document.getElementById("navlist").scrollTop += 30;
	}
	held=false;
}

function autoNav(direction){
	autoScroll = window.setInterval("moveNav(\""+direction+"\");", 100);
}

function moveNav(direction){
	held = true;
	if(direction == "up"){
		document.getElementById("navlist").scrollTop -= 8;
	}
	else{
		document.getElementById("navlist").scrollTop += 8;
	}
}

function clearTimer(){
	window.clearInterval(autoScroll);
}

function setNav(){
	listTop = document.getElementById("navlist").offsetTop;
	activeTop = document.getElementById("active").offsetTop;
	if(navigator.userAgent.indexOf("MSIE") != -1){
		document.getElementById("navlist").scrollTop = 0 + activeTop;
	}
	else{
		document.getElementById("navlist").scrollTop = 0 + (activeTop - listTop);
	}
}

function toggleScroll(turnOn, fromCookie){
	if(turnOn){
		document.getElementById("scrollbuttons").style.display = "block";
		document.getElementById("navlist").style.height = "250px";
		document.getElementById("navlist").style.overflow = "hidden";
		/*document.getElementById("last").style.paddingBottom = "283px";*/
		setNav();
	}
	else{
		document.getElementById("scrollbuttons").style.display = "none";	
		document.getElementById("navlist").style.height = "auto";
		document.getElementById("navlist").style.overflow = "visible";
		/*document.getElementById("last").style.paddingBottom = "0px";*/
	}
	if(fromCookie == null){setOptions(fontFamily,fontSize,turnOn);}
}
/*------------------End of NavScrolling---------------------*/



/*------------------fontCookie-----------------------
Stores a cookie with the FONT name.
sel - The storing to be stored in the cookie
---------------------------------------------------*/
function fontCookie(sel)
{
	var p;
	var l = new String(location);
	if(l.indexOf("/courses/univ/") != -1) p= "/courses/univ/";
	else p = "";
	var FONT = new Cookie(document, "FONT", 8760, p, ".byu.edu");
	oldCookie = FONT.load();
	
	if(!oldCookie){
			if (sel != null) FONT.font = sel;	 // stores the drive 
			else return "none";
			FONT.store();
			return FONT.font;
	}
	else {
		if (sel != null) {
			FONT.font = sel;
			FONT.store();
		}
		return FONT.font;
	}
}
//------------------End FontCookie-------------------







/*------------------fontDel--------------------------
Deletes the FONT value in the cookie.
---------------------------------------------------*/
function fontDel()
{
	var FONT = new Cookie(document, "FONT", 8760, "/courses/univ", ".byu.edu");
	FONT.remove();
} 
//------------------End fontDel----------------------



/*------------------clip-----------------------------
Completes all of the javascript initialization when a page is loaded.
loadFunctions is called in the ONLOAD event.
---------------------------------------------------*/
function clip(file)
{	
	var topedge = (screen.height - 310)/2 - 20;
	var leftedge = (screen.width - 370)/2;
	
	var w;
	w=window.open("","","height=310,width=370,toolbar=no,scrollbars=no,screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
	w.document.write('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Video Clip</title></head><body>');
	w.document.write('<embed src="' + file + '" bgcolor="#ffffff" width="350" height="280" scale=tofit pluginspace="http://www.apple.com/quicktime/download/" autoplay="true" volume="100" cache="true">');
	w.document.write('</body></html>');
}
//------------------End clip--------------------------




/*------------------flash----------------------------
Loads a flash object either in a popup window or in the page.
src    - The source of the flash object
width  - The width of the flash object 
height - The height of the flash object
popup  - true or false, load the flash in popup window
---------------------------------------------------*/
function flash(src,width,height,popup)
{
	if(width == null) width = 550;
	if(height == null) height = 420;
	var html = "";
	var w;
	if(popup)
	{
		var topedge = (screen.height - height+25)/2 - 20;
		var leftedge = (screen.width - width+20)/2;
	
		w = window.open("","","height="+(height+25)+",width="+(width+20)+"menubar=no,toolbar=no,scrollbars=no,resizable=no, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
		html += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Flash Clip</title></head><body>';
		height = "100%";
		width = "100%";
	}
	else w = window;
	html += '<object height="'+height+'" width="'+width+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
	html += '<param value="'+src+'" name="movie"/>';
	html += '<param name=FlashVars value="cdROMdrive='+CDPath()+'"/>';
	html += '<param value="high" name="quality"/>';
	html += '<param value="#FFFFFF" name="bgcolor"/>';
	html += '<embed FlashVars="cdROMdrive='+CDPath()+'" height="'+height+'" width="'+width+'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" quality="high" src="'+src+'"/>';
	html += '</object>';
	if(popup) html += '</body></html>';
	w.document.write(html);
	if(popup) w.document.close();
}
//------------------End flash-------------------------

function image(src, width, height, title, popup)
{
	var html = "";
	var w;
	if(popup)
	{
		if(width == null) width = 560;
		if(height == null) height = 500;
		height = height + 25;
		width = width + 25;
		var topedge = (screen.height - height)/2 - 20;
		var leftedge = (screen.width - width)/2;
		w = window.open("","","height="+ height +",width="+ width +"menubar=no, toolbar=no, resizable=yes, scrollbars=yes, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
		html += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Image Window</title></head><body>';
	}
	else w = window;
	html += '<img src="'+src+'" alt="'+title+'"/>';
	if(popup) html += '</body></html>';
	w.document.write(html);
	w.document.close();
}



/*------------------CDDel----------------------------
Deletes the CDROM value in the cookie.
---------------------------------------------------*/
function CDDel()
{
	var CDROM = new Cookie(document, "CDROM", 8760, "/courses/univ", ".byu.edu");
	CDROM.remove();
} 
//------------------End CDDel------------------------






/*------------------CDCookie-------------------------
This function stores which drive they selected is their cd drive.  
it gets the drive, and if specified, it sets it to sel.
sel - value to set the CD-ROM drive cookie to
---------------------------------------------------*/
function CDCookie(sel)
{
	var p;
	var lc = new String(location);
	if(lc.indexOf("/courses/univ/") != -1) p= "/courses/univ/";
	else p = "";
	var CDROM = new Cookie(document, "CDROM", 8760, p, ".byu.edu");
	oldCookie = CDROM.load();
	
	if(!oldCookie){
			if (sel != null) CDROM.drive = sel;	 // stores the drive 
			else return "none";
			CDROM.store();
			return CDROM.drive;
	}
	else {
		if (sel != null) {
			CDROM.drive = sel;
			CDROM.store();
		}
		return CDROM.drive;
	}
}
//------------------End CDCookie---------------------





/*------------------CDPath---------------------------
Returns the CDROM drive letter that's stored in the cookie.  Returns "none"
if there is no drive letter in the cookie.
---------------------------------------------------*/
function CDPath() 
{
	var drv;
	var agt = navigator.userAgent.toLowerCase();
	if (agt.indexOf("mac")!=-1 && agt.indexOf("msie")!=-1) drv = "webclips";
	else if (agt.indexOf("mac") != -1) drv = "volumes/webclips";
	else drv = CDCookie();
	return drv;
}
//------------------End CDPath-----------------------





/*------------------CDCheck--------------------------
Checks to see if there is a CDROM drive letter stored in the cookie.  If there isn't,
it pops up a CD drive setup window.
---------------------------------------------------*/
function CDCheck() 
{
	drv = top.CDPath();
	if (drv == "none") {
		CDSetup();
		return false;
	}
	return true;
}
//------------------End CDCheck----------------------


/*------------------swapImage------------------------
Removes an image in a page and replaces it with a new one.
wndw     - The window that contains the image.  Usually passed in as "window" without the quotes
arraynum - The name if the image to be swapped or the array number in the document.images array
isource  - The url of the new image
---------------------------------------------------*/
function swapImage(wndw,arraynum,isource)
{
        if (isNaN(parseInt(arraynum)) && wndw.document[arraynum]) wndw.document[arraynum].src = isource;
        else if (wndw.document.images[arraynum]) wndw.document.images[arraynum].src = isource;
}
//------------------End swapImage--------------------


/*------------------Cookie Code-----------------------
The cookie object greatly eases the use of cookies on our pages
It starts out with no value.  It has several properties, most of which
are useless, but I'll leave there just in case.  

--------------------Section 1-------------------------
 
document = usually the current document object or literally "document" - without the quotes
name		= the name of the cookie

The following are properties of all cookies that are used by the browser.
Each property shares the same name as the parameter, except "days" where the real property name is "expiration"
 
days		= the days until the cookie expires
path		= the directories on this server where the cookie is available, in addition to this one.
domain	= other servers where the cookie is available
secure 	= boolean, if the cookie should only be sent encrypted	 
		
--------------------Section 2-------------------------

When one wants to store a value or values to a cookie, they have but to use the following convention:

	var myCookie = new Cookie(document, "thisCookie", 365);
	myCookie.value1 = "The stuff I want to put in";
	myCookie.value2 = "The stuff I want to put in";
	myCookie.store();

********** "value1", and "value2" don't need to be called that.  They could be "crazy_monkey_value" or "sinisterWaterMan1" whatever

This will store the cookie under the following format:
   
	var allCookies = document.cookie;
	alert(unescape(allCookies));	   // unescape replaces the %20's with spaces etc.
	 

Which would alert:
	"nameOfFirstCookie=value1:The stuff I want to put in&value2:The stuff I want to put in; 	  ...
	... expiration=Fri, 02-Jan-2002 00:00:00 GMT; path=/mypath; domain=http://www.mydomain.com; secure; ...
	... nameOfSecondCookie=value1:The stuff I want to put in ... etc. "
---------------------------------------------------*/

function Cookie(document, name, days, path, domain, secure)
{
	// These first are properties of Cookie.  It is essential that they use the convention _[property] because
	// by this they are distinguished from the values of the cookie	when in is stored.
	this._document = document;
	this._name = name;	  
	
	if (days) {
		this._expiration = new Date((new Date()).getTime() + days*24*60*60*1000);
	}
	else this._expiration = null;
	
	if (path) this._path = path; 		else this._path = null;
	if (domain) this._domain = domain; 	else this._domain = null;
	if (secure) this._secure = true; 	else this._secure = false;	 
	
	//The following are functions of the Object Cookie.  They are associated here, and defined right after this Object Constructor.
	this.store = _Cookie_store;	 
	this.load = _Cookie_load;
	this.remove = _Cookie_remove;

} // end Cookie
 
 
/*-----------function _Cookie_store, _Cookie_load, and _Cookie_remove-------------
These are functions of Cookie.  They are associated in the Cookie constructor, above.   
--------------------------------------------------------------------------------*/
function _Cookie_store()
{
	var cookievalue = "";
	
	// The following syntax "for ( var myProperty in myObject )".  puts the name of each property of Cookie
	// into "property" sequentially.  Then, the script tests to see if the property is either a function or 
	// a general property of a Cookie, like expiration, path, etc. (It does this by testing for the "_" as the 
	// first character, which is the convention) If it isn't, then it is a value and is stored into cookievalue 
	// following the convention described above.  
	
	for(var property in this) {	
		if ((property.charAt(0) == '_') || ((typeof this[property]) == 'function')) {continue;}	// typeof this[property] = what is the type of the current property?
		if (cookievalue != "") cookievalue += '&';
		cookievalue += property + ':' + escape(this[property]);  // escape encodes the spaces, ; " ', and other reserved characters, use unescape() to reverse.
	}
	
	// Now we are writing the actual cookie string.  We only need store one at a time, and will follow the convention described above
	// for the first cookie.  
	
	var cookie = this._name + '=' + cookievalue;  // myName=value1:my text output&value2=:my text output, etc.  
	if (this._expiration)	 
		cookie += '; expires=' + this._expiration.toGMTString();  // add "; expires=[the date]   toGMTString() is required.  
	if (this._path) cookie += '; path=' + this._path;		 //etc.
	if (this._domain) cookie += '; domain=' + this._domain;
	if (this._secure) cookie += '; secure';
	this._document.cookie = cookie;		//this actually stores the cookie into the _document defined in the Cookie constructor, usually document.
}
function _Cookie_load()
{
	var allcookies = this._document.cookie;	 // this string is exactly like the input described in Section 2, above. 
	if (allcookies == "") return false;		// if there are no cookies, then this isn't going to work
	var start = allcookies.indexOf(this._name + '=');  // getting the index in the string of the cookie we are referring to.  _name referres to the _name of the Cookie object's load method we called
		if (start == -1) return false;   // if it doesn't exist, we're gone.
		start += this._name.length + 1;
	var end = allcookies.indexOf(';', start);	// this feeds in information to the end of the values, right before we start into the general cookie properties.
		if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);
	
	// The following section takes each "myValueName:what i typed", and splits it off into currentValue, then stores the data into "a".  
	// It then chops that section of leftString, and continues until it reads them all..
	
	var a = new Array();
	leftString = cookieval;
	currentValue = "";
	if (typeof leftString == "string") { 
		index = leftString.indexOf('&');   // refer to convention described in Section 2, above.
		while (index != -1) {
			currentValue = leftString.substring(0,index);
			a[a.length] = currentValue;
			leftString = leftString.substring(index+1,leftString.length);
			index = leftString.indexOf('&');

		}
		a[a.length] = leftString;
	}// end if
	
	// This section takes all of the "myValueName:what I typed" from the "a" array and stores them back in "a".
	// Each entry in "a" then becomes an array with a length of 2 a[i][0] = myValueName and a[i][1] = what I typed
	  
	for(var i=0; i < a.length; i++) {
		tmp = new Array();
		temp1 = a[i];
		temp2 = "";
		if (typeof temp1 == "string") { 
			index = temp1.indexOf(':');
			while (index != -1) {
				temp2 = temp1.substring(0,index);  // splits it along the : and takes the left side
				tmp[tmp.length] = temp2;
				temp1 = temp1.substring(index+1,temp1.length);			// takes the right side.
				index = temp1.indexOf(':');
			}
		tmp[tmp.length] = temp1;	// stores the right side in the tmp array
		}
		
		a[i] = tmp;		// stores the tmp array in an entry of a
	}
	
	// these lines do this:
	//
	// for each entry in "a"
	//		make a property (named whatever is stored in a[i][0]) of the current Cookie object and in it store whatever is in a[i][1]
	 
	for( var i=0; i < a.length; i++) {
		this[a[i][0]] = unescape(a[i][1]);
	}
	return true;
}

function _Cookie_remove()
{
	var cookie;
	cookie = this._name + '=';
	if (this._path) cookie += '; path=' + this._path;
	if (this._domain) cookie += '; domain=' + this._domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';// this is the important line, it is set to expire in 1970, and the browser will delete it.
	this._document.cookie = cookie;
}

function CDSetup()
{
	var html = "";
	html += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>CDROM Setup</title><link href="../css/design.css" rel="stylesheet" type="text/css">';
	html += '<script type="text/javascript" language="javascript" src="/is/global/scripts/start.js"></script>';
	html += '<style>body {background:url();}</style></head>';
	html += '<body bgcolor="FFFFFF"><form name="CDform">';
	html += '<center><table border="0">';
	html += '<tr><td><b><i>My CD-ROM drive letter is:</i></b> <select name="thedrive" onchange="CDCookie(options[selectedIndex].value)">';
	html += '<option value="none"></option>';
	html += '<option value="none">Mac</option>';
	html += '<option value="A|">A:</option>';
	html += '<option value="B|">B:</option>';
	html += '<option value="C|">C:</option>';
	html += '<option value="D|">D:</option>';
	html += '<option value="E|">E:</option>';
	html += '<option value="F|">F:</option>';
	html += '<option value="G|">G:</option>';
	html += '<option value="H|">H:</option>';
	html += '<option value="I|">I:</option>';
	html += '<option value="J|">J:</option>';
	html += '<option value="K|">K:</option>';
	html += '<option value="L|">L:</option>';
	html += '<option value="M|">M:</option>';
	html += '<option value="N|">N:</option>';
	html += '<option value="O|">O:</option>';
	html += '<option value="P|">P:</option>';
	html += '<option value="Q|">Q:</option>';
	html += '<option value="R|">R:</option>';
	html += '<option value="S|">S:</option>';
	html += '<option value="T|">T:</option>';
	html += '<option value="U|">U:</option>';
	html += '<option value="V|">V:</option>';
	html += '<option value="W|">W:</option>';
	html += '<option value="X|">X:</option>';
	html += '<option value="Y|">Y:</option>';
	html += '<option value="Z|">Z:</option>';
	html += '</select></td><td><input type="button" value="Set CD Path" ';
	html += 'onclick=\'if (CDPath() != "none" && CDPath() != "volumes/webclips" && CDPath() != "webclips") ';
	html += 'alert("This course will look for the course CD on drive " + unescape(CDPath()).charAt(0).toUpperCase() + "."); ';
	html += 'else if (CDPath() != "none") ';
	html += 'alert("This course will look for the course CD on " + CDPath()); opener.location = opener.location; window.close();\'> ';
	html += '</tr></table></center></form>';
	html += '<p align="center"><a href="#" onclick="window.close()">Close this window</a></p>';
	html += '</body></html>';
	html += '';
	var topedge = (screen.height - 70)/2 - 20;
	var leftedge = (screen.width - 500)/2;
    var mywin = window.open("","","width=500,height=70,toolbar=no,menubar=no,resizable=no,scrollbars=no,screenX=" + leftedge + ",screenY=" + topedge);
	if(!mywin) alert("Please enable popup windows on your browser for this course to work properly.");
	mywin.document.write(html);
	mywin.document.close();
}

/*------------------Disclaimer Script----------------
This is the script for the disclaimer.  Any time there is a link, use the function openLink(URL)
to open that link with the disclaimer.  Just pass in the URL into the function and the link will be 
opened.  Be aware that sometimes the link will not work if the pagelinked to uses javascript in 
frames.  This is due to how that page's javascript uses it's frame page, it willaccess the wrong 
frame page.  Most links will be fine though.

Example: openLink("www.blizzard.com");   (opens blizzard's home page)

Included Functions:
    openLink
    changeIframe
	reportBadLink
---------------------------------------------------*/

/*------------------openLink-------------------------
This is the function that needs to be called in the HTML.  Just enter in the 
URL and the function will take care of the rest.  openLink will open a window
and create a frame page and copy the script function reportBadLink
to that frame page.  This had to be done to make it work in netscape.  The
frames are then created.
url - URL to be linked to
---------------------------------------------------*/

function openLink(url)
{
	var HTML = "";
	var referringURL = location.href;
	var outsideURL = "none";
	var str = new String(url);
	if(str.indexOf("http:\/\/") != 0 && str.indexOf("https:\/\/") != 0 && str.indexOf("ftp:\/\/") != 0) outsideURL = "http:\/\/" + url;
	else outsideURL = url;
	var width = 800;
	var height = 600;
	var topedge = (screen.height - height)/2 - 20;
	var leftedge = (screen.width - width)/2;
	newwin = window.open("","","width="+width+", height="+height+", toolbar=yes, scrollbars=yes, resizable=yes, screenX=" + leftedge + ", screenY=" + topedge + ", left=" + leftedge + ", top=" + topedge);
	newwin.focus();
	//newwin.onresize=changeIframe;
	
	if(navigator.userAgent.indexOf("Safari") != -1)
	{
		HTML += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Outside Link</title>\n'
		HTML += '<script language="JavaScript">' + reportBadLink + '\n' + changeIframe + '</script>\n';
		HTML += '<style type="text/css">\n';
		HTML += '.style1{ font-weight: bold; text-decoration: none; color: #000000; font-size: 10pt;}\n';
		HTML += '.style1:hover{ text-decoration: none; color: #3729e7; font-size: 10pt; font-family: ariel;}\n';
		HTML += '.disclaimer{ text-decoration: none; color: #350697; font-size: 12pt;}\n';
		HTML += '.background {background-image: url("http://ce.byu.edu/is/cid/html/Warning02.jpg"); background-repeat: no-repeat;background-position: top center;}\n';
		HTML += '</style> ';
		HTML += '</head>\n ';
		HTML += '<body bgcolor="#ffffff" class="background"><br/>\n';
		HTML += '<table align="center" cellspacing="0" cellpadding="0" border="0"> \n';
		HTML += '<tr><td COLSPAN="2" align="center" height="25" width="300"></td>\n';
		HTML += '</tr><tr><td><a class="style1" href="#" onclick="top.window.close();"><font \n';
		HTML += 'size="-2">RETURN TO COURSE</font></A></TD> \n';
		HTML += '<td align="right"><a href="#" class="style1" \n';
		HTML += 'onclick="opener.reportBadLink(\'' + outsideURL + '\',\'' + referringURL + '\',\'RSNumber\');return false;"><font size="-2">REPORT BAD \n';
		HTML += 'LINK</font></a></td> \n';
		HTML += '</tr>\n';
		HTML += '</table>\n';
		HTML += '<center><iframe id="link" height="450" width="785" border="0" vspace="0" hspace="0"></iframe></center></body></html>\n';
	}
	/*All non-Safari browsers*/
	else
	{
		HTML += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Outside Link</title>';
		HTML += '<script language="JavaScript">' + reportBadLink + '</script>';
		HTML += '</head>\n ';
		HTML += '<frameset ROWS="75,*" frameborder="0" framespacing="0" border="0">\n';
		HTML += '<frame src="about:blank" id="nav" name="nav" marginwidth="0" marginheight="0" \n';
		HTML += 'scrolling="auto">\n';
		HTML += '<frame src="about:blank" id="link" name="link" marginwidth="0" marginheight="0" \n';
		HTML += 'scrolling="auto">\n';
		HTML += ' </frameset> \n';
		HTML += '</html>\n';
	}

	newwin.document.writeln(HTML);

	var body = "";
	if(navigator.userAgent.indexOf("Safari") == -1) /*All non-Safari browsers*/
	{
		newwin.window.nav.document.open();
		body += '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>';
		body += '<title>top</title>';
		body += '<style tyoe="text/css">';
		body += '.style1{ font-weight: bold; text-decoration: none; color: #000000; font-size: 10pt;}';
		body += '.style1:hover{ text-decoration: none; color: #3729e7; font-size: 10pt; font-family: ariel;}';
		body += '.disclaimer{ text-decoration: none; color: #350697; font-size: 12pt;}';
		body += '.background {background-image: url("http://ce.byu.edu/is/cid/html/Warning02.jpg"); background-repeat: no-repeat;background-position: center;}';
		body += '</style> ';
		body += '</head> ';
		body += '<body bgcolor="#ffffff" class="background"> <BR> ';
		body += '<table align="center" cellspacing="0" cellpadding="0" border="0"> ';
		body += '<tr><td colspan="2" align="center" height="25" width="300"></td>';
		body += '</tr><tr><td><a class="style1" href="#" onclick="top.window.close();"><font ';
		body += 'size="-2">RETURN TO COURSE</font></a></td> ';
		body += '<td align="right"><a href="#" class="style1" ';
		body += 'onclick="top.reportBadLink(\'' + outsideURL + '\',\'' + referringURL + '\',\'' + top.RS6000 + '\');return false;"><font size="-2">REPORT BAD ';
		body += 'LINK</font></a></td> ';
		body += '</tr>';
		body += '</table>';
		body += '</body></html>';
		newwin.nav.document.writeln(body);
		newwin.nav.document.close();
	}
	newwin.document.getElementById("link").src = outsideURL;
	if(navigator.userAgent.indexOf("Safari") != -1) 
	{
		newwin.onresize = changeIframe;
		newwin.onload = changeIframe;
	}
	
		
}
//------------------End openLink---------------------  




/*------------------changeIframe---------------------
Used by Safari on macs for when the window changes size.  Safari uses an
iframe to load the outside link in, and it has to change size when the
window changes size.  This function is set as the onresize function.
---------------------------------------------------*/
function changeIframe()
{
	var element = newwin.document.getElementById("link");
	element.style.height = newwin.innerHeight-75;
	element.style.width = newwin.innerWidth-15;
}   
//------------------End changeIframe-----------------        




/*------------------reportBadLink--------------------
In the case the user clicks on "Report Bad Link" in the disclaimer, this function
is called.  It prints out on a new new window the form needed
to report a bad link. This function should never be called in HTML not 
created by the disclaimer page.
outsideURL   - The URL being reported
referringURL - The URL of the page that the link is on
RS6000       - the RS6000 number of the course
---------------------------------------------------*/
function reportBadLink(outsideURL,referringURL,RS6000)
{
  var url=outsideURL;
  var page_location=referringURL;
  var page_name=page_location.substring(page_location.lastIndexOf("/")+1,page_location.lastIndexOf("."));
  var locationlist = referringURL.split("/");
  var rsnumber = locationlist[5];
  var win1 = window.open("","","width=800,height=600,resizable,toolbar");
  win1.document.writeln('<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><title>Report bad URLs</title>');
  win1.document.writeln('<link href="http://ce.byu.edu/is/cid/course.css" rel="stylesheet"');
  win1.document.writeln('type="text/css"></head>');
  win1.document.writeln('<body bgcolor="FFFFFF" onload="document.FeedbackForm.Name.focus();">');
  win1.document.writeln('<center><p><img src="http://ce.byu.edu/is/cid/imgs/comments.gif"');
  win1.document.writeln('alt="Comments and Questions"></P>');
  win1.document.writeln('<p align="center">Use this form to send comments or complaints');
  win1.document.writeln('about links in this course to BYU. Ideas on how we can make improvements ');
  win1.document.writeln('are always welcome. If you are reporting inappropriate information ');
  win1.document.writeln('contained on any linked web page or that the linked web page is inactive, ');
  win1.document.writeln('please note the nature of the problem in the area below marked ');
  win1.document.writeln('"Description of problem". Comments made on this form are recieved directly ');
  win1.document.writeln("by Independent Study's tech support team.</P>");
  win1.document.writeln('<form action="http://ce.byu.edu/cgi-bin/generic.scr" method="post"');
  win1.document.writeln(' NAME="FeedbackForm">');
  win1.document.writeln('<input type="hidden" name="scriptname" value="mailback">');
  win1.document.writeln('<input type="hidden" name="respurl" value="is/common/comments.htm">');
  win1.document.writeln('<input type="hidden" name="required" value="SSN,Barcode">');
  win1.document.writeln('<input type="hidden" name="whoto" value="corrections@byu.edu">');
  win1.document.writeln('<input type="hidden" name="subject" value="Link Comments">');
  win1.document.writeln('<input type="hidden" name="Browser">');
  win1.document.writeln('<input type="hidden" name="noprint" value="whoto,scriptname,respurl,required,subject,noprint">');
  win1.document.writeln('<input type="hidden" name="course" value="'+rsnumber+'">');
  win1.document.writeln('<input type="hidden" name="Location" size="41" value="'+page_name+'">');
  win1.document.writeln('<input type="hidden" name="link" value="'+url+'">');
  win1.document.writeln('</center>');
  win1.document.writeln('<center><table align="center" cellpadding="3" cellspacing="3" bgcolor="#dddddd" width="500">');
  win1.document.writeln('<tr><td width="200"><b>Course number: </b></td><td>'+rsnumber+'</td></tr>');
  win1.document.writeln('<tr><td><b>Page number: </b></td><td>'+page_name+'</td></tr>');
  win1.document.writeln('<tr><td><b>Link location: </b></td><td>'+url+'</td></tr>');
  win1.document.writeln('<tr><td><b>Full name:</b></td><td><INPUT NAME="Name" SIZE="25"></td></tr>');
  win1.document.writeln('<tr><td><b>E-mail address:</b></td>');
  win1.document.writeln('<td><input name="E-mail" size="25"></td></tr>');
  win1.document.writeln('<tr><td colspan="2" align="center">');
  win1.document.writeln('<font size="-1">Description of problem:</font><br/>');
  win1.document.writeln('<textarea name="comments" rows="4" cols="51" wrap="hard"></textarea>');
  win1.document.writeln('<center><input type="submit" value="Send Message"');
  win1.document.writeln('onclick="document.forms[0].Browser.value=navigator.appName+navigator.appVersion">');
  win1.document.writeln('</center></td></tr></table></form></center></body></html>');
}
//------------------End reportBadLink----------------

