var input_normals = {};
var input_alternates = {};

function setup_empties () {
  var nodes = document.getElementsByTagName ('input');
  var input, alt_input;
  
  // Create extra inputs
  for (var i = 0; i < nodes.length; i++) {
    input = nodes.item(i);
    
    
    var et = input.getAttribute ('emptytext')
    if (et != null) {
      
      alt_input = create_element ('input', {
        'type': 'text',
        'name': input.name,
        'value': input.getAttribute ('emptytext')
      });
      
      alt_input.style.width = input.style.width;
      alt_input.style.display = 'none';
      alt_input.style.color = '#777';
      alt_input.onfocus = input.onfocus;
      alt_input.onblur = input.onblur;
      
      input_normals[input.name] = input;
      input_alternates[input.name] = alt_input;
      
      // on focus makes it into a boring text field
      alt_input.onfocus = function () {
        input_normals[this.name].style.display = '';
        input_alternates[this.name].style.display = 'none';
        input_normals[this.name].focus();
      }
      
      // on blur makes it into a grayed text field - if it is empty
      input.onblur = function () {
        if (this.value == '') {
          input_normals[this.name].style.display = 'none';
          input_alternates[this.name].style.display = '';
        }
      }
      
      input.onblur ();
    }
  }
  
  // Add the inputs that we have just created
  for (i in input_alternates) {
    input_normals[i].parentNode.insertBefore (input_alternates[i], input_normals[i]);
  }
}


// On-states code for image buttons: makes all elements of class 'buttonroll' try to highlight
function imgon (event) {
  var node = event.currentTarget;
  node.src = node.src.replace (/([^_]..)\.(gif|jpg|png)$/i, '$1_on.$2');
}

function imgoff (event) {
  var node = event.currentTarget;
  node.src = node.src.replace (/_on\.(gif|jpg|png)$/i, '.$1');
}

listen ('load', window, function() {
  mlisten ('mouseover', getElementsByClass ('buttonroll'), imgon);
  mlisten ('mouseout', getElementsByClass ('buttonroll'), imgoff);
});


// Clears the site-wide search
function clear_search (node) {
  if (node.value == 'Keyword(s)') {
    node.value = '';
  }
}
