function changeLayer(layer_id)
{
  var field_1 = document.getElementById('main_1');
  if(field_1 == null)
    return;
  var field_2 = document.getElementById('main_2');
  if(field_2 == null)
    return;
  var field_3 = document.getElementById('main_3');
  if(field_3 == null)
    return;
  if (layer_id == 1)
  {
    field_1.style.display = 'inline';
    field_2.style.display = 'none';
    field_3.style.display = 'none';
  }
  else if (layer_id == 2)
  {
    field_1.style.display = 'none';
    field_2.style.display = 'inline';
    field_3.style.display = 'none';
  }
  else if (layer_id == 3)
  {
    field_1.style.display = 'none';
    field_2.style.display = 'none';
    field_3.style.display = 'inline';
  }
}


function replace(url)
{
  window.location.replace(url);
}


function closeWindow()
{
  window.close();
}


function closeWindowAndReloadOpener()
{
  window.opener.location.reload();
  window.close();
}


function closeWindowAndReplaceOpener(url)
{
  window.opener.location.replace(url);
  window.close();
}


function dialogWindow(url, width, height)
{
  var options = "directories=no";
  options += ",menubar=no";
  options += ",toolbar=no";
  options += ",location=no";
  options += ",status=no";
  options += ",scrollbars=no";
  options += ",resizable=no";
  options += ",width=" + width;
  options += ",height=" + height;

  var url_has_attributes = false;
  for (i = 0; i < url.length; i++)
  {
    if (url.charAt(i) == '?')
    {
      url_has_attributes = true;
      break;
    }
  }


  if (url_has_attributes)
    url = url + '&width=' + width + '&height=' + height;
  else
    url = url + '?width=' + width + '&height=' + height;

  w = window.open(url, '', options);
  w.focus();
}


function helpWindow(url)
{
  var options = "directories=no";
  options += ", menubar=no";
  options += ", toolbar=no";
  options += ", location=no";
  options += ", status=no";
  options += ", scrollbars=yes";
  options += ", resizable=yes";


  w = window.open(url, '', options);
  w.focus();
}


function confirmDialog(ptx_path, title, message, action_script, action_script_args, access_key)
{
  // Pruefung ob der Dialog ein Javascript als Zielaufruf hat
  if (action_script.substring(0, 11) != 'Javascript:' && action_script.substring(0, 11) != 'JavaScript:')
     // .... ansonsten relativen Pfad hinzufuegen
     action_script = './../../' + action_script;

  //hardcodiert
  var url = ptx_path + 'admin/dialog/dialog.confirm.php' +
            '?title=' + title +
            '&message=' + message +
            '&action_script=' + action_script +
            '&action_script_args=' + action_script_args +
            '&access_key=' + access_key;

  dialogWindow(url, 380, 200);
}



function nameInputDialog(ptx_path, title, label, action_script, action_script_args, access_key)
{
  var url = ptx_path + 'admin/dialog/dialog.name_input.php' +
            '?title=' + title +
            '&label=' + label +
            '&action_script=../../../' + ptx_path + action_script +
//          '&action_script=' + action_script +
            '&action_script_args=' + action_script_args +
            '&access_key=' + access_key;

  dialogWindow(url, 380, 200);
}
