(function($)
{
	Drupal.behaviors.mtp = {
		attach:function() {

      $('#calculator-reset').click(function() {
        $('input[type="text"]').val(0);
        return false;
      });

      $('input[type="text"]').blur(function() {
        var temp = this.id.substr(15).split('-');
        var type = '';
        for (var i=0; i < (temp.length-1); i++) {
          if (temp[i] != 'length' || temp[i] != 'width' || temp[i] != 'flooring' || temp[i] != 'area') {
            if (i > 0){
              type += '-';
            }
            type += temp[i];
          }
        }

        var value = $('#edit-submitted-'+type+'-length').val() * $('#edit-submitted-'+type+'-width').val();
        var total = 0;
        $('#edit-submitted-'+type+'-flooring-area').val(value);
        
        $("input[type='text'][id*='flooring-area']").each(function(index) {
          total += parseInt($(this).val());
        });

        $('#edit-submitted-total').val(total);
      });

      $('.field-name-field-product-pdf a').attr('target', '_blank');

    }
	};

  
}(jQuery));
;

