// requires Dom v1.71
// initialisation of library objects


var debug = false;
var nbsp = String.fromCharCode(160); // non-breaking space


function exceptionError(ex, location) {
	// critical exception handler
	var result = "JavaScript exception: " + ex.name+"\n";
	result += "Error message: " + ex.message + "\n";
	result += "Error location: " + location + "\n";
	alert(result);
}

function exceptionWarning(ex, location) {
	// non-critical exception handler
	if (debug) {
		var result = "JavaScript exception: " + ex.name+"\n";
		result += "Warning message: " + ex.message + "\n";
		result += "Warning location: " + location + "\n";
		alert(result);
	};
}


// custom functions
function setTarget(link) {
	if (link.href) {
		var domain = document.location.host;
		// Obsahuje-li domain port, odstranime ho
		if (domain) domain = (domain.indexOf(":")>-1)? domain.substr(0,domain.indexOf(":")): domain;
		var host = link.host;
		// Obsahuje-li host port, odstranime ho
		if(host) host = (host.indexOf(":")>-1)? host.substr(0,host.indexOf(":")): host;
		var protocol = link.protocol;
		if ((host != domain) && (host != ("www."+domain) && ("www."+host) != domain)&&((protocol == "http:") || (protocol == "https:") || (protocol == "ftp:"))) {
			// jestlize se domena dokumentu a odkazu neshoduji, otevirani nastavime do noveho okna
			link.target="_blank";
//			if (!cls.has(link,"noIcon")) addIcon(link,newWindowIcon,"after");
		}
		return true;
	}
	else return false;
}

function addContent(item, contentString, position) {
	try {
		var cnt = document.createTextNode(contentString);
		if (position == "before") item.insertBefore(cnt.cloneNode(true), item.firstChild);
		else item.appendChild(cnt.cloneNode(true));
		return true;
	} catch (ex) {
		alert("addContent error "+ex);
		return false;
	}
}

function addIcon(item, iconImage, position, iconTitle) {
	try {
		space = document.createTextNode(nbsp)
		icon = document.createElement("img");
		icon.src = iconImage;
		icon.alt = "*";
		if (typeof iconTitle != "undefined") {
			icon.title = iconTitle;
			icon.alt = iconTitle;
		};
		icon.className = "icon";
		if (position == "before") {
			item.insertBefore(space, item.firstChild);
			item.insertBefore(icon, item.firstChild);
		} else {
			item.appendChild(space);item.appendChild(icon);
		};
	} catch (ex) {}
	return true;
}

function openImageWindow(e){
	link = evt.getTarget(e);
	while (link.tagName.toLowerCase()!="a")
		link = link.parentNode;
	link.target = "_blank";
}

function getChildrenByTag(tagName, srcElm) {
	try{
		if(document.getElementsByTagName){
			tagName = tagName.toLowerCase();
			srcElm = (srcElm) ? srcElm : document;
			foundElements = [];
			if(srcElm.all) allElements = srcElm.all;	// IE hack
			else allElements = srcElm.getElementsByTagName(tagName);
			for(var i = 0; i < allElements.length; i++)
				if((tagName == "*") || (allElements[i].tagName.toLowerCase() == tagName.toLowerCase()))
						if(allElements[i].parentNode == srcElm)
							foundElements[foundElements.length] = allElements[i];
			return(foundElements);
		}
		else return([]);
	}
	catch(ex) {alert("getChildrenByTag error ("+ex.name+"): "+ex.message);return(false);}
}


// end of custom functions
