function doPopups() {
  if (!document.getElementsByTagName) return false;
  var links=document.getElementsByTagName("a");
  for (var i=0; i < links.length; i++) {
    if (links[i].className.match("popup")) {
      links[i].onclick=function() {
      // Next two lines should be on one line
        window.open(this.href, "",
          "top=40,left=40,width=500,height=500");
        return false;
      }
    }
  }
}
window.onload=doPopups;

function show(element)
{
	if (document.getElementById)
	{
		document.getElementById(element).style.display = 'block';
	}
}


function hide_element(element)
{
	if (document.getElementById)
	{
		document.getElementById(element).style.display = 'none';
	}
}


function hide_elements(element)
{
	for (var i = 0; i < element.length; i++)
	{
		hide_element(element[i]);
	}
}


function toggle_visibility(element_to_use)
{
	if (document.getElementById)
	{
		var element = document.getElementById(element_to_use);
		
		if (element.style.display == 'none')
		{
			element.style.display = 'block';
		}
		else
		{
			element.style.display = 'none';
		}
	}
}


function prepareGallery(){
  if( document.getElementById &&
      document.getElementsByTagName ){
    if( document.getElementById( 'popus' ) ){
      var gallery = document.getElementById( 'popus' );
      var links = gallery.getElementsByTagName( 'a' );
      for( var i=0; i < links.length; i++ ){
        links[i].onclick = function(){
          return popupgallery(this);
        };
      }
    }
  }
}


function popupgallery(osoite)
{
	var nimi = 'teloitus';
	var settings = "width=500,height=450"
	+ ",left=" + position_left + ",top=" + position_top
	+ ",toolbar=0,menubar=0,location=" + location
	+ ",status=0,resizable=" + resizable + ",scrollbars=" + scrollbars;
	window.open(osoite,nimi,settings)
}

function popup(page, name, style, width, height)
{
	var position_left = 0;
	var position_top = 0;
	var location = 0;
	var scrollbars = 0;
	var resizable = 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=0,menubar=0,location=" + location
	+ ",status=0,resizable=" + resizable + ",scrollbars=" + scrollbars;
	
	window.open(page,name,settings);
}