/////////////////////////////////////////////////////////////////////////////////////////////
// Classes for Healthline Information Systems, Inc.
// Written by Gene M. Angelo, www.Business2Web.com
// Copyright (C) 2002, Gene M. Angelo
/////////////////////////////////////////////////////////////////////////////////////////////

// Globals needed
var g_imageDir = "Graphics/NavbarLeft/";

/////////////////////////////////////////////////////////////////////////////////////////////
// CHISSubMenu class
// 
// menuNo			- The positional number of the submenu's parent menu within the menu system
// subMenuNo		- The positional number of the submenu within the menu system
// menuText			- The text of the sub menu item
// menuURL			- The link to goto when menuText is clicked
// menuClassClick		- The class to use for the td containing the sub menu item when it has been // selected
// menuClassOut		- The class to use for the td containing the sub menu item when onMouseOut
// menuClassOver	- The class to use for the td containing the sub menu item when onMouseOver
// bIsOn			- true if the menu option is active, that is, selected from the menu
/////////////////////////////////////////////////////////////////////////////////////////////
function CHISSubMenu(menuNo, subMenuNo, menuText, menuURL, menuClassClick, menuClassOut, menuClassOver)
	{
	this.menuNo		= menuNo;
	this.subMenuNo	= subMenuNo;
	this.menuText	= menuText;
	this.menuURL	= menuURL;
	this.arrayClass	= new Array(menuClassClick, menuClassOut, menuClassOver);	

	CHISSubMenu.OPTION_CLICK	= 0;
	CHISSubMenu.OPTION_OUT		= 1;
	CHISSubMenu.OPTION_OVER		= 2;

	CHISSubMenu.prototype.getSubMenuIdTR = function()
		{
		return ("submenu" + this.menuNo + this.subMenuNo + "TR");
		}

	CHISSubMenu.prototype.getSubMenuIdTD = function()
		{
		return ("submenu" + this.menuNo + this.subMenuNo + "TD");
		}

	CHISSubMenu.prototype.setSubMenu = function(option)
		{	
		document.getElementById(this.getSubMenuIdTD()).className = this.arrayClass[CHISSubMenu.OPTION_OVER];		
		}

	// This function returns the td html needed to display the
	// sub menu item. One of the OPTION_X..X values is expected
	// to determine the type of html you want to get returned
	CHISSubMenu.prototype.getHTML = function(option)
		{
		var html;

		html = 			
			"<tr id='" + this.getSubMenuIdTR() + "' style='cursor: pointer;'> " +		
				"<td id='" + this.getSubMenuIdTD() + "' class='" + this.arrayClass[option] + "' " +
					"onMouseOver=\"this.className='" + this.arrayClass[CHISSubMenu.OPTION_OVER] + "';\" " +					
					"onMouseOut=\"this.className='" + this.arrayClass[CHISSubMenu.OPTION_OUT] + "';\"" +		
					"onClick=\"window.location.href='" + this.menuURL + "';\"" +					
					">" +					
					this.menuText +					
				"</td> " +			
			"</tr>";
		return html;
		}

	return this;
	}

////////////////////////////////////////////////////////////////////////////////////////////
// CHISMenu class
//
// menuNo		- The index of the menu within the CHISMenuControl class object
// arraySubMenu	- An array of CHISSubMenu objects of all child submenu items belonging to this menu
// imgURLOn		- The url of the image that is to be displayed when the menu button has been selected
// imgURLOut	- The url of the image that is to be displayed when onMouseOut
// imgURLOver	- The url of the image that is to be displayed when onMouseOver
////////////////////////////////////////////////////////////////////////////////////////////
function CHISMenu(menuNo, arraySubMenu, imgURLOn, imgURLOut, imgURLOver)
	{	
	// Inits from passed parameters
	this.menuNo			= menuNo;
	this.arraySubMenu	= arraySubMenu;
	this.arrayImage		= new Array(new CImage(imgURLOn), new CImage(imgURLOut), new CImage(imgURLOver));		

	// Below are initialized down below
	this.bOpen			= false;	// Is the menu currently "open" or "dropped down"
	this.origInnerHTML	= "";		// Holds the original inner html so we can restore it onMouseOut	

	this.idName			= null;	// See initMenu()
	this.idObject		= null;	// See initMenu()
	this.imgName		= null;	// See initMenu()
	this.imgObject		= null;	// See initMenu()

	// Statics for mouse events - used as passed parameters to functions
	// and used as index into the arrayImage to get the proper menu buttons
	// displayed for the proper mouse events.
	CHISMenu.OPTION_CLICK	= 0;
	CHISMenu.OPTION_OUT		= 1;
	CHISMenu.OPTION_OVER	= 2;

	// Saves the original inner html so we can restore it onMouseOut
	// DO NOT CALL THIS FUNCTION DIRECTLY, it must be called from 
	// a CHISMenuControl class object
	CHISMenu.prototype.initMenu = function(idName, imgName)
		{
		this.idName		= idName;
		this.imgName	= imgName;		
		this.updateAllObjects();	// Always get the current object pointers		
		this.origInnerHTML = this.idObject.innerHTML;	// Only call this after updateAllObjects()!
		}

	// WARNING: This member must be called every time you need to access an object
	CHISMenu.prototype.updateAllObjects = function()
		{
		// We must update our objects because we are dynamically replacing the html
		// on the web page. Doing this invalidates our pointers. We need to update
		// them with every menu action we take.
		this.idObject	= document.getElementById(this.idName);
		this.imgObject	= document.getElementsByName(this.imgName)[0];		
		//if(! this.imgObject)
		//	alert(this.imgObject);
		}

	// Is the menu currently open?
	CHISMenu.prototype.isOpen = function()
		{
		return this.bOpen;
		}

	// Set the open status
	CHISMenu.prototype.setOpen = function(bOpen)
		{
		this.bOpen = bOpen;
		}

	// Sets the state of the menu button. This function expects a OPTION_X..X value
	CHISMenu.prototype.setMenu = function(option)
		{
		this.updateAllObjects();		
		if(! this.idObject)	// Prohibit any actions if the page is still loading.
			return false;
		if(option == CHISMenu.OPTION_OUT)
			this.imgObject.src = this.arrayImage[CHISMenu.OPTION_OUT].getURL();			
		else
		if(option == CHISMenu.OPTION_OVER)			
			this.imgObject.src = this.arrayImage[CHISMenu.OPTION_OVER].getURL();			
		else		
		if(option == CHISMenu.OPTION_CLICK)
			{
			if(this.isOpen())
				{				
				this.setOpen(false);	
				//alert(this.origInnerHTML);
				this.idObject.innerHTML = this.origInnerHTML;
				}
			else
				{
				this.setOpen(true);
				this.idObject.innerHTML = this.getHTML(option);
				}
			}
		this.updateAllObjects();

		return true;
		}

	// Sets the state of the submenu - this is called from the CHISMenuControl class object
	CHISMenu.prototype.setSubMenu = function(subMenu, option)
		{
		if(! this.isOpen())	// Expand the menu if it is not currently expanded
			this.setMenu(CHISMenu.OPTION_CLICK);
		this.arraySubMenu[subMenu].setSubMenu(option);
		}

	// This function returns the td html needed to display the menu item. One of the OPTION_X..X values 
	// is expected to determine the type of html you want to get returned.
	CHISMenu.prototype.getHTML = function(option)
		{
		var html = "";

		if(this.arraySubMenu != null)
			{
			html += "<table width='100%' bgcolor='#FFFFFF' border='1' cellpadding='0' cellspacing='0'>";
			
			for(i = 0; i < this.arraySubMenu.length; i++)
				html += this.arraySubMenu[i].getHTML(CHISSubMenu.OPTION_OUT);

			html += "</table>";
			}


		html +=
		"<table width='100%' bgcolor='#FFFFFF' border='0' cellpadding='0' cellspacing='0'>" +
			"<tr>" +
				"<td>" +
					"<a href='#' onClick='JavaScript: g_menuControl.setMenu(" + this.menuNo + ", CHISMenu.OPTION_CLICK); return false;'>" +
						"<img src='" + this.arrayImage[option].getURL() + "' border='0' />" + 
					"</a>" +
				"</td>" +
			"</tr>" +
		"</table>";
					
		return html;
		}

/* Below code makes submenu items appear below the button
		html =
		"<table width='100%' bgcolor='#000000' border='0' cellpadding='0' cellspacing='0'>" +
			"<tr>" +
				"<td>" +
					"<a href='#' onClick='JavaScript: g_menuControl.setMenu(" + this.menuNo + ", CHISMenu.OPTION_CLICK); return false;'>" +
						"<img src='" + this.arrayImage[option].getURL() + "' border='0' />" + 
					"</a>" +
				"</td>" +
			"</tr>" +
		"</table>";						

		if(this.arraySubMenu != null)
			{
			html += "<table width='100%' bgcolor='#000000' border='1' cellpadding='0' cellspacing='0'>";
			
			for(i = 0; i < this.arraySubMenu.length; i++)
				html += this.arraySubMenu[i].getHTML(CHISSubMenu.OPTION_OUT);

			html += "</table>";
			}

		return html;
		}
*/

	return this;
	}

////////////////////////////////////////////////////////////////////////////////////////////
// CHISMenuControl class
//
////////////////////////////////////////////////////////////////////////////////////////////
function CHISMenuControl(sRelDir)
	{				
	// Relative dir to any links or graphics if applicable
	this.sRelDir = (sRelDir == null) ? "./" : String.trimAll(sRelDir) + "/";

	// If bAutoClose = true, only one menu may be open at a time e.g. others close when one is opened
	this.bAutoClose = false;

	// This is our control array that will hold all of our sub menu arrays below...
	this.arrayMenuCtrl = new Array();

	// These arrays hole our sub menu
	this.arraySubMenuHome = new Array();	// home
	this.arraySubMenuProd = new Array();	// products
	this.arraySubMenuServ = new Array();	// services
	this.arraySubMenuSupp = new Array();	// support
	this.arraySubMenuConn = new Array();	// contact

	// Note: these values MUST correspond to the proper element
	// associated with the menu in the arrayMenu array!
	CHISMenuControl.MENU_HOME		= 0;
	CHISMenuControl.MENU_PRODUCTS	= 1;
	CHISMenuControl.MENU_SERVICES	= 2;
	CHISMenuControl.MENU_SUPPORT	= 3;
	CHISMenuControl.MENU_CONTACT	= 4;

	// This function MUST be called in the body onLoad event
	// in order to work properly
	CHISMenuControl.prototype.initMenuControl = function(bAutoClose)
		{
		this.bAutoClose = bAutoClose;
		this.arrayMenuCtrl[CHISMenuControl.MENU_HOME].initMenu("idHome", "imgHome");
		this.arrayMenuCtrl[CHISMenuControl.MENU_PRODUCTS].initMenu("idProducts", "imgProducts");
		this.arrayMenuCtrl[CHISMenuControl.MENU_SERVICES].initMenu("idServices", "imgServices");
		this.arrayMenuCtrl[CHISMenuControl.MENU_SUPPORT].initMenu("idSupport", "imgSupport");
		this.arrayMenuCtrl[CHISMenuControl.MENU_CONTACT].initMenu("idContact", "imgContact");
		}

	// Returns the relative address to all graphics and links
	CHISMenuControl.prototype.getRelDir = function()
		{
		return this.sRelDir;
		}

	// Returns the graphics directory - note this returns the full path.
	CHISMenuControl.prototype.getGraphicsDir = function()
		{
		return this.sRelDir + g_imageDir;
		}

	// All menu actions must come through this function here!
	CHISMenuControl.prototype.setMenu = function(menu, option)
		{
		if(this.bAutoClose && option == CHISMenu.OPTION_CLICK)
			{
			for(n = 0; n < this.arrayMenuCtrl.length; n++)
				{				
				if(n != menu && this.arrayMenuCtrl[n].isOpen())
					this.arrayMenuCtrl[n].setMenu(CHISMenu.OPTION_CLICK);					
				}
			}

		return this.arrayMenuCtrl[menu].setMenu(option);
		}

	// All submenu actions must come through this function here!
	CHISMenuControl.prototype.setSubMenu = function(menu, subMenu, option)
		{
		if(this.bAutoClose)
			this.setMenu(menu, CHISMenu.OPTION_CLICK);	// close any other open menus if autoclose is on
		/*
		if(this.bAutoClose)
			{
			for(n = 0; n < this.arrayMenuCtrl.length; n++)
				{				
				if(n != menu && this.arrayMenuCtrl[n].isOpen())
					this.arrayMenuCtrl[n].setMenu(CHISMenu.OPTION_CLICK);					
				}
			}
		*/
		this.arrayMenuCtrl[menu].setSubMenu(subMenu, option);
		}

	// Init our menu

	// Create the sub menu array for the Home menu...
//	this.arraySubMenuHome[0] = new CHISSubMenu(CHISMenuControl.MENU_HOME, 0, "In - The News", this.getRelDir() + "InTheNews.html", "menuHome", "menuHome", "menuHomeOver", false);	
	this.arraySubMenuHome[0] = new CHISSubMenu(CHISMenuControl.MENU_HOME, 1, "About Healthline", this.getRelDir() + "MissionStatement.html", "menuHome", "menuHome", "menuHomeOver", false);
	this.arraySubMenuHome[1] = new CHISSubMenu(CHISMenuControl.MENU_HOME, 2, "Our Business Relationships", this.getRelDir() + "BusRelation.html", "menuHome", "menuHome", "menuProductsOver", false);
	this.arraySubMenuHome[2] = new CHISSubMenu(CHISMenuControl.MENU_HOME, 3, "Home", this.getRelDir(), "menuHome", "menuHome", "menuHomeOver", false);
	
	this.menuHome = new CHISMenu(CHISMenuControl.MENU_HOME, this.arraySubMenuHome, this.getGraphicsDir() + "Home_Click.jpg", this.getGraphicsDir() + "Home_Out.jpg", this.getGraphicsDir() + "Home_Over.jpg");

	///////////////////////////////////////////////////////////////////////////////////////////
	// Create the sub menu array for the Products menu...				
	///////////////////////////////////////////////////////////////////////////////////////////	
	this.arraySubMenuProd[0] = new CHISSubMenu(CHISMenuControl.MENU_PRODUCTS, 0, "Hospital Market", this.getRelDir() + "Products/HM/Index.html", "menuProducts", "menuProducts", "menuProductsOver", false);
	this.arraySubMenuProd[1] = new CHISSubMenu(CHISMenuControl.MENU_PRODUCTS, 1, "Practice Market", this.getRelDir() + "PMIndex.html", "menuProducts", "menuProducts", "menuProductsOver", false);
	//this.arraySubMenuProd[2] = new CHISSubMenu(CHISMenuControl.MENU_PRODUCTS, 2, "All Products", this.getRelDir() + "UnderConstruction.html", "menuProducts", "menuProducts", "menuProductsOver", false);
	//this.arraySubMenuProd[3] = new CHISSubMenu(CHISMenuControl.MENU_PRODUCTS, 3, "OEM Technology", this.getRelDir() + "UnderConstruction.html", "menuProducts", "menuProducts", "menuProductsOver", false);
	
	this.menuProducts = new CHISMenu(CHISMenuControl.MENU_PRODUCTS, this.arraySubMenuProd, this.getGraphicsDir() + "Products_Click.jpg", this.getGraphicsDir() + "Products_Out.jpg", this.getGraphicsDir() + "Products_Over.jpg");

	///////////////////////////////////////////////////////////////////////////////////////////
	// Create the sub menu array for the Services menu...				
	///////////////////////////////////////////////////////////////////////////////////////////	
	
	//this.arraySubMenuServ[0] = new CHISSubMenu(CHISMenuControl.MENU_SERVICES, 0, "Medical Imaging", this.getRelDir() + "UnderConstruction.html", "menuServices", "menuServices", "menuServicesOver", false);
	//this.arraySubMenuServ[1] = new CHISSubMenu(CHISMenuControl.MENU_SERVICES, 1, "Document Management", this.getRelDir() + "UnderConstruction.html", "menuServices", "menuServices", "menuServicesOver", false);
	this.arraySubMenuServ[0] = new CHISSubMenu(CHISMenuControl.MENU_SERVICES, 0, "Data Migration", this.getRelDir() + "ConversionsIndex.html", "menuServices", "menuServices", "menuServicesOver", false);
	this.arraySubMenuServ[1] = new CHISSubMenu(CHISMenuControl.MENU_SERVICES, 1, "OEM", this.getRelDir() + "OEMIndex.html", "menuServices", "menuServices", "menuServicesOver", false);
	//this.arraySubMenuServ[4] = new CHISSubMenu(CHISMenuControl.MENU_SERVICES, 4, "Software Engineering", this.getRelDir() + "UnderConstruction.html", "menuServices", "menuServices", "menuServicesOver", false);

	this.menuServices = new CHISMenu(CHISMenuControl.MENU_SERVICES, this.arraySubMenuServ, this.getGraphicsDir() + "Services_Click.jpg", this.getGraphicsDir() + "Services_Out.jpg", this.getGraphicsDir() + "Services_Over.jpg");

	///////////////////////////////////////////////////////////////////////////////////////////
	// Create the sub menu array for the Support menu...
	///////////////////////////////////////////////////////////////////////////////////////////	

	// Live links when ready
	// this.arraySubMenuSupp[0] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 0, "Medical Imaging", this.getRelDir() + "Support/MI/Index.html", "menuSupport", "menuSupport", "menuSupportOver", false);
	// this.arraySubMenuSupp[1] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 1, "Cardio Pulmonary", this.getRelDir() + "Support/CP/Index.html", "menuSupport", "menuSupport", "menuSupportOver", false);
	// this.arraySubMenuSupp[2] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 2, "Other", this.getRelDir() + "Support/OT/Index.html", "menuSupport", "menuSupport", "menuSupportOver", false);

	// Temp - points to under construction page
//	this.arraySubMenuSupp[0] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 0, "Cardio Pulmonary FAQ", this.getRelDir() + "Support/CP/Index.html", "menuSupport", "menuSupport", "menuSupportOver", false);
	this.arraySubMenuSupp[0] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 1, "HealthE*Helpdesk", this.getRelDir() + "cms/user.php", "menuSupport", "menuSupport", "menuSupportOver", false);
//	this.arraySubMenuSupp[2] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 2, "Live Chat", this.getRelDir() + "cms/modules/x7chat/", "menuSupport", "menuSupport", "menuSupportOver", false);
   //this.arraySubMenuSupp[2] = new CHISSubMenu(CHISMenuControl.MENU_SUPPORT, 2, "Other", this.getRelDir() + "UnderConstruction.html", "menuSupport", "menuSupport", "menuSupportOver", false);
	
	this.menuSupport = new CHISMenu(CHISMenuControl.MENU_SUPPORT, this.arraySubMenuSupp, this.getGraphicsDir() + "Support_Click.jpg", this.getGraphicsDir() + "Support_Out.jpg", this.getGraphicsDir() + "Support_Over.jpg");

	///////////////////////////////////////////////////////////////////////////////////////////
	// Create the sub menu array for the Contact menu...
	///////////////////////////////////////////////////////////////////////////////////////////	
	this.arraySubMenuConn[0] = new CHISSubMenu(CHISMenuControl.MENU_CONTACT, 0, "Contact Us", this.getRelDir() + "Contact.html", "menuContact", "menuContact", "menuContactOver", false);
	this.menuContact = new CHISMenu(CHISMenuControl.MENU_CONTACT, this.arraySubMenuConn, this.getGraphicsDir() + "Contact_Click.jpg", this.getGraphicsDir() + "Contact_Out.jpg", this.getGraphicsDir() + "Contact_Over.jpg");

	// The menu array that controls everything
	this.arrayMenuCtrl[CHISMenuControl.MENU_HOME]		= this.menuHome;
	this.arrayMenuCtrl[CHISMenuControl.MENU_PRODUCTS]	= this.menuProducts;
	this.arrayMenuCtrl[CHISMenuControl.MENU_SERVICES]	= this.menuServices;
	this.arrayMenuCtrl[CHISMenuControl.MENU_SUPPORT]	= this.menuSupport;
	this.arrayMenuCtrl[CHISMenuControl.MENU_CONTACT]	= this.menuContact;

	return this;
	}

// Our one and only menu control object
var g_menuControl = null;
