(function(){
if(!window.FX) { window['FX'] = {} }

function formHelper() {
  var def_vals = new Array(),
      def_vals_ta = new Array(),
      jsid = 'jsid_',
      k = jsid.length,
      i, j,
      nodes = new Array();

  nodes = document.getElementsByTagName('INPUT');
  for (i=0; i<nodes.length; i++) {
    if (nodes[i].getAttribute('type') == 'text'
        && !ADS.hasClassName(nodes[i], 'js-off') ) {
            def_vals[i] = nodes[i].getAttribute('value');
            if (def_vals[i] == null) { continue; }

            ADS.addClassName(nodes[i], jsid + i);

            ADS.addEvent(nodes[i], 'focus', function() {
                j = this.className.substr( this.className.lastIndexOf(jsid) + k);

                if (this.value == def_vals[j]) {
                    this.value = '';
                }
            });

            ADS.addEvent(nodes[i], 'blur', function() {
                j = this.className.substr( this.className.lastIndexOf(jsid) + k);

                if (this.value == '') {
                    this.value = def_vals[j];
                }
            });
    }
  }

  nodes = document.getElementsByTagName('TEXTAREA');
  for (i=0; i<nodes.length; i++) {
    if (ADS.hasClassName(nodes[i], 'js-off')) {
      continue;
    }

    def_vals_ta[i] = nodes[i].innerHTML;

    nodes[i].className += ' ' + jsid + i;

    ADS.addEvent(nodes[i], 'focus', function() {
        j = this.className.substr( this.className.lastIndexOf(jsid) + k);

        if (this.innerHTML == def_vals_ta[j]) {
            this.innerHTML = '';
        }
    });

    ADS.addEvent(nodes[i], 'blur', function() {
        j = this.className.substr( this.className.lastIndexOf(jsid) + k);

        if (this.innerHTML == '') {
            this.innerHTML = def_vals_ta[j];
        }
    });
  }

  return;
}
window['FX']['formHelper'] = formHelper;

})();

ADS.addEvent(window, 'load', FX.formHelper);
