// this file specifies JS functions that should be applied to all pages of the webapp
$(document).ready(function() {
  var currentURL = document.location.href;
  
  $(".sub_nav li a").each(
    function(intIndex) {
      var path_match = '/' + $(this).attr("id") + '/';
      if (( currentURL.indexOf(path_match) > 0 ) ||
          (( currentURL.indexOf( '/content/' ) > 0 ) && ($(this).attr('id') === 'industry_articles'))) {
        $(this).addClass("selected");
      }
    }
  )

  pathname = document.location.pathname.toString();
  if (pathname == "/") {
    $("#arnco-home").addClass("selected");
  }
  if (pathname == "/aboutus/") {
    $("#arnco-about-us").addClass("selected");
  }
  if (pathname == "/contactus/") {
    $("#arnco-contact-us").addClass("selected");
  }

});

function navHoverOver( thisElement ) {
  navHoverOff();
  var currentId = $(thisElement).attr("id");  
  $("#sub_nav"+currentId).show();
}

function navHoverOff( defaultNavOn ) {
  $(".sub_nav").hide();
  
  if (defaultNavOn != null) {
    $(defaultNavOn).show();
  }
}

PoundsPerJoint = new Array(18)
PoundsPerJoint[0] = [.378, .504, 1.008, 1.512, 1.890, 2.016];
PoundsPerJoint[1] = [.398, .531, 1.062, 1.593, 1.990, 2.124];
PoundsPerJoint[2] = [.419, .559, 1.118, 1.677, 2.096, 2.236];
PoundsPerJoint[3] = [.440, .586, 1.172, 1.758, 2.198, 2.344];
PoundsPerJoint[4] = [.460, .613, 1.226, 1.839, 2.299, 2.452];
PoundsPerJoint[5] = [.481, .641, 1.282, 1.923, 2.404, 2.564];
PoundsPerJoint[6] = [.502, .669, 1.338, 2.007, 2.509, 2.676];
PoundsPerJoint[7] = [.513, .684, 1.368, 2.052, 2.565, 2.736];
PoundsPerJoint[8] = [.524, .698, 1.396, 2.094, 2.618, 2.792];
PoundsPerJoint[9] = [.546, .728, 1.456, 2.184, 2.734, 2.912];
PoundsPerJoint[10] = [.555, .740, 1.480, 2.220, 2.775, 2.960];
PoundsPerJoint[11] = [.565, .753, 1.506, 2.259, 2.824, 3.012];
PoundsPerJoint[12] = [.586, .781, 1.562, 2.343, 2.930, 3.124];
PoundsPerJoint[13] = [.607, .809, 1.618, 2.427, 3.034, 3.236];
PoundsPerJoint[14] = [.629, .838, 1.676, 2.514, 3.143, 3.352];
PoundsPerJoint[15] = [.671, .894, 1.788, 2.682, 3.353, 3.576];
PoundsPerJoint[16] = [.697, .929, 1.858, 2.787, 3.484, 3.716];
PoundsPerJoint[17] = [.723, .964, 1.928, 2.892, 3.615, 3.856];

$('#numJoints').focus(function() {
  this.value = '';
});

$('#calculateUsage').click(function() {
  var poundsPerJoint = PoundsPerJoint[$('#jointDiameter').val()][$('#hardbandingWidth').val()];
  var poundsRequired = poundsPerJoint * $('#numJoints').val();
  var reworkContingency = poundsRequired / 10;

  document.getElementById('poundsPerJoint').innerHTML = poundsPerJoint.toFixed(2);
  document.getElementById('poundsRequired').innerHTML = poundsRequired.toFixed(0);
  document.getElementById('reworkContingency').innerHTML = reworkContingency.toFixed(1);
  document.getElementById('totalPounds').innerHTML = (poundsRequired + reworkContingency).toFixed(1);
});

$('#clearCalculator').click(function() {
  document.getElementById('poundsPerJoint').innerHTML = '';
  document.getElementById('poundsRequired').innerHTML = '';
  document.getElementById('reworkContingency').innerHTML = '';
  document.getElementById('totalPounds').innerHTML = '';
});

$('#applicator_go').click(function() {
  window.location.href='/presence/applicators/' + $('#sideModuleGoApp').val() + '/';
});

$('#manuals_go').click(function() {
  if ($('#sideModuleGoManual').val() != '') {
    window.location.href='/site_media/' + $('#sideModuleGoManual').val();
  }
});

