﻿var IActiveHiLite;

function IActiveHiLiteBlink(h, ms, pause)
{
  IActiveHiLite = document.getElementById(h);
  if (IActiveHiLite)
  {
    var msec = 0;
    while (msec < ms)
    {
      setTimeout("IActiveHiLite.style.border = '2px solid #CCCCCC'",msec);
      msec += pause;
      setTimeout("IActiveHiLite.style.border = '2px solid #E20072'",msec);
      msec += pause;
    }
    setTimeout("IActiveHiLite.style.borderWidth = ''",msec);
    setTimeout("IActiveHiLite.style.borderStyle = ''",msec);
    setTimeout("IActiveHiLite.style.borderColor = ''",msec);
  }
}

function IActiveAddHiLite()
{
  for (var i=0; i<=(document.links.length-1); i++)
  {
    if (document.links[i].hash.length > 1)
    {
      document.links[i].onclick=function() {IActiveHiLiteBlink(this.hash.substring(1),3400,220)};
    }
  }
  if (document.location.hash)
    IActiveHiLiteBlink(document.location.hash.substring(1),3000,200);
}

var IActiveNewWindow=window.IActiveNewWindow;
function IActiveNewWinOpen(link)
{
  var retValue=true;
  if (IActiveNewWindow != null && !IActiveNewWindow.closed)
  {
    IActiveNewWindow.focus();
    if (IActiveNewWindow.location.href!=link.href)
      IActiveNewWindow.location.href=link.href;
  }
  else
  {
    IActiveNewWindow=window.open(link.href,'_IActiveNewWindow','dependent=no,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=no,toolbar=yes');
    if (IActiveNewWindow==null || typeof(IActiveNewWindow)=="undefined")
      retValue=false;
    else
    {
      link.target = '_IActiveNewWindow';
      IActiveNewWindow.focus();
    }
  }
  return retValue;
}

function IActiveAddNewWin()
{
  var articleObj = document.getElementById('article');
  if (articleObj != null)
  {
    var elementCol = articleObj.getElementsByTagName('a');
    for (i=0;i<elementCol.length;i++)
    {
      thisObj = elementCol[i];
      if (((' '+thisObj.className+' ').indexOf('new-win') != -1))
      {
        thisObj.onclick=function() {return IActiveNewWinOpen(this)};
      }
    }
  }
}

function IActiveCollapse()
{
  var articleObj = document.getElementById('article');
  if (articleObj != null)
  {
    var elementCol = articleObj.getElementsByTagName('div');
    for (i=0;i<elementCol.length;i++)
    {
      thisObj = elementCol[i];
      if (((' '+thisObj.className+' ').indexOf('iactive-collapsible') != -1))
      {
        thisObj.className='iactive-collapsible iactive-collapsed';
        var button = document.createElement('a');
        if (thisObj.title.length > 0)
          button.innerHTML=thisObj.title;
        else
          button.innerHTML=IActiveExpandText;
        button.className = 'down';
        button.title=IActiveExpandToolTip;
        button.href='#';
        button.onclick=function(){ IActiveUnCollapse(this, 1);return false; };
        var p = document.createElement('p');
        p.title=IActiveExpandToolTip;
        p.className="iactive-expand";
        p.appendChild(button);
        thisObj.parentNode.getElementsByTagName('div')[0].appendChild(p);
      }
    }
    var elementTableCol = articleObj.getElementsByTagName('table');
    // necha prvni tabulku rozbalenou, proto cyklus zacina za od 1
    for (i=1;i<elementTableCol.length;i++)
    {
      // najde <tbody>, ktere se potom schova, pokud ma prirazenu classu 'iactive-collapsible'
      thisObj = elementTableCol[i].getElementsByTagName('tbody')[0];
      if (((' '+thisObj.className+' ').indexOf('iactive-collapsible') != -1))
      {
        // pokud existuji alespon dve sbalitelne tabulky, vygeneruje button, ktery umozni rozbalit vse
        if (i==2)
          GenerateExpandAllButton(elementTableCol[i-1]);
        thisObj.className = 'iactive-collapsed';
        var button = document.createElement('a');
        button.href='#';
        button.innerHTML = IActiveExpandText;
        button.title = IActiveExpandToolTip;
        button.className = 'down';
        button.onclick=function(){ IActiveUnCollapse(this, 2);return false; };
        var tableCaption = thisObj.parentNode.caption;
        if (tableCaption != null)
        {
          var span = document.createElement('p');
          span.className = 'iactive-expand';
          span.appendChild(button);
          tableCaption.appendChild(span);
        }
      }
    }
  }
}

function GenerateExpandAllButton(table)
{
  var parentElement = table.parentNode;
  var button = document.createElement('a');
  button.href='#';
  button.innerHTML = IActiveExpandAllText;
  button.title = IActiveExpandAllToolTip;
  button.className = 'down-all';
  button.onclick=function(){ IActiveUnCollapseAll(this, 2);return false; };
  var p = document.createElement('p');
  p.className = 'iactive-expand-all';
  p.appendChild(button);
  parentElement.insertBefore(p, table);
}

function IActiveUnCollapse(bObj, tObj)
{
  var pObj;
  switch (tObj)
  {
   case 1:
     pObj = bObj.parentNode.parentNode.parentNode.getElementsByTagName('div')[1];
     break;
   case 2:
     pObj = bObj.parentNode.parentNode.parentNode.getElementsByTagName('tbody')[0];
     break;
  }
  if (pObj.className != 'iactive-collapsible')
  {
    pObj.className = 'iactive-collapsible';
    bObj.innerHTML = IActiveCollapseText;
    bObj.title = IActiveCollapseToolTip;
    bObj.className = 'up';
  }
  else
  {
    pObj.className='iactive-collapsible iactive-collapsed';
    bObj.innerHTML = IActiveExpandText;
    bObj.title = IActiveExpandToolTip;
    bObj.className = 'down';
  }
}

function IActiveUnCollapseAll(bObj,tObj)
{
  var articleObj = document.getElementById('article');
  if (articleObj != null)
  {
    var elementCol = articleObj.getElementsByTagName('a');
    for (j=0;j<elementCol.length;j++)
    {
      thisObj = elementCol[j];
      if (thisObj.className =='down')
      {
        IActiveUnCollapse(thisObj,tObj);
      }
    }
  }
  bObj.scrollIntoView();
}

function IActiveExpand(buttonObj)
{
  buttonObj.className = 'noscreen';
  buttonObj.nextSibling.className = 'iactive-collapsible iactive-expanded';
}

// Tato funkce se spousti pri nacteni stranky v Footer.ascx
// Schova nezaskrtnute checkboxy nebo radiobuttony, pokud jsou umisteny ve fieldsetu, ktery ma nastavenu tridu 'iactive-checkboxlist'
function IActiveHandSetsSelection()
{
  var buttonObj, thisObj;
  var form = document.aspnetForm;
  if (form != null)
  {
    var elementCol = form.getElementsByTagName('fieldset');
    for (i=0;i<elementCol.length;i++)
    {
      thisObj = elementCol[i];
      // pokud ma dany FIELDSET tridu 'iactive-checkboxlist'
      if (((' '+thisObj.className+' ').indexOf('iactive-checkboxlist') != -1))
      {
        // vytvori tlacitko (A ve SPANu) a vsadi ho do LEGEND daneho FIELDSETu. Jeho vlastnosti nastavi pozdeji.
        buttonObj = document.createElement('a');
        var span = document.createElement('span');
        span.appendChild(buttonObj);
        var legend = thisObj.getElementsByTagName('legend')[0];
        legend.className = 'iactive-expand-left';
        legend.innerHTML = ''; // vymaze text uvnitr LEGEND
        legend.appendChild(span);
        
        var showAll = false;
        // pokud ma byt FIELDSET pri nacteni stranky v rozbalenem stavu (obsahuje tridu "onLoadExpanded"
        if (((' '+thisObj.className+' ').indexOf('onLoadExpanded') != -1))
          showAll = true; form.elements[2].checked; // pokud je u vyberu vyrobce telefonu zaskrtnuty INPUT "vsechny", nastavi showAll na true (defaultne vydz pri prvnim nacteni stranky), jinak je false
        
        // spusti prochazeni inputu prislusneho FIELDSETu, pokud ma tridu firstExpanded, zobrazi pri prvnim nacteni stranky vsechny jeho INPUTy
        IActiveSetInputsVisibility(buttonObj, showAll);
      }
    }
  }
}

function IActiveSetInputsVisibility(buttonObj, showAll)
{
  var isHidden = false; // priznak, zda je alespon jeden INPUT schovan (nezaskrtnuty)
  var input, label, br;
  var thisObj = buttonObj.parentNode.parentNode.parentNode; // FIELDSET obsahujici dane tlacitko a INPUTy
  var inputCol = thisObj.getElementsByTagName('input');
  for (j=0;j<inputCol.length;j++)
  {
    input = inputCol[j]; // najde INPUT
    label = input.nextSibling; // jeho LABEL
    br = label.nextSibling; // a pripadne i BR, pokud existuje
    if (input.type == 'checkbox' || input.type == 'radio')
    {
      // pokud je showAll true, tak zobrazi vsechny INPUTY, jinak pouze ty zaskrtnuty
      if (showAll || input.checked)
      {
        input.className = 'iactive-showElement';
        label.className = 'iactive-showElement';
        if (br != null && br.nodeName == 'BR')
        {
          br.className = '';
        }
      }
      else
      {
        input.className = 'iactive-hideElement';
        label.className = 'iactive-hideElement';
        if (br != null && br.nodeName == 'BR')
        {
          br.className = 'noscreen';
        }
        isHidden = true; // nastavi priznak, ze je alespon jeden INPUT schovany (nezaskrtnuty) a tudiz se ma zobrazit rozbalovaci tlacitko (sipka dolu)
      }
    }
    
    // nastavi vlastnosti buttonu - text, tooltip, tridu a navaze funkci na onclick
    if (isHidden)
    {
      buttonObj.title = IActiveExpandToolTip;
      if (thisObj.title.length > 0)
        buttonObj.innerHTML=thisObj.title;
      else
        buttonObj.innerHTML=IActiveExpandText;
      buttonObj.href = "#";
      buttonObj.className = "down";
      buttonObj.onclick = function(){ IActiveSetInputsVisibility(this, true);return false; };
    }
    else
    {
      buttonObj.title = IActiveCollapseToolTip;
      if (thisObj.title.length > 0)
        buttonObj.innerHTML=thisObj.title;
      else
        buttonObj.innerHTML=IActiveCollapseText;
      buttonObj.href = "#";
      buttonObj.className = "up";
      buttonObj.onclick = function(){ IActiveSetInputsVisibility(this, false);return false; };
    }
  }
}

function IActiveSetScrolled()
{
  var articleObj = document.getElementById('article');
  if (articleObj != null)
  {
    var elementCol = articleObj.getElementsByTagName('div');
    for (i=0;i<elementCol.length;i++)
    {
      thisObj = elementCol[i];
      if (((' '+thisObj.className+' ').indexOf('iactive-scrollable') != -1))
      {
        if (thisObj.offsetHeight > 200)
        {
          thisObj.className='iactive-scrollable iactive-scrolled';
          var button = document.createElement('a');
          button.innerHTML=IActiveExpandText;
          button.title=IActiveExpandToolTip;
          button.href="#";
          button.className="iactive-expand";
          button.onclick=function(){ IActiveExpand(this);return false; };
          thisObj.parentNode.insertBefore(button,thisObj);
        }
      }
    }
  }
}

function IActiveSetTabbed()
{
  var thisObj;
  var thisSubObj;
  var articleObj = document.getElementById('article');
//  if (articleObj == null)
  //  articleObj = document.getElementById('contentviewer');
  if (articleObj != null)
  {
    var elementCol = articleObj.getElementsByTagName('div');
    for (i=0;i<elementCol.length;i++)
    {
      thisObj = elementCol[i];
      if (((' '+thisObj.className+' ').indexOf('articletabs-group') != -1))
      {
        var ul = document.createElement('ul');
        ul.className="articletabs";
        thisObj.insertBefore(ul,thisObj.firstChild);
        var tabItemsCount = 0;
        for (ii=0;ii<thisObj.childNodes.length;ii++)
        {
          thisSubObj = thisObj.childNodes[ii];
          if (((' '+thisSubObj.className+' ').indexOf('articletabs-item') != -1))
          {
            tabItemsCount++;
            var li = document.createElement('li');
            ul.appendChild(li);
            var a =  document.createElement('a');
            a.innerHTML = thisSubObj.getAttribute('title');
            a.href=window.location.href;
            a.onclick=function(){ IActiveSwitchTab(this);return false; };
            if (tabItemsCount == 1)
            {
              a.className = 'active';
            }
            else
            {
              thisSubObj.style.display = 'none';
            }
            li.appendChild(a);
          }
        }
      }
    }
  }
}

function IActiveSwitchTab(tabObj)
{
  var tabIndex = 0;
  var tabItemCount = 0;
  var itemCol = tabObj.parentNode.parentNode.parentNode.getElementsByTagName('div');
  var litems= tabObj.parentNode.parentNode.getElementsByTagName('li');
  for (i=0;i<litems.length;i++)
  {
    if (litems[i]== tabObj.parentNode)
      tabIndex = i;
    else
      litems[i].firstChild.className = '';
  }

  var thisObj;
  for (var i=0;i<itemCol.length;i++)
  {
    thisObj = itemCol[i];
    if (((' '+thisObj.className+' ').indexOf('articletabs-item') != -1))
    {
      if (tabItemCount == tabIndex)
      {
        thisObj.style.display = 'block';
      }
      else
      {
        thisObj.style.display = 'none';
      }
      tabItemCount++;
    }
  }

  tabObj.className = 'active';
  tabObj.blur();
  return false;
}


var _collapsedPersonalZoneHeight = 180;
var _maxPersonalZoneHeight = 200;

function IActiveSwitchPersonalZone(pTag)
{
  var personalzone = pTag.parentNode;
  var switchbutton = pTag.childNodes[0];
  var isOpen = Boolean(personalzone.style.height == "auto");
  if (isOpen)
  {
    personalzone.style.overflow = "auto";
    personalzone.style.height = _collapsedPersonalZoneHeight + "px";
    if (_IActivePersonalZoneExpandText)
       switchbutton.setAttribute("title", _IActivePersonalZoneExpandTitleText);
    switchbutton.className = 'down';
    switchbutton.innerHTML = _IActivePersonalZoneExpandText;
  }
  else
  {
    personalzone.style.overflow = "visible";
    personalzone.style.height = "auto";
    if (_IActivePersonalZoneCollapsText)
       switchbutton.setAttribute("title", _IActivePersonalZoneCollapsTitleText);
    switchbutton.className = 'up';
    switchbutton.innerHTML = _IActivePersonalZoneCollapsText;
  }
}

function IActiveGenerateSwitchButton(personalzone, state)
{
  var pTag = document.createElement("p");
  pTag.className= 'iactive-expand'; //.setAttribute("class", "iactive-expand");
  personalzone.insertBefore(pTag, personalzone.childNodes[0]);

  var switchbutton = document.createElement("span");
  pTag.appendChild(switchbutton);
  if (state==0)
  {
    switchbutton.className = 'down';
    switchbutton.innerHTML = _IActivePersonalZoneExpandText;
  }
  else
  {
    switchbutton.className = 'up';
    switchbutton.innerHTML = _IActivePersonalZoneCollapsText;
  }
  switchbutton.onclick = function()
  {
    IActiveSwitchPersonalZone(this.parentNode);
  }
}

function IActiveEshopOfferSwTab(tabObj)
{
  var tabIndex = 0;
  var tabItemCount = 0;
  var itemCol = tabObj.parentNode.parentNode.parentNode.getElementsByTagName('div');
  var litems= tabObj.parentNode.parentNode.getElementsByTagName('li');
  for (i=0;i<litems.length;i++)
  {
    if (litems[i]== tabObj.parentNode)
      tabIndex = i;
    else
      litems[i].firstChild.className = '';
  }

  var thisObj;
  for (var i=0;i<itemCol.length;i++)
  {
    thisObj = itemCol[i];
    if (((' '+thisObj.className+' ').indexOf('eshopofferbar') != -1))
    {
      if (tabItemCount == tabIndex)
      {
        thisObj.style.display = 'block';
      }
      else
      {
        thisObj.style.display = 'none';
      }
      tabItemCount++;
    }
  }

  tabObj.className = 'active';
  tabObj.blur();
  return false;
}
function IActiveEshopOfferTabbed()
{
  var thisSubObj;
  var thisObj = document.getElementById('eshopoffer');
  if (thisObj != null)
  {
    var ul = document.createElement('ul');
    ul.id="eshopoffertabs";
    thisObj.insertBefore(ul,thisObj.firstChild);
    var tabItemsCount = 0;
    for (ii=0;ii<thisObj.childNodes.length;ii++)
    {
      thisSubObj = thisObj.childNodes[ii];
      if (((' '+thisSubObj.className+' ').indexOf('eshopofferbar') != -1))
      {
        tabItemsCount++;
        var li = document.createElement('li');
        ul.appendChild(li);
        var a =  document.createElement('a');
        a.innerHTML = thisSubObj.getAttribute('title');
        a.href=window.location.href;
        a.onclick=function(){ IActiveEshopOfferSwTab(this);return false; };
        IActiveEshopOfferJustifyButtons(thisSubObj);
        if (tabItemsCount == 1)
        {
          a.className = 'active';
        }
        else
        {
          thisSubObj.style.display = 'none';
        }
        li.appendChild(a);
      }
    }
  }
}

function IActiveEshopOfferJustifyButtons(tabObj)
{
  var itemCol = tabObj.getElementsByTagName('div');
  var maxHeight = 0;
  var lastHeight = 0;
  for (var i=0;i<itemCol.length;i++)
  {
    if (((' '+itemCol[i].className+' ').indexOf('item') != -1))
    {
      var hDiv = (itemCol[i].getElementsByTagName('div'))[0];
      maxHeight = Math.max(lastHeight,(hDiv.offsetHeight));
      lastHeight=maxHeight;
    }
  }
  
  for (var i=0;i<itemCol.length;i++)
  {
    if (((' '+itemCol[i].className+' ').indexOf('item') != -1))
    {
      var hDiv = (itemCol[i].getElementsByTagName('div'))[0];
      var isMSIE = /*@cc_on!@*/false;
      if (isMSIE)
        hDiv.style.overflow = 'hidden';
      hDiv.style.height = maxHeight + 'px';
    }
  }
}

/*

function IActiveGetFirstPersonalZone(name)
{
    var personalzone = document.getElementById(name);
    if (personalzone)
    {

      if (personalzone.offsetHeight >= _maxPersonalZoneHeight)
      {
          IActiveGenerateSwitchButton(personalzone, 0);
          personalzone.style.overflowY = "scroll";
          personalzone.style.height = _collapsedPersonalZoneHeight + "px";
      }
      else
      {
          personalzone.style.overflowY = "visible";
          personalzone.style.height = "auto";
      }
   }
}
*/

// Najde personalni zonu a urci jeji chovani podle rovnosti mezi referrem a url

function IActiveGetFirstPersonalZone(name)
{
  
  var personalzone = document.getElementById(name);
  if (personalzone)
  {
   
    if (personalzone.offsetHeight >= _maxPersonalZoneHeight)
    {
       var referrer = document.referrer;
       var url = document.location.href;
       var iurl1 = url.indexOf('#');
       var iurl2 = url.indexOf('?');
       if(iurl1 > 0)
       {
        url = url.substring(0, iurl1);
       }
       if(iurl2 > 0)
       {
        url = url.substring(0, iurl2);
       }

       if (referrer == url)
       {
          // pokud je referrer stejny jako url tak predpokladame, ze akce vznikla v personalni zone a tudiz s ni uzivatel pracuje = nezabalujeme mu ji
          IActiveGenerateSwitchButton(personalzone, 1);
          personalzone.style.overflow = "visible";
          personalzone.style.height = "auto";
       }
       else
       {
          IActiveGenerateSwitchButton(personalzone, 0);
          personalzone.style.overflow = "auto";
          personalzone.style.height = _collapsedPersonalZoneHeight + "px";
       }
    }
  }
}

function IActiveGetNextPersonalZone(name)
{
  var personalzone = document.getElementById(name);
  if (personalzone)
  {
    if (personalzone.offsetHeight >= _maxPersonalZoneHeight)
    {
      IActiveGenerateSwitchButton(personalzone, 1);
      personalzone.style.overflow = "visible";
      personalzone.style.height = "auto";
    }
    else
    {
      personalzone.style.overflowY = "visible";
      personalzone.style.height = "auto";
    }
  }
}

function IActiveActivate()
{
  IActiveCollapse();
  IActiveSetScrolled();
  IActiveSetTabbed();
  IActiveAddHiLite();
  IActiveAddNewWin();
  IActiveHandSetsSelection();
}