
function BrowserCheck() {
	var b = navigator.appName
	this.mac = (navigator.appVersion.indexOf('Mac') != -1)
	if (b=="Netscape") this.b = 'ns'
	else if (b=="Microsoft Internet Explorer") this.b = 'ie'
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=5)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && this.v==5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	if (this.mac) this.ie = this.ie5
	this.ie5mac = (this.ie5 && this.mac);
	this.min = (this.ns||this.ie)
}

is = new BrowserCheck();


if ((is.min == false)||(is.ie5mac)){
	alert('Your browser can\'t handle this page. On the Mac, you will need Netscape 6, and on Windows Internet Explorer 5 or Netscape 6, in order to see all the features of the text.');
}

function Card(ID){
	this.elm=document.getElementById(ID);
	this.name=ID;
	this.css=this.elm.style;
	this.elm.style.left = 0 +'px';
	this.elm.style.top = 0 +'px';
	this.HomeL = 0;
	this.HomeT = 0;
	this.tag=-1;
	this.index=-1;
}

function CardGetL(){return parseInt(this.css.left)}
Card.prototype.GetL=CardGetL;

function CardGetT(){return parseInt(this.css.top)}
Card.prototype.GetT=CardGetT;

function CardGetW(){return parseInt(this.elm.offsetWidth)}
Card.prototype.GetW=CardGetW;

function CardGetH(){return parseInt(this.elm.offsetHeight)}
Card.prototype.GetH=CardGetH;

function CardGetB(){return this.GetT()+this.GetH()}
Card.prototype.GetB=CardGetB;

function CardGetR(){return this.GetL()+this.GetW()}
Card.prototype.GetR=CardGetR;

function CardSetL(NewL){this.css.left = NewL+'px'}
Card.prototype.SetL=CardSetL;

function CardSetT(NewT){this.css.top = NewT+'px'}
Card.prototype.SetT=CardSetT;

function CardSetW(NewW){this.css.width = NewW+'px'}
Card.prototype.SetW=CardSetW;

function CardSetH(NewH){this.css.height = NewH+'px'}
Card.prototype.SetH=CardSetH;

function CardInside(X,Y){
	var Result=false;
	if(X>=this.GetL()){if(X<=this.GetR()){if(Y>=this.GetT()){if(Y<=this.GetB()){Result=true;}}}}
	return Result;
}
Card.prototype.Inside=CardInside;

function CardSwapColours(){
	var c=this.css.backgroundColor;
	this.css.backgroundColor=this.css.color;
	this.css.color=c;
}
Card.prototype.SwapColours=CardSwapColours;

function CardOverlap(OtherCard){
	var smR=(this.GetR()<OtherCard.GetR())? this.GetR(): OtherCard.GetR();
	var lgL=(this.GetL()>OtherCard.GetL())? this.GetL(): OtherCard.GetL();
	var HDim=smR-lgL;
	if (HDim<1){return 0;}
	var smB=(this.GetB()<OtherCard.GetB())? this.GetB(): OtherCard.GetB();
	var lgT=(this.GetT()>OtherCard.GetT())? this.GetT(): OtherCard.GetT();
	var VDim=smB-lgT;
	if (VDim<1){return 0;}
	return (HDim*VDim);	
}
Card.prototype.Overlap=CardOverlap;

function CardDockToR(OtherCard){
	this.SetL(OtherCard.GetR() + 5);
	this.SetT(OtherCard.GetT());
}

Card.prototype.DockToR=CardDockToR;

function CardSetHome(){
	this.HomeL=this.GetL();
	this.HomeT=this.GetT();
}
Card.prototype.SetHome=CardSetHome;

function CardGoHome(){
	this.SetL(this.HomeL);
	this.SetT(this.HomeT);
}

Card.prototype.GoHome=CardGoHome;

function GetVScrollPos(){
	if (is.ie){
		return document.body.scrollTop;
	}
	else {
		return window.pageYOffset;
	}
}

function Highlight(Tag, Colour){
/*
	FullTag = Tag;
	if (is.ns){FullTag = 'MDHCustom:' + Tag;}
	var NList = document.getElementsByTagName(FullTag);
	for (var i=0; i<NList.length; i++){
		var NewColour = '#FFFFFF';
		if (document.getElementById('Show' + Tag).checked == true){
			NewColour = Colour;
		}
		NList[i].style.backgroundColor = NewColour;
		var Kids = NList[i].getElementsByTagName('*');
		for (var j=0; j<Kids.length; j++){
			Kids[j].style.backgroundColor = NewColour;
		}
	}
*/
}

var Popup = null;

function PageDim(){
//Get the page width and height
	this.W = 600;
	this.H = 400;
	if (is.ns) this.W = window.innerWidth;
	if (is.ie) this.W = document.body.clientWidth;
	if (is.ns) this.H = window.innerHeight;
	if (is.ie) this.H = document.body.clientHeight;
}

var pg = null;
var DisplayTop = 200;

function StartUp(){
	pg = new PageDim();
	parent.HalfPage = Math.floor(pg.H/2) * -1;
	PopWidth = Math.floor(pg.W/3);
//	PopWidth = 5;
	Popup = new Card('PopDiv');
	Popup.SetW(PopWidth);
	HidePopup();
	if (is.ns){document.getElementById('RightDiv').style.zIndex = 0;}
//	DisplayTop = parseInt(document.getElementById('PointBelowTitle').style.top);
//alert(DisplayTop);
}

function ShowPopup(e,Data){
	Popup.css.display = 'none';
	Popup.elm.innerHTML = '';
	Popup.elm.innerHTML = Data;
//	Popup.elm.zIndex = 0;
	Popup.css.display = 'block';
	Popup.SetT(e.clientY - (Popup.GetH()+15 - GetVScrollPos()));
	if (Popup.GetT() < 0){Popup.SetT(2);}
	Popup.SetL(e.clientX - (Popup.GetW()-5));
	if (Popup.GetL() < 0){Popup.SetL(5);}
//alert('zIndex of RightDiv is ' + document.getElementById('RightDiv').zIndex + '; zIndex of Popup is ' + Popup.elm.zIndex + '.');
	return false;
}

function HidePopup(){
	Popup.SetT(0);
	Popup.SetL(0);
	Popup.css.display = 'none';
}

function HideRightDiv(){
	document.getElementById('RightDiv').style.display = 'none';
}

function ShowLinkPopup(e,LinkId){
	var El = document.getElementById(LinkId);
	var Stuff;
	if (El != null){
		Stuff = El.innerHTML;
		ShowPopup(e,Stuff);
	}
}

function TimerStartUp(){
	setTimeout('StartUp()', 100);
}

function Delimit(Bit){
	Bit.style.borderColor = '#ff0000';
}

function Undelimit(Bit){
	Bit.style.borderColor = '#ffffff';
}

function ShowEntry(EntryId){
	var ThisEntry = document.getElementById(EntryId);
	if (ThisEntry  != null){
		if (ThisEntry.style.display == 'block'){
			ThisEntry .style.display = 'none';
		}
		else{
			ThisEntry.style.display = 'block';
//			ThisEntry.zIndex = -1;
		}
	}
}

function ShowEnclosure(e, EnclosureId){
	var El = document.getElementById(EnclosureId);
	if (El != null){
		var RD = document.getElementById('RightDiv');
		RD.innerHTML = El.innerHTML;
		VPos = GetVScrollPos();
		RD.style.display = 'block';
		var EncHeight = parseInt(RD.offsetHeight);
		RD.style.top = (e.clientY + VPos) + 'px';
//alert(EncHeight + ' ' + VPos + ' ' + RD.style.top);
		if ((e.clientY + EncHeight) > pg.H){

			RD.style.top = VPos + pg.H - EncHeight + 'px';
			if (parseInt(RD.style.top) < VPos){
				if (VPos < DisplayTop){
					RD.style.top = DisplayTop + 'px';
				}
				else{
					RD.style.top = VPos + 'px';
				}
			}
		}
//alert(EncHeight + ' ' + VPos + ' ' + RD.style.top);
//		RD.zIndex = -1;
	}
//alert('zIndex of RightDiv is ' + document.getElementById('RightDiv').zIndex + '; zIndex of Popup is ' + Popup.elm.zIndex + '.');
}

