﻿

function FlexMenu(PageArea, DirLevel){
	document.write('<link href="theme/Flex/menu/default/flexmenu.css" type="text/css" rel="stylesheet" />');
	if (BrowserDetect.browser == 'Explorer'){
		document.write('<link rel="stylesheet" type="text/css" href="theme/Flex/menu/default/FlexMenu_ie.css" media="screen"/>');
		if (BrowserDetect.version < 7)
			document.write('<link rel="stylesheet" type="text/css" href="theme/Flex/menu/default/FlexMenu_ie6.css" media="screen"/>');
	}
	this.MenuItemArray = new Array();
	// Paths to Stuff
	var _pathImages = DirLevel + 'theme/Flex/menu/';
	var _pathArrowImages = _pathImages;
	var _styleName = DirLevel + 'util/';this.SetStyleName = function(s){_styleName = s;};
	// Feature Enablement Booleans
	var _showEmptyGridOnLoad = true;
	var _showEmptyGridAfterSearch = true;
	var _showToolTips = false;this.EnableToolTips = function(s){_showToolTips = s;};
	// Control Names
	var _loadingAnimation = '';this.SetLoadingAnimation = function(s){_loadingAnimation = s;}
	var _errorMessageContainer = '';this.SetErrorMessageContainer = function(s){_errorMessageContainer = s;}
	// Other parameters
	var _controlNamePrefix = 'menu';
	var _name = '';this.SetName = function(s){_name = s;};this.GetName = function(){return _name;};
	
  this.Initialize = function(){
		this.BuildBaseMenu();
  };

  this.BuildBaseMenu = function(){
		GetControl(_controlNamePrefix + '_' + PageArea).innerHTML = '';
		var divE = document.getElementById(_controlNamePrefix + '_' + PageArea);
		
		var UL = document.createElement('UL');
		UL.setAttribute('id','navigation');
		divE.appendChild(UL);
		
		for (var i=0;i<this.MenuItemArray.length;i++){
			var LI = document.createElement('LI');
			if (this.MenuItemArray[i].IsActive())
				LI.className = 'active';
			UL.appendChild(LI);
			
			var LNK = document.createElement('A');
			LNK.className = 'nav-a';
			if ((this.MenuItemArray[i].GetUrl() != null) && (this.MenuItemArray[i].GetUrl() != ''))
				LNK.setAttribute('href', this.MenuItemArray[i].GetUrl());
			else
				LNK.setAttribute('href', 'javascript: void(0);');
			LI.appendChild(LNK);
			
			var SPNl = document.createElement('SPAN');
			SPNl.className = 'menu-left';
			LNK.appendChild(SPNl);
			
			var SPNm = document.createElement('SPAN');
			SPNm.className = 'menu-mid';
			SPNm.innerHTML = this.MenuItemArray[i].GetText();
			LNK.appendChild(SPNm);
			
			var SPNr = document.createElement('SPAN');
			SPNr.className = 'menu-right';
			LNK.appendChild(SPNr);
			
			if (this.MenuItemArray[i].Children.length > 0){
				LI.appendChild(BuildSubMenu(this.MenuItemArray[i]));
			}
		}
  }
  function BuildSubMenu(parentMI){
		var divE = document.createElement('DIV');
		divE.className = 'sub';
		
		var UL = document.createElement('UL');
		UL.setAttribute('id','navigation');
		divE.appendChild(UL);
		
		for (var i=0;i<parentMI.Children.length;i++){
			var LI = document.createElement('LI');
			if (parentMI.Children[i].IsActive())
				LI.className = 'active';
			UL.appendChild(LI);
			
			var LNK = document.createElement('A');
			LNK.className = 'nav-a';
			LNK.innerHTML = parentMI.Children[i].GetText();
			if ((parentMI.Children[i].GetUrl() != null) && (parentMI.Children[i].GetUrl() != ''))
				LNK.setAttribute('href', parentMI.Children[i].GetUrl());
			else
				LNK.setAttribute('href', '#');
			LI.appendChild(LNK);
			
		}
		var divEf = document.createElement('DIV');
		divEf.className = 'btm-bg';
		divE.appendChild(divEf);
		
		return divE;
  }
}

function MenuItem(text,url,isActive){
	this.Children = new Array();
	var _url = null;this.GetUrl = function(){return _url;};this.SetUrl = function(s){_url=s;};
	var _text = null;this.GetText = function(){return _text;};this.SetText = function(s){_text=s;};
	var _uniqueID = RandomString(6);this.GetUniqueID = function(){return _uniqueID;};
	var _isActive = false;this.IsActive = function(){return _isActive;};this.SetActive = function(s){_isActive=s;};
	if (text !== 'undefined')
		_text = text;
	if (url !== 'undefined')
		_url = url;
	if (isActive !== 'undefined')
		_isActive = isActive;
}

function RandomString(string_length) {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	//var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}
