function selectMenu(value)
{
  if (value)
  {
    document.cookie = 'menu=' + value;
  }
  return true;
}

function popup(url, id, w, h, scroll, resize, menubar, titlebar, status, location, toolbar, dir)
{
  // http://www.w3schools.com/htmldom/met_win_open.asp
  var win = window.open(url, id, 'toolbar='+toolbar+', titlebar='+titlebar+', menubar='+menubar+', location='+location+', directories='+dir+', status='+status+', width='+w+', height='+h+', scrollbars='+scroll+', resizable='+resize+'', false);
  win.focus();
}

window.default_on_submit = function(event)
{
  frm = event.srcElement ? event.srcElement : event.target;
  btnValue = frm.submit_button_value ? frm.submit_button_value.value : '';

  elems = document.getElementsByTagName('INPUT');
  for (i = 0; i < elems.length; i++)
  {
    el = elems[i];
    if (el.type == 'submit' || el.type == 'button')
    {
      el.style.color = 'silver';
      el.disabled = true;
    }
  }
}

window.default_on_click = function(event, ask_confirmation)
{
  if (ask_confirmation)
  {
    if(!confirm('Vajuta OK nġustumiseks')) return false;
  }

  btn = window.event ? window.event.srcElement : event.target;
  if (btn && btn.form)
  {
    el = btn.form.submit_button_value;
    el.name = btn.name;
    el.value = btn.value;
  }
  return true;
}

window.buttonConfirm = function(text)
{
  text = text ? text : 'Vajuta OK nġustumiseks';
  if(!confirm(text)) return false;
}

function saada(name, domain, end)
{
  window.location = "mailto:" + name + "@" + domain + "." + end;
}

function addParentSelect(selectid, value, text, select)
{
  var s = window.opener.$(selectid);
  var y = document.createElement('option');
  y.text = text;
  y.value = value;
  y.selected = select;
  s.add(y, null);
  window.opener.focus()
  window.close();
}
/**
* Check listmanager fields
*/
function checkLMfields()
{
  var val = $('action').value;
  $('people').disabled = $('email').disabled = $('comment').disabled = $('freetext').disabled = '';
  if (val == '')
  {
    $('people').disabled = $('email').disabled = $('comment').disabled = true;
  }
  else if (val == 'review')
  {
    $('people').disabled = $('email').disabled = $('comment').disabled = $('freetext').disabled = true;
  }
  else if (val == 'del')
  {
    $('people').disabled = $('comment').disabled = $('freetext').disabled = true;
  }
  else if (val == 'add')
  {
    $('freetext').disabled = true;
  }
}

function toggleEventEnddate()
{
  $('end[y]').disabled = $('end[m]').disabled = $('end[d]').disabled = !$('hasenddate').checked;
}

function startUpdater(content, sleep)
{
  sleep = sleep ? sleep : 10;
  setTimeout("new Ajax.PeriodicalUpdater('"+content+"', 'index.php?ajaxrequest=1&content="+content+"',{encoding:'iso-8859-1',method:'get',frequency:"+sleep+",decay:1});", sleep*1000);
}

function updateDiv(content)
{
  new Ajax.Request('index.php', {
    parameters: {
      'ajaxrequest': 1,
      'content': content
    },
    onSuccess: function(transport)
    {
      $(content).update(transport.responseText);
    }
  });
}
