/*****************************************************
* Name        : opmb.js
* Author      : Richard Powell <rpowell@opriver.com>
* Date        : 31-Mar-2003
* Version     : 0.9.5
* Web Site    : http://www.opriver.com/
* Description : This Navigation Menu Bar was designed
*   for the purpose of providing a plug and play menu
*   bar system for our customers.  As the open-source
*   community has given so much to the advancement of
*   my personal knowledge/career, I'm giving back. :)
*
* License     : You are free to use and modify this
*               code all you want, so long as this
*               original text appears at the top.
*
* WARNING     : This code is provided AS-IS and
*               with NO WARRANTY WHAT SOEVER.
*
*               ***** USE AT YOUR OWN RISK *****
*
*****************************************************/

//**************************************************
//**   Primary Menu Bar Object/Class [opmb]
//**************************************************
function toolbar(barname,top,left,lname) {
    this.bn      = barname;
    this.top     = top;
    this.left    = left;
    this.lname   = lname;
    this.moff    = 0;
    this.subicon = "";
    //this.subicon = " >";
    this.buffer  = 0                       // Right offset for submenus

    this.height = 28;						// Menu Item Height
    this.width  = 125;						// Menu Item Default Width
    this.border = 0;						// Menu Item Border
    this.bc     = "#00529B"; 			    // Menu Background Color
    this.tc     = "#ffffff"; 			    // Menu Text/Font Color
    this.boc    = ""; 			    // Menu Background MouseOver Color
    this.toc    = "#bcd000"; 			    // Menu Text/Font MouseOver Color
    this.bgi    = "../Images/Buttons/Backup/Unselected.png"; 					// Menu Background Image URL
    this.bgoi   = "../Images/Buttons/Backup/GreenHouse.png"; 					// Menu Background MouseOver Image URL
    this.img    = "";						// Menu Image (Not Realistic in Global Scope)
    this.imgo   = "";						// Menu MouseOver Image (Not Realistic in Global Scope)
    this.ff     = "verdana,arial,helvetica,sans-serif";	// Menu Font Family
    this.fs     = 12;						// Menu Font Size
    this.fw		= "bold";						// Menu Font Weight
    this.bt     = 0;						// Menu Border Top
    this.bta    = "solid #DDDDDD";			// Menu Border Top Attributes
    this.bl     = 0;						// Menu Border Left
    this.bla    = "solid #DDDDDD";			// Menu Border Left Attributes
    this.bb     = 0;						// Menu Border Bottom
    this.bba    = "solid #DDDDDD";			// Menu Border Bottom Attributes
    this.br     = 0;						// Menu Border Right
    this.bra    = "solid #DDDDDD";			// Menu Border Right Attributes
    this.pad	= 0;						// Menu Item Padding
	
    //**************************************************
    //**   Create Menu Items Here
    //**************************************************

    this.item = function(itemname,itemtext,itemurl,width) {

	// Item name form m_#_#_# (m_#)
	//                m_(Menu#_MenuSub#_MenuSub#)

	// Create our new menu item/object

	eval ( 'this.' + itemname + '=new Object()' );
	eval ( 'this.' + itemname + '.text="' + itemtext + '"' );
	eval ( 'this.' + itemname + '.url="'  + itemurl  + '"' );
	eval ( 'this.' + itemname + '.width="'+ width    + '"' );
	
	var nary = itemname.split("_");
	var nt   = "";				// Variable Menu Name

	// Get Default LEFT Value

	var il   = this.left;			// Left Margin
	i = nary.length-1;
	j = parseInt(nary[i]);

	// i = Last Menu Item (1 for menu, 2 for 1st sub menu, 3 for 2nd sub menu)
	// j = Count of last menu item

	if ((i==2)&&(j==1)) {			// Get from Menu Above Us - first submenu item for any menu item
	   nt = "";
	   for (k=0;k<i;k++) {
		if (k>0) nt += "_";
		nt += nary[k];
	   }
	   il = eval('this.'+nt+'.left')+this.buffer;
	} else if ((j>1)&&((i)>1)) {		// Get Left Margin from item above us.
	   nt = "";
	   for (k=0;k<i;k++) {
		if (k>0) nt += "_";
		nt += nary[k];
	   }
	   nt += "_" + (j-1).toString();
	   il  = eval('this.' + nt + '.left' );
	} else if ((i==1)&&(j>1)) {		// Get Left Margin from item to left of us.
	    nt = "";
	    for (k=0;k<i;k++) {
		if (k>0) nt += "_";
		nt += nary[k];
	    }
	    nt += "_" + (j-1).toString();
	    il	= eval('this.' + nt + '.left');
	    il += eval('this.' + nt + '.width');
	} else if ((i)>1) {			// Get Left Margin from item to left of us.
	    nt = "";
	    for (k=0;k<i;k++) {
		if (k>0) nt += "_";
		nt += nary[k];
	    }
	    il  = eval('this.' + nt + '.left' );
	    il += eval('this.' + nt + '.width');
	}

	// Get Default TOP Value

	var it   = this.top;
	var tt   = parseInt(nary[nary.length-1]);

	if ((tt>1)&&((nary.length)<3)) {
	    if ((nary.length-2)<=0) nt = "m";
	    else nt = "";
	    for (i=0;i<nary.length-2;i++) {
		if (i>0) nt += "_";
		nt += nary[i];
	    }
	    nt += "_" + eval(tt-1);
	    it  = eval ( 'this.' + nt + '.top' );
	} else if (tt>1) {
	    i = nary.length-1;
	    if (i>=1) {
		nt = "";
		for (j=0;j<i;j++) {
		    if (j>0) nt += "_";
		    nt += nary[j];
		}
		nt += "_" + (parseInt(nary[j])-1).toString();
		it  = eval('this.'+nt+'.top');
		it += eval('this.'+nt+'.height');
		//if (document.layers) it = it + eval('this.'+nt+ '.pad');
	    }
	} else {
	    i = nary.length-2;
	    if (i>=1) {
		nt = "";
		for (j=0;j<=i;j++) {
		    if (j>0) nt += "_";
		    nt += nary[j];
		}
		it  = eval ( 'this.' + nt + '.top' );
		if ((nary.length)<4) it += eval ( 'this.' + nt + '.height' );
		//if (document.layers) it = it + eval('this.'+nt+ '.pad');
	    }
	}

	if (document.layers) {
	    if ((nary.length)>2) {	// Going By Previous Reference... Which One?
		var ts   = parseInt(nary[nary.length-1]);
		if ((ts>1)||(nary.length==3)) {
		    it = it + (eval('this.'+nt+'.border')*2);
		}
	    }
	}

	eval ( 'this.' + itemname + '.left=' + il );		// Menu Left
	eval ( 'this.' + itemname + '.top=' + it );		// Menu Top
	eval ( 'this.' + itemname + '.height=this.height');
	eval ( 'this.' + itemname + '.width=width');
	eval ( 'this.' + itemname + '.bc=this.bc');
	eval ( 'this.' + itemname + '.tc=this.tc');
	eval ( 'this.' + itemname + '.boc=this.boc');
	eval ( 'this.' + itemname + '.toc=this.toc');
	eval ( 'this.' + itemname + '.bgi=this.bgi');
	eval ( 'this.' + itemname + '.bgoi=this.bgoi');
	eval ( 'this.' + itemname + '.img=this.img');
	eval ( 'this.' + itemname + '.imgo=this.imgo');
	eval ( 'this.' + itemname + '.border=this.border');
	eval ( 'this.' + itemname + '.ff=this.ff');
	eval ( 'this.' + itemname + '.fs=this.fs');
	eval ( 'this.' + itemname + '.fw=this.fw');
	eval ( 'this.' + itemname + '.bt=this.bt');
	eval ( 'this.' + itemname + '.bta=this.bta');
	eval ( 'this.' + itemname + '.bl=this.bl');
	eval ( 'this.' + itemname + '.bla=this.bla');
	eval ( 'this.' + itemname + '.bb=this.bb');
	eval ( 'this.' + itemname + '.bba=this.bba');
	eval ( 'this.' + itemname + '.br=this.br');
	eval ( 'this.' + itemname + '.bra=this.bra');
	eval ( 'this.' + itemname + '.pad=this.pad');
    };

    this.mouseOnS = function(stxt,txt) {
	var mt    = "";
	var tm    = "";
	var i     = 0;
	var j     = 0;
	var nry   = txt.split("_");
	var nryS;
	var tmp;
	var tmq;
	var ishow = 0;

	for (i=1;(eval('this.'+stxt+'_'+i));i++) {
	    // Test if should be visible?
	    mt   = stxt + "_" + i.toString();
	    nryS = mt.split("_");
	    ishow = 0;
	    if (parseInt(nry[1]) != parseInt(nryS[1])) {	// Hide the layer
		ishow = 0;
	    } else {
		if (nryS.length<nry.length) {	// Compare ALL text in Sub String nry
//		    if (parseInt(nry[1]) == parseInt(nryS[1])) ishow = 1;
		    ishow = 1;
		    for (j=1;j<(nryS.length-1);j++) {
//			alert("comparing ["+parseInt(nry[j])+"] to ["+parseInt(nryS[j])+"]");
			if (parseInt(nry[j]) != parseInt(nryS[j])) ishow = 0;
		    }
		} else if (nryS.length==nry.length) {	// Compare ALL but LAST
		    tmp = txt.substring(0,txt.length-(nry[nry.length-1].length)-1);
		    tmq = mt.substring(0,mt.length-(nryS[nryS.length-1].length)-1);
		    if (tmq==tmp) ishow = 1;
		} else if (nryS.length==(nry.length+1)) {	// Compare ALL but LAST
		    tmp = mt.substring(0,mt.length-(nryS[nryS.length-1].length)-1);
		    if (tmp==txt) ishow = 1;
		} else ishow = 0;				// Hide this layer
	    }
	    if (document.layers) {
		if (ishow) {
		    eval('document.layers["'+this.bn+'"].document.layers["'+mt+'"].visibility="show"');
		} else {
		    eval('document.layers["'+this.bn+'"].document.layers["'+mt+'"].visibility="hide"');
		}
	    } else {
		tm = this.bn + mt;
		if (ishow) {
		    document.getElementById(tm).style.visibility = "visible";
		} else {
		    document.getElementById(tm).style.visibility = "hidden";
		}
	    }
	    if (eval('this.'+mt+'_1')) this.mouseOnS(mt,txt);
	}

    };

    this.mouseOn = function(txt) {
        var mt = "";
        var i = 0;
        this.moff = 0;
        var tmp;

        //alert(txt);
        //tmp = eval('this.'+txt);

        if (document.layers) {
            if (eval('this.' + txt + '.bgi.length') < 1) {
                eval('document.layers["' + this.bn + '"].document.layers["' + txt + '"].bgColor=this.' + txt + '.boc');
                eval('document.layers["' + this.bn + '"].document.layers["' + txt + '"].fgColor=this.' + txt + '.toc');
            } else {
                tmp = eval('this.' + txt + '.bgoi');
                eval('document.layers["' + this.bn + '"].document.layers["' + txt + '"].background.src="' + tmp + '"');
            }
            if (eval('this.' + txt + '.img.length') > 0) {
                tmp = eval('this.' + txt + '.imgo');
                eval('document.layers["' + this.bn + '"].document.layers["' + txt + '"].document.images.' + txt + 'i.src="' + tmp + '"');
            }
        } else {
            //alert("Setting Color ["+txt+"]");
            if (eval('this.' + txt + '.bgi.length') < 1) {
                eval('document.getElementById("' + eval('this.bn') + txt + '").style.backgroundColor=this.' + txt + '.boc');
                eval('document.getElementById("' + eval('this.bn') + txt + '").style.color=this.' + txt + '.toc');
            } else {
                tmp = eval('this.' + txt + '.bgoi');
                eval('document.getElementById("' + eval('this.bn') + txt + '").style.background=\'url(' + tmp + ')\'');
                eval('document.getElementById("' + eval('this.bn') + txt + '").style.color=this.' + txt + '.toc');
            }
            if (eval('this.' + txt + '.img.length') > 0) {
                tmp = eval('this.' + txt + '.imgo');
                eval('document.getElementById("' + eval('this.bn') + txt + 'i").src="' + tmp + '"');
            }
        }

        for (i = 1; (eval('this.m_' + i)); i++) {
            //mt   = this.bn + "m_" + i.toString();
            //alert('checking ['+mt+']');
            mt = "m_" + i.toString();
            if (eval('this.' + mt + '_1')) this.mouseOnS(mt, txt);
        }
    };

    this.mouseOffS = function(stxt) {
	var tm    = "";
	var mt    = "";
	var i     = 0;
	var nryS;
	var tmp;
	var tmq;
	var ishow = 0;

	for (i=1;(eval('this.'+stxt+'_'+i));i++) {
	    mt   = stxt + "_" + i.toString();

//	    alert('checking ['+mt+']');

	    if (document.layers) {
		eval('document.layers["'+this.bn+'"].document.layers["'+mt+'"].visibility="hide"');
	    } else {
		tm = this.bn + mt;
		document.getElementById(tm).style.visibility = "hidden";
	    }

	    if (eval('this.'+mt+'_1')) this.mouseOffS(mt);
	}
    };

    this.mouseOff = function() {
	if (!(this.moff)) return;
	var i  = 0;
	var mt = "";
	//var tm = "";
	for (i=1;(eval('this.m_'+i));i++) {
	    mt = "m_" + i.toString();
	    //tm = this.bn + mt;
	    if (eval('this.'+mt+'_1')) this.mouseOffS(mt);
	}
    };

    this.mouseOffC = function(txt) {
	var tmp;

//	eval('document.getElementById("'+txt+'").style.backgroundColor=this.'+txt+'.boc');
	if (document.layers) {
	    if (eval('this.'+txt+'.bgi.length')<1) {
		eval('document.layers["'+this.bn+'"].document.layers["'+txt+'"].bgColor=this.'+txt+'.bc');
		eval('document.layers["' + this.bn + '"].document.layers["' + txt + '"].Color=this.' + txt + '.tc');
	    } else {
		tmp = eval('this.'+txt+'.bgi');
		eval('document.layers["'+this.bn+'"].document.layers["'+txt+'"].background.src="'+tmp+'"');
	    }
	    if (eval('this.'+txt+'.img.length')>0) {
		tmp = eval('this.'+txt+'.img');
		eval('document.layers["'+this.bn+'"].document.layers["'+txt+'"].document.images.'+txt+'i.src="'+tmp+'"');
	    }
	} else {
	    if (eval('this.'+txt+'.bgi.length')<1) {
		eval('document.getElementById("'+eval('this.bn')+txt+'").style.backgroundColor=this.'+txt+'.bc');
		eval('document.getElementById("' + eval('this.bn') + txt + '").style.color=this.' + txt + '.tc');
	    } else {
		tmp = eval('this.'+txt+'.bgi');
		eval('document.getElementById("'+eval('this.bn')+txt+'").style.background=\'url('+tmp+')\'');
		eval('document.getElementById("'+eval('this.bn')+txt+'").style.color=this.'+txt+'.tc');
	    }
	    if (eval('this.'+txt+'.img.length')>0) {
		tmp = eval('this.'+txt+'.img');
		eval('document.getElementById("'+eval('this.bn')+txt+'i").src="'+tmp+'"');
	    }
	}
    }

    //**************************************************
    //**   Load a menu/div into variable
    //**************************************************

    this.menuAppend = function(tx, sub) {
        var ot = "";
        var iz = 0;
        var tmp;
        var itp = 0;

        if (document.layers) {
            ot += "<layer name=\"" + tx + "\" left=\" " + eval('this.' + tx + '.left');
            ot += "\" top=\"" + eval('this.' + tx + '.top') + "\"";
            ot += " style=\"cursor:pointer;\"";
            if (eval('this.' + tx + '.bgi.length') > 0) {
                ot += " background=\"" + eval('this.' + tx + '.bgi') + "\"";
            }
            ot += " bgcolor=\"" + eval('this.' + tx + '.bc');
            ot += " vertical-align=\"middle\"";
            ot += "\" width=\"" + eval('this.' + tx + '.width') + "\" height=\"" + eval('this.' + tx + '.height');
            if (sub) ot += "\" visibility=\"hide\" ";
            else ot += "\" visibility=\"show\" ";
            ot += "onFocus=\"window.location.href='" + eval('this.' + tx + '.url') + "'\" ";
            ot += "onMouseover=\"" + this.lname + ".mouseOn(\'" + tx + "\');\" onMouseout=\"" + this.lname + ".moff=1;";
            ot += this.lname + ".mouseOffC('" + tx + "');setTimeout('" + this.lname + ".mouseOff()',1000);\"";
            ot += "\">";
            ot += "<table id=\"" + tx + "t\" width=100% border=\"" + eval('this.' + tx + '.border/2');
            ot += "\"";
            ot += "><tr><td>";
            if (eval('this.' + tx + '.img.length') > 0) {
                ot += "<img name=\"" + tx + "i\" border=0 src=\"" + eval('this.' + tx + '.img') + "\">";
            } else {
                //ot += "<a href=\"javascript:void(0)\" style=\"text-decoration:none\">";
                ot += eval('this.' + tx + '.text');
                if ((sub) && (eval('this.' + tx + '_1'))) ot += this.subicon;
                //ot += "</a>";
            }
            ot += "</td></tr></table>";
            ot += "</layer>\n";
        } else {
            ot += "<div id=\"" + eval('this.bn') + tx + "\" style=\"position:absolute; top:" + eval('this.' + tx + '.top') + "px; ";
            ot += "left:" + eval('this.' + tx + '.left') + "px; ";
            ot += "vertical-align: middle; ";
            if (parseInt(navigator.appVersion) >= 5 && navigator.appName == "Netscape") {
                //tmp = eval('this.'+tx+'.height');
                //itp = parseInt(tmp) - (parseInt(eval('this.'+tx+'.border'))*2) - 4;
                itp = parseInt(eval('this.' + tx + '.height')) - parseInt(eval('this.' + tx + '.bt'));
                itp = itp - parseInt(eval('this.' + tx + '.bb')) - (parseInt(eval('this.' + tx + '.pad')) * 2);
                ot += "height:" + itp.toString() + "px; ";
            } else ot += "height:" + eval('this.' + tx + '.height') + "px; ";
            if (parseInt(navigator.appVersion) >= 5 && navigator.appName == "Netscape") {
                //tmp = eval('this.'+tx+'.width');
                //itp = parseInt(tmp) - 6;
                itp = parseInt(eval('this.' + tx + '.width')) - parseInt(eval('this.' + tx + '.bl'));
                itp = itp - parseInt(eval('this.' + tx + '.br')) - (parseInt(eval('this.' + tx + '.pad')) * 2);
                ot += "width:" + itp.toString() + "px; ";
            } else ot += "width:" + eval('this.' + tx + '.width') + "px; ";
            if (sub) ot += "visibility:hidden; ";
            else ot += "visibility:visible; ";
            ot += "color:" + eval('this.' + tx + '.tc') + "; ";
            if (eval('this.' + tx + '.ff.length') > 0) ot += "font-family:" + eval('this.' + tx + '.ff') + "; ";
            if (eval('this.' + tx + '.fs') > 0) ot += "font-size:" + eval('this.' + tx + '.fs') + "px; ";
            if (eval('this.' + tx + '.fw.length') > 0) ot += "font-weight:" + eval('this.' + tx + '.fw') + "; ";
            if (eval('this.' + tx + '.bt') > 0) {
                ot += "border-top:" + eval('this.' + tx + '.bt') + "px";
                if (eval('this.' + tx + '.bta.length') > 0) ot += " " + eval('this.' + tx + '.bta');
                ot += "; ";
            }
            if (eval('this.' + tx + '.bl') > 0) {
                ot += "border-left:" + eval('this.' + tx + '.bl') + "px";
                if (eval('this.' + tx + '.bla.length') > 0) ot += " " + eval('this.' + tx + '.bla');
                ot += "; ";
            }
            if (eval('this.' + tx + '.bb') > 0) {
                ot += "border-bottom:" + eval('this.' + tx + '.bb') + "px";
                if (eval('this.' + tx + '.bba.length') > 0) ot += " " + eval('this.' + tx + '.bba');
                ot += "; ";
            }
            if (eval('this.' + tx + '.br') > 0) {
                ot += "border-right:" + eval('this.' + tx + '.br') + "px";
                if (eval('this.' + tx + '.bra.length') > 0) ot += " " + eval('this.' + tx + '.bra');
                ot += "; ";
            }
            if (eval('this.' + tx + '.pad') > 0) ot += "padding:" + eval('this.' + tx + '.pad') + "px; ";
            if (eval('this.' + tx + '.bgi.length') < 1) {
                ot += "background-color:" + eval('this.' + tx + '.bc') + "; ";
            } else ot += "background-image: url(" + eval('this.' + tx + '.bgi') + "); ";
            ot += "cursor:pointer;cursor:hand;\" ";
            if (parseInt(navigator.appVersion) >= 5 && navigator.appName == "Netscape")
                ot += " onClick=\"window.location.href='" + eval('this.' + tx + '.url') + "'\"";
            else ot += " onClick=\"location.href('" + eval('this.' + tx + '.url') + "')\"";
            ot += " onMouseover=\"" + this.lname + ".mouseOn(\'" + tx + "\');\"";
            ot += " onMouseout=\"" + this.lname + ".moff=1;";
            ot += this.lname + ".mouseOffC('" + tx + "');setTimeout('" + this.lname + ".mouseOff()',1000);\"";
            ot += ">";

            if (eval('this.' + tx + '.img.length') > 0) {
                ot += "<img id=\"" + eval('this.bn') + tx + "i\" border=0 src=\"" + eval('this.' + tx + '.img') + "\">";
            } else {
                ot += eval('this.' + tx + '.text');
                if (eval('this.' + tx + '_1')) ot += this.subicon;
            }

            ot += "</div>\n";
        }
        return ot;
    };

    //**************************************************
    //**   Load a sub-menu/div into a variable
    //**************************************************

    this.subMenuAppend = function(txt) {
	var otmp = "";
	var iz   = 0;
	for (iz=1;(eval('this.'+txt+'_'+iz.toString()));iz++) {	// Loop through this sub-menu
	    mtx = txt + '_' + iz.toString();
	    otmp += this.menuAppend(mtx,1);

	    if (eval('this.'+mtx+'_1')) otmp += this.subMenuAppend(mtx);
	}
	return otmp;
    }

    //**************************************************
    //**   Load the menu bar into the DIV/Layer
    //**************************************************

    this.load = function() {
	var ot  = "";
	var mt  = "";
	var i   = 0;
	for (i=1;(eval('this.m_'+i));i++) {
	    mt  = "m_" + i.toString();
	    ot += this.menuAppend(mt,0);

	    //**************************************************
	    //**   Loop through all sub-menus here.
	    //**************************************************

	    if (eval('this.'+mt+'_1')) {
		ot += this.subMenuAppend(mt);
	    }
	}

//	alert(ot);

	if (document.layers) {
	    var oLayer = eval('document.layers["' + this.bn + '"].document');
	    oLayer.open();
	    oLayer.write(ot);
	    oLayer.close();
	} else if (parseInt(navigator.appVersion)>=5&&navigator.appName=="Netscape") {
	    document.getElementById(this.bn).innerHTML = ot;
	} else if (document.all) {
	    document.getElementById(this.bn).innerHTML = ot;
	}

    };

};


