//*************************************************************************
// Include this javascript file on every page, including the syllabus page.
// All the bookmarking/cookie functions are here.
//*************************************************************************
var thisCookieName = "hist";
var thisDelimiter = "#cf#";
var expDays = 100;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

var num = parseFloat(navigator.appVersion);
		
if (navigator.appName == "Netscape" && num >= 3){
	var browserVer = 1   //test for browserVer == 1 in all dependent functions						
} 
else {
	if (navigator.appName == "Microsoft Internet Explorer" && num >= 4){
		var browserVer = 1   //test for browserVer == 1 in all dependent functions
	} 
	else {
		var browserVer = 2
	}
}
//*************************************************************************
// These are the syllabus functions
//*************************************************************************
function setChecks(){
	cookieValue = getCookie(thisCookieName);
	if (cookieValue != null && browserVer == 1){
		var bON=new Image();
		bON.src="images/bulletON.gif";
		
		cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
		bookmarkArray = cookieValue.split(thisDelimiter);
		for (i=0; i < bookmarkArray.length; i++) {
	    	document[bookmarkArray[i]].src = eval("bON.src");
		}
	}
}

function go(url){
	opener.location.href=url;
	self.close();
}

function startOver(){
	cookieValue = "";
	setCookie(thisCookieName, cookieValue, exp);
	makeSyllabus();
}

//*************************************************************************
// These are the shared functions
//*************************************************************************
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;  
	thisValue = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
	document.cookie = thisValue;
}

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;
}

//*************************************************************************
// These are the lesson-page functions
//*************************************************************************
function addPageMark(pageID){
	cookieValue = getCookie(thisCookieName);
	isMarked = false;
	if (cookieValue == null){
		cookieValue = "";
	}
	else{
		cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
		bookmarkArray = cookieValue.split(thisDelimiter);
		var isMarked = false;
		for (i=0; i < bookmarkArray.length; i++) {
			if (bookmarkArray[i] == pageID){
				isMarked = true;
				break;
			}
		}
		cookieValue = cookieValue + thisDelimiter; // Add back last delimiter
	}
	if (!isMarked){
		cookieValue = cookieValue + pageID + thisDelimiter;
		//alert("cv "+cookieValue);
		setCookie(thisCookieName, cookieValue, exp);
	}
}

function makeSyllabus(){
	syllabus=window.open("","syllabuswin","width=600,height=500,scrollbars=yes,resize=yes,menubar=yes");
	syllabus.location.href="syllabus.html";
	if(syllabus.opener==null){
		syllabus.opener=window;
	}
	syllabus.opener.name = "opener";
}

//******************************************************
