<!--

/*	 Rubico.cz app; drobne fce aplikace					*/
/*	 (C) ivosan(at)atlas(dot)cz							*/
/*	*********************************************************	*/

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';

//...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();
		}
	}

	function callSearch() {
		if (document.srch.s.value) {
			document.srch.submit();
		}
	}

	function catAdd() {
		var Cats = document.bookform.cidlist.options;
		if (Cats.selectedIndex > 0) {
			var val=Cats[Cats.selectedIndex].value;
			var txt=Cats[Cats.selectedIndex].text;
			
			var NewCats = document.bookform.cids.options;
			for (var i = NewCats.length - 1; i >= 0; i--) {
				if (NewCats[i].value == val)
					return true;			//...byl tam, tak nic
			}
			var currLen = NewCats.length;
			NewCats[currLen] = new Option();
			NewCats[currLen].value = val;
			NewCats[currLen].text = txt;
			var sentence = document.bookform.catids.value;
			if (val == document.bookform.acid.value) {
				NewCats[currLen].style.color = '#873408';
			} else if (sentence.indexOf(val)!=-1) {
				NewCats[currLen].style.color = 'black';
			} else NewCats[currLen].style.color = '#4673AB';
		}
		return recountCids();
	}

	function catDrop() {
		var NewCats = document.bookform.cids.options;
		for (var i = NewCats.length - 1; i >= 0; i--) {
			if (NewCats[i].selected)
				document.bookform.cids.remove(i);
		}
		return recountCids();
	}

	function recountCids() {
		var newcids = '';
		var NewCats = document.bookform.cids.options;
		for (var i = 0; i < NewCats.length; i++)
			newcids = (i == 0 ? '' : newcids + ',') + NewCats[i].value;
		document.bookform.newcids.value = newcids;
		return true;
	}

	function selAllCats() {
		var NewCats = document.bookform.cids.options;
		for (var i = NewCats.length - 1; i >= 0; i--)
			NewCats[i].selected = true;
		return true;
	}

//...stav a logovani
	function setStat(txt) {		//...prepina prostor pro mouseover
		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 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 = "#E9F1FB";
			}
		} catch (e) {
			return;
		}
	}

	function moFocus(item) {
		try {
			var ret = document.getElementById(item + 'Mover');
			if (ret) {
				ret.style.color = "#A08572";
			}
		} catch (e) {
			return;
		}
	}

	function moBlur(item) {
		try {
			var ret = document.getElementById(item + 'Mover');
			if (ret) {
				ret.style.color = "#E9F1FB";
			}
		} 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 changeClass(combo, artkey, atype, paraid) {
		try {
			var sclass = combo.options[combo.selectedIndex].value;
			var url = "/editor.php?artkey=" + artkey + "&type=" + atype + "&paraid=" + paraid + "&paraclass=" + sclass  + "&action=chtype";
			location.href = url;
		} catch (e) {
			return;
		}
	}

	function addRoleSubmit() {
		document.allactions.expiration.value = document.expform.expire.value;
		sendAllActAction('addrole');
	}


//...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 {;}
	}
	
	
//-->

