var xmlDocFce;
var xmlDocString;

function OnCallbackStart()
{
	//getID("divLoading").style.display = "block";
	$.blockUI('<strong style="font-size:20px;"><img src="/gfx/indicator.gif" /> Čekejte prosím...</strong>'); 
}
function OnCallbackEnd()
{
	//getID("divLoading").style.display = "none";
	$.unblockUI();
}
function GetRadWindow()
{
	var oWindow = null;
	if (window.radWindow) oWindow = window.radWindow;
	else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
	return oWindow;
}
function CloseRadWindow()
{
	var oWindow = GetRadWindow();
	if (arguments[0] != null && arguments[1] != null) {
		var obj = new Object();
		obj.Event = arguments[0];
		obj.Argument = arguments[1];
		oWindow.CallBack(obj);
	} else {
	    if (arguments[0] != null)
	        oWindow.Callback(arguments[0]);
	    else
		    oWindow.Close();
    }
}
function HideLoading() 
{
	try {
		document.getElementById("divLoading").style.display = "none";
	} catch (e) {}
}

function ShowHits(tab, id) {
	window.open("ShowHits.aspx?tab=" + tab + "&id=" + id, "_blank", "resizable=yes,scrollbars=yes,height=500px,width=500px");
}

function loadXMLDoc(url, fce) {
	xmlDocFce = fce;
	
	req = false;
    if(window.XMLHttpRequest) {
    	try {
			req = new XMLHttpRequest();
        } catch(e) {
			req = false;
        }
    } else if(window.ActiveXObject) {
       	try {
        	req = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		req = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		req = false;
        	}
		}
    }
   
	if (req) {
		req.onreadystatechange = processReqChange;
		req.open("GET", url, true);
		req.send("");
	}
}
function processReqChange() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			eval(xmlDocFce + "(req.responseText);");
		} else {
			alert("There was a problem retrieving the data:\n" + req.statusText);
		}
	}
}
function CKomentar_Enlarged(o, id) {
	document.getElementById("komentar"+id).style.display = o.checked ? "block" : "none";
}
function ResetDTPTime(id) {
	if (!(parseInt(document.getElementById("hod"+id).value) > 0 || parseInt(document.getElementById("min"+id).value) > 0))
	{
		document.getElementById("hod"+id).value = "00";
		document.getElementById("min"+id).value = "00";
	}
}
function setPageCommandSubmit(commandName, commandArgument, commandArgument2)
{
	setPageCommand(commandName, commandArgument, commandArgument2);
	document.forms[0].submit();
}
function setPageCommand(commandName, commandArgument, commandArgument2)
{
	document.getElementById("__OTTIK_COMMAND").value = commandName;
	document.getElementById("__OTTIK_COMMAND_ARGUMENT").value = commandArgument;
	document.getElementById("__OTTIK_COMMAND_ARGUMENT2").value = commandArgument2;
}
function OpenPreview(url) {
	window.open(url, "preview", "scrollbars=yes,width=600px");
}
function PicgalSelect_Vybrat(ctrl,druh) 
{
	window.open("/obrazky.aspx?link=1&druh=" + druh + "&ctrl=" + ctrl, "_blank", "width=650px,height=530px,scrollbars=yes,resizable=yes");
}
function PicgalSelect_Vybrat3(link)
{ 
	var r = prompt("Title obrazku:", "");
	if (r != null)
	{
		var returnValue = 
		{
			path:link,
			title:r
		};
		self.opener.callBackFunctionPtr(returnValue);
		self.close();
	}
}
function PicgalSelect_Vybrat2(ctrl, obrazek)
{
	try {
		self.opener.document.getElementById(ctrl).value = obrazek;
		if (self.opener.document.getElementById(ctrl + "_img") != null) {
			self.opener.document.getElementById(ctrl + "_img").src = self.opener._PicgalSelectImagePath + obrazek;
			self.opener.document.getElementById(ctrl + "_img").style.display = "block";
		}
		if (self.opener.document.getElementById(ctrl + "_rem") != null) {
			self.opener.document.getElementById(ctrl + "_rem").style.display = "block";
		}
	} catch (e) {}
	self.close();
}
function PicgalSelect_Smazat(ctrl)
{
	try {
		document.getElementById(ctrl).value = "";
		document.getElementById(ctrl + "_img").style.display = "none";
		document.getElementById(ctrl + "_rem").style.display = "none";
	} catch (e) {}
}
function getID(s) {
	return document.getElementById(s);
}

function setNadpis(s_nadpis) {
	if (self.name == "o_mainframe" && self.parent.frames("o_topframe").document.getElementById("nadpis") != null) {
		self.parent.frames("o_topframe").document.getElementById("nadpis").innerHTML = s_nadpis;
	}
}
function trim(s_in) {
	s_in.replace(" ", "");
	s_in.replace("\n", "");
	return (s_in);
}
function make_number(val) {
	var re = /,/;
	val = val.toString().replace(re, ".");
	var i = new Number(val);
	return i;
}
function make_string(val) {
	var re = /\./;
	val = val.toString().replace(re, ",");
	return val;
}
function myround(k) {
	var i = k * 10;
	i = Math.round(i);
	return (i / 10);
}
function getID(id) {
	return (document.getElementById(id));
}

function control_date(date_in) {
	var re = /^(([1-9])|([0-2]?[0-9])|(3[01]))\.(([1-9])|([0]?[1-9])|(1[0-2]))\.(199[0-9])|(20[0-9][0-9])$/;
	return re.test(date_in);
}

function control_time(time_in) {
	var re = /^(([0-1]?[0-9])|(2[0-3])):(([0-5]?[0-9])|(60)):(([0-5]?[0-9])|(60))$/;
	if (re.test(time_in)) {
		return (true);
	} else {
		re = /^([0-9]{1,4}):(([0-5]?[0-9])|(60))$/;
		return (re.test(time_in));
	}
}

function control_money(money_in) {
	var re = /^[0-9]$/;
	var re2 = /^[0-9].[0-9]{1,2}$/;
	return (re.test(money_in) || re2.test(money_in));
}

function control_time_obj(obj) {
	if (!control_time(obj.value)) {
		window.alert(__FormatCasu	);
		obj.focus();
		return false;
	} else {
		return true;
	}
}

function control_date_obj(obj) {
	if (!control_date(obj.value)) {
		window.alert(__FormatData);
		obj.focus();
		return false;
	} else {
		return true;
	}
}

function control_email(mail) {
	var re = /^[_a-zA-Z0-9-]*@[a-zA-Z0-9-.]*\.([a-zA-Z]{2,3})$/;
	return (re.test(mail));
}

function key_check(keycode, func, element) {
	var x = String.fromCharCode(keycode);
	var re = null;
	var r = true, i, j;
	
	switch(func) {
		case "mail_key":
			re = /[a-zA-Z0-9_\.@]/;
			r = re.test(x);
			break;
		case "password_key":
			re = /[a-zA-Z0-9_?!*+-]/;
			r = re.test(x);
			break;
		case "num_key":
			re = /[0-9]/;
			r = re.test(x);
			break;
		case "num_key_minus":
			re = /[0-9\-]/;
			if (r = re.test(x)) {
				if (x == "-" && element.value.length > 0) return(false);
			}
			break;
		case "date_key":
			re = /[0-9.]/;
			if (r = re.test(x)) {
				if (element.value.length == 10 && x != ".") {
					element.value = "";
				} else {
					i = element.value.indexOf(".");
					j = element.value.indexOf(".", i+1);
					if (i != -1 && j != -1 && x == ".") return (false);
					if (i == -1 && element.value.length == 2 && x != ".") element.value += ".";
					if (j == -1 && x != "." && (element.value.length - i) == 3) element.value += ".";
				}
			}
			break;
		case "money_key":
		case "num_key_comma":
			re = /[0-9,\-]/;
			if (r = re.test(x)) {
				if (x == "-" && element.value.length > 0) return(false);
				i = element.value.indexOf(",");
				if (i != -1 && x == ",") return (false);
			}
			break;
		case "time_key":
			if (x == ".") {
				x = ":";
				event.keyCode = 58;
			}
			re = /[0-9:]/;
			if (r = re.test(x)) {
				if (element.value.length == 5 && x != ":") {
					element.value = "";
				} else {
					if (element.value.length == 0 && x == ":") return (false);
					i = element.value.indexOf(":");
					if (i != -1 && x == ":") return (false);
					if (element.value.length == 2 && i == -1 && x != ":") element.value += ":";
				}
			}
			break;
		case "longtime_key":
			if (x == ".") {
				x = ":";
				event.keyCode = 58;
			}
			re = /[0-9:]/;
			if (r = re.test(x)) {
				if (element.value.length == 0 && x == ":") return (false);
				i = element.value.indexOf(":");
				if (i != -1 && x == ":") return (false);
			}
			break;
		case "tel_key":
			re = /[0-9+ ]/;
			r = re.test(x);
			break;
	}
	return (r);
}

function find_element_by_id(parent_element, id) {
	var l = id.length;
	for (var i=0; i < parent_element.children.length; i++) {
		if (parent_element.children(i).id.substr(0, l) == id) return (parent_element.children(i));
	}
	return (null);
}

function controlInputs(f) {
	var e;
	for (var i=0; i < f.elements.length; i++) {
		e = f.elements(i);
		if (e.fcont != null) {
			if (e.value == "" && e.fcont == "1") {
				alert(__PovinnePole);
				e.focus();
				return(false);
			} else {
				if (e.func != null && ((e.fcont == "2" && e.value != "") || e.fcont != "2")) {
					switch (e.func) {
					case "date_key":
						if (!control_date_obj(e)) return(false);
						break;
					case "time_key":
						if (!control_time_obj(e)) return(false);
						break;
					}
				}
			}
		}
	}
	return(true);
}

function find_next_tab(col, tab, iter, bTabIndex) {
	if (++iter > col.length) return(null);
	var tab2 = 0;
	
	loop:
	for (i = 0; i < col.length; i++) {
		tab2 = (bTabIndex ? col[i].tabIndex : col[i].sourceIndex);
		if (tab == tab2) {
			var nm = col[i].tagName.toLowerCase();
			//if (col[i].style.display != "none" && col[i].style.visibility != "hidden" && (nm == "select"  || nm == "textarea" || nm == "button" || (nm == "input" && col[i].isContentEditable))) {
			if (col[i].style.display != "none" && col[i].style.visibility != "hidden" && (nm == "select"  || nm == "textarea" || nm == "button" || nm == "input")) {
				return (col[i]);
			} else {
				break loop;
			}
		}
	}
	
	return (find_next_tab(col, ++tab, iter, bTabIndex));
}


