// If user agent understands DOM, call site functions
if (document.getElementById && document.createTextNode)
{addLoadEvent(unobtrusive_links);}


/**
* By Simon Willison @ http://simonwillison.net/2004/May/26/addLoadEvent/
*/
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{oldonload();}
			func();
		}
	}
}


/**
* Add JavaScript functionality to all a tags.
* Functionality depends on the class name
*/
function unobtrusive_links()
{
	var as, i;
	as = document.getElementsByTagName('a');
	for (i = 0; i < as.length; i++)
	{
		if (/ujs_popup/.test(as[i].className)) // Pop up
		{
			as[i].onclick = function() { return popup(this); }
			// as[i].onkeypress = function() { return popup(this) }
		}
		else if (/ujs_out_of_use/.test(as[i].className)) // Out of use
		{
			as[i].onclick = function() { alert('Tämä ominaisuus ei ole vielä käytössä.'); return false; }
		}
	}
}


function include_js(filename)
{
	document.write('<script type="text/javascript" src="' + filename + '"></script>');
}

function popup(o, style)
{
	var address = o.href;
	var position_left = 0;
	var position_top = 0;
	var menubar = 0;
	var toolbar = 0;
	var location = 0;
	var scrollbars = 0;
	var resizable = 1;
	var status = 0;
	
	if (style == 'panorama')
	{
		var width = 600;
		var height = 400;
		var scrollbars = 1;
	}
	
	if ((position_left + width) >= screen.width)
	{
		width = (screen.width - 50);
	}
	
	if ((position_top + height) >= screen.height)
	{
		height = (screen.height - 75);
	}
	
	var settings = "width=" + width + ",height=" + height + ",left=" + position_left + ",top=" + position_top + ",toolbar=" + toolbar + ",menubar=" + menubar + ",location=" + location + ",status=" + status + ",resizable=" + resizable + ",scrollbars=" + scrollbars;
	
	window.open(address, style, settings);
}