var currentLang = 'no';
var system = { lang: 'no' };

function openTree(id)
{
  el = document.getElementById(id);
  if (el != null)
  {
    if (el.style.display == 'block')
      el.style.display = 'none';
    else
      el.style.display = 'block';
  }
}

function toggleMarker(el)
{
  if (el.src.indexOf('plus.gif') != -1)
    el.src = '/grf/gray_minus.gif';
  else
    el.src = '/grf/gray_plus.gif';
}

function displayPopup()
{
  el = document.getElementById('popup');
  if (el != null)
  {
    el.style.display = 'block';
  }
}

function closePopup()
{
  el = document.getElementById('popup');
  if (el != null)
  {
    el.style.display = 'none';
  }
}

function clearSearchCookies()
{
  // clear cookies
  cs_setCookie('sted_0', '');
  cs_setCookie('sted_1', '');
  cs_setCookie('kateg_0', '');
  cs_setCookie('kateg_1', '');

  // clear the search field
  el = document.getElementsByName('searchLawyer');
  if (el != null)
    el[0].value = '';

  // clear subcategories
  el = document.getElementsByName('underkat');
  if (el != null)
    el[0].innerHTML = '';
  el = document.getElementsByName('kommune');
  if (el != null)
    el[0].innerHTML = '';
}

function prepareSearchCookies(fylke, kommune, kategori)
{
  cs_setCookie('sted_0', '[],' + fylke + ',');
  cs_setCookie('sted_1', '[' + fylke + '],' + kommune + ',');
  if (kategori != null)
  {
    cs_setCookie('kateg_0', '[],' + kategori + ',');
  }
}

function open_win(id)
{
  dest = document.getElementById('popup');
  if (dest != null)
  {
    src = document.getElementById('win_' + id);
    if (src != null)
    {
      dest.innerHTML = src.innerHTML;
      dest.style.display = 'block';
    }
  }

  return false;
}

function open_newWin(url, width, height)
{
  if (width == null)
    width = 800;
  if (height == null)
    height = 500;

  var myWindow = window.open(url,'','scrollbars=yes,menubar=no,height=' + height + ',width=' + width + ',resizable=yes,toolbar=no,location=no,status=no');
}

function evaluateForm(button)
{
  var title = document.getElementById('title');
  var question = document.getElementById('question');
  var name = document.getElementById('name');
  var email = document.getElementById('email');
  var txt = ''
  if (title && question && name && email)
  {
    txt = title.value
    txt = txt.replace(/ /, "")
    if (txt == '' || question.value == '' || name.value == '' || email.value == '')
    {
      alert("Du må fylle ut alle feltene før du kan sende spørsmålet.");
      return false;
    }

    if (button.style.visibility == 'hidden')
      return false;

    button.style.visibility = 'hidden';
    return true;
  }

  return false; 
}



var OA_channel = 'bg/test/preview';


var OA_p=location.protocol=='https:'?'https:':'http:';
var OA_r=Math.floor(Math.random()*99999999);
if (!document.OA_used) document.OA_used = ',';
function OA_adjs(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//openx.advokatforeningen.kunder.linpro.no/www/delivery/ajs.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    az+="&mmm_fo="+(document.mmm_fo)?'1':'0';
    if (document.context) az+= "&context=" + escape(document.context);
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}
function OA_adpop(z,n)
{
  if (z>-1) {
    var az="<"+"script language='JavaScript' type='text/javascript' ";
    az+="src='"+OA_p+"//openx.advokatforeningen.kunder.linpro.no/www/delivery/apu.php?n="+n+"&zoneid="+z;
    az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
    if (window.location) az+="&loc="+escape(window.location);
    if (document.referrer) az+="&referer="+escape(document.referrer);
    az+="'><"+"/script>";
    document.write(az);
  }
}

function twitter_click()
{
  u=location.href;
  t=document.title;
  window.open('http://twitter.com/home/?status='+encodeURIComponent(t)+'%20'+encodeURIComponent(u),'sharer','toolbar=0,status=0,width=626,height=436');
  return false;
}
