addEvent(window,'load',addSearchText);
addEvent(window,'load',addPageBack);

/* check for page tools and add a back button if found */
function addPageBack() {
  var pagetools;
  if (pagetools = document.getElementById("pagetools")) {
    backLi = pagetools.insertBefore(document.createElement("li"), pagetools.firstChild);
    backLi.className = "left";
    backOption = document.createElement("a");
    backOption.appendChild(document.createTextNode("Previous page"));
    backOption.href = "javascript:history.back();";
    backLi.appendChild(backOption);
  }
}

/* add text to the search boxes */
function addSearchText() {
  var quick_search;
  var my_search;

  if (quick_search = document.getElementById("quick_search")) {
    if (quick_search.getAttribute('value') == null || quick_search.getAttribute('value') == "") {
			quick_search.style.color = "#858585";
			addEvent(quick_search,'click',clearSearch);
			quick_search.value = "What are you looking for?";
	  }
  }
  if (my_search = document.getElementById("my_search")) {
    my_search.style.color = "#858585";
    addEvent(my_search,'click',clearSearch);
    my_search.value = "Enter your postcode";
  }
}

function clearSearch() {
  this.style.color = "";
  this.value = "";
  removeEvent(this,'click',clearSearch);
}

/* clearInput is for legacy pages with text in inputs */
function clearInput(object, value) {
  if (object.value == value) {
    object.value = "";
  }
}

/* popup is used on some of the legacy jobs forms */
function popUp(page, width, height){
	win = eval('window.open("' + page + '","_blank","width='+width+',height='+height+', resizable, scrollbars=yes")');
	win.focus();
}

/* helper functions */
function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}