



	
		
function isEnter(e) {
	var keynum = 0;
	if (window.event) {
		keynum = e.keyCode;
	} else if (e.which) {
		keynum = e.which;
	} else {
		return false;
	}
	
	return (keynum == 13);
}

/**
 * @param form An HTML DOM form
 * @param name The name of a field in the specified form
 * @param index An index of the named field, starting from 0
 */
function getElement(form, name, index) {
	var count = 0;
	
	for (var i = 0; i < form.elements.length; i++) {
		var element = form.elements[i];
		if (element.name == name) {
			if (count == index)
				return element;
			count++;
		}
	}
	
	return null;
}

	

	
		/**
 * This script defines HTML utility functions
 */

function GetHTMLObjectById(id) {
    if (document.getElementById) return document.getElementById(id);
    else if (document.all) return document.all[id];
    else alert("Browser not supported at this time.");
}

function SetHTMLObjectVisibility(obj, vis) {
	if (!vis) obj.style.visibility = 'hidden';
	else obj.style.visibility = 'visible';
}

function SetHTMLObjectExistence(obj, exists) {
	if (exists) obj.style.display = '';
	else obj.style.display = 'none';
}

function SetHTMLObjectExistenceDIV(obj, exists) {
	if (exists && document.all) obj.style.display = '';
	else if (exists) obj.style.display = 'table-cell';
	else obj.style.display = 'none';
}

function ToggleHTMLObjectExistence(obj) {
	SetHTMLObjectExistence(obj, !HTMLObjectExists(obj));
}

function HTMLObjectExists(obj) {
	return (obj.style.display == 'none') ? false : true;
}

function SetHTMLIdExistence(id, exists) {
	var obj = GetHTMLObjectById(id);
	if (obj != null)
		SetHTMLObjectExistence(obj, exists);
}

function HTMLObjectAppearDisappear(id1, id2) {
	SetHTMLObjectExistence(GetHTMLObjectById(id1), true);
	SetHTMLObjectExistence(GetHTMLObjectById(id2), false);
}



function FloatCenterObject(obj) {
	if (obj.offsetWidth < obj.parentNode.offsetWidth) {
		obj.style.float = 'left';
		obj.style.marginLeft = (obj.parentNode.offsetWidth - obj.offsetWidth) / 2;
	}
}

function GetHTMLObjectPosition(obj) {
	var pt = {x:0, y:0, w:0, h:0};

	if (obj != null) {
		pt.w = obj.offsetWidth;
		pt.h = obj.offsetHeight;

		while (obj != null) {
			pt.x += obj.offsetLeft;
			pt.y += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}

	return pt;
}

function SetHTMLObjectPosition(obj, x, y, w, h) {
	obj.style.left = "" + x + "px";
	obj.style.top = "" + y + "px";

	if (w > 0) obj.style.width = "" + w + "px";
	if (h > 0) obj.style.height = "" + h + "px";
}



function GetSelectedOption(selectObj) {
	return selectObj.options[selectObj.selectedIndex];
}

function GetOptionByValue(selectObj, optionValue) {
	var i = 0;
	for (i = 0; i < selectObj.options.length; i++) {
		var optionObj = selectObj.options[i];
		if (optionObj.value == optionValue)
			return optionObj;
	}
}

function SelectOption(selectObj, optionValue) {
	var i = 0;
	for (i = 0; i < selectObj.options.length; i++) {
		var optionObj = selectObj.options[i];
		if (optionObj.value == optionValue) {
			selectObj.selectedIndex = i;
			return;
		}
	}
}

function CopySelectedOption(fromSelectObj, toSelectObj) {
	var fromOptionObj = GetSelectedOption(fromSelectObj);
	toSelectObj.options[toSelectObj.options.length] = new Option(fromOptionObj.text, fromOptionObj.value);
}

function AddOption(selectObj, optionValue, optionDisplay) {
	selectObj.options[selectObj.options.length] = new Option(optionDisplay, optionValue);
}

function RemoveSelectedOption(selectObj) {
	var optionObj = GetSelectedOption(selectObj);
	selectObj.options[selectObj.selectedIndex] = null;
	return optionObj;
}

function ClearOptions(selectObj) {
	while (selectObj.options.length > 0)
		selectObj.options[selectObj.options.length-1] = null;
}

	

	
		
var MENU_HIDE_DELAY = 500;  // in milliseconds



function killDelayedHide(menu) {
	if (menu.parentmenu && menu.parentmenu.timedmenu) {
		clearTimeout(menu.parentmenu.timedmenu.timerid);
		menu.parentmenu.timedmenu.timerid = null;
		
		if (menu.parentmenu.timedmenu != menu)
			execHide(menu.parentmenu.timedmenu.id, menu.parentmenu.timediframe.id);
		
		menu.parentmenu.timedmenu = null;
		menu.parentmenu.timediframe = null;
	}
	
	if (menu.timerid != null) {
		clearTimeout(menu.timerid);
		menu.timerid = null;
	}
}

function execDelayedHide(menu, iframe) {
	killDelayedHide(menu);
	menu.parentmenu.timedmenu = menu;
	menu.parentmenu.timediframe = iframe;
	menu.timerid = setTimeout("execHide('"+menu.id+"', '"+iframe.id+"')", MENU_HIDE_DELAY);
}

function execHide(menuid, iframeid) {
	var menu = GetHTMLObjectById(menuid);
	var iframe = GetHTMLObjectById(iframeid);
	
	SetHTMLObjectExistence(iframe, false);
	SetHTMLObjectExistenceDIV(menu, false);
	
	if (menu.parentelement) menu.parentelement.className = 'element-submenu';
	if (menu.parentmenu && menu.parentmenu.timedmenu) {
		menu.parentmenu.timedmenu.timerid = null;
		menu.parentmenu.timedmenu = null;
		menu.parentmenu.timediframe = null;
	}
}



function showMenu(menuid, parentid, parentOrient, orient) {
	var menu = GetHTMLObjectById(menuid + '-menu');
	var element = GetHTMLObjectById(menuid + '-element');
	
	menu.parentmenu = GetHTMLObjectById(parentid + '-menu');
	menu.parentelement = element;
	
	killDelayedHide(menu);

	if (!HTMLObjectExists(menu)) {
		var elementpos = GetHTMLObjectPosition(element);

		if (parentOrient == 'V' && orient == 'V')
			SetHTMLObjectPosition(menu, elementpos.x + elementpos.w, elementpos.y, 0, 0);
		else if (parentOrient == 'H' && orient == 'V')
			SetHTMLObjectPosition(menu, elementpos.x, elementpos.y + elementpos.h, 0, 0);
		else if (parentOrient == 'H' && orient == 'H') {
			parentpos = GetHTMLObjectPosition(menu.parentmenu);
			SetHTMLObjectPosition(menu, parentpos.x, elementpos.y + elementpos.h, 0, 0);
		}

		menu.parentelement.className = 'element-submenu-active';
		
		var iframe = GetHTMLObjectById(menuid + '-iframe');

		SetHTMLObjectExistenceDIV(menu, true);
		SetHTMLObjectExistenceDIV(iframe, true);
		
		var table = GetHTMLObjectById(menuid + '-table');
		var tablepos = GetHTMLObjectPosition(table);
		SetHTMLObjectPosition(iframe, tablepos.x, tablepos.y, tablepos.w, tablepos.h);
	}
}

function setActiveMenu(menuid, parentid, parentOrient, orient) {
	var activeMenu = GetHTMLObjectById(menuid + '-menu');
	activeMenu.alwaysshow = true;

	showMenu(menuid, parentid, parentOrient, orient);

	activeMenu.parentelement.className = 'element-submenu-default';
	activeMenu.className = 'menusystem-default-H';
}

function hideMenu(menuid) {
	var menu = GetHTMLObjectById(menuid + '-menu');
	var iframe = GetHTMLObjectById(menuid + '-iframe');
	if (!menu.alwaysshow) {
		while (menu.parentmenu != null) {
			execDelayedHide(menu, iframe);
			menu = menu.parentmenu;
		}
	}
}

function stopHideMenu(menuid) {
	var menu = GetHTMLObjectById(menuid + '-menu');
	while (menu.parentmenu != null) {
		killDelayedHide(menu);
		menu = menu.parentmenu;
	}
}

	

