//File Name: dispMenu.js, Created On: 5/23/05.
// Add an empty image before new line after line feed
// to adjust start point of menu texts
function addEmptyImage(src_str) {

	var rep_work;
	var rep_pos;
	var rep_str;

	rep_str = '<dummy><img src="../images/empty.gif" border="0">';

	rep_work = src_str;
	for (rep_pos=0 ; rep_pos<rep_work.length ; rep_pos++) {
		rep_pos = rep_work.indexOf('<br>', rep_pos);
		if (rep_pos == -1) {
			break;
		} else {
			rep_work = rep_work.replace('<br>',rep_str);
		}
	}
	
	for (rep_pos=0 ; rep_pos<rep_work.length ; rep_pos++) {
		rep_pos = rep_work.indexOf('<dummy>', rep_pos);
		if (rep_pos == -1) {
			break;
		} else {
			rep_work = rep_work.replace('<dummy>','<br>');
		}
	}
	return rep_work;
}

// Drow dinamically Main Menu
function dispMainMenu(menuList) {
	var tagText;
	var htmlText;
	var firstCol = true;
	var isInside = false;
	var rep_work;

	htmlText = "";

	tagText = '<tr><td nowrap>';  // dependent on other parts in Main Menu
	htmlText = htmlText + tagText;

	for (var i = 0 ; i < menuList.length ; i++ ) {
		tagText ="";
		if (menuList[i].mainClass == "") {
			if (isInside) {
				tagText = "</div>";
				htmlText = htmlText + tagText;
				isInside = false;
			}
			if (!firstCol) {
				tagText = "</div>";
				htmlText = htmlText + tagText;
			} else {
				firstCol = false;
			}
			tagText = '<div>';
			htmlText = htmlText + tagText;
	  		tagText = '<a href="javascript:fncJumpTo(\'' + menuList[i].itemNo + '\',' + menuList[i].type + ')" class="menulink">';
			htmlText = htmlText + tagText;
			// adjustment for line feed with empty image
			rep_work = addEmptyImage(menuList[i].subClass);
	    		tagText = '<img src="../images/list.gif" border="0">' + rep_work + '</a>';
			htmlText = htmlText + tagText;
		} else if (menuList[i].mainClass != "1") {
			if (isInside) {
				tagText = "</div>";
				htmlText = htmlText + tagText;
				isInside = false;
			}
			if (!firstCol) {
				tagText = "</div>";
				htmlText = htmlText + tagText;
			} else {
				firstCol = false;
			}
			// Main Class
			tagText = '<div class="menulink" style="text-decoration:none;">';
			htmlText = htmlText + tagText;
			tagText = '<img src="../images/arrow_r.gif" border="0"><font color="black">' + menuList[i].mainClass + '</font>';
			htmlText = htmlText + tagText;
			tagText = '<div style="padding-left: 1em;">';
			htmlText = htmlText + tagText;
			// Sub Class
	 		tagText = '<a href="javascript:fncJumpTo(\'' + menuList[i].itemNo + '\',' + menuList[i].type + ')" class="menulink1">';
			htmlText = htmlText + tagText;
			// adjustment for line feed with empty image
			rep_work = addEmptyImage(menuList[i].subClass);
	    		tagText = '<img src="../images/list.gif" border="0">' + rep_work + '</a>';
			htmlText = htmlText + tagText;
			isInside = true;
		} else {
			if (isInside) {
				tagText = '<br>';
				htmlText = htmlText + tagText;
			} else {
				isInside = true;
			}
	 		tagText = '<a href="javascript:fncJumpTo(\'' + menuList[i].itemNo + '\',' + menuList[i].type + ')" class="menulink1">';
			htmlText = htmlText + tagText;
			// adjustment for line feed with empty image
			rep_work = addEmptyImage(menuList[i].subClass);
	    		tagText = '<img src="../images/list.gif" border="0">' + rep_work + '</a>';
			htmlText = htmlText + tagText;
		}
	}

	tagText = "</div></td></tr>";
	htmlText = htmlText + tagText;

	document.writeln(htmlText);
}