var EcotechFormTrader = Class.create({
    initialize: function(form) {
      this.dom = {};
      this.dom.form = $(form);
      this.dom.destination = $(this.dom.form.elements.destination);

      this.dom.destination.observe('change', function(ev) {
	  this.init_check();
	}.bindAsEventListener(this));

      this.init_check();
    },

    init_check: function() {
      switch (this.dom.destination.getValue()) {
      case '勤務先':
      $$('input.must.if_destination_is_office').each(function(elem) {
	  this.add_elem_check(elem);
	}.bind(this));
      $$('span.must.if_destination_is_office').invoke('show');
      break;

      default:
      $$('input.must.if_destination_is_office').each(function(elem) {
	  this.remove_elem_check(elem);
	}.bind(this));
      $$('span.must.if_destination_is_office').invoke('hide');
      break;
      }
    },

    add_elem_check: function(elem, reg, extra) {
      if (elem) {
	try {
	  delete elem.onblur;	// FF はこちら
	} catch(e) {
	  elem.onblur = null;	// IE はこちら (余計だが)
	}

	elem.onblur = function() { Validator.check(this, reg, extra); }
      }
    },

    remove_elem_check: function(elem) {
      if (elem) {
	if (elem._validbaloon) {
	  elem._validbaloon.close();
	}
	if ('onblur' in elem) {
	  try {
	    delete elem.onblur;	// FF はこちら
	  } catch(e) {
	    elem.onblur = null;	// IE はこちら
	  }
	}
      }
    },

    dummy: null
  });

Event.observe(window, 'load', function() {
    new EcotechFormTrader(document.forms[0]);
  });
