function lybexSelectValue(select) {
	var oSelect = document.getElementById(select);
	if (oSelect.options != null && oSelect.options.length > 0 &&
			oSelect.selectedIndex != null) {
		return oSelect.options[oSelect.selectedIndex].value;
	}
	return null;
}

/**
 * Функция обновляет значение селекта моделей по текущему значению селекта марок
 * телефонов.
 *
 * @param parentSelect
 * @param childSelect
 * @param childArray
 *
 */
	function lybexSelectUpdateChildSelect(parentSelect, childSelect, childArray) {
		// select of models object
		var oParent = document.getElementById(parentSelect);
		var oChild = document.getElementById(childSelect);
		
		var currentParentValue = lybexSelectValue(parentSelect);
		var currentChildLength = oChild.options.length;
		
		var newChildLength = 0;

		// check if currentParentValue exists in array
		if (currentParentValue != null && childArray != null) {
			if (childArray[currentParentValue] != null) {
				// new parent count
				newChildLength = childArray[currentParentValue].length;
				
				if (newChildLength > 0) {
					for (i = 0; i < newChildLength; i++) {
						oChild.options[i] = new Option(childArray[currentParentValue][i].name, childArray[currentParentValue][i].id);
					}
				}
				
				if (newChildLength < currentChildLength) {
					for (i = newChildLength; i < currentChildLength; i++) {
						oChild.options[i] = null;
					}
				}
				
				if (oChild.disabled) {
					oChild.disabled = false;
				}
			} else {
				oChild.options[0] = new Option();
				
				for (i = 1; i < currentChildLength; i++) {
					oChild.options[i] = null;
				}
				
				oChild.disabled = true;
			}
			
			oChild.options.length = newChildLength;
		}
	}
	
/**
 * Функция выбирает указанную модель в селекте моделей
 * при этом нужная марка телефона должна быть уже подсвечена
 * в селекте марок телефонов
 *
 * @param select
 * @param value
 */
	function lybexSelectSetValue(select, value) {
		var oSelect = document.getElementById(select);
		if (oSelect.options != null && oSelect.options.length > 0) {
			for (i = 0; i < oSelect.options.length; i++) {
				if (oSelect.options[i].value == value) {
					oSelect.selectedIndex = i
					break;
				}
			}
		}
	}
	