function storeCaret (textEl) {
	if (textEl.createTextRange) {
		textEl.caretPos = document.selection.createRange().duplicate();
	}
}
function insertAtCaret (textEl, text) {
	if (textEl.createTextRange && textEl.caretPos) {
		var caretPos = textEl.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
	} else {
		textEl.value  = text;
	}
}
function InsertLetter(l) {
	insertAtCaret(document.forms.poszuk.z, l);
	document.forms.poszuk.z.focus();
	return 0;
}

function update_usich_czeknuc() {
	v = document.forms.encselector.usich_czeknuc.checked ? true : false;
	var el = document.forms.encselector.elements;
	for (i = 0; i < el.length; i++) {
		if (el[i].name.substring(0,1) == 'e' && el[i].type == 'checkbox') {
			el[i].checked = v;
		}
	}

    document.forms.poszuk.enc.value = v ? 'all' : '';
}

function check_uncheck() {
    var selectedItems = new Array();
	var el = document.forms.encselector.elements;
	var state = true;
	for (i = 0; i < el.length; i++) 
	{
		if (el[i].name.substring(0,1) == 'e' && el[i].type == 'checkbox') 
		{
			state = state & el[i].checked;
			if (el[i].checked) selectedItems.push(el[i].value);
		}
	}
	document.forms.encselector.usich_czeknuc.checked = state;
	document.forms.poszuk.enc.value = selectedItems.join(',');
}

function init() {
    if (typeof(document.forms.poszuk) != "undefined")
    {
        var inp = document.forms.poszuk.z;
        if (typeof(inp) != "undefined")
        {
	        inp.focus();
	        inp.select();
	        storeCaret(inp)
	    }
	}
}
