var popupWin;

function openPopup(url, width, height) {
    if (popupWin) {
       popupWin.close();
    }

    var options = 'toolbar=no,location=no,directories=no,status=no,'
    options += 'menubar=no,scrollbars=no,resizable=no,dependent=1,'
    options += 'width='+width+',height='+height;

    popupWin = window.open(url,'popupWin',options);

    return false;
}
function openAndResizePopup(url, width, height) {
    openPopup(url, width, height);
    window.setTimeout('setDimensions()', 50);
    return false;
}
function modelPic(url) {
    return openAndResizePopup(url,540,540);
}

function setDimensions() {
  if (!popupWin || !popupWin.document || !popupWin.document.body.firstChild) {
    window.setTimeout('setDimensions()', 50);
    return;
  }
  var w = popupWin.document.body.firstChild.width + 30;
  var h = popupWin.document.body.firstChild.height + 70;
  if (w && h) {
    popupWin.window.resizeTo(w,h);
  }
}

function hideEmail (name, domain) {
  var addr = name + "@" + domain;
  document.write("<a href=mailto:"+addr+"><font class=\"titleorimageid1siteid33\">"+addr+"</font></a>");
}
function checkAndSubmit(formId, selectElem) {
  var form = document.getElementById(formId);
  if (selectElem.options[selectElem.selectedIndex].value.length > 0) {
    form.submit();
  }
}

var redirect = false;
function languages() {

    if (!redirect) {
        var path = window.location.pathname;

        var params = '';
        var q = window.location.href.indexOf('?');
        if (q != -1) {
            params = window.location.href.substring(q);
        }

        redirect = path + params;
    }

    var sfFlag = document.getElementById('sf');
    var sFlag = document.getElementById('s');
    if (sfFlag) {
      sfFlag.setAttribute('href', '/portal/page/portal/lang-fi' + redirect);
    }
    if (sFlag) {
      sFlag.setAttribute('href', '/portal/page/portal/lang-sv' + redirect);
    }

    if (mode == window.location.href && document.getElementById('langselect')) {
     document.getElementById('langselect').style.top = '17px';
    }
}
function kerroKaverille(url, title) {
window.open('http://www.kastelli.fi/kastelli/kerrokaverille?url='+escape(url)+'&title='+escape(title),'kerro_kaverille','toolbar=1,location=0,scrolling=1,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,copyhistory=0,width=670,height=500');
}