// drtube.js
// Global javaScript routines for the Dr.Tube site.

// W3CDOM (level 1 DOM) indicator.
var W3CDOM = (document.createElement && document.getElementsByTagName);

// Add initMO to the Window.onload chain.
AddOnLoad(window, InitMO);


//*********************************************************
// Image Mouseover Javascript.
//*********************************************************
function InitMO() {
	// This only works in "modern" level 1 DOMs...
	if (!W3CDOM) 
		return;

	// Only handle the IMG's in the 'nav' div.
	var div = document.getElementById('nav');
	var imgs = div.getElementsByTagName('img');

	// Check all the img's...
	for (var i=0; i<imgs.length; i++) {
		// If the name of the image ends with a '1', then 
		// replace that '1' with a '2' for the mouseover image.
		var dot = imgs[i].src.lastIndexOf('.');
		if (dot>0) {
			var name = imgs[i].src.substring(0, dot);
			var ext  = imgs[i].src.substring(dot, imgs[i].src.length);
			if (name.charAt(name.length-1) == '1') {
				imgs[i].mosrc = new Image();
				imgs[i].mosrc = name.substring(0, name.length-1) + '2' + ext;
				imgs[i].onmouseover = SwitchSrc;
				imgs[i].onmouseout  = SwitchSrc;
			}
		}
	}
}


//*********************************************************
// SwitchSrc switches the two SRC's in an IMG element.
//*********************************************************
function SwitchSrc() {
	var tempsrc = this.src;
	this.src = this.mosrc;
	this.mosrc = tempsrc;
}


//*********************************************************
// AddOnLoad
// To add an init function to the onload chain.
// Target = window, etc.
//*********************************************************
function AddOnLoad (target, onload_fn) {
	if (target.addEventListener) // W3CDOM / DOM-1
		target.addEventListener("load", onload_fn, false)
	else 
		if (target.attachEvent) // MS IE5+/Win only
			target.attachEvent("onload", onload_fn)
		else 
			if (document.getElementById) { // We're down to Jurassic browsers here...
				var PrevOnLoad = target.onload; // DOM-0 ?
				if ((PrevOnLoad != NULL) && (typeof PrevOnLoad == 'function'))
					target.onload = function() { PrevOnLoad(); onload_fn; }
				else
					target.onload = onload_fn;
			}
}


//*********************************************************
// OpenPDF
//*********************************************************
function OpenPDF(FileName, Title) {
	var Str = "";
	var aW = 800, aH = 600;

	if (window.screen) {
		aW = screen.availWidth;
		aH = screen.availHeight;
	}

	Str = "scrollbars=no,status=no,menubar=no,width="+(aW-10)+",height="+(aH-30)+"outerwidth="+aW+",outerheight="+aH;
	Str+= ",left=0,top=0,screenX=0,screenY=0";

	myWin = window.open(FileName,'_blank',Str);
	if (myWin) {
		myWin.document.title=Title; // Werkt niet...
		myWin.document.close;
	}
	return myWin;
}


//*********************************************************
// OpenIMGXY
//*********************************************************
function OpenImgXY(FileName, W, H, Title) {
	var myWin = null;
	var Str = "", Max = false;
	var X = 0, Y = 0, oW = 0, oH = 0;
	var aW = 0, aH = 0, xc = 0, yc = 0;

	if (window.screen) { // centre it on the screen...
		aW=screen.availWidth;
		aH=screen.availHeight;
		xc = (aW-W)/2;
		yc = (aH-H)/2;
	}

	if (W!=null) {
		if (W>0) { 
			X = W;
		}
		if (W>(aW-10) || W<0) {
			Max = true;
			oW = aW;
			W  =aW-10;
			xc = 0;
		} 
	}

	if (H!=null) {
		if (H>0) { 
			Y = H;
		}
		if (H>(aH-30) || H<0) {
			Max = true;
			oH = aH; H = aH-30;
			yc = 0;
		}
	}

	if (Max) {
		Str = "scrollbars=yes,resizable=yes,width="+W+",height="+H+",outerWidth="+oW+",outerHeight="+oH;
	} else {
		Str = "scrollbars=no,resizable=yes,status=no,menubar=no,width="+W+",height="+H+",innerWidth="+W+",innerHeight="+H;
	}
	Str +=",left="+xc+",top="+yc+",screenX="+xc+",screenY="+yc;

	myWin = window.open("",'_blank',Str);
	if (myWin) {
		myWin.document.writeln("<HTML><HEAD><TITLE>"+Title+"</TITLE></HEAD>");
		myWin.document.writeln("<BODY BGColor=#FFFFFF LeftMargin=0 TopMargin=0 MarginWidth=0 MarginHeight=0>");
		myWin.document.write("<IMG SRC="+FileName);
		if (X!=0) { myWin.document.write(" Width="+X); }
		if (Y!=0) { myWin.document.write(" Height="+Y); }
		myWin.document.writeln(">");
		myWin.document.writeln("</BODY></HTML>");
		myWin.document.close();
	}
	return myWin;
}


//*********************************************************
// OpenWin
//*********************************************************
function OpenWin(FileName) {
	return(window.open(FileName,'_blank','scrollbars=yes,resizable=yes,status=no,menubar=no'));
}