// JavaScript Document

function createHeaderMenu(xmlDoc, selectSection)
{
	var sitehome = xmlDoc.getElementsByTagName("site");
	var menus = sitehome.item(0).getElementsByTagName("menu");
	
	// loop through the sections
	for(var n=0; n <= menus.length; n++)
	{
		// check the existance of a menu in the list
		if(menus.item(n) != null)
		{
			// find the matching menu
			if(menus.item(n).getAttribute("id") == "header")
			{
				var docElm = menus.item(n);
				var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
				var sections = newdoc.getElementsByTagName("section"); // get the sections list of nodes from the xml doc
				
				// check the existance of a section in the list
				if(sections.item(0) != null)
				{
					var headerMenu;
					var menuStartItem;
					var menuItem;
					var menuEndItem;
					var voidLink = "javascript:void(0)";
					var itemsCount = sections.length;
					var itemsStartCount = 1;
					var firstItem = 0;
					var lastItem = sections.length-1;
					var highlightStyle = "style=\"font-weight:bold; color:#CCCCCC;\"";
					var regularStyle = "style=\"font-weight:regular\"";
					
					// get the first node
					var startItemTitle = sections.item(firstItem).getElementsByTagName("title").item(0).firstChild;
					var startItemDesc = sections.item(firstItem).getElementsByTagName("desc").item(0).firstChild;
					var startItemLink = sections.item(firstItem).getElementsByTagName("link").item(0).firstChild;
					menuStartItem = "<li id=\"startitem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (startItemLink ? startItemLink.nodeValue : voidLink) + "\" title=\"" + (startItemDesc ? startItemDesc.nodeValue : '') + "\" " + ((sections.item(firstItem).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (startItemTitle ? startItemTitle.nodeValue : null) + "</a></li>";
					// collect the list
					headerMenu = menuStartItem;
					
					// loops through the sections starting at the second node
					for(var n=itemsStartCount; n < itemsCount; n++)
					{
						if(n < lastItem)
						{
							var menuItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
							var menuItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
							var menuItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
							menuItem = "<li id=\"menuitem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (menuItemLink ? menuItemLink.nodeValue : voidLink) + "\" title=\"" + (menuItemDesc ? menuItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (menuItemTitle ? menuItemTitle.nodeValue : null) + "</a></li>";
							// collect the list
							headerMenu += menuItem;
						}
						else
						{
							var endItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
							var endItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
							var endItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
							menuEndItem = "<li id=\"enditem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (endItemLink ? endItemLink.nodeValue : voidLink) + "\" title=\"" + (endItemDesc ? endItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (endItemTitle ? endItemTitle.nodeValue : null) + "</a></li>";
							// collect the list
							headerMenu += menuEndItem;
						}
					}
					
					// push the list in the element
					document.getElementById("headermenu").innerHTML = headerMenu;
				}
				
				break;
			}
		}
	}
}

function createMainMenu(xmlDoc, selectSection)
{
	var sitehome = xmlDoc.getElementsByTagName("site");
	var menus = sitehome.item(0).getElementsByTagName("menu");
	
	// loop through the sections
	for(var n=0; n <= menus.length; n++)
	{
		// check the existance of a menu in the list
		if(menus.item(n) != null)
		{
			// find the matching menu
			if(menus.item(n).getAttribute("id") == "main")
			{
				var docElm = menus.item(n);
				var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
				var sections = newdoc.getElementsByTagName("section"); // get the sections list of nodes from the xml doc
		
				// check the existance of a section in the list
				if(sections.item(0) != null)
				{
					var mainMenu;
					var menuStartItem;
					var menuItem;
					var menuEndItem;
					var voidLink = "javascript:void(0)";
					var itemsCount = sections.length;
					var itemsStartCount = 1;
					var firstItem = 0;
					var lastItem = sections.length-1;
					var highlightStyle = "style=\"font-weight:bold; color:#006699;\"";
					var regularStyle = "style=\"font-weight:regular\"";
					
					// get the first node
					var startItemTitle = sections.item(firstItem).getElementsByTagName("title").item(0).firstChild;
					var startItemDesc = sections.item(firstItem).getElementsByTagName("desc").item(0).firstChild;
					var startItemLink = sections.item(firstItem).getElementsByTagName("link").item(0).firstChild;
					menuStartItem = "<li id=\"startitem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (startItemLink ? startItemLink.nodeValue : voidLink) + "\" title=\"" + (startItemDesc ? startItemDesc.nodeValue : '') + "\" " + ((sections.item(firstItem).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (startItemTitle ? startItemTitle.nodeValue : null) + "</a></li>";
					// collect the list
					mainMenu = menuStartItem;
					
					// loops through the sections starting at the second node
					for(var n=itemsStartCount; n < itemsCount; n++)
					{
						if(n < lastItem)
						{
							var menuItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
							var menuItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
							var menuItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
							menuItem = "<li id=\"menuitem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (menuItemLink ? menuItemLink.nodeValue : voidLink) + "\" title=\"" + (menuItemDesc ? menuItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (menuItemTitle ? menuItemTitle.nodeValue : null) + "</a></li>";
							// collect the list
							mainMenu += menuItem;
						}
						else
						{
							var endItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
							var endItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
							var endItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
							menuEndItem = "<li id=\"enditem\" class=\"HMenuItem BorderLess Transparent\"><a href=\"" + (endItemLink ? endItemLink.nodeValue : voidLink) + "\" title=\"" + (endItemDesc ? endItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (endItemTitle ? endItemTitle.nodeValue : null) + "</a></li>";
							// collect the list
							mainMenu += menuEndItem;
						}
					}
					
					// push the list in the element
					document.getElementById("mainmenu").innerHTML = mainMenu;
				}
				
				// End loop through the sections
				break;
			}
		}
	}
}

function createLocalMenu(xmlDoc, selectSection, selectCategory)
{
	var sitehome = xmlDoc.getElementsByTagName("site");
	var menus = sitehome.item(0).getElementsByTagName("menu");
	
	// loop through the sections
	for(var n=0; n <= menus.length; n++)
	{
		// check the existance of a menu in the list
		if(menus.item(n) != null)
		{
			// find the matching menu
			if(menus.item(n).getAttribute("id") == "main")
			{
				var docElm = menus.item(n);
				var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
				var sections = newdoc.getElementsByTagName("section"); // get the sections list of nodes from the xml doc
				
				// loop through the sections
				for(var n=0; n <= sections.length; n++)
				{
					// check the existance of a section in the list
					if(sections.item(n) != null)
					{
						// find the matching section
						if(sections.item(n).getAttribute("id") == selectSection)
						{
							var docElm = sections.item(n);
							var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
							var categories = newdoc.getElementsByTagName("category"); // get the categories list of nodes from the xml doc
							
							// check the existance of a category in the list
							if(categories.item(0) != null)
							{
								// start populating the menu
								var localMenu;
								var menuStartItem;
								var menuItem;
								var menuEndItem;
								var voidLink = "javascript:void(0)";
								var itemsCount = categories.length;
								var itemsStartCount = 1;
								var firstItem = 0;
								var lastItem = categories.length-1;
								var highlightStyle = "style=\"font-weight:bold; color:#006699;\"";
								var regularStyle = "style=\"font-weight:regular\"";
								
								// get the first node
								var startItemTitle = categories.item(firstItem).getElementsByTagName("title").item(0).firstChild;
								var startItemDesc = categories.item(firstItem).getElementsByTagName("desc").item(0).firstChild;
								var startItemLink = categories.item(firstItem).getElementsByTagName("link").item(0).firstChild;
								menuStartItem = "<li id=\"startitem\" class=\"LocalHMenuItem BorderLess Transparent\"><a href=\"" + (startItemLink ? startItemLink.nodeValue : voidLink) + "\" title=\"" + (startItemDesc ? startItemDesc.nodeValue : '') + "\" " + ((categories.item(firstItem).getAttribute("id") == (selectSection + "." + selectCategory)) ? highlightStyle : regularStyle) + ">"+ (startItemTitle ? startItemTitle.nodeValue : null) + "</a></li>";
								// collect the list
								localMenu = menuStartItem;
								
								// loops through the sections starting at the second node
								for(var n=itemsStartCount; n < itemsCount; n++)
								{
									if(n < lastItem)
									{
										var menuItemTitle = categories.item(n).getElementsByTagName("title").item(0).firstChild;
										var menuItemDesc = categories.item(n).getElementsByTagName("desc").item(0).firstChild;
										var menuItemLink = categories.item(n).getElementsByTagName("link").item(0).firstChild;
										menuItem = "<li id=\"menuitem\" class=\"LocalHMenuItem BorderLess Transparent\"><a href=\"" + (menuItemLink ? menuItemLink.nodeValue : voidLink) + "\" title=\"" + (menuItemDesc ? menuItemDesc.nodeValue : '') + "\" " + ((categories.item(n).getAttribute("id") == (selectSection + "." + selectCategory)) ? highlightStyle : regularStyle) + ">"+ (menuItemTitle ? menuItemTitle.nodeValue : null) + "</a></li>";
										// collect the list
										localMenu += menuItem;
									}
									else
									{
										var endItemTitle = categories.item(n).getElementsByTagName("title").item(0).firstChild;
										var endItemDesc = categories.item(n).getElementsByTagName("desc").item(0).firstChild;
										var endItemLink = categories.item(n).getElementsByTagName("link").item(0).firstChild;
										menuEndItem = "<li id=\"enditem\" class=\"LocalHMenuItem BorderLess Transparent\"><a href=\"" + (endItemLink ? endItemLink.nodeValue : voidLink) + "\" title=\"" + (endItemDesc ? endItemDesc.nodeValue : '') + "\" " + ((categories.item(n).getAttribute("id") == (selectSection + "." + selectCategory)) ? highlightStyle : regularStyle) + ">"+ (endItemTitle ? endItemTitle.nodeValue : null) + "</a></li>";
										// collect the list
										localMenu += menuEndItem;
									}
								}
					
								// push the list in the element
								document.getElementById("localmenu").innerHTML = localMenu;
							}
							
							// End loop through the categories
							break;
						}
					}
				}
				// End loop through the sections
				break;
			}
		}
	}
}

function createContentMenu(xmlDoc, selectSection, selectCategory, selectItem)
{
	var sitehome = xmlDoc.getElementsByTagName("site");
	var menus = sitehome.item(0).getElementsByTagName("menu");
	
	// loop through the sections
	for(var n=0; n <= menus.length; n++)
	{
		// check the existance of a menu in the list
		if(menus.item(n) != null)
		{
			// find the matching menu
			if(menus.item(n).getAttribute("id") == "main")
			{
				var docElm = menus.item(n);
				var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
				var sections = newdoc.getElementsByTagName("section"); // get the sections list of nodes from the xml doc
				
				// loop through the sections
				for(var n=0; n <= sections.length; n++)
				{
					// check the existance of a section in the list
					if(sections.item(n) != null)
					{
						// find the matching section
						if(sections.item(n).getAttribute("id") == selectSection)
						{
							var docElm = sections.item(n);
							var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
							var categories = newdoc.getElementsByTagName("category"); // get the categories list of nodes from the xml doc
							
							// loop through the categories
							for(var n=0; n <= categories.length; n++)
							{
								// check the existance of a category in the list
								if(categories.item(n) != null)
								{
									// find the matching category
									if(categories.item(n).getAttribute("id") == (selectSection + "." + selectCategory))
									{
										var docElm = categories.item(n);
										var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
										var items = newdoc.getElementsByTagName("item"); // get the categories list of nodes from the xml doc
										
										// check the existance of an item in the list
										if(items.item(0) != null)
										{
											// start populating the menu
											var localMenu;
											var menuStartItem;
											var menuItem;
											var menuEndItem;
											var voidLink = "javascript:void(0)";
											var itemsCount = items.length;
											var itemsStartCount = 1;
											var firstItem = 0;
											var lastItem = items.length-1;
											var highlightStyle = "style=\"font-weight:bold; color:#006699;\"";
											var regularStyle = "style=\"font-weight:regular\"";
											
											// get the first node
											var startItemTitle = items.item(firstItem).getElementsByTagName("title").item(0).firstChild;
											var startItemDesc = items.item(firstItem).getElementsByTagName("desc").item(0).firstChild;
											var startItemLink = items.item(firstItem).getElementsByTagName("link").item(0).firstChild;
											menuStartItem = "<li id=\"startitem\" class=\"ContentHMenuItem BorderLess Transparent\"><a href=\"" + (startItemLink ? startItemLink.nodeValue : voidLink) + "\" title=\"" + (startItemDesc ? startItemDesc.nodeValue : '') + "\" " + ((items.item(firstItem).getAttribute("id") == (selectSection + "." + selectCategory + "." + selectItem)) ? highlightStyle : regularStyle) + ">"+ (startItemTitle ? startItemTitle.nodeValue : null) + "</a></li>";
											// collect the list
											localMenu = menuStartItem;
											
											// loops through the sections starting at the second node
											for(var n=itemsStartCount; n < itemsCount; n++)
											{
												if(n < lastItem)
												{
													var menuItemTitle = items.item(n).getElementsByTagName("title").item(0).firstChild;
													var menuItemDesc = items.item(n).getElementsByTagName("desc").item(0).firstChild;
													var menuItemLink = items.item(n).getElementsByTagName("link").item(0).firstChild;
													menuItem = "<li id=\"menuitem\" class=\"ContentHMenuItem BorderLess Transparent\"><a href=\"" + (menuItemLink ? menuItemLink.nodeValue : voidLink) + "\" title=\"" + (menuItemDesc ? menuItemDesc.nodeValue : '') + "\" " + ((items.item(n).getAttribute("id") == (selectSection + "." + selectCategory + "." + selectItem)) ? highlightStyle : regularStyle) + ">"+ (menuItemTitle ? menuItemTitle.nodeValue : null) + "</a></li>";
													// collect the list
													localMenu += menuItem;
												}
												else
												{
													var endItemTitle = items.item(n).getElementsByTagName("title").item(0).firstChild;
													var endItemDesc = items.item(n).getElementsByTagName("desc").item(0).firstChild;
													var endItemLink = items.item(n).getElementsByTagName("link").item(0).firstChild;
													menuEndItem = "<li id=\"enditem\" class=\"ContentHMenuItem BorderLess Transparent\"><a href=\"" + (endItemLink ? endItemLink.nodeValue : voidLink) + "\" title=\"" + (endItemDesc ? endItemDesc.nodeValue : '') + "\" " + ((items.item(n).getAttribute("id") == (selectSection + "." + selectCategory + "." + selectItem)) ? highlightStyle : regularStyle) + ">"+ (endItemTitle ? endItemTitle.nodeValue : null) + "</a></li>";
													// collect the list
													localMenu += menuEndItem;
												}
											}
											
											// push the list in the element
											document.getElementById("contentmenu").innerHTML = localMenu;
											document.getElementById("contentmenu").className = "Visible";
										}
										
										// End loop through the items
										break;
									}
								}
							}
							// End loop through the categories
							break;
						}
					}
				}
				// End loop through the sections
				break;
			}
		}
	}
}

function createFooterMenu(xmlDoc, selectSection)
{
	var sitehome = xmlDoc.getElementsByTagName("site");
	var menus = sitehome.item(0).getElementsByTagName("menu");
	
	// loop through the sections
	for(var n=0; n <= menus.length; n++)
	{
		if(menus.item(n) != null)
		{
			// find the matching menu
			if(menus.item(n).getAttribute("id") == "footer")
			{
				var docElm = menus.item(n);
				var newdoc = domAdapter.parseXml(domAdapter.convertToString(docElm));
				var sections = newdoc.getElementsByTagName("section"); // get the sections list of nodes from the xml doc
				
				var footerMenu;
				var menuStartItem;
				var menuItem;
				var menuEndItem;
				var voidLink = "javascript:void(0)";
				var itemsCount = sections.length;
				var itemsStartCount = 1;
				var firstItem = 0;
				var lastItem = sections.length-1;
				var highlightStyle = "style=\"font-weight:bold; color:#006699;\"";
				var regularStyle = "style=\"font-weight:regular\"";
				
				// get the first node
				var startItemTitle = sections.item(firstItem).getElementsByTagName("title").item(0).firstChild;
				var startItemDesc = sections.item(firstItem).getElementsByTagName("desc").item(0).firstChild;
				var startItemLink = sections.item(firstItem).getElementsByTagName("link").item(0).firstChild;
				menuStartItem = "<li id=\"startitem\" class=\"FooterHMenuItem BorderLess Transparent\"><a href=\"" + (startItemLink ? startItemLink.nodeValue : voidLink) + "\" title=\"" + (startItemDesc ? startItemDesc.nodeValue : '') + "\" " + ((sections.item(firstItem).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (startItemTitle ? startItemTitle.nodeValue : null) + "</a></li>";
				// collect the list
				footerMenu = menuStartItem;
				
				// loops through the sections starting at the second node
				for(var n=itemsStartCount; n < itemsCount; n++)
				{
					if(n < lastItem)
					{
						var menuItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
						var menuItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
						var menuItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
						menuItem = "<li id=\"menuitem\" class=\"FooterHMenuItem BorderLess Transparent\"><a href=\"" + (menuItemLink ? menuItemLink.nodeValue : voidLink) + "\" title=\"" + (menuItemDesc ? menuItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (menuItemTitle ? menuItemTitle.nodeValue : null) + "</a></li>";
						// collect the list
						footerMenu += menuItem;
					}
					else
					{
						var endItemTitle = sections.item(n).getElementsByTagName("title").item(0).firstChild;
						var endItemDesc = sections.item(n).getElementsByTagName("desc").item(0).firstChild;
						var endItemLink = sections.item(n).getElementsByTagName("link").item(0).firstChild;
						menuEndItem = "<li id=\"enditem\" class=\"FooterHMenuItem BorderLess Transparent\"><a href=\"" + (endItemLink ? endItemLink.nodeValue : voidLink) + "\" title=\"" + (endItemDesc ? endItemDesc.nodeValue : '') + "\" " + ((sections.item(n).getAttribute("id") == selectSection) ? highlightStyle : regularStyle) + ">"+ (endItemTitle ? endItemTitle.nodeValue : null) + "</a></li>";
						// collect the list
						footerMenu += menuEndItem;
					}
				}
		
				// push the list in the element
				document.getElementById("footermenu").innerHTML = footerMenu;
				
				// End loop through the sections
				break;
			}
		}
	}
}

function clearStatusBar()
{
	window.status='';
	return true;
}
