function getParent(el, pTagName)
{
   if (el == null) return null;
   else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) // Gecko bug, supposed to be uppercase
      return el;
   else
      return getParent(el.parentNode, pTagName);
}

// uses Suckerfish dropdowns, http://www.htmldog.com/articles/suckerfish/
// * former source was modified as needed *

sfActive = function()
{
 var tmp = document.getElementById("psMenu");
 if (tmp == null) return;
	var sfEls = document.getElementById("psMenu").getElementsByTagName("a");
	for (var i=0; i<sfEls.length; i++)
  {
		sfEls[i].onmousedown=function()
    {
		  var tmp = getParent(this, "LI");
		  tmpCN = tmp.className;
		  if (tmpCN.indexOf("sfactive") != -1) // odstran pozadie...
		  {
        if (tmpCN.indexOf("Open") == -1) // ...iba ak
        {
          tmp.className=tmp.className.replace(new RegExp(" sfactive\\b"), "");
        }
      }
      else
      {
  			tmp.className += " sfactive";
  			tmpCN = tmp.className;
  			if (tmpCN.indexOf("hasChild") != -1 && tmpCN.indexOf("ulLiLevel2") == -1)
  			{
          this.href = "javascript:;";
        }
      }
		}
	}
}


if (window.attachEvent)
  window.attachEvent("onload", sfActive);
else
  window.onload = sfActive;
/* Suckerfish dropdowns end */

function addRemCSS(obj, css)
{
  if (typeof(window.external) != "undefined") // || navigator.userAgent.indexOf("Opera") != -1)
  {
    if (obj.className.search(new RegExp(""+css+"\\b")) != -1)
      obj.className = obj.className.replace(new RegExp(""+css+"\\b"), "");
    else
      obj.className += " "+css;
  }
}

function wjPopupAdv(url, width, height, param)
{
	var options;
	if (param.length > 50) { alert("Zly parameter pre popup funkciu"); return }
	if (param.search("menu") != -1) { options='menubar=yes,' } else { options='menubar=no,' }
	if (param.search("tool") != -1) { options='toolbar=yes,' } else { options='toolbar=no,' }
	if (param.search("stat") != -1) { options='status=yes,' } else { options='status=no,' }
	if (param.search("scroll") != -1) { options +='scrollbars=yes,' } else { options +='scrollbars=no,' }
	if (param.search("res") != -1) { options +='resizable=yes,' } else { options +='resizable=no,' }
      options += 'width='+width+',height='+height+';'
      popupWindow=window.open(url,"_blank",options);
}


/* colorBow */
var traq = new Array(); /* pole stavu pohybu v poli farieb */
var intval = new Array(); /* pole intervalov */
var colors = new Array(); /* pole farieb */

/* farebne prechody */
colors['default'] = new Array("def0", "def1", "def2", "def3", "def4", "def5", "def6");
colors['home'] = new Array("home0", "home1", "home2", "home3", "home4", "home5", "home6");
colors['hw'] = new Array("hw0", "hw1", "hw2", "hw3", "hw4", "hw5", "hw6");
colors['psp-hw'] = new Array("psp-hw0", "psp-hw1", "psp-hw2", "psp-hw3", "hpsp-hw4", "psp-hw5", "psp-hw6", "psp-hw7", "psp-hw8");
/* end */

var speed = 30; /* ms */
var objekt = new Object();
var objekty = new Array();
var objektId, colorSet, numbOfColors;

function moveIn(set)
{
  var setStr = new String(set);
  if (setStr.indexOf("-") != -1)
  {
    setStr = setStr.substr(1);
    var traqNum = traq[setStr];
    var tagId = "nadpis"+"-"+setStr;
    if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];
    var tagId = "text"+"-"+setStr;
    if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];
    var tagId = "text2"+"-"+setStr;
    if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];
    if (traq[setStr] == numbOfColors) { clearInterval(intval[setStr]); return; }
    traq[setStr] += 1;
  }
  else
  {
    var traqNum = traq[set];
    document.getElementById(set).className = colorSet[traqNum];
    traq[set] += 1;
    if (traq[set] == numbOfColors) clearInterval(intval[set]);
  }
}
function moveOut(set)
{
   var setStr = new String(set);
   if (setStr.indexOf("-") != -1)
   {
      setStr = setStr.substr(1);
      var traqNum = traq[setStr];
      var tagId = "nadpis"+"-"+setStr;
      if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];
      var tagId = "text"+"-"+setStr;
      if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];
      var tagId = "text2"+"-"+setStr;
      if (document.getElementById(tagId) != null && typeof(colorSet[traqNum]) != "undefined") document.getElementById(tagId).className = colorSet[traqNum];

      traq[setStr] -= 1;
      if (traq[setStr] < 0) clearInterval(intval[setStr]);
   }
   else
   {
      var traqNum = traq[set];
      objekty[set].classNamer = colorSet[traqNum];
      traq[set] -= 1;
      if (traq[set] < 0) clearInterval(intval[set]);
   }
}
function fadeMove(obj,colArr,dir)
{
  objekt = obj; objektId = objekt.id;
  if (objektId.indexOf("-") == -1)
  {
    if (typeof(objekty[objektId]) == "undefined") objekty[objektId] = objekt;

    if (dir) {
       if (typeof(intval[objektId]) != "undefined") clearInterval(intval[objektId]);
       if (typeof(traq[objektId]) == "undefined") traq[objektId] = 0;

       colorSet = colors[colArr];
       numbOfColors = colorSet.length;
       intval[objektId] = setInterval("moveIn("+objektId+")", speed);
    } else {
       clearInterval(intval[objektId]);
       intval[objektId] = setInterval("moveOut("+objektId+")", speed);
    }
  }
  else
  {
    var splitArr = objektId.split("-");
    objektId = splitArr[1];

    if (typeof(objekty[objektId]) == "undefined") objekty[objektId] = objekt;

    if (dir) {
       if (typeof(intval[objektId]) != "undefined") clearInterval(intval[objektId]);
       if (typeof(traq[objektId]) == "undefined") traq[objektId] = 0;

       colorSet = colors[colArr];
       numbOfColors = colorSet.length;
       intval[objektId] = setInterval("moveIn("+"-"+objektId+")", speed);
    } else {
       clearInterval(intval[objektId]);
       intval[objektId] = setInterval("moveOut("+"-"+objektId+")", speed);
    }
  }
}
/* end */

function genBack()
{
  var tmp = window.history.length;
  if (tmp < 2)
    self.close();
  else
    history.back();
}

function inquirySubmit(anketa)
{
  var radia = document.getElementById(anketa).getElementsByTagName("input");
  var tmp = false;
  for (var i = 0; i < radia.length; i++)
  {
    if (radia[i].checked)
      tmp = true;
  }
  
  if (tmp)
  {
    return (true);
  }
  else
  {
    alert("Zvoľte prosím odpoveď pre anketu.");
    return (false);
  }
}

function iViewer (target, source)
{
  if (source.length > 10)
  {
    target.src = source;
    target.className = "imgYes";
  }
  else
  {
    target.src = "/images/obsah/prazdny.png";
    target.className = "imgNo";
  }
}
function tViewer (target, text)
{
  if (text.length > 0)
  {
    target.innerHTML = text;
  }
  else
  {
    target.innerHTML = "&nbsp;";
  }
}

var pm_alsoRemoveThis = "";
function promoMenuPS2_mover(tag)
{
  if (pm_alsoRemoveThis != "")
  {
    var tmp = (typeof(tag) == "object") ? tag.id : tag;
    if (tmp != pm_alsoRemoveThis)
    {
      if (typeof(pm_alsoRemoveThis) == "string")
        document.getElementById(pm_alsoRemoveThis).className = "";
      else
        pm_alsoRemoveThis.className = "";
    }
    pm_alsoRemoveThis = "";
  }
  var view = document.getElementById("text-polozky");
  var tag = (typeof(tag) == "object") ? tag : document.getElementById(tag);
  view.innerHTML = document.getElementById(tag.id+"-text").innerHTML;
  tag.className = "on";
}
function promoMenuPS2_mout(tag)
{
  tag.className = "";
}

var sending = false;
var isSendingText = "Formulár sa odosiela, prosím čakajte...";
function formOK()
{
  alert("Formulár bol úspešne odoslaný.");
}
function formFAIL()
{
  alert('Formulár sa nepodarilo odoslať! Skúste ho znova odoslať neskôr.');
}

if (location.href.indexOf("formsend=true") != -1)
	window.onload=formOK;
else if (location.href.indexOf("formfail=") != -1)
	window.onload=formFAIL;


function sutazSupport()
{
  var myForm = document.forms.sutaznyForm;

  var inputs = myForm.getElementsByTagName("INPUT");

  var i = 0;
  var y = 0;
  var isName = "otazka";
  var wasName = "";
  var tmp = Array();
  var bool = false;

  for (i; i<inputs.length; i++)
  {
    if (inputs[i].name.indexOf("otazka") != -1)
    {
      tmp[y] = inputs[i];
      y++;
    }
  }

  inputs = tmp;
  i = 0;

  tmp = inputs[i].name;
  for (i; i<inputs.length; i++)
  {
    if (inputs[i].type == "radio")
    {
      if (tmp == inputs[i].name)
      {
        if (inputs[i].checked)
        {
          bool = true;
        }
      }
      else
      {
        if (!bool)
        {
          alert("Prosím vyznač svoju odpoveď pre všetky otázky.");
          return (false);
        }
        else
        {
          bool = false;
        }
        tmp = inputs[i].name;
        if (inputs[i].checked)
        {
          bool = true;
        }
      }
    }
  }
}

/* common compliant */
function printPage()
{
  var options = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=460;"
  url = top.location.href;
  if (url.indexOf("#")>0) url = url.substring(0, url.indexOf("#"));
  if (url.indexOf("?")>0) url = url + "&print=yes";
  else url = url + "?print=yes";
  printWindow=window.open(url,"_blank",options);
}

function printPageEn()
{
  var options = "menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,width=630,height=460;"
  url = top.location.href;
  if (url.indexOf("#")>0) url = url.substring(0, url.indexOf("#"));
  if (url.indexOf("?")>0) url = url + "&print=yes&eng=yes";
  else url = url + "?print=yes&eng=yes";
  printWindow=window.open(url,"_blank",options);
}

function popup(url, width, height)
{
  var options = "toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+";"
  popupWindow=window.open(url,"_blank",options);
}

function wjPopup(url, width, height)
{
  var options = "toolbar=no,scrollbars=yes,resizable=yes,width="+width+",height="+height+";"
  popupWindow=window.open(url,"_blank",options);
}
