/*******************************************************************************
PURPOSE : Hold 'generic' JS methods
REMARKS : -
REQUIRES: -
USES    : -
ISSUES  : -
TODO    : 1. Clean up subnav_hover
          2. Clean up main_init
          3. Clean up window.onload call - standardize for all pages?
HISTORY : Tue Jan 15 00:03:17 GMT 2008 - jerald - Initial Creation
          Wed Feb 06 19:37:00 GMT 2008 - jerald
            1. Pasted code from TransInt - will need to clean up
          Fri Feb 08 18:04:00 GMT 2008 - jerald
            1. Added OpenWindow function

*******************************************************************************/

/**
 PURPOSE :
    Remove default value of a text box.  Normally called onfocus.
 ACCEPTS :
    p_elt - the text box element
 RETURNS :
    Nothing
*/
function ClearDefaultValue( p_elt ) {
  if ( p_elt.value == p_elt.defaultValue ) {
    p_elt.value = '';
  }
}

/**
 PURPOSE :
    Open a file in a new window and control its display properties
 ACCEPTS :
    p_url - string - file to open
    p_options - number - dirty, fugly way to set display properties
 RETURNS :
    Nothing
*/
function OpenWindow( p_url, p_options ) {
  var opts = '';
  switch ( p_options ) {
    case 1:
      opts = 'scrollbars=yes,resizable=yes,width=650,height=595';
      break;
  }
  window.open( p_url, '', opts);
}



/**
 PURPOSE :
    If text box does not have a value, return the default value
 ACCEPTS :
    p_elt - the text box element
 RETURNS :
    Nothing
*/
function ReturnDefaultValue( p_elt ) {
  if ( p_elt.value == '' ) {
    p_elt.value = p_elt.defaultValue;
  }
}


function CollapseExpandFromIcon( p_elt, p_action_elt ) {
  if ( p_action_elt.style.display == 'none' ) {
    p_action_elt.style.display = 'block';
    p_elt.src = '/_img/collapse-icon.gif';
  }
  else {
    p_action_elt.style.display = 'none';
    p_elt.src = '/_img/expand-icon.gif';
  }
}




var subnav_hover = {
  nav_id: 'subnav',
  nav: false,
  nav_elements: false,
  hover_activate: function(event) {
    if(!event) {
      // just a workaround for ie misbehavior
      if(window.event) {
        event = window.event;
        if(!event.target) {
          event.target = event.srcElement;
        }
      }
    }
    if(event.target.parentNode == this) {
      this.className = 'selected';
      for(var i = 0; i < this.hover_object.nav_elements.length; i++) {
        if(this.hover_object.nav_elements[i] != this) {
          this.hover_object.nav_elements[i].className = '';
        }
      }
    }
  },
  hover_clear: function(event) {
    for(var i = 0; i < this.hover_object.nav_elements.length; i++) {
      this.hover_object.nav_elements[i].className = '';
    }
  },
  init: function() {
    if(this.nav = document.getElementById(this.nav_id)) {
      this.nav_elements = this.nav.getElementsByTagName('li');
      this.nav.onmouseout = this.hover_clear;
      this.nav.hover_object = this;
      for(var i = 0; i < this.nav_elements.length; i++) {
        this.nav_elements[i].hover_object = this;
        this.nav_elements[i].onmouseover = this.hover_activate;
      }
    }
  }
};

function main_init() {
  // initiate hover states for left column nav
  subnav_hover.init();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


window.onload = main_init;

// autoload some images
var img = new Image();
img.src = "/_img/bg_nav_on.jpg";

