$(function() {
  
  $(".int").keypress(function() {
    var self = this;
    setTimeout(function() { $(self).trigger('change') }, 0);
  }).change(function() {
    var val = $(this).val();
    if (/\D/.test(val)) $(this).val(val.replace(/\D/g, ''));
  });
  
  $(".float").keypress(function() {
    var val = $(this).val();
    if (/[^\d\.\,]/.test(val)) $(this).val(val.replace(/[^\d\.\,]/g, ''));
  }).change(function() {
    var val = $(this).val();
    if (!parseFloat(val)) $(this).val(0);
  });
  
  $("table.active-rows tbody").find("tr")
    .hover(function() { $(this).addClass("over") }, function() { $(this).removeClass("over") })
    .click(function(ev) {
      if (!(ev.target.href))
        open($(this).find("a:first")[0].href, "_self");
      });
  
  $("input[type=text]").focus(function(){
    this.select();
  });
  
  

  $("li.prod").hover(
    function() {
      $(this).find('.online-price').show("slow");
    },
    function() {
      $(this).find('.online-price').hide("fast");
    }
  );
  
  $(".online-price-container").hover(
    null,
    function(ev) {
      $(this).find(".online-price-tip").fadeOut("slow");
    }
  ).find(".online-price").mouseover(
    function() {
      $(this).next('.online-price-tip').fadeIn("slow");
    }
  );
  
  $("li .online-price, .online-price-tip").hide();
});

document.write(
  '<style type="text/css">.js_display { display: none } .js_hidden { visibility: hidden } li .online-price-container { display: block; }</style>'
);


function printContent() {
  var f = $("#print_frame")[0];
  if (!f) {
    f = document.body.appendChild(document.createElement("iframe"));
    f.id = "print_frame";
  }
  var doc = f.contentDocument;
  for(;;) {
    try {
      doc.title = document.title;
      doc.body.innerHTML = $("#content").html();
      doc.defaultView.print();
    } catch(e) {
      if (f) {
        f = null;
        var w = open("about:blank", "agrif_print");
        doc = w.document;
        w.setTimeout(function() {
          w.print();
          w.close();
        }, 100);
        continue;
      }
    }
    break;
  }
}
