function gl(o){var x=o.offsetLeft;if(o.offsetParent!=null)x+=gl(o.offsetParent);return x}
function gt(o){var y=o.offsetTop;if(o.offsetParent!=null)y+=gt(o.offsetParent);return y}

function ClearDefault(obj)
{
    if (!obj.getAttribute('cleared'))
    {
        obj.setAttribute('cleared', 1)
        obj.style.color = '#eee'
        obj.value = ''
    }
}

function email(prefix)
{
	location.href = 'mailto:' + prefix + '@theory11.com'
}

function ValidateLength(id, name, minlen, maxlen, errortarget)
{
	elem = $(id)
	if (elem)
	{
		len = elem.value.length
		if (len >= minlen && len <= maxlen) {
			return true
		}
		SubmitError(name + ' must be between ' + minlen + ' and ' + maxlen + ' characters long.', errortarget)
	}
	else
	{
		//alert('Couldn\'t find ' + name)
	}
	return false
}

function AddToFavorites(id)
{
	$('addToFaves').style.display = 'none'
	$('addingToFaves').style.display = 'inline'
/*
	$.get('/add_favorite', {
			js: 1,
			id: id
		}, function() {
			$('addingToFaves').style.display = 'none'
			$('removeFromFaves').style.display = 'inline'
		}
	);
	*/
	new Ajax.Request(
		'/add_favorite',
		{
			asynchronous: true,
			onSuccess:function(transport) {
				$('addingToFaves').style.display = 'none'
				$('removeFromFaves').style.display = 'inline'
			},
			parameters: 'js=1&id=' + id
		}
	);

	return false;
}

function RemoveFromFavorites(id)
{
	$('removeFromFaves').style.display = 'none'
	$('removingFromFaves').style.display = 'inline'
/*
	$.get('/remove_favorite', {
			js: 1,
			id: id
		}, function() {
			$('removingFromFaves').style.display = 'none';
			$('addToFaves').style.display = 'inline';
		}
	);
	*/
	new Ajax.Request(
		'/remove_favorite',
		{
			asynchronous: true,
			onSuccess:function(transport) {
				$('removingFromFaves').style.display = 'none';
				$('addToFaves').style.display = 'inline';
			},
			parameters: 'js=1&id=' + id
		}
	);

	return false;
}

function hotify(obj)
{
	obj.src = obj.src.replace(/\.gif/i, '_hot.gif')
	obj.onmouseout = function() {
		this.src = this.src.replace(/_hot\.gif/i, '.gif')
	}
}

var _onloadfuncs = [];
function AddOnLoadFunction(func)
{
    _onloadfuncs.push(func);
}
window.onload = function()
{
    for (var i = 0; i < _onloadfuncs.length; ++i)
    {
        (_onloadfuncs[i])();
    }
}