/*
 * Bentley.js
 * Nicholas Maloney
 * version 1.1 2006-06-26
 * http://creativecommons.org/licenses/by-sa/2.5/
 * A rate this page module using prototype
 * Dependencies: /js/*.js
 * This file contains various utilities and object contstructor methods
 */
 

//Retrieves URL via ajax for relocate function
function searchLinks(txt, li)	{
//This hack disables the default select
if($F(txt) != '&nbsp;') {
  var url = '/search/search.cfc?method=getLinkFromName';
  var pars = 'keyword_name=' + $F(txt);		
  var myAjax = new Ajax.Request( url, { method: 'get', parameters: pars, onComplete: relocate });
  }
}

//Relocate function for search box
function relocate(originalRequest) {
  var thisLink = originalRequest.responseText.trim();
  var thisLength = thisLink.length;
  if (thisLength > 1) {
  	window.location=thisLink;
  }
  else {
  	var keyword = $F('keyword');
  	var keywordLen = keyword.length;
  	var cleanKeyword = keyword.substring(0,keywordLen-1);
  	document.searchForm.keyword.value=cleanKeyword;
  	document.searchForm.submit();
  }  
}	

/* Strip whitespace from the beginning and end of a string */
if (typeof String.prototype.trim == "undefined") {
    String.prototype.trim = function () {
        var s = this.replace(/^\s*/, "");
        return s.replace(/\s*$/, "");
    }
}