// Hide and reveal default text for any input that has an 'id' attribute
// By Brad Greenwald of Five Technology | www.fivetechnology.com

var inputObjects = new Array;
		
// object-maker 
function inputObject(id, val) {
  this.id = id;
  this.value = val;
}

function bindInputs (inputArray) {

  // loop input Array
  for (i=0;i<inputArray.length;i++) {
    
    if (!inputArray[i].id || !inputArray[i].value) {

    	// missing id or value attribute
    	continue;
    	
    } else {
    	
    	var ipt = inputArray[i];
    	
	    // grab inputs with type='text'
	    if (ipt.getAttribute('type')=='text') {
	    
	      // build object array
	      io = new inputObject(ipt.id,ipt.value);
	      inputObjects.push(ipt.id);
	      inputObjects[ipt.id] = io;
	      
	      // bind focus/blur routines
	      document.getElementById(ipt.id).onfocus = function(){updateInput(this.id);}
	      document.getElementById(ipt.id).onblur = function(){updateInput(this.id);}
	    }

    }
  }
}

function updateInput(id) {
  var theInput = document.getElementById(id);
  
  // if default text, clear field
  if (theInput.value==inputObjects[id].value) {
    theInput.value = '';
    
  // if field clear, reset to default
  } else if (theInput.value=='') {
    theInput.value = inputObjects[id].value;
  }
}

// doc load function
function init() {
  //grab desired elements
  var docInputs = document.getElementsByTagName("input");
  
  //run appropriate functions
  bindInputs(docInputs);
}

window.onload = init;
