/*' ==================================================================
	Magicalia DHTML Library
	(c) 2003 Magicalia Ltd.
	Author: Dave Searle (dave@magicalia.com)
	==================================================================*/

var isNS4, isIE4, isIE5, isNS6, isDOM, xMousePos, yMousePos, sRightClickEventHandler

function DHTML_Object(sDIV_Id) {

	this.DIV_Id = sDIV_Id;
	this.Show = ShowObject;
	this.Hide = HideObject;
	this.Move = MoveObject;
	this.Contents = SetContents;
	this.SetMouseEvents = SetMouseEvents;
	this.GetObj = GetObject;

	this.x = 0;
	this.y = 0;
	this.z = 0;

	if (isNS4) {
		this.obj = document.layers[sDIV_Id];
	} else if (isIE4) {
		this.obj = document.all[sDIV_Id];
	} else if (isDOM) {
		this.obj = document.getElementById(sDIV_Id);
	}

}

function GetObject()
{
	return this.obj;
}

// Set mouse events for the object (not the page)
function SetMouseEvents( argOnUp, argOnDown, argOnMove )
{
	this.obj.onmousedown = eval( argOnDown);
	this.obj.onmousemove = eval( argOnMove );
	this.obj.onmouseup = eval( argOnUp );
}

// set mouse events for the whole page
function SetPageMouseEvents( argOnUp, argOnDown, argOnMove )
{
	document.onmousedown = eval( argOnDown);
	document.onmousemove = eval( argOnMove );
	document.onmouseup = eval( argOnUp );
	
	if (isNS4)
		document.captureEvents(Event.MOUSEDOWN | Event.MOUSEMOVE | Event.MOUSEUP)
}

function SetContents(sContents) {

	this.obj.innerHTML = sContents;

}

function HideObject() {

	if(isNS4) {
		this.obj.visibility ="hide";  
	} else {
		this.obj.style.visibility = "hidden";
	}
}

function ShowObject() {

	if(isNS4) {
		this.obj.visibility ="show"; 
	} else {
		this.obj.style.visibility = "visible";
	}
}

function MoveObject(x,y,z)
{
	if( isNS4 )
	{
		this.obj.left = x;		
		this.obj.top = y;
		this.obj.zIndex = z;
		return;
	}
	
	this.obj.style.left = x;
	this.obj.style.top = y;
	this.obj.style.zIndex = z;
}

function GetBrowserWidth()
{
	var nWidth;
	if ( isNS4 )
	{
		nWidth = window.innerWidth;
		return( nWidth );
	}

	nWidth = document.body.clientWidth;
	
	return( nWidth );
}

function GetBrowserHeight()
{
	var nHeight;
	if( isNS4 )
	{
		nHeight = window.innerHeight;
		return( nHeight );
	}
	
	nHeight = document.body.clientHeight;
	return( nHeight );
}

function CaptureMousePosition(e) {

    if (isNS4) {

        xMousePos = e.pageX;
        yMousePos = e.pageY;

    } else if (isIE4) {

        xMousePos = window.event.x+document.body.scrollLeft;
        yMousePos = window.event.y+document.body.scrollTop;

    } else if (isDOM) {

        xMousePos = e.pageX;
        yMousePos = e.pageY;

    }
}

function GetRightClick(e)
{
	if (isNS4) {
		
		if (e.which == 3) {
			eval(sRightClickEventHandler + '( window.event.srcElement );');
			return false;
		}
	}
			
	if (isIE4) {
		eval(sRightClickEventHandler + '( window.event.srcElement );');
		return false;
	}

	if (isDOM) {
		if (e.button == 2) {
			eval(sRightClickEventHandler + '( e.target );');
			e.preventDefault();
			return false;
		}
	}
}

function FindTableRow( objItem )
{
	if (objItem.tagName == "DIV")
		return objItem;
	else if (objItem.tagName == "BODY")
		return null;
 
	return FindTableRow(objItem.parentNode);
}

function SetupRightMouseClick(strRightClickEventHandler) {

	sRightClickEventHandler = strRightClickEventHandler;

	if (isIE4)  {
		document.oncontextmenu = GetRightClick;
	}	
						
	if (isNS4) {
		document.captureEvents(Event.MOUSEDOWN);
		document.onmousedown = GetRightClick;
	}
		
	if (isDOM) {
		document.addEventListener("click", GetRightClick, false);
	}
}

function DHTML_Init() {

	isNS4 = (document.layers) ? true : false;
	isIE4 = (document.all) ? true : false;
	isNS6 = (!document.all && document.getElementById) ? true : false;
	isDOM = (document.getElementById && !document.all) ? true : false;
	
	/*if (isNS4)
		alert("Netscape 4");
	
	if (isIE4)
		alert("IE4/5");
		
	if (isNS6)
		alert("Netscape 6");
		
	if (isDOM)
		alert("DOM Com");*/	

}
