// Canonical version lives at C:/Richard/js

// Copyright (C) 1999-2003 Richard Goode
// Email <richard@richardgoode.com>
// This code may not be used without permission.

browser = navigator.appName;
version = parseInt(navigator.appVersion);
n4 = (document.layers)? true:false;
mozilla = (browser=="Netscape" && version>=5)? true:false;
ie4 = (navigator.userAgent.indexOf("MSIE 4")!=-1)? true:false;
ie = (navigator.userAgent.indexOf("MSIE")!=-1)? true:false;
msdom = (ie && !ie4)? true:false;

mac = (navigator.appVersion.indexOf("Mac") != -1);
ie5 = (navigator.userAgent.indexOf("MSIE 5")!=-1)? true:false;
win98 = (navigator.userAgent.indexOf("Windows 98")!=-1 || navigator.userAgent.indexOf("Win98")!=-1)? true:false;

mod = (document.getElementById)? true:false;
msb = (document.all && !mod)? true:false;
naf = (document.layers)? true:false;

function doNothing() {return true;}
//window.onerror = doNothing;

function shiftTo(id,x,y) {
	if (mod) {
		document.getElementById(id).style.left = x + "px";
		document.getElementById(id).style.top = y + "px";
	} else if (msb) {
		document.all(id).style.left = x + "px";
		document.all(id).style.top = y + "px";
	} else if (naf) {
		document.layers['bg'].document.layers[id].left = x;
		document.layers['bg'].document.layers[id].top = y;
	}
}

function clipBy(id,t,r,b,l) {
	if (n4) {
	document.layers[id].clip.top = t;
	document.layers[id].clip.right = r;
	document.layers[id].clip.bottom = b;
	document.layers[id].clip.left = l;
	}
	if (ie) {
	document.all(id).style.clip = "rect(" + t + "px "+ r + "px " + b + "px " + l + "px)";
	}
	if (mozilla) {
	document.getElementById(id).style.clip = "rect(" + t + "px "+ r + "px " + b + "px " + l + "px)";
//	document.getElementById(id).style.overflow = "hidden";
	}}
	
function showLayer(id,parentid) {
	if (mod) {
		document.getElementById(id).style.visibility = "visible";
	} else if (msb) {
		document.all(id).style.visibility = "visible";
	} else if (naf) {
		if (arguments.length==2) {
			document.layers[parentid].document.layers[id].visibility = "show";
		} else {
			document.layers[id].visibility = "show";
		}
	}
}

function hideLayer(id,parentid) {
	if (mod) {
		document.getElementById(id).style.visibility = "hidden";
	} else if (msb) {
		document.all(id).style.visibility = "hidden";
	} else if (naf) {
		if (arguments.length==2) {
			document.layers[parentid].document.layers[id].visibility = "hide";
		} else {
			document.layers[id].visibility = "hide";
		}
	}
}

function getLeft(id,parentid) {
	var xpos = 0;
	if (mod) {
		xpos = document.getElementById(id).offsetLeft;
	} else if (msb) {
		xpos = parseInt(document.all(id).offsetLeft);
	} else if (naf) {
		xpos = (parentid)? document.layers[parentid].document.layers[id].left:document.layers[id].left;
	}
	return xpos;
}

function getTop(id,parentid) {
	var ypos = 0;
	if (mod) {
		ypos = document.getElementById(id).offsetTop;
	} else if (msb) {
		ypos = parseInt(document.all(id).offsetTop);
	} else if (naf) {
		ypos = (parentid)? document.layers[parentid].document.layers[id].top:document.layers[id].top;
	}
	return ypos;
}

function getWidth(id) {
	if (n4) {
		if (document.layers[id].w) {
		w = document.layers[id].w;
		} else {
		w = document.layers[id].clip.width;
		document.layers[id].w = document.layers[id].clip.width;
		}
	}
	if (ie4) {w = parseInt(document.all(id).offsetWidth);}
	if (msdom || mozilla) {w = document.getElementById(id).offsetWidth;}
	return w;
	}

function getHeight(id) {
	if (n4) {
		if (document.layers[id].h) {
		h = document.layers[id].h;
		} else {
		h = document.layers[id].clip.height;
		document.layers[id].h = document.layers[id].clip.height;
		}
	}
	if (ie4) {h = parseInt(document.all(id).offsetHeight);}
	if (msdom || mozilla) {h = document.getElementById(id).offsetHeight;}
	return h;
	}

function canvasWidth() {
	if (!ie) {
		w = window.innerWidth;
	} else {
		w = document.body.clientWidth;
	}
	return w;
}

function canvasHeight() {
	if (!ie) {
		var h = window.innerHeight;
	} else {
		var h = document.body.clientHeight;
	}
	return h;
}

function eventXcoord(e) {
	if (n4) { var x = e.pageX; }
	if (ie) { var x = event.x + document.body.scrollLeft - 2; }
	if (mozilla) { var x = e.clientX + document.body.scrollLeft; }
	return x;
	}

function eventYcoord(e) {
	if (n4) { var y = e.pageY; }
	if (ie) { var y = event.y + document.body.scrollTop - 2; }
	if (mozilla) { var y = e.clientY + document.body.scrollTop; }
	return y;
	}

function eventX(e) {
	var x = 0;
	if (!e) var e = window.event;
	if (e.pageX) {
		x = e.pageX;
	} else if (e.clientX) {
		x = e.clientX + document.body.scrollLeft;
	}
	return x;
}

function eventY(e) {
	var y = 0;
	if (!e) var e = window.event;
	if (e.pageY) {
		y = e.pageY;
	} else if (e.clientY) {
		y = e.clientY + document.body.scrollTop;
	}
	return y;
}

function setLeft(id,l) {
	if (n4) {document.layers[id].left = l;}
	if (ie4) {document.all(id).style.left = l + "px";}
	if (msdom || mozilla) {document.getElementById(id).style.left = l + "px";}
	}

function setTop(id,t) {
	if (n4) {document.layers[id].top = t;}
	if (ie4) {document.all(id).style.top = t + "px";}
	if (msdom || mozilla) {document.getElementById(id).style.top = t + "px";}
	}

function setWidth(id,w) {
	if (n4) {document.layers[id].width = w;}
	if (ie4) {document.all(id).style.width =w + "px";}
	if (msdom || mozilla) {document.getElementById(id).style.width = w + "px";}
	}

function setHeight(id,h) {
	if (n4) {document.layers[id].height = h;}
	if (ie4) {document.all(id).style.height = h + "px";}
	if (msdom || mozilla) {document.getElementById(id).style.height = h + "px";}
	}

function setZIndex(id,z) {
	if (n4) {document.layers[id].zIndex = z;}
	if (ie) {document.all(id).style.zIndex = z;}
	if (mozilla) {document.getElementById(id).style.zIndex = z;}
	}

function setBackgroundColor(id,color) {
	if (id==null) {
		if (n4 || mozilla) document.bgColor = color;
		if (ie) document.body.style.backgroundColor = color;
	}
	else {
		if (n4) document.layers[id].document.bgColor = color;
		if (ie4) document.all(id).style.backgroundColor = color;
		if (msdom || mozilla) document.getElementById(id).style.backgroundColor = color;
	}
}

function layerWrite(id,content) {
	if (mod) {
		document.getElementById(id).innerHTML = content;
	}
	else if (msb) {
		document.all(id).innerHTML = content;
	}
	else if (naf) {
		var lyr = document.layers[id].document;
		lyr.open();
		lyr.write(content);
		lyr.close();
	}
}

function getZIndex(id) {
	var z;
	if (ie) {z = document.all(id).style.zIndex;}
	if (n4) {z = document.layers[id].zIndex;}
	if (mozilla) {z = 0;}
	return z;
	}
	
function decimate(num) {
	var num = parseInt(num*100+.5)/100;	
	if (num == parseInt(num)) {
		num = ""+num+".00";
	} else if (num == parseInt(num*10)/10) {
		num = ""+num+"0";
	}
	return num;
}

