﻿
// lang -- predavana z aplikace
// msgConfirmVarDelete
// spamName -- predavana z aplikace v pripade spam controlu

function BuSelectGet (el) {
	for (var i=0; i < el.length; ++i) {
		if (el[i].selected) return el[i].value;
	}
	return undefined;
}

function ZmenJazyk() {
	var nlang = "";
	var sel = document.forms[0].selJazyky;
	if (sel) {
		nlang = BuSelectGet(sel);
		var adr = window.location.href;
		if (adr.indexOf("l="+lang) > 0) {
			adr = adr.replace("l="+lang, "l="+nlang);
		} else {
			var sep = "&";
			if (window.location.search == "") sep = "?";
			adr += sep + "l=" + nlang;
		}
		window.location.href = adr;
	}
}

function ZmenFiltraci() {
	var sel = document.forms[0].selCategory;
	if (sel) {
		var targetID = BuSelectGet(sel);
		var s = document.location.search;
		var n = "r="+targetID;
		var sn = s.replace(/r=\d*/, n);
		if (s == sn) sn = (s == "") ? "?"+n : s+"&"+n;
		document.location.href = document.location.pathname + sn;
	}	
}


// link pro editaci promenne - pripadne lze predat control, na ktery se bude vracet
function OpenVariable(varName, ctrl, a) {
	if (ctrl == null) ctrl = "";
	var b = "b";
	if (a != null) b = "bb"
	document.location.href = "main.aspx?v=" + varName + "&" + b + "=" + ctrl + "&l=" + lang;
}
// link pro pridani promenne - pripadne lze predat control, na ktery se bude vracet
function AddVariable(colName, ctrl) {
	if (ctrl == null) ctrl = "";
	document.location.href = "main.aspx?a=" + colName + "&b=" + ctrl + "&l=" + lang;
}
// link pro zobrazeni controlu
function OpenControl(ctrlName) {
	document.location.href = "main.aspx?c=" + ctrlName + "&l=" + lang;
}
// -- spammers --
function OpenSpammer(ctrlName) {
	document.location.href = "main.aspx?s=" + ctrlName + "&l=" + lang;
}
function OpenSpammerAkce(akce, spamId, param) {
	var adr = "main.aspx?s=" + spamName + "&l=" + lang + "&p1=" + akce + "&p2=" + spamId;
	if (param) adr += "&p3=" + param;
	document.location.href = adr;
}

function HiT(el) {
	el.style.textDecoration = "underline";
}
function LoT(el) {
	el.style.textDecoration = "";
}

function ImgEdit(type, field, imgID) {
	// type se predava, aby se z config souboru daly nacist potrebne udaje
	var isIE = !window.innerHeight; // jedna se se o IE nebo M?
 	var s = "no";
	if (!isIE) s = "yes";
	var href = "imgLoad.aspx?t=" + type + "&f=" + field + "&i=" + imgID;
	var wname = "imgLoad" + type + field;
	wname = wname.replace(/[^a-zA-Z0-9]/gi, "");
	var w = window.open(href, wname, "width=600, height=570, scrollbars="+s+", resizable=yes");
	w.focus();
}
function SimpleImgEdit(type, field, imgID) {
	// type se predava, aby se z config souboru daly nacist potrebne udaje
	var isIE = !window.innerHeight; // jedna se se o IE nebo M?
 	var s = "no";
	if (!isIE) s = "yes";
	var href = "imgSimpleLoad.aspx?t=" + type + "&f=" + field + "&i=" + imgID;
	var wname = "imgSimpleLoad" + type + field;
	wname = wname.replace(/[^a-zA-Z0-9]/gi, "");
	var w = window.open(href, wname, "width=600, height=540, scrollbars="+s+", resizable=yes");
	w.focus();
}

function SetImg (field, imgID) {
	var F = document.forms[0];
	var h = F[field];
	if (h && h.value) h.value = imgID;
	F.submit();
}

function FileEdit(type, field, fileID) {
	var isIE = !window.innerHeight; // jedna se se o IE nebo M?
 	var s = "no";
	if (!isIE) s = "yes";
	var href = "fileLoad.aspx?t=" + type + "&f=" + field + "&i=" + fileID;
	var wname = "fileLoad" + type + field;
	wname = wname.replace(/[^a-zA-Z0-9]/gi, "");
	var w = window.open(href, wname, "width=600, height=540, scrollbars="+s+", resizable=yes");
	w.focus();
}
function SetFile (field, fileID) {
	var F = document.forms[0];
	var h = F[field];
	if (h && h.value) h.value = fileID;
	F.submit();
}
function OpenFile (href) {
	window.location.href = href;
}
function FileColEdit(vType, fieldName, idx, value) {
	var F = document.forms[0];
	F[fieldName + "Idx"].value = idx;
	FileEdit(vType, fieldName, value);
}


function DeleteVar() {
	return confirm(msgConfirmVarDelete);
}

function OpenAdmin(href) {
	var sep = "&";
	if (href.indexOf("?") == -1) sep = "?";
	window.location.href = href + sep + "l=" + lang;
}

function ImgColEdit (vType, fieldName, idx, value) {
	var F = document.forms[0];
	F[fieldName + "Idx"].value = idx;
	ImgEdit(vType, fieldName, value);
}
/*
function ImgEdit(type, field, imgID) {
	// type se predava, aby se z config souboru daly nacist potrebne udaje
	var isIE = !window.innerHeight; // jedna se se o IE nebo M?
 	var s = "no";
	if (!isIE) s = "yes";
	var href = "imgLoad.aspx?t=" + type + "&f=" + field + "&i=" + imgID;
	var wname = "imgLoad" + type + field;
	var w = window.open(href, wname, "width=600, height=540, scrollbars="+s+", resizable=yes");
	w.focus();
}
*/
function WOpenWindow (href, name) {
	if (name == undefined) name = "";
	var okno = window.open(href, name, "");
	okno.focus();
}
function QuestionReset() {
	// TODO: 
	if (confirm("Opravdu vynulovat?")) {
		document.forms[0].hQAAkce.value = 9;
		document.forms[0].submit();
	}
}

// =============================================================================


