var usingDOM = (document.getElementById);
var usingDHTML = (usingDOM || document.all || document.layers);

var monthLengths = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

// Use this function to gain access to the HTML element you want to influence
// Thanks to http://www.quirksmode.org/
function getObj(obj_name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(obj_name);
		if (this.obj)
			this.style = document.getElementById(obj_name).style;
		else
			this.style = null;
	}
	else if (document.all)
	{
		this.obj = document.all[obj_name];
		if (this.obj)
			this.style = document.all[obj_name].style;
		else
			this.style = null;
	}
	else if (document.layers)
	{
		this.obj = getObjNN4(document, obj_name);
		this.style = this.obj;
	}
	else
	{
		this.obj = null;
		this.style = null;
	}
}

// Handle nested layers in Netscape Navigator 4
// Thanks to http://www.quirksmode.org/
function getObjNN4(obj, obj_name)
{
	var x = obj.layers;
	var foundLayer = null;
	for (var i=0; i < x.length; i++)
	{
		if (x[i].id == obj_name)
		 	foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i], obj_name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

// Thanks to http://www.quirksmode.org/
function findPosX1(obj)
{
	var x_obj = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			x_obj += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		x_obj += obj.x;

	return x_obj;
}

// Thanks to http://www.quirksmode.org/
function findPosX2(obj)
{
	var x_obj = 0;
	var obj_tmp = obj;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			x_obj += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		x_obj += obj.x;

	if (obj_tmp.offsetWidth)
		x_obj += obj_tmp.offsetWidth;
	else
		x_obj += obj_tmp.width;

	return x_obj;
}

// Thanks to http://www.quirksmode.org/
function findPosY1(obj)
{
	var y_obj = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			y_obj += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		y_obj += obj.y;

	return y_obj;
}

function setPosX(obj, val)
{
	if (obj.style.pixelLeft)
		obj.style.pixelLeft = val;
	else
		obj.style.left = val;
}

function setPosY(obj, val)
{
	if (obj.style.pixelTop)
		obj.style.pixelTop = val;
	else
		obj.style.top = val;
}

function movePosX(obj, val)
{
	if (obj.style.pixelLeft)
		obj.style.pixelLeft += val;
	else
		obj.style.left += val;
}

function movePosY(obj, val)
{
	if (obj.style.pixelTop)
		obj.style.pixelTop += val;
	else
		obj.style.top += val;
}

function clipThing(thing, clip_top, clip_right, clip_bottom, clip_left)
{
	if (clip_top < 0) clip_top = 0;
	if (clip_right < 0) clip_right = 0;
	if (clip_bottom < 0) clip_bottom = 0;
	if (clip_left < 0) clip_left = 0;

	if (document.layers)
	{
		thing.style.clip.top = clip_top;
		thing.style.clip.right = clip_right;
		thing.style.clip.bottom = clip_bottom;
		thing.style.clip.left = clip_left;
	}
	else
	{
		thing.obj.style.clip = 'rect(' + clip_top + ' ' + clip_right + ' ' + clip_bottom + ' ' + clip_left + ')';
	}
}

// Thanks to http://www.quirksmode.org/
function checkDate(yy, mm, dd)
{
	if (!dd || !mm || !yy)
		return false;

	if (yy/4 == parseInt(yy/4))
		monthLengths[1] = 29;

	if (dd > monthLengths[mm - 1])
		return false;

	monthLengths[1] = 28;

	var now = new Date();
	now = now.getTime(); //NN3

	var dateToCheck = new Date();
	dateToCheck.setYear(yy);
	dateToCheck.setMonth(mm - 1);
	dateToCheck.setDate(dd);
	var checkDate = dateToCheck.getTime();

	var futureDate = (now < checkDate);
	var pastDate = (now > checkDate);
}

function trimString(tmp_string)
{
	for (var i = 0; i < tmp_string.length; i++)   // trimming spaces from the head of the string.
	{
		if (tmp_string.charAt(i) != ' ')
		{
			tmp_string = tmp_string.slice(i, tmp_string.length);
			break;
		}
	}

	for (var i = (tmp_string.length - 1); i >= 0; i--) // trimming spaces from the tail of the string.
	{
		if (tmp_string.charAt(i) != ' ')
		{
			tmp_string = tmp_string.slice(0, i+1);
			break;
		}
	}

	return tmp_string;
}
