//function init( sPath ) {
function init() {

  initCopyright();
  initImage();
  //initNav( sPath );
  initNav();

  if (document.getElementById( 'txtSearch' )) { document.getElementById( 'txtSearch' ).focus(); }
}

function initCopyright() {

  var oDate = new Date();
  var sYear = oDate.getFullYear();

  document.getElementById( 'footer_copyright' ).firstChild.firstChild.nodeValue = document.getElementById( 'footer_copyright' ).firstChild.firstChild.nodeValue.replace( /RMT/, sYear + ' RMT'  );
  document.getElementById( 'footer_copyright' ).style.visibility = 'visible';
}

function initImage() {

  var aImage = document.getElementsByTagName( 'img' );

  // loop through all <img> tags on this page...
  for (var i = 0; i < aImage.length; i++) {

    // if this <img> tag has an onclick event... 
    if (aImage[i].onclick != null) { aImage[i].style.cursor = 'pointer'; }
  }
}


function initElement() {

  // assign id values (via name)
  for (var i = 0; i < document.forms.length; i++) {
    for (var j = 0; j < document.forms[i].elements.length; j++) {
      if (document.forms[i].elements[j].name == null || document.forms[i].elements[j].name == '') {
        document.forms[i].elements[j].name = document.forms[i].elements[j].id;
      }
    }
  }
}

//function initNav( sPath ) {
function initNav() {

  var aEvent = [ [ 'out', '' ], [ 'over', 'over' ], [ 'up', 'over' ], [ 'down', 'over' ] ];
  var aElement = document.getElementsByTagName( 'li' );

  // loop through <li> tags...
  for (var i = 0; i < aElement.length; i++) {

    var sElementID = aElement[i].getAttribute( 'id' );

    // if id and id starts with 'header_nav_'... 
    if (sElementID != null && sElementID.match( 'header_nav' )) {

      // if <a> tag has an associated href value...
      if ((aElement[i].getElementsByTagName( 'a' ))[0].href != '') {

        // assign cursor/href 
        aElement[i].style.cursor = 'pointer';
        aElement[i].onclick = function () {
            document.location = (this.getElementsByTagName( 'a' ))[0].href;
         }
      }

      // if not type 'over'...
      if (!sElementID.match( '_over' )) {

        // loop types (out/over/up/down)... 
        for (var j = 0; j < aEvent.length; j++) {

          // build image path and assign event
          //var sImage = (sPath ? sPath : '')+ 'images/' + sElementID.replace( /^header\_/, '' ) + ((aEvent[j][1] != '') ? '_' : '') + aEvent[j][1] + '.gif';
          var sImage = 'images/' + sElementID.replace( /^header\_/, '' ) + ((aEvent[j][1] != '') ? '_' : '') + aEvent[j][1] + '.gif';
          eval( 'aElement[i].onmouse' + aEvent[j][0] + ' = function () { this.style.backgroundImage = \'url( "' + sImage + '" )\'; }' );
        }
      }
    }
  }
}

var oMedia = new Object();
function openMedia( nWidth, nHeight, sSRC, sDownload ) {

  if (nWidth != null && nHeight != null && sSRC != null) {

    oMedia.width    = nWidth;
    oMedia.height   = nHeight;
    oMedia.src      = sSRC;
    oMedia.download = sDownload;

    var nParentWidth  = (document.all) ? document.body.clientWidth  : window.innerWidth;
    var nParentHeight = (document.all) ? document.body.clientHeight : window.innerHeight;

    var oWindow = new Object();

    oWindow.width  = nWidth  + 70;
    oWindow.height = nHeight + 60;
    oWindow.top    = Math.round( (nParentHeight - nHeight) / 2 ) + 50;
    oWindow.left   = Math.round( (nParentWidth - nWidth) / 2 );

    oWindow.url     = 'media.html';
    oWindow.name    = 'winMedia_' + nWidth.toString() + 'x' + nHeight.toString();
    oWindow.feature = 'top=' + oWindow.top + ',left=' + oWindow.left + ',width=' + oWindow.width + ',height=' + oWindow.height;
    
    eval( 'var ' + oWindow.name + ' = window.open( oWindow.url, oWindow.name, oWindow.feature )' );
    eval( oWindow.name + '.focus()' );
  }
}

function validateLength( oElement, nMaxLength ) {
  if (oElement.value.length > nMaxLength) { oElement.value = oElement.value.substring( 0, nMaxLength ); }
}
