
function htmlCheckbox(checkBoxName, text, selected, id, style) {

	selected = ((selected != 'N') && selected) ? ' checked="checked"' : '';
	
	if (! text) {
		return '<input type="checkbox" value="A" name="' + checkBoxName + '" id="' + id + selected + ' style="' + style + '/>';
	}

	if (! id) {
		id = "checkbox" + Math.round(Math.random()*1000000);
	}
	
	return '<span style="' + style + '"><input type="checkbox" value="A" name="' + checkBoxName + '" id="' + id + '"' + selected + '/>&nbsp;<span class="checkboxtext" onclick="document.getElementById(\'' + id + '\').checked = ! document.getElementById(\'' + id + '\').checked;">' + text + '</span></span>';
	
}

function comboSelectValue(combobox, value) {
	for(i in combobox.options) {
		if (combobox.options[i].value == value) {
			combobox.selectedIndex = i;
		}
	}
}


ere = /^\s*$/;

/**
 * Overi, zda je textove pole prazde a pokud ano, tak zobrazi "errorMessage"
 */
function checkEmpty(textFieldId, errorMessage) {
	textField = document.getElementById(textFieldId);
	if (! textField) {
		return false;
	}
	if (ere.exec(textField.value)) {
		if (errorMessage) {
			textField.select();
			textField.focus();
			alert(errorMessage);
		}
		return false;
	} else {
		return true;
	}
}

/**
 * Overi, zda hodnota vybrana v selectu prazdna
 */
function checkSelectEmpty(selectId, errorMessage) {
	selectField = document.getElementById(selectId);
	if (! selectField) {
		return false;
	}
	if (ere.exec(selectField.options[selectField.selectedIndex].value)) {
		selectField.focus();
		if (errorMessage) {
			alert(errorMessage);
		}
		return false;
	} else {
		return true;
	}
}

function checkEmptyAll(textFieldIds, errorMessage) {

	isEmpty = true;
	for(i in textFieldIds) {
		isEmpty &= document.getElementById(textFieldIds[i]).value == '';
	}

	if (isEmpty) {
		if (errorMessage) {
			alert(errorMessage);
		}
		return false;
	} else {
		return true;
	}

}

function toggleSection(sectionId) {
	s  = document.getElementById(sectionId);
	if (s) {
		s.style.display = s.style.display == 'none' ? 'block' : 'none';
	}
}

function setVisible(elementId, visible) {
	s  = document.getElementById(elementId);
	if (s) {
		s.style.display = visible ? 'block' : 'none';
	}
}

function toggleHeight(elementId, smallHeight, highHeight) {
	s  = document.getElementById(elementId);
	if (s) {
		s.style.height = s.style.height == smallHeight ? highHeight : smallHeight;
	}
}

function textFieldWithDefaultValueOnFocus(field, colorFg, colorFgEmpty, defValue) {
	field.style.color = colorFg;
	if (field.value == defValue) {
		field.value = '';
	}
}

function textFieldWithDefaultValueOnBlur(field, colorFg, colorFgEmpty,defValue) {
	if (! field.value) {
		field.style.color = colorFgEmpty;
		field.value =defValue;
	} else {
		field.style.color = colorFg;
	}
}


