var aver=parseInt(navigator.appVersion.substring(0,1));
var aname=navigator.appName;
var ns4=document.layers?1:0
var opera = typeof opera != 'undefined';
var ie=document.all && !opera
var ns6=document.getElementById&&!document.all?1:0
var ns = ns4 || ns6

var jsDOM0 = (document.all);
var jsDOM1 = (document.getElementById);
var jsDOM = jsDOM0 || jsDOM1;
var prva_novinka = 1;
var aktivna_temp = 1;

function request( value ){
    //vytvoreni nove promenne
    var request = null;
    //gecko
    if( window.XMLHttpRequest ){
        request = new XMLHttpRequest()
    }
    else if ( window.ActiveXObject ){
        //IE
        request = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //pokud se neporadilo vytvorit 
    if (!request) {
         alert('nie je možné pripojiť sa na server');
         return false;
    }
      
    request.onreadystatechange = function () {go(request); } ;
    request.open("GET", "setup.php?value=" + value, true);
    request.send( null );
}

function getObj(name) 
{
    if (typeof name == "object") return name;
    if (jsDOM1) return document.getElementById(name);
    if (jsDOM0) return eval('document.all.'+name);
    else return null;
}

function isEMailAddr(elem) {
    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) { return false; }
    else { return true; }
}

function isValid(elem,typ) {
	var str = elem.value;
    if (typ == 'email') re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (typ == 'psc') re = /\d{3} ?\d{2}/;
    if (!str.match(re)) { return false; }
    else { return true; }
}

function PrecitajCookie(nazov)
{
  obsah=document.cookie;   upravene=obsah.split(';');
  velkost=upravene.length; kusy=""; vrat="";

  for (x=0;((x<velkost) && (vrat==""));x++) 
  {
    kusy=upravene[x].split('=');
    if (kusy[0].substring(0,1)==' ') kusy[0]=kusy[0].substring(1,kusy[0].length);
    if (kusy[0]==nazov) vrat=kusy[1];
  }

  return unescape(vrat);
}

function ZapisCookie(nazov,hodnota,vyprsi)
{
  datum=new Date();
  if(vyprsi)
  {
    datum.setTime(datum.getTime()+vyprsi);
    document.cookie=nazov+"="+escape(hodnota)+"; expires="+datum.toGMTString();
  }
    else document.cookie=nazov+"="+escape(hodnota);
}

function W_open(theURL,winName,width,height) 
{ //v2.0
  var left = (screen.width/2) - width/2;
  var top = (screen.height/2) - height/2;
  features = 'width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
  myTWin = window.open(theURL,winName,'toolbar=yes, menubar=yes,location=no, directories=no, scrollbars=yes,resizable=yes,status=no,'+features);
  myTWin.focus( );
}
	
function page_link(link)
{
	rodic = window.opener; 
	rodic.location = link;
}

function goto_link(link)
{
	window.location = link;
}

function zmen_tx_ty(objekt,val,init)
{
   v = objekt.value;
   if (v == init) objekt.value = val;
}

function zapis_obj(id,pr,nm)
{    
	link = 'objednaj.php?id=' + id + '&pr=' + pr + '&nm=' + nm;
	send_xmlhttprequest(link);
}

function getWinHeight() {
  if( typeof( window.innerWidth ) == 'number' ) {
    myWinWidth = window.innerWidth;
    myWinHeight = window.innerHeight;
  } else {
    if( document.documentElement &&
        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      myWinWidth = document.documentElement.clientWidth;
      myWinHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        myWinWidth = document.body.clientWidth;
        myWinHeight = document.body.clientHeight;
      }
    }
  }
  myWinWidth += (ns ? -20 : 0)
}

function getScrollXY() {
  if( typeof( window.pageYOffset ) == 'number' ) {
    myScrTop = window.pageYOffset;
    myScrLeft = window.pageXOffset;
  } else {
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      myScrTop = document.body.scrollTop;
      myScrLeft = document.body.scrollLeft;
    } else {
      if( document.documentElement &&
          ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        myScrTop = document.documentElement.scrollTop;
        myScrLeft = document.documentElement.scrollLeft;
      } else {myScrLeft = 0; myScrTop = 0;}
    }
  }
}

function resize() {
  getWinHeight();
  getScrollXY();
  cislo = myWinHeight + myScrTop - 27;
  
  obj = getObj('NAVI_BAR');
  obj.style.top = cislo + 'px';
}

function scroll() {
  getWinHeight();
  getScrollXY();
  cislo = myWinHeight + myScrTop - 27;
  
  obj = getObj('NAVI_BAR');
  obj.style.top = cislo + 'px';
}

function change_pocasie()
{
    var theForm = document.pocasie_form;
    var lo = theForm.p_lokalita.value;
    var dn = theForm.p_dni.value;
	  
	ZapisCookie("poc_lokalita",lo,"");
	ZapisCookie("poc_dni",dn,"");
	window.location.reload();
}

function show_time()
{
  var month = new Array("Január","Február","Marec","Apríl","Máj","Jún","Júl","Január","Január","Január","Január","Január");
  var Digital = new Date();
  var hours = Digital.getHours();
  var minutes = Digital.getMinutes();
  var seconds = Digital.getSeconds();
  var day = Digital.getDate();
  var mon = month[Digital.getMonth()];
  var vis = document.getElementById('my_time');

  if (minutes<=9) minutes="0"+minutes;
  if (seconds<=9) seconds="0"+seconds;
  
  var ctime = "<b>"+day+"."+mon+"</b> "+hours+":"+minutes+":"+seconds;
  
  vis.innerHTML = ctime;
  setTimeout("show_time()",1000);
}

//window.onload=show_time;

function vrat()
{
  var stara = 'novinka_' + aktivna_temp;
  var nova = 'novinka_' + aktivna_novinka;
  var me_st = 'menunov_' + aktivna_temp;
  var me_no = 'menunov_' + aktivna_novinka;  

  aktivna_temp = aktivna_novinka;
  
  document.getElementById(stara).style.display = "none";
  document.getElementById(nova).style.display = "block"; 
 
  document.getElementById(me_st).className="pol_up";
  document.getElementById(me_no).className="pol_dn"; 	
}

function prehod(nov)
{ 
  var stara = 'novinka_' + aktivna_temp;
  var nova = 'novinka_' + nov;
  var me_st = 'menunov_' + aktivna_temp;
  var me_no = 'menunov_' + nov;  

  aktivna_temp = nov;
  
  document.getElementById(stara).style.display = "none";
  document.getElementById(nova).style.display = "block"; 
  
  document.getElementById(me_st).className="pol_up";
  document.getElementById(me_no).className="pol_dn";
}

function news_change(typ,pocet)
{
  var posledna = pocet - prva_novinka + 1;
  var roll = document.getElementById('roll').style;
  var kolko = Math.round(89/(pocet));
  
  if ((typ==2) && (posledna>0))
  {
	    var hore = 'menunov_' + prva_novinka;
	    var dole = 'menunov_' + (prva_novinka+5);
		document.getElementById(hore).style.display = "none";
	    document.getElementById(dole).style.display = "block";
	    prva_novinka++;
	    if (prva_novinka > aktivna_temp) prehod(aktivna_temp+1);
	    kde = ((prva_novinka-1)*kolko) + 'px';
	    roll.paddingTop = kde;
  }
  
  if ((typ==1) && (prva_novinka>1))
  {
	    prva_novinka--;
		var hore = 'menunov_' + prva_novinka;
	    var dole = 'menunov_' + (prva_novinka+5);
		document.getElementById(hore).style.display = "block";
	    document.getElementById(dole).style.display = "none";
		if (prva_novinka+4 < aktivna_temp) prehod(aktivna_temp-1);
		kde = ((prva_novinka-1)*kolko) + 'px';
	    roll.paddingTop = kde;  
  }
}

function zmen_fun(va)
{	
	var skry, odkry;
    val =  Math.round(va);
	
	if (aktivna_temp < val+1) { prehod(val+1); }
	if (aktivna_temp > val+5) { prehod(val+5); }
	
	for (i=prva_novinka; i<prva_novinka+5;i++)
	{
	  skry = 'menunov_' + i;
	  document.getElementById(skry).style.display = "none";
	}
	prva_novinka = val + 1;
	for (j=prva_novinka; j<prva_novinka+5;j++)
	{
	  odkry = 'menunov_' + j;
	  document.getElementById(odkry).style.display = "block";
	}
}

function toggleRegister(objname) {
  var div = objname + "_setup_bot";
  var img = objname + "_img";
  var btn1 = "images/" + objname + "_btn.gif";
  var btn2 = "images/" + objname + "_btn_down.gif";  
  	
  if(document.getElementById(div).style.display == "none"){
    slidedown(div);
	document.getElementById(img).src = btn2;  
  }else{
    slideup(div);
	document.getElementById(img).src = btn1;   
  }
}

function send_over()
{
	  var theForm = document.send_Form;
	  var submit = true;
	  
	  if (submit && theForm.text.value == "")
	  {
		 alert("Prosím zadajte otázku.");
		 submit = false;
	  }
	  if (submit && theForm.email.value != "" && !isValid(theForm.email,'email'))
	  {
		 alert("Zle zadaná e-mailová adresa.");
		 submit = false;
	  }	  
	  if (submit)
	  {
	  	 theForm.action = "posli_otazku.php";
		 theForm.submit();
	  }
}

function reg_over()
{
	  var theForm = document.reg_Form;
	  var submit = true;
	  
	  if (submit && theForm.meno.value == "")
	  {
		 alert("Prosím zadajte svoje meno.");
		 submit = false;
	  }
	  if (submit && theForm.priezvisko.value == "")
	  {
		 alert("Prosím zadajte svoje priezvisko.");
		 submit = false;
	  }
	  if (submit && !isValid(theForm.email,'email'))
	  {
		 alert("Zle zadaná e-mailová adresa.");
		 submit = false;
	  }	  
	  if (submit && theForm.telefon.value == "")
	  {
		 alert("Prosím zadajte telefónne číslo.");
		 submit = false;
	  }
	  if (submit)
	  {
	  	 theForm.action = "prihlas.php";
		 theForm.submit();
	  }
}

function _otvor() {
    var calc = document.getElementById("innerdiv");
    calc.style.display = 'block';    
}

function _close() {
    var calc = document.getElementById("innerdiv");
    calc.style.display = 'none'; 
}

function download()
{
	object = getObj('download'); 
	num = object.value;
	subor = 'download/' + num;
	if (num) W_open(subor,'subor',800,600);
	object.value = 0;
}

/***********************************************
* Pausing up-down scroller- Â© Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/

function pausescroller(content, divId, divClass, delay, smooth)
{
    this.content=content //message array content
    this.tickerid=divId //ID of ticker div to display information
    this.delay=delay //Delay between msg change, in miliseconds.
    this.smooth=smooth //Delay between msg change, in miliseconds.
	this.mouseoverBol=0 //Boolean to indicate whether mouse is currently over scroller (and pause it if it is)
	this.hiddendivpointer=1 //index of message array for hidden div
	document.write('<div id="'+divId+'" class="'+divClass+'" style="position: relative; overflow: hidden"><div class="innerDiv" style="position: absolute; width: 100%" id="'+divId+'1">'+content[0]+'</div><div class="innerDiv" style="position: absolute; width: 100%; visibility: hidden" id="'+divId+'2">'+content[1]+'</div></div>')
	var scrollerinstance=this
	if (window.addEventListener) //run onload in DOM2 browsers
	window.addEventListener("load", function(){scrollerinstance.initialize()}, false)
	else if (window.attachEvent) //run onload in IE5.5+
	window.attachEvent("onload", function(){scrollerinstance.initialize()})
	else if (document.getElementById) //if legacy DOM browsers, just start scroller after 0.5 sec
	setTimeout(function(){scrollerinstance.initialize()}, 500)
}

// -------------------------------------------------------------------
// initialize()- Initialize scroller method.
// -Get div objects, set initial positions, start up down animation
// -------------------------------------------------------------------

pausescroller.prototype.initialize = function()
{
	this.tickerdiv=document.getElementById(this.tickerid)
	this.visiblediv=document.getElementById(this.tickerid+"1")
	this.hiddendiv=document.getElementById(this.tickerid+"2")
	this.visibledivtop=parseInt(pausescroller.getCSSpadding(this.tickerdiv))
	//set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
	this.visiblediv.style.width=this.hiddendiv.style.width=this.tickerdiv.offsetWidth-(this.visibledivtop*2)+"px"
	this.getinline(this.visiblediv, this.hiddendiv)
	this.hiddendiv.style.visibility="visible"
	var scrollerinstance=this
	document.getElementById(this.tickerid).onmouseover=function(){scrollerinstance.mouseoverBol=1}
	document.getElementById(this.tickerid).onmouseout=function(){scrollerinstance.mouseoverBol=0}
	if (window.attachEvent) //Clean up loose references in IE
	window.attachEvent("onunload", function(){scrollerinstance.tickerdiv.onmouseover=scrollerinstance.tickerdiv.onmouseout=null})
	setTimeout(function(){scrollerinstance.animateup()}, this.delay)
}


// -------------------------------------------------------------------
// animateup()- Move the two inner divs of the scroller up and in sync
// -------------------------------------------------------------------

pausescroller.prototype.animateup = function()
{
	var scrollerinstance=this
	if (parseInt(this.hiddendiv.style.top)>(this.visibledivtop+this.smooth))
	{
		this.visiblediv.style.top=parseInt(this.visiblediv.style.top)-this.smooth+"px"
		this.hiddendiv.style.top=parseInt(this.hiddendiv.style.top)-this.smooth+"px"
		setTimeout(function(){scrollerinstance.animateup()}, 30)
		}
		else{
		this.getinline(this.hiddendiv, this.visiblediv)
		this.swapdivs()
		setTimeout(function(){scrollerinstance.setmessage()}, this.delay)
	}
}

// -------------------------------------------------------------------
// swapdivs()- Swap between which is the visible and which is the hidden div
// -------------------------------------------------------------------

pausescroller.prototype.swapdivs = function()
{
	var tempcontainer=this.visiblediv
	this.visiblediv=this.hiddendiv
	this.hiddendiv=tempcontainer
	}
	
	pausescroller.prototype.getinline=function(div1, div2){
	div1.style.top=this.visibledivtop+"px"
	div2.style.top=Math.max(div1.parentNode.offsetHeight, div1.offsetHeight)+"px"
}

// -------------------------------------------------------------------
// setmessage()- Populate the hidden div with the next message before it's visible
// -------------------------------------------------------------------

pausescroller.prototype.setmessage = function() 
{
	var scrollerinstance=this
	if (this.mouseoverBol==1) //if mouse is currently over scoller, do nothing (pause it)
	setTimeout(function(){scrollerinstance.setmessage()}, 200)
	else
	{
		var i=this.hiddendivpointer
		var ceiling=this.content.length
		this.hiddendivpointer=(i+1>ceiling-1)? 0 : i+1
		this.hiddendiv.innerHTML=this.content[this.hiddendivpointer]
		this.animateup()
    }
}

pausescroller.getCSSpadding = function(tickerobj)
{ //get CSS padding value, if any
	if (tickerobj.currentStyle)
	return tickerobj.currentStyle["paddingTop"]
	else if (window.getComputedStyle) //if DOM2
	return window.getComputedStyle(tickerobj, "").getPropertyValue("padding-top")
	else
	return 0
}