    var DocRootPath = "/public_site";
    var IndexMainPath = "/webapp/NanShan/public_site";
//    var DocRootPath = "";

    var PageOnly = CheckPageOnly();

    var TopMenuHTML;
    TopMenuHTML =  "<span class='topmenu' id='topmenu' style='position:absolute'>";
    TopMenuHTML += "<table width='100%' height='26'  border='0' cellspacing='0' cellpadding='0' STYLE='table-layout:FIXED'>";
    TopMenuHTML += "  <tr>";
    TopMenuHTML += "    <td background='" + DocRootPath + "/button/images/bg_btn.gif'>";
	  TopMenuHTML += "    	<table width='1%'  border='0' cellspacing='0' cellpadding='0' " + (getIsSinoPac()?" style='display:none' ":"") + ">";
	  TopMenuHTML += "      	<tr>";
	  TopMenuHTML += "        	<td><a href='#'><img id='service' class='TopMenuImg' src='" + DocRootPath + "/button/images/btn_svc.gif' width='118' height='26' border='0'></a></td>";
	  TopMenuHTML += "        	<td><a href='#'><img id='products' class='TopMenuImg' src='" + DocRootPath + "/button/images/btn_prd.gif' width='118' height='26' border='0'></a></td>";
	  TopMenuHTML += "        	<td><a href='#'><img id='company' class='TopMenuImg' src='" + DocRootPath + "/button/images/btn_abt.gif' name='Image18' width='118' height='26' border='0'></a></td>";
	  TopMenuHTML += "        	<td><a href='#'><img id='info' class='TopMenuImg' src='" + DocRootPath + "/button/images/btn_inf.gif' name='Image19' width='118' height='26' border='0'></a></td>";
	  TopMenuHTML += "        	<td><a href='#'><img id='elite' class='TopMenuImg' src='" + DocRootPath + "/button/images/btn_elite.gif' name='Image19' width='118' height='26' border='0'></a></td>";
	  TopMenuHTML += "        	<td><img src='" + DocRootPath + "/button/images/btn_end.gif' width='2' height='26'></td>";
	  TopMenuHTML += "      	</tr>";
	  TopMenuHTML += "    	</table>";
    TopMenuHTML += "    </td>";
    TopMenuHTML += "  </tr>";
    TopMenuHTML += "</table>";
    TopMenuHTML += "</span>";
    
    if ((PageOnly == false) & (CheckInsidePublicSiteFrame() == true))
    {
        document.write(TopMenuHTML);
        document.close();                       
    }

      // pre-cache menubar image pairs
    var ImgMenuItem = new Image(18,20);
        ImgMenuItem.src = DocRootPath + "/button/images/topmenu_arrow.gif"; 
         
    var BtnImagesNormal = new Array();
    BtnImagesNormal["service"] = new Image(118, 26);
    BtnImagesNormal["service"].src = DocRootPath + "/button/images/btn_svc.gif";
    BtnImagesNormal["products"] = new Image(118, 26);
    BtnImagesNormal["products"].src  = DocRootPath + "/button/images/btn_prd.gif";
    BtnImagesNormal["company"] = new Image(118, 26);
    BtnImagesNormal["company"].src  = DocRootPath + "/button/images/btn_abt.gif";
    BtnImagesNormal["info"] = new Image(118, 26);
    BtnImagesNormal["info"].src  = DocRootPath + "/button/images/btn_inf.gif";
    BtnImagesNormal["elite"] = new Image(118, 26);
    BtnImagesNormal["elite"].src  = DocRootPath + "/button/images/btn_elite.gif";

    var BtnImagesMouseOver = new Array();
    BtnImagesMouseOver["service"] = new Image(118, 26);
    BtnImagesMouseOver["service"].src = DocRootPath + "/button/images/btn_svc_over.gif";
    BtnImagesMouseOver["products"] = new Image(118, 26);
    BtnImagesMouseOver["products"].src  = DocRootPath + "/button/images/btn_prd_over.gif";
    BtnImagesMouseOver["company"] = new Image(118, 26);
    BtnImagesMouseOver["company"].src  = DocRootPath + "/button/images/btn_abt_over.gif";
    BtnImagesMouseOver["info"] = new Image(118, 26);
    BtnImagesMouseOver["info"].src  = DocRootPath + "/button/images/btn_inf_over.gif";
    BtnImagesMouseOver["elite"] = new Image(118, 26);
    BtnImagesMouseOver["elite"].src  = DocRootPath + "/button/images/btn_elite_over.gif";

function getElementStyle(elem, IEStyleProp, CSSStyleProp) {
    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleProp];
    } else if (window.getComputedStyle) {
        var compStyle = window.getComputedStyle(elem, "");
        return compStyle.getPropertyValue(CSSStyleProp);
    }
    return "";
}

// carry over some critical menu style sheet attribute values
var CSSRuleValues = {
                        menuItemHeight:"20px",
                        menuWrapperBorderWidth:"1px",
                        menuWrapperPadding:"1px",
                        defaultBodyFontSize:"12px"
                    };

  // specifications for menu contents and menubar image associations
var TopMenu = new Array();
TopMenu[0] = {  
                ImgId: "service",
                ImgNormal: BtnImagesNormal["service"],
                ImgMouseOver: BtnImagesMouseOver["service"],
                MenuItems:[
                          //{text:"VIP貴賓保戶", id:"service.vip"},
                            {text:"服務櫃台", id:"service.counter"},
                            {text:"理賠櫃台", id:"service.claim"},
                            {text:"服務通路", id:"service.channel"},
                            {text:"收費服務", id:"service.pay"},
                            {text:"數位簽章", id:"service.digital_sign"},
                            {text:"常見問題", id:"service.faq"},
                            {text:"Skype線上通話", id:"service.skype"}
                          ],
                MenuItemOnClass: "service_menuItemOn",
                ElemId:""          
             };
           
TopMenu[1] = {
                ImgId:"products",
                ImgNormal:BtnImagesNormal["products"],
                ImgMouseOver:BtnImagesMouseOver["products"],
                MenuItems:[
                            //{text:"商品聚光燈", id:"products.prod"},
							//{text:"健康險", id:"products.health"},
							//{text:"傷害險", id:"products.accident"},
							//{text:"傷害險暨健康險", id:"products.accident_health"},
							//{text:"壽險暨健康險", id:"products.comprehensive"},
							//{text:"壽險暨傷害險", id:"products.buffet"},
							//{text:"定期險", id:"products.term"},
							{text:"107條說明", id:"products.law107"}, //新選單
							{text:"精選商品名店", id:"products.hot", NewWindow:"/public_site/products/hot/hot.htm"},
							{text:"微型保險專區", id:"products.mpa"},
							{text:"保障型保險商品", id:"products.ensure"},							
							{text:"還本型終身壽險", id:"products.whole_life_repay"},
							{text:"養老險商品", id:"products.endowment"},
							{text:"年金險商品", id:"products.annuity"},
							{text:"投資型商品", id:"products.investment"},
							{text:"保單借款權益", id:"products.ehia"}, //新選單
							{text:"團體保險", id:"products.group_new"},
							{text:"房屋貸款", id:"products.loan_new"},
							{text:"汽車貸款", id:"products.car_new"},
                            {text:"保戶福利報", id:"products.favored"}, //新選單-顧客行銷部
							//{text:"優質保戶專案", id:"products.favored"}, //舊選單-顧客行銷部
                            {text:"旅行險專區", id:"products.travel", NewWindow:"/promotion/travel/index.htm"},
                            {text:"職場行銷專區", id:"products.worksite"}
                          ],
                MenuItemOnClass: "products_menuItemOn",
                ElemId:""          
             };
           
TopMenu[2] = {
                ImgId:"company",
                ImgNormal:BtnImagesNormal["company"],
                ImgMouseOver:BtnImagesMouseOver["company"],
                MenuItems:[
                            {text:"公司簡介", id:"company.intro"},
                            {text:"得獎紀錄", id:"company.award"},
                            {text:"菁英招募", id:"company.want"},
                            {text:"資訊公開", id:"company.open"}
                            //{text:"南山慈善基金會", id:"company.foundation"}
                          ],
                MenuItemOnClass: "company_menuItemOn",
                ElemId:""          
             };

TopMenu[3] = {
                ImgId:"info",
                ImgNormal:BtnImagesNormal["info"],
                ImgMouseOver:BtnImagesMouseOver["info"],
                MenuItems:[
                            {text:"退休市場專區", id:"info.retire"},
                            {text:"稅務小常識專區", id:"info.tax"},
                            {text:"網路資源", id:"info.resources"},
                            {text:"性騷擾防治措施", id:"info.sex"}
                          ],
                MenuItemOnClass: "info_menuItemOn",          
                ElemId:""          
             };
TopMenu[4] = {
                ImgId:"elite",
                ImgNormal:BtnImagesNormal["elite"],
                ImgMouseOver:BtnImagesMouseOver["elite"],
                MenuItems:[
                            {text:"金鷹會會員", id:"elite.eagle"},
                            {text:"財富管理業務員", id:"elite.rich"},
	                        {text:"財富管理專區", id:"elite.wm", NewWindow:"/public_promotion/subject/wms/index.htm"}
                          ],
                MenuItemOnClass: "elite_menuItemOn",          
                ElemId:""          
             };
/*             
TopMenu[4] = {
                ImgId:"ces",
                ImgNormal:BtnImagesNormal["ces"],
                ImgMouseOver:BtnImagesMouseOver["ces"],
                MenuItems:[
                            {text:"會員註冊", id:"ces.register"},
                            {text:"會員登入服務", id:"ces.login"},
                            {text:"保戶資料變更", id:"ces.data_change"},
                            {text:"保單查詢及服務", id:"ces.query_service"},
                            {text:"文件申請", id:"ces.doc"},
                            {text:"國際支援服務", id:"ces.international_support"}
                          ],
                MenuItemOnClass: "ces_menuItemOn",          
                ElemId:""          
             };
*/             
  // create hash table-like lookup for menu objects with id string indexes
function MakeHashes() 
{
   for (var i = 0; i < TopMenu.length; i++) 
   {
       TopMenu[TopMenu[i].ElemId] = TopMenu[i];
       TopMenu[TopMenu[i].ImgId] = TopMenu[i];
   }    
}

// assign menu label image event handlers
function AssignButtonEvents() 
{
    var Element;                                
    
    for (var i = 0; i < TopMenu.length; i++) 
    {
        Element = document.getElementById(TopMenu[i].ImgId);
        Element.onmouseover = SwapImage;
        Element.onmouseout = SwapImage;
    }
}

function MakeMenu()                                
{
    var MenuDiv, MenuItem, ItemLink, BarImg, TextNode, OffsetLeft, OffsetTop;
    var MenuItemH = 20;
    var HeightAdjust = 0;
    var Img;

    // use menu array to drive div creation loop
    for ( var i = 0; i < TopMenu.length; i++) 
    {
        MenuDiv = document.createElement("div");
        MenuDiv.id = "PopupMenu" + i;
        
          // preserve menu's ID as property of the menus array item
        TopMenu[i].ElemId = "PopupMenu" + i;
        MenuDiv.className = "menuWrapper";
        if (TopMenu[i].MenuItems.length > 0) 
           MenuDiv.style.height = ((MenuItemH * TopMenu[i].MenuItems.length) + TopMenu[i].MenuItems.length + 2) + "px";
        else  // don't display any menu div lacking menu items
            MenuDiv.style.display = "none";
        
          // define event handlers
        MenuDiv.onmouseover = KeepMenu;
        MenuDiv.onmouseout = RequestHide;

          // set stacking order in case other layers are around the page
        MenuDiv.style.zIndex = 1000;
        
          // assemble menu item elements for inside menu div
        for (var j = 0; j < TopMenu[i].MenuItems.length; j++) 
        {
            MenuItem = document.createElement("div");
            MenuItem.id = TopMenu[i].MenuItems[j].id;
            MenuItem.className = "menuItem";
            if (!document.all)MenuItem.style.height="23px"
            MenuItem.onmouseover = ToggleHighlight;
            MenuItem.onmouseout = ToggleHighlight;
            MenuItem.onclick = MenuItemSelect;
            MenuItem.style.top = ((MenuItemH * j) + j) + "px";
            Img = document.createElement("Img");
            Img.src = ImgMenuItem.src;
            Img.style.align = "absmiddle";
            ItemLink = document.createElement("a");
//            ItemLink.href = TopMenu[i].MenuItems[j].target;
//            ItemLink.className = "menuItem";
//            ItemLink.onmouseover = ToggleHighlight;
//            ItemLink.onmouseout = ToggleHighlight;
            TextNode = document.createTextNode(TopMenu[i].MenuItems[j].text);
            MenuItem.appendChild(Img);
            MenuItem.appendChild(TextNode);
//            MenuItem.appendChild(ItemLink);
            MenuDiv.appendChild(MenuItem);
            MenuItem.NewWindow = TopMenu[i].MenuItems[j].NewWindow==null?"":TopMenu[i].MenuItems[j].NewWindow;
        }
        
        // append each menu div to the body
        document.body.appendChild(MenuDiv);
    }
    
    MakeHashes();
    AssignButtonEvents();
    
    // pre-position menu
    for (var i = 0; i < TopMenu.length; i++) 
        PositionMenu(TopMenu[i].ElemId);
}

// initialize global that helps manage menu hiding
var Timer;

// invoked from mouseovers inside menus to cancel hide
// request from mouseout of menu bar image et al.
function KeepMenu() 
{
    clearTimeout(Timer);
}

function CancelAll() 
{
    KeepMenu();
}

// invoked from mouseouts to request hiding all menus
// in 1/4 second, unless cancelled
function RequestHide() 
{
    Timer = setTimeout("HideMenu()", 250);
}

function MenuItemSelect(evt)
{
    var MenuItemId;
    var URL;
    var NewWindow;
    
    evt = (evt) ? evt : ((event) ? event : null);
    var elem = (evt.target) ? evt.target : evt.srcElement;
    if (elem.nodeType == 3) {
        elem = elem.parentNode;        
    }
		NewWindow = (elem.NewWindow==null?"":elem.NewWindow);
		if(NewWindow!=""){//另開視窗
			window.open(NewWindow);
		}else{//在主視窗開啟
			HideMenu();
    	MenuItemId = elem.id;
			//LoadLeftMenu(MenuItemId);
			//LoadTopFrame(MenuItemId);
    	URL = "http://" + top.main.location.hostname + IndexMainPath + "/index_main.jsp?MenuId=" + MenuItemId;    
    	top.location.href = URL;
		}
}                                       


// "brute force" hiding of all menus and restoration
// of normal menu bar images
function HideMenu() 
{
    for (var i = 0; i < TopMenu.length; i++) 
    {
       document.getElementById(TopMenu[i].ImgId).src = TopMenu[i].ImgNormal.src;
       var Menu = document.getElementById(TopMenu[i].ElemId)
       Menu.style.visibility = "hidden";
    }
      // check if we need to hide pdf iframe
    if (document.getElementById('pdf') != null)
       document.getElementById('pdf').style.visibility = "visible";  
	if (document.getElementById('flash') != null)
       document.getElementById('flash').style.visibility = "visible";       
}

// set menu position just before displaying it
function PositionMenu(menuId)
{
    // use the menu bar image for position reference of related div
    var mBarImg = document.getElementById(TopMenu[menuId].ImgId);
    var offsetTrail = mBarImg;
    var offsetLeft = 0;
    var offsetTop = 0;
    
    while (offsetTrail) 
    {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    
    var menuDiv = document.getElementById(menuId);
    menuDiv.style.left = offsetLeft + "px";
    menuDiv.style.top = offsetTop + mBarImg.height + "px";
}

// display a particular menu div
function ShowMenu(MenuId) 
{   
    var Menu;
    
    KeepMenu();
    HideMenu();
    PositionMenu(MenuId);
    Menu = document.getElementById(MenuId);
    Menu.style.visibility = "visible";
      // check if we need to hide pdf iframe
    if (document.getElementById('pdf') != null)
       document.getElementById('pdf').style.visibility = "hidden";      
	if (document.getElementById('flash') != null)
       document.getElementById('flash').style.visibility = "hidden";     
}

// menu bar image swapping, invoked from mouse events in menu bar
// swap style sheets for menu items during rollovers
function ToggleHighlight(evt) 
{
    var MenuItemId;
    
    evt = (evt) ? evt : ((event) ? event : null);
    var elem = (evt.target) ? evt.target : evt.srcElement;
    if (elem.nodeType == 3) {
        elem = elem.parentNode;
    }
    
    if ((elem.className == "menuItemOn") || (elem.className == "menuItem") || 
        (elem.className == "service_menuItemOn") || (elem.className == "products_menuItemOn") || 
        (elem.className == "company_menuItemOn") || (elem.className == "info_menuItemOn") || 
        (elem.className == "ces_menuItemOn")		 || (elem.className == "elite_menuItemOn") )
    {
        if (evt.type == "mouseover") 
        {
            KeepMenu();
            MenuItemId = elem.id.split(".");
            elem.className = TopMenu[MenuItemId[0]].MenuItemOnClass;
        } 
        else 
        {
            elem.className = "menuItem";
            RequestHide();
        }
    }    
    evt.cancelBubble = true;
}

function SwapImage(evt) 
{
    evt = (evt) ? evt : ((event) ? event : null);
    if (evt && (document.getElementById && document.styleSheets)) 
    {
        var elem = (evt.target) ? evt.target : evt.srcElement;
        if (elem.className == "TopMenuImg") 
        {
            if (evt.type == "mouseover") 
            {
                ShowMenu(TopMenu[elem.id].ElemId);
                elem.src = TopMenu[elem.id].ImgMouseOver.src;
            } 
            else if (evt.type == "mouseout") 
            {
                RequestHide();
            }
            evt.cancelBubble = true;
        }
    }
}

function LoadLeftMenu(MenuId)
{
   var LeftURL;
   var Dir;

   Dir = MenuId.split(".");
   LeftURL = DocRootPath + "/left/" + Dir[0] + "/" + Dir[1] + ".htm";
      // load corresponding left menu web page
   top.left.location.href = LeftURL;
}

function LoadTopFrame(MenuId)
{
   var TopURL;
   var Dir;

   Dir = MenuId.split(".");
   TopURL = DocRootPath + "/top/" + Dir[0] + ".htm";
      // load corresponding top menu web page with query string
   top.up.location.href = TopURL + "?Target=" + MenuId;
}

function Reposition()
{
    if (document.getElementById('topmenu') != null)
    {
    	if (document.all) document.getElementById('topmenu').style.pixelTop=document.body.scrollTop;
  	else document.getElementById('topmenu').style.top=document.body.scrollTop
        document.getElementById('topmenu').style.zIndex = 100;
    }    
}

function CheckPageOnly() 
{
    var cName = "PageOnly=";
    var QueryString = self.location.search;

    if (QueryString.length > 0) 
    {
        var Begin = QueryString.indexOf(cName);
        if (Begin != -1) 
            return true;
        else    
            return false;
    }
    return false;
}

function CheckInsidePublicSiteFrame()
{
     var mainframe; 
    
    try 
    {
        mainframe = top.frames["main"];
        if (mainframe == null)
           return false;
    }
    catch(e)
    {
        return false;
    }
    
    if (top == self)
       return false;   
    return true;   
}

if ((PageOnly == false) && (CheckInsidePublicSiteFrame() == true))
    MakeMenu();
    
function getIsSinoPac(){	
	var bRtn = false;
	try{
		var frames = parent.frames;
		for(var i=0;frames!=null&&i<frames.length;i++){
			try{
				//alert("Frame("+i+") Name:"+frames[i].name);
				if(frames[i].isSinoPac==true){
						bRtn = true;
						break;
				}
			}catch(err){
				//alert("frame["+i+"].isSinoPac Not Found");
			}
		}
	}catch(err){
		//alert("parent.frames Not Found");		
		bRtn = false;
	}
	return bRtn;
}