function goLocation()
{
    var regionIndex = window.document.getElementById("region").selectedIndex;
    var selectedRegion = window.document.getElementById("region")[regionIndex].value;

    var dateIndex = window.document.getElementById("date").selectedIndex;
    var selectedDate = window.document.getElementById("date")[dateIndex].value;

    createCookie('region',selectedRegion,7000);
    
    //window.location.href = baseUrl+'/';
    
    window.location.href = baseUrl+'/loc-'+selectedRegion+'/'+selectedDate;

    
    //alert(selectedRegion+"---"+selectedDate);
}

function goLocationHospudkoviny()
{
    var kdyIndex = window.document.getElementById("kdy").selectedIndex;
    var kdy = window.document.getElementById("kdy")[kdyIndex].value;

    var kdeIndex = window.document.getElementById("kde").selectedIndex;
    var kde = window.document.getElementById("kde")[kdeIndex].value;

    var coIndex = window.document.getElementById("co").selectedIndex;
    var co = window.document.getElementById("co")[coIndex].value;

    createCookie('hospudkoviny',kdy+'-'+kde+'-'+co,7000);

    window.location.href = baseUrl+'/akce/?kdy='+kdy+'&kde='+kde+'&co='+co;
}

/*--------------------------------------------------------------------------------------------*/
//handle the Ajax response …
function handleResponse(transport)
{
    //alert(transport.responseText);
    tmp =  transport.responseText.split('@')



    var img2 = new Image();
    var img = window.document.getElementById('hello');
    var name = tmp[0]+'?aaa='+Math.floor(Math.random()*10000);

    img2.src = name;
    img.src = img2.src;//+datum.getSeconds();

    //link = window.document.getElementById('hello_link');
    //link.href = tmp[1];


}

//creates
function callAjax()
{

    //input = window.document.getElementById("baseUrl");

    var myAjax = new Ajax.Request   (  baseUrl+'/banner/',
                                        {   method: 'get',
                                            onComplete: handleResponse}
                                    );
}

function swapbanner()
{
    var b = window.document.getElementById("banner_R_"+banner_R_actual);
    b.style.display = "none";

    banner_R_actual = (banner_R_actual + 1)%banner_R_count;
    var b = window.document.getElementById("banner_R_"+banner_R_actual);
    b.style.display = "block";
}

/*LIGHTBOX BANNER*/
var banner = "";
var autohide = "";

function show_fbanner()
{   
    autohide = window.setInterval("hide_fbanner()", banner_F_autohide*1000);
    Effect.Appear('fs_banner', { duration: 1.0 });

}

function hide_fbanner()
{
    Effect.Fade('fs_banner', { duration: 1.0 });
}

function hide_lottery()
{
    if(confirm("Před zavřením okna se ujistěte zda máte pečlivě opsán Váš kód.\nChcete okno opravdu zavřít?"))
    {
        var b = window.document.getElementById("lottery");
        b.style.display = "none";
        
        var c = window.document.getElementById("lottery_link");
        c.style.display = "none";
    }
}

function bannerOn()
{
    if(banner=="")
    {
        //input = window.document.getElementById("Fbanner_time");
        banner = window.setTimeout("show_fbanner()", Fbanner_time*1000);
    }
}

function bannerOf()
{
    clearTimeout(banner);
    banner = "";
}

function removeFromFavourite(id, element)
{
    var old_cookie = readCookie('favourite');
    var new_cookie = '';

    if(old_cookie != null && old_cookie != '')
    {
        items =  old_cookie.split(',');

        //pridani produktu do kosiku
        for(var i=0;i < items.length;i++)
        {

            if(id != items[i])
            {

                if(new_cookie != '')
                    new_cookie = new_cookie + ',' + items[i] ;
                else
                    new_cookie = items[i];
            }
        }
    }

    createCookie('favourite', new_cookie, 15000);
    element.className = 'content_center_left_header_notfavourite';
    element.attributes['onclick'].value = "addToFavourite("+id+"); return false;";
}

function addToFavourite(id)
{
    //nacteni cookie
    var old_cookie = readCookie('favourite');
    var new_cookie = '';
    var changed = true;

    if(old_cookie != null && old_cookie != '')
    {
        items =  old_cookie.split(',');

        //pridani produktu do kosiku
        for(var i=0;i < items.length;i++)
        {

            if(id == items[i])
            {
                changed = false;
            }

            if(new_cookie != '')
                new_cookie = new_cookie + ',' + items[i] ;
            else
                new_cookie = items[i];
        }
    }

    if(changed)
    {
        if(new_cookie != '')
        {
            new_cookie = new_cookie + ',' + id;
        }
        else
        {
            new_cookie =  id;
        }
    }

    //vlozeni kosiku do cookie
    createCookie('favourite', new_cookie, 15000);
    window.location.reload( true );
}

function createCookie(name,value,hours) {
  if (hours) {
    var date = new Date();
    date.setTime(date.getTime()+(hours*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function createCookieTo(name,value,hours,minutes) {
  if (hours) {
    var date = new Date();
    date.setHours(hours);
    date.setMinutes(minutes);
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

//Nacteni cookie
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

/* PRACE S CASEM --------------------------------------------------------------------------------*/



window.onload = function(e)
{  //alert(window.document.getElementById('top').clientHeight + 20);
    try{
    document.execCommand("BackgroundImageCache", false, true);
    }
    catch(err){}
    getTime(); //naplneni na zacatku
    window.setInterval("getTime()", 1000); //pravidelna zmena, 1000 je sekunda
    if(banner_R_count >0)
    {
        banner_R_actual = 0;
        window.setInterval("swapbanner()", 30000);
    }


    if(banner_F != "")
    {
        var cookieBanner = readCookie("banner");
        if (cookieBanner == null)
        {
            i_preload = new Image();
            i_preload.src = banner_F;

            createCookieTo("banner", "1", 23, 59);
            show_fbanner();

            //alert("banner");
            //this.activate();
        }
    }
    
    try
    {
        bodyHeight = $('wrapper').getHeight();
        $('back_banner').style.height = bodyHeight+'px';
    }catch(err)
    {}
    
    //window.setInterval("callAjax()", 5000);
    //callAjax();
    //window.setInterval("callAjax()", 5000);
    //window.setInterval("scrollingDetector()", 50);
    //alert(document.body.clientHeight);


}

function hideTopBanner()
{
    $('top_banner').toggle();
    $('banner_close_button').toggle();
    
    bodyHeight = $('wrapper').getHeight();
    $('back_banner').style.height = bodyHeight+'px';
}

window.onscroll= function(e)
{
    if (navigator.appName == "Microsoft Internet Explorer")
    {
        margin = document.documentElement.scrollTop;
        footerHeight = 180;
    }
    else
    {
        margin = window.pageYOffset;
        footerHeight = 160;
    }

    headHeight = 118;

    bodyHeight = window.document.getElementById('content').clientHeight;
    bannerHeight = window.document.getElementById('content_right_banner').clientHeight;
    
    if($('top_banner'))
        headHeight += $('top_banner').getHeight();
        
    margin -=  (headHeight);

    if (margin < 0)
       margin = 0;

    //alert('body: '+bodyHeight+'\nbanner: '+bannerHeight+'\nmargin: '+margin+'\nfooter: '+footerHeight);

    if(bodyHeight < bannerHeight + margin + footerHeight)
    {
        margin = bodyHeight - bannerHeight - footerHeight;
    }

    window.document.getElementById('content_right_banner').style.marginTop = margin + 'px';
}
/* POSOUVAC BANNERU -----------------------------------------------------------------------------*/
function getTime ()
{
    var datum = new Date(); // aktualni datum

    var denVTydnu = new Array("Neděle","Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota");

    var retezec = "";
    retezec += denVTydnu[datum.getDay()] + " ";    // Den v tydnu
    retezec += datum.getDate() + ".";              // Den v mesici
    retezec += (1 + datum.getMonth()) + ".";       // Mesice jsou cislovany od nuly

    if (navigator.appName == "Microsoft Internet Explorer")
    {
        retezec += datum.getYear() + " ";         // Rok
    }
    else
    {
        retezec += 1900+datum.getYear() + " ";         // Rok
    }

    retezec += datum.getHours() + ":";

    var minutes = datum.getMinutes();
    if(minutes < 10)                                //uprava formatu casu
        minutes = "0" + minutes;
    retezec += minutes + ":";

    var seconds = datum.getSeconds();
    if(seconds < 10)                                //uprava formatu casu
        seconds = "0" + seconds;
    retezec += seconds;

    // vybral jsem z data, co potrebuju a obalil znamenky, aby se to prevedlo na ?et?zec
    window.document.getElementById("gray_middle_time").innerHTML = retezec;
    // vypocitana hodnota se vklada jako html dovnitr elemnetu, ktery ma id "cas"
}




