// $Id: main.js 468 2009-11-11 03:39:19Z jakub.boucek $
$(document).ready(function() {
  $('.deletelink').click(function() {
    if(this.title)
      return confirm("Opravdu chcete: " + this.title + "?");
    else
    return confirm("Opravdu chcete smazat tuto položku?");
  });
  
  $('.rollup').hide();
  
  $('a.rollup_header').click(function() {
    var content_name = this.id.replace(/^rollup_header_/, "rollup_content_");
    $('#' + content_name).slideToggle('slow');
  });
  
  $('#formpassword')
    .each(function() {
      try {
        if(this.value == this.defaultValue)
          //$(this).attr('type', 'text');
          var tmp_value = this.value;
          $(this).replaceWith($(this).wrap(document.createElement("span")).parent().html().replace(/type=\"?password\"?/, 'type="text"'));
          $('#formpassword').val(tmp_value).focus(function() {
            this.value = '';
            $(this).replaceWith($(this).wrap(document.createElement("span")).parent().html().replace(/type=\"?text\"?/, 'type="password"'));
            $('#formpassword').each(function() {
              this.style.color='black';
              this.focus();
              this.value='';
            });
          });
      }
      catch(err){}
    })
    
      
  $('#formlogin')
    .focus(function() {
      try {
        if(this.value == this.defaultValue) {
          this.value = '';
          this.style.color='black'
        }
      }
      catch(err){}
    });  
});

tinyMCE.init({
	mode : "exact",
  elements : "formcontent",
	theme : "advanced",
  language : "cs",
	theme_advanced_buttons1 : "bold,italic,formatselect,|,bullist,numlist,outdent,indent,|,undo,redo,cut,copy,paste,|,link,unlink,|,sub,sup,blockquote,charmap,|,code",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_blockformats : "p,h2,h3",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
  theme_advanced_resizing : true,
	theme_advanced_resize_horizontal : false,
	theme_advanced_path : false,
	entity_encoding : "raw",
  plugins : "advimage",
  valid_elements : "@[id|class|title],a[rel|rev|charset|hreflang|tabindex|accesskey|type|"
    + "name|href|title|class],strong/b,em/i,strike/u,"
    + "#p,-ol[type|compact],-ul[type|compact],-li,br,img[longdesc|usemap|"
    + "src|border|alt=|title|hspace|vspace|width|height|align],-sub,-sup,"
    + "-blockquote,-table[border=0|cellspacing|cellpadding|width|frame|rules|"
    + "height|align|summary|bgcolor|background|bordercolor],-tr[rowspan|width|"
    + "height|align|valign|bgcolor|background|bordercolor],tbody,thead,tfoot,"
    + "#td[colspan|rowspan|width|height|align|valign|bgcolor|background|bordercolor"
    + "|scope],#th[colspan|rowspan|width|height|align|valign|scope],caption,-div,"
    + "-span,-code,-pre,address,-h1,-h2,-h3,-h4,-h5,-h6,hr[size|noshade],dd,dl,dt,cite,abbr,acronym,del[datetime|cite],ins[datetime|cite],"
    + "object[classid|width|height|codebase|*],param[name|value|_value],embed[type|width"
    + "|height|src|*],script[src|type],map[name],area[shape|coords|href|alt|target],bdo,"
    + "button,col[align|char|charoff|span|valign|width],colgroup[align|char|charoff|span|"
    + "valign|width],dfn,fieldset,form[action|accept|accept-charset|enctype|method],"
    + "input[accept|alt|checked|disabled|maxlength|name|readonly|size|src|type|value],"
    + "kbd,label[for],legend,noscript,optgroup[label|disabled],option[disabled|label|selected|value],"
    + "q[cite],samp,select[disabled|multiple|name|size],small,"
    + "textarea[cols|rows|disabled|name|readonly],tt,var,big"
});

function toggleEditor() {
  var id = "formcontent";
  var elm = document.getElementById(id);
  if (tinyMCE.getInstanceById(id) == null)
    tinyMCE.execCommand("mceAddControl", false, id);
  else
    tinyMCE.execCommand("mceRemoveControl", false, id);
}

function newwin(url) {
  newwinobj = window.open(url, '');
  
  if(typeof newwinobj == 'object')
    return false;
  return true; 
}


//Nastavení stylopisu pro skrytí jshide polí

addStyleRule('.jsfakelink', 'text-decoration: underline; cursor: pointer;');
addStyleRule('.jsnolink', 'text-decoration: none; cursor: normal;');

function addStyleRule(selector, value) {
  //Vybere první stylopis. Nevím, jak se bude chovat při vypnutých stylech, ale kromě ošetření chyby to není třeba řešit :)
  var stylesht = document.styleSheets[0];
  
  var styleshts_lngt = (stylesht.cssRules?stylesht.cssRules.length:stylesht.rules.length);
  if (stylesht.insertRule) {
    stylesht.insertRule(selector + ' {' + value + '}', styleshts_lngt);
    return styleshts_lngt;
  } else if (stylesht.addRule) {
    stylesht.addRule(selector, value, styleshts_lngt);
    return styleshts_lngt;
  }
  return false;
}

function onloadHandler() {}