﻿/* search.js
   client-side code for search box in LEAF theme */

function activateSearch(controlId, buttonId, inactiveClass, activeClass, inactiveText, url) {

  this.controlId = controlId;
  this.control = document.getElementById(controlId);
  this.button = document.getElementById(buttonId);

  this.inactiveClass = inactiveClass;
  this.activeClass = activeClass;
  this.inactiveText = inactiveText;
  this.isActive = false;

  this.control.className = inactiveClass;
  this.control.value = inactiveText;

  this.control.onfocus = function () {
    if (!isActive) {
      control.className = activeClass;
      control.value = "";
      isActive = true;
    }
  }

  this.control.onblur = function () {
    if (isActive && (control.value == "" || control.value == inactiveText)) {
      control.className = inactiveClass;
      control.value = inactiveText;
      isActive = false;
    }
  }

  this.control.onkeydown = function (e) {
    if (window.event) { e = window.event; }
    if (e.keyCode == 13) {
      document.location.href = url + "?terms=" + encodeURI(control.value);
      return false;
    }
  }

  this.button.onclick = function () {
    if (isActive) { document.location.href = url + "?terms=" + encodeURI(control.value); }
  }

}