function setsize()
  {
  w=document.documentElement.clientWidth;
  if (w<1210)
    {
	setcookie("width",1024,365);
    document.getElementById('tr').style.display="none";
    document.getElementById('mr').style.display="none";
    document.getElementById('ml').style.display="block";
    document.getElementById('obklady').style.width="981px";
    document.getElementById('header').style.backgroundImage="url('/images/back/back2-top1024.gif')";
    document.getElementById('main').style.backgroundImage="url('/images/back/back-middle1024.gif')";
    document.getElementById('foot').style.backgroundImage="url('/images/back/back-bottom1024.gif')";
	}
  else
    {
	setcookie("width",1280,365);
    document.getElementById('obklady').style.width="1221px";
    document.getElementById('tr').style.display="block";
    document.getElementById('mr').style.display="block";
    document.getElementById('ml').style.display="none";
    document.getElementById('header').style.backgroundImage="url('/images/back/back2-top1280.gif')";
    document.getElementById('main').style.backgroundImage="url('/images/back/back-middle1280.gif')";
    document.getElementById('foot').style.backgroundImage="url('/images/back/back-bottom1280.gif')";
	}
  }

window.onload=setsize; 

window.onresize=setsize; 

function getexpirydate(nodays)
  {
  var UTCstring;
  Today = new Date();
  nomilli=Date.parse(Today);
  Today.setTime(nomilli+nodays*24*60*60*1000);
  UTCstring = Today.toUTCString();
  return UTCstring;
  }
function setcookie(name,value,duration)
  {
  document.cookie = name+"="+escape(value)+";expires="+getexpirydate(duration)+";path=/";
  }


function sp(i,j)
  {
  //zobraz snimek j,i, ostatni smaz
  var k=0;
  while( el=document.getElementById('snimek'+i+'-'+k) )
    {
    if (k==j) el.style.display="block";
	else el.style.display="none";
    k++;
    }
//  if (casovac) clearInterval(casovac);
  }

var aktsnimek=0;
function spa()
  {
  //automaticka zmena obrazku
  var j=0;
  while( el=document.getElementById('snimek'+j) )
    {
    if (j==aktsnimek) el.style.display="block";
	else el.style.display="none";
    j++;
    }
  aktsnimek++;
  if (!document.getElementById('snimek'+aktsnimek)) aktsnimek=0;
  }

function vyhledavani(id)
  {
  window.location.href='/vyhledavani?q='+document.getElementById(id).value;
  }

function srf(id)
  {
  if (document.getElementById(id).value=='Hledej...') document.getElementById(id).value='';
  }

function tisk()
  {
  window.print();
  }

addLoadEvent(initResPict);

function initResPict()
  {
  if (!document.getElementsByTagName){ return; }
  var anchors = document.getElementsByTagName("a");
  for (var i=0; i<anchors.length; i++)
    {
	var an = anchors[i];
	if (an.getAttribute("href") && (an.getAttribute("rel") == "respict" || an.getAttribute("rel") == "respict2"))
	  {
	  var w=an.childNodes[0].width;
	  var h=an.childNodes[0].height;
	  if (an.getAttribute("rel")=="respict2")
	    {
		if (w==0) w=240;
		if (h==0) h=160;
		}
	  an.style.overflow="hidden";
	  an.style.width=w+'px';
	  an.style.height=h+'px';
	  an.aktzoom=1;
      switch(an.getAttribute("rel"))
	    {
		case 'respict':
	  an.onmouseover = function () {respict(this,1,4); return false;}
	  an.onmouseout = function () {respict(this,0,4); return false;}
	    break;
	    default:
	  an.onmouseover = function () {respict(this,1,0); return false;}
	  an.onmouseout = function () {respict(this,0,0); return false;}
		}
	  }
	}
  }

function respict(id,stav,border)
  {
  id.stav=stav;
  if (stav==1) zvetsuj(id,border);
  if (stav==0) zmensuj(id,border);
  }

function zvetsuj(id,border)
  {
  if (id.stav==1)
    {
    var dost=false;
    var id2=id.childNodes[0];
    id.aktzoom+=0.03;
    if (id.aktzoom>1.20) { id.aktzoom=1.20;dost=true;}
    id2.style.width=(id.offsetWidth-border)*id.aktzoom+'px';
    id2.style.height=(id.offsetHeight-border)*id.aktzoom+'px';
    id2.style.marginTop=-(id.aktzoom-1)*(id.offsetWidth-border)/2+'px';
    id2.style.marginLeft=-(id.aktzoom-1)*(id.offsetHeight-border)/2+'px';

    if (!dost && id.stav==1)  setTimeout(function() { zvetsuj(id,border); }, 10);
	}
  }

function zmensuj(id,border)
  {
  if (id.stav==0)
    {
    var dost=false;
    var id2=id.childNodes[0];
    id.aktzoom-=0.03;
    if (id.aktzoom<1) { id.aktzoom=1;dost=true;}
    id2.style.width=(id.offsetWidth-border)*id.aktzoom+'px';
    id2.style.height=(id.offsetHeight-border)*id.aktzoom+'px';
    id2.style.marginTop=-(id.aktzoom-1)*(id.offsetWidth-border)/2+'px';
    id2.style.marginLeft=-(id.aktzoom-1)*(id.offsetHeight-border)/2+'px';

    if (!dost && id.stav==0)  setTimeout(function() { zmensuj(id,border); }, 10);
	}
  }



function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}

function preposlat()
  {
  httpRequest = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
  httpRequest.open("GET", "/poslat-znamemu?url="+location.href+"&title="+document.title, true);
  httpRequest.onreadystatechange= function () {zobrDialog()};
  httpRequest.send(null);
  }

function zobrDialog()
  {
  if (httpRequest.readyState == 4)
    {
    if(httpRequest.status == 200)
      {
      var prvek = document.getElementById("preposlatmailem");
      prvek.innerHTML = httpRequest.responseText;
      }
    }
  }


function mail_odeslat()
  {
  //kontrola jestli jsou vyplneny udaje
  var email=document.getElementById('komu').value;
  var emailfrom=document.getElementById('odkoho').value;
  var jmeno=document.getElementById('jmeno').value;
  var vzkaz=document.getElementById('vzkaz').value;
  if (email=='')
    {
	alert('Je zapotřebý vyplnit e-mailovou adresu, kam se má odkaz zaslat');
	}
  else
    {
    //pokud ano, zavolam odesilaci skript
	odeslat('/poslat-znamemu',document.getElementById('form1'));
	}
  return false;
  }

//////////////////////////////////////////////////////////////
function odeslat(soub,form)
  {
  return post_xmlhttprequest(function (xmlhttp) {
        if (xmlhttp.readyState == 4)
		  {
          var prvek = document.getElementById("preposlatmailem");
          prvek.innerHTML = xmlhttp.responseText;
          }
    }, soub, form);
  }

function post_xmlhttprequest(state_change, url, form, headers)
  {
  var elements = form.elements;
  var content = [];
  for (var i=0; i < elements.length; i++)
    {
    if (elements[i].attributes.name && elements[i].attributes.name.specified && !elements[i].disabled)
	  {
      if (/^(select)$/i.test(elements[i].tagName))
	    {
        var options = elements[i].options;
        for (var j=0; j < options.length; j++)
		  {
          if (options[j].selected)
		    {
            var value = (options[j].attributes.value && options[j].attributes.value.specified ? options[j].value : options[j].text);
            content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(value));
            }
          }
        }
	  else if (!/^(submit|reset|button|file|image)$/i.test(elements[i].type) && (!/^(radio|checkbox)$/i.test(elements[i].type) || elements[i].checked))
	    {
        content.push(encodeURIComponent(elements[i].name) + '=' + encodeURIComponent(elements[i].value));
        }
      }
    }
  if (!headers)
    {
    headers = {};
    }
  headers['Content-Type'] = 'application/x-www-form-urlencoded';
  
  return send_xmlhttprequest(state_change, 'POST', url, content.join('&'), headers);
  }

function send_xmlhttprequest(state_change, method, url, content, headers)
  {
  var xmlhttp = (window.XMLHttpRequest ? new XMLHttpRequest() : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : false));
  if (!xmlhttp) return false;
  xmlhttp.open(method, url);
  xmlhttp.onreadystatechange = function () {state_change(xmlhttp);};
  headers = headers || {};
  headers['X-Requested-With'] = headers['X-Requested-With'] || 'XMLHttpRequest';
  for (var key in headers) xmlhttp.setRequestHeader(key, headers[key]);
  xmlhttp.send(content);
  return true;
  }


