/***************************************
** Title.........: 
** Version.......: 2.5
** Author........: Mattias Bodlund <mattias@oncotype.dk>
** Filename......: js_main.js
** Last changed..: 26/03/2002
***************************************/

var W3C=DOM=!!document.getElementById;
var NS6=(navigator.userAgent.indexOf("Gecko")!=-1);
var IE4=!!(document.all && !W3C);
var NS4=!!document.layers;
var Mac=(navigator.appVersion.indexOf("Mac")!=-1);
var IEMac = (W3C && Mac && document.all);

var loadDone = false;
var menuIndex = 1;
var x_active = false;
var drag_e = false;

var navdata = new Cookie(document,"xVal_yVal");

if (NS4) {
	var visible = "show";
	var hidden = "hide";
	var savedInnerWidth = innerWidth; 
	var savedInnerHeight = innerHeight;
	onResize = NS4_resize;
} else {
	var visible = "visible";
	var hidden = "hidden";
}

function NS4_resize() { 
	if ((savedInnerWidth != innerWidth) || (savedInnerHeight !=innerHeight)) {
		f_StoreNaviPos();
		location.reload();
	}
}

function f_GetElement(obid){
	return W3C?document.getElementById((obid)):
		IE4?document.all[(obid)]:
		NS4?document[(obid)]:false;
}

function f_GetElementStyle(obid) {
	return W3C?document.getElementById((obid)).style:
		IE4?document.all[(obid)].style:
		NS4?document.layers[obid]:false;
}

/********************************************************************/
/********************************************************************/

function init(the_index) {
	
	menuIndex = the_index;
	f_cacheImg('pics/navi/menuminus.gif','pics/navi/menuplus.gif');	
	
	dragObj = f_GetElementStyle("dNav");
	var dragElement = f_GetElement("dNav");
	
	divNavB = f_GetElementStyle("dNavB");
	divNavM = f_GetElementStyle("dNavM");

	if (!f_addEvent(dragElement, "mousedown", f_MouseDown, true)) {
		if (IE4 || IEMac || NS4) {
			dragElement.onmousedown = f_MouseDown;
			document.onmousemove = f_MouseMove;
			document.onmouseup = f_MouseUp;
			if (NS4) {
				dragElement.captureEvents(Event.MOUSEDOWN);
				document.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
			}
		}
	}
	loadDone = true;
}

/********************************************************************/
/********************************************************************/

function f_MouseDown(e) {
	if (loadDone && (((IE4||IEMac) || f_MouseButton(e) == 1) && !x_active)) {
		if ((IE4||IEMac) && event) e=event;	
		deltaX = f_MouseX(e) - parseInt(dragObj.left);
		deltaY = f_MouseY(e) - parseInt(dragObj.top);
		drag_e = true;	
		f_addEvent(document, "mousemove", f_MouseMove, true);
		f_addEvent(document, "mouseup", f_MouseUp, true);	
		if (NS4) return false; // routeEvent
	}
}

/********************************************************************/

function f_MouseMove(e) {
	if ((IE4||IEMac) && event) e=event;
	if (drag_e) {
		f_MoveNavi((f_MouseX(e) - deltaX),(f_MouseY(e) - deltaY));
		return false;
	} else {
		return true;
	}
}

/********************************************************************/

function f_MoveNavi(toX,toY) {
	divNavM.left = divNavB.left = dragObj.left = dragObj.left = NS4?toX:toX+"px";
	divNavB.top = dragObj.top = dragObj.top = NS4?toY:toY+"px";
	tmpY = parseInt(dragObj.top) - (menuIndex*10);
	divNavM.top = NS4 ? tmpY : tmpY + "px";
}

/********************************************************************/

function f_MouseUp(e) {
	if (drag_e) {
		drag_e = false;
		f_removeEvent(document, "mousemove", f_MouseMove, true);
		f_removeEvent(document, "mouseup", f_MouseUp, true);
	}
}

/********************************************************************/

function f_ToggleNav() {
	if (divNavM.visibility == visible){
		f_HideElement('dNavM');
		f_SwitchImg('dNav','onoff','pics/navi/menuplus.gif');
	} else {
		f_ShowElement('dNavM');
		f_SwitchImg('dNav','onoff','pics/navi/menuminus.gif');
	}
}

function f_GetURL(url) {
	f_StoreNaviPos();
	window.location.href = url;
}

function f_MouseButton(mev) {
	return NS6?mev.which:W3C?mev.button:NS4?mev.which:false;
}

function f_MouseX(mev) {
	return (IE4||IEMac)?mev.x:(NS6||NS4)?mev.pageX:W3C?mev.clientX:false;
}

function f_MouseY(mev) {
	return (IE4||IEMac)?mev.y:(NS6||NS4)?mev.pageY:W3C?mev.clientY:false;
}

function f_addEvent(obj, evType, fn, capture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, capture)
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

function f_removeEvent(obj, evType, fn, capture) {
	if (obj.removeEventListener) {
		obj.removeEventListener(evType, fn, capture);
		return true;
	} else if (obj.detachEvent) {
		var r = obj.detachEvent("on"+evType, fn);
		return r;
	} else {
		return false;
	}
}

/********************************************************************/

function f_HideElement() {
	var args = f_HideElement.arguments;
	var n = args.length;
	for (i=0; i < n; i++) {
		var styleObj = f_GetElementStyle(args[i]);
		if (styleObj) styleObj.visibility = hidden;
	}
}

function f_ShowElement() {
	var args = f_ShowElement.arguments;
	var n = args.length;
	for (i=0; i < n; i++) {
		var styleObj = f_GetElementStyle(args[i]);
		if (styleObj) styleObj.visibility = visible;
	}
}

function f_ShowHideElement() {
	var args = f_ShowHideElement.arguments;
	var n = args.length;
	for (i=0; i < n; i++) {
		var styleObj = f_GetElementStyle(args[i]);
		if (styleObj) (styleObj.visibility == visible) ? styleObj.visibility = hidden : styleObj.visibility = visible;
	}
}

/********************************************************************/
	
function f_SwitchImg(taget_div, imgid, new_img) {
	if (W3C) document.getElementById(imgid).src = new_img;
	else if (IE4) eval("document." + imgid).src = new_img;
	else if (NS4) document.layers[taget_div].document.images[imgid].src = new_img;
	else return false;	
}

function f_cacheImg() {
	if (document.images) {
		ImageCache = new Array;
		var n = f_cacheImg.arguments.length;
		for(imageToLoad=0;imageToLoad<n;imageToLoad++) {
			ImageCache[imageToLoad] = new Image();
			ImageCache[imageToLoad].src = f_cacheImg.arguments[imageToLoad];
		}
	}	
}

/********************************************************************/

function f_StoreNaviPos() {
	if (loadDone) {
		navdata.xVal = dragObj.left;
		navdata.yVal = dragObj.top;
		navdata.store();
	}
}

/********************************************************************/

function Cookie(document, name, days, path, domain, secure) {
	this.$document = document;
	this.$name = name;
	if (days)
        this.$expiration = new Date((new Date()).getTime() + days*86400000);
	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;
}

function _Cookie_store() {
	var cookieval = "";
	for (var prop in this) {
		if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
			continue;
		if (cookieval != "") cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
    }

    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    this.$document.cookie = cookie;
}

function _Cookie_load() {
	var allcookies = this.$document.cookie;
	if (allcookies == "") return false;

	var start = allcookies.indexOf(this.$name + '=');
	if (start == -1) return false;
	start += this.$name.length + 1;
	var end = allcookies.indexOf(';', start);
	if (end == -1) end = allcookies.length;
	var cookieval = allcookies.substring(start, end);

	var a = cookieval.split('&');
	var n = a.length;
	for (var i=0; i < n; i++)
        a[i] = a[i].split(':');

    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }

    return true;
}

new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;


/********************************************************************/