// attach event listener for hijack
if(window.addEventListener) { window.addEventListener('load', lwp_hijack_search, false); }
else { window.attachEvent('onload', lwp_hijack_search); }
// Prep WP search form for Lijit functionality
function lwp_pnode( objNode, strTagName ){
for (
objNode = objNode.parentNode ;
(
objNode && (
(objNode.tagName && (objNode.tagName.toLowerCase() != strTagName)) ||
(!objNode.tagName && (objNode.nodeType != 3))
)
);
objNode = objNode.parentNode
){}
return( objNode );
}
function lwp_findElem(lwp_el_type,lwp_method){
if (lwp_el_type == 'FORM')
{
lwp_search_id = new Array('searchform','searchForm','search_form','search','Search','search-form','searchform2');
}
else if (lwp_el_type == 'INPUT')
{
lwp_search_id = new Array('s','search','search-text','search-input','Search','searchbox','q');
}
for (var i in lwp_search_id)
{
if (document.getElementById(lwp_search_id[i]) && document.getElementById(lwp_search_id[i]).tagName == lwp_el_type)
{
if (lwp_el_type == 'INPUT'&& lwp_method == 'id')
{
lwp_obj = document.getElementById(lwp_search_id[i]);
if (!lwp_obj)
{
lwp_obj = document.getElementsByName(lwp_search_id[i])[0];
}
var lwp_both = new Array(lwp_obj,lwp_pnode(lwp_obj,'form'));
return lwp_both;
}
else
{
return document.getElementById(lwp_search_id[i]);
}
}
else
{
if (lwp_el_type == 'INPUT'&& lwp_method == 'id')
{
lwp_obj = document.getElementsByName(lwp_search_id[i])[0];
var lwp_both = new Array(lwp_obj,lwp_pnode(lwp_obj,'form'));
return lwp_both;
}
else if (lwp_el_type == 'INPUT' && lwp_method == '')
{
lwp_obj = document.getElementsByName(lwp_search_id[i])[0];
return lwp_obj;
}
}
}
return false;
}
function lwp_hijack_search() {
var lwp_formId = lwp_findElem('FORM','id');
if (!lwp_formId)
{
var lwp_finder= lwp_findElem('INPUT','id');
inputText = lwp_finder[0];
lwp_formId = lwp_finder[1];
inputText.value = 'Lijit Search';
inputText.onblur = function(){if (inputText.value == ''){inputText.value = 'Lijit Search';}};
inputText.onfocus = function(){if (inputText.value == 'Lijit Search'){inputText.value = '';}};
try
{
lwp_formId.onsubmit = lwp_hijack_submit;
}
catch(err)
{
}
}
else
{
var inputText= lwp_findElem('INPUT','');
inputText.value = 'Lijit Search';
inputText.onblur = function(){if (inputText.value == ''){inputText.value = 'Lijit Search';}};
inputText.onfocus = function(){if (inputText.value = 'Lijit Search'){inputText.value = '';}};
try
{
lwp_formId.onsubmit = lwp_hijack_submit;
}
catch(err)
{
}
}
}
// do the search
function lwp_hijack_submit(e) {
var lwp_inputText = lwp_findElem('INPUT','');
lwp_dosearch(lwp_inputText.value);
return false;
}