﻿//=======================
// DropDownListRemover.js
//=======================

// HideDropDownLists(excludeElemID)
//  скрыть выпадающие списки со страницы, 
//  кроме списков внутра блока с ID = excludeElemID

// ShowDropDownLists()
//  показать выпадающие списки, скрытые ранее

var _global_SavedDropDownLists;
		
function DropDownListObject(dropDownList, inputText)
{
	this.dropDownList = dropDownList;
	this.inputText = inputText;
}

function ShowDropDownLists()
{
	if (_global_SavedDropDownLists==null) return;
	for (var i=0;i<_global_SavedDropDownLists.length;i++)
	{
		var obj = _global_SavedDropDownLists[i];
		obj.inputText.parentNode.replaceChild(obj.dropDownList, obj.inputText);
		
	}
	_global_SavedDropDownLists = null;
}

function HideDropDownLists(excludeElemID)
{
	if (!_global_SavedDropDownLists) _global_SavedDropDownLists = new Array();
	var excludeElem = document.getElementById(excludeElemID);
	
	var ie = navigator.appName == "Microsoft Internet Explorer";

	for (var i=0;i<document.forms.length;i++)
	{
		var f = document.forms[i];
		for (var j=0;j<f.elements.length;j++)
		{
			var e = f.elements[j];
			if (IsNodeParent(e, excludeElem)) continue;
			if (e.type=="select-one")
			{
				var inputText = document.createElement("input");
				
				inputText.id = e.id;
				inputText.name = e.name;
				inputText.value = e.selectedIndex>=0 ? e.options[e.selectedIndex].text : "";
				var s = (e.clientWidth-(ie?6:4)) + "px";
				inputText.style.width = Math.max(0,(e.clientWidth-(ie?6:4))) + "px";
				inputText.style.backgroundColor = e.style.backgroundColor;
				inputText.style.display = e.style.display;
				inputText.disabled = true;
				
				e.parentNode.replaceChild(inputText, e);

				_global_SavedDropDownLists.push(new DropDownListObject(e,inputText));
			}
		}
	}
}

function IsNodeParent(node, parent)
{
	while (node.parentNode!=null)
	{
		if (node.parentNode==parent) return true;
		node = node.parentNode;
	}
	return false;
}
		