var QuantityInput = Class.create({
  
  initialize: function(input) {
    this.input = $(input);
    this.input.observe('focus', this.focus.bindAsEventListener(this));
    this.input.observe('blur', this.blur.bindAsEventListener(this));
  },
  
  focus: function(event) {
    if(this.input.value == '0')
      this.input.value = '';      
  },
  
  blur: function(event) {
    if(this.input.value == '')
      this.input.value = 0;
  }  
  
})

document.observe('dom:loaded', function() {
  $$('input.quantity').each(function(el){
    new QuantityInput(el);
  })
})

function checkAllIn(el) {
  $(el).getElementsBySelector('input[type=checkbox]').each(function(e){
    e.checked = true;
  })
}

function uncheckAllIn(el) {
  $(el).getElementsBySelector('input[type=checkbox]').each(function(e){
    e.checked = false;
  })
}


function show_link(l) {
  alert(l);
}

function clearForm(el) {
	form = $(el).up('form');
	form.getElementsBySelector('input[type=text], input[type=password], textarea').each(function(e){
		e.value = '';
	});
	form.getElementsBySelector('input[type=checkbox]').each(function(e){
		e.checked = false;
	})
}

function toggle_notes(el) {
	$(el).up('tr').toggleClassName('with_notes')
	$(el).up('tr').down('input.notes').focus();
}