// Indicates Internet Explorer, set to true in the ie.js file
var IE = false;

// Adds an event to an object.
function addEvent(Obj, Event, Callback)
{
	if (!document.getElementById || !Obj) return;

	if (Obj.addEventListener)
	{
		// Standards compliant browsers.
		Obj.addEventListener(Event, Callback, false);
	}
	else
	{
		// IE-based.
		Obj.attachEvent('on' + Event, Callback);
	}
}

function GetEventSrc(Evt)
{
	if (!Evt) return;
	if (Evt.srcElement) return Evt.srcElement;
	else if (Evt.currentTarget) return Evt.currentTarget;
	return false;
}

function GetEventKey(Evt)
{
	if (!Evt) return;
	if (Evt.which) return Evt.which;
	else if (Evt.keyCode) return Evt.keyCode;
	return false;
}

function InClassName(Element, Name)
{
	var ClassNames = Element.className.split(' ');
	for (var i in ClassNames)
	{
		if (ClassNames[i] == Name)
		{
			return true;
			break;
		}
	}
	return false;
}

// Courtesy of quirksmode.org
// Gets the current text selection.
function getSel(obj)
{
	if (window.getSelection)
	{
		return window.getSelection();
	}
	else if (document.getSelection)
	{
		return document.getSelection();
	}
	else if (document.selection)
	{
		return document.selection.createRange().text;
	}
}

function GoTo(Href)
{
	window.location = Href;
}

/* The following functions are a courtesy of quirksmode.org */
// Finds object's absolute position on X axis.
function findPosX(obj)
{
	var curleft = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	{
		curleft += obj.x;
	}

	return curleft;
}

// Finds object's absolute position on Y axis.
function findPosY(obj)
{
	var curtop = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	{
		curtop += obj.y;
	}

	return curtop;
}

// Here we deal with the window sizes and box sizes and such.
function windowInnerSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return [myWidth, myHeight];
}

addEvent(window, 'load', AddDeletePrompts);

function AddDeletePrompts(evt)
{
	var inputs = document.getElementsByTagName('input');
	for (var i = 0; input = inputs[i]; i++)
	{
		if (InClassName(input, 'delete'))
		{
			addEvent(input, 'click', function()
			{
				return confirm(Msg_DeletePrompt);
			});
		}
	}

	var links = document.getElementsByTagName('a');
	for (var i = 0; link = links[i]; i++)
	{
		if (InClassName(link, 'delete'))
		{
			addEvent(link, 'click', function()
			{
				return confirm(Msg_DeletePrompt);
			});
		}
	}
}

String.prototype.trim = function()
{
    return this.replace(/^\s*|\s*$/g, '');
}

String.prototype.ltrim = function()
{
    return this.replace(/^\s*/g, '');
}

String.prototype.rtrim = function()
{
    return this.replace(/\s*$/g, '');
}
