/*
  $Id: smenu-v2.js 4580 2009-04-17 17:02:10Z andreas.mohrig $

  //-------------------------------------------------------------------------------
  // File: smenu-v2.js -
  // Description: Simple Menu Constractor V2.1
  //-------------------------------------------------------------------------------
  // Tested with: IE 5.x 6.x, Mozilla 1.x, Netscape 4.x 6.x 7.x, Opera 7
  // Created:  9.10.2002
  // LastUpd:  17.04.2003
  //
  // Author: Panos Galanis <pg@iap.de>
  //
  // IAP GmbH
  // Ingenieurburo fur Anwendungs-Programmierung
  // Mörkenstraße 9, D-22767 Hamburg
  // Web: http://www.iap.de, Mail: info@iap.de
  //-------------------------------------------------------------------------------
  ke, 30 mar 04; fixed bug: two submenu in a line didn't hide correctly
  ke, 31 mar 04; fixed bug: A horizontal bar belongs always to submenu if there created
  ke, 01 apr 04; fixed bug: submenu as last menu entry gives wrong position of next Header
  ke, 23 aug 04; Added separate color for the MenuHead border and MenuHead border suppress
  am, 13 jun 07: Added a workaround for hiding applets to make the menu visible
  */


/// --------------- ///
/// Configuration   ///
/// --------------- ///


/// Help for some elements

// To see how targets could defined see the function "sM_link"


/// Common Style settings ///

// The default classes. These classes are used if no other classes are given
var JSM_DefaultClass="MDef";        // Default class for every object
var JSM_HeadClass="MHead";          // Menu Bar default class
var JSM_MenuClass="MMenu";          // Pull Down Menu (1st level) default class
var JSM_SubMenuClass="MSub";        // Submenu (2nd level) default class
var JSM_InactiveClass="MInactive";  // Inactive entry default class


/// Cell border/style settings ///

// Make space between cells (set to 0 to suppress)
var JSM_Space=0;
// Border in Pixels (set to 0 to suppress border)
// Space is taken from width/height
var JSM_Border=1;
// Border Color (has no effect if border is suppressed)
var JSM_BorderColor="#e5e5dd";
// MenuHead can have own border color. If not set (""), no Border will show up
//var JSM_MenuHeadBorder=JSM_BorderColor;
var JSM_MenuHeadBorder="#002b55";
// Padding in Pixels (space will be added to with/height)
var JSM_Padding=2;

// Horizontal linebars (some possibilities, examples, do not delete)
//var linebar="<hr>";
//var JSM_linebar="<hr style='border:0px;width:100%;height:1px;background:"+JSM_BorderColor+";'>";
//var JSM_linebar="------------------------";
//var JSM_linebar="<hr noshade='noshade' width='100' size='1' class='MRuler'>";
// ke; To change color use the background attribut in the css file (for MRuler)
var JSM_linebar="<img src='js/icons/hr.gif' class='MRuler'>";
// NETSCAPE 4.x Have his own Ruler at Netscape 4 Section !!!!


/// Position Options ///

// Main menu bar attributs
var JSM_sx=17;            // X Positioning
var JSM_sy=82;            // Y Positioning
var JSM_sh=14;            // Height, also default for submenues

// HorizontalPadding (Pixels left and rigth in every header!)
// if header menu is variable (isHeadFixed=false)
var JSM_hPadding=20;

// Header menu cell width could be fixed or variable
// Header/Submenu width
// isHeadFixed=true  : Used for main and submenu
// isHeadFixed=false : Used only for submenu
var JSM_isHeadFixed=true;  // false: No specified Head Width!  true: Fixed header width (sw)

// If true (1) The script will check every Group to find
// the bigest width. Then will set this to all members of this group.
// Note: This will not work for menu elements with a linebar or
//       if the menu element is a SUBMENU Header and JSM_subimg include an image!!!
//       The resaon is that the width will not be set
//       if is 3x bigger than JSM_sw.. (hardcoded)
// This does _not_ affect DOM-less clients. ex. Will not work for NS4
// Slow's a bit things down but ....
var JSM_isAutoWidthMenu=false;

// Static Menu element Width
// Please set this even you have JSM_isAutoWidthMenu to true (1).
// This is used in every case in NS 4.x
var JSM_sw=160;


/// Submenu positon ///

var JSM_subx=0;          // Sub X Positioning (measured against right border of parent cell)
var JSM_suby=0;


/// Effect options ///

// Show as "Title" attribute (tooltip) the link (like alternative in image)
var JSM_LinkAsTitle=true;

// Transparent Option for IE & Mozilla
var JSM_isOpaque=false;
// Visibility 0-100 (%) if (isOpaque)
var JSM_OpaqueValue=100;

// Miliseconds for Menu Visibility to hidden if is been trigered "onmouseout"
var JSM_ClearMenuTimer=500;
// Miliseconds for Submenu Visibility to hidden if is been trigered "onmouseout"
var JSM_ClearSubMenuTimer=200;
// Milliseconds before a submenu is shown, when the mouse is on the menu entry
var JSM_ShowSubMenuTimer=75;
var JSM_DelayOnlyFirstSubMenu=true;
// Milliseconds before a drop down menu is shown, when the mouse is on the menu entry
var JSM_ShowMenuTimer=200;
var JSM_DelayOnlyFirstMenu=true;



/// Image options ///

// Image for submenu pointer
var JSM_subimg="static/images/icons/arrow_black.gif";
// The Width of this image (Spaceholder)
var JSM_subimgwidth=20;
// path to icon images
var JSM_IconPath="static/images/icons";

// allow icons on left side of menu point (e.g. check hook)
// This will add space on the left side for the default icon
// var icons=true;
var JSM_UseIcons=true;
// default icon for left side icon
var JSM_DefaultIcon="empty.gif";


/// Netscape 4.x Specific ///

// Simple Class
// pls. Without background: or background-color:!!
var JSM_SimpleClass="MSimple";
// This is The Netscape Ruler :-)
var JSM_NSlinebar="<hr noshade width='100%' size='1'>";

// Normal & Hover Background Color for Menu Items
// Used Only in Netscape 4.x
var JSM_MenuHead_BGColor_Normal="#002b55";    // Background Color for Menu Header
var JSM_MenuHead_BGColor_Hover="#56B7DF";      // Background Color for Menu Header onMouseOver
var JSM_Menu_BGColor_Normal="#FFFFFF";        // Background Color for Menu
var JSM_Menu_BGColor_Hover="#56B7DF";          // Background Color for Menu onMouseOver
var JSM_MenuSub_BGColor_Normal="#FFFFFF";      // Background Color for Sub-Menu
var JSM_MenuSub_BGColor_Hover="#56B7DF";      // Background Color for Sub-Menu onMouseOver

var Dbg=false;

// Workaround for hiding applets to make the menu visible
var JSM_ObjectsToHide = null;
var JSM_EmbeddedToHide = null;
var JSM_ElementsToHideWidths = new Array();

/// --------------- ///
/// Main part       ///
/// --------------- ///

// States if the created element was a Menu/SubMenu to reset X position of new header element
var JSM_WasSubMenu=JSM_WasMenu=0;
// Hold context of submenu, categories, timeout etc.
var JSM_cat=JSM_subcat=JSM_vsID=JSM_vsSID=JSM_lastHeadID=0;
var JSM_lastCat=JSM_lastSub=null;

// Needed as counter to create layer for NS4
var JSM_dummyCnt=0;


// List of all Header and Menu Elements (Elements which have elements of the next level attached)
var JSM_idmaster=new Array();
var JSM_idsub=new Array();
// Concat list of menu and connected submenu, e.g. 0_1,0_2,0_3,4_5,4_6,0_7,8_8...
var JSM_idpool=new Array();

var JSM_awidthpool=new Array();
// Main array for menu elements
var JSM_fapi=new Array();
var JSM_TimeOuts = new Array(); // List of timeouts

// unneeded? var JSM_sM=new Array();
var JSM_lid=JSM_headw=JSM_NSheadw=0;

var JSM_nspadfix=(JSM_Border*2) + (JSM_Padding*2);
var JSM_xnew=JSM_sx;

var JSM_ynew=ysub=JSM_sy;

var JSM_ver=navigator.appVersion;
var JSM_dom=document.getElementById? 1:0;
var JSM_ns=(navigator.appName.indexOf("Netscape")>-1)? 1:0;
var JSM_ie=(JSM_ver.indexOf("MSIE")>-1)? 1:0;
var JSM_ie4=(document.all)? 1:0;
var JSM_ie7=JSM_ie && (window.XMLHttpRequest)?1:0;
var JSM_ns4=(JSM_ns && !JSM_dom)? 1:0;
var JSM_ns6=(JSM_ns && JSM_dom)? 1:0;
var JSM_DCE=(document.createElement)? 1:0
var JSM_DCTN=(document.createTextNode)? 1:0
var JSM_isJunk=(!JSM_dom && !JSM_ie && !JSM_ns)? 1:0;

// IE does not recognize push ... so we must have a function for this ...
// Original at javascript.faqts.com
if (Array.prototype && !Array.prototype.push)  Array.prototype.push = IE_push;


function hasFullDom()
{
    return (JSM_dom && JSM_DCE && JSM_DCTN);
}

function needsIe6Fix()
{
    return hasFullDom() && JSM_ie && !JSM_ie7;
}


function IE_push () {
    for (var a = 0; a < arguments.length; a++) this[this.length] = arguments[a];
    return this.length;
}

// Calculate x/y position of menu elements
function cal(m,i,l) {

    // New MenuHead element
    if (m[i][0]==0) {
        JSM_idmaster.push(i+l); // add to MenuHead array
        JSM_cat=(i+l);          // define block category?
        JSM_ynew=JSM_sy;        // reset y counter to header position
        // alert(m[i][1]+"/n"+JSM_WasSubMenu);
        if (JSM_WasSubMenu) {
            // Go to left start of Menu
            JSM_xnew-=(JSM_subx + JSM_sw + JSM_Space);
            JSM_WasSubMenu=0;
            if (JSM_ns6) JSM_xnew-=JSM_nspadfix;
        }
        // calc x pos for 2nd, 3rd... header
        if (i>0) {
            // Add "last header width" + space
            JSM_xnew+=(JSM_headw+JSM_Space);
            if (!JSM_isHeadFixed) JSM_xnew+=JSM_hPadding;
            if (JSM_ns6) JSM_xnew+=JSM_nspadfix;
        }
    }  // of new menuhead element

    // New Menu element
    else if(m[i][0]==1) {
        if (JSM_WasSubMenu) {
            JSM_cat=JSM_subcat;
            JSM_xnew -= (JSM_sw+JSM_Space+JSM_subx);
            JSM_ynew = JSM_ysub+JSM_lasty+JSM_Space;
            JSM_WasSubMenu=0;
            if (JSM_ns6) JSM_xnew-=JSM_nspadfix;
        }
        else{
            JSM_ynew+=m[i-1][5]+JSM_Space;
        }
        if (JSM_ns6) JSM_ynew+=JSM_nspadfix;
    } // of new menu element

    // New SubMenu element
    else if(m[i][0]==2) {
        // first submenu element in submenu
        if (!JSM_WasSubMenu) {
            JSM_WasSubMenu=1;
            JSM_idsub.push(i+l-1);
            JSM_subcat=JSM_cat;
            JSM_cat=(i+l);
            JSM_xnew+=JSM_sw+JSM_Space+JSM_subx;
            JSM_ysub=JSM_ynew;
            JSM_lasty=m[i-1][5];
            JSM_ynew+=JSM_suby;
            if (JSM_ns6) JSM_ynew-=JSM_nspadfix
            if (JSM_ns6) JSM_xnew+=JSM_nspadfix;
        }
        else {
            JSM_ynew+=m[i-1][5]+JSM_Space;
        }
        if (JSM_ns6) JSM_ynew+=JSM_nspadfix;
    } // of new submenu element

    if(JSM_cat != (i+l) || JSM_WasSubMenu) JSM_idpool.push(JSM_cat+"_"+(i+l));
} // function cal


// Test if a given id (number) is in an array; returns 1 if in array
function isInArray(id,a){
    for(i=0;i<a.length;i++){
        if(a[i]==id) return 1;
    }
    return 0;
}

// Set visibility for submenu(s) (Parent-ID, on/off (1/0), all or specific parid)
function vis(id,on,all)
{
    for(i=0;i<JSM_idpool.length;i++)
    {
        var Parent=JSM_idpool[i].split("_")[0]; // get parent object
        var Child=JSM_idpool[i].split("_")[1]; // get child object id
        var vis=(on)? "visible" : "hidden"; // text for style
        // switch for childs of parent or all childs
        if ( (Parent==id)||all )
        {
            getObj("M_"+Child).style.visibility = vis; // show/hide object
            if(needsIe6Fix()) getObj("M_"+Child+"XX").style.visibility = vis;
        }
    } // of for
} // of functin vis

function getCat(id){
    for(i=0;i<JSM_idpool.length;i++){
        var io=JSM_idpool[i].split("_")[0];
        var no=JSM_idpool[i].split("_")[1];
        if (no==id) return io;
    }
    return null;
}


function subMenuShower(oid)
{
    if (JSM_lastSub) vis((parseInt(JSM_lastSub) + 1),0,0);
    vis((parseInt(oid)+1),1,0);               // Show submenu
    JSM_lastSub=oid;                          // Store this in last open submenu
}


function dropDownShower(oid)
{
    //window.status = window.status + " - Header " + oid;
    vis(0,0,1);        // Hide all Menus and Submenus
    vis(oid,1,0);      // Show Menu of Header
    JSM_lastCat=oid;
    JSM_lastSub=null;
}


// calculate the real delay for showing a menu
// params: lastId - what (of this categorie was shown (when this is null, this is the first)
//         delayTime - the the delay configured (JSM_ShowMenuTimer);
function calcRealDelayTimeMenu()
{
    if(JSM_lastCat==null || !JSM_DelayOnlyFirstMenu) return JSM_ShowMenuTimer;
    return 0;
}


// calculate the delay for showing a submenu
// params: lastId - what (of this categorie was shown (when this is null, this is the first)
//         delayTime - the the delay configured (JSM_ShowMenuTimer);
function calcRealDelayTimeSubMenu()
{
    if(JSM_lastSub==null || !JSM_DelayOnlyFirstSubMenu) return JSM_ShowSubMenuTimer;
    return 0;
}

/**
 * Since the menu cannot be placed on top of an applet we (as a workaround) resize the applet
 * to 0 pixels in width.
 * The applets to hide have to be explicitly registered for this to work, so that other applets can
 * remain visible.
 * Please refer to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4858528 for more information.
 *
 * @author Markus Schwarz, wortzwei GmbH (c) 2007
 * @author Andreas Mohrig (modified to be backwards-compatible and affect only registered applets)
 */
function hideElementsToHide(hide) {
  var offset = 0;
  if (JSM_EmbeddedToHide) {
    for (var i = 0; i < JSM_EmbeddedToHide.length; i++) {
      if (JSM_EmbeddedToHide[i].width > 0) {
        JSM_ElementsToHideWidths[i] = JSM_EmbeddedToHide[i].width;
      }
      var w = JSM_ElementsToHideWidths[i];
      if (hide) {
        w = 0;
      }
      JSM_EmbeddedToHide[i].width = w;
    }
    offset = JSM_EmbeddedToHide.length;
  }

  if (JSM_ObjectsToHide) {
    for (var i = 0; i < JSM_ObjectsToHide.length; i++) {
      if (JSM_ObjectsToHide[i].width > 1) {
        JSM_ElementsToHideWidths[i+offset] = JSM_ObjectsToHide[i].width;
      }
      var w = JSM_ElementsToHideWidths[i+offset];
      if (hide) {
        w = 1;
      }
      JSM_ObjectsToHide[i].width = w;
    }
  }
}



// Handling for hoverover/onmouseover (obj_ref, css_class, is_bar, bgcolor)
function sM_hover(obj,c,isbar,bgc) {
    hideElementsToHide(true);
    clearTimeout(JSM_vsID); // Reset timeout of "last" submenu
    oid=obj.id.substr(2);   // Get obj id/nr
    //window.status = "hover into " + oid;

    // First switch to new header element
    if(isInArray(oid, JSM_idmaster)&&JSM_lastCat!=oid)
    {
        JSM_vsID=setTimeout("dropDownShower(oid)",calcRealDelayTimeMenu());
    }

    // Open to submenu
    if(isInArray(oid, JSM_idsub))
    {
        //window.status = window.status + " - Enter submenu " + oid + " (last submenu: " + JSM_lastSub + ")";
        clearTimeout(JSM_vsSID);                  // Reset timeout of last open submenu
        // Hide last submenu
        //JSM_vsSID=setTimeout("subMenuShower(oid)",JSM_ShowSubMenuTimer);
        JSM_vsSID=setTimeout("subMenuShower(oid)",calcRealDelayTimeSubMenu());
    }

    // Leave submenu to non-submenu element
    if(!isInArray(getCat(oid)-1,JSM_idsub) && !isInArray(oid, JSM_idsub) && JSM_lastSub!=null)
    {
        //window.status = window.status + " - Enter non-submen " + JSM_lastSub;
        clearTimeout(JSM_vsSID);
        JSM_vsSID=setTimeout("vis(parseInt(JSM_lastSub)+1,0,0);JSM_lastSub=null;",JSM_ClearSubMenuTimer);
    }
    if (!isbar) eval("obj.className='"+c+"_hover'");
    if (JSM_ns4) obj.bgColor=bgc;
} // end of function sM_hover



// handling for hoverout/onmouseout (obj_ref, css_class, is_bar, bgcolor)
function sM_hout(obj,c,isbar,bgc) {
    //oid=obj.id.substr(2);
    if(!isbar) obj.className=c;
    if (JSM_ns4) obj.bgColor=bgc;
    clearTimeout(JSM_vsID);
    clearTimeout(JSM_vsSID);
    // Hide all M/SM if not entering menu again
    JSM_vsID=setTimeout("JSM_lastCat=JSM_lastSub=null; vis(0,0,1);",JSM_ClearMenuTimer)
    hideElementsToHide(false);
} // end of function sM_hout


// Start the link
function sM_link(url,targ){
    var key=(JSM_ie)? window.event.button :0;
    if (key==2) {return true;};

    // If the target string begins with a f_ it will call directly a function
    if (targ.substr(0,2)=="f_") {
        var FVal=targ.substr(2);
        //alert(FVal);
        eval(FVal);
        return;
    }

    // If parameters are given open URL in customized window with these parameters.
    if (targ.indexOf(";") > 0) {
        var WName=targ.substr(0,targ.indexOf(";"));
        var WParam=targ.substr(targ.indexOf(";")+1);
        // alert(WName + " - " + WParam);
        window.open(url, WName, WParam);
        return;
    }
    //alert(targ);
    // If no target is set or target is _self, load URL in actual browser window
    if(!targ || targ=="_self") location.href=url;
    // Start a new window. Size of window is defined by browser
    else if(targ=="_blank") window.open(url);
    // Load target in the first open window
    else if(targ=="_top" || targ=="window") top.location.href=url;
    // ??? here valid?
    else if(top[targ]) top[targ].location.href=url;
    // Test if parent of target
    else if(parent[targ]) parent[targ].location.href=url;
    else return false;
} // end of function sM_link


// Create menu from array
function sM_create(m)
{
    var oldcat=null;
    var lastai=0;
    JSM_nspadfix=(JSM_Border*2) + (JSM_Padding*2);
    JSM_xnew=JSM_sx;
    JSM_ynew=JSM_ysub=JSM_sy;
    JSM_headw=(JSM_isHeadFixed)?JSM_sw:0;
    if(JSM_isJunk) return errMsg("Uncompatible Client for this Script!");

    // Go through all menu elements
    for (var i=0;i<m.length;i++)
    {
        var isbar=(m[i][1]=="-----")? 1:0;
        // Set text of linebar for NS 4 to NSLIneBar, else to given expression + nbsp
        m[i][1]=(isbar && JSM_ns4)? JSM_NSlinebar :(isbar)? JSM_linebar: m[i][1]+"&nbsp;";

        var objid="M_"+ (i+JSM_lid);
        // If not given set link to empty
        if (!m[i][2]) m[i][2] = "";
        // If not given set target to empty
        if (!m[i][3]) m[i][3] = "";

        // If not given set Class to default class of type
        if (!m[i][4])
        {
            if (m[i][0]==0) m[i][4] = JSM_HeadClass;
            else if (m[i][0]==1) m[i][4] = JSM_MenuClass;
            else if (m[i][0]==2) m[i][4] = JSM_SubMenuClass;
            else m[i][4] = JSM_DefaultClass;
        }

        // If not given set height to default; add space for ns6
        if (!m[i][5]) m[i][5] = JSM_sh;
        if (!JSM_ns6) m[i][5] += JSM_nspadfix;

        // If not given set Menu Icon to default
        if (!m[i][7]) m[i][7] = JSM_DefaultIcon;
        // put in image if set
        if (!isbar&& JSM_UseIcons && m[i][7])
        m[i][1] = "<img src='"+JSM_IconPath+"/"+m[i][7]+"' border='0' align='left'>"+ m[i][1];
        // set background hover color depending on element type
        bgchover=(!m[i][0])?  JSM_MenuHead_BGColor_Hover  : (m[i][0]==1)?  JSM_Menu_BGColor_Hover : (m[i][0]==2)? JSM_MenuSub_BGColor_Hover : "";
        // set color for leaving element depending on element type
        bgchout=(!m[i][0])? JSM_MenuHead_BGColor_Normal : (m[i][0]==1)? JSM_Menu_BGColor_Normal : (m[i][0]==2)? JSM_MenuSub_BGColor_Normal : "";

        // for DOM browser append html to BODY
        //if (JSM_dom && JSM_DCE && JSM_DCTN)
        if(hasFullDom())
        {
            var obj=document.createElement("div");
            obj.id=objid;
            obj.style.visibility="hidden";
            obj.innerHTML=m[i][1] + ((Dbg) ? objid : "");
            document.getElementsByTagName("BODY")[0].appendChild(obj);
            //obj.appendChild(document.createTextNode(m[i][1]));
        } // end of dom/div browsers

        // NS4
        else if(JSM_ns4)
        {
            if (!m[i][0] && !JSM_isHeadFixed)
            {
                JSM_NSheadw=getNSDummyWidth(m[i][1],m[i][4]);
                owi=(JSM_NSheadw+JSM_hPadding);
            }
            else
            {
                owi=JSM_sw;
            }

            if (JSM_subimg && m[i+1] && m[i][0]==1 && m[i+1][0]==2)
            {
                owi-=3;
                m[i][1]= "<img src='"+JSM_subimg+"' border='0' align='right'>"+m[i][1];
            }
            out="";
            out+="<layer name='"+objid+"' width='"+owi+"' height='"+m[i][5]+"' visibility='hide' bgcolor='"+bgchout+"' class='"+JSM_SimpleClass+"'>";
            out+="<layer top='"+JSM_Padding+"' left='"+JSM_Padding+"'>"+m[i][1]+"</layer>";
            out+="<layer width='100%' height='100%'></layer>";
            out+="</layer>";
            document.write(out+"\n");
            obj=document.layers[objid];
            obj.captureEvents( Event.MOUSEOVER | Event.MOUSEOUT | Event.CLICK | Event.MOUSEUP );
            obj.style=obj;
        } // end of NS4
        // other browser, e.g. IE4 & 5, opera < 7...
        else
        {
            out="<div id='"+objid+"' class='"+m[i][4]+"'>"+m[i][1]+"</div>";
            document.write(out);
            obj=(JSM_ie4)? document.all[objid]: eval("document."+objid);
        } // end of other browser, e.g. IE 4??

        // Create eventhandler for over, out as function in attribute
        obj.onmouseover=new Function("sM_hover(this,'" + m[i][4] + "'," + isbar + ",'" + bgchover + "')");
        obj.onmouseout=new Function("sM_hout(this,'"+ m[i][4] +"',"+isbar+",'"+bgchout+"')");

        // Mouse pointer for active/inactive elements
        if (m[i][2] && m[i][4]!=JSM_InactiveClass)
        {
            obj.onmouseup=new Function("sM_link('"+ m[i][2] +"','"+ m[i][3] +"')");
            obj.style.cursor=(JSM_ie4)? "hand" : "pointer";
        }
        else {
            obj.style.cursor="default";
        }
        // Set link as tooltip (title)
        if (JSM_LinkAsTitle && m[i][2]) obj.title=m[i][2];
        // Set style attributes
        obj.style.position="absolute";

        // Set border for MenuHead
        if (m[i][0]==0) {
            if (JSM_MenuHeadBorder!="") { // Suppress MenuHead border if color not defined
                obj.style.border=JSM_Border+"px solid "+JSM_MenuHeadBorder;
            }
        }
        else { // Set border for other elements
            obj.style.border=JSM_Border+"px solid "+JSM_BorderColor;
        }

        obj.style.padding=JSM_Padding+"px "+JSM_Padding+"px "+JSM_Padding+"px "+JSM_Padding+"px ";
        if (m[i][4])obj.className=m[i][4];
        cal(m,i,JSM_lid); // Calc x/y positions
        awidth=(JSM_ie)?  obj.clientWidth :(!JSM_ie && JSM_dom)?  obj.offsetWidth : JSM_sw;

        if (!m[i][0] && !JSM_isHeadFixed){
            JSM_headw=(JSM_ns4)? JSM_NSheadw : awidth;
        }
        if (JSM_subimg && m[i+1] && m[i][0]==1 && m[i+1][0]==2){
            m[i][1]= "<img src='"+JSM_subimg+"' border='0' align='right'>"+m[i][1];
            if (JSM_dom) obj.innerHTML=m[i][1];
            awidth+=JSM_subimgwidth;
        }

        obj.style.left=(JSM_ns4)?JSM_xnew:JSM_xnew+'px';
        obj.style.top=(JSM_ns4)?JSM_ynew:JSM_ynew+'px';
        obj.style.overflow="hidden";
        if(JSM_isOpaque && JSM_ie) obj.style.filter="alpha(opacity="+JSM_OpaqueValue+")";
        if(JSM_isOpaque && JSM_ns6) obj.style.MozOpacity=JSM_OpaqueValue/100;
        // Set initial visibility for Head elements to true, else false
        obj.style.visibility=(m[i][0])?"hidden":"visible";
        obj.style.width=(!m[i][0] && !JSM_isHeadFixed)?(JSM_headw+JSM_hPadding):(JSM_isAutoWidthMenu)? awidth : JSM_sw;
        obj.style.height=m[i][5];
        obj.style.zIndex=JSM_cat + 10;
        if (JSM_isAutoWidthMenu) aWCheck(JSM_cat, awidth);

        if(needsIe6Fix()) ieMenuFix(objid, obj);
    } // end of for each array element

    JSM_lid+=i;
    // alert("idmaster: "+JSM_idmaster+"\nidsub: "+JSM_idsub+"\nidpool: "+JSM_idpool);
    if (JSM_dom && JSM_isAutoWidthMenu) REPositionElements();
} // function sM_create(m)

function ieMenuFix(objId, obj)
{
    // fix for ie 6
    var obj2=document.createElement("iframe");
    obj2.src="static/images/icons/empty.gif";
    obj2.id=objId + "XX";
    obj2.style.visibility="hidden";
    document.getElementsByTagName("BODY")[0].appendChild(obj2);
    obj2.style.position=obj.style.position;
    //obj2.style.padding=obj.style.padding;
    obj2.style.left=obj.style.left;
    obj2.style.top=obj.style.top;
    obj2.style.overflow=obj.style.overflow;
    if(JSM_isOpaque && JSM_ie) obj2.style.filter=obj.style.filter;
    // Set initial visibility for Head elements to true, else false
    obj2.style.visibility="hidden";
    obj2.style.width=obj.style.width;
    obj2.style.height=obj.style.height;
    obj2.style.zIndex=obj.style.zIndex - 1;
}


// Set width of a submenu/menu to
// (Category, actual width)
function aWCheck(c,w) {
    aifound=-1;
    // Go through array of element "groups"
    for (ai=0;ai<JSM_awidthpool.length;ai++) {
        io=JSM_awidthpool[ai].split("_")[0];
        no=JSM_awidthpool[ai].split("_")[1];
        if (io == c) aifound=ai;
    }

    if (aifound >-1) {
        io=JSM_awidthpool[aifound].split("_")[0];
        no=JSM_awidthpool[aifound].split("_")[1];
        // if ( w > JSM_sw ) w=JSM_sw;
        if ( no < w && w < JSM_sw * 3) JSM_awidthpool[aifound]=io+"_"+w;
    }
    // Add element "group" to array
    else {
        JSM_awidthpool.push(c+"_"+w);
    }
}

function REPositionElements() {
    //alert(JSM_awidthpool);
    for (ai=0;ai<JSM_awidthpool.length;ai++) {
        ac=JSM_awidthpool[ai].split("_")[0];
        aw=JSM_awidthpool[ai].split("_")[1];
        //aw=parseInt(aw) + 20;
        for (i=0;i<JSM_idpool.length;i++) {
            ic=JSM_idpool[i].split("_")[0];
            ino=JSM_idpool[i].split("_")[1];
            if (ic == ac) {
                //alert("Object: M_"+ino+" :: "+aw);
                getObj("M_"+ino).style.width=aw;
            }
        }
    }
    for (si=0;si<JSM_idsub.length;si++) {
        sii=JSM_idsub[si]+1;
        for (i=0;i<JSM_idpool.length;i++) {
            ic=JSM_idpool[i].split("_")[0];
            ino=JSM_idpool[i].split("_")[1];
            if (ic == sii) {
                hs=parseInt(getObj("M_"+JSM_idsub[si]).style.left);
                hw=parseInt(getObj("M_"+JSM_idsub[si]).style.width);
                hp=(JSM_ns6)? JSM_nspadfix : 0;
                getObj("M_"+ino).style.left=hs+hw+hp+JSM_Space+JSM_subx;
            }
        }
    }
}

function getNSDummyWidth(txt,cla){
    JSM_dummyCnt+=1;
    document.write(  "<layer name='DummyNS_" + JSM_dummyCnt
                   + "' class='" + cla
                   + "' visibility='hide'>"
                   + txt + "&nbsp;</layer>\n");

    dum=document.layers["DummyNS_" + JSM_dummyCnt];
    // alert(dum.clip.width);
    return dum.clip.width;
}

function getObj(id){
    if (JSM_dom) return document.getElementById(id);
    if (JSM_ie4) return document.all[id];
    if (JSM_ns4) return document.layers[id];
    return null;
}

function errMsg(txt) {
    var info="Document Object Model: ("+JSM_dom
    +")\nCreate Element: ("+ JSM_DCE
    +")\nCreate Text Node: ("+ JSM_DCTN
    +")"
    +"\n\nClient: "+navigator.appName+"/"+JSM_ver;
    alert("Error: "+txt+"\n\n");
    return false;
}


//
// Psevdo-API  functions
// -------------------------------------------

function getMenuID(name){
    for(i=0;i<JSM_fapi.length;i++){
        if(JSM_fapi[i][6]==name) return i;
    }
    return -1;
}

// addMenuHead("admin","Administration","#","_self","",0, "punkt.gif");
function addMenuHead(name, txt, lin, tar, cla, hei, ico) {
    JSM_lastHeadID=0;
    return JSM_fapi.push([0, txt, lin, tar, cla, hei, name, ico]);
}

//  addMenu("subscr","Subscribe","#2","_NewFr","class1", 0, "checked.gif");
function addMenu(name, txt, lin, tar, cla, hei, ico) {
    JSM_lastHeadID=1;
    return JSM_fapi.push([1, txt, lin, tar, cla, hei, name, ico]);
}

// addSubMenu("airfreight","Airfreight","#","_self","MSub", 0, "abc.gif");
function addSubMenu(name, txt, lin, tar, cla, hei, ico) {
    JSM_lastHeadID=2;
    return JSM_fapi.push([2, txt, lin, tar, cla, hei, name, ico]);
}

// Set a menu bar in menu/submenu. Parameters: class, InMenu
// The parameter InMenu is logical; it will bring the bar on menu level
function addMenuBar(cla, MenuLevel){
    if (MenuLevel) JSM_lastHeadID = MenuLevel;
    if (!cla) cla=JSM_DefaultClass;
    if (JSM_lastHeadID) {
        if (JSM_lastHeadID==1) cla=JSM_MenuClass;
        if (JSM_lastHeadID==2) cla=JSM_SubMenuClass;
        JSM_fapi.push([JSM_lastHeadID, "-----","","",cla]);
    }
}


function setMenuText(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][1]=value;
    }else{
        alert("ID: "+name+" not found!\nText not set.");
    }
}
function setMenuLink(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][2]=value;
    }else{
        alert("ID: "+name+" not found!\nLink not set.");
    }
}
function setMenuTarget(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][3]=value;
    }else{
        alert("ID: "+name+" not found!\nLink Target not set.");
    }
}
function setMenuClass(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][4]=value;
    }else{
        alert("ID: "+name+" not found!\nClass not set.");
    }
}
function setMenuInactive(name){
    id=getMenuID(name);
    if (!JSM_InactiveClass) alert("Variable: [JSM_InactiveClass] not set!\nTake a look in configuration section.");
    if (id > -1) {
        JSM_fapi[id][4]=JSM_InactiveClass;
    }else{
        alert("ID: "+name+" not found!\nInactive Class not set.");
    }
}
function setMenuHeight(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][5]=value;
    }else{
        alert("ID: "+name+" not found!\nHeight not set.");
    }
}


function setMenuIcon(name,value){
    id=getMenuID(name);
    if (id > -1) {
        JSM_fapi[id][7]=value;
    }else{
        alert("ID: "+name+" not found!\nIcon not set.");
    }
}

// Realize the menu
function createMenu(){
    return sM_create(JSM_fapi);
}