if(typeof window.addEventListener != 'undefined') {
	window.addEventListener('load', addAnchors, false);
	window.addEventListener('load', attachFormHandlers, false);
}
else if(typeof document.addEventListener != 'undefined') {
	document.addEventListener('load', addAnchors, false);
	document.addEventListener('load', attachFormHandlers, false);
}
else if(typeof window.attachEvent != 'undefined') {
	window.attachEvent('onload', attachFormHandlers);
	window.attachEvent('onload', addAnchors);
}
else {
	if(typeof window.onload == 'function') {
		var existing = onload;
		window.onload = function() {
			existing();
			attachFormHandlers; addAnchors;
		}
	}
	else
	{
		window.onload = attachFormHandlers; addAnchors;
	}
}

// Kalkulacka
function attachFormHandlers() {
	if (document.getElementById) {
		var myForm = document.getElementById('calc');
		if (!myForm) return;
		for (var a=0; a<myForm.length; a++) {
            myForm[a].onchange = function(){
                return checkChanges(this.form);
			}
		}
	}
}

// Odkazy s class='popup';
function addAnchors()
{
    var arClass;
    var anchors = document.getElementsByTagName('a');
    if (!anchors) return;

    for (var i=0; i<anchors.length; i++)
    {
        // Allow for multiple values being assigned to the class attribute
        arClass = anchors[i].className.split(' ');
        for (var x=0; x<arClass.length; x++)
        {
            if (arClass[x] == 'popup'){
                anchors[i].onclick = openPopup;
                anchors[i].title += 'Otevře se nové okno se zvětšeným obrázkem';
            }
        }
    }
}

function openPopup() {
    var windowTop = 100;                // Top position of popup
    var windowLeft = 100                // Left position of popup
    var defaultWidth = 500;             // Default width (for browsers that cannot resize)
    var defaultHeight = 500;            // Default height (for browsers that cannot resize)
    var onLoseFocusExit = true;         // Set if window to exit when it loses focus
    var undefined;


    var caption = this.firstChild.getAttribute('alt');

    var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",resizable"

    var myScript = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
    "<html>\n" +
    "<head>\n" +
    "<title>" + caption + "\</title>\n" +
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
        "  var width = document.myimage.width;\n" +
        "  var height = document.myimage.height;\n";

        // Netscape
        if (navigator.appName.indexOf("Netscape") != -1) {
            myScript = myScript +  "  window.innerHeight = height;\n  window.innerWidth = width;\n"
        }

        // Opera
        else if (navigator.appName.indexOf("Opera") != -1) {
            myScript = myScript +  "  window.resizeTo (width+12, height+31);\n"
        }

        // Microsoft
        else if (navigator.appName.indexOf("Microsoft") != -1) {
            myScript = myScript + "  window.resizeTo (width+12, height+45);\n"
        }

        // Assume a frig factor for any other browsers
        else {
            myScript = myScript + "  window.resizeTo (width+14, height+34);\n"
        }

    myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";

    if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}

    myScript = myScript + "style=\"margin: 0; padding: 0;\">\n" +
    "<img src=\"" + this.getAttribute('href') + "\" alt=\"" + caption + "\" name=\"myimage\">\n" +
    "</body>\n" +  "</html>\n";

    var imageWindow = window.open ("","imageWin",Options);
    imageWindow.document.write (myScript)
    imageWindow.document.close ();
    if (window.focus) imageWindow.focus();
    return false;
}


function sendFromZapatec() {
	var obj = document.getElementById(this.button.id);
	if (obj) {
		searchStatus('1');
		obj.form.submit();
	}
}


function addGoInput(objF,inputVal) {
	var newInput = document.createElement("input");
	newInput.name="go_to";
	newInput.type="hidden";
	newInput.value=inputVal;
	objF.appendChild(newInput);

	return true;
}

function searchStatus (str) {
	var status = document.getElementById("searchstatus");
	if (status) {
		switch (str) {
			case "1":
				status.innerHTML = 'Čekejte prosím, provádím hledání ...';
				break;
			default:
				status.innerHTML = 'Čekejte prosím, upřesňuji vyhledávací filtr ...';
				break;
		}
	}

}


function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function ProtiBotum() {
	if (document.getElementById("form") && document.getElementById("antibotinput")) {
		document.getElementById("antibotvalue").value = 5;
		document.getElementById("antibotinput").style.display = "none";
	}
}
addLoadEvent(ProtiBotum);