function setCookie(name, value) {
	expires = new Date();
	expires.setTime(expires.getTime() + 1000*60*60*24);
	document.cookie = name + '=' + value + "; expires=" + expires.toGMTString() + "; path=/";
}
function getCookie(name) {
	var search = name + '=';
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) {
			offset += search.length;
			end = document.cookie.indexOf(';', offset);
			if (end == -1) {end = document.cookie.length;}
			return unescape(document.cookie.substring(offset, end));
		} else { return '';}
	} else { return ''; }
}
function deleteCookie(name) {
	if (getCookie(name)) { document.cookie = name + "=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT"; }
}

function mailto(before, after, do_action) {
	if (do_action == "link") {
		document.write("<a href=\"mailto:"+before+"@"+after+"\">"+before+"@"+after+"</a>");
	} else if (do_action == "text") {
		document.write(before+"@"+after);
	} else if (do_action == "open") {
		window.open("mailto:"+before+"@"+after);
	}
}

function check_form(f) {
	err = "";
	for (i=0; i<f.elements.length; i++) {
		if (f.elements[i].id != "") {
			if ($("#"+f.elements[i].id).hasClass("required") && !f.elements[i].disabled && $("#"+f.elements[i].id).css("display")!="none") {
				lbl = $("#l_"+f.elements[i].id).html();
				if (f.elements[i].type == "checkbox") {
					if (f.elements[i].checked == false) {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}
				} else {
					if (f.elements[i].value == "") {
						err += "      - "+removeHTMLTags(lbl.replace(":*", "").replace(":", ""))+"\n";
					}
				}
			}
		}
	}
	if (err != "") {
		alert("Nezadali ste tieto údaje:\n"+err);
		return false;
	} else {
		return true;
	}
}

function do_bookmark() {
	var agt=navigator.userAgent.toLowerCase();
	var major = parseInt(navigator.appVersion);
	if ( ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) && (major >= 4) ) {
		window.external.AddFavorite(window.top.document.location, window.top.document.title);
	} else {
		alert("Na pridanie stránky k obľúbeným stlačte Ctrl+D.");
	}
}
function do_send() {
	url = document.location.toString().replace("index.php", "content.php");
	if (url.indexOf("?") == -1) { url = url+"?action=send"; } else { url = url+"&action=send"; }
	_open(url, "SiteLabSendPage", "375", "275");
}
function do_print() {
	url = document.location.toString().replace("index.php", "content.php");
	if (url.indexOf("?") == -1) { url = url+"?action=print"; } else { url = url+"&action=print"; }
	_open(url, "_blank", "640", "480");
}

function _open(wURL, wName, wWidth, wHeight) {
	return window.open(wURL, wName, "width="+wWidth+",height="+wHeight+",top="+((screen.availHeight-wHeight)/2)+",left="+((screen.availWidth-wWidth)/2)+"");
}

function removeHTMLTags(str) {
	str = str.replace(/&(lt|gt);/g, function (strMatch, p1) {
		return (p1 == "lt")? "<" : ">";
	});
	var str = str.replace(/<\/?[^>]+(>|$)/g, "");
	return str;
}	



var isIE = document.all?true:false;
var isNS = document.layers?true:false;
function onlyInteger(myfield,e) {
	var _ret = true;
	if (isIE) {
		if ((window.event.keyCode < 48 || window.event.keyCode > 57) && window.event.keyCode != 45) { window.event.keyCode = 0; _ret = false; }
		if (window.event.keyCode == 45) { if (myfield.value.indexOf("-") != -1) { window.event.keyCode = 0; _ret = false; } }
	}
	if (isNS) {
		if ((e.which < 48 || e.which > 57) && e.which != 45) { e.which = 0; _ret = false; }
		if (e.which == 45) { if (myfield.value.indexOf("-") != -1) { e.which = 0; _ret = false; } }
	}
	return (_ret); 
}
function onlyReal(myfield,e) {
	var _ret = true;
	if (isIE) {
		if ((window.event.keyCode < 48 || window.event.keyCode > 57) && window.event.keyCode != 46 && window.event.keyCode != 44) { window.event.keyCode = 0; _ret = false; }
		if (window.event.keyCode == 44) { window.event.keyCode = 46; }
		if (window.event.keyCode == 46) { if (myfield.value.indexOf(".") != -1) { window.event.keyCode = 0; _ret = false; } }
	}
	if (isNS) {
		if ((e.which < 48 || e.which > 57) && e.which != 46 && e.which != 44) { e.which = 0; _ret = false; }
		if (e.which == 44) { e.which = 46; }
		if (e.which == 46) { if (myfield.value.indexOf(".") != -1) { e.which = 0; _ret = false; } }
	}
	return (_ret); 
}

function onlyChars(myfield,e,def_only,def_chrs) {
	if (def_only) { var _ret = false; } else { var _ret = true; }
	if (isIE) { keyCode = window.event.keyCode; }
	if (isNS) { keyCode = e.which; }
	for (i=0; i<=def_chrs.length; i++) {
		if (def_only) {
			if (String.fromCharCode(keyCode) == def_chrs.substr(i,1)) { _ret = true; }
		} else {
			if (String.fromCharCode(keyCode) == def_chrs.substr(i,1)) { _ret = false; }
		}
	}
	if (isIE) { if (!_ret) { window.event.keyCode = 0; } }
	if (isNS) { if (!_ret) { e.which = 0; } }
	return (_ret); 
}

function formatNum(expr,decplaces) {
	var str = (Math.round(parseFloat(expr) * Math.pow(10,decplaces))).toString();
	while (str.length <= decplaces) { str = "0" + str; }
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
function formatInt(expr,ln) {
	var str = expr.toString();
	while (str.length < ln) { str = "0" + str; }
	return str;
}
