// dyna.js v1.1 by David Kearns
// copyright 2000 by Doceus
//
// These routines should provide a framework for
// commonly used DHTML functions, in a way that should
// divorce the browser from the code, so that the 
// developer need not worry about what platform the
// user is using.
//

// For purposes of the Intranet, we will attempt to guess
// what browser is being used.
//
// There are obvious problems with this scheme, as browsers
// are constantly changing, but I feel that in this case
// this should be sufficient
//
var NN = (navigator.appName == "Netscape") ? 1 : 0;
// var NN = (document.layers) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var D2 = (document.getElementById ) ? 1 : 0;

// Debug info
// window.defaultStatus = 'NN:'+NN+' IE:'+IE+' D2:'+D2;

// Setup global variable for use in PopUpMenus
var PUM;

// Capture events for cursor tracking. Setup global variables
var cursorX = 0;
var cursorY = 0;
document.onmousemove = mouseTrack;
if (NN)
{	document.captureEvents(Event.MOUSEMOVE);
}

// Debug info. Uncomment if you wish to use it.
// window.defaultStatus = 'NN:'+NN+' IE:'+IE+' D2:'+D2;

// Return a pointer to the object specified by the ID "reference".
// In netscape 4 this must be a layer.
// The Object reference returned by this is suitable for passing
// to any function below that has an obj attribute.
//
// In order to assure this, you can use CF_DHTMLContainer
function dyObject(reference)
{	if (D2)
	{	return document.getElementById(reference);
	}
	else if (IE)
	{	return document.all[reference];
	}
	else if (NN)
	{	return document.layers[reference];
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

////////////////////////////////////////////////////////////////////////////////////////////

// Provide a method for error reporting, in the odd case that a user
// is not using one of the approved browsers
// NN 4.x, IE 4.x or higher, NN 6.x
function err(msg)
{	alert(msg);
	exit;
}

// Cursor move triggers event to set global variables
function mouseTrack(e) {
	if (NN)
	{	cursorX=e.pageX;
		cursorY=e.pageY;
	}
	else if (D2 && IE)
	{	cursorX=event.x+document.body.scrollLeft; 
		cursorY=event.y+document.body.scrollTop;
	}
	else if (IE) 
	{	cursorX=event.x; 
		cursorY=event.y;
	}
	else if (D2)
	{	cursorX=e.clientX + parseInt(window.scrollX);
		cursorY=e.clientY + parseInt(window.scrollY);
	}
	// debug info
	// window.status = cursorX + ' ' + cursorY;
}

// Return the y coordinate of the object
function dyTop(obj)
{	if (D2)
	{	return(parseInt(obj.style.top));
	}
	else if (IE)
	{	return(parseInt(obj.style.pixelTop));
	}
	else if (NN)
	{	return(obj.top);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Return the x coordinate of the object
function dyLeft(obj)
{	if (D2)
	{	return (parseInt(obj.style.left));
	}
	else if (IE)
	{	return(parseInt(obj.style.pixelLeft));
	}
	else if (NN)
	{	return(obj.left);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Return the height of the object in pixels
function dyHeight(obj)
{	if (IE)
	{	return(parseInt(obj.clientHeight));
	}
	else if (D2)
	{	return (parseInt(obj.style.height));
	}
	else if (NN)
	{	return obj.clip.height;
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Return the width of the object in pixels
function dyWidth(obj)
{	if (IE)
	{	return(parseInt(obj.clientWidth));
	}
	else if (D2)
	{	return(parseInt(obj.style.width));
	}
	else if (NN)
	{	return(obj.clip.width);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Moves the object to the specified X Y coordinates
function dyMoveTo(obj,x,y)
{	if (D2)
	{	obj.style.left = x;
		obj.style.top = y;
	}
	else if (IE)
	{	obj.style.pixelLeft = x;
		obj.style.pixelTop = y;
	}
	else if (NN)
	{	obj.moveTo(x,y);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Moves the object by x,y pixels. Use negative numbers for up or right
function dyMoveBy(obj,x,y)
{	if (D2)
	{	obj.style.left += x;
		obj.style.top += y;
	}
	else if (IE)
	{	obj.style.pixelLeft += x;
		obj.style.pixelTop += y;
	}
	else if (NN)
	{	obj.moveBy(x,y);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Make the object visible.
function dyShow(obj)
{	if (D2)
	{	obj.style.display = 'block';
		obj.style.visibility = 'visible';
	}
	else if (IE)
	{	obj.style.visibility = 'visible';
	}
	else if (NN)
	{	obj.visibility = 'visible';
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Hide the object
function dyHide(obj)
{	if (D2)
	{	obj.style.display = 'none';
	}
	else if (IE)
	{	obj.style.visibility = 'hidden';
	}
	else if (NN)
	{	obj.visibility = 'hidden';
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

// Resize the height and width of the object to h,w. The upper right hand corner
// of the object will remain static.
function dyResizeTo(obj,h,w)
{	if (D2)
	{	obj.style.height=h;
		obj.style.width=w;
	}
	else if (IE)
	{	obj.style.height=h;
		obj.style.width=w;
	}
	else if (NN)
	{	obj.clip.height = h;
		obj.clip.width = w;
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

//Change the background color of the object. This might not always work, depending on other factors.
function dyColor(obj,color)
{	if (D2)
	{	obj.style.backgroundColor = color;
		obj.bgColor = color;
	}
	else if (IE)
	{	obj.style.backgroundColor = color;
	}
	else if (NN)
	{	obj.bgColor = color;
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

//This should return the width of the browser page. 
function dyFieldWidth()
{	if (IE)
	{	return(document.body.clientWidth);
	}
	else if (D2)
	{	return(window.innerWidth);
	}
	else if (NN)
	{	return(window.innerWidth);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

//This should return the height of the browser page. 
function dyFieldHeight()
{	if (IE)
	{	return(document.body.clientHeight);
	}
	else if (D2)
	{	return(window.innerHeight);
	}
	else if (NN)
	{	return(window.innerHeight);
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

////////////////////////////////////////////////////////////////////////////////////////////
// Dynamic Rewriting functions.
// Previously thought to not work on NN6/Mozilla. I was wrong.

//Dynamically rewrite the object.
function dyRewrite(obj,text)
{	if (IE || D2)
	{	obj.innerHTML = text;
	}
	else if (NN)
	{	obj.document.close();
		obj.document.writeln(text);
		obj.document.close();
	}
	else
	{	err('IE 4+ or Navigator 4+ is required');
	}
}

