/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="http://dataplan.info/img/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

function expandDiv(id, hide_id) {
  var id_displayed = getDisplayValue(id);
  displayDiv(id, (id_displayed == 'none'));
  displayDiv(hide_id, (id_displayed != 'none'));
}

function displayDiv(id, show) {
  var divtag=document.all? document.all[id] : document.getElementById? document.getElementById(id) : ""
  if (divtag && (ns6||ie)) {
    divtag.style.display = (show ? "block" : 'none')
  }
}

function getDisplayValue(id) {
  var divtag=document.all? document.all[id] : document.getElementById? document.getElementById(id) : ""
  return divtag.style.display;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)  (* for all)
//  c - class name                             (* for all)
//  p - CSS property
//  v - value
function setStyleByClass(t,c,p,v){
    var elements;
    if(t == '*') {
        // '*' not supported by IE/Win 5.5 and below
        elements = (ie) ? document.all : document.getElementsByTagName('*');
    } else {
        elements = document.getElementsByTagName(t);
    }
    for(var i = 0; i < elements.length; i++){
        var node = elements.item(i);
        if(c=='*') {
            eval('node.style.' + p + " = '" +v + "'");
        } else {
            var classes = new Array();
            for(var j = 0; j < node.attributes.length; j++) {
                if(node.attributes.item(j).nodeName == 'class') {
                    classes = node.attributes.item(j).nodeValue.split(' ');
                    for (var k = 0; k < classes.length; k++ ) {
                         if (classes[k] == c) {
                             eval('node.style.' + p + " = '" +v + "'");
                         }
                    }
                }
            }
        }
    }
}

// volat jako onclick="set4Priorities(this.checked)"
function set4Priorities(priority_hide) {
    setStyleByClass("div","zamer","display", priority_hide ? "none" : "block");
    //setStyleByClass("div","hide","display", priority_hide ? "none" : "block");
    setStyleByClass("hr","bold","display", priority_hide ? "none" : "block");
    setStyleByClass("h3","hide","display", priority_hide ? "none" : "block");
    setStyleByClass("div","namet","display", priority_hide ? "none" : "block");
    setStyleByClass("div","namet","display", priority_hide ? "none" : "block");
    setStyleByClass("dt","hide","display", priority_hide ? "none" : "block");
    setStyleByClass("dd","hide","display", priority_hide ? "none" : "block");
    setStyleByClass("div","namet","display", priority_hide ? "none" : "block");
//    setStyleByClass("div","zamer","display", show ? "none" : "block"); // atd.
}

function porovnejm(selboxname) {
    var idx;
    idx = eval('document.f.'+selboxname).selectedIndex
    if ( idx < 0 ) {
        return false;
    }
    document.f.m.value = eval('document.f.'+selboxname).options[idx].value;
    document.f.submit();
}

document.onmousemove=positiontip

// if user is logged it adds "Edit" lins to all headlines, which represent AA items
function addAALinks() {
    if ( typeof addAALinks.shown == 'undefined' ) {
        addAALinks.shown = true;
        //var loaderdiv = '<div id="absoluteloader" style="position:absolute;left:0px;top:0px;">'+ AA_Config.loader +'</div>';
        //$$('body').each(function(element) { element.insert(loaderdiv); });
        $$('*[data-aa-id]').each(function(element) {
            var edittag = '<a href="https://dataplan.info/aaa/admin/itemedit.php3?edit=1&id='+element.readAttribute('data-aa-id')+'" class="toolkitka" target="_blank"><img src="/aaa/images/toolkit.gif" width="8" height="8" border="0" title="Editovat v Toolkitu" alt="Editovat v Toolkitu"></a>';
            if (element.up('a') == undefined) {
                element.insert({before: edittag});
            } else {
                element.up('a').up().insert({before: edittag});
            }
        });
//        $('absoluteloader').hide();
    } else {
        $$('a.toolkitka').invoke('toggle');
    }
}

// gallery
function photo_update(thumb_id, photo_div, viewid, sitemid, galeryid) {
    $(photo_div).show();
    url = '/aaa/view.php3?vid=' + viewid + '&cmd[' + viewid + ']=x-' + viewid + '-' + sitemid + '&convertfrom=windows-1250&als[GALERYID]=' + galeryid;
    new Ajax.Updater(photo_div, url);
    $$('div.switcher img.active').invoke('removeClassName', 'active');
    $(thumb_id).addClassName('active');
}

function Nszm_Trashit_Plan(item_id,slice_id) {
//    DisplayAaResponse(div_id, 'Nszm_Trashit', {id:item_id});
//    new Ajax.Updater(div_id, AA_Config.AA_INSTAL_PATH + 'central/responder.php?AA_Sess=215978b6eb9cd9940e7d13169cd0040a&command=Nszm_Trashit', {parameters: {id:item_id}});

    if (!confirm("Chystáte se smazat záznam včetně nižších úrovní. Jedná se o nevratnou operaci. Opravdu chcete smazat tento záznam?")) {
        return;
    }

    if ($('tree'+item_id) != undefined) {
        $('tree'+item_id).update(AA_Config.loader);
    }

    var params = eval('({inline: 1, slice_id: "'+ slice_id+'", "aa[u' +item_id+ '][status_code_____][]": 3})');
    new Ajax.Request(AA_Config.AA_INSTAL_PATH + '/filler.php3', {
        parameters: params,
        onSuccess: function(transport) {
            if ($('tree'+item_id) != undefined) {
                AA_Refresh($('tree'+item_id).up('div[id^=tree]'),false,InitPlan);
            }
        }
    });
}

function Nszm_Trashit(item_id,slice_id) {

    if (!confirm("Chystáte se smazat záznam. Jedná se o nevratnou operaci. Opravdu jej chcete smazat?")) {
        return;
    }

    var params = eval('({inline: 1, slice_id: "'+ slice_id+'", "aa[u' +item_id+ '][status_code_____][]": 3})');
    new Ajax.Request(AA_Config.AA_INSTAL_PATH + '/filler.php3', {
        parameters: params,
        onSuccess: function(transport) {
            window.location.reload();
        }
    });
}

function Nszm_Trash_Value(iid,fid,val,refresh) {
    if (confirm("Chystáte se smazat hodnotu. Jedná se o nevratnou operaci. Opravdu chcete hodnotu smazat?")) {
       AA_Response('Nszm_Trash_Value', {item_id: iid, field_id: fid, value: val}, function(response_text) { AA_Refresh(refresh,true); }, function(response_text) { AA_Refresh(refresh,true); } );
   }
   //return false;
}




/*===========================================================================
  SORTABLE TABLES by Inventive Labs
  * Uses Prototype 1.5+ (http://prototype.conio.net/)

  Sort a table by clicking on a column heading. To make a table sortable,
  give it a class of 'sortable':

  <table class="sortable">
    <tr>
      <th data-sort="integer">ID</th>
      <th>Summary</th>
      <th data-sort="date">Occurred on</th>
    </tr>
    <tr> (some cells...) </tr>
  </table>

  The 'data-sort' attribute of the table cell headers determines the way that
  the column is sorted. The default is case-insensitive alphabetical comparison.

  Note: during the sort, every other row is given a class of 'alt' - you can
  use this to alternate background colours & etc.

  Based on tableSort.js by Inigo Surguy (http://surguy.net). This file is made
  available under the same Creative Commons Attribution-ShareAlike 2.5 license:
  http://creativecommons.org/licenses/by-sa/2.5/
---------------------------------------------------------------------------*/
SortableTable = function (table) {
  var me = this;

  this.table = table;
  this.rows = $A(table.rows).map(function(r) { return $(r) });
  this.headerRow = this.rows.shift();
  this.headers = Selector.findChildElements(this.headerRow, ['th']);

  this.headers.each(function(th) {
    var span = $(document.createElement('span'));
    $A(th.childNodes).each(function(c) { span.appendChild(c); });
    th.appendChild(span);
    span.onclick = function () { me.sortOnColumn(th, span) }
  });
}

SortableTable.find = function () {
  $$('table.sortable').each(function(table) { new SortableTable(table) })
}

SortableTable.prototype.simpleCompare = function(a,b) {
  return a < b ? -1 : a == b ? 0 : 1;
};

SortableTable.prototype.compareComposer = function(normalizeFn) {
  var me = this;
  return function(a,b) {return me.simpleCompare(normalizeFn(a), normalizeFn(b))}
}

// Add any new comparison functions you need to this switch statement.
SortableTable.prototype.compareFunction = function (sType) {
  switch (sType) {
    case "caseSensitive":
      return this.simpleCompare;
    case "integer":
      // Extracts the first numeric part of a string
      return this.compareComposer(function(a) {
        return parseInt(a.replace(/^.*?(\d+).*$/,"$1"))
      });
    case "float":
      // Similar, but permits floating points (.)
      return this.compareComposer(function(a) {
        return parseFloat(a.replace(/^.*?([\d\.]+).*$/,"$1"))
      });
    case "date":
      // Expects an ISO date format "13 MAR 2006 10:17:02 GMT"
      return this.compareComposer(Date.parse)
    default:
      return this.compareComposer(function(a) { return a.toLowerCase(); });
  }
}

SortableTable.prototype.sortOnColumn = function (th, span) {
  // figure out which column this is
  var pos = $A(this.headerRow.cells).indexOf(th);

  this.headers.each( function(cell) { cell.removeClassName('sortup');   });
  this.headers.each( function(cell) { cell.removeClassName('sortdown');   });
  //this.headerRow.each( function(cell) { cell.removeClassName('sortdown'); });
  //this.headerRow).removeClassName('sortdown');

  // do the sort
  var sortFn = this.compareFunction(th.getAttribute('data-sort'));
  span.order = span.order || 1;
  this.rows.sort(
    function (rowA, rowB) {
      return span.order * sortFn(rowA.getCellText(pos), rowB.getCellText(pos));
    }
  );
  span.order *= -1;
  th.addClassName((span.order == 1) ? 'sortup' : 'sortdown');

  // rearrange the rows based on sort results
  var alt = 0;
  var tbody = this.table.tBodies[0];
  this.rows.each(function(row) {
    if ((alt += 1) % 2) {
      if (!row.hasClassName('alt')) { row.addClassName('alt') }
    } else {
      row.removeClassName('alt');
    }
    tbody.appendChild(row);
  });
}

Element.addMethods({
  getText:function(e){return e.text = e.text||e.textContent||e.innerText||e.innerHTML||''},
  getCellText: function(row, pos) {
    row.cellTexts = row.cellTexts || [];
    row.cellTexts[pos] = row.cellTexts[pos] || row.down("td", pos).getText();
    return row.cellTexts[pos];
  }
});

Event.observe(window, 'load', SortableTable.find, false);








