<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:user="http://travelers.com/dynportal">

<msxsl:script language="csharp" implements-prefix="user">
  <msxsl:assembly name="System.Core" />
  <msxsl:using namespace="System.IO" />
  <msxsl:using namespace="System.Collections.Generic" />

  <![CDATA[
        int tabNumber = 0;
        string portalName = string.Empty;
        string portalIncludeUrl = string.Empty;
        string portalIncludeMarginHeight = string.Empty;
        string portalIncludeMarginWidth = string.Empty;
        string portalIncludeHeight = string.Empty;
        string portalIncludeWidth = string.Empty;
        string portalIncludeDisplay = string.Empty;
        string gPageID = string.Empty;
        string oNode = string.Empty;
        int menucount = 1;

        public XmlElement GetXmlElement(XPathNodeIterator oNode, Boolean isMoveNext = true)
        {
            if (isMoveNext) oNode.MoveNext();
            var oDoc = new XmlDocument();
            oDoc.Load(new StringReader(oNode.Current.OuterXml));
            return oDoc.DocumentElement;
        }
        public XmlElement GetParentXmlElement(XPathNodeIterator oNode)
        {
            oNode.Current.MoveToParent();
            return GetXmlElement(oNode);
        }
        public string setPortalIncludeData(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);

            var idNode = oNode.SelectNodes("/Portal/Name");
            var urlNode = oNode.SelectNodes("/Portal/IncludeFile/Url");
            var heightNode = oNode.SelectNodes("/Portal/IncludeFile/Height");
            var widthNode = oNode.SelectNodes("/Portal/IncludeFile/Width");
            var marginHeightNode = oNode.SelectNodes("/Portal/IncludeFile/MarginHeight");
            var marginWidthNode = oNode.SelectNodes("/Portal/IncludeFile/MarginWidth");

            if (idNode != null && idNode.Count > 0)
            {
                portalName = idNode[0].InnerText;
            }

            if (urlNode != null && urlNode.Count > 0)
            {
                portalIncludeUrl = urlNode[0].InnerText;
                portalIncludeDisplay = "inline";

                portalIncludeMarginHeight = marginHeightNode != null && marginHeightNode.Count > 0 ? marginHeightNode[0].InnerText : "0";
                portalIncludeMarginWidth = marginWidthNode != null && marginWidthNode.Count > 0 ? marginWidthNode[0].InnerText : "0";
                portalIncludeHeight = heightNode != null && heightNode.Count > 0 ? heightNode[0].InnerText : "0";
                portalIncludeWidth = widthNode != null && widthNode.Count > 0 ? widthNode[0].InnerText : "0";
            }
            else
            {
                portalIncludeMarginHeight = "0";
                portalIncludeMarginWidth = "0";
                portalIncludeHeight = "0";
                portalIncludeWidth = "0";
                portalIncludeDisplay = "none";
            }

            return string.Empty;
        }
        public string getPortalIncludeStyle()
        {
            var display = "position: absolute;";
            display += "top: " + getPortalIncludeInfo("MARGINHEIGHT") + ";";
            display += "left: " + getPortalIncludeInfo("MARGINWIDTH") + ";";
            display += "width: " + getPortalIncludeInfo("WIDTH") + ";";
            display += "pixelheight: " + getPortalIncludeInfo("HEIGHT") + ";";
            display += "height: " + getPortalIncludeInfo("HEIGHT") + ";";
            display += "display: " + getPortalIncludeInfo("DISPLAY") + ";";
            display += "visibility:visible;";
            return display;
        }
        public string getPortalIncludeImageStyle()
        {
            var display = "position: absolute;";
            display += "top: " + getPortalIncludeInfo("MARGINHEIGHT") + ";";
            display += "left: " + getPortalIncludeInfo("MARGINWIDTH") + ";";
            display += "pixelheight: " + getPortalIncludeInfo("HEIGHT") + ";";
            display += "display: " + getPortalIncludeInfo("DISPLAY") + ";";
            display += "visibility:visible;";
            return display;
        }
        public string getTabIncludeStyle(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);

            var marginWidth = getValue(oNode.SelectNodes("//IncludeFile/MarginWidth/text()"));
            var marginHeight = getValue(oNode.SelectNodes("//IncludeFile/MarginHeight/text()"));
            var width = getValue(oNode.SelectNodes("//IncludeFile/Width/text()"));
            var height = getValue(oNode.SelectNodes("//IncludeFile/Height/text()"));
            var urlNode = oNode.SelectNodes("//IncludeFile/Url/text()");
            var display = string.Empty;

            if (marginHeight != "0")
            {
                display = "position: absolute;";
                display += "top: " + marginHeight + ";";
            }
            else
            {
                display = "position: relative;";
            }
            display += "left: " + marginWidth + ";";
            display += "width: " + width + ";";
            display += "pixelheight: " + height + ";";
            display += "height: " + height + ";";
            if (urlNode != null && urlNode.Count > 0)
            {
                //  display += "display:inline;visibility:visible;"
            }
            else
            {
                // display += "display:none;"
            }
            return display;
        }
        public string getTabIncludeImageStyle(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var marginWidth = getValue(oNode.SelectNodes("IncludeFile/MarginWidth/text()"));
            var marginHeight = getValue(oNode.SelectNodes("IncludeFile/MarginHeight/text()"));

            var urlNode = oNode.SelectNodes("IncludeFile/Url/text()");
            var display = string.Empty;

            if (marginHeight != "0")
            {
                display = "position: absolute;";
                display += "top: " + marginHeight + ";";
            }
            else
            {
                display = "position: relative;";
            }
            display += "left: " + marginWidth + ";";

            if (urlNode != null && urlNode.Count > 0)
            {
                //  display += "display:inline;visibility:visible;"
            }
            else
            {
                // display += "display:none;"
            }
            return display;
        }
        public string getPortalIncludeInfo(string property)
        {
            var prooertyName = string.Empty;
            switch (property)
            {
                case "NAME":
                    prooertyName = portalName;
                    break;
                case "URL":
                    prooertyName = portalIncludeUrl;
                    break;
                case "MARGINHEIGHT":
                    prooertyName = portalIncludeMarginHeight;
                    break;
                case "MARGINWIDTH":
                    prooertyName = portalIncludeMarginWidth;
                    break;
                case "HEIGHT":
                    prooertyName = portalIncludeHeight;
                    break;
                case "WIDTH":
                    prooertyName = portalIncludeWidth;
                    break;
                case "DISPLAY":
                    prooertyName = portalIncludeDisplay;
                    break;
            }
            return prooertyName;
        }
        public string getDisplay(XPathNodeIterator oNode1)
        {
            var oCurrXmlElement = GetXmlElement(oNode1);
            return oCurrXmlElement.InnerText.Length > 0 ? "display:inline;" : "display:none;";
        }
        public string getValue(XmlNodeList oNode)
        {
            if (oNode.Count > 0)
            {
                return oNode[0].InnerText;
            }
            else
            {
                return "0";
            }
        }
        public string buildNavArray(XPathNodeIterator oNode1)
        {
            string gMenuStr = string.Empty;
            string pgName = string.Empty;
            string menuName = string.Empty;
            var root = GetXmlElement(oNode1);

            var domain = root.SelectSingleNode("/Portal/MultipleDomains/text()");

            if (domain != null)
            {
                gMenuStr = domain.InnerText == "true" ? "\nvar domainValue=getDomain(); \n document.domain = domainValue; \nvar g_Keys = new Array;\nvar g_Menus = new Array;\n" :
                    "var g_Keys = new Array;\nvar g_Menus = new Array;\n";
            }
            else
            {
                gMenuStr = "\nvar domainValue=getDomain(); \n document.domain = domainValue; \nvar g_Keys = new Array;\nvar g_Menus = new Array;\n";
            }
            var gPageInfoStr = "var g_PageInfo = new Array;\n";
            var gDefaultPageStr = "var g_DefaultPage = new Array;\n";            
            var gPortalID = root.SelectSingleNode("/Portal/Name/text()");
            var gPortalIDStr = "var portalID = '" + gPortalID.InnerText + "';\n";
            var gLockNavState = root.SelectSingleNode("/Portal/LockNavigation/text()");
            var gLockNavigationStr = "var LockNavigation = " + gLockNavState.InnerText + ";\n";
            var gMaxSubPortalsCount = root.SelectSingleNode("/Portal/MaxSubPortals/text()");
            var gMaxSubPortals = string.Empty;

            if (gMaxSubPortalsCount != null)
            {
                if (gMaxSubPortalsCount.InnerText != string.Empty)
                {
                    gMaxSubPortals = "var MaxSubPortals = " + gMaxSubPortalsCount.InnerText + ";\n";
                }
            }

            var tabSearchStr = "/Portal/Tab[Visible='true']";
            var tabNodeList = root.SelectNodes(tabSearchStr);

            for (var i = 0; i < tabNodeList.Count; ++i)
            {
                var thisTab = tabNodeList[i];
                var tabId = thisTab.SelectSingleNode("Id/text()");
                var startPage = thisTab.SelectSingleNode("StartPage/text()");

                gMenuStr += "g_Menus[" + i + "] = \"mnu" + tabId.InnerText.Substring(3, tabId.InnerText.Length - 3) + "\";\n";

                if (startPage != null && startPage.InnerText.Substring(0, 11) != "javascript:")
                {
                    gDefaultPageStr += "g_DefaultPage[\"mnu" + tabId.InnerText.Substring(3, tabId.InnerText.Length - 3) + "\"] = \"" +
                                       startPage.InnerText + "\";\n";
                }
                else
                {
                    gDefaultPageStr += "g_DefaultPage[\"mnu" + tabId.InnerText.Substring(3, tabId.InnerText.Length - 3) + "\"] = \"\";\n";
                }

                //Select all visible Pages for this tab  


                var pgNodeList = thisTab.SelectNodes("Page[Visible='true']");
                var mnuTabid = "mnu" + tabId.InnerText.Substring(3, tabId.InnerText.Length - 3);

                for (var x = 0; x < pgNodeList.Count; x++)
                {
                    var thisPg = pgNodeList[x];
                    var pgId = thisPg.SelectSingleNode("Id/text()");
                    var thisPgUrl = thisPg.SelectSingleNode("Url/text()");
                    var pgNameNode = thisPg.SelectSingleNode("Name/text()");
                    try
                    {
                        if (pgNameNode.InnerText.Length > 0)
                        {
                            //remove spaces non-alpha char
                            pgName = pgNameNode.InnerText;
                            var tmpPgName = normalizeName(pgName);
                            pgName = string.Empty;
                            pgName = mnuTabid + "_" + tmpPgName;
                        }
                    }
                    catch (Exception ex)
                    {
                        pgName = mnuTabid + "_empty";
                    }

                    if (thisPgUrl.InnerText.Length > 0)
                    {
                        var thePageNodeValue = editPageUrl(thisPgUrl.InnerText);
                        if (thePageNodeValue.Length > 0)
                        {
                            gPageInfoStr += "g_PageInfo[\"" + thePageNodeValue + "\"] = new Array(\"" + tabId.InnerText + "\",\"" + pgName + "\",\"" + pgName + "\");\n";
                        }
                    }
                } //end for loop 


                //Select all visible Menus for this tab

                var menuNodeList = thisTab.SelectNodes("Menu[Visible='true']");

                for (var j = 0; j < menuNodeList.Count; ++j)
                {
                    var thisMenu = menuNodeList[j];
                    var menuId = thisMenu.SelectSingleNode("Id/text()");
                    var thisUrlNode = thisMenu.SelectNodes("Url/text()");

                    var PageNodeList = thisMenu.SelectNodes("Page[Visible='true']");

                    var menuNameNode = thisMenu.SelectSingleNode("Name/text()");

                    if (menuNameNode.InnerText.Length > 0)
                    {
                        var tmpMenuName = normalizeName(menuNameNode.InnerText);
                        menuName = mnuTabid + "_" + tmpMenuName;
                        gPageInfoStr += "g_PageInfo[\"" + tmpMenuName + "\"] = new Array(\"" + tabId.InnerText + "\",\"" + menuName + "\",\"" + menuName + "\");\n";
                    }

                    if (PageNodeList.Count > 0)
                    {
                        for (var k = 0; k < PageNodeList.Count; ++k)
                        {
                            var thisPage = PageNodeList[k];
                            var PageId = thisPage.SelectSingleNode("Id/text()");
                            var thisPageUrl = thisPage.SelectSingleNode("Url/text()");
                            var pgNameNode = thisPage.SelectSingleNode("Name/text()");

                            if (pgNameNode.InnerText.Length > 0)
                            {
                                //remove spaces non-alpha char
                                pgName = pgNameNode.InnerText;
                                var tmpPgName = normalizeName(pgName);
                                pgName = string.Empty;
                                pgName = menuName + "_" + tmpPgName;
                            }

                            if (thisPageUrl.InnerText.Length > 0)
                            {
                                var thePageNdVal = editPageUrl(thisPageUrl.InnerText);
                                if (thePageNdVal.Length > 0)
                                {
                                    gPageInfoStr += "g_PageInfo[\"" + thePageNdVal + "\"] = new Array(\"" + tabId.InnerText + "\",\"" + menuName + "\",\"" + pgName + "\");\n";
                                }

                            }
                        }
                    }
                }

            }

            return gMenuStr + "\n" + gPageInfoStr + "\n" + gDefaultPageStr + "\n" + gPortalIDStr + "\n" + gLockNavigationStr + gMaxSubPortals;

        }
        public string normalizeName(string vName)
        {
            for (var i = 0; i < vName.Length; i++)
            {
                vName = Regex.Replace(vName, @"[^\w]", "");
            }

            return vName;
        }
        public string getSource(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theSource = string.Empty;
            
            var PageList = oNode.SelectNodes("Page[Visible='true']"); 
            var MenuView = oNode.SelectNodes("Expanded/text()");
            if (PageList != null && PageList.Count > 0)
            {
                theSource = MenuView != null && MenuView[0].InnerText == "True" ? "images/SPT-minus.gif" : "images/SPT-plus.gif";
            }
            else
            {
                theSource = "images/green_bullet.gif";
                var x = (tabNumber % 4);

                switch (x)
                {
                    case 1:
                        theSource = "images/green_bullet.gif";
                        break;
                    case 2:
                        theSource = "images/green_bullet.gif";
                        break;
                    case 3:
                        theSource = "images/green_bullet.gif";
                        break;
                    case 0:
                        theSource = "images/green_bullet.gif";
                        break;
                }
            }
            return theSource;
        }
        public string getMenuImage()
        {
            var theSource = string.Empty;
            theSource = "/images/green_bullet.gif";
            var x = (tabNumber % 4);

            switch (x)
            {
                case 1:
                    theSource = "/images/blue_bullet.gif";
                    break;
                case 2:
                    theSource = "/images/red_bullet.gif";
                    break;
                case 3:
                    theSource = "/images/green_bullet.gif";
                    break;
                case 0:
                    theSource = "/images/green_bullet.gif";
                    break;
            }
            return theSource;
        }
        public string incrementTabNumber()
        {

            tabNumber++;
            if (tabNumber == 5)
            {
                tabNumber = 1;
            }
            return string.Empty;
        }
        public string getPageHref(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theHref = string.Empty;
            var checkForFunction = string.Empty;
            var tmpNewWindowHasToolbar = string.Empty;
            var urlList = oNode.SelectNodes("/Page/Url/text()");
            var theId = getPageID(oNode1);
            var newWindow = oNode.SelectSingleNode("/Page/NewWindow/text()");
            var newWindowFullScreen = oNode.SelectSingleNode("/Page/NewWindowFullScreen/text()");
            var launchReplace = oNode.SelectSingleNode("/Page/LaunchReplace/text()");
            var persistant = oNode.SelectSingleNode("/Page/Persistant/text()");
            var newWindowHasToolbar = oNode.SelectSingleNode("/Page/NewWindowHasToolbar/text()");
            var launchNewWindowFullScreen = string.Empty;

            launchNewWindowFullScreen = newWindowFullScreen == null ? "false" : newWindowFullScreen.InnerText;
            tmpNewWindowHasToolbar = newWindowHasToolbar == null ? "false" : newWindowHasToolbar.InnerText;

            if (urlList.Count > 0)
            {
                var thisPage = editPageUrl(urlList[0].InnerText);
                checkForFunction = thisPage.Substring(0, 11);
                if (checkForFunction == "javascript:")
                {
                    theHref = thisPage;
                }
                else
                {
                    if (newWindow != null && newWindow.InnerText == "true")
                    {
                        if (tmpNewWindowHasToolbar == "false")
                        {
                            theHref = "javascript:PFSLaunchNewWindowNoToolbar('" + thisPage + "','" + theId + "'," +
                                      launchNewWindowFullScreen + ")";
                        }
                        else
                        {
                            theHref = "javascript:PFSLaunchNewWindow('" + thisPage + "','" + theId + "'," + launchNewWindowFullScreen + ")";
                        }
                    }
                    else
                    {
                        try
                        {	//needed to avoid HTML errors with older xml files
                            if (persistant != null && persistant.InnerText == "true")
                            {
                                theHref = "javascript:PFSNavPersistant('" + theId + "','" + thisPage + "')";
                                return theHref;
                            }
                        }
                        catch (Exception ex)
                        {
                        }

                        if (launchReplace != null && launchReplace.InnerText == "true")
                        {
                            theHref = "javascript:PFSLaunchReplace('" + thisPage + "')";
                        }
                        else
                        {
                            theHref = "javascript:PFSNavigate('" + theId + "','" + thisPage + "')";
                        }
                    }
                }
            }
            else
            {
                if (newWindow != null && newWindow.InnerText == "true")
                {
                    theHref = tmpNewWindowHasToolbar == "false" ? "javascript:PFSLaunchNewWindowNoToolbar('NoPage.htm')" : "javascript:PFSLaunchNewWindow('NoPage.htm')";
                }
                else
                {
                    if (launchReplace != null && launchReplace.InnerText == "true")
                    {
                        theHref = "javascript:PFSLaunchReplace('NoPage.htm')";
                    }
                    else
                    {
                        theHref = "javascript:PFSNavigate('" + theId + "','" + "NOPage.htm" + "')";
                    }
                }
            }

            return theHref;
        }
        public string getMenuTitleHref(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theHref = string.Empty;
            var urlList = oNode.SelectNodes("/Tab/StartPage/text()");

            if (urlList != null && urlList.Count > 0)
            {
                var thisPage = editPageUrl(urlList[0].InnerText);
                theHref = "javascript:PFSNavigateMenuTitle('" + thisPage + "')";
            }
            else
            {
                theHref = string.Empty; //"javascript:PFSMenuClick('" + theId.nodeValue + "')"
            }

            return theHref;
        }
        public string getMenuHref(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theHref = string.Empty;
            var urlList = oNode.SelectNodes("Url/text()");

            var theId = getMenuID(oNode1);

            if (urlList != null && urlList.Count > 0)
            {
                var thisPage = editPageUrl(urlList[0].InnerText);
                theHref = "javascript:PFSNavigate('" + theId + "','" + thisPage + "')";
            }
            else
            {
                theHref = "javascript:PFSMenuClick('" + theId + "')";
            }

            return theHref;
        }
        public string editPageUrl(string oNode)
        {
            // made by sully to ignore the code
            return oNode;

            //This function is used to edit the url with the following rule:
            //  1.  If the url does not begin with "http:", and the 6th byte is "/", then strip off the first 6 bytes.
            if (oNode.Length > 0)
            {
                if (oNode.Length > 0)
                {
                    var startCharacters = string.Empty;
                    if (oNode.Length >= 5)
                    {
                        startCharacters = oNode.Substring(0, 5);
                    }
                    if (startCharacters != "http:")
                    {
                        var theIndexOf = oNode.IndexOf("/", StringComparison.Ordinal);
                        if (theIndexOf == 5)
                        {
                            theIndexOf++;
                            oNode = oNode.Substring(theIndexOf, oNode.Length - 1);
                        }
                    }
                }
                return oNode;
            }
            else
            {
                return string.Empty;
            }
        }
        public string getMenuValue(XPathNodeIterator oNode1, int lineNumber)
        {
            var oNode = GetXmlElement(oNode1);
            var mnuValue = oNode.SelectSingleNode("Description/text()").InnerText;

            try
            {
                if (mnuValue.Length > 0)
                {
                    var mnuValueArray = mnuValue.Split('~');
                    if (mnuValueArray[lineNumber] != null && mnuValueArray[lineNumber] != "&nbsp;")
                    {
                        return mnuValueArray[lineNumber];
                    }
                    else { return string.Empty; }
                }
            }
            catch (Exception ex) { return string.Empty; }

            return string.Empty;
        }
        public string getMenuPageClass(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theClass = string.Empty;

            var theEnabledFlag = oNode.SelectSingleNode("Enabled/text()");

            if (theEnabledFlag != null && theEnabledFlag.InnerText == "false")
            {
                theClass = "clsMenuLinkInActive";
            }
            else
            {
                var urlList = oNode.SelectNodes("Url/text()");
                if (urlList != null && urlList.Count > 0)
                {
                    theClass = "clsMenuLinkActive";
                }
                else
                {
                    theClass = "clsMenuLinkInActive";
                }
            }
            return theClass;
        }
        public string getTabPageClass(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theClass = string.Empty;

            var theEnabledFlag = oNode.SelectSingleNode("/Page/Enabled/text()");

            if (theEnabledFlag != null && theEnabledFlag.InnerText == "false")
            {
                theClass = "clsMenuNavInActive";
            }
            else
            {
                var urlList = oNode.SelectNodes("/Page/Url/text()");
                if (urlList != null && urlList.Count > 0)
                {
                    theClass = "clsMenuNavActive";
                }
                else
                {
                    theClass = "clsMenuNavInActive";
                }
            }
            return theClass;
        }
        public string getMenuClass(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var theClass = string.Empty;

            var theEnabledFlag = oNode.SelectSingleNode("/Menu/Enabled/text()");

            if (theEnabledFlag != null && theEnabledFlag.InnerText == "false")
            {
                theClass = "clsMenuInActive";
            }
            else
            {
                var urlList = oNode.SelectNodes("/Menu/Url/text()");
                if (urlList != null && urlList.Count > 0)
                {
                    theClass = "clsMenuNavActive";
                }
                else
                {
                    theClass = "clsMenu";
                }
            }
            return theClass;
        }
        public string getClass(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);

            var theClass = string.Empty;
            var PageList = oNode.SelectNodes("/Page");

            if (PageList != null && PageList.Count > 0)
            {
                theClass = "clsMenuImage";
            }
            else
            {
                theClass = "clsMenu";
            }
            return theClass;
        }
        public string getOnClick(XPathNodeIterator oNode1, string oNodeName)
        {
            var oNode = GetXmlElement(oNode1);
            var theSource = string.Empty;
            var MenuId = oNodeName;
            var PageList = oNode.SelectNodes("/Page");

            if (PageList != null && PageList.Count > 0)
            {
                theSource = "PFSMenuClick('" + MenuId + "')";
            }
            else
            {
                theSource = string.Empty;
            }
            return theSource;
        }
        public string getVisibility(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var visibilityProperty = string.Empty;
            var DefaultValue = oNode.SelectSingleNode("/Tab/Default/text()");

            if (DefaultValue != null && DefaultValue.InnerText == "true")
            {
                visibilityProperty = "visible";
            }
            else
            {
                visibilityProperty = "hidden";
            }
            return visibilityProperty;

        }
        public string getMenuBlockClass(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var className = string.Empty;
            var DefaultValue = oNode.SelectSingleNode("Default/text()");

            if (DefaultValue.InnerText == "true")
            {
                className = "clsMenuImageBlock";
            }
            else
            {
                className = "clsMenuImageBlockHide";
            }
            return className;
        }
        public string convertName(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var oIdNode = oNode.SelectSingleNode("Id/text()");
            var MenuId = oIdNode != null ? oIdNode.InnerText : string.Empty;
            return "mnu" + MenuId.Substring(3, MenuId.Length - 3);
        }
        public string getTabValue(XPathNodeIterator oNode1)
        {
            var oNode = GetXmlElement(oNode1);
            var oDescriptionNode = oNode.SelectSingleNode("Description/text()");
            var tabValue = oDescriptionNode != null ? oDescriptionNode.InnerText : string.Empty;
            if (tabValue.IndexOf('~') > 0)
            {
                var tabValueArray = tabValue.Split('~');
                tabValue = "<DIV style='TEXT-ALIGN:center;'>" + tabValueArray[0] + "<BR/>" + tabValueArray[1] + "</DIV>";

            }
            return tabValue;
        }
        public bool chkMenuValue()
        {
            return false;
        }
        public string getStyleSheet()
        {
            return "StyleSheets/PortalFrameworkSystem.css";
        }
        public string getPageID(XPathNodeIterator oNode1)
        {
            var thisPageName = string.Empty;
            var oCurrXmlElement = GetXmlElement(oNode1);

            var thisPageNode = oCurrXmlElement.SelectSingleNode("Name/text()");

            if (thisPageNode != null && thisPageNode.InnerText != string.Empty)
            {
                thisPageName = normalizeName(thisPageNode.InnerText);
            }

            var thisPageParent = GetParentXmlElement(oNode1);
            gPageID = string.Empty;
            if (thisPageParent != null && thisPageParent.Name == "Tab")
            {
                var parentName = thisPageParent.SelectSingleNode("Name/text()");
                var tmpTabName = parentName != null ? "mnu" + normalizeName(parentName.InnerText) : string.Empty;
                gPageID = tmpTabName + "_" + thisPageName;

            }

            if (thisPageParent != null && thisPageParent.Name == "Menu")
            {
                var parentName = thisPageParent.SelectSingleNode("Name/text()");
                var tmpMenuName = parentName != null ? normalizeName(parentName.InnerText) : string.Empty;
                var thisMenuParent = GetParentXmlElement(oNode1);
                var tmpTabName = "mnu" + normalizeName(thisMenuParent.SelectSingleNode("Name/text()").InnerText);
                gPageID = tmpTabName + "_" + tmpMenuName + "_" + thisPageName;

            }
            return gPageID;
        }
        public string getTop(XPathNodeIterator oNode1)
        {
            var gTop = 5;
            var oNode = GetXmlElement(oNode1);
            var MenuImageBlockValue = oNode.SelectNodes("MenuImageBlock/text()");

            if (portalIncludeUrl != string.Empty)
            {
                gTop = 112;
            }
            else
            {
                gTop = 5;
            }

            return gTop.ToString();
        }
        public string getWidth(XPathNodeIterator oNode1)
        {
            var gWidth = 147;
            try
            {
                var thisTab = GetXmlElement(oNode1);
                var thisTabWidth = thisTab.SelectSingleNode("//Portal/MenuWidth/text()");
                if (thisTabWidth.InnerText == "135")
                {
                    gWidth = 127;
                }
                else { gWidth = 144; }
            }
            catch (Exception ex) { }
            return gWidth.ToString();
        }
        public string getMenuNum(bool size)
        {
            var clsTabMenu = string.Empty;
            try
            {

                var menuNum = ((menucount++) % 4);
                if (menuNum == 0)
                { menuNum = 4; }
                if (size)
                {
                    clsTabMenu = "clsTabMenu" + menuNum;
                }
                else
                {
                    clsTabMenu = "clsTabMenu135" + menuNum;
                }
            }
            catch (Exception ex) { }
            return clsTabMenu;
        }
        public string gotPageID()
        {
            return gPageID;
        }
        public string getMenuID(XPathNodeIterator thisPage)
        {
            var thisPageElement = GetXmlElement(thisPage);
            var thisPageParent = GetParentXmlElement(thisPage);
            var thisPageParentName = thisPageParent.SelectSingleNode("Name/text()");
            var tmpTabName = thisPageParentName != null ? "mnu" + normalizeName(thisPageParentName.InnerText) : string.Empty;
            var parentName = thisPageElement.SelectSingleNode("Name/text()");
            var tmpMenuName = parentName != null ? normalizeName(parentName.InnerText) : string.Empty;
            var gPageID = tmpTabName + "_" + tmpMenuName;
            return gPageID;
        }
        public string blankSpace()
        {
            return "&nbsp;";
        }
        public string lineBreak()
        {
            return "\n";
        }
        public string blankSpaceLbl()
        {
            return "<label>&nbsp;</label>";
        }

        ]]>



</msxsl:script>

<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="user:lineBreak()"/><xsl:comment>Travelers.BI.PortalFramework.Web.PortalXSLT.PortalMenuSTA.xsl</xsl:comment><xsl:value-of select="user:lineBreak()"/>
<HTML>
<HEAD>

<TITLE>Portal Menu</TITLE>


<SCRIPT language="JavaScript" type="text/javascript">
<xsl:value-of select="user:buildNavArray(.)"/>
<xsl:value-of select="user:setPortalIncludeData(.)"/>
var iFrameSrc = "<xsl:value-of select="user:getPortalIncludeInfo('URL')"/>"
var g_Style= "<xsl:value-of select="Portal/StyleSheet" />"
var menu_Size= "<xsl:value-of select="Portal/MenuWidth" />"
 function getDomain() {
   var docname = document.domain
       var tmpDocName = docname.split(".")
       if (tmpDocName[1]){
   		var strDocName = tmpDocName[tmpDocName.length-2] + "." + tmpDocName[tmpDocName.length-1]
   		return strDocName;
    } else { return docname; }
}
		
</SCRIPT>

<link rel="stylesheet" TYPE="text/css" href="StyleSheets/PFS-Style-START.css"></link>
</HEAD>
<BODY>
    <xsl:choose>
      <xsl:when test="Portal/MenuWidth[. ='135']">
    	<xsl:attribute name="class">clsmenubackground135</xsl:attribute>
    	<xsl:value-of select="user:lineBreak()"  />  
	<Script Language='JavaScript' src='scripts/PortalFrameworkSystem.js' type="text/javascript"><xsl:comment></xsl:comment></Script>     
        <div id="divMenuSpacer" style="width:132" class="clsMenuSpacerTop"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="class">clsMenuBackGrndGrn</xsl:attribute>
        <xsl:value-of select="user:lineBreak()"  />  
	<Script Language='JavaScript' src='scripts/PortalFrameworkSystem.js' type="text/javascript"><xsl:comment></xsl:comment></Script>     
     	<div id="divMenuSpacer" style="width:144" class="clsMenuSpacerTop"/>
      </xsl:otherwise>
    </xsl:choose>
    
    <xsl:value-of select="user:lineBreak()"  />
    <xsl:apply-templates select="//Tab" />
       
    <xsl:if test="//Portal/IncludeFile/Url[@image='false']">
		<iframe>
		<xsl:attribute name="src"></xsl:attribute>
		<xsl:attribute name="allowTransparency">true</xsl:attribute>
		<xsl:attribute name="style"><xsl:value-of select="user:getPortalIncludeStyle()"/></xsl:attribute>
		<xsl:attribute name="id">mnu<xsl:value-of select="user:getPortalIncludeInfo('NAME')"/><xsl:value-of select="Name"/>Iframe</xsl:attribute>
		<xsl:attribute name="name">mnu<xsl:value-of select="user:getPortalIncludeInfo('NAME')"/><xsl:value-of select="Name"/>Iframe</xsl:attribute>
		<xsl:attribute name="scrolling">no</xsl:attribute>
		<xsl:attribute name="frameborder">0</xsl:attribute>
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		</iframe>
    </xsl:if>
    	<xsl:if test="//Portal/IncludeFile/Url[@image='true']">
    		<img>
	    		<xsl:attribute name="src"><xsl:value-of select="user:getPortalIncludeInfo('URL')"/></xsl:attribute>
				<xsl:attribute name="style"><xsl:value-of select="user:getPortalIncludeImageStyle()"/></xsl:attribute>
				<xsl:attribute name="id">mnu<xsl:value-of select="user:getPortalIncludeInfo('NAME')"/><xsl:value-of select="Name"/>Iframe</xsl:attribute>
				<xsl:attribute name="name">mnu<xsl:value-of select="user:getPortalIncludeInfo('NAME')"/><xsl:value-of select="Name"/>Iframe</xsl:attribute>
				<xsl:attribute name="scrolling">no</xsl:attribute>
				<xsl:attribute name="frameborder">0</xsl:attribute>
    		</img>
    	</xsl:if>
           
     </BODY>
     </HTML>
  </xsl:template>    
   
<xsl:template match="Tab">
  <xsl:if test="Visible[. ='true']">
  	<xsl:value-of select="user:lineBreak()"  />
	<xsl:comment>Associated Tab: <xsl:value-of select="Name"/></xsl:comment><xsl:value-of select="user:lineBreak()"  />
	<xsl:if test="MenuImageBlock[. !='']">
	  <div>
		<xsl:attribute name="id"><xsl:value-of select="user:convertName(.)"/>_imgblock</xsl:attribute>
		<xsl:choose>
		      <xsl:when test="//Portal/MenuWidth[. ='135']">
		    	<xsl:attribute name="style">width:132</xsl:attribute>
		      </xsl:when>
		      <xsl:otherwise>
		        <xsl:attribute name="style">width:162</xsl:attribute>
		      </xsl:otherwise>
    		</xsl:choose>
		<xsl:attribute name="class"><xsl:value-of select="user:getMenuBlockClass(.)"/></xsl:attribute>
		<img>
			<xsl:attribute name="id"><xsl:value-of select="user:convertName(.)"/>_img</xsl:attribute>	
			<xsl:attribute name="class">clsMenuPic</xsl:attribute>	
			<xsl:attribute name="src"><xsl:value-of select="MenuImageBlock" /></xsl:attribute>	
		</img>
	  </div>
	</xsl:if>
	
	
	<DIV>
	<xsl:attribute name="id"><xsl:value-of select="user:convertName(.)"/></xsl:attribute>
	<xsl:attribute name="style">position: absolute;left:5;top:<xsl:value-of select="user:getTop(.)"/>;width:<xsl:value-of select="user:getWidth(.)-5"/>;visibility:<xsl:value-of select="user:getVisibility(.)"/></xsl:attribute>         
  	<xsl:value-of select="user:lineBreak()"  />	
	<DIV>
	    <xsl:choose>
	    	<xsl:when test="//Portal/MenuWidth[. ='135']">
	    	    <xsl:attribute name="class"><xsl:value-of select="user:getMenuNum(0)" /></xsl:attribute>
	    	</xsl:when>
	    	<xsl:otherwise>
	    	       <xsl:attribute name="class"><xsl:value-of select="user:getMenuNum(1)" /></xsl:attribute>
	    	</xsl:otherwise>
    	    </xsl:choose>
	    <xsl:attribute name="id"><xsl:value-of select="Id" /></xsl:attribute>
	    <xsl:value-of select="user:getTabValue(.)" disable-output-escaping = "yes"/>

	  </DIV>	


    <xsl:apply-templates select="Menu | Page" />		
      
    <xsl:if test="IncludeFile/Url[@image='true']">
       <img>
       	<xsl:attribute name="src"><xsl:value-of select="IncludeFile/Url" /></xsl:attribute>
       	<xsl:attribute name="style"><xsl:value-of select="user:getTabIncludeImageStyle(.)"/></xsl:attribute>
	<xsl:attribute name="id">mnu<xsl:value-of select="Id"/>Iframe</xsl:attribute>
	<xsl:attribute name="name">mnu<xsl:value-of select="Id"/>Iframe</xsl:attribute>
       </img>
    </xsl:if>
    <xsl:if test="IncludeFile/Url[@image='false']">
       <iframe>
       	<xsl:attribute name="src"><xsl:value-of select="IncludeFile/Url" /></xsl:attribute>
       	<xsl:attribute name="allowTransparency">true</xsl:attribute>
        <xsl:attribute name="style"><xsl:value-of select="user:getTabIncludeStyle(.)"/></xsl:attribute>
        <xsl:attribute name="id">mnu<xsl:value-of select="Id"/>Iframe</xsl:attribute>
        <xsl:attribute name="name">mnu<xsl:value-of select="Id"/>Iframe</xsl:attribute>
        <xsl:attribute name="scrolling">no</xsl:attribute>
        <xsl:attribute name="frameborder">0</xsl:attribute>
        <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
       </iframe>
   </xsl:if>
  		
	</DIV>
	<xsl:value-of select="user:lineBreak()"  />
	<xsl:value-of select="user:incrementTabNumber()"/>
  </xsl:if>
</xsl:template>	   
    
<xsl:template match="Menu">
  <xsl:if test="Visible[. ='true']">
  	<xsl:value-of select="user:lineBreak()"  />
  	<xsl:comment>    Menu: <xsl:value-of select="Name"/></xsl:comment><xsl:value-of select="user:lineBreak()"  />
  	<span><xsl:attribute name="id"><xsl:value-of select="user:getPageID(.)"/>_linkspan</xsl:attribute>
	<xsl:if test="Display[. !='true']">
  	  <xsl:attribute name="class">clsSpanHidden</xsl:attribute>
  	</xsl:if>
  	<xsl:if test="Display[. ='true']">
          <xsl:attribute name="class">clsSpan</xsl:attribute>
  	</xsl:if>
  	<xsl:value-of select="user:blankSpaceLbl()" disable-output-escaping = "yes" />
  	<img>
	<xsl:attribute name="id"><xsl:value-of select="user:gotPageID()"/>_img</xsl:attribute>
	<xsl:attribute name="class">clsMenuImage</xsl:attribute>
	<xsl:attribute name="src"><xsl:value-of select="user:getSource(.)"/></xsl:attribute>
	<xsl:attribute name="OnClick">PFSMenuClick('<xsl:value-of select="user:gotPageID()"/>')</xsl:attribute>
  	<xsl:value-of select="user:blankSpaceLbl()" disable-output-escaping = "yes" /></img>
  	<xsl:value-of select="user:lineBreak()"  />
  	<A>
  	<xsl:attribute name="href"><xsl:value-of select="user:getMenuHref(.)"/></xsl:attribute>
  	<xsl:attribute name="class"><xsl:value-of select="user:getMenuClass(.)"/></xsl:attribute>
  	<xsl:attribute name="id"><xsl:value-of select="user:gotPageID()"/></xsl:attribute>
  	<xsl:value-of select="user:getMenuValue(.,0)"/>
   	<xsl:if test="SplitTitle[. = 'true']">
		<br/>
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:getMenuValue(.,1)"/>
   	</xsl:if>
   	<xsl:if test="user:getMenuValue(.,2) != ''">
		<br/>
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:getMenuValue(.,2)"/>
   	</xsl:if>
  	</A>
  	<xsl:value-of select="user:lineBreak()"  />
  	<span>
	<xsl:attribute name="id"><xsl:value-of select="user:gotPageID()"/>_span</xsl:attribute>
	<xsl:if test="Expanded[(. = 'true') or (. = 'True')]">
	  <xsl:attribute name="class">clsMenuSpanShow</xsl:attribute>
  	</xsl:if>
  	<xsl:if test="Expanded[(. = 'false') or (. = 'False')]">
	  <xsl:attribute name="class">clsMenuSpanHide</xsl:attribute>
  	</xsl:if>
	<xsl:apply-templates select="Page" />		
	</span>
  	</span>
  </xsl:if>
</xsl:template>
  
<xsl:template match="Menu/Page">  
  <xsl:if test="Visible[. ='true']">
  	<xsl:value-of select="user:lineBreak()"  />
  	<xsl:comment>   SubPage: <xsl:value-of select="Name"/></xsl:comment><xsl:value-of select="user:lineBreak()"  />
	<span><xsl:attribute name="id"><xsl:value-of select="user:getPageID(.)"/>_linkspan</xsl:attribute>
  	<xsl:if test="Display[. !='true']">
	  <xsl:attribute name="class">clsSpanHidden</xsl:attribute>
  	</xsl:if>
  	<xsl:if test="Display[. ='true']">
  	  <xsl:attribute name="class">clsSpan</xsl:attribute>
  	</xsl:if>
  	<xsl:value-of select="user:lineBreak()"  />
  	<xsl:apply-templates select="Page" />
  	
   	<a>
   	<xsl:attribute name="title"><xsl:value-of select="ToolTip" /></xsl:attribute>
   	<xsl:attribute name="Id"><xsl:value-of select="user:gotPageID()"/></xsl:attribute>
   	<xsl:attribute name="href"><xsl:value-of select="user:getPageHref(.)"/></xsl:attribute>
   	<xsl:attribute name="class"><xsl:value-of select="user:getMenuPageClass(.)"/></xsl:attribute>
   	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />-
   	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   	<xsl:value-of select="user:getMenuValue(.,0)"/>
	<xsl:if test="user:getMenuValue(.,1) != ''">
		<br/><xsl:value-of select="user:lineBreak()"  />
   		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:getMenuValue(.,1)"/>
	</xsl:if>
	<xsl:if test="user:getMenuValue(.,2) != ''">
		<br/><xsl:value-of select="user:lineBreak()"  />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
   		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
		<xsl:value-of select="user:getMenuValue(.,2)"/>
   	</xsl:if>
  	</a><br/>
  	<xsl:value-of select="user:lineBreak()"  />
  	</span><xsl:variable name="n">\n</xsl:variable>
  </xsl:if>
</xsl:template>
      
<xsl:template match="Tab/Page">  
  <xsl:if test="Visible[. ='true']">
  	<xsl:value-of select="user:lineBreak()"  />
        <xsl:comment>Page: <xsl:value-of select="Name"/></xsl:comment>
	  	<xsl:value-of select="user:lineBreak()"  />
  	<span><xsl:attribute name="id"><xsl:value-of select="user:getPageID(.)"/>_linkspan</xsl:attribute>
  	<xsl:if test="Display[. !='true']">
   	  <xsl:attribute name="class">clsSpanHidden</xsl:attribute>
  	</xsl:if>
  	<xsl:if test="Display[. ='true']">
  	  <xsl:attribute name="class">clsSpan</xsl:attribute>
  	</xsl:if>
  	<xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
  	<img>
	  <xsl:attribute name="id"><xsl:value-of select="user:gotPageID()"/>_img</xsl:attribute>
	  <xsl:attribute name="class">clsMenuImage</xsl:attribute>
	  <xsl:attribute name="src"><xsl:value-of select="user:getMenuImage()"/></xsl:attribute>
	  <xsl:attribute name="border">0</xsl:attribute>
  	  <xsl:attribute name="width">10</xsl:attribute>
	  <xsl:attribute name="height">10</xsl:attribute>  	  
	</img><xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
	<xsl:value-of select="user:lineBreak()"  />
	<a>
	  <xsl:attribute name="title"><xsl:value-of select="ToolTip" /></xsl:attribute>
          <xsl:attribute name="Id"><xsl:value-of select="user:gotPageID()"/></xsl:attribute>
          <xsl:attribute name="href"><xsl:value-of select="user:getPageHref(.)"/></xsl:attribute>
          <xsl:attribute name="class"><xsl:value-of select="user:getTabPageClass(.)"/></xsl:attribute>
	  <xsl:value-of select="user:getMenuValue(.,0)" disable-output-escaping = "yes"/>

	  <xsl:if test="SplitTitle[. = 'true']">
	    <br/>
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
            <xsl:value-of select="user:blankSpace()" disable-output-escaping = "yes" />
	    <xsl:value-of select="user:getMenuValue(.,1)" disable-output-escaping = "yes"/>
          </xsl:if>
	</a><br/>
        </span>
  </xsl:if>
</xsl:template>   
    
<xsl:template match="Include">  
  <img>
  </img>
</xsl:template>    

</xsl:stylesheet>
