function openWindow(link) // inspired by porneL - http://pornel.net/pups/
{
  try
  {
    var new_window = window.open(link, '_blank');
    if(new_window) return false;
  }
  catch(e){}
  return true;
}

function checkRequiredFields(form_id)
{
  ok = true;
  fields = document.getElementsByTagName('input');
  for(var i in fields) if(fields[i].id && fields[i].className.match('required'))
  {
    if(fields[i].parentNode.parentNode.id==form_id && !fields[i].value) ok = false;
  }
  fields = document.getElementsByTagName('textarea');
  for(var i in fields) if(fields[i].id && fields[i].className.match('required'))
  {
    if(fields[i].parentNode.parentNode.id==form_id && !fields[i].value) ok = false;
  }
  if(ok) return true;
  alert('Musisz wypełnić wszystkie wymagane pola (oznaczone gwiazdką).');
  return false;
}

function addMenuHover()
{
  m = document.getElementsByTagName('li');
  for(var i in m) if(m[i].innerHTML && m[i].id && m[i].parentNode.id=='menu' && m[i].className.match('dropdown'))
  {
    m[i].onmouseover = function()
    {
      document.getElementById('s'+this.id).style.visibility = 'visible';
    }
    m[i].onmouseout = function()
    {
      document.getElementById('s'+this.id).style.visibility = 'hidden';
    }
  }
}

function fixMenuWidth()
{
  menu_width = 0;
  m = document.getElementsByTagName('li');
  for(var i in m) if(m[i].innerHTML && m[i].id && m[i].parentNode.id=='menu')
  {
    menu_width += m[i].offsetWidth;
  }
  document.getElementById('menu').style.width = menu_width;
}

onload = function()
{
  m = document.getElementsByTagName('li');
  for(var i in m) if(m[i].innerHTML && m[i].id && m[i].className.match('dropdown'))
  {
    sm = document.getElementsByTagName('li');
    max_width = 0;
    for(var j in sm) if(sm[j].innerHTML && !sm[j].id && sm[j].parentNode.parentNode.id==m[i].id)
    {
      if(sm[j].firstChild.firstChild.offsetWidth>max_width) max_width = sm[j].firstChild.firstChild.offsetWidth;
    }
    if(max_width<m[i].firstChild.firstChild.offsetWidth) document.getElementById('s'+m[i].id).style.width = m[i].clientWidth + 'px';
    else
    {
      if(m[i].className.match('first') || m[i].className.match('last')) max_width += 30;
      else max_width += 40;
      document.getElementById('s'+m[i].id).style.width = max_width + 'px';
    }
  }

}

