
/* Merged Plone Javascript file
 * This file is dynamically assembled from separate parts.
 * Some of these parts have 3rd party licenses or copyright information attached
 * Such information is valid for that section,
 * not for the entire composite file
 * originating files are separated by - filename.js -
 */

/* - highlightsearchterms.js - */
// http://www.classicwines.nl/portal_javascripts/highlightsearchterms.js?original=1
function highlightTermInNode(node,word){var contents=node.nodeValue;if(jq(node).parent().hasClass("highlightedSearchTerm")) return;var highlight=function(content){return jq('<span class="highlightedSearchTerm">'+content+'</span>')}
while(contents&&(index=contents.toLowerCase().indexOf(word))>-1){jq(node).before(document.createTextNode(contents.substr(0,index))).before(highlight(contents.substr(index,word.length))).before(document.createTextNode(contents.substr(index+word.length)));var next=node.previousSibling;jq(node).remove();node=next;contents=node.nodeValue}}
function highlightSearchTerms(terms,startnode){if(!terms||!startnode) return;jq.each(terms, function(i,term){term=term.toLowerCase();if(!term||/(not|and|or)/.test(term)) return;jq(startnode).find('*').andSelf().contents().each(function(){if(this.nodeType==3) highlightTermInNode(this,term)})})}
function getSearchTermsFromURI(uri){var query;if(typeof decodeURI!='undefined'){query=decodeURI(uri)} else if(typeof unescape!='undefined'){query=unescape(uri)} else{}
var result=new Array();if(window.decodeReferrer){var referrerSearch=decodeReferrer();if(null!=referrerSearch&&referrerSearch.length>0){result=referrerSearch}}
var qfinder=new RegExp("(searchterm|SearchableText)=([^&]*)","gi");var qq=qfinder.exec(query);if(qq&&qq[2]){var terms=qq[2].replace(/\+/g,' ').split(' ');result.push.apply(result,jq.grep(terms, function(a){return a!=""}));return result}
return result.length==0?false:result}
jq(function(){var terms=getSearchTermsFromURI(window.location.search);highlightSearchTerms(terms,getContentArea())});

/* - se-highlight.js - */
// http://www.classicwines.nl/portal_javascripts/se-highlight.js?original=1
var searchEngines=[['^http://([^.]+\\.)?google.*','q='],['^http://search\\.yahoo.*','p='],['^http://search\\.msn.*','q='],['^http://search\\.aol.*','userQuery='],['^http://(www\\.)?altavista.*','q='],['^http://(www\\.)?feedster.*','q='],['^http://search\\.lycos.*','query='],['^http://(www\\.)?alltheweb.*','q='],['^http://(www\\.)?ask\\.com.*','q=']]
function decodeReferrer(ref){if(null==ref&&document.referrer){ref=document.referrer}
if(!ref) return null;var match=new RegExp('');var seQuery='';for(var i=0;i<searchEngines.length;i++){if(!match.compile){match=new RegExp(searchEngines[i][0],'i')} else{match.compile(searchEngines[i][0],'i')}
if(ref.match(match)){if(!match.compile){match=new RegExp('^.*[?&]'+searchEngines[i][1]+'([^&]+)&?.*$','i')} else{match.compile('^.*[?&]'+searchEngines[i][1]+'([^&]+)&?.*$')}
seQuery=ref.replace(match,'$1');if(seQuery){seQuery=decodeURIComponent(seQuery);seQuery=seQuery.replace(/\'|"/, '');return seQuery.split(/[\s,\+\.]+/)}}}
return null}


/* - first_input_focus.js - */
// http://www.classicwines.nl/portal_javascripts/first_input_focus.js?original=1
jq(function(){if(jq("form div.error :input:first").focus().length) return;jq("form.enableAutoFocus :input:not(.formTabs):visible:first").focus()});
