function showHideSearch() {
  if(!document.getElementById) return;
  var o = document.getElementById('languageBox');
  visibilityHidden(o);
  o = document.getElementById('searchBox');
  if(o.className.indexOf('hidden') != -1) {
    visibilityVisible(o);
    var ao = o.getElementsByTagName('INPUT');
    ao[0].focus();
  }
  else visibilityHidden(o);
  return;
}

function showHideLanguage() {
  if(!document.getElementById) return;
  var o = document.getElementById('searchBox');
  visibilityHidden(o);
  o = document.getElementById('languageBox');
  if(o.className.indexOf('hidden') != -1) visibilityVisible(o);
  else visibilityHidden(o);
  return;
}

function visibilityHidden(po) {
  po.className = po.className.replace(/visible/, 'hidden');
  return;
}

function visibilityVisible(po) {
  po.className = po.className.replace(/hidden/, 'visible');
  return;
}

function searchOver(po) {
  po.className = po.className.replace(/off/, 'on');
  return;
}

function searchOut(po) {
  po.className = po.className.replace(/on/, 'off');
  return;
}

function loadStyleCookie() {
  var mTemp = getStyleCookie();
  if(mTemp) { changeStyle(mTemp); }
  else { changeStyle('Kunsthalle 1'); }
  return;
}

function getStyleCookie() {
  if(!navigator.cookieEnabled || !document.cookie) return false;
  var sTemp = document.cookie;
  var aTemp = null;
  if(sTemp.indexOf(';') == -1) {
    aTemp = sTemp.match(/^as=(Kunsthalle\s[0-9])$/);
  }
  else {
    aTemp = sTemp.match(/as=(Kunsthalle\s[0-9]);/);
  }
  if(!aTemp) return false;
  return aTemp[1];
}

function setStyleCookie(ps) {
  if(!navigator.cookieEnabled) return;
  var oDate = new Date();
  var iTemp = oDate.getTime() + (90 * 24 * 60 * 60 * 1000);
  oDate.setTime(iTemp);
  document.cookie = 'as=' + ps + '; path=/; expires=' + oDate.toGMTString();
  return;
}

function changeStyle(ps) {
  if(!document.getElementsByTagName) return;
  var ao = document.getElementsByTagName('link');
  var iLength = ao.length;
  for(var i = 0; i < iLength; i++) {
    if(ao[i].rel.indexOf('stylesheet') != -1) {
      ao[i].disabled = true;
      if(ao[i].title == ps) {
        ao[i].disabled = false;
        if(arguments.length == 1) { setStyleCookie(ps); }
        else { window.scrollTo(0,0); }
      }
    }
  }
  return;
}

function showHideAddInfo(po) {
  if(!document.getElementById) return;
  if(po.blur && 
      (typeof(po.blur) == 'function' || typeof(po.blur) == 'object')) {
    po.blur();
  }
  var o = po.parentNode.parentNode;
  if(o.className.indexOf('Hidden') != -1) {
    o.className = o.className.replace(/Hidden/, 'Visible');
  }
  else {
    o.className = o.className.replace(/Visible/, 'Hidden');
  }
  if(navigator.userAgent.toLowerCase().indexOf(' msie ') != -1 && document.all){
    window.setTimeout("loadStyleCookie()", 0);
  }
  return;
}

loadStyleCookie();

/**
* Pops up a new window in the middle of the screen
*/
function popupWindow(mypage, myname, w, h, scroll) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
  win = window.open(mypage, myname, winprops)
  if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
