//
// general functions
//


// setup cookie functions

function getCookieVal(offset)
// internal call for GetCookie

// Julie Russell version 1.0
{ 
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name)
// this retrieves the setting of a cookie
// as a min it needs name, and will return 
// the setting (as set using SetCookie)

// Julie Russell version 1.0
{
	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)
// this allows the setting of a cookie
// as a min it needs name, and value arguments

// if a third argument is used this is:
// *** expires ** (cookie will be valid for ?? after being set)
// valid values are min, hour, day, week, 
// month, trimonth or a value in ms
// if missing or null, cookie expires at the
// end of the current session

// if a forth argument is used this is:
// *** path ** 
// valid value is a string indicating the 
// path for which the cookie is valid, if 
// missing or null it is the path of the 
// calling document.

// if a fifth argument is used this is:
// *** domain ** 
// valid value is a string indicating the 
// domain for which the cookie is valid, if 
// missing or null it is the domain of the 
// calling document.

// if a sixth argument is used this is:
// *** secure ** 
// valid value is a boolean true/false indicating
// if the cookie requires a secure channel (HTTPS)
// for transmission.

// Julie Russell version 1.0
{
	var argv = SetCookie.arguments;
	var argl = SetCookie.arguments.length;
	var expires = (argl > 2)? argv[2]:null;
	var path = (argl > 3)? argv[3]:null;
	var domain = (argl > 4)? argv[4]:null;
	var secure = (argl > 5)? argv[5]:false;
	var expdate = new Date();
	if (expires != null)
	{
		if (expires == "trimonth") expires = (1000 * 60 * 60 * 24 * 30 * 3);
		if (expires == "month") expires = (1000 * 60 * 60 * 24 * 30);
		if (expires == "week")  expires = (1000 * 60 * 60 * 24 * 7);
		if (expires == "day")   expires = (1000 * 60 * 60 * 24);
		if (expires == "hour")  expires = (1000 * 60 * 60);
		if (expires == "min")   expires = (1000 * 60);
	};
	expdate.setTime(expdate.getTime()+ (expires)); 
	document.cookie = name + "=" + escape(value)+ 
	((expires == null)? "" : ("; expires=" + expdate.toGMTString()))+
	((path == null)? "" : ("; path=" + path))+
	((domain == null)? "" : ("; domain=" + domain))+
	((secure == true)? "; secure" : "" );
}

function DeleteCookie(name)
// this deletes a cookie (just sets the date 
// to before current date)
// it needs the name of the cookie

// Julie Russell version 1.0
{
	var exp = new Date();
	exp.setTime (exp.setTime()-1); 
	// cookie valid until 1ms before current time!
	var cval = GetCookie(name);
	document.cookie = name + "=" + cval + 
	"; expires=" + exp.toGMTString();
}

// end of setup cookie functions





function updateDisp(LinkID, hist, Disp, ListID, SetTheCookie)
// this enables/disables a display list
// creates a cookie / reads a cookie for history
// and displays the link as visited/not visited
//
// LinkID =  ID of link (known as ID=??? in the HTML)
// hist = name used to ref the cookie
// Disp = display/do not disp = 1/0
// ListID = ID of list (known as ID=??? in the HTML)
// SetTheCookie = set cookie
//

{
	if (SetTheCookie) {SetCookie(hist,"1","min");}
	if (!SetTheCookie)Disp=0;
	var look;
	ListID.style.display = (Disp)? "":"none";
	look=GetCookie(hist);
	LinkID.style.color= (Disp)? "#FF0000":(look)? "#993399":"#6666FF";
}


//
// literals and function for DispTime
//

// To use create a form:
// <FORM><CENTER><INPUT TYPE="text" NAME="disp" 
// ALIGN="center"  VALUE="" SIZE=60
//  onFocus="this.blur()"  >
// then call DispTime()
// or periodicly every sec (1000ms) :
//  var oInterval=window.setInterval("DispTime()",1000);
// close form
// </SCRIPT></INPUT></CENTER></FORM >

dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
monName = new Array ("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December")

function DispTime()
{
	now = new Date;
	var dayth = "th";
	if(now.getDate()== (1||21||31)) dayth= "st";
	if(now.getDate()== (2||22)) dayth= "nd";
	if(now.getDate()== (3||23)) dayth= "rd";
	var mins = (now.getMinutes()<10)? ("0"+now.getMinutes()):now.getMinutes();
	var textstr=(" Today is " + dayName[now.getDay()] + ", " + monName[now.getMonth()] + " " + now.getDate() + dayth+" at "+ now.getHours()+":"+ mins + " mins, "+now.getSeconds()+ " seconds"+ ".");
	document.forms[0].elements[0].value = textstr;
}

//
// "New" display functions
//

//
// these functions display a new.gif graphic if the Newcheck is newer than 
// the last time the page was visited, or the cookie has expired.
// they must be set as follows:
// IN:
//  <SCRIPT ID=clientEventHandlersJS   LANGUAGE=javascript TYPE="TEXT/JAVASCRIPT" ><!--
//	lastVisit = new Date;
//	setLastVisited("the cookiename","trimonth");
//	--></SCRIPT>
//
// & then use:
//	<SCRIPT  ID=clientEventHandlersJS   LANGUAGE=javascript>NewCheck(14,7,2003,lastVisit);</SCRIPT>
//  
// with the date set as required, wherever the "new" is needed.
//

//
// setLastVisited takes a name (Pagevisit), and a time (Period)
// and using lastVisit, which is the name of a global date object 
// (set via: lastVisit = new Date, which must be global on the page);
// it sets lastVisit to the date in UT when the page was last visited
// and sets the cookie (via the name Pagevisit) to the date in UT that
// the function was called.
// The cookie is set for the time period, set via Period
// this may be "sec", "hour", "day", "week", "month", or "trimonth"
//
function setLastVisited(Pagevisit,Period){
	lastVisit=GetCookie(Pagevisit);
	if(lastVisit){if(lastVisit.indexOf(':') != -1){lastVisit="0";}}
	var thisVisit = new Date();
	SetCookie(Pagevisit,thisVisit.getTime(),Period);}

//
// NewCheck takes a date (dd mm yyyy) and checks the last time the page was visited 
// (from lastVisit), if the date is newer, then the graphic new.gif is placed
// in the document.
// 	
function NewCheck(dd,mm,yyyy,lastVisit){
	var lastChanged= new Date(yyyy,mm-1,dd);
	//alert("changed: "+lastChanged.getTime()+ " Visit: "+lastVisit);
	if (lastChanged.getTime()> lastVisit)	
		{document.write("<IMG SRC='../images/new.gif' WIDTH='28' HEIGHT='11' ALT='new'>");}}
//
// home sets the top level to reload the Voyager main site
//
function home(){top.location.replace("index.htm?Intro.htm")}

//
// HomeMO takes the object (use as HomeMO(this);)
// changes the curser to the hand and sets the window status
// 
function HomeMO(object){object.style.cursor = "hand"; window.status = "Reload Voyager home page"}

//
// HomeML takes the object (use as HomeML(this);)
// Resets the curser and the window status
//
function HomeML(object){object.style.cursor = "auto"; window.status = ""}




