var advancedConsole=true;function throwError(type,text){if(type=='console'){}else if(type=='alert'){alert('Suggestion error: '+text);}else{throwError('console','illegal or no errorType given!');}}
var suggestionFields=[['txt_input','KEYUP','txt_suggestions2','TEMPLATE',7,'all','TO_DEFAULT',false,'TO_OBJECTNRCHECK'],['quick_input','KEYUP','quick_suggestions2','TEMPLATE',5,'all','TO_DEFAULT',false,'TO_OBJECTNRCHECK_QUICK']];var input_min_length=3;var requests=new Array();var suggestionElements=new Array();var indexToSuggestionID=new Array();var lastRequestedString='';var cleanedSearchString='';function requestSuggestions(requestValue,inputElementID,displayElement,responseGroup,outputType,maxResults,responseID,dedicatedBestMatch){if(requestValue&&requestValue!=lastRequestedString){lastRequestedString=requestValue;if(typeof requests[displayElement]!='undefined'){requests[displayElement].abort();}
requests[displayElement]=$.post('/xmlProcessing/Suggestion5/php/ajaxReceive.php',{requestValue:requestValue,responseGroup:responseGroup,maxResults:maxResults,outputType:outputType,responseID:responseID,dedicatedBestMatch:dedicatedBestMatch},function(response){var displayElementObject=$('#'+displayElement);if(response){displayElementCloseAllowed[responseID]=true;selectedSuggestionItem[responseID]=false;previousItem[responseID]=false;if(outputType!='TEMPLATE'){displayElementObject.html(response);displayElementObject.show();}else{var responseData=$.parseJSON(response);if(responseData.html){displayElementObject.html(responseData.html);suggestionElements[responseID]=responseData.js.suggestionElements;cleanedSearchString=responseData.cleanedSearchString;suggestionElements[responseID].inputElementID=inputElementID;indexToSuggestionID[responseID]=responseData.js.indexToSuggestionID;displayElementObject.show();}else{displayElementObject.hide();}}}else{displayElementObject.hide();}
delete requests[displayElement];});}}
var displayElementCloseAllowed=new Array(),selectedSuggestionItem=new Array(),previousItem=new Array();$(document).ready(function(){$.each(suggestionFields,function(index,value){var inputElementID=value[0];var eventType=value[1];var displayElement=value[2];var outputType=value[3];var maxResults=value[4];var responseGroup=value[5];var itemSelectFunction=value[6];var dedicatedBestMatch=value[7];var customSubmitFunction=value[8];var responseID=index;displayElementCloseAllowed[responseID]=true;selectedSuggestionItem[responseID]=false;previousItem[responseID]=false;var inputField=$('#'+inputElementID);if(inputField.length>0){if(displayElement!=null){if(eventType!=null){inputField.extend({getValue:function(){switch($(this).get(0).nodeName){case'INPUT':case'TEXTAREA':return $(this).val();default:return false;}},setValue:function(value){switch($(this).get(0).nodeName){case'INPUT':case'TEXTAREA':$(this).val(value);return true;default:return false;}},getAttribute:function(attributeName){switch(attributeName){case'INPUTELEMENTID':return inputElementID;case'RESPONSEID':return responseID;case'DISPLAYELEMENT':return displayElement;case'RESPONSEGROUP':return((responseGroup!=null)?responseGroup:'all');case'EVENTTYPE':return((eventType!=null)?eventType:'KEYUP');case'MAXRESULTS':return((maxResults>0)?maxResults:'all');case'OUTPUTTYPE':return((outputType!=null)?outputType:'PLAIN');case'CUSTOMSUBMITFUNCTION':return((customSubmitFunction!=null)?customSubmitFunction:'DEFAULT');case'ITEMSELECTFUNCTION':return((itemSelectFunction!=null)?itemSelectFunction:'DEFAULT');case'DEDICATEDBESTMATCH':return((dedicatedBestMatch!=null)?dedicatedBestMatch:false);}}});createRequestSuggestionEvent(inputField);}else{}}else{}
setEvents(inputField);}});});function createRequestSuggestionEvent(element){switch(element.getAttribute('EVENTTYPE')){case'KEYUP':element.keyup(function(event){var keyCode=event.keyCode;if(keyCode==46||keyCode==8||keyCode==0||(keyCode>=48&&keyCode<=90)){if(element.getValue().length>=input_min_length){requestSuggestions(element.getValue(),element.getAttribute('INPUTELEMENTID'),element.getAttribute('DISPLAYELEMENT'),element.getAttribute('RESPONSEGROUP'),element.getAttribute('OUTPUTTYPE'),element.getAttribute('MAXRESULTS'),element.getAttribute('RESPONSEID'),element.getAttribute('DEDICATEDBESTMATCH'));}else{$('#'+element.getAttribute('DISPLAYELEMENT')).hide();}}
$.customSubmit(element.getAttribute('CUSTOMSUBMITFUNCTION'),element);});break;}}
function setEvents(inputField){var localDisplayElement=$('#'+inputField.getAttribute('DISPLAYELEMENT'));var localResponseID=inputField.getAttribute('RESPONSEID');localDisplayElement.find('ul.suggestionOutput').find('li').live('mouseover mouseout click',function(event){switch(event.type){case'mouseover':displayElementCloseAllowed[localResponseID]=false;if(previousItem[localResponseID]){previousItem[localResponseID].removeClass('selectedSuggestionLiItem');previousItem[localResponseID]=false;}
$(this).addClass('selectedSuggestionLiItem');break;case'mouseout':displayElementCloseAllowed[localResponseID]=true;$(this).removeClass('selectedSuggestionLiItem');break;case'click':var idParts=this.id.split('_');if(typeof allowForceSubmit!="undefined"&&allowForceSubmit===true)forceSubmit=true;$.itemSelect(suggestionElements[localResponseID][idParts[1]],inputField.getAttribute('ITEMSELECTFUNCTION'),inputField);localDisplayElement.hide();break;}});inputField.bind('focus blur keydown click',function(event){switch(event.type){case'click':if(previousItem[localResponseID]!==false){previousItem[localResponseID].removeClass('selectedSuggestionLiItem');}
selectedSuggestionItem[localResponseID]=false;previousItem[localResponseID]=false;if(localDisplayElement.children().length>0){localDisplayElement.show();}
break;case'focus':if(localDisplayElement.children().length>0){localDisplayElement.show();}
break;case'blur':directSubmit=true;if(displayElementCloseAllowed[localResponseID]){if(selectedSuggestionItem[localResponseID]===false&&typeof indexToSuggestionID[localResponseID]!='undefined'&&((inputField.getValue()+'').toUpperCase()==(suggestionElements[localResponseID][indexToSuggestionID[localResponseID][1]].title+'').toUpperCase()||cleanedSearchString.toUpperCase()==(suggestionElements[localResponseID][indexToSuggestionID[localResponseID][1]].title+'').toUpperCase())){selectedSuggestionItem[localResponseID]=1;var localSuggestionElement=suggestionElements[localResponseID][indexToSuggestionID[localResponseID][selectedSuggestionItem[localResponseID]]];$.itemSelect(localSuggestionElement,inputField.getAttribute('ITEMSELECTFUNCTION'),inputField);}
closeSuggestionList(localDisplayElement,localResponseID);}
break;case'keydown':switch(event.keyCode){case 38:localDisplayElement.show();selectSuggestionItem(-1,localResponseID);break;case 40:localDisplayElement.show();selectSuggestionItem(1,localResponseID);break;case 13:if(selectedSuggestionItem[localResponseID]===false&&((inputField.getValue()+'').toUpperCase()==(suggestionElements[localResponseID][indexToSuggestionID[localResponseID][1]].title+'').toUpperCase()||cleanedSearchString.toUpperCase()==(suggestionElements[localResponseID][indexToSuggestionID[localResponseID][1]].title+'').toUpperCase())){selectedSuggestionItem[localResponseID]=1;}
if(selectedSuggestionItem[localResponseID]!==false){var localSuggestionElement=suggestionElements[localResponseID][indexToSuggestionID[localResponseID][selectedSuggestionItem[localResponseID]]];closeSuggestionList(localDisplayElement,localResponseID);$.itemSelect(localSuggestionElement,inputField.getAttribute('ITEMSELECTFUNCTION'),inputField);}
break;case 27:closeSuggestionList(localDisplayElement,localResponseID);break;}
break;}});}
function closeSuggestionList(localDisplayElement,localResponseID){if(previousItem[localResponseID]!==false)previousItem[localResponseID].removeClass('selectedSuggestionLiItem');selectedSuggestionItem[localResponseID]=false;previousItem[localResponseID]=false;localDisplayElement.hide();}
function selectSuggestionItem(direction,responseID){var itemCount=Object.size(suggestionElements[responseID]);if(itemCount){if(selectedSuggestionItem[responseID]===false){if(direction){selectedSuggestionItem[responseID]=1;}else{selectedSuggestionItem[responseID]=itemCount-1;}}else{var newItem=selectedSuggestionItem[responseID]+direction;if(newItem<itemCount&&newItem>0){selectedSuggestionItem[responseID]=newItem;}}}
if(previousItem[responseID])previousItem[responseID].removeClass('selectedSuggestionLiItem');previousItem[responseID]=$('#'+responseID+'_'+indexToSuggestionID[responseID][selectedSuggestionItem[responseID]]).addClass('selectedSuggestionLiItem');}
Object.size=function(obj){var size=0,key;for(key in obj){if(obj.hasOwnProperty(key))size++;}
return size;};$.customSubmit=function(submitFunction,inputField){switch(submitFunction){case'TO_OBJECTNRCHECK':toObjectNrCheck(inputField,false);break;case'TO_OBJECTNRCHECK_QUICK':toObjectNrCheck(inputField,true);break;default:defaultSubmit();break;}}
function defaultSubmit(){}
function toObjectNrCheck(inputField,quick){if(typeof searchPath!='undefined'&&typeof wwwDomain!='undefined'){$('#'+((quick==true)?'searchForm':'mainSearchForm')).attr('action',searchPath);}
if(isObjectNumber(inputField.getValue())){$('#'+((quick==true)?'searchForm':'mainSearchForm')).attr('action','/'+inputField.getValue());jQuery('#searchMethod').val('form');}else{jQuery('#searchMethod').val('form');}}
function isObjectNumber(str){var preg=/^(\d{7}[a-z]|\d{7}|\d{6}|[oO]02\d{2}[a-z]|[oO]01\d{3})$/;return preg.test(str);}
function onsubmitcheck()
{return true;}
$.itemSelect=function(suggestionElement,selectFunction,inputField){switch(selectFunction){case'TO_DEFAULT':toDefaultItemSelect(suggestionElement,inputField);break;default:copyTitleToInput(suggestionElement,inputField);defaultItemSelect(suggestionElement);break;}}
function copyTitleToInput(suggestionElement,inputField){inputField.setValue(suggestionElement.title);}
function defaultItemSelect(suggestionElement){}
function toDefaultItemSelect(suggestionElement,inputField){var latitude=isset(suggestionElement.options.latitude);var longitude=isset(suggestionElement.options.longitude);var tr_latitude=isset(suggestionElement.options.tr_latitude);var tr_longitude=isset(suggestionElement.options.tr_longitude);var bl_latitude=isset(suggestionElement.options.bl_latitude);var bl_longitude=isset(suggestionElement.options.bl_longitude);var countryID=isset(suggestionElement.options.countryID);var locationID=isset(suggestionElement.options.locationID);var url=isset(suggestionElement.options.url);var searchUrl=isset(suggestionElement.options.searchUrl);var detailObjectType=null;var detailPool=null;var detailPetAllowed=null;var detailDistBeach=null;var detailSkiing=null;var detailFishing=null;if(isset(suggestionElement.searchFilter))
{detailObjectType=isset(suggestionElement.searchFilter.detailObjectType);detailPool=isset(suggestionElement.searchFilter.detailPool);detailPetAllowed=isset(suggestionElement.searchFilter.detailPetAllowed);detailDistBeach=isset(suggestionElement.searchFilter.detailDistBeach);detailSkiing=isset(suggestionElement.searchFilter.detailSkiing);detailFishing=isset(suggestionElement.searchFilter.detailFishing);}
var coordsJoined=[latitude,longitude,tr_latitude,tr_longitude,bl_latitude,bl_longitude];var typed=inputField.val();copyTitleToInput(suggestionElement,inputField);if(locationID)jQuery('input[name="hiddenLocationID"]').val(locationID);if(countryID)jQuery('input[name="hiddenCountryID"]').val(countryID);if(latitude)jQuery('input[name="latitude"]').val(latitude);if(longitude)jQuery('input[name="longitude"]').val(longitude);if(longitude&&latitude)jQuery('input[name="searchMethod"]').val('coordinates');var appendSearchform=(((inputField.attr('id')=="quick_input")&&$('#searchForm').length>0)?$('#searchForm'):$('#mainSearchForm'));var directSubmit=false;if(searchUrl!='')
{appendSearchform.attr("action",searchUrl);if(longitude&&latitude)jQuery('input[name="searchMethod"]').val(searchUrl);}
if(detailPool)
{var setPool=false;if(jQuery('input[name="detailPool"]').length>0)
{jQuery('input[name="detailPool"]').attr('checked',true);setPool=true;}
if(jQuery('input[name="pool"]').length>0)
{jQuery('input[name="pool"]').attr('checked',true);setPool=true;}
if(setPool==false)
{appendSearchform.append('<input type="hidden" name="detailPool" value="'+detailPool+'">');}}
if(detailSkiing)
{var setSki=false;if(jQuery('input[name="detailSkiing"]').length>0)
{jQuery('input[name="detailSkiing"]').attr('checked',true);setSki=true;}
if(jQuery('input[name="ski"]').length>0)
{jQuery('input[name="ski"]').attr('checked',true);setSki=true;}
if(setSki==false)
{appendSearchform.append('<input type="hidden" name="detailSkiing" value="'+detailSkiing+'">');}}
if(detailPetAllowed)
{var setPetAllowed=false;if(jQuery('input[name="detailPetAllowed"]').length>0)
{jQuery('input[name="detailPetAllowed"]').attr('checked',true);setPetAllowed=true;}
if(jQuery('input[name="pets"]').length>0)
{jQuery('input[name="pets"]').attr('checked',true);setPetAllowed=true;}
if(setPetAllowed==false)
{appendSearchform.append('<input type="hidden" name="detailPetAllowed" value="'+detailPetAllowed+'">');}}
if(detailFishing)
{if(jQuery('input[name="detailFishing"]').length>0)jQuery('input[name="detailFishing"]').attr('checked',true);else appendSearchform.append('<input type="hidden" name="detailFishing" value="'+detailFishing+'">');}
if(detailDistBeach)
{var setBeach=false;var beachAvailable=false;if(jQuery('input[name="detailDistBeach"]').length>0)
{jQuery('input[name="detailDistBeach"]').val(detailDistBeach);if(jQuery('input[name="detailDistBeach"]').val()==detailDistBeach)setBeach=true;beachAvailable=true;}
if(jQuery('select[name="detailDistBeach"]').length>0)
{jQuery('select[name="detailDistBeach"]').val(detailDistBeach);if(jQuery('select[name="detailDistBeach"]').val()==detailDistBeach)setBeach=true;beachAvailable=true;}
if(setBeach==false)
{appendSearchform.append('<input type="hidden" name="detailDistBeach" value="'+detailDistBeach+'">');}}
if(detailObjectType)
{var setObjectType=false;var objectTypeAvailable=false;if(jQuery('input[name="detailObjectTypes[]"]').length>0)
{objectTypeAvailable=true;jQuery('input[name="detailObjectTypes[]"]').val(detailObjectType);if(jQuery('input[name="detailObjectTypes[]"]').val()==detailObjectType)setObjectType=true;}
if(jQuery('select[name="detailObjectTypes[]"]').length>0)
{objectTypeAvailable=true;jQuery('select[name="detailObjectTypes[]"]').val(detailObjectType);if(jQuery('select[name="detailObjectTypes[]"]').val()==detailObjectType)setObjectType=true;}
if(setObjectType==false)
{appendSearchform.append('<input type="hidden" name="detailObjectTypes[]" value="'+detailObjectType+'">');}}
$.post('/xmlProcessing/Suggestion5/php/benchmarkReceive.php',{typed:typed,klicked:suggestionElement.title});if((inputField.attr('id')=="quick_input")&&$('#searchForm').length>0)appendSearchform.submit();}
function isset(variable){if(typeof variable!='undefined'&&variable!=null&&variable!='undefined'){return variable;}else{return false;}}
