// Copyright (C) 1999-2001 Richard Goode
// Email <richard.goode@virgin.net>
// This code may not be used without permission.

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

//alert(browser +  " " + version + " "  )
if( opera )
{
   ie = true;
}

msdom = (ie && !ie4)? true:false;

//if( ie )
//{
//alert("You are using ie")
//}
//if( ie4 )
//{
//alert("You are using ie4")
//}
//if( n4 )
//{
//alert("You are using n4")
//}
//if( mozilla )
//{
//alert("You are using Mozilla")
//}

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

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) {
//	r = parseInt(document.getElementById(id).style.width) - r;
//	b = parseInt(document.getElementById(id).style.height) - b;
	document.getElementById(id).style.clip = "rect(" + t + "px "+ r + "px " + b + "px " + l + "px)";
//	document.getElementById(id).style.overflow = "hidden";
	}}
	
function showLayer(id) {
	if (n4) document.layers[id].visibility = "show";
	if (ie4) document.all(id).style.visibility = "visible";
	if (msdom || mozilla) document.getElementById(id).style.visibility = "visible";
	}

function hideLayer(id) {
	if (n4) document.layers[id].visibility = "hide";
	if (ie4) document.all(id).style.visibility = "hidden";
	if (msdom || mozilla) document.getElementById(id).style.visibility = "hidden";
	}

function showNestedLayer(id,parentid) {
	if (n4) document.layers[parentid].document.layers[id].visibility = "show";
	if (ie4) document.all(id).style.visibility = "visible";
	if (msdom || mozilla) document.getElementById(id).style.visibility = "visible";
	}

function hideNestedLayer(id,parentid) {
	if (n4) document.layers[parentid].document.layers[id].visibility = "hide";
	if (ie4) document.all(id).style.visibility = "hidden";
	if (msdom || mozilla) document.getElementById(id).style.visibility = "hidden";
	}

function getLeft(id) {
	if (n4) {xpos = document.layers[id].left;}
	if (ie4) {xpos = parseInt(document.all(id).offsetLeft);}
	if (msdom || mozilla) {xpos = document.getElementById(id).offsetLeft;}
	if (mac && ie) xpos += 10;
	return xpos;
	}

function getTop(id) {
	if (n4) {ypos = document.layers[id].top;}
	if (ie4) {ypos = parseInt(document.all(id).offsetTop);}
	if (msdom || mozilla) {ypos = document.getElementById(id).offsetTop;}
	if (mac && ie) ypos += 15;
	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 (n4 || mozilla) { w = window.innerWidth; }
	if (ie) { w = document.body.clientWidth; }
	return w;
	}

function canvasHeight() {
	if (n4 || mozilla) { h = window.innerHeight; }
	if (ie) { 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; }
	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; }
	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) document.bgColor = color;
	if (ie) document.body.style.backgroundColor = color;
	if (mozilla) {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;
	}}
	
// The functions beyond this point are not yet Mozilla compatible.

if (mozilla) {
	eval("HTMLElement.prototype.innerHTML setter = function (str) {var r = this.ownerDocument.createRange();r.selectNodeContents(this);r.deleteContents();var df = r.createContextualFragment(str);this.appendChild(df);return str;}");
	}
  
function layerWrite(id,content) {
	if (n4) {
	var lyr = document.layers[id].document;
	lyr.open();
	lyr.write(content);
	lyr.close();
	}
	else if (ie) {
	document.all(id).innerHTML = content;
	}
	else if (mozilla) {
	document.getElementById(id).innerHTML = content;
	}}

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;
	}
	

