var timeouts = [];
function popup(url, name, height)
{
	if (!height)
		height = 635;
	if (!name)
		name = '_blank';
	var __popup = window.open(url, name, 'width=635,height=' + height + ',scrollbars=yes', true);
	__popup.focus();
}
function display_trace()
{
	var trace = document.getElementById('_trace');
	if (trace.style.display == 'none')
		trace.style.display = '';
	else
		trace.style.display = 'none';
}
function print_r(obj) 
{
	win_print_r = window.open('about:blank', 'win_print_r');
	win_print_r.document.write('<html><body>');
	r_print_r(obj, win_print_r);
	win_print_r.document.write('</body></html>');
}

function r_print_r(theObj, win_print_r) 
{
	if(theObj.constructor == Array || theObj.constructor == Object)
	{
		if (win_print_r == null)
			win_print_r = window.open('about:blank', 'win_print_r');
	}
	for(var p in theObj)
	{
		if(theObj[p].constructor == Array || theObj[p].constructor == Object)
		{
			win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
			win_print_r.document.write("<ul>")
			r_print_r(theObj[p], win_print_r);
			win_print_r.document.write("</ul>")
		} 
		else 
		{
			win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
		}
	}
	win_print_r.document.write("</ul>");
}

function urlencode(str)
{
	while (str.indexOf(' ') > -1)
		str = str.replace(' ', '+');
	str = escape(str);
	return str;
}

function onEnter(evt, id) 
{
	var keyCode = null;	
	if(evt.which) 
	{
		keyCode = evt.which;
	} 
	else if(evt.keyCode) 
	{
		keyCode = evt.keyCode;
	}
	if(13 == keyCode) 
	{
		document.getElementById(id).click();
		return false;
	}
	return true;
}

// jQuery
function scrollLeft(id)
{
	var scroller = document.getElementById(id);
	if (!scroller)
		return;
	var toScroll = scroller.scrollWidth - 280;
	var time = Math.round(toScroll/40) + 3;
	if (toScroll <= 0)
		return;
	$('#' + id).scrollTo(toScroll, time*1000, {axis:'x', onAfter:function(){setTimeout("scrollRight('" + id + "');", 500);}});
}

function scrollRight(id)
{
	var scroller = document.getElementById(id);
	if (!scroller)
		return;
	var toScroll = scroller.scrollWidth - 280;
	var time = Math.round(toScroll/40) + 3;
	if (toScroll <= 0)
		return;
	$('#' + id).scrollTo(0, time*1000, {axis:'x', onAfter:function(){setTimeout("scrollLeft('" + id + "');", 500);}});
}

function refreshContent(id, url, time)
{
	$('#' + id).load(url);
	timeouts[timeouts.length] = setTimeout("refreshContent('" + id + "', '" + url + "', " + time + ");", time);
}
function clearTimeouts()
{
	var len = timeouts.length;
	for (var i = 0; i < len; i++)
		clearTimeout(timeouts[i]);
	timeouts = [];
}