// --------------------------------------------------
// ------ This class encapsulates a very ------------
// ------ basic DHTML object that can be ------------
// ------ moved around. It also demon-   ------------
// ------ strates how a class can be     ------------
// ------ written including member       ------------
// ------ functions.                     ------------
// --------------------------------------------------

function inspect(obj)
{
	var str = new Array();
	var count =0;
	//var obj = document.all;
	for (var i in obj)
	{
		var newElem = new String(obj[i]);
		if (newElem.length > 60)
			newElem = newElem.substr(0,60)+"... T R U N C A T E D";
		str[count++] = i +"="+ newElem;
	}
	str.sort();
	var out = new String();
	count = 0;
	for (var i in str)
	{
		out += str[i]+"\n";
		if (count++ > 30)
		{
			count =0;
			alert(out);
			out = "";
		}
	} // of for
	alert(out);
}



// first some code to detect which browser we are using...
var isNav4 = false;
var isIE4 = false;
var isNav5 = false;
if (navigator.appVersion.charAt(0) == "4")
{
    if (navigator.appName.indexOf("Explorer") >= 0)
    {
        isIE4 = true;
    }
    else
    {
        isNav4 = true;
    }
}
else if (navigator.appVersion.charAt(0) > "4")
{
    isNav5 = true;
}

function Movable(item)
{
	this.name = item;

	if (isNav4)
	{
	  this.style = this.obj = document[item];
	 // inspect(window);
	}
	else if (isNav5)
	{
	  this.obj = document.getElementById( item );
	  this.style = this.obj.style;
	}
	else if (isIE4)
	{
	  this.obj = document.all[item];
	  this.style = this.obj.style;
	}

	if (!this.obj)
	{
		alert("The given item does not exist!");
		return;
	} 
//	else inspect(this.obj);
	this.style.position = "relative";
// --------------------------------------------------
	this.setPosition = function(mode)
	{
		this.style.position = mode;
	};
// --------------------------------------------------
	this.toString = function()
	{
		return (this.name+" is movable");
	};
// --------------------------------------------------
	this.moveTo = function (x,y)
	{
		if (isIE4)
		{
			this.style.posTop = y;
			this.style.posLeft = x;
		}
		else if (isNav4)
		{
			this.obj.pageY = y;
			this.obj.pageX = x;
		}
		else if (isNav5)
		{
			this.style.top = y;
			this.style.left = x;
		}
	}; // of moveTo
// --------------------------------------------------
	this.getHeight = function()
	{
		if (!isNav4)
			return this.obj.scrollHeight;
		else
			return this.obj.window.innerHeight;
	};  // getTop
// --------------------------------------------------
	this.getWidth = function()
	{
		if (!isNav4)
			return this.obj.scrollWidth;
		else
			return this.obj.window.innerWidth;
	};  // getLeft
// --------------------------------------------------
} // of class
//===========================================

function ElementExists(item)
/*
	This function takes a string, like "document.forms[5].item" and checks for the existence
	of the described element. This is done by decomposing the string into elements from left
	to right and checking each sub-property. Once a property fails, the function returns false.
	This will not work for strings containing variables: "document.forms[j].item", because they
	are not evaluated!
*/
{
	if ((typeof item) != "string")
	{
		alert("ElementExists: Argument must be String");
		return false;	
	}
	item = item.toLowerCase();
	var div = item.split('.');
//	if (div[0] != "document")
	if (
			div[0] !="document" &&
			div[0] !="top" &&
			div[0] !="window" &&
			div[0] !="parent" &&
			div[0] !="self" 
		)
	{
		alert('ElementExists: argument must be a top-level object');
		return false;	
	}
	var exists = true;
	var test = div[0];
	for (var i=1; i<div.length&&exists; i++)
	{
//		alert(test+" "+exists);
		if (!eval(test))
			exists = false;
		test += '.'+div[i];
	}
	return exists;
}
