<!--

/*	
	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	drobne fce aplikace actavia by ivosan; (C) ivo andrle

  	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/

vSuppOK = (
	((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) >= 3 )) ||
	((navigator.appName == 'Microsoft Internet Explorer') && (parseInt(navigator.appVersion) >= 4 ))
);

var defStatus = '';

var statTimer 			= null;			//...timer - smazani status row
var statTimerRunning 	= false;			//...timer jede
var statNoTimer 		= false;			//...timer potlacen, nevyvolava se (Start)

var editorSelCol 		= '#FFFEE1';
var editorNoSelCol 		= 'transparent';

var request;

//...odpoved

	function doChallengeResponse() {
		if (document.login.hit.value == 0) {
			document.login.hit.value = 1;

			str = document.login.username.value + ":" + document.login.password.value + ":" + document.login.challenge.value;
			document.login.response.value = MD5(str);
			document.login.password.value = "";
			document.login.screenwidth.value = screen.width;
			document.login.submit();
		}
	}

	function confirmationYes() {
		if (document.confirmation.hit.value == 0) {
			document.confirmation.hit.value = 1;

			document.confirmation.confirmed.value = 1;
			document.confirmation.submit();
		}
	}

	function confirmationNo() {
		if (document.confirmation.hit.value == 0) {
			document.confirmation.hit.value = 1;

			document.confirmation.confirmed.value = 0;
			document.confirmation.submit();
		}
	}

	function confirmaction(txt) {
		if (document.confirmation.hit.value == 0) {
			document.confirmation.hit.value = 1;

			document.confirmation.action.value = txt;
			document.confirmation.submit();
		}
	}

//...status span - prostor pro mouseover
	function setStat(txt) {
		var stbar = document.getElementById('headMOver');
		stbar.innerHTML = txt;
		if (!statNoTimer) {
			if (statTimerRunning) {
				window.clearTimeout(statTimer);
			}
			if (txt != defStatus) {
				statTimer = window.setTimeout('setStat(defStatus, 1)', 999);
				statTimerRunning = true;
			} else statTimerRunning = false;
		}
	}

//...drobnosti

	function pageContainerHideShow (pgname, ThisIsShow) {
		var pagename = 'page_' + pgname;
		var ret = document.getElementById(pagename);
		if (ret)
			ret.style.display = (ThisIsShow ? 'block' : 'none');
	}

	function showHideByDeliveryType() {
		var Opt = document.userform.deliverytype.options;
		if (Opt.selectedIndex == -1) return true;
		var val = Opt[Opt.selectedIndex].value;
		var pg = document.getElementById('page_delinfo');
		if (pg)
			pg.style.display = (val > 0 ? 'block' : 'none');
	}

	function showHideByCompanyType() {
		var Opt = document.userform.companytype.options;
		if (Opt.selectedIndex == -1) return true;
		var val = Opt[Opt.selectedIndex].value;
		var pg = document.getElementById('page_fainfo');
		if (pg)
			pg.style.display = (val > 0 ? 'block' : 'none');
	}

	function noteFocus(item) {
		try {
			var ret = document.getElementById(item.name + 'Note');
			if (ret) {
				ret.style.color = "#999";
			}
		} catch (e) {
			return;
		}
	}

	function noteBlur(item) {
		try {
			var ret = document.getElementById(item.name + 'Note');
			if (ret) {
				ret.style.color = "#fff";
			}
		} catch (e) {
			return;
		}
	}

	function moFocus(item) {
		try {
			var ret = document.getElementById(item + 'Mover');
			if (ret) {
				ret.style.color = "#999";
			}
		} catch (e) {
			return;
		}
	}

	function moBlur(item) {
		try {
			var ret = document.getElementById(item + 'Mover');
			if (ret) {
				ret.style.color = "#fff";
			}
		} catch (e) {
			return;
		}
	}

	function SwapAutNames() {
		var val = document.forms['autsetting'].elements['fname'].value;
		document.forms['autsetting'].elements['fname'].value = document.forms['autsetting'].elements['lname'].value;
		document.forms['autsetting'].elements['lname'].value = val;
	}

	function layComboChng(formname, valname, val, valtxt) {
		try {
			document.forms[formname].elements[valname].value = val;
			var ret = document.getElementById(formname + '_' + valname);
			if (ret) {
				ret.innerHTML = valtxt;
			}
		} catch (e) {
			return;
		}
	}

	function addRoleSubmit() {
		document.allactions.expiration.value = document.expform.expire.value;
		sendAllActAction('addrole');
	}

	function addVipSendSubmit() {
		document.allactions.sendmode.value = document.sendfrm.sendmode.value;
		document.allactions.sentto.value = document.sendfrm.sentto.value;
		sendAllActAction('send');
	}

//...fce specificke pro revisions

	function callUploadAttachment(mode) {
		try {
			if (document.reviewform.hit.value == 0) {
				document.reviewform.hit.value = 1;
				document.reviewform.showupload.value = mode;
				document.reviewform.submit();
			}
		} finally {;
		};
	}

//...editor

	function iEdClickRow(i) {
		try {
			var seleStat = isInArray(edSelRows, i);
			document.getElementById('eTr_'+i).style.background = (seleStat ? editorNoSelCol : editorSelCol);
			if (seleStat) {
				var wasChange = false;
				var newArr = new Array();
				for (id in edSelRows) {
					if (edSelRows[id] == i) {
						var wasChange = true;
					} else newArr.push(edSelRows[id]);
				}
				if (wasChange)
					edSelRows = newArr;
			} else {
				edSelRows.push(i);
			}
			iEdImplode();
		} finally {;}
	}
	
	function iEdClickRowFr(i) {
		try {
			edSelFr = i;
			if (edSelTo < edSelFr) 
				edSelTo = edSelMaxOrd;
			iEdReselectOnBorders();
			iEdImplode();
		} finally {;}
	}
	
	function iEdClickRowTo(i) {
		try {
			edSelTo = i;
			if (edSelFr > edSelTo) 
				edSelFr = edSelMinOrd;
			iEdReselectOnBorders();
			iEdImplode();
		} finally {;}
	}
	
	function iEdSelectAll() {
		try {
			edSelFr = edSelMinOrd;
			edSelTo = edSelMaxOrd;
			iEdReselectOnBorders();
		} finally {;}
	}
	
	function iEdUnselectAll() {
		try {
			edSelFr = 0;
			edSelTo = 0;
			iEdReselectOnBorders();
		} finally {;}
	}
	
	function iEdInvertSel() {
		try {
			var newArr = new Array();
			for (j=edSelMinOrd; j<=edSelMaxOrd; j++) {
				if (document.getElementById('eTr_'+j)) {
					var seleStat = isInArray(edSelRows, j);
					if (!seleStat)
						newArr.push(j);
					document.getElementById('eTr_'+j).style.background = (seleStat ? editorNoSelCol : editorSelCol);
				}
			}
			edSelRows = newArr;
			edSelFr = edSelMinOrd;
			edSelTo = edSelMaxOrd;
		} finally {;}
	}
	
	function iEdReselectOnBorders() {
		try {
			var wasChange = false;
			var newArr = new Array();
			for (id in edSelRows) {
				if (edSelRows[id] < edSelFr || edSelRows[id] > edSelTo) {
					var wasChange = true;
					if (document.getElementById('eTr_'+edSelRows[id]))
						document.getElementById('eTr_'+edSelRows[id]).style.background = editorNoSelCol;
				} else newArr.push(edSelRows[id]);
			}
			if (wasChange)
				edSelRows = newArr;
			for (j=edSelFr; j<=edSelTo; j++) {
				if (document.getElementById('eTr_'+j) && !isInArray(edSelRows, j)) {
					edSelRows.push(j);
					document.getElementById('eTr_'+j).style.background = editorSelCol;
				}
			}
		} finally {;}
	}
	
	function isInArray(arr, val) {
		for (i in arr)
			if (arr[i] == val)
				return true;
		return false;
	}
	
	function iEdImplode() {
		try {
			document.massedit.masskeys.value = edSelRows.join('~');
		} finally {;}
	}

	function photoTagsCopy(addtags) {
		document.allactions.keyw.value = document.keyform.keyw.value;
		sendAllActAction(addtags ? 'addtags' : 'droptags');
	}

//...short news & aktuality

	function showHideByActWSType() {
		try {
			var val = document.snedit.withacts.value;
			var pg = document.getElementById('page_actinfo');
			if (pg)
				pg.style.display = (val > 0 ? 'block' : 'none');
		} finally {;}
	}

//...ajax:

	function getHTTPObject() {
		var htto = false;
		if (window.XMLHttpRequest) {
			htto = new XMLHttpRequest();
		} else if (window.ActiveXObject) {
			try {
				htto = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					htto = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					htto = false;
				}
			}
		}
		return htto;
	}
	
	function clearCont(elem) {
		try {
			var dC = document.getElementById(elem);
			if (dC)
				dC.innerHTML = '';
		} finally {;}
	}

	function getContent(varMode, variant, elem) {
		request = getHTTPObject();
		request.onreadystatechange = 
			function() {
				var dC = document.getElementById(elem);
				if (dC) {
					if (request.readyState == 1) {
						dC.innerHTML = '<img src="/img/loading.gif" style="margin-left: 144px;" alt="Loading..." />  Loading...';
					} else if(request.readyState == 4) {
						dC.innerHTML = request.responseText;
					}
				}
			};
		request.open("GET", "/iajax.php?mode="+varMode+"&var="+variant, true);
		request.send(null);
	}

	function getContent2(requrl, elem) {
		request = getHTTPObject();
		request.onreadystatechange = 
			function() {
				var dC = document.getElementById(elem);
				if (dC) {
					if (request.readyState == 1) {
						dC.innerHTML = '<br/><br/><img src="/img/loading.gif" style="margin-left: 144px;" alt="Loading..." />  Loading...';
					} else if(request.readyState == 4) {
						dC.innerHTML = request.responseText;
					}
				}
			};
		request.open("GET", requrl, true);
		request.send(null);
	}

	function getContent3(requrl, varMode, variant, elem, synch) {
		request = getHTTPObject();
		request.onreadystatechange = 
			function() {
				var dC = document.getElementById(elem);
				if (dC) {
					if (request.readyState == 1) {
						dC.innerHTML = '<br/><img src="/img/loading.gif" style="margin-left: 144px;" alt="Loading..." />  Loading...';
					} else if(request.readyState == 4) {
						dC.innerHTML = request.responseText;
					}
				}
			};
		request.open("GET", requrl+(requrl.indexOf('?') == -1 ? '?' : '&')+"mode="+varMode+"&var="+variant, (synch ? false : true));
		request.send(null);
	}

	function runAjax(JSONstring, callFunction) {
		request = getHTTPObject();
		request.onreadystatechange = callFunction;
		request.open("GET", "iajax.php?json="+JSONstring, true);
		request.send(null);
	}

	function sendDataJSON() {
	    if(request.readyState == 4) {
			var JSONtext = request.responseText;
			var JSONobject = JSON.parse(JSONtext);
			if (JSONobject.errorsNum) {
				var msg = "Number of errors: "+JSONobject.errorsNum+"\n- "+JSONobject.error[0]+"\n- "+JSONobject.error[1];
				alert(msg);
			}	//...pro ucely ladeni, pak zamaskovat!
	    }
	}
	
	function changeClass(combo, artkey, atype, paraid, ord) {
		try {
			var sclass = combo.options[combo.selectedIndex].value;
			if (sclass == 97 || sclass == 99) {		//...html -> reload!
				var url = "/editor.php?artkey=" + artkey + "&type=" + atype + "&paraid=" + paraid + "&paraclass=" + sclass  + "&action=chtype";
				location.href = url;
			} else {								//...ajax!
				var variant = artkey + '~' + atype + '~' + paraid + '~' + ord + '~' + sclass;
				return getContent('ajaxEditorClass', variant, 'eds_' + ord);
			}
		} catch (e) {
			return;
		}
	}

	function changeSmartLinkVar(combo, varname, artkey, atype, paraid, aord) {
		try {
			var val = combo.options[combo.selectedIndex].value;
			var variant = artkey + '~' + atype + '~' + paraid + '~' + aord + '~' + varname + '~' + val;
			return getContent('ajaxEditorSmartLink', variant, 'eds_' + aord);
		} catch (e) {
			return;
		}
	}

//-->
