var clickCount = 0;
$(document).ready(function() {
  $("#comparisonItems .homeproduct").each(function() {
    if ( $(this).find(".homelistPrice").text() == 'List Price: ' ) {
      $(this).find(".homelistPrice").css("visibility", "hidden");
    }
    if ( $(this).find(".homesavings").text() == '' ) {
      $(this).find(".homesavings").html('&nbsp;');
      $(this).find(".homesavings").css("visibility", "hidden");
    }
    if ( $(this).find(".homePriceValue").text() == 'Discontinued' ) {
      $(this).find(".homeprice").html('Discontinued');
    }
  });
  $("#comparisonItems .homeproduct .itemSelector input").click(function() {
    clickCount = $("#comparisonItems .homeproduct .itemSelector input:checked").length;
    if ( clickCount == 4 ) {
      $("#comparisonItems .homeproduct .itemSelector input:not(:checked)").attr('disabled', 'disabled');
    } else {
      $("#comparisonItems .homeproduct .itemSelector input:not(:checked)").attr('disabled', '');
    }
  });
  $(".comparisonChartButton").click(function() {
    if ( !$("#comparisonItems .homeproduct .itemSelector input:checked").length ) {
      alert('Please select up to 4 products to compare.');
      return false;
    }
    var str = '';
    $("#comparisonItems .homeproduct .itemSelector input:checked").each(function() {
      if ( str.length ) str += ',';
      str += $(this).val();
    });
    if ( str.length ) {
      //window.open('/comp-chart/?products='+str,'Chart','width=800, height=600, menubar=no, scrollbars=yes, resizable=yes, status=no, toolbar=no');
      $(this).attr('href', '/comp-chart/?products='+str);
      return true;
    }
    return false;
  });
});