// set hidden/visible vars for Netscape 4 compatibility
if (document.layers) {
  var hidden = "hide";
  var visible = "show";
} else {
  var hidden = "hidden";
  var visible = "visible";
}
   

var smenu;
var dmenu;
var mmenubar;
var smenubar;
var dmenubar;
var pagetype;
var Omodel;
var Ooem;
var chartdesc;	



function setPageType( acttype ) {
  pagetype = acttype;
  if (pagetype == 'make') {
    Omodel  = getObj( 'fmodel' );
    Ooem    = getObj( 'foem' );}
}


function gotopage(fname, sname){
  var mname = document[fname][sname];
  var newpage = mname.options[mname.selectedIndex].value;
  if(newpage!=""){window.location.href = newpage;} }

function linkTo( linkRef ) {
  window.location.href = linkRef;
}


function menu0in( objBar, objMenu ) {
  mmenubar = getBar( objBar );
  mmenubar.bgColor = "#f8ab92";
  dmenu = getObj( objMenu );
  dmenu.visibility = visible;
  if (pagetype == 'make') {
    Omodel.visibility = hidden;
    Ooem.visibility = hidden; }
}

function menu0out() {
  mmenubar.bgColor = "#fbbe64";
  dmenu.visibility = hidden;
  if (pagetype == 'make') {
    Omodel.visibility = visible;
    Ooem.visibility = visible; }
}

function item0in( objBar ) {
  mmenubar = getBar( objBar );
  mmenubar.bgColor = "#f8ab92";
}

function item0out() {
  mmenubar.bgColor = "#fbbe64";
}

function menu1in() {
  mmenubar.bgColor = "#f8ab92";
  dmenu.visibility = visible;
  if (pagetype == 'make') {
    Omodel.visibility = hidden;
    Ooem.visibility = hidden; }
}

function menu1out() {
  mmenubar.bgColor = "#fbbe64";
  dmenu.visibility = hidden;
  if (pagetype == 'make') {
    Omodel.visibility = visible;
    Ooem.visibility = visible; }
}

function item1in( objBar, subMenu ) {
  dmenubar = getBar( objBar );
  dmenubar.bgColor = "#f8ab92";
  smenu = getObj( subMenu );
  smenu.visibility = visible;
}

function item1out() {
  dmenubar.bgColor = "#fbbe64";
  smenu.visibility = hidden;
}

function link1in( objBar ) {
  dmenubar = getBar( objBar );
  dmenubar.bgColor = "#f8ab92";
}

function link1out() {
  dmenubar.bgColor = "#fbbe64";
}



function menu2in() {
  mmenubar.bgColor = "#f8ab92";
  dmenubar.bgColor = "#f8ab92";
  dmenu.visibility = visible;
  smenu.visibility = visible;
  if (pagetype == 'make') {
    Omodel.visibility = hidden;
    Ooem.visibility = hidden; }
}

function menu2out() {
  mmenubar.bgColor = "#fbbe64";
  dmenubar.bgColor = "#fbbe64";
  dmenu.visibility = hidden;
  smenu.visibility = hidden;
  if (pagetype == 'make') {
    Omodel.visibility = visible;
    Ooem.visibility = visible; }
}

function item2in( objBar ) {
  smenubar = getBar( objBar );
  smenubar.bgColor = "#f8ab92";
}

function item2out() {
  smenubar.bgColor = "#fbbe64";
}


function showdesc( objDesc ) { 
  chartdesc = getObj( objDesc );
  chartdesc.visibility = visible;
}

function hidedesc() {
  chartdesc.visibility = hidden;
}



function getObj(id) {
/*
Takes the ID of a positioned HTML element and returns an object reference.
*/

  // This function checks for DOM strategy, then
  // returns an object reference.
//  if (document.all) {
    return document.all[id].style;
//  } else if(document.layers) {
//    return document.layers[id];
//  }
}



function getBar(id) {
/*
Takes the ID of a positioned HTML element and returns an object reference.
*/

  // This function checks for DOM strategy, then 
  // returns an object reference.
//  if (document.all) {
    return document.all[id];
//  } else if(document.layers) {
//    return document.layers[id];
//  }
}



function changeVisibility() {
  if (document.layers || document.all) {
    var inc, endInc=arguments.length;
    // run through the args (objects) and set the visibility of each
    for (inc=0; inc<endInc; inc+=2) {
      // get a good object reference
      var daObj = WM_checkIn(arguments[inc]);
      if (arguments[inc+1] == hidden) {
        // hide the object
        daObj.visibility = hidden;
      } else if (arguments[inc+1] == visible) {
        // show the object
        daObj.visibility = visible;
      } else if (arguments[inc+1] == toggle) {
        // toggle the object's visibility
        if (daObj.visibility == visible) {
          daObj.visibility = hidden;
        } else if (daObj.visibility == hidden) {
          daObj.visibility = visible;
        }
      }
    }
  }
}






function WM_checkIn(WM_id) { 

/*
WM_checkIn()
Takes the ID of a positioned HTML element and returns an object reference.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Taylor
Author Email: taylor@wired.com
Author URL: http://www.taylor.org/

Usage: WM_checkIn('id')
*/

  // First we initialize all the variables.
  var theObj,ss,sr,i,j,WM_layers=new Array();
  // This chunk handles the IE portion of the checkIn code.
  if (document.all) {
    // This checks to see if the inline style declaration has 
    // a position property associated with it. If not, it will 
    // scan the global stylesheets for the ID.
    if((document.all[WM_id].style.position != 'absolute') && (document.all[WM_id].style.position != 'relative')){
      // This little loop I'm very proud of, because it's kinda 
      // slick and I wrote it all myself. It loops through all 
      // global stylesheets and all the rules in each stylesheet, 
      // tests for the selected ID, then returns that as the object.
      for (ss=0 ; ss < document.styleSheets.length; ss++) {
        for (sr=0 ; sr < document.styleSheets(ss).rules.length; sr++) { 
          if (document.styleSheets(ss).rules(sr).selectorText == '#' + WM_id) {
            theObj = document.styleSheets(ss).rules(sr).style;
            break;
          }
        }
      }
    } else {
      // This works the same as in the light version, so you can 
      // use inline styles.
      theObj = document.all[WM_id].style;
    }
  } else if(document.layers) {
    // Now we're in Netscapeland. The main problem here 
    // is finding the object in a maze of hierarchy.
    // I wish I could say that I'm proud of this code, 
    // because it's really slick. Unfortunately, I ripped 
    // it off from Macromedia Dreamweaver's drag layer code 
    // (with permission, of course :-) 
    // Dreamweaver/Configuration/Behaviors/Actions/Drag Layer.htm 
    // It works wonderfully and solves the problem.
    WM_layers = new Array();
    with (document) {
      for (i=0; i<layers.length; i++) WM_layers[i]=layers[i]; {
        for (i=0; i<WM_layers.length; i++) {
          if (WM_layers[i].document && WM_layers[i].document.layers) {
            for (j=0; j<WM_layers[i].document.layers.length; j++) {
              WM_layers[WM_layers.length] = WM_layers[i].document.layers[j];
            }
            if(WM_layers[i].name == WM_id){
              // So if the code matches the name of the layer, 
              // return the reference. 
              theObj = WM_layers[i];
            }
          }
        }
      }
    }
  }
  return theObj;
}




function WM_position2element() {
/*
WM_position2element()
Author: Taylor
Author Email: taylor@wired.com
Author URL: http://www.taylor.org/
URL: http://www.hotwired.com/webmonkey/code_library/dhtml/wm_position2element/
This action positions one DHTML element a specified number of 
pixels away from another, based on the left, top, right, or 
bottom of the bounding box of each element. To use it, you must 
choose the element to position and the element to position against;
specify which side of each element's bounding box to base the 
positioning on; and supply the number of pixels difference between 
the two. Optionally, you can choose the browser window as the 
element to position against by using the string "window".

You can only position either the left or the top of an element 
on each function call, not both at once, so multiple calls will 
be necessary if you want to offset the positioned element in two 
dimensions at once. This also only updates the element once, so 
if you want elements to follow each other in formation you'll 
need to call the function multiple times.

Usage: WM_position2element(elementPositioned, 
left|top|right|bottom, differenceInPixels, 
elementPositionedAgainst|window, left|top|right|bottom);
*/

  // First we set up our variables. posE is short for positionEE 
  // and posR is short for positionER.
  var posE,posR,mod;
  with(WM_position2element);
  posE = WM_checkIn(arguments[0]);
  // This block of code takes the string 'window' and makes it mean 
  // the browser window. This is handled in very different ways by 
  // Netscape and IE, so this block of code is rather long.
  if (arguments[3] == 'window') {
    if (document.all){
      posR = document.body;;
      posR.left = 0;
      posR.top = 0;
      // For some reason IE was adding four pixels. 
      // I subtracted it here.
      posR.width = document.body.offsetWidth - 4;
      posR.height = document.body.offsetHeight - 4;
    } else if (document.layers) {
      posR = document;
      posR.left = 0;
      posR.top = 0;
      posR.width = this.window.innerWidth;
      posR.height = this.window.innerHeight;
      // You need to set the width and height manually for Netscape. 
      // You can do this based on its clip.
      posE.width = posE.clip.width;
      posE.height = posE.clip.height;
    } 
  } else {
    // This is for positioning your element based on another element.
    // First, the standard checkIn procedure to conditionalize around 
    // the differences in the DOMs. You can replace this with any 
    // function that returns an object reference to a DHTML object.
    posR = WM_checkIn(arguments[3]);
    // Netscape doesn't know the object's width, only its 
    // clip.width, so I construct all that here.
    if (document.layers) {
      posE.width = posE.clip.width;
      posE.height = posE.clip.height;
      posR.width = posR.clip.width;
      posR.height = posR.clip.height;
    }
  }
  // This is where the faux properties are constructed. Right and 
  // bottom are equal to width and height, but I still use them, 
  // because it's easier to construct references to them based on 
  // the arguments later on.
  posE.right = parseInt(posE.width);
  posE.bottom = parseInt(posE.height);
  posR.right = parseInt(posR.left) + parseInt(posR.width);
  posR.bottom = parseInt(posR.top) + parseInt(posR.height);
  // This is where all that conditional work comes into play - the 
  // algorithm for the actual positioning. This is also where the 
  // difference between left and right or top and bottom is handled, 
  // through the setting of the mod[ifier] variable.
  if((arguments[1] == 'left') || (arguments[1] == 'right')) {
    if(arguments[1] == 'left') mod = 0;
    if(arguments[1] == 'right') mod = posE.right * -1;
    posE.left = parseInt(posR[arguments[4]]) + parseInt(arguments[2]) + mod;
  }
  if((arguments[1] == 'top') || (arguments[1] == 'bottom')) {
    if(arguments[1] == 'top') mod = 0;
    if(arguments[1] == 'bottom') mod = posE.bottom * -1;
    posE.top = parseInt(posR[arguments[4]]) + parseInt(arguments[2]) + mod;
  }
}





function WM_netscapeCssFix() {
  /*
    Source: Webmonkey Code Library
    (http://www.hotwired.com/webmonkey/javascript/code_library/)

    Author: Taylor
    Author Email: taylor@wired.com
    Author URL: http://www.taylor.org/
    */

  // This part was inspired by Matthew_Baird@wayfarer.com
  // It gets around another unfortunate bug whereby Netscape 
  // fires a resize event when the scrollbars pop up. This 
  // checks to make sure that the window's available size 
  // has actually changed.
  if (document.WM.WM_netscapeCssFix.initWindowWidth != window.innerWidth || document.WM.WM_netscapeCssFix.initWindowHeight != window.innerHeight) {
    document.location = document.location;
  }
}

function WM_netscapeCssFixCheckIn() {
  // This function checks to make sure the version of Netscape 
  // in use contains the bug; if so, it records the window's 
  // width and height and sets all resize events to be handled 
  // by the WM_netscapeCssFix() function.
  if ((navigator.appName == 'Netscape') && (parseInt(navigator.appVersion) == 4)) {
    if (typeof document.WM == 'undefined'){
      document.WM = new Object;
    }
    if (typeof document.WM.WM_scaleFont == 'undefined') {
      document.WM.WM_netscapeCssFix = new Object;
      document.WM.WM_netscapeCssFix.initWindowWidth = window.innerWidth;
      document.WM.WM_netscapeCssFix.initWindowHeight = window.innerHeight;
    }
    window.onresize = WM_netscapeCssFix;
  }
}
