$(document).ready(function () {
  $('#radMetric').click(function () { $('.metric').show(); $('.imperial').hide(); });
  $('#radImperial').click(function () { $('.metric').hide(); $('.imperial').show(); });
  $('#printer-friendly-button').click(function () { loadPrinterFriendlyVersion(); return false; });
});

// Loads the printer friendly window.
function loadPrinterFriendlyVersion(){
  var url;
  url = document.location.href;
  if (url.indexOf('?') != -1) {
    url = url + '&pf=1';
  } else {
    url = url + '?pf=1';
  }
  w = window.open(url, "printer_friendly", "menubar=1,location=0,status=0,scrollbars=1,resizable=1,width=655,height=440");

  return false;
}

function toggleTellColl(evt) {
  evt = (evt) ? evt : ((window.event) ? event : null);
  if (evt) {
    collDiv = document.getElementById('tellCollDetails');
    var target = (evt.target) ? evt.target : evt.srcElement;
    if (target.checked == true) {
      collDiv.style.display = "block";
    } else {
      collDiv.style.display = "none";
    }
  }
}

function formInit() {
  if (document.getElementById) {
    var tellColl = document.getElementById('tellColl');
    var tellCollDetails = document.getElementById('tellCollDetails');
    var submitfeedback = document.getElementById('submit-feedback');
    var returnLink = document.getElementById('return-link');

    if (submitfeedback && returnLink) {
      submitfeedback.style.display = 'block';
      returnLink.style.display = 'none';
    }
    if (tellColl && tellCollDetails) {
      tellColl.onclick = toggleTellColl;
      if (tellColl.checked == true) {
        tellCollDetails.style.display = "block";
      } else {
        tellCollDetails.style.display = "none";
      }
    }
  }
}

function closeWindow() {
  window.close();
}

function showFeedbackForm(siteroot) {
  w = window.open(siteroot + "/feedback_form.html", "form", "location=0,status=0,scrollbars=1,resizable=1,width=720,height=400");
  return false;
}
