function confirm_url(msg, url)
{
  if (confirm(msg)) document.location.href = url;
}

//****************************************************************************

function selection_value(sel_id)
{
  sel = getElement(sel_id);
  return sel.options[sel.selectedIndex].value;
}

//****************************************************************************

function load_ajax_content(url, target)
{
  d = doSimpleXMLHttpRequest(url);
  d.addCallback(function (req) {
    getElement(target).innerHTML = req.responseText;
  });
}

//****************************************************************************

function toggle_proposals_preview(shell, container, url)
{
  if (hasElementClass(shell, "invisible") && hasElementClass(shell, "no-content"))
  {
    load_ajax_content(url, container)
    removeElementClass(shell, "no-content"); // avoid further loading
  }
  toggleElementClass("invisible", shell);
}

//****************************************************************************

function autoredirect(anchor)
{
  if (!autoredirect_enabled) return;
  href = getElement(anchor);
  addLoadEvent(function(){
    window.setTimeout(function(){
      document.location.href = href;
    }, 800);
  });
}

//****************************************************************************

/// Hide the save button, replace elm with a "wait" image
/// and submit the form.
function submit_form_and_wait(form, elm_to_hide, waiting_img)
{
  swapDOM(elm_to_hide, waiting_img);
  getElement(form).submit();
}

//****************************************************************************
// attributes grid
//****************************************************************************

var attribute_grids = {};

function AttributesGrid(container_id, loader_html)
{
  this.container = getElement(container_id);
  this.loader_html = loader_html;

  this.show_loader = function () 
  {
    this.container.innerHTML = this.loader_html;
  }
  this.load = function (url)
  {
    this.show_loader();
    grid = this;
    if (arguments.length > 1)
      params = arguments[1];
    else
      params = {}
    var d = doSimpleXMLHttpRequest(url, params);
    d.addCallback(function (req) {
      grid.container.innerHTML = req.responseText;
    });
  }

  attribute_grids[container_id] = this;
}

//****************************************************************************
// tabs
//****************************************************************************

tabs = {};

function tabs_register(tabs_name, tab_id, body_id)
{
  if (!(tabs_name in tabs)) tabs[tabs_name] = new Array();
  tabs[tabs_name].push({
      tab_id: tab_id,
      body_id: body_id
    });
}

function tabs_activate(tabs_name, tab_id)
{
  tbs = tabs[tabs_name];
  for(i = 0; i < tbs.length; i++)
  {
    tab = tbs[i];
    div_tab = getElement(tab.tab_id)
    if (tab.tab_id == tab_id)
    {
      div_tab.className = "active";
      showElement(tab.body_id);
    } else {
      div_tab.className = "";
      hideElement(tab.body_id);
    }
  }
}

//****************************************************************************
// TinyMCE
//****************************************************************************

function setup_tinymce()
{
  if (!need_wysiwyg_editor) return;
  tinyMCE.init({
    editor_selector : "mceEditor",
    theme: "advanced",
    mode : "textareas",
    plugins: "contextmenu,insertdatetime,layer,paste,searchreplace,table,style,nonbreaking,visualchars,fullscreen,advlink,advimage,autonbsp",
    theme_advanced_buttons1: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,undo,redo,|,link,unlink,anchor,image,|,insertdate,inserttime,charmap,nonbreaking,autonbsp,visualchars",
    theme_advanced_buttons2: "bold,italic,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,styleselect,|,bullist,numlist,|,sub,sup,|,outdent,indent",
    theme_advanced_buttons3 : "code,removeformat,cleanup,|,tablecontrols,|,fullscreen",
    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "none",
    theme_advanced_resizing: true,
    theme_advanced_resize_horizontal: false,
    theme_advanced_resizing_use_cookie : false,
    theme_advanced_path : true,
    theme_advanced_fonts : "Arial=sans-serif;Times=Times New Roman, Times, serif;Courier=courier new,courier,monospace",
    theme_advanced_blockformats: "p,h1,h2,h3",
    theme_advanced_styles: "",
    content_css : rel_root + "css/main.css",
    plugin_insertdate_dateFormat : "%d.%m.%Y",
    plugin_insertdate_timeFormat : "%H:%M:%S",
    language : "cs",

    accessibility_warnings : false,
    convert_fonts_to_spans: true,
    entities: "160,nbsp,38,amp,34,quot,60,lt,62,gt",
    entity_encoding: "named",
    convert_urls: false,
    verify_html: false,
    apply_source_formatting : true,
    cleanup_on_startup : true,
    invalid_elements : "",

    auto_reset_designmode: true
  });
}

//****************************************************************************
//****************************************************************************

setup_tinymce();

