﻿function ge(id){
	return document.getElementById(id);
}

function registerMenuRows(){
	var rowsCollection = ge('theTable').getElementsByTagName('TR');
	var cellPreTag = '';
	for (var i = 0; i < rowsCollection.length; i++){
		cellPreTag = '<img src="images/';
		if (rowsCollection[i].getAttribute('cr') == null){
			rowsCollection[i].onmouseover = function(){
				switchStyle(this, 1);
			}
			rowsCollection[i].onmouseout = function(){
				switchStyle(this, 0);
			}
		}
		if (rowsCollection[i].nextSibling != null){
			if (rowsCollection[i].nextSibling.getAttribute('cr') != null){
				if (rowsCollection[i].onclick == null){
					rowsCollection[i].onclick = function(){
						toggleChild(this);
					};
				}
			}
		}
		if (rowsCollection[i].getAttribute('cr') == null){
			switch(rowsCollection[i].className.replace('mLev', '').replace('Over', '').replace('Up', '')){
				case '1':
					cellPreTag += 'PointerRedSmall.gif';
					cellPreTag += '" class="mImage" /><span class="mSpan">';
					break;
				case '2':
					cellPreTag += 'PointerSmall2.gif';
					cellPreTag += '" class="mImage2" /><span class="mSpan">';
					break;
				default:
					cellPreTag += 'PointerSmall3.gif';
					cellPreTag += '" class="mImage3" /><span class="mSpan">';
			}
			
			rowsCollection[i].firstChild.innerHTML = cellPreTag + rowsCollection[i].firstChild.innerHTML + '</span>';
		}
	}
}

function toggleChild(pressedRow){
	var childRow;
	var siblings = pressedRow.parentNode.childNodes;
	switchStyle(pressedRow.firstChild, 1);
	pressedRow.setAttribute('pressed', '1');
	for (var i = 0; i < siblings.length; i++){
		if (siblings[i] != pressedRow){
			siblings[i].setAttribute('pressed', '');
			switchStyle(siblings[i], 0);
			childRow = siblings[i].nextSibling;
			if (childRow != null && childRow.getAttribute('cr') != null)
				childRow.style.display = 'none';
		}
	}
	childRow = pressedRow.nextSibling;
	if (childRow != null && childRow.getAttribute('cr') != null){
		if (childRow.style.display == 'none')
			childRow.style.display = '';
		else {
			childRow.style.display = 'none';
			pressedRow.setAttribute('pressed', '');
		}
	}
}

function switchStyle(theRow, onOff){
	var classNum = theRow.className.replace('mLev', '').replace('Over', '').replace('Up', '');
	if (theRow.getAttribute('pressed') == null)
		theRow.setAttribute('pressed', '');
	if (theRow.getAttribute('pressed') == ''){
		if (onOff == 1)
			theRow.className = 'mLev' + classNum + 'Over';
		else
			theRow.className = 'mLev' + classNum + 'Up';
	}
}

function navi(url){
	if (url.length > 0){
		if (url.toLowerCase().substr(0, 6) == 'iframe')
			document.location.href = 'PlainText.aspx' + url.toLowerCase().substr(url.indexOf('?MenuTxtId'), url.length - 1);
		else
			document.location.href = url;
	}
}