function getElementsByClass(searchClass,node,tag)
{
    var classElements = new Array();

    if ( node == null )
        node = document;
    if ( tag == null )
        tag = '*';

    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++)
    {
        if ( pattern.test(els[i].className) )
        {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
} 
function print_this(num) 
{
    arr_class = new Array();
    arr_class = getElementsByClass('print_section');
    for(i=0; i<arr_class.length; i++)
    {
        if(arr_class[i].id != ('c' + num + '_section'))
        {
            arr_class[i].className = arr_class[i].className.replace("print_section", "no_print");
        }
    }
    window.print();
    for(i=0; i<arr_class.length; i++)
    {
        arr_class[i].className = arr_class[i].className.replace("no_print", "print_section");
    }
}
function popup(url,id,width,height) 
{
    pos_horizon = ((screen.width/2)-(width/2));
    pos_vertical = ((screen.height/2)-(height/2));
    var popup_win = window.open(url,id,'width='+width+',height='+height+',left='+pos_horizon+',top='+pos_vertical+',resizable=yes,scrollbars=yes,menubar=no,status=no');
}
function change_class(idTag) 
{
    if (document.getElementById(idTag).className == 'hidden')
    {
        document.getElementById(idTag).className = '';
        document.getElementById(idTag + '_toggle').innerHTML = 'Luk';
    }
    else
    {
        document.getElementById(idTag).className = 'hidden';
        document.getElementById(idTag + '_toggle').innerHTML = '&Aring;ben';
    }
}
function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}
}

/**
* Setting .mac class on bodytag if on mac
* - We can then use the .mac selector in CSS to make speciel mac exceptions...
* 
* @param none
* @return Void
*/
function prepare_for_mac()
{
	if(navigator.platform.indexOf("Mac") != -1 || navigator.userAgent.indexOf("Safari") != -1)
	{
		document.body.className = ( navigator.userAgent.indexOf("Safari") != -1 ? 'mac safari' : 'mac firefox' );
	}
}

function set_heights()
{
	if(document.getElementById('middle') && document.getElementById('left') && document.getElementById('right'))
	{
		var height = Math.max(document.getElementById('left').offsetHeight,document.getElementById('middle').offsetHeight,document.getElementById('right').offsetHeight);
		document.getElementById('left').style.height	= height + 'px';
		document.getElementById('middle').style.height	= height + 'px';
		document.getElementById('right').style.height	= height + 'px';
	}
}
function reset_heights()
{
	document.getElementById('left').style.height	= 'auto';
	document.getElementById('middle').style.height	= 'auto';
	document.getElementById('right').style.height	= 'auto';
}
function show_abstract(el_id)
{
	if(document.getElementById(el_id))
	{
		reset_heights();
		document.getElementById(el_id).style.display	= ( document.getElementById(el_id).style.display == 'none' ? 'block' : 'none' );
		set_heights();
	}
}

// Adding onLoad events
addLoadEvent(prepare_for_mac);
addLoadEvent(set_heights);