/*Author: Robert Seber
Revision: 1.24 

ns4 = (document.layers);
ie4 = (document.all && !document.getElementById);
ie5 = (document.all && document.getElementById);
ns6 = (!document.all && document.getElementById);
*/

function initialiseDivs(ids){
	/*Create divs object - an array of divs with cross browser DHTML methods */
        divs = new Array();	
	if      (document.all) 	// ie4, ie5
		ie_initialiseDivs(document);
	else if (document.layers)			// ns4
		ns_initialiseDivs(document);
	else if (!document.all && document.getElementById)
		ns6_initialiseDivs(document);
	 
}  

function ie_initialiseDivs(doc){
	for (var i=0;i<doc.all.length;i++){
		if (doc.all[i].id){
			divs[doc.all[i].id] = new Div(doc.all[i]);
			divs[divs.length] = divs[doc.all[i].id];
		}
	}
	nsie_setDivMethods();
	ie_setDivMethods();
}

function ns_initialiseDivs(doc){
	for (var i=0;i<doc.layers.length;i++){
		if (doc.layers[i].id){
			divs[doc.layers[i].id] = new Div(doc.layers[i]);
			divs[divs.length] = divs[doc.layers[i].id];
			ns_initialiseDivs(doc.layers[i].document);
		}
	}
	nsie_setDivMethods();
	ns_setDivMethods();
}

function ns6_initialiseDivs(doc){

	var divArray = doc.getElementsByTagName("div");
	for (var i=0;i<divArray.length;i++){
		if (divArray[i].id){
			if(divArray[i].document) alert("doc");
			divArray[i].document=doc;
			divs[divArray[i].id] = new Div(divArray[i]);
			divs[divs.length] = divs[divArray[i].id];
		}
	}
	nsie_setDivMethods();
	ns6_setDivMethods();
}

function initialiseMouse(){
	/*Create mouse object - has x and y properties plus button tracking */
	mouse = new Object();
	mouse.onmove = new Function("");
	mouse.ondown = new Function("");
	mouse.onup = new Function("");
	mouse.x = 0;
	mouse.y = 0;
	mouse.button = 0;
	document.onmouseup = nsie_onmouseup;
	if (document.all){
		document.onmousemove = ie_onmousemove;
		document.onmousedown = ie_onmousedown;
	}
	else {
		document.captureEvents(Event.MOUSEMOVE | Event.MOUSEDOWN | Event.MOUSEUP);
		document.onmousemove = ns_onmousemove;
		document.onmousedown = ns_onmousedown;
	}
}

function initialiseKeyboard(){
	/* Create keyboard object - tracks pressed keys */
	keyboard = new Object();
	keyboard.onkeydown = new Function("");
	keyboard.onkeyup = new Function("");
	keyboard.key = null;
	if (document.all){
		document.onkeydown = ie_onkeydown;
		document.onkeyup = ie_onkeyup;
	}
	else {
		document.captureEvents(Event.KEYUP | Event.KEYDOWN);
		document.onkeydown = ns_onkeydown;
		document.onkeyup = ns_onkeyup;
	}
}

function ie_onkeydown(){
	keyboard.key = "";
	if (window.event.ctrlKey) keyboard.key += "[ctrl]-";
	if (window.event.altKey) keyboard.key += "[alt]-";
	if (window.event.shiftKey) keyboard.key += "[shift]-";
	keyboard.key += String.fromCharCode(window.event.keyCode);
	return keyboard.onkeydown();
}

function ns_onkeydown(event){
	keyboard.key = "";
	switch (event.modifiers){
		case 1: keyboard.key += "[??]-"; break;
		case 2: keyboard.key += "[ctrl]-"; break;
		case 3: keyboard.key += "[ctrl]-[alt]-"; break;
		case 4: keyboard.key += "[shift]-"; break;
		case 5: keyboard.key += "[???]-"; break;
		case 6: keyboard.key += "[ctrl]-[shift]-"; break;
		case 7: keyboard.key += "[ctrl]-[shift]-[alt]"; break;
	}
	var characterCode = "";
	if (event.which>96&&event.which<123) characterCode = event.which-32;
	else if (event.which>0&&event.which<27) characterCode = event.which+64;
	keyboard.key += String.fromCharCode(characterCode);
	return keyboard.onkeydown();
}

function ie_onkeyup(){
	keyboard.key = "";
	return keyboard.onkeyup();
}

function ns_onkeyup(event){
	keyboard.key = "";
	return keyboard.onkeyup();
}

function ie_onmousemove(){
	mouse.x = window.event.clientX + document.body.scrollLeft;
	mouse.y = window.event.clientY + document.body.scrollTop;;
	return mouse.onmove();
}

function ns_onmousemove(event){
	mouse.x = event.pageX;
	mouse.y = event.pageY;
	return mouse.onmove();
}

function ie_onmousedown(){
	mouse.button = window.event.button;
	return mouse.ondown();
}

function ns_onmousedown(event){
	mouse.button = event.which;
	return mouse.ondown();
}

function nsie_onmouseup(){
	mouse.button = 0;
	return mouse.onup();
}

function Div(div){
	this.div = div;
}

function nsie_setDivMethods(){
	var pt = Div.prototype;
	pt.setClippingRectangle = deprecated_setClippingRectangle;
	pt.getClippingRectangle = deprecated_getClippingRectangle;
	pt.getFullHeight = deprecated_getFullHeight;
	pt.getFullWidth = deprecated_getFullWidth;
	pt.setClippingRectangle = deprecated_setClippingRectangle;
	pt.getClippingRectangle = deprecated_getClippingRectangle;
	pt.center = nsie_center;
	pt.getRight = nsie_getRight;
	pt.getBottom = nsie_getBottom;
	pt.setOnMouseOver = nsie_setOnMouseOver;
	pt.setOnMouseOut = nsie_setOnMouseOut;
	pt.scrollBy = nsie_scrollBy;
	pt.scrollTo = nsie_scrollTo;
	pt.getClipTop = nsie_getClipTop;
	pt.getClipRight = nsie_getClipRight;
	pt.getClipBottom = nsie_getClipBottom;
	pt.getClipLeft = nsie_getClipLeft;

}

function ns_setDivMethods(){
	var pt = Div.prototype;
	pt.getClipWidth = ns_getClipWidth;
	pt.getClipHeight = ns_getClipHeight;
	pt.setInnerHtml = ns_setInnerHtml;
	pt.setClip = ns_setClip;
	pt.getClip = ns_getClip;
	pt.setBackgroundColor = ns_setBackgroundColor;
	pt.setZIndex = ns_setZIndex;
	pt.getZIndex = ns_getZIndex;
	pt.moveTo = ns_moveTo;
	pt.moveBy = ns_moveBy;
	pt.show = ns_show;
	pt.hide = ns_hide;
	pt.isHidden = ns_isHidden;
	pt.isVisible = ns_isVisible;
	pt.getHeight = ns_getHeight;
	pt.getWidth = ns_getWidth;
	pt.getLeft = ns_getLeft;
	pt.setLeft = ns_setLeft;
	pt.getTop = ns_getTop;
	pt.setTop = ns_setTop;
	getInsideWindowWidth = ns_getInsideWindowWidth;
	getInsideWindowHeight = ns_getInsideWindowHeight;
	pt.windowOffsetLeft = ns_windowOffsetLeft;
	pt.windowOffsetTop = ns_windowOffsetTop;
}

function ns6_setDivMethods(){
	var pt = Div.prototype;
	pt.getClipWidth = ns6_getClipWidth;
	pt.getClipHeight = ns6_getClipHeight;
	pt.setInnerHtml = ns_setInnerHtml;
	pt.setClip = ns6_setClip;
	pt.getClip = ns6_getClip;
	pt.setBackgroundColor = ns_setBackgroundColor;
	pt.setZIndex = ns_setZIndex;
	pt.getZIndex = ns_getZIndex;
	pt.moveTo = ns6_moveTo;
	pt.moveBy = ns_moveBy;
	pt.show = ns6_show;
	pt.hide = ns6_hide;
	pt.isHidden = ns6_isHidden;
	pt.isVisible = ns6_isVisible;
	pt.getHeight = ns6_getHeight;
	pt.getWidth = ns6_getWidth;
	pt.getLeft = ns6_getLeft;
	pt.setLeft = ns6_setLeft;
	pt.getTop = ns6_getTop;
	pt.setTop = ns6_setTop;
	getInsideWindowWidth = ns_getInsideWindowWidth;
	getInsideWindowHeight = ns_getInsideWindowHeight;
	pt.windowOffsetLeft = ns6_windowOffsetLeft;
	pt.windowOffsetTop = ns6_windowOffsetTop;
}

function ie_setDivMethods(){	
	var pt = Div.prototype;
	pt.getClipWidth = ie_getClipWidth;
	pt.getClipHeight = ie_getClipHeight;
	pt.setInnerHtml = ie_setInnerHtml;
	pt.setClip = ie_setClip;
	pt.getClip = ie_getClip;
	pt.setBackgroundColor = ie_setBackgroundColor;
	pt.setZIndex = ie_setZIndex;
	pt.getZIndex = ie_getZIndex;
	pt.moveTo = ie_moveTo;
	pt.moveBy = ie_moveBy;
	pt.show = ie_show;
	pt.hide = ie_hide;
	pt.isHidden = ie_isHidden;
	pt.isVisible = ie_isVisible;
	pt.getHeight = ie_getHeight;
	pt.getWidth = ie_getWidth;
	pt.getLeft = ie_getLeft;
	pt.setLeft = ie_setLeft;
	pt.getTop = ie_getTop;
	pt.setTop = ie_setTop;
	getInsideWindowWidth = ie_getInsideWindowWidth;
	getInsideWindowHeight = ie_getInsideWindowHeight;
	pt.windowOffsetLeft = ie_windowOffsetLeft;
	pt.windowOffsetTop = ie_windowOffsetTop;

}

function deprecated_setClippingRectangle(){
	alert("Call made to setClippingRectangle() - please use setClip() instead")
}

function deprecated_getClippingRectangle(){
	alert("Call made to getClippingRectangle() - please use getClip() instead")
}

function deprecated_getFullHeight(){
	alert("Call made to getFullHeight() - please use getHeight() instead")
}

function deprecated_getFullWidth(){
	alert("Call made to getFullWidth() - please use getWidth() instead")
}

function ns_getClipHeight(){
	return this.div.clip.height;
}

function ns6_getClipHeight(){
	return this.div.offsetHeight;
}

function ns_getHeight(){
	return this.div.document.height;
}

function ns6_getHeight(){
//	return this.div.document.height;
	return this.div.offsetHeight;
}

function ie_getClipHeight(){
	var rect = this.getClip();
	return rect.bottom-rect.top;
}

function ie_getHeight(){
	return this.div.clientHeight;
}

function ns_getClipWidth(){
	return this.div.clip.width;
}

function ns6_getClipWidth(){
	return this.div.offsetWidth;
}

function ns_getWidth(){
	return this.div.document.width;
}

function ns6_getWidth(){
	return this.div.offsetWidth;
}

function ie_getClipWidth(){
	var rect = this.getClip();
	return rect.right-rect.left;
}

function ie_getWidth(){
	return this.div.clientWidth;
}

function ie_setInnerHtml(html){
	this.div.innerHTML = html;
}

function ns_setInnerHtml(html){
	this.div.document.write(html);
	this.div.document.close();
}

function nsie_scrollBy(x,y){
	this.moveBy(-x,-y);
	var rect = this.getClip();
	this.setClip(rect.top+y,rect.right+x,rect.bottom+y,rect.left+x);
}

function nsie_scrollTo(x,y){
	var rect = this.getClip();
	this.moveBy(rect.left-x,rect.top-y);
	this.setClip(y,rect.right-rect.left+x,rect.bottom-rect.top+y,x);
}

function ie_setClip(top,right,bottom,left){
	this.div.style.clip = "rect("+top+"px "+right+"px "+bottom+"px "+left+"px )";
}

function ie_getClip(){
	var ob = new Object();
	if (this.div.style.clip&&this.div.style.clip!="auto"){
		var tempArray = this.div.style.clip.match(/-?\d+/g);
		ob.top = parseInt(tempArray[0]);
		ob.right = parseInt(tempArray[1]);
		ob.bottom = parseInt(tempArray[2]);
		ob.left = parseInt(tempArray[3]);
	}
	else {
		ob.top = 0;
		ob.right = this.div.clientWidth;
		ob.bottom = this.div.clientHeight;
		ob.left = 0;
	}
	return ob;
}

function ns_getClip(){
	return this.div.clip;
}
function ns6_getClip(){
	var ob = new Object();
	if (this.div.style.clip&&this.div.style.clip!="auto"){
		var tempArray = this.div.style.clip.match(/\d+/g);
		ob.top = parseInt(tempArray[0]);
		ob.right = parseInt(tempArray[1]);
		ob.bottom = parseInt(tempArray[2]);
		ob.left = parseInt(tempArray[3]);
	}
	else {
		ob.top = 0;
		ob.right = this.div.clientWidth;
		ob.bottom = this.div.clientHeight;
		ob.left = 0;
	}
	return ob;
}
function nsie_getClipTop(){
	var rect = this.getClip();
	return rect.top;
}

function nsie_getClipRight(){
	var rect = this.getClip();
	return rect.right;
}

function nsie_getClipBottom(){
	var rect = this.getClip();
	return rect.bottom;
}

function nsie_getClipLeft(){
	var rect = this.getClip();
	return rect.left;
}

function ns_setClip(top,right,bottom,left){
	this.div.clip.top = top;
	this.div.clip.right = right;
	this.div.clip.bottom = bottom;
	this.div.clip.left = left;
}

function ns6_setClip(top,right,bottom,left){
	//alert("rect("+top+"px "+right+"px "+bottom+"px "+left+"px )");
	this.div.style.clip = "rect("+top+"px "+right+"px "+bottom+"px "+left+"px )";
}	

function nsie_setOnMouseOver(functionObject){
	if (typeof(functionObject)=="string") this.div.onmouseover = new Function(functionObject);
	else this.div.onmouseover = functionObject;
}

function nsie_setOnMouseOut(functionObject){
	if (typeof(functionObject)=="string") this.div.onmouseout = new Function(functionObject);
	else this.div.onmouseout = functionObject;
}


function ie_setBackgroundColor(color){
	this.div.style.backgroundColor = color;
}

function ns_setBackgroundColor(color){
	this.div.bgColor = color;
}

function ie_setZIndex(zIndex){
	this.div.style.zIndex = zIndex;
}

function ie_getZIndex(zIndex){
	return this.div.style.zIndex;
}

function ns_setZIndex(zIndex){
	this.div.zIndex = zIndex;
}

function ns_getZIndex(zIndex){
	return this.div.zIndex;
}

function nsie_getRight(){
	return this.getLeft()+this.getWidth();
}

function nsie_getBottom(){
	return this.getTop()+this.getHeight();
}

function ie_getLeft(){
	return this.div.style.pixelLeft;
}

function ns_getLeft(){
	return this.div.left;
}

function ns6_getLeft(){ 
	return parseInt(this.div.style.left);
}
function ie_setLeft(x){
	this.div.style.pixelLeft = x;
}

function ns_setLeft(x){
	this.div.moveTo(x,this.getTop());
}
function ns6_setLeft(x){
	this.div.style.left = x +"px";
}

function ie_setTop(y){
	this.div.style.pixelTop = y;
}

function ns_setTop(y){
	this.div.moveTo(this.getLeft(),y);
}

function ns6_setTop(y){
	this.div.style.top = y;
}

function ie_getTop(){
	return this.div.style.pixelTop;
}

function ns_getTop(){
	return this.div.top;
}

function ns6_getTop(){
	return parseInt(this.div.style.top);
}

function ns_moveTo(x,y){
	this.div.moveTo(x,y);
}

function ns6_moveTo(x,y){
	this.div.style.left = x +"px";
	this.div.style.top = y +"px";
}
function ie_moveTo(x,y){
	this.div.style.pixelLeft = x;
	this.div.style.pixelTop = y;
}

function ns_moveBy(x,y){
	this.div.moveBy(x,y);
}

function ie_moveBy(x,y){
	this.div.style.pixelLeft += x;
	this.div.style.pixelTop += y;
}

function ns_show(){
	this.div.visibility = "visible";
}

function ns6_show(){
	this.div.style.visibility = "visible";
}

function ie_isHidden(){
	return (this.div.style.visibility == "hidden");
}

function ns_isHidden(){
	return this.div.hidden;
}

function ns6_isHidden(){
	return (this.div.style.visibility == "hidden");
}

function ie_isVisible(){
	return (this.div.style.visibility != "hidden");
}

function ns_isVisible(){
	return !this.div.hidden;
}

function ns6_isVisible(){
	return (this.div.style.visibility != "hidden");
}

function ie_show(){
	this.div.style.visibility = "visible";
}

function ns_hide(){
	this.div.visibility = "hidden";
}

function ns6_hide(){
	this.div.style.visibility = "hidden";
}

function ie_hide(){
	this.div.style.visibility = "hidden";
}

function ie_getInsideWindowWidth(){
	return document.body.clientWidth;
}

function ie_getInsideWindowHeight(){
	return document.body.clientHeight;
}

function ns_getInsideWindowWidth(){
	return window.innerWidth;
}

function ns_getInsideWindowHeight(){
	return window.innerHeight;
}

function nsie_center(){
	this.setLeft((getInsideWindowWidth()-this.getWidth())/2);
}

/* Window OffsetLeft */
function ns_windowOffsetLeft(){
	return this.div.pageX;
}
function ns6_windowOffsetLeft(){
	return this.div.offsetLeft;
}
function ie_windowOffsetLeft(){
    var left =0;
    var elem = this.div;
    while(elem != document.body)
    {
      left  +=elem.offsetLeft;
      elem = elem.offsetParent;
    }
    return left;
}

/* Window OffsetTop */
function ns_windowOffsetTop(){
	return this.div.pageY;
}
function ns6_windowOffsetTop(){
	return this.div.offsetTop;
}
function ie_windowOffsetTop(){
    var top =0;
    var elem = this.div;
    while(elem != document.body)
    {
      top  +=elem.offsetTop;
      elem = elem.offsetParent;
    }
    return top;
}
	
