// JavaScript Document
    function KatUkSk(coK){
      displ = document.getElementById('coK'+coK).style.display;
    	if(displ==''){
    	  document.getElementById('coK'+coK).style.display='none';
    		document.getElementById('coIK'+coK).src='/img/tree-c.gif';
    	}else{
    	  document.getElementById('coK'+coK).style.display='';
    		document.getElementById('coIK'+coK).src='/img/tree-o.gif';
      }
    }
// Zobrazí popup okno s obrázkem
function PopupPic(sPicURL, imageWidth, imageHeight)
{
	var elemId = "popup-image";
	var NS = (navigator.appName=="Netscape")?true:false;
	var el = document.getElementById(elemId);
	if (el)
	{
		document.body.removeChild(el);
	}

	el = document.createElement('img');
	el.setAttribute('src', sPicURL);	
	el.style.position = 'absolute';
	el.style.visibility = 'hidden';
	el.style.padding = '0px';
	//el.style.-moz-border-radius = '5px';
	//el.style.-webkit-border-top-right-radius = '5px';

	// border (CSS rule)
	el.style.border = '2px solid #E4E4E4';
	el.style.zIndex = '999';
	el.style.cursor = 'pointer';
	el.title = "";
	el.id = elemId;
	
	// click to close
	if (window.addEventListener)
		el.addEventListener('click', doPopupClick, false);
	else if (window.attachEvent)
		el.attachEvent('onclick', doPopupClick);

	document.body.appendChild(el);

	// centre the image
	if (this.innerHeight) {
		windowHeight = this.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowHeight = document.body.clientHeight;
	}
	if (this.innerWidth) {
		windowWidth = this.innerWidth;
	} else if (document.documentElement && document.documentElement.clientWidth) {
		windowWidth = document.documentElement.clientWidth;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
	}
	
	// Scrollbars
	if (this.pageYOffset != null)
		offsetY = this.pageYOffset;
	else if (document.body.scrollTop != null)
		offsetY = document.documentElement.scrollTop;
	if (this.pageXOffset != null)
		offsetX = this.pageXOffset;
	else if (document.body.scrollLeft != null)
		offsetX = document.documentElement.scrollLeft;
	
	// Zdroj velikosti okna
	if (imageWidth <= 0)
		imageWidth = el.offsetWidth;
	if (imageHeight <= 0)
		imageHeight = el.offsetHeight;	
	
	// Případné omezení velikosti příliš velkého obrázku (zatím upravujeme jen jeden, aby se zachovali proporce)
	/*if (imageHeight > windowHeight)
	{
		var oldWidth = el.width;
		if (oldWidth == 0)
			oldWidth = imageWidth;
		
		el.height = windowHeight - windowHeight / 6;
		var ratio = el.height / imageHeight;
		imageHeight = el.height;
				
		// dopocitani sirky
		el.width = imageWidth * ratio;
		imageWidth = el.width;
	}
	if (imageWidth > windowWidth)
	{
		var oldHeight = el.height;
		if (oldHeight == 0)
			oldHeight = imageHeight;
		
		el.width = windowWidth - windowWidth / 6;
		var ratio = el.width / imageWidth;
		imageWidth = el.width;
				
		// dopocitani vysky
		el.height = imageHeight * ratio;
		imageHeight = el.height;
	}
*/
	// Pozice okna
	el.style.left = (windowWidth / 2 - imageWidth / 2 + offsetX).toString() + 'px';
	el.style.top = (windowHeight / 2 - imageHeight / 2 + offsetY).toString() + 'px';

	el.style.visibility = 'visible';
}

function doPopupClick(e)
{
	var obj = e.target || e.srcElement;
	obj.parentNode.removeChild(obj);
}

// Ajax ----------------------------------------------------------------

function UpateModel(){
  if (xmlHttp){
    try{
      //nacte cenu s DPH
      path="/aj-model.php?ch=1&V=" + document.c.V.value;
      xmlHttp.open("get", path, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.send(null);
    }catch (e){
      alert("Operaci se nepovedlo provést!\n");
    }
  }
}

function handleServerResponse()
{
  var response = xmlHttp.responseText;
  if (response.indexOf("ERRNO") >= 0 
      || response.indexOf("error:") >= 0
      || response.length == 0)
    throw(response.length == 0 ? "Prazdna odpoved serveru." : response);
    var myDiv = document.getElementById("mymodel");
    myDiv.innerHTML = response;
}
// function called when the state of the HTTP request changes
function handleRequestStateChange() 
{
  if (xmlHttp.readyState == 4) 
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200){
     // try{
        handleServerResponse();
      //}catch(e){
       // alert("Error cteni odpovedi serveru: " + e.toString());        // display error message
      //}
    }else{
      alert("Problem s inicializaci dat:\n" + xmlHttp.statusText); 
    }
  }
}
var xmlHttp = createXmlHttpRequestObject();

function createXmlHttpRequestObject() {
  var xmlHttp;
  try
  {
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    var XmlHttpVersions = new Array(
                                    "MSXML2.XMLHttp.7.0",
                                    "MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  if (!xmlHttp)
    alert("Operace se nezdařila."); //return false;
  else 
    return xmlHttp;
}

