//include file that will contain and manage all cookie information retrieving
//created 20/01/04

//Cookies:
//CurrentUser is a temporary cookie, stores the userid and page variables.
//User[userid] is persistent, and stores all the parameters for a specific user

CookieDebug = 0;


function browserCheck() {
	this.ns4 = (document.layers)? true:false;
	this.ie = (document.all&&(!window.opera))? true:false;
	this.dom = (document.getElementById)? true:false;
//this.sidebar causes an error in netscape 6
	//this.ns6 = (window.sidebar)? true:false;
	this.ns6 = (navigator.userAgent.indexOf("Netscape6"))?1:0
	if(!this.ns6){
		this.moz = (window.sidebar||navigator.userAgent.indexOf('Gecko')!=-1)? true:false;
	}else{
		this.moz = 0;
	}

	this.opera = (window.opera)? true:false;
	this.mac = (navigator.userAgent.indexOf('Mac')!=-1)? true:false;
}

is = new browserCheck();
var Obj;

function getObjectName(nameOfObject){
	Obj = null;
	if (is.ie) Obj = document.all[nameOfObject]
	else if (is.dom) Obj = findDOMObject(nameOfObject)
	else if (is.ns4) findLayer(window,nameOfObject);
	if (!Obj || ( is.ns4 && Obj == window ) ) Obj = "Object not found";
	return Obj;
}

function findDOMObject(nameOfObject) {
	for (var i = 0; i < document.images.length; i++) {
		if (document.images[i].name==nameOfObject) return document.images[i];
	}
	return document.getElementById(nameOfObject);
}

function findLayer(node,nameOfObject) {
	if ( node.name == nameOfObject ) Obj = node;
	for ( var counter = 0; counter < node.document.images.length; counter++ ) {
		if (node.document.images[counter].name==nameOfObject) Obj = node.document.images[counter];
	}
	for ( var i = 0; i < node.document.layers.length; i++ ) {
		findLayer(node.document.layers[i],nameOfObject);
	}
}


function replace(string,text,by) {
	if (CookieDebug>3) alert("replace("+string+", "+text+" ,"+by+")");
	if (typeof(string) != "string") {
		string = toString(string);
	}
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;
	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;
	var newstr = string.substring(0,i) + by;
	if (i+txtLength < strLength)
	newstr += replace(string.substring(i+txtLength,strLength),text,by);
	return newstr;
}

function loadCookie(NameOfCookie) {
	if (CookieDebug>1) alert("loadCookie("+NameOfCookie+")");
	if (document.cookie.length > 0) {
		if (CookieDebug>1) alert(document.cookie);
		begin = document.cookie.indexOf(objNav.courseId+NameOfCookie+"=");
		if (begin != -1) {
			begin += (objNav.courseId+NameOfCookie).length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
//			return document.cookie.substring(begin, end);
		}
		if (CookieDebug>1) alert(NameOfCookie+ " NOT found...");
	}
	return null;
}

function saveCookie(NameOfCookie, value, expiredays,callerID) {
	if (CookieDebug>1) alert("saveCookie("+NameOfCookie+", "+value+", "+expiredays+") called by "+callerID);
	if (expiredays == null) {
		expiry = "";
	} else {
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		expiry = "; path=/;expires=" + ExpireDate.toUTCString();
	}
	document.cookie = objNav.courseId+NameOfCookie + "=" + replace(replace(replace(escape(value), "%3D", "="), "%27", "'"), "%7C", "|") + expiry;
//	document.cookie = NameOfCookie + "=" + value + expiry;
}


function windowOpen(xgoto) {
	var junk = '';
	junk = window.open(xgoto, 'printwindow', '');
}



function clkBut() {
	; // Do Nothing - Dummy Function for IE4.0 & IE5.0 button fix. S Thorne 16/02/04
}

