<!--
// JavaScript Document


	/* *****************************************
	Created		18/03/03
	Author		Glenn Lyons
	Description	gets value of cookie by offset value
	***************************************** */
	function getCookieVal (offset) {
	    var endstr = document.cookie.indexOf (";", offset);
	    if (endstr == -1)
	    endstr = document.cookie.length;
	    return unescape(document.cookie.substring(offset, endstr));
	}

	/* *****************************************
	Created		18/03/03
	Author		Glenn Lyons
	Description	Returns the value of the cookie by "name" or null if the cookie does not exist.
	***************************************** */
	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;
	}

	/* *****************************************
	Created		18/03/03
	Author		Glenn Lyons
	Description	Function to create or update a cookie.
	***************************************** */
	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;
	  //if (path==null) { path="/"; }
		var str = name + "=" + escape (value) +
	    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	    ((path == null) ? "" : ("; path=" + path)) +
	    ((domain == null) ? "" : ("; domain=" + domain)) +
	    ((secure == true) ? "; secure" : "");
	  document.cookie = str;
	}
	/* *****************************************
	Created		18/03/03
	Author		Glenn Lyons
	Description	Function to delete a cookie. (Sets expiration date to current date/time)
	***************************************** */
	function DeleteCookie (name) {
	  var exp = new Date();
	  exp.setDate (exp.getDate() - 1);  // This cookie is history
	  var cval = GetCookie (name);
	  //if (cval != null)	
	  SetCookie( name, null, exp );
	}
	
	/* *****************************************
	Created		18/03/03
	Author		Glenn Lyons
	Description store the details of this newly-viewed course in cookies,
	 			to show up in the recently viewed right-nav box elsewhere
	***************************************** */
	function updateVisitedTablets(recentTabletIDs,newTabletID){	
		var separator = "|";
	
		// do nothing if no tablet ID
		if( !newTabletID ) return;
		
		// put newest viewed course at top of list
		var newRecentTabletIDs = newTabletID + separator; 
		
		// if previously viewed courses exist in the cookies, append these in order
		var iTabletsToStore = 5;
		var iNumTabletsStored = 1;
		if( recentTabletIDs ){
			var arrRecentTabletIDs = recentTabletIDs.split(separator);
			for( var i=0; i < arrRecentTabletIDs.length; i++ ){
				var notCurrentTablet = (arrRecentTabletIDs[i] != newTabletID);
				var moreToStore = (iNumTabletsStored < iTabletsToStore);
				if( notCurrentTablet && moreToStore ){
					newRecentTabletIDs += arrRecentTabletIDs[i] + separator;
					iNumTabletsStored++;
				}
			}
		}
		var nowDate = new Date();
		var monthFromNowDate = new Date();
		if( monthFromNowDate.getMonth() == 11 ){
			monthFromNowDate.setMonth(0);
			monthFromNowDate.setYear(nowDate.getYear() + 1);	
		}
		else{
			monthFromNowDate.setMonth(nowDate.getMonth() + 1);
		}
		SetCookie( "recentlyViewedIDs", newRecentTabletIDs.substr(0,newRecentTabletIDs.length-1), monthFromNowDate );
	}
	
// -->