/*
	Cross-browser helper functions
*/

//
// Fetches an element from the page by it's ID value
//
function fetchElement(idref)
{
	if (typeof(idref) != 'string') return idref;
	if (document.getElementById) return document.getElementById(idref);
	else if (document.all) return document.all[idref];
	else return null;
}

// 
// Returns the width of the document body 
//
function fetchWindowWidth()
{	
	if (self.innerWidth) // all except Explorer
	{
		return self.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth) // Explorer 6 Strict Mode
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body) // other Explorers
	{
		return document.body.clientWidth;
	}
}

//
// Returns the height of the document body
//
function fetchWindowHeight()
{
	if (self.innerHeight) // all except Explorer
	{
		return self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) // Explorer 6 Strict Mode
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		return document.body.clientHeight;
	}		
}

//
// Gets the width of an element
//
function fetchElementWidth(idref)
{
	return fetchElement(idref).offsetWidth;
}

//
// Gets the height of an element
//
function fetchElementHeight(idref)
{
	return fetchElement(idref).offsetHeight;
}

//
// Gets the horizontal scroll offset of the window
//
function fetchScrollX()
{
	if (document.documentElement && document.documentElement.scrollLeft) return document.documentElement.scrollLeft;		
	else if (document.body)	return document.body.scrollLeft;
	else return self.pageXOffset;
}

//
// Gets the vertical scroll offset of the window
//
function fetchScrollY()
{
	if (document.documentElement && document.documentElement.scrollTop)	return document.documentElement.scrollTop;		
	else if (document.body)	return document.body.scrollTop;
	else return self.pageYOffset;
}

function fetchMouseX()
{
	
}

function fetchMouseY()
{
	
}

/*
//////////////////////////////////////////////////////////

Type Detection Functions

//////////////////////////////////////////////////////////
*/
	
function isAlien(a) 
{
   return isObject(a) && typeof a.constructor != 'function';
}

function isArray(a) 
{
	return isObject(a) && a.constructor == Array;
}

function isBoolean(a) 
{
	return typeof a == 'boolean';
}

function isEmpty(o) 
{
	var i, v;
	if (isObject(o)) 
	{
		for (i in o) 
		{
			v = o[i];
			if (isUndefined(v) && isFunction(v)) 
			{
				return false;
			}
		}
	}
	return true;
}

function isFunction(a) 
{
	return typeof a == 'function';
}

function isNull(a) 
{
	return a === null;
}

function isNumber(a) 
{
	return typeof a == 'number' && isFinite(a);
}

function isObject(a) 
{
	return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) 
{
	return typeof a == 'string';
}

function isUndefined(a) 
{
	return typeof a == 'undefined';
} 	
