function getOffsetfunction(obj, bool)
{
	var total = 0;

	while (obj != null)
	{
		total += obj['offset' + (bool ? 'Left':'Top')];

		obj = obj.offsetParent;
	}

	return total;
}

function trim(str)
{
	if (str == null)
		return str;

	return str.replace(/^\s*|\s*$/g,"");
}

function isInteger(id, need_alert, default_value)
{
	str = trim(document.getElementById(id).value);
	isNotNum = str.match(/[^0-9]/g);

	if (isNotNum)
	{
		if (need_alert)
		{
			alert("You must enter a number.");
			document.getElementById(id).focus();
		}

		document.getElementById(id).value = default_value;

		return false;
	}

	return true;
}

function formatCurrency(num, digits_to_add_comma, dp) 
{
	if (dp == null)
		dp = 0;

	num = num.toString().replace(/\$|\,/g, '');

	if (isNaN(num))
		num = "0";

	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * Math.pow(10, dp) + 0.50000000001);

	cents = num % Math.pow(10, dp);

	for (var i = 1; i <= (dp - 1); i++)
	{
		if (cents < Math.pow(10, i))
		{
			cents = '0' + cents;
		}
	}

	num = Math.floor(num / Math.pow(10, dp)).toString();

	for (var i = 0; i < Math.floor((num.length - (1 + i)) / digits_to_add_comma); i++)
		num = num.substring(0, num.length - ((digits_to_add_comma + 1) * i + digits_to_add_comma)) + ',' + 
			num.substring(num.length - ((digits_to_add_comma + 1) * i + digits_to_add_comma));

	if (dp == 0)
		return (((sign) ? '' : '-') + num);
	else if (dp > 0)
		return (((sign) ? '' : '-') + num + '.' + cents);
}

function observe(el, event, func)
{
	try
	{
		el.addEventListener(event, func, false);
	}
	catch (e)
	{
		try 
		{
			el.detachEvent('on'+ event, func);
			el.attachEvent('on'+ event, func);
		}
		catch (e)
		{
			el['on'+ event] = func;
		}
	} 
}


function getPageSize()
{
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function resize()
{
	var menuTdWidth = 151;
	var contentTdWidth = 789;

	var page = getPageSize();

	if ((!document.all || window.opera) && page[1] != page[3])
		page[2] -= 18;

	var width = (page[2] - contentTdWidth - menuTdWidth) / 2;
	
	if (page[2] < menuTdWidth + contentTdWidth + 2)
		document.getElementById('main_table').width = menuTdWidth + contentTdWidth + 2;
	else
		document.getElementById('main_table').width = page[2];
	
	if (width >= 1)
	{
		document.getElementById('right_td').width = width;
		document.getElementById('left_td').width = width;
	}
	else 
	{
		document.getElementById('right_td').width = 1; // ie cant set width to 0
		document.getElementById('left_td').width = 1;
	}
	
	//document.getElementById('menu_div').style.left = (parseInt(getOffsetfunction(document.getElementById('menu_td'), true)) + parseInt(document.getElementById('menu_td').width - menuTdWidth)) + 'px';
	
	if (document.getElementById('main_gif'))
	{
		document.getElementById('main_gif').style.left = (parseInt(getOffsetfunction(document.getElementById('menu_td'), true)) + parseInt(document.getElementById('menu_td').width)) + 0 + 'px';
	}
}
