moz=document.getElementById&&!document.all;
isIE6 = /msie|MSIE 6/.test(navigator.userAgent); 

if (!document.getComputedStyle){
  if(!document.defaultView){
    document.getComputedStyle = function(el, pseudo) {
    this.el = el;
    this.getPropertyValue = function(prop) {
    var re = /(\-([a-z]){1})/g;
    if (prop == 'float') prop = 'styleFloat';
    if (re.test(prop)) {
      prop = prop.replace(re,function(){return arguments[2].toUpperCase();});
      };
      return el.currentStyle[prop] ? el.currentStyle[prop] : null;
    };
    return this;
    };
  }else{
    if(!document.defaultView.getComputedStyle){
    }else{
      document.getComputedStyle = function(el, pseudo){ return document.defaultView.getComputedStyle(el, pseudo);  }
    };
  };
};

function stripix(s){if(s==null)return 0;var re=/px/gi;var c=s.replace(re,'');return Number(c);};

function e(o){return document.getElementById(o)}
function el(o){return document.getElementById(o)}
function goNewWindow(url){var newWindow = window.open(url, '_blank');newWindow.focus();}
function go(url){location.href=url;}
function go(url,e){if (url) location.href=url;if (!e) var e = window.event;e.cancelBubble = true;if (e.stopPropagation) e.stopPropagation();return false;}
function show_element(name){e(name).style.display='block';return false;}
function hide_element(name){e(name).style.display='none';return false;}
function hide_current_row(t)
{
    while ((t) && (t.parentNode))
    {
        if (t.nodeName.toLowerCase() == 'tr')
        {
            t.style.display = 'none';
            return;
        }
        t=t.parentNode;
    }
    alert(t.nodeName);
}
function switchVisibility(what)
{
    if (typeof(what) == "object")
    {
        if ((what.style.display == 'none') || (what.style.display == ''))
        {
            what.style.display = 'block';
        } else {
            what.style.display = 'none';
        }
    } else {
        if ((el(what).style.display == '') || (el(what).style.display == 'none'))
        {
            el(what).style.display = 'block';
        } else {
            el(what).style.display = 'none';
        }
    }
}
function mini_modal_message(t,text,color,auto_close)
{
var p = t;
x = 0;
y = 0;
while(p && p.offsetParent)
{
    x += p.offsetLeft;
    y += p.offsetTop;
    p = p.offsetParent;
}
dx = t.offsetWidth;
dy = t.offsetHeight;
if (!color) color = 'red';
e('mini_message_div_bg').style.display = 'block';
e('mini_message_div_bg').style.backgroundImage = 'url(\'/img/bg_'+color+'_mini_modal_dialog.png\')';
e('mini_message_div_bg').style.left = x + dx - t.offsetWidth-200;
e('mini_message_div_bg').style.top = y + dy - t.offsetHeight-80;
e('mini_message_div_text').innerHTML = text;
if (auto_close)
    setTimeout('close_mini_modal_message()',auto_close);

}
function modal_message(text,color,auto_close)
{
if (!color) color = 'red';
e('modal_div').style.width = '100%';
e('modal_div').style.height = '100%';
e('modal_div').style.display = 'block';
e('modal_div_text_bg').style.backgroundImage = 'url(\'/img/bg_'+color+'_modal_dialog.png\')';
e('modal_div_text_bg').style.left = (document.width-500)/2;
e('modal_div_text_bg').style.top = (document.height-193)/2;
e('modal_div_text').innerHTML = text;
if (auto_close)
    setTimeout('close_modal_message()',auto_close);
}
function close_modal_message()
{
e('modal_div').style.display = 'none';
}
function close_mini_modal_message()
{
e('mini_message_div_bg').style.display = 'none';
}

function getX(id)
{
    var abs_pos;
    abs_pos = 0;
    el = document.getElementById(id);
    while(el.offsetParent != null)
    {
        el = el.offsetParent;
        if (el.offsetLeft != null) abs_pos += el.offsetLeft;
    }
    return abs_pos;    
}

function getY(id)
{
    var abs_pos;
    abs_pos = 0; 
    el = document.getElementById(id);
    while(el.offsetParent != null)
    {
        el = el.offsetParent;
        if (el.offsetLeft != null) abs_pos += el.offsetTop;
    }
    return abs_pos;    
}
function getXbyID(id)
{
    var abs_pos;
    abs_pos = 0;
    el = id;
    while(el.offsetParent != null)
    {
        el = el.offsetParent;
        if (el.offsetLeft != null) abs_pos += el.offsetLeft;
    }
    return abs_pos;    
}

function getYbyID(id)
{
    var abs_pos;
    abs_pos = 0; 
    el = id;
    while(el.offsetParent != null)
    {
        el = el.offsetParent;
        if (el.offsetLeft != null) abs_pos += el.offsetTop;
    }
    return abs_pos;    
}

function showElementAtItem(id_element, id_item, args)
{
    var p;
    var x = 0;
    var y = 0;
    var parent;
    p = document.getElementById(id_item);
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        if (p.parentNode.scrollTop != undefined)
        {
            y -= p.parentNode.scrollTop;
        }
        p = p.offsetParent;
    }
    

    document.getElementById(id_element).style.left = (x - args);
    document.getElementById(id_element).style.top = y + 21;
    document.getElementById(id_element).style.position = 'absolute';
    document.getElementById(id_element).style.display = 'block';
    document.getElementById(id_element).style.zIndex = '200';
    width = document.getElementById(id_element).clientWidth;

    if (document.getElementById('adminBody') != undefined)
    {
        if (window.innerWidth <= (x+width)+25) 
            args = (x+width+25) - window.innerWidth;
        document.getElementById(id_element).style.left = (x - args);
    } 
    
    return false;                    
}
function showElementAtItem2(id_element, id_item, args)
{
    var p;
    var x = 0;
    var y = 0;
    var parent;
    p = document.getElementById(id_item);
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        if (p.parentNode.scrollTop != undefined)
        {
            //y -= p.parentNode.scrollTop;
        }
        p = p.offsetParent;
    }
    

    document.getElementById(id_element).style.left = (x - args);
    document.getElementById(id_element).style.top = y + 21;
    document.getElementById(id_element).style.position = 'absolute';
    document.getElementById(id_element).style.display = 'block';
    width = document.getElementById(id_element).clientWidth;

    if (document.getElementById('adminBody') != undefined)
    {
        if (window.innerWidth <= (x+width)+25) 
            args = (x+width+25) - window.innerWidth;
        document.getElementById(id_element).style.left = (x - args);
    } 
    
    return false;                    
}
function showElementAtItemExactly(id_element, id_item)
{
    var p;
    var x = 0;
    var y = 0;
    var parent;
    p = document.getElementById(id_item);
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        if (p.parentNode.scrollTop != undefined)
        {
            //y -= p.parentNode.scrollTop;
        }
        p = p.offsetParent;
    }
    

    document.getElementById(id_element).style.left = x;
    document.getElementById(id_element).style.top = y;
    document.getElementById(id_element).style.position = 'absolute';//absolute
    document.getElementById(id_element).style.display = 'block';
    
    return false;                    
}
function showElementAtItemWithOffset(id_element, id_item,l,t)
{
    //alert('S'+id_element);
    var p;
    var x = 0;
    var y = 0;
    var parent;
    if (typeof(id_item) == "string")
    {
        p = document.getElementById(id_item);
    } else {
        p = id_item;
    }
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        if (p.parentNode.scrollTop != undefined)
        {
            //y -= p.parentNode.scrollTop;
        }
        p = p.offsetParent;
    }
    
    
    document.getElementById(id_element).style.left = Number(x)+Number(l);
    document.getElementById(id_element).style.top = Number(y)+Number(t);
    document.getElementById(id_element).style.position = 'absolute';//absolute
    document.getElementById(id_element).style.display = 'block';
    document.getElementById(id_element).style.zIndex = '200';
    return false;                    
}
function hideElement(id_element)
{
    //alert('H'+id_element);
    document.getElementById(id_element).style.display = 'none';
    return false;
}

function addDynamicContent(id_element, from_url)
{
    document.getElementById(id_element).innerHTML = '';
    script = document.createElement('script');
    script.src = from_url; 
    
    // (script musi byt vo formate document.getElementById(id_element).innerHTML = ...
    document.getElementById(id_element).appendChild(script); 
    return false;    
}


function drag_element(e,element_id, max_height)
{
    id = element_id;
    document.getElementById(id).onmouseup = element_mouse_up;
    cursor_position_x=(!moz ? window.event.clientX : e.clientX); 
    cursor_position_y=(!moz ? window.event.clientY : e.clientY);
    object_position_x=document.getElementById(id).offsetLeft; 
    object_position_y=document.getElementById(id).offsetTop;
    cursor_top = (cursor_position_y - object_position_y);
    if (cursor_top < max_height || max_height == null)
    {
        moving=true;
        document.onmousemove=move_element;
        document.getElementById(id).style.cursor= "move";
    } else {
        moving = false;
        document.getElementById(id).style.cursor="auto";
    }
}

function move_element(e)
{
    current_cursor_pos_x=(!moz ? window.event.clientX : e.clientX); 
    current_cursor_pos_y=(!moz ? window.event.clientY : e.clientY);
    if (moving==true)
    {
        document.getElementById(id).style.left=current_cursor_pos_x-(cursor_position_x-object_position_x); // Objectx Current Position
        document.getElementById(id).style.top=current_cursor_pos_y-(cursor_position_y-object_position_y); //Objecty Current Position
        return false;
    }
}

function element_mouse_up()
{
    document.onmouseup=new Function("moving=false");
    document.getElementById(id).style.cursor="auto";
}



function fadeIn(where, endColor, which) 
{
    Color= new Array();
    Color[1] = "ff";
    Color[2] = "ee";
    Color[3] = "dd";
    Color[4] = "cc";
    Color[5] = "bb";
    Color[6] = "aa";
    Color[7] = "99";
    if(!document.getElementById(which))return false;
    if (where >= 1)
    {
        document.getElementById(which).style.backgroundColor = "#ffff" + Color[where];

        if (where == 7)
        {
            iWait = 600;
        } else {
            iWait = 300-(where*20);
        }

        if (where > 1)
        {
            where -= 1;
            setTimeout("fadeIn("+where+",'" + endColor + "','" + which + "')", iWait);
        } else {
            where -= 1;
            setTimeout("fadeIn("+where+",'" + endColor + "','" + which + "')", iWait);
            document.getElementById(which).style.backgroundColor = endColor;
        }
    }
} 

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date()
    exdate.setDate(exdate.getDate()+expiredays)
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
        } 
      }
    return ""
}

function setOpac(o,t) {
  t=(t==100)?99.999:t;
  if(typeof o.style.opacity !== 'undefined'){
// W3C
    o.style.opacity=t/100;
  }else if (typeof o.style.MozOpacity !== 'undefined') {
// Older Mozilla
    o.style.MozOpacity=t/100;
  }else if (typeof o.style.filter != 'undefined') {
// IE 
    o.style.filter='alpha(opacity:'+t+')';
  }else if (typeof o.style.KHTMLOpacity != 'undefined') {
// Older KHTML Based Browsers 
    o.style.KHTMLOpacity=t/100;
  }
};

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
};
function getPageWH() {
  if(window.outerHeight==undefined){
    var wh = document.body.clientHeight;
    var ww = document.body.clientWidth;
  }else{
    var wh = window.innerHeight;
    var ww = window.innerWidth;
  }
  return [ ww, wh ];
};
function getObjectWH(o) {
  var ow = o.style.width;
  var oh = o.style.height;
  return [ stripix(ow), stripix(oh) ];
};
function hide_new_popup(el_name){
document.getElementById(el_name).style.display='none';
document.getElementById('clona_'+el_name).style.display='none';
  document.body.style.overflow='auto';
  document.body.style.height='auto';
  document.body.style.width='auto';
  window.onscroll = null;
  window.onresize = null;
return false;
}
function show_new_popup(el_name){
    var wh = getPageWH();
    var xy = getScrollXY();
    var wgbox = document.getElementById(el_name);
    var wgwh = getObjectWH(wgbox);
    wgbox.style.position = 'absolute';
    wgbox.style.zIndex=1000;
    var need_scrolling = false;
    if ((wh[1]-wgwh[1])>0)
        wgbox.style.top = Math.floor(xy[1]+Math.floor((wh[1]-wgwh[1])/2))+'px';
    else{     
        wgbox.style.top = '0px';
        need_scrolling = true;
    }
    if ((wh[0]-wgwh[0])>0)    
        wgbox.style.left = Math.floor(xy[0]+Math.floor((wh[0]-wgwh[0])/2))+'px';
    else{     
        wgbox.style.left = '0px';
        need_scrolling = true;
    }
    wgbox.style.width = Math.floor(wgwh[0])+'px';
    wgbox.style.height = Math.floor(wgwh[1])+'px';
    wgbox.style.display = 'block';
    wgbox.style.overflow='hidden';

  var o = document.getElementById('clona_'+el_name);
  //if(!o)return false;
  o.style.position = 'absolute';
  o.style.zIndex=900;
  o.style.display = 'block';
  o.style.top = Math.floor(xy[1]-25)+'px';
  o.style.left = Math.floor(xy[0]-25)+'px';    
  o.style.width = Math.floor(wh[0]+35)+'px';
  o.style.height = Math.floor(wh[1]+35)+'px';
  if (need_scrolling){
    o.style.top = '0px';
    o.style.left = '0px';
    if ((wh[1]-wgwh[1])<=0)
        o.style.height = Math.floor(wgwh[1]+35)+'px';
    if ((Math.floor(wh[0]+35))<800)    
        o.style.width = Math.floor(800)+'px';             
  }
  o.style.backgroundColor = 'white';
  o.onmousedown = function(){return false;};
  o.onmousemove = function(){return false;};
  setOpac(o,75);  
  if (!need_scrolling)
    document.body.style.overflow='hidden';
  document.body.style.height=wh[1]+'px';
  document.body.style.width=wh[0]+'px';
  if (!need_scrolling)
    window.onscroll = function(){window.scrollTo(xy[0],xy[1]);};
  window.onresize = function(){hide_new_popup(el_name); show_new_popup(el_name);};
}
function show_new_popup_at_item(el_name,id_item,l,t){
    if(window.outerHeight==undefined){
    var wh = document.body.clientHeight;
    var ww = document.body.clientWidth;
    }else{
    var wh = window.innerHeight;
    var ww = window.innerWidth;
    }
    
    var p;
    var x = 0;
    var y = 0;
    var parent;
    p = document.getElementById(id_item);
    while(p && p.offsetParent)
    {
        x += p.offsetLeft;
        y += p.offsetTop;
        if (p.parentNode.scrollTop != undefined)
        {
            //y -= p.parentNode.scrollTop;
        }
        p = p.offsetParent;
    }
    
    var wgbox = document.getElementById(el_name);
    wgbox.style.position = 'absolute';
    wgbox.style.top = y+t+'px';
    wgbox.style.left = x+l+'px';
    //wgbox.style.width = Math.floor(wgw)+'px';
    //wgbox.style.height = Math.floor(wgh)+'px';
    wgbox.style.display = 'block';
    wgbox.style.overflow='hidden';

  var o = document.getElementById('clona_'+el_name);
  //if(!o)return false;
  o.style.position = 'absolute';
  o.style.display = 'block';
  o.style.top = '0px';
  o.style.left = '0px';    
  o.style.width = ww+'px';
  o.style.height = Math.floor(wh+y)+'px';
  o.style.backgroundColor = 'white';
  setOpac(o,75);  
  document.body.style.overflow='hidden';
  document.body.style.height=wh+'px';
  document.body.style.width=ww+'px';
  //window.onscroll = function(){window.scrollTo(0,0);};
}
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function dont_post(event, sender, alternate)
{
    if (event.which)
        key = event.which;
    else key = event.keyCode;

    if (key == 13)
    {
        if (sender.form != null)
        {
            sender.form.onsubmit = function() {return false;};
            if (typeof(alternate) == 'string')
            {
                alternate_url = alternate.replace('#SENDER_VALUE#', String(sender.value));
                document.location.href = alternate_url;
            }
            if (typeof(alternate) == 'function')
            {
                alternate();   
            }
        }
        return false;
    }
    if (key == 27)
    {
        sender.blur();
    }    
}

// zavola php skript v pozadi, a zobrazi ho v body
function call_external_url(url)
{
    script = document.createElement('script');
    script.src = url; 
    
    document.getElementById('body').appendChild(script); 
    return false;    
} 


function admin_call_external_url(url)
{
    script = document.createElement('script');
    script.src = url; 
    
    document.getElementById('adminBody').appendChild(script); 
    return false;    
} 


function get_help(url, event, id)
{
    // download
    script = document.createElement('script');
    script.src = url;
    
    // generate popup div
    var div;
    div = document.getElementById('help_div_'+id);
    if (div != null && div.innerHTML != '<img src="/img/loading.gif"></img>')
    {
        
    } else {
        div = document.createElement('div');
        div.id = 'help_div_'+id;
        //div.style.background = "#e0efd5";
        div.style.border = "0px solid #000000";
        div.style.zIndex = "1";
        div.style.position = "absolute";
        div.style.overflow = "hidden";
        div.style.height = "105px";
        div.style.width = "250px";
        if(isIE6)
          div.style.backgroundImage = "url(/img/bublinka.gif)";
        else
          div.style.backgroundImage = "url(/img/bublinka.png)";

        div.innerHTML = '<img src="/img/loader.gif" style="margin:20px auto;"></img>';
        div.appendChild(script);
        div.style.display = 'block';
        document.body.appendChild(div); 
    }

    //showElementAtItem(div.id, id, -30);
    showElementAtItemWithOffset(div.id, id,-168,-105);

    return false;    
}

function hide_help(id)
{
    if (document.getElementById('help_div_'+id) != null)
    {
        document.getElementById('help_div_'+id).style.display = 'none';    
    }
}