// search.js for dithered.com
// functionality for meta/search.html
// code by chris nott (chris[at]dithered[dot]com)


function isDefined(property) {
  return (typeof property != 'undefined');
}

function doGlobalOnPageLoad() {
   if (isDefined(document.getElementById)) {
      
      // add onfocus and onblur event handlers to search input field to toggle initial value
      var searchInput = document.getElementById('searchInput');
      searchInput.onfocus = function() {
            if (this.value == 'Enter search terms') {
               this.value = '';
            }
         };
      searchInput.onblur = function() {
            if (this.value == '') {
               this.value = 'Enter search terms';
            }
         };
         
      // add onsubmit event handler to search form to prevent default label text to be submitted
      var searchForm = document.getElementById('searchForm');
      searchForm.onsubmit = function() {
            var searchInput = document.getElementById('searchInput');
            return (searchInput.value == 'Enter search terms') ? false : true;
         };
   }
}

function validateSearch() {
   if (isDefined(document.getElementById)) {
      
      
// call doGlobalOnPageLoad when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', doGlobalOnPageLoad, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', doGlobalOnPageLoad);
}