//<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
//<!--
// Universal Related Select Menus - v2.02 19991104
// (Dynamically-sized related menus using JS 1.1's new Option cmd)
// by Andrew King aking@internet.com & Michael Guitton saramaca@mail.dotcom.fr
// Copyright (c) 1999 internet.com Corp. All Rights Reserved.
// Originally published and documented at http://www.webreference.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Change History
//
// see http://www.webreference.com/dev/menus/ for prev code 
//
// ---- TOTAL REWRITE ENSUES HERE -----
// NB: The current script is inspired by the above work.
//     Yet the related menus aren't created the same way and
//     a couple of bugs have been squashed. 
//     I would advise you to refer to the original program
//     to get an idea of what is going on below. ;)
//
//     Michael Guitton
//     saramaca@mail.dotcom.fr
//
// Change History
//
// 27-Oct-1999 :: added support for frames -mg
// 08-Oct-1999 :: comments added, updated docs - abk
// 05-Oct-1999 :: ref() & relate() renamed, respectively, relate() & update()
//                for consistency w/ their respective behaviors - mg
// 04-Oct-1999 :: ref() is all you need (the icing on the cake ;)
//                relate() don't rely on get() anymore.
//                The current form index is fetched only once
//                See onChange handlers in HTML - mg 
// 30-Sep-1999 :: printItems() mod so won't stumble on null 1st lvl items - mg
// 29-Sep-1999 :: Added more comments - removed ie5 fix - abk
// 16-Sep-1999 :: relate() changed to be live with end branch
// 14-Sep-1999 :: ref() code rewritten from scratch. Tx Andy!
// 13-Sep-1999 :: New sindex() call checks for unselected parent menu option
// 09-Sep-1999 :: Technique extended to allow 2,3 or more levels with only 
//                one relate() function (a feature requested by Andy ;)
// 20-Jul-1999 :: IE4+ bug fix (Thanks Peter!)
// 23-Apr-1999 :: Use an entirely different method for menu setup
//                Array name isn't hardcoded in the relate() function, 
//                so several URPMs can be embedded in the same page
//                Fixed a couple of bugs

<!-- Begin: URPM Setup -->
var v = false;
var m = null;
var i = null;
// Set all menu trees to null to avoid any error in JavaScript 1.0 browsers -->

var urpm = self; // frame work-around
// urpm = parent.dummy; // Set the target to the relevant frame
// Comment out the above if you don't intend to use frames

function get(form)
{
   // loop thru document.forms property and exit w/ current form index
   var num = -1;
   for (var i = 0; i < document.forms.length; i++) {
      if (document.forms[i] == form) {
         num = i; // save form index
         break;
      }
   }
   return num; // returns current form index
}

function sindex(num, offset, elt)
{ 
   // sel finds selected index of num + offset's form elt's element
   // in this case elt is always 0, or first select menu in each form
   var sel = document.forms[ num + offset ].elements[elt].selectedIndex;
   if (sel < 0) sel = 0;
   return sel;
}

//function jmp(form, elt)
//{ // urpm.location added for optional navigation to named frames
//   if (form != null) {
//      with (form.elements[elt]) {
//         if (0 <= selectedIndex)
//            urpm.location = options[selectedIndex].value; // jump to selected option's value
//      }
//   }
//}

function update(num, elt, m)
{ // updates submenus - form(num)'s menu options, and all submenus
   // if refd form exists
//   var maxnumchar = 10; // is a global
   if (num != -1) {
      //num++; // reference next form, assume it follows in HTML
      with (document.forms[num].elements[elt]) {
         for (var i = options.length - 1; 0 < i; i--)
            options[i] = null; // null out options in reverse order (bug work-around)
         for (var i = 0; i < m.length; i++) {
		    var optionText = m[i].text;
			if (optionText.length > maxnumchar){
				optionText = optionText.substring(0,maxnumchar-1)+'...';
			}
			
			
            options[i] = new Option(optionText, m[i].value); // fill up next menu's items
         }  
         options[0].selected = true; // default to 1st menu item, windows bug kludge
      }
      if (m[0].length != 0) {
         update(num, elt, m[0]); // update subsequent form if any grandchild menu exists
      }
   }
}

function relate(form, elt, tree, depth)
{ // relate submenus based on sel of form - calls update to redef submenus
//   if (v) {
      var num = get(form); // fetch the current form index
      var a = tree;        // set a to be the tree array
      while (a != null && --depth != -1)
         // traverse menu tree until we reach the corresponding option record
         a = a[sindex(num, -depth, elt)];
      // at depth 3, should end up w/ something like a[i][j][k]
      // where each index holds the value of s(elected )index in related form select elts
      if (a != null && a.length) {
         // if a array exists and it has elements,
         // feed update() w/ this record reference
          var temp = elt + 1 //mwEdit
         update(num, temp, a); 
         return;
      }
//   }
   // if a hasn't any array elements or new Option unsupported then end up here ;)
//   jmp(form, elt); // make like a live popup
}

// Internet Explorer 4+ bug fix:
// IE4+ remembers the index of each SELECT but NOT the CONTENTS of each SELECT, 
// so it gets it wrong.
//
// Thanks to Peter Belesis (pbel@internet.com) for pointing this out.

function resetIE() {
   for (var i = 0; i < document.forms.length; i++) {
      document.forms[i].reset();
   }
}

if (document.all)
   window.onload = resetIE;
//-->
//</SCRIPT>

//<SCRIPT LANGUAGE="JavaScript1.1" TYPE="text/javascript">
//<!-- This script can also be referenced externally...

// Check if Option constructor is supported
if ((typeof(Option) + "") != "undefined") v = true;

// This constructor works equally well for 2D,3D and over
function O(text, value, submenu)
{
   this.text = text;
   this.value = value;
   this.length = 0;
   if (submenu != null) {
      // submenu is an array of options...
      for (var i = 0; i < submenu.length; ) {
         this[i] = submenu[i];
         this.length = ++i;
      }
   }
}
//-->
//</SCRIPT>