﻿var currentIndex = 0;
var prevIndex = 0;
var content;
var oInterval = "";
var strSplash = "";
var allowRefresh = true;
var refreshDate;

AddOnLoad(function() {
  treneri_skryj_vsechny();
  skryj_vsechny_legendy();
  });

function AddOnLoad(func) {
    if(window.addEventListener) { 
        window.addEventListener("load", func, false); 
    } 
    else if(window.attachEvent) { 
        window.attachEvent("onload", func); 
    } 
    else { 
        window.onload=func; 
    } 
}

function OnlineRefresh() {
  d = new Date();
  var oc = document.getElementById('onlineControl');
  if (oc)
    oc.innerHTML = 'Obnovení: ' + (allowRefresh ? d > refreshDate ? 'obnovuji' : 'za ' + Math.round((refreshDate - d) / 1000) + ' s' : 'zastaveno');
  
  if (allowRefresh && d > refreshDate) {
    location.reload();
    clearInterval(onlineTimer);
  }
}

function onlinePopup(docId){
  window.open('/Online-zapas' + (langCode == 'en' ? '-en' : '') + '?docid=' + docId, 'online', 'toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=600');
}

function SubmitSearch(e) {
  if (e.keyCode == 13) {
    Search();
    return false;
  }
  return true;
}

function Search() {
  window.location = '/Archiv' + (langCode == 'en' ? '-en' : '') + '?search=' + encodeURIComponent(document.getElementById('txtSearch').value);
}

function showSplash() {
  if (strSplash != "" && GetCookie("splashseen") != "1") {
    var date = new Date();
		date.setTime(date.getTime()+(24*60*60*1000));
    document.cookie = "splashseen=1; expires="+date.toGMTString();
    setTimeout(strSplash, 1000);
  }
}

var el_last;
function legenda_zobraz(element) {
  var el = document.getElementById(element);
  
  if(el)
  {
	 if(el_last && el_last != el)
	{
		// skryjeme otevřenou legendu
		el_last.style.display = "none";
	}		
		//zobrazíme požadovanou legendu
		el.style.display = (el.style.display != 'none' ? 'none' : '' );
			
		//uložíme ukazatele na otevřenou legendu
		el_last = el;
	return;
  }
}

// schová elementy podle class
function hideElement(cls) {
	//vybere všechny elementy
   var class_el = document.getElementsByTagName("*");
   var i;
   var j;
	
	//projde každý element a skryje el. s určitou class
   for (i=0,j=0;i < class_el.length;i++) 
   {
      var c = " " + class_el[i].className + " ";
      if (c.indexOf(" " + cls + " ") != -1) 
	  {
		class_el[i].style.display = "none";
	  }
   }
} 

function skryj_vsechny_legendy()
{
     hideElement("legenda_text");
}

//globální proměnná
var trener_last;

function treneri_zobraz(id) {
  var trener = document.getElementById("treneri_"+id);
  if(trener)
  {
  if(trener_last && trener_last != trener){
		// skryjeme otevřeného trenéra
		trener_last.style.display = "none";
		
}		
		//zobrazíme požadovaného trenéra
		trener.style.display=(trener.style.display != 'none' ? 'none' : '' ); // případně = "block", ale block zlobil a trenér se zobrazoval jako pruh...

		//uložíme ukazatele na otevřeného trenéra
		trener_last = trener;
    return;
  }
}

function treneri_skryj_vsechny()
{
     var treneri = document.getElementById("treneri");
     if (treneri) {
         var tr_count = treneri.rows.length;
         var tr_text;
         for (a = 0; a <= tr_count; a++)
         {
              tr_text = treneri.rows[a];
             //skryjeme jen sude radky
             //liche radky obsahuji jmena, sude texty
             if ((a % 2) == 1)
            {
                if (tr_text)    tr_text.style.display = 'none';
            }
        }
   }
}

function getSuperArticle() 
{
    content = new Array();
    var allTags = document.getElementsByTagName("div");
    var index = 0;
    
    for (i = 0; i < allTags.length; i++)
    {
        if (allTags[i].className == "superArticleTop" || allTags[i].className == "superArticleTopActive")
        {
            content[index] = new Array();
            content[index]["top"] = allTags[i];
            index++;
        }
    }

    index = 0;
    
    for (i = 0; i < allTags.length; i++) 
    {
        if (allTags[i].className == "superArticleList") 
        {   
            allTags[i].index = index;
            content[index++]["list"] = allTags[i];
                         
            allTags[i].onmouseover = function() {
                showContent(this.index);
            }
            
            allTags[i].onmouseout = function() {
                if (oInterval == "") 
                  oInterval = setInterval("rotateContent()", 5000);
            }
        }
    } 
    
    currentIndex = content.length;
}
   
function rotateContent() 
{
    currentIndex = (currentIndex < content.length - 1) ? currentIndex + 1 : 0;
    prevIndex = (currentIndex == 0) ? content.length - 1 : currentIndex - 1;
    
    try
    {
        content[prevIndex]["top"].className = "superArticleTop";
        content[prevIndex]["list"].className = "superArticleList";
    
        content[currentIndex]["top"].className = "superArticleTopActive";
        content[currentIndex]["list"].className = "superArticleListActive";
    }
    catch(e) {}
}

function showContent(index) 
{
    clearInterval(oInterval);
    oInterval = "";
    
    try 
    {
        content[currentIndex]["top"].className = "superArticleTop";
        content[currentIndex]["list"].className = "superArticleList";
        
        content[index]["top"].className = "superArticleTopActive";
        content[index]["list"].className = "superArticleListActive";
    }
    catch(e) {}
    
    currentIndex = index;
}

function GetCookie(sName) {
    // cookies are separated by semicolons
    var aCookie = document.cookie.split("; ");
    for (var i = 0; i < aCookie.length; i++) {
        // a name/value pair (a crumb) is separated by an equal sign
        var aCrumb = aCookie[i].split("=");
        if (sName == aCrumb[0])
            return unescape(aCrumb[1]);
    }

    // a cookie with the requested name does not exist
    return null;
}

function ajaxAnketa(id, iqid, visitor) {
    var xmlhttp;
    try {
        xmlhttp = new XMLHttpRequest();
    }
    catch (e) {
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e) {
                alert("Váš prohlížeč nepodporuje AJAX!");
                return false;
            }
        }
    }
    var url = '/Pages/Inquiry.aspx?id=' + id + '&iqid=' + iqid + '&v=' + visitor + '&d=' + (new Date()).getTime()

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4) {
            var anketa = document.getElementById("anketa" + id);
            if (anketa)
                anketa.innerHTML = xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET", url, true);
    xmlhttp.send(null);
}

function Smile(xsmile) {
    var textbox = document.getElementById(forumItemEdit + '_TextBoxMessage');
    textbox.focus();
    textbox.value = textbox.value + xsmile;
}

function SmileReag(xsmile) {
    var textbox = document.getElementById(forumItemEdit + '_TextBoxReagovat');
    textbox.focus();
    textbox.value = textbox.value + xsmile;
}

function reagovat(i) {
    allowRefresh = false;
    document.getElementById(forumItemEdit + '_tbEntry').value = i;
    document.getElementById('forumEntry' + i).appendChild(document.getElementById('reagovat'));
    document.getElementById(forumItemEdit + '_TextBoxReagovat').focus()
}

function showform(i) {
    allowRefresh = false;
    document.getElementById('forumEntry' + i).appendChild(document.getElementById('reagovat'));
}

function edit(i, t) {
    allowRefresh = false;
    document.getElementById(forumItemEdit + '_tbEditEntry').value = i;
    document.getElementById(forumItemEdit + '_TextBoxReagovat').value = t;
    document.getElementById('forumEntry' + i).appendChild(document.getElementById('reagovat'));
    document.getElementById(forumItemEdit + '_TextBoxReagovat').focus()
}

function deleteitem(i) {
    if (!confirm((typeof(langCode) !== 'undefined' && langCode == 'cs') ? 'Opravdu chcete smazat tento příspěvek?' : 'Do you really want to delete this message?'))
        return;

    document.getElementById(forumItemEdit + '_tbEntry').value = i
    document.getElementById(forumItemEdit + '_btnDelete').click();
}

function showadd() {
    allowRefresh = false;
    document.getElementById('forumAdd').appendChild(document.getElementById('forumItemAdd'));
    document.getElementById('divadd').style.display = 'none';
}

function checkNickClient(source, args)
{
    var val = args.Value;
    if ((!val) || val.length < 1)
        return;

    if (val.length < 4)
    {
        args.IsValid = false;
        return;
    }

    var ch;
    var notNumber = false;

    for (var count = 0; count < val.length; count++)
    {
        ch = val.charAt(count);

        if (ch < '0' || ch > '9')
        {
            notNumber = true;
            if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') && ch != '-' && ch != '_' && ch != '.' && ch != ',' && ch != '@' && ch != '+')
            {
                args.IsValid = false;
                return;
            }
        }
    }

    args.IsValid = notNumber;
}

