if( document.addEventListener ) document.addEventListener( 'DOMContentLoaded', mbhydroform, false );

function mbhydroform(){
  // Hide forms
  $( 'form.mbhydroform' ).hide().end();
  
  // Processing
  $( 'form.mbhydroform' ).find( 'li/label' ).not( '.nombhydro' ).each( function( i ){
    var labelContent = this.innerHTML;
    var labelWidth = document.defaultView.getComputedStyle( this, '' ).getPropertyValue( 'width' );
    var labelSpan = document.createElement( 'span' );
        labelSpan.style.display = 'block';
        labelSpan.style.width = labelWidth;
        labelSpan.innerHTML = labelContent;
    this.style.display = '-moz-inline-box';
    this.innerHTML = null;
    this.appendChild( labelSpan );
  } ).end();
  
  // Show forms
  $( 'form.mbhydroform' ).show().end();
}

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

function externalLinks()
{
 var objCurrent, objReplacement;

 if (document.getElementsByTagName)
 {
  var objAnchors = document.getElementsByTagName('a');
  for (var iCounter=0; iCounter<objAnchors.length; iCounter++)
  {
   if (objAnchors[iCounter].getAttribute('href') &&objAnchors[iCounter].getAttribute('rel') == 'external')
   {
    objAnchors[iCounter].onclick = function(event){return launchWindow(this, event);}
    objAnchors[iCounter].onkeypress = function(event){return launchWindow(this, event);}
    objAnchors[iCounter].title = (objAnchors[iCounter].title != "") ? objAnchors[iCounter].title+" (open new window)" : "open new window";

    if (document.replaceChild)
    {
     objCurrent = objAnchors[iCounter].firstChild;
     if (objCurrent.nodeType == 3) // Text node
     {
      objReplacement = document.createTextNode(objCurrent.data + ' (open new window)');
      objAnchors[iCounter].replaceChild(objReplacement, objCurrent);
     }
     else if (objCurrent.alt) // Current element is an image
     {
      objReplacement = objCurrent;
      objReplacement.alt = objCurrent.alt + ' (open new window)';
      try
      {
       objAnchors[iCounter].replaceChild(objReplacement, objCurrent);
      }
      catch(e){}
     }
    }
   }
  }
 }
}

function launchWindow(objAnchor, objEvent)
{
var iKeyCode;

if (objEvent && objEvent.type == 'keypress')
{
 if (objEvent.keyCode)
  iKeyCode = objEvent.keyCode;
 else if (objEvent.which)
  iKeyCode = objEvent.which;

 if (iKeyCode != 13 && iKeyCode != 32)
  return true;
}

return !window.open(objAnchor);
}

/***************************************************************/
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}


