var overOptionCss = "background: highlight; color: highlighttext";

var globalSelect;			//This is used when calling an unnamed selectbox with onclick="this.PROPERTY"
var globalDropDown = null;  //This is a reference to the current "open" dropdown

var ie5 = (document.all != null);

var q = 0;
var keyIdx = -1;
var multiselect = false;

function initSelectBox(el) {
	if (el.getAttribute("initialized") == null) {
		var size = el.getAttribute("size");
		if (size == null)
			size = 1;
		
		if (el.getAttribute("buttononly") == null)
			el.buttononly = false;
		else
			el.buttononly = true;
		
		if (el.getAttribute("multiple") == null) {
			el.multiple = false;
			multiselect = false;
		}
		else {
			el.multiple = true;
			multiselect = true;
		}

		if (el.getAttribute("popselect") == null) {
			el.popselect = false;
		}
		else {
			el.popselect = true;
		}
		
		if (el.getAttribute("combo") == null) {
			el.combo = false;
		}
		else {
			el.combo = true;
		}
		
		el.sortorder = el.getAttribute("sortorder");
		
		if (el.sortorder == "") {
			el.options = el.children[1].children;
		}
		else {
			el.options = sortOptions(el.children[1], el.sortorder);
		}
		
		if ((el.options.length == 0) || (el.buttononly) || ((el.popselect) && (!el.multiple))) {
			el.selectedIndex = -1;
		}
		else {
			el.selectedIndex = findSelected(el.children[1].children);	//Set the index now!
			if ((el.selectedIndex == -1) && (size == 1)) {
				el.selectedIndex = 0;
			}
		}

		// onchange="alert(this.options[this.selectedIndex].value)"
		// Some methods that are supported on the real SELECT box
		el.remove = new Function("i", "int_remove(this,i)");
		el.item   = new Function("i", "return this.options[i]");
		el.add    = new Function("e", "i", "int_add(this, e, i)");
		// The real select box let you have lot of options with the same NAME. In that case the item
		// needs two arguments. When using DIVs you can't have two with the same NAME (or ID) and
		// then there is no need for the second argument
		
		if (el.selectedIndex != -1) {
			el.options[el.selectedIndex].selected = true;
		}
	
		dropdown = el.children[1];
		
		if ((size > 1) || (el.multiple) || (el.popselect)) {
			el.size = size;
			dropdown.style.zIndex = 0;
			if (el.popselect) {
				var boxel = eval("DisplayBox" + el.id);
				if (boxel != null) {
					boxel.popselect = el.popselect;
					boxel.multiple = el.multiple;
					if (el.multiple) {
						boxel.size = size;
					}
					else {
						boxel.size = 1;
					}
					initSized(boxel);
				}
			}
			else {
				initSized(el);
			}
		}
		else {
			el.size = 1;
			dropdown.style.zIndex = 999;
		}
		el.setAttribute("initialized", true);
	}
}

function navHandler() {
	var i = 0, bCombo = false;

	el = getReal(window.event.srcElement, "className", "dropDown");
	if (el.tagName == "INPUT") {
		el = getReal(window.event.srcElement, "className", "select");
		bCombo = el.combo;
		el = el.children[1];
	}
	if (el.parentElement.className == "select") {
		selectBox = el.parentElement;
	}
	else {
		DDdivobj = eval('document.all.myDDdiv');
		selectBox = DDdivobj.parentElement;
	}

	if (globalDropDown != null)
		el = globalDropDown;
		
	if ((el.children.length > 0) && ((window.event.keyCode == 13) || (window.event.keyCode == 38) || (window.event.keyCode == 40))) {
		if (bCombo) {
			i = findSelected(el.children);
			if (i == -1)
				i = 0;
			else
				el.children[i].removeAttribute("selected");
		}
		else {
			i = selectBox.selectedIndex;
		}
	
		switch (window.event.keyCode) {
			case 13:
				toggleDropDown(selectBox);
				if (bCombo) {
					selectBox.selectedIndex = i;
				}
				return;
				
			case 38:
				if (i > 0) {
					i--;
				}
				break;
		
			case 40:
				if (i < (el.children.length - 1)) {
					i++;
				}
				break;
		}
		if (bCombo) {
			el.children[i].setAttribute("selected", 1);
			highlightSelected(el, true);
		}
		else {
			multiselect = false;
			selectBox.selectedIndex = i;
		}
		// scroll option into view
		if ((el.children[i].offsetTop < el.scrollTop) || ((el.children[i].offsetTop + el.children[i].offsetHeight) > (el.scrollTop + el.offsetHeight))) {
			el.scrollTop = el.children[i].offsetTop;
		}
		window.event.cancelBubble = true;
		window.event.returnValue = false;
	}
}

function keyHandler() {
	var startIdx, el, i, reg, searchStr = "";
	var bStop = false, bFound = false, bCombo = false;
	
	if ((window.event.keyCode == 13) || (window.event.keyCode == 38) || (window.event.keyCode == 40))
		return;
	
	el = getReal(window.event.srcElement, "className", "dropDown");
	if (el.tagName == "INPUT") {
		el = getReal(window.event.srcElement, "className", "select");
		bCombo = el.combo;
		el = el.children[1];
	}
	if (bCombo) {
		if (window.event.srcElement.value == "")
			hideDropDown(el);
		else {
			if (el.parentElement.className == "select") {
				selectBox = el.parentElement;
			}
			else {
				DDdivobj = eval('document.all.myDDdiv');
				selectBox = DDdivobj.parentElement;
			}
			selectedCell = selectBox.getElementsByTagName('INPUT');
			selectedCell[1].value = window.event.srcElement.value;
			
			if (globalDropDown != null)
				el = globalDropDown;
				
			searchStr = window.event.srcElement.value;
			// replace special chars. with octal values
			searchStr = searchStr.replace("*", "\\52");
			searchStr = searchStr.replace("+", "\\53");
				
			reg = new RegExp("^" + searchStr, "i");
			for (i = 0; i < el.children.length; i++) {
				if ((reg.exec(el.children[i].innerText)) && (!bFound)) {
					el.children[i].setAttribute("selected", 1);

					// show dropdown, highlight found item and resize dropdown to contents
					if (globalDropDown == null)
						showDropDown(el, false);
					
					highlightSelected(el, true);
					el.style.height = el.scrollHeight;
					el.style.overflowY = "visible";
					if (el.offsetHeight > 200) {
						el.style.height = 200;
						el.style.overflowY = "scroll";
					}
					
					// scroll option into view
					if ((el.children[i].offsetTop < el.scrollTop) || ((el.children[i].offsetTop + el.children[i].offsetHeight) > (el.scrollTop + el.offsetHeight))) {
						el.scrollTop = el.children[i].offsetTop;
					}
					bFound = true;
				}
				else {
					el.children[i].removeAttribute("selected");
				}
			}
			if (!bFound)
				hideDropDown(selectBox.children[1]);
		}
	}
	else {
		if (el.parentElement.className == "select") {
			selectBox = el.parentElement;
		}
		else {
			DDdivobj = eval('document.all.myDDdiv');
			selectBox = DDdivobj.parentElement;
		}
		i = keyIdx + 1;
		if (i == el.children.length) {
			i = 0;
		}
		startIdx = i;
		while (!bStop) {
			if ((!bFound) && (el.children[i].innerText.charCodeAt(0) == window.event.keyCode)) {
				multiselect = false;
				selectBox.selectedIndex = i;
				
				// scroll option into view
				if ((el.children[i].offsetTop < el.scrollTop) || ((el.children[i].offsetTop + el.children[i].offsetHeight) > (el.scrollTop + el.offsetHeight))) {
					el.scrollTop = el.children[i].offsetTop;
				}
				keyIdx = i;
				bFound = true;
			}
			i++;
			if (i == el.children.length) {
				i = 0;
			}
			if (i == startIdx) {
				bStop = true;
			}
		}
	}
}

function updateSelectBox(el) {
	if (event.propertyName == "selectedIndex") {
		if (el.children[1].id == 'myDDdiv') {
			dropdown = globalDropDown;
		}
		else {
			dropdown = el.children[1];
		}
		if (!multiselect) {
			oldSelected = dropdown.children[findSelected(dropdown.children)];
			if (oldSelected != null) {
				oldSelected.removeAttribute("selected");
			}
			newSelected = dropdown.children[el.selectedIndex];
			if (newSelected != null) {
				newSelected.setAttribute("selected", 1);
			}
			highlightSelected(dropdown, true);
		}
		copySelected(el);
		multiselect = false;
	}
}

function updateOption(el) {
	var el, i, j;

	if (event.propertyName == "selected") {
		el = getReal(window.event.srcElement, "className", "option");
	
		if (el.className == "option") {
			dropdown  = el.parentElement;
			if (dropdown.parentElement.className == "select") {
				selectBox = dropdown.parentElement;
			}
			else {
				selectBox = globalDropDown.parentElement;
			}
			if (selectBox.multiple) {
				if (el.getAttribute("selected") == false) {
					el.removeAttribute("selected");
				}
			}
			if (selectBox.popselect) {
				updateDisplayBox(selectBox);
				if (!selectBox.multiple) {
					closeSelectPopup();
				}
			}
		}
	}
}

function updateDisplayBox(el) {
	var box, ec;
	var i;
	
	box = eval("DisplayBox" + el.id);
	if (box != null) {
		for (i = box.children.length; i > 0; i--) {
			box.removeChild(box.children[i - 1]);
		}
		ec = el.children[1].children;
		for (i = 0; i < ec.length; i++) {
			if (ec[i].getAttribute("selected") != null) {
				var html = "<div nowrap style='cursor: hand; overflow-x: hidden; width: 100%;'>";
				html += ec[i].innerHTML;
				html += "</div>"
				box.insertAdjacentHTML("BeforeEnd", html);
			}
		}
	}
}

function displayClick(id) {
	var el, boxel;
	
	el = eval("DD" + id);
	boxel = eval("DisplayBoxDD" + id);
	if ((el != null) && (boxel != null)) {
		el.style.position = "absolute";
		el.style.background = "white";
		el.style.left = getElementPosition(boxel, false);
		el.style.top = getElementPosition(boxel, true);
		el.style.display = "";
		initSized(el);
		el.focus();
	}
}

function closeSelectPopup() {
	var el;
	
	el = getReal(window.event.srcElement, "className", "select");
	el.style.display = "none";
}

function int_remove(el, i) {
	var j, childEls;

	if (el.options[i] != null) {
		el.options[i].outerHTML = "";
	}

	if (el.children[1].id == 'myDDdiv') {
		dropdown = globalDropDown;
	}
	else {
		dropdown = el.children[1];
	}

	el.options = dropdown.children;
	
	if (el.options.length == 0) {
		var btns = el.children[0].getElementsByTagName("BUTTON");
		if (btns.length > 0) {
			btns[0].disabled = true;
		}
		childEls = el.getElementsByTagName("INPUT");
		for (j = 0; j < childEls.length; j++) {
			if (childEls[j].type == "checkbox") {
				childEls[j].checked = false;
			}
		}
	}
	
	if (el.selectedIndex == i) {
		el.selectedIndex = findSelected(dropdown.children);
	}
}

function int_add(el, e, i) {
	var html = "<div nowrap width='100%' class='option' onpropertychange='updateOption(this);'";
	if (e.value != null)
		html += ' value="' + e.value + '"';
	if (e.style.cssText != null)
		html += " style='" + e.style.cssText + "'";
	html += ">";
	if (e.text != null)
		html += e.text;
	html += "</div>";

	if (el.children[1].id == 'myDDdiv') {
		dropdown = globalDropDown;
	}
	else {
		dropdown = el.children[1];
	}

	if (el.sortorder == "") {
		el.options = dropdown.children;
	}
	else {
		el.options = sortOptions(dropdown, el.sortorder);
	}

	if (el.options.length == 0) {
		dropdown.insertAdjacentHTML("BeforeEnd", html);
	}
	else {
		if ((i == null) || (i >= el.options.length))
			i = el.options.length - 1;

		el.options[i].insertAdjacentHTML("AfterEnd", html);
	}
	
	var btns = el.children[0].getElementsByTagName("BUTTON");
	if (btns.length > 0) {
		btns[0].disabled = false;
	}
	
	if (dropdown.offsetHeight > 200) {
		dropdown.style.height = 200;
		dropdown.style.overflowY = "scroll";
	}

	if ((el.combo) || (el.buttononly) || ((el.popselect) && (!el.multiple))) {
		el.selectedIndex = -1;
	}
	else if (el.selectedIndex == -1) {
		el.selectedIndex = findSelected(dropdown.children);
	}
}

function sortOptions(dropdown, sortorder) {
	var i, repeatsort;
	
	do {
		repeatsort = false;
		for (i = 0; i < dropdown.children.length - 1; i++) {
			if (sortorder.toUpperCase() == "ASC") {
				if (dropdown.children[i].innerText > dropdown.children[i + 1].innerText) {
					dropdown.children[i].swapNode(dropdown.children[i + 1]);
					repeatsort = true;
				}
			}
			else if (sortorder.toUpperCase() == "DESC") {
				if (dropdown.children[i].innerText < dropdown.children[i + 1].innerText) {
					dropdown.children[i].swapNode(dropdown.children[i + 1]);
					repeatsort = true;
				}
			}
		}
	} while (repeatsort);
	return dropdown.children;
}
	
function initSized(el) {
	var h = 0, j, padding = 0, lineheight = 0, Divobj;

	if (el.className == "select") {
		dropdown = el.children[1];
		if ((el.popselect) && (el.size == 1)) {
			el.size = 6;
		}
	}
	else {
		dropdown = el;
	}

	j = Math.min(el.size, dropdown.children.length);
	if (el.size > dropdown.children.length) {
		padding = el.size - j;
	}
	if (j > 0) {
		for (var i = 0; i < j; i++) {
			// Use a hidden Div to calculate font height in the background
			Divobj = dropdown.children[i].cloneNode(false);
			Divobj.style.visibility = "hidden"
			Divobj.style.position = "absolute";
			dropdown.parentElement.appendChild(Divobj);
			lineheight = Divobj.offsetHeight;
			Divobj.removeNode(true);
			h += lineheight;
		}
	}
	else {
		Divobj = document.createElement('DIV');
		Divobj.className = "option";
		dropdown.parentElement.appendChild(Divobj);
		lineheight = Divobj.offsetHeight;
		Divobj.removeNode(true);
	}
	h += (padding * lineheight);
	
	if (dropdown.style.borderWidth != null) {
		dropdown.style.pixelHeight = h + 4;
	}
	else {
		dropdown.style.pixelHeight = h;
	}

	dropdown.style.display = "";
	if ((dropdown.scrollHeight > dropdown.style.pixelHeight) || (el.multiple)) {
		dropdown.style.overflowY = "scroll";
	}

	// Turn off the scroll bar if not needed.
	if ((el.popselect) && (dropdown.scrollHeight <= dropdown.clientHeight) && (!el.multiple)) {
		dropdown.style.overflowY = "visible";
	}
	keyIdx = -1;
}

function selectAll(Checked) {
	var el, i;
	var SelectItem = false;
	
	el = getReal(window.event.srcElement, "className", "select");

	if (Checked) {
		SelectItem = true;
	}
	for (i = 0; i < el.options.length; i++) {
		el.options[i].selected = SelectItem;
	}
	multiselect = true;
	el.selectedIndex = findSelected(el.children[1].children);
}

function copySelected(el) {
	var i;
	var selcount = 0;

	selectedCell = el.getElementsByTagName('INPUT');
	if (el.selectedIndex != -1) {
		if (el.multiple) {
			selectedCell[1].value = "";
			for (i = 0; i < el.children[1].children.length; i++) {
				if (el.children[1].children[i].getAttribute("selected") != null) {
					selcount ++;
					if (selectedCell[1].value == "") {
						selectedCell[1].value = el.children[1].children[i].value;
					}
					else {
						selectedCell[1].value = selectedCell[1].value + "," + el.children[1].children[i].value;
					}
				}
			}
			if (selcount == el.children[1].children.length) {
				selectedCell[2].checked = true;
			}
			else {
				selectedCell[2].checked = false;
			}
		}
		else {
			if (el.children[1].id == 'myDDdiv') {
				selectedDiv = globalDropDown.children[el.selectedIndex];
			}
			else {
				selectedDiv = el.children[1].children[el.selectedIndex];
			}
			selectedCell[0].value = selectedDiv.innerText;
			selectedCell[0].title = selectedDiv.innerText;
			selectedCell[1].value = selectedDiv.value;
			if (el.combo) {
				el.selectedIndex = -1;
			}
		}
	}
	else if (!el.combo) {
		selectedCell[0].value = "";
		selectedCell[1].value = "";
	}
}

function findSelected(ec) {
	var selected = null;
	var ecl = ec.length;
	
	if (ecl == 0) {
		return -1;
	}
	
	for (var i = 0; i < ecl; i++) {
		if (ec[i].getAttribute("selected") != null) {
			if (selected == null) {	// Found first selected
				selected = i;
			}
			else if (!multiselect) {
				// remove other selected items if we're not "multi-selecting"
				ec[i].removeAttribute("selected");
			}
		}
		if (ec[i].getAttribute("selected") == null) {
			if (ec[i].backupCss != null)
				ec[i].style.cssText = ec[i].backupCss;
		}
		else {
			if (ec[i].backupCss == null)
				ec[i].backupCss = ec[i].style.cssText;
			ec[i].style.cssText = ec[i].backupCss + "; " + overOptionCss;
		}
	}
	
	if (selected == null) {
		// If nothing found, return -1
		selected = -1;
	}

	return selected;
}

function toggleDropDown(el) {
	var dropDown, clickEl;

	if (el.size == 1) {
		dropDown = el.children[1];
		
		if (dropDown.id != "myDDdiv") {
			hideShownDropDowns();
			highlightSelected(dropDown, true);
			clickEl = document.elementFromPoint(event.clientX, event.clientY);
			if ((dropDown.children.length > 0) && ((!el.combo) || ((el.combo) && (clickEl.tagName != "INPUT"))))
				showDropDown(dropDown);
			keyIdx = -1;
		}
		else {
			hideDropDown(dropDown);
		}
	}
}

function optionClick() {
	var el, i, j, newitem = false;

	el = getReal(window.event.srcElement, "className", "option");

	if (el.className == "option") {
		dropdown  = el.parentElement;
		if (dropdown.parentElement.className == "select") {
			selectBox = dropdown.parentElement;
		}
		else {
			DDdivobj = eval('document.all.myDDdiv');
			selectBox = DDdivobj.parentElement;
		}
		
		toggleDropDown(selectBox);

		for (i = 0; i < dropdown.children.length; i++) {
			if (dropdown.children[i] == el) {
				if ((selectBox.multiple) && (window.event.ctrlKey)) {
					if (el.getAttribute("selected") == null) {
						el.setAttribute("selected", 1);
					}
					else {
						el.removeAttribute("selected");
						if (selectBox.popselect) {
							updateDisplayBox(selectBox);
						}
					}
					multiselect = true;
					selectBox.selectedIndex = findSelected(dropdown.children);
				}
				else if ((selectBox.multiple) && (window.event.shiftKey)) {
					j = i;
					while ((j >= 0) && (dropdown.children[j].getAttribute("selected") == null)) {
						dropdown.children[j].setAttribute("selected", 1);
						j--;
					}
					multiselect = true;
					selectBox.selectedIndex = findSelected(dropdown.children);
				}
				else {
					if ((selectBox.selectedIndex != i) || (selectBox.multiple)) {
						newitem = true;
						multiselect = false;
						selectBox.selectedIndex = i;
					}
				}
				if ((newitem) || (selectBox.buttononly) || (selectBox.multiple)) {
					if (selectBox.onchange != null) {	// This executes the onchange when you chnage the option
						if (selectBox.id != "") {		// For this to work you need to replace this with an ID or name
							eval(selectBox.onchange.replace(/this/g, selectBox.id));
						}
						else {
							globalSelect = selectBox;
							eval(selectBox.onchange.replace(/this/g, "globalSelect"));
						}
					}
				}
			}
		}
	}
}

function optionOver() {
	var toEl = getReal(window.event.toElement, "className", "option");
	var fromEl = getReal(window.event.fromElement, "className", "option");
	if (toEl == fromEl) return;
	var el = toEl;
	
	if (el.className == "option") {
		// Reset keyboard selected option, if any
		if (keyIdx != -1) {
			el.parentElement.children[keyIdx].style.cssText = el.parentElement.children[keyIdx].backupCss;
			keyIdx = -1;
		}
		if (el.backupCss == null)
			el.backupCss = el.style.cssText;
		highlightSelected(el.parentElement, false);
		el.style.cssText = el.backupCss + "; " + overOptionCss;
	}
}

function optionOut() {
	var toEl = getReal(window.event.toElement, "className", "option");
	var fromEl = getReal(window.event.fromElement, "className", "option");

	if ((toEl == null) || (toEl.className != "option")) {
		highlightSelected(fromEl.parentElement, true);
		return;
	}
	
	if (toEl != null) {
		if (toEl.className != "option") {
			if (fromEl.className == "option") {
				highlightSelected(fromEl.parentElement, true);
			}
		}
	}
	
	if (toEl == fromEl) return;
	var el = fromEl;

	if (el.className == "option") {
		if (el.backupCss != null) {
			el.style.cssText = el.backupCss;
		}
	}
}

function highlightSelected(el, hilite) {
	if (el.parentElement.buttononly)
		return;

	var selectedIndex = findSelected(el.children);
	if (selectedIndex != -1) {
		var selected = el.children[selectedIndex];
		
		if (hilite) {
			if (selected.backupCss == null)
				selected.backupCss = selected.style.cssText;
			selected.style.cssText = selected.backupCss + "; " + overOptionCss;
		}
		else if (!hilite) {
			if (selected.backupCss != null)
				selected.style.cssText = selected.backupCss;
		}
	}
}

function hideShownDropDowns() {
	var dropDown;
	var el = getReal(window.event.srcElement, "className", "select");
	try {
		var spans = document.all.tags("SPAN");
	}
	catch(er) {
		return;
	}
	for (var i = 0; i < spans.length; i++) {
		if ((spans[i].className == "select") && (spans[i] != el)) {
			dropDown = spans[i].children[1];
			if ((spans[i].size == 1) && (dropDown.id == "myDDdiv"))
				hideDropDown(dropDown);
		}
	}
}

function hideDropDown(el) {
	if (globalDropDown == null)
		return;
		
	if (typeof(fade) == "function")
		fade(globalDropDown, false);
	else
		globalDropDown.style.visibility = "hidden";
	globalDropDown.style.display = "none";
	el.swapNode(globalDropDown);
	globalDropDown = null;
}

function showDropDown(el, setfocus) {
	var DDdivobj, ScrollY;
	
	if (setfocus == null)
		setfocus = true;

	DDdivobj = eval('document.all.myDDdiv');
	if (DDdivobj == null) {
		DDdivobj = document.createElement('DIV');
		DDdivobj.id = 'myDDdiv';
		DDdivobj.style.display = "none";
		DDdivobj.style.visibility = "hidden";
		DDdivobj.style.position = "absolute";
		DDdivobj.style.zIndex = 99;
		document.body.insertAdjacentElement("beforeEnd", DDdivobj);
	}
	selectedCell = el.parentElement.getElementsByTagName('BUTTON');
	el.style.display = "";

	el.style.height = el.scrollHeight;
	el.style.overflowY = "visible";
	if (el.offsetHeight > 200) {
		el.style.height = 200;
		el.style.overflowY = "scroll";
	}
	
	el.style.top = getElementPosition(el.parentElement, true) + selectedCell[0].offsetHeight + 3;
	if (((el.style.pixelTop + el.offsetHeight) - document.body.offsetHeight) > 0) {
		el.style.pixelTop = getElementPosition(selectedCell[0], true) - el.offsetHeight - 3;
	}
	el.style.left = getElementPosition(el.parentElement, false);
	if (((el.style.pixelLeft + el.offsetWidth) - document.body.offsetWidth) > 0) {
		el.style.pixelLeft -= ((el.style.pixelLeft + el.offsetWidth) - document.body.offsetWidth);
	}
	if (el.offsetWidth < el.parentElement.offsetWidth) {
		el.style.width = el.parentElement.offsetWidth;
	}
	else {
		el.style.width = el.offsetWidth;
	}
	
	if (el.parentElement.selectedIndex != -1) {
		// scroll option into view, if necessary
		if (el.children[el.parentElement.selectedIndex].offsetTop > el.offsetHeight) {
			ScrollY = el.children[el.parentElement.selectedIndex].offsetTop;
		}
	}

	globalDropDown = el.swapNode(DDdivobj);

	// actual scroll needs to be done after above's node swap
	el.scrollTop = ScrollY;
	
	if (typeof(fade) == "function")
		fade(el, true, setfocus);
	else if (typeof(swipe) == "function") {
		if (el.style.pixelTop < getElementPosition(selectedCell[0], true))
			swipe(el, 8, 4, 25, setfocus);
		else
			swipe(el, 2, 4, 25, setfocus);
	}
	else {
		el.style.visibility = "visible";
		if (setfocus)
			el.focus();
	}
}

function initSelectBoxes() {
	var spans = document.all.tags("SPAN");
	var selects = new Array();
	var index = 0;
	
	for (var i=0; i<spans.length; i++) {
		if (spans[i].className == "select")
			selects[index++] = spans[i];
	}
	
	for (var j=0; j<selects.length; j++) {
		initSelectBox(selects[j]);
	}	
}

function getReal(el, type, value) {
	temp = el;
	while ((temp != null) && (temp.tagName != "BODY")) {
		if (eval("temp." + type) == value) {
			el = temp;
			return el;
		}
		temp = temp.parentElement;
	}
	return el;
}

function getElementPosition(el, isGetTop) {
	var pos;
	
	if (el == null) {
		pos = 0;
	}
	else {
		pos = (isGetTop) ? el.offsetTop : el.offsetLeft;
		while ((el = el.offsetParent) != null) {
	    	pos += (isGetTop) ? el.offsetTop : el.offsetLeft;
			if ((el.tagName == "DIV") && (isGetTop)) {
				pos -= el.scrollTop;
			}
    	}
	}
	return pos;
}

if (ie5) {
	window.attachEvent('onload', initSelectBoxes);
	document.attachEvent('onclick', hideShownDropDowns);
}


var swipeSteps = 4;
var swipemsec = 25;
var swipeArray = new Array();	// Needed to keep track of which elements are animating

//////////////////////////////////////////////////////////////////////////////////////////
// the dir parameter is the direction read from the NumPad on your keyboard

function swipe(el, dir, steps, msec, setfocus) {

	if (steps == null) steps = swipeSteps;
	if (msec == null) msec = swipemsec;
	if (setfocus == null) setfocus = true;

	if (el.swipeIndex == null)
		el.swipeIndex = swipeArray.length;
	if (el.swipeTimer != null)
		window.clearTimeout(el.swipeTimer);
		
	swipeArray[el.swipeIndex] = el;

	el.style.clip = "rect(-99999, 99999, 99999, -99999)";

	if (el.swipeCounter == null) {		// No animation yet!
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	else if (el.swipeCounter == 0) {	// The Animation has stopped! It's now safe to update the position.
		el.orgLeft  = el.offsetLeft;
		el.orgTop  = el.offsetTop;
		el.orgWidth = el.offsetWidth;
		el.orgHeight  = el.offsetHeight;
	}
	
	el.style.left = el.orgLeft;
	el.style.top  = el.orgTop;
	
	el.swipeCounter = steps;
	el.style.clip = "rect(0,0,0,0)";
			
	window.setTimeout("repeat(" + dir + "," + el.swipeIndex + "," + steps + "," + msec + "," + setfocus + ")", msec);
}


function repeat(dir, index, steps, msec, setfocus) {
	el = swipeArray[index];
	var left   = el.orgLeft;
	var top    = el.orgTop;
	var width  = el.orgWidth;
	var height = el.orgHeight;
	
	if (el.swipeCounter == 0) {
		el.style.clip = "rect(-99999, 99999, 99999, -99999)";
		if ((el.style.visibility == "visible") && (el.style.display != "none")) {
			if (setfocus)
				el.focus();
		}
		return;
	}
	else {
		el.swipeCounter--;
		el.style.visibility = "visible";
		switch (dir) {
			case 2:		//down (see the numpad)
				el.style.clip = "rect(" + height*el.swipeCounter/steps + "," + width + "," + height + "," + 0 + ")";
				el.style.top  = top - height*el.swipeCounter/steps;
				break;
			case 8:
				el.style.clip = "rect(" + 0 + "," + width + "," + height*(steps-el.swipeCounter)/steps + "," + 0 + ")";
				el.style.top  = top + height*el.swipeCounter/steps;
				break;
			case 6:
				el.style.clip = "rect(" + 0 + "," + width + "," + height + "," + width*(el.swipeCounter)/steps + ")";
				el.style.left  = left - width*el.swipeCounter/steps;
				break;
			case 4:
				el.style.clip = "rect(" + 0 + "," + width*(swipeSteps - el.swipeCounter)/steps + "," + height + "," + 0 + ")";
				el.style.left  = left + width*el.swipeCounter/steps;
				break;
		}
		el.swipeTimer = window.setTimeout("repeat(" + dir + "," + index + "," + steps + "," + msec + "," + setfocus + ")", msec);
	}
}

function hideSwipe(el) {
	window.clearTimeout(el.swipeTimer);
	el.style.visibility = "hidden";
	el.style.clip = "rect(-99999, 99999, 99999, -99999)";
	el.swipeCounter = 0;
}

