getElementsWithClass = function(_tag_name, _class_name) {
	  var col = new Array();
	  var expr = new RegExp("\\b"+_class_name+"\\b");
	  var c = (document.childNodes && _tag_name == "*") ? document.childNodes : document.getElementsByTagName(_tag_name);
	  for(var i = 0; i < c.length; i++) {
	    if(expr.test(c[i].className)) col[col.length] = c[i];
	  }
	  return col;
	}
  
extendedHover = function() {
  if (hoverElems)
	for (var i=0; i<hoverElems.length; i++) {
		hoverElems[i].onmouseover=function() {
			this.className+=" hover";
		}
		hoverElems[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" hover\\b"), "");
		}
	}
}

//search

function submitForm() {
  var frm = document.getElementById("searchForm");
  var q = document.getElementById("query");
  var qValue = q.value;
  var _q = checkLuceneQuery(qValue);
  if (_q != "_none_") {
    q.value = _q;
    frm.action = "/search.jsp";
    frm.submit();
  }
}

function checkLuceneQuery(_query) {
  if(_query != null && _query.length > 0) {
    var matches = _query.match(/^(\*)|([^a-zA-Z0-9_]\*)/);
    if(matches != null && matches.length > 0) {
      alert("Invalid search query! The wildcard (*) character must be preceded by at least one alpha or number character. Please try again.")
      return "_none_";
    }
    matches = _query.match(/^([^\n()]*|(\(([a-zA-Z0-9_+\-:()\" ]|\*)+\)))*$/);
    if(matches == null || matches.length == 0) {
      alert("Invalid search query! Parentheses must contain at least one alphabet or number. Please try again.")
      return "_none_";
    }     
    matches = _query.match(/^(([^\n+-]*|[+-]([a-zA-Z0-9_:()]|\*)+))*$/);
    if(matches == null || matches.length == 0) {
      alert("Invalid search query! '+' and '-' modifiers must be followed by at least one alphabet or number. Please try again.")
      return "_none_";
    }      
    matches = _query.match(/\"/g);
    if(matches != null) {
      var number = matches.length;
      if((number % 2) > 0) {
        alert("Invalid search query! Please close all quote (\") marks.");
        return "_none_";
      }
    }
    matches = _query.match(/^(([^\n:]*|([a-zA-Z0-9_]|\*)+[:]([a-zA-Z0-9_()"]|\*)+))*$/);
    if(matches == null || matches.length == 0) {
      alert("Invalid search query! Field declarations (:) must be preceded by at least one alphabet or number and followed by at least one alphabet or number. Please try again.")
      return "_none_";
    }
    if(_query.indexOf("*") != -1) {
      _query = _query.toLowerCase();
    }
    return _query;
  } else {
    alert("Invalid search query! Text needs to entered in the search field.")
    return "_none_";
  }
}

var t; var theImg; var hoverElems=null;

window.onload = function() {if (window.attachEvent) {hoverElems=getElementsWithClass('DFN', 'term');window.attachEvent("onload", extendedHover);}}

