/* $Id: inputs.js 2142 2011-08-17 13:41:27Z jure.merhar $ */

function init_inputs()
{
  var inputs = $$('input.inline');
  inputs.each(init_input);
  var textareas = $$('textarea.inline');
  textareas.each(init_input);
}

function init_input(item)
{
  set_default_input.call(item);
  Event.observe(item, 'blur',  set_default_input.bindAsEventListener(item));
  Event.observe(item, 'focus', clear_default_input.bindAsEventListener(item));
}

function clear_default_input()
{
  if (this.name == 'password') switch_type(this, 'password');
	if (this.value == this.title) this.value = '';
}
function set_default_input()
{
  if (this.value == '') {
    if (this.name == 'password') switch_type(this, 'text');
    this.value = this.title;
  }
}

function switch_type(input, type)
{
  try { input.type = type } catch (e) {}
}

/* for IE
function switch_type(input, type, focus)
{
  if ((input.name != 'password') || (input.type == type)) return;
  var new_input = document.createElement('input');
  new_input.type      = type;
  new_input.name      = input.name;
  new_input.id        = input.id;
  new_input.className = input.className;
  new_input.title     = input.title;
  new_input.value     = input.value;
  input.parentNode.replaceChild(new_input, input);
  Event.observe(new_input, 'focus', clear_default_input.bindAsEventListener(new_input));
  Event.observe(new_input, 'blur',  set_default_input.bindAsEventListener(new_input));
  if (focus) setTimeout(new_input.focus, 10);
}
*/

Event.onDOMReady(init_inputs);

