/* Набор функций, необходимый для эмуляции поведения disable у options в IE */


function onClickDisableCheck(e, event) {
	// для Mozilla, т.е. поддерживается originalTarget
	// это кусок кода необходим для определения в Mozille, является ли option, на который кликнули disable
	if (event.originalTarget) {
		if (event.originalTarget.disabled) {
			return false;
		} else {
			return true;
		}
	// для IE
	} else {
		// если option disable, возвращаемся на предыдущий option 
		if (e.options[e.selectedIndex].disabled) {
			e.selectedIndex = window.select_current[e.id]; 
			return false;
		// если option не disable, сохраняем e.selectedIndex в select_current
		} else {
			window.select_current[e.id] = e.selectedIndex;
			return true;
		}
	} 
}

/* Функция вызывается при перемещении по option при помощи клавы */
function onPropChangeDisableCheck(e) {
//	alert(event.propertyName);
	var temp = e.selectedIndex;
	// если перемещаемся вниз от предыдущего выделенного option
	if (e.selectedIndex > window.select_current[e.id]) {
		while (e.options[temp].disabled) {
			temp += 1;
			if (temp >= e.options.length) {
				temp = window.select_current[e.id];
				break;
			}
		}
	} 
	// если перемещаемся вверх от предыдущего выделенного option
	if (e.selectedIndex < window.select_current[e.id]) {
		while (e.options[temp].disabled) {
			temp -= 1;
			if (temp < 0) {
				temp = window.select_current[e.id];
				break;
			}
		}
	}   
	e.selectedIndex = temp;
	window.select_current[e.id] = e.selectedIndex;
	if (e.selectedIndex == -1) {
		return false;
	} else {
		return true;
	} 
}

/*
	Раскрашивает disable и enable элементы комбобокса 
	Т.к. IE не может работать с аттрибутом disabled, специально для него, для всех options, которые д.б. disable, устанавливается дополнительный аттрибут disabled4ie50  
*/
function DisableEmulate(e) {
	for (var i=0, option; option = e.options[i]; i++) {
		if (option.disabled || option.disabled4ie50) {
			option.style.color = "gray";
			option.disabled = true;
		}
		else {
			option.style.color = "black";
		}
	}
	window.select_current[e.id] = e.selectedIndex;
}