var states_geocodes=[{"code":"AL","name":"ALABAMA","lat":"32.7990","lon":"-86.8073"},{"code":"AK","name":"ALASKA","lat":"61.3850","lon":"-152.2683"},{"code":"AZ","name":"ARIZONA","lat":"33.7712","lon":"-111.3877"},{"code":"AR","name":"ARKANSAS","lat":"34.9513","lon":"-92.3809"},{"code":"CA","name":"CALIFORNIA","lat":"36.1700","lon":"-119.7462"},{"code":"CO","name":"COLORADO","lat":"39.0646","lon":"-105.3272"},{"code":"CT","name":"CONNECTICUT","lat":"41.5834","lon":"-72.7622"},{"code":"DE","name":"DELAWARE",
"lat":"39.3498","lon":"-75.5148"},{"code":"DC","name":"WASHINGTON D.C.","lat":"38.8964","lon":"-77.0262"},{"code":"FL","name":"FLORIDA","lat":"27.8333","lon":"-81.7170"},{"code":"GA","name":"GEORGIA","lat":"32.9866","lon":"-83.6487"},{"code":"HI","name":"HAWAII","lat":"21.1098","lon":"-157.5311"},{"code":"ID","name":"IDAHO","lat":"44.2394","lon":"-114.5103"},{"code":"IA","name":"IOWA","lat":"42.0046","lon":"-93.2140"},{"code":"IL","name":"ILLINOIS","lat":"40.3363","lon":"-89.0022"},{"code":"IN","name":"INDIANA",
"lat":"39.8647","lon":"-86.2604"},{"code":"KS","name":"KANSAS","lat":"38.5111","lon":"-96.8005"},{"code":"KY","name":"KENTUCKY","lat":"37.6690","lon":"-84.6514"},{"code":"LA","name":"LOUISIANA","lat":"31.1801","lon":"-91.8749"},{"code":"ME","name":"MAINE","lat":"44.6074","lon":"-69.3977"},{"code":"MD","name":"MARYLAND","lat":"39.0724","lon":"-76.7902"},{"code":"MA","name":"MASSACHUSETTS","lat":"42.2373","lon":"-71.5314"},{"code":"MI","name":"MICHIGAN","lat":"43.3504","lon":"-84.5603"},{"code":"MN",
"name":"MINNESOTA","lat":"45.7326","lon":"-93.9196"},{"code":"MS","name":"MISSISSIPPI","lat":"32.7673","lon":"-89.6812"},{"code":"MO","name":"MISSOURI","lat":"38.4623","lon":"-92.3020"},{"code":"MT","name":"MONTANA","lat":"46.9048","lon":"-110.3261"},{"code":"NE","name":"NEBRASKA","lat":"41.1289","lon":"-98.2883"},{"code":"NV","name":"NEVADA","lat":"38.4199","lon":"-117.1219"},{"code":"NH","name":"NEW HAMPSHIRE","lat":"43.4108","lon":"-71.5653"},{"code":"NJ","name":"NEW JERSEY","lat":"40.3140","lon":"-74.5089"},
{"code":"NM","name":"NEW MEXICO","lat":"34.8375","lon":"-106.2371"},{"code":"NY","name":"NEW YORK","lat":"42.1497","lon":"-74.9384"},{"code":"NC","name":"NORTH CAROLINA","lat":"35.6411","lon":"-79.8431"},{"code":"ND","name":"NORTH DAKOTA","lat":"47.5362","lon":"-99.7930"},{"code":"OH","name":"OHIO","lat":"40.3736","lon":"-82.7755"},{"code":"OK","name":"OKLAHOMA","lat":"35.5376","lon":"-96.9247"},{"code":"OR","name":"OREGON","lat":"44.5672","lon":"-122.1269"},{"code":"PA","name":"PENNSYLVANIA","lat":"40.5773",
"lon":"-77.2640"},{"code":"RI","name":"RHODE ISLAND","lat":"41.6772","lon":"-71.5101"},{"code":"SC","name":"SOUTH CAROLINA","lat":"33.8191","lon":"-80.9066"},{"code":"SD","name":"SOUTH DAKOTA","lat":"44.2853","lon":"-99.4632"},{"code":"TN","name":"TENNESSEE","lat":"35.7449","lon":"-86.7489"},{"code":"TX","name":"TEXAS","lat":"31.1060","lon":"-97.6475"},{"code":"UT","name":"UTAH","lat":"40.1135","lon":"-111.8535"},{"code":"VT","name":"VERMONT","lat":"44.0407","lon":"-72.7093"},{"code":"VA","name":"VIRGINIA",
"lat":"37.7680","lon":"-78.2057"},{"code":"WA","name":"WASHINGTON","lat":"47.3917","lon":"-121.5708"},{"code":"WI","name":"WISCONSIN","lat":"44.2563","lon":"-89.6385"},{"code":"WV","name":"WEST VIRGINIA","lat":"38.4680","lon":"-80.9696"},{"code":"WY","name":"WYOMING","lat":"42.7475","lon":"-107.2085"}];function initializeGeocoder(){geo=new google.maps.Geocoder}var SuggestionsProvider=Class.create();
SuggestionsProvider.prototype={suggestionsTitle:null,initialize:function(suggestionsTitle){this.suggestionsTitle=suggestionsTitle},getSuggestions:function(criteria,callback){},formatSuggestion:function(record,keyword){},formatSuggestionsTitle:function(record,keyword){}};var StatesSuggestionsProvider=Class.create();
StatesSuggestionsProvider.prototype=Object.extend(new SuggestionsProvider,{data:null,initialize:function(suggestionsTitle,data){this.suggestionsTitle=suggestionsTitle;this.data=data},getSuggestions:function(query,callback){var results=[];var nKwd=query.keyword.replace(/^\s+|\s+$/g,"");for(var i=0;i<this.data.length;i++)if(this.match(this.data[i].code,this.data[i].name,nKwd))results[results.length]=this.data[i];callback.call(this,results)},formatSuggestion:function(record,keyword){var label=record.name.toUpperCase()+
"<SPAN> "+UnifiedSearchMessages.centerOfState+"</SPAN>";var value="::"+record.lon+":"+record.lat+":"+record.code;return new Option(label,value)},formatSuggestionsTitle:function(optionRecord,keyword){var label=optionRecord.text;var value=optionRecord.value;return new Option(label,value)},match:function(code,name,keyword){var match=code.toUpperCase().indexOf(keyword.toUpperCase())==0||name.toUpperCase().indexOf(keyword.toUpperCase())==0;return match}});var GeocodingSuggestionsProvider=Class.create();
GeocodingSuggestionsProvider.prototype=Object.extend(new SuggestionsProvider,{initialize:function(suggestionsTitle){this.suggestionsTitle=suggestionsTitle},getSuggestions:function(query,callback){if(geo)geo.geocode({"address":query.keyword+",USA"},function(result,status){if(status==google.maps.GeocoderStatus.OK)callback.call(this,result);else callback.call(this,null)})},formatSuggestion:function(record,keyword){var label=record.formatted_address.toUpperCase();var value="::"+record.geometry.location.lng()+
":"+record.geometry.location.lat()+":";return new Option(label,value)},formatSuggestionsTitle:function(optionRecord,keyword){var label=optionRecord.text+"&nbsp;&nbsp;<img src='images/google_power.png' alt='"+UnifiedSearchMessages.poweredByGoogle+"'  align='absmiddle'/>";var value=optionRecord.value;return new Option(label,value)}});var AjaxSuggestionsProvider=Class.create();
AjaxSuggestionsProvider.prototype=Object.extend(new SuggestionsProvider,{action:null,_ajaxRequest:null,initialize:function(suggestionsTitle,action){this.suggestionsTitle=suggestionsTitle;this.action=action},getSuggestions:function(query,callback){var actionURL=this.action+"?location="+escape(query.keyword);this._ajaxRequest=new Ajax.Request(actionURL,{method:"post",onComplete:function(result){if(result){var records=eval(result.responseText);callback.call(this,records)}else callback.call(this,[])}})},
formatSuggestion:function(record,keyword){var label=record.parkName.toUpperCase();return new Option(label,record.position)},formatSuggestionsTitle:function(optionRecord,keyword){return optionRecord}});var PlacesSuggestionsProvider=Class.create();
PlacesSuggestionsProvider.prototype=Object.extend(new SuggestionsProvider,{service:null,naLocation:null,initialize:function(suggestionsTitle,action){this.suggestionsTitle=suggestionsTitle;this.naLocation=new google.maps.LatLng(-33.8665433,151.1956316);map=new google.maps.Map(document.getElementById("locationMap"),{mapTypeId:google.maps.MapTypeId.ROADMAP,center:this.naLocation,zoom:15});this.service=new google.maps.places.PlacesService(map)},getSuggestions:function(query,callback){var request={name:query.keyword,
location:this.naLocation,radius:"5000000",types:["political","campground","locality","amusement_park","establishment","geocode"]};this.service.search(request,function(result,status){if(status==google.maps.places.PlacesServiceStatus.OK)callback.call(this,result)})},formatSuggestion:function(record,keyword){var label=record.name.toUpperCase()+", "+record.vicinity;var lat=record.geometry.location.lat();var lng=record.geometry.location.lng();var value="::"+lng+":"+lat+":";return new Option(label,value)}});
var dropdownInstances={};var DropdownList=Class.create();
DropdownList.prototype={id:null,targetEl:null,options:[],container:null,value:null,selectedIndex:null,drawn:false,navIndex:-1,_lastNavIndex:-1,_keepOnBlur:false,initialize:function(id,targetEl){this.id=id;this.targetEl=targetEl;this.container=$(targetEl.id+"_container");this.container.style.position="absolute";this.container.style.display="none";this.resetPosition();dropdownInstances[id]=this;Event.observe(this.targetEl,window.opera?"keypress":"keydown",this.onKeyPress.bind(this));Event.observe(window,
"resize",this.resetPosition.bind(this));Event.observe(window,"scroll",this.resetPosition.bind(this))},addOption:function(option){this.options[this.options.length]=option;this.drawn=false},clearOptions:function(){this.options=[]},resetPosition:function(){var pos=Position.cumulativeOffset(this.targetEl);pos.push(pos[0]+this.targetEl.offsetWidth);pos.push(pos[1]+this.targetEl.offsetHeight);this.container.style.left=""+pos[0]+"px";this.container.style.top=""+pos[3]+"px"},redraw:function(){if(this.options&&
this.options.length>0){var content=[];var crtOption=null;var crtLabel=null;var evString="";for(var i=0;i<this.options.length;i++)try{crtOption=this.options[i];crtLabel=crtOption.value==""?crtOption.text:this.highlight(crtOption.text,crtOption.value,this.targetEl.value);evString="onmouseout=\"dropdownInstances['"+this.id+"'].onMouseOut("+i+')" onmouseover="dropdownInstances[\''+this.id+"'].onMouseOver("+i+')" onMouseDown="dropdownInstances[\''+this.id+"'].onClick("+i+')"';if(this.selectedIndex==i)content.push('<div class="selected"  '+
evString+" >"+crtLabel+"</div>");else{var cls=crtOption.value==""?"unselectable":"selectable";content.push('<div class="'+cls+'" '+evString+" >"+crtLabel+"</div>")}}catch(err){}this.container.innerHTML=content.join("");this.drawn=true}else this.container.innerHTML=""},highlight:function(label,value,searchTerm){var re=searchTerm.replace(/^\s+|\s+$/g,"");if(value.indexOf("::")==0&&label.toUpperCase().indexOf("<STRONG>")<0){var ind=label.indexOf("<SPAN>");var uVal=ind<0?label:label.substring(0,ind).toUpperCase();
var higl=uVal.replace(re.toUpperCase(),function(match){return"<strong>"+match+"</strong>"});var retVal=ind<0?higl:higl+label.substring(ind);if(retVal.indexOf("<strong>")==0)return retVal}return label},show:function(){if(!this.drawn)this.redraw();this.resetPosition();this.container.style.display="inline"},hide:function(){this.container.style.display="none";this._keepOnBlur=false},getSelectedOption:function(){try{return this.options[this.selectedIndex]}catch(err){return null}},setSelectedIndex:function(index){if(index<
this.options.length){try{var item=this.container.childNodes[this.selectedIndex];item.className=""}catch(err){}this.selectedIndex=index;this.value=this.options[index].value;item=this.container.childNodes[this.selectedIndex];item.className="selected"}},setValue:function(value){var newIndex=-1;for(var i=0;i<this.options.length;i++)if(this.options[i].value=value)newIndex=i;if(newIndex>=0)this.setSelectedIndex(newIndex)},isSelectableOption:function(index){try{var item=this.container.childNodes[index];
return item.className.indexOf("select")==0}catch(err){return false}},onMouseOver:function(index){try{if(this.isSelectableOption(index))for(var i=0;i<this.container.children.length;i++){var item=this.container.childNodes[i];var oInd=item.className.indexOf("_over");if(index==i){if(oInd==-1){item.className=item.className+"_over";this.navIndex=i}}else if(oInd>=0)item.className=item.className.substring(0,oInd)}}catch(err){}},onMouseOut:function(index){try{this._lastNavIndex(index)}catch(err){}},onClick:function(index){this.select(index,
"mouse")},select:function(index,device){if(this.isSelectableOption(index)){this.setSelectedIndex(index);this.hide();this.reset();this.onSelect(device)}else{this._keepOnBlur=true;this.show()}},onSelect:function(device){},isVisible:function(){return this.container.style.display!="none"},onKeyPress:function(e){if(!this.isVisible())switch(e.keyCode){case Event.KEY_UP:case Event.KEY_DOWN:case Event.KEY_RETURN:return false;break;default:return}else{this.drawn=false;switch(e.keyCode){case Event.KEY_UP:this.moveUp();
break;case Event.KEY_DOWN:this.moveDown();break;case Event.KEY_RETURN:if(this.navIndex>=0)this.select(this.navIndex,"keyboard");break;default:return}}Event.stop(e)},moveUp:function(){if(this.options.length>0){this.onMouseOut(this.navIndex);this.navIndex=this.navIndex-1;if(this.navIndex<0)this.navIndex=this.options.length-1;if(this.isSelectableOption(this.navIndex))this.onMouseOver(this.navIndex);else this.moveUp()}},moveDown:function(){if(this.options.length>0){this.onMouseOut(this.navIndex);this.navIndex=
this.navIndex+1;if(this.navIndex>=this.options.length)this.navIndex=0;if(this.isSelectableOption(this.navIndex))this.onMouseOver(this.navIndex);else this.moveDown()}},reset:function(){this.navIndex=-1}};var CompositeAutoComplete=Class.create();
CompositeAutoComplete.prototype={dataProviders:[],selector:null,input:null,inputHidden:null,resultsMap:{},timeout:null,options:{minQueryLength:[2,2,4],suggestions:[5,5,5],delay:150,responseDelay:250},_minQ:0,_maxQ:0,_callQuery:null,_responseTimestamp:[],_currentMessage:null,_drawn:false,_dropNewSuggestions:false,_submitted:false,_mustSubmit:false,_hasSuggestions:false,_cache:{},_descriptionLoaderMap:{},initialize:function(dataProviders,input,inputHidden,options){this.dataProviders=dataProviders;this.input=
input;this.inputHidden=inputHidden;this.setOptions(options);this.input.autocomplete="off";this.selector=new DropdownList("unifSearchLocation",input);var thisObj=this;this.selector.onSelect=function(device){thisObj._dropNewSuggestions=true;thisObj.loadingStopped();selOption=thisObj.selector.getSelectedOption();thisObj.input.value=thisObj.extractLocationName(selOption.text,selOption.value);thisObj.inputHidden.value=selOption.value;thisObj._mustSubmit=false;if(device=="mouse")setTimeout(function(){thisObj.setLocationFocus();
thisObj._mustSubmit=true},150)};Event.observe(this.input,"keyup",this.onKeyUp.bindAsEventListener(this));Event.observe(this.input,"blur",this.onBlur.bindAsEventListener(this));Event.observe(this.input,"focus",this.onFocus.bindAsEventListener(this));Event.observe(this.input,"change",this.onChange.bindAsEventListener(this))},setLocationFocus:function(){this.input.blur();if(this.input.setSelectionRange)this.input.setSelectionRange(0,0);this.input.focus();this.onFocus()},setOptions:function(opts){this.options.minQueryLength=
opts.minQueryLength?opts.minQueryLength:this.options.minQueryLength;this.options.suggestions=opts.suggestions?opts.suggestions:this.options.suggestions;this.options.delay=opts.delay?opts.delay:this.options.delay;this.options.responseDelay=opts.responseDelay?opts.responseDelay:this.options.responseDelay;this._maxQ=this.getMaximumValue(this.options.minQueryLength);this._minQ=this.getMinimumValue(this.options.minQueryLength)},setResponseTimestamp:function(){this._responseTimestamp[this._responseTimestamp.length]=
(new Date).getTime()},extractLocationName:function(label,value){label=label.replace(/<strong>/g,"");label=label.replace(/<.strong>/g,"");label=label.replace(/<STRONG>/g,"");label=label.replace(/<.STRONG>/g,"");var isNotFacility=value.indexOf("::")==0;var spInd=label.indexOf("<SPAN>");if(spInd>=0)if(isNotFacility){label=label.replace("<SPAN>","");label=label.replace("</SPAN>","")}else label=label.substring(0,spInd);return label},onFocus:function(){if(this.input.value.length==0)this.setMessage("<div class='message'>"+
UnifiedSearchMessages.locationDirective+"</div>",true)},onChange:function(){if(!this._dropNewSuggestions)this.inputHidden.value="";this._dropNewSuggestions=false},onMouseDown:function(event){this.selector._keepOnBlur=true;this.onBlur(event)},onBlur:function(event){var thisObj=this;setTimeout(function(){if(!thisObj.selector._keepOnBlur){thisObj.selector.hide();thisObj.loadingStopped();thisObj._dropNewSuggestions=true}else{thisObj.input.focus();thisObj.selector._keepOnBlur=false;thisObj.onFocus()}},
100)},onKeyUp:function(event){this._dropNewSuggestions=false;this.makeSuggestions(event)&&Event.stop(event)},submit:function(){},makeSuggestions:function(event){this.resultsMap={};if(this.timeout){clearTimeout(this.timeout);this.timeout=null}var key=event.keyCode;switch(key){case Event.KEY_LEFT:case Event.KEY_RIGHT:case Event.KEY_DOWN:case Event.KEY_UP:return false;break;case Event.KEY_RETURN:this.loadingStopped();this._dropNewSuggestions=true;if(this._mustSubmit)this.submit();else{this._mustSubmit=
true;return false}break;case Event.KEY_ESC:this.selector.hide();return false;break;case Event.KEY_BACKSPACE:case Event.KEY_DELETE:this.inputHidden.value="";if(this.input.value.length==0){this.setMessage("<div class='message'>"+UnifiedSearchMessages.locationDirective+"</div>");return false;break}else if(!this.shouldAutocomplete()){this.setMessage("<div class='message'>"+UnifiedSearchMessages.locationDirective+"</div>");return false;break}default:this._mustSubmit=true;break}if(this.shouldAutocomplete())this.timeout=
setTimeout(this.getSuggestions.bind(this),this.options.delay);else{clearTimeout(this.timeout);this.timeout=null;this.setMessage("<div class='message'>"+UnifiedSearchMessages.locationDirective+"</div>")}return false},setMessage:function(msg,showAnyway){var showCond=showAnyway||!this._dropNewSuggestions;if(showCond)if(msg!=this._currentMessage){this._currentMessage=msg;this.selector.clearOptions();this.selector.show();this.selector.container.innerHTML=msg}else this.selector.container.style.display=
"inline"},setNoSimpleMatchMessage:function(){var nVal=this.normalizeCharacters(this.input.value);var valCount=nVal.replace(/[^a-z0-9]+/g,"").length;var shouldDisplay=!this._submitted;if(shouldDisplay)if(valCount>=this._maxQ)this.setMessage('<SPAN class="warn msg"> '+UnifiedSearchMessages.noSimpleMatch+"</SPAN>");else this.setMessage("<div class='message'>"+UnifiedSearchMessages.locationDirective+"</div>")},loadingStarted:function(){if(!this._dropNewSuggestions)$("loadingLocations").style.display=
"block"},loadingStopped:function(){$("loadingLocations").style.display="none"},setSearchingMessage:function(searchMsg){this.loadingStarted();var thisObj=this;if(this._currentMessage!=searchMsg){var thisObj=this;setTimeout(function(){if(searchMsg==thisObj._currentMessage&&thisObj.selector.options.length==0)thisObj.setNoSimpleMatchMessage();thisObj.loadingStopped()},1E4)}},shouldAutocomplete:function(){this.inputHidden.value="";var nVal=this.normalizeCharacters(this.input.value);var valCount=nVal.replace(/[^a-z0-9]+/g,
"").length;var shouldAuto=!this._submitted&&valCount>=this._minQ;if(shouldAuto)this.setSearchingMessage();else this.loadingStopped();return shouldAuto},normalizeCharacters:function(str){var nStr=str.toLowerCase();for(var i=0;i<NORMALIZATION_MAPPINGS.length;i++)nStr=nStr.replace(new RegExp("["+NORMALIZATION_MAPPINGS[i].mapping+"]","ig"),NORMALIZATION_MAPPINGS[i].character);return nStr},getMinimumValue:function(numArray){var min=100;if(numArray&&numArray.length>1)for(var i=0;i<numArray.length;i++)min=
numArray[i]<min?numArray[i]:min;else if(numArray.length==1)min=numArray[0];return min},getMaximumValue:function(numArray){var max=0;if(numArray&&numArray.length>1)for(var i=0;i<numArray.length;i++)max=numArray[i]>max?numArray[i]:max;else if(numArray.length==1)max=numArray[0];return max},getSuggestions:function(){var query={keyword:this.normalizeCharacters(this.input.value)};if(this._callQuery&&query.keyword==this._callQuery.keyword&&this.drawCount==this.dataProviders.length){this.loadingStopped();
return}else{this._callQuery=query;this._responseTimestamp=[];this._hasSuggestions=false;this._drawn=false;if(!this.shouldAutocomplete())return;this.selector.clearOptions(false);var thisObj=this;for(var i=0;i<thisObj.dataProviders.length;i++)if(query.keyword.length>=thisObj.options.minQueryLength[i]&&thisObj.options.suggestions[i]>0)try{cachedRes=thisObj.getCachedResults(i,query);if(cachedRes)this.onSuggestions(thisObj,i,query,cachedRes);else this.getResults(i,query)}catch(err){eval('thisObj.resultsMap["'+
i+'"] = [];');thisObj.setResponseTimestamp()}else{eval('thisObj.resultsMap["'+i+'"] = [];');thisObj.setResponseTimestamp()}}},getCacheKey:function(provIndex,query){return provIndex+":"+escape(query.keyword)},getCachedResults:function(provIndex,query){return eval('this._cache["'+this.getCacheKey(provIndex,query)+'" ]')},getResults:function(index,query){var thisObj=this;this.dataProviders[index].getSuggestions(query,function(objData){thisObj.onSuggestions(thisObj,index,query,objData)})},onSuggestions:function(thisObj,
index,query,objData){if(!thisObj._dropNewSuggestions){if(!thisObj._hasSuggestions&&objData&&objData.length>0)thisObj._hasSuggestions=true;eval('thisObj._cache[ "'+thisObj.getCacheKey(index,query)+'"] = objData');eval('thisObj.resultsMap["'+index+'"] = objData;');crtTimeout=thisObj._responseTimestamp.length==0?thisObj.options.responseDelay:0;thisObj.setResponseTimestamp();if(objData&&objData.length>0){thisObj._currentMessage=null;thisObj._drawn=false}setTimeout(function(){if(!thisObj._drawn){if(thisObj._hasSuggestions)thisObj.drawResults();
if(thisObj._responseTimestamp.length==thisObj.dataProviders.length){if(!thisObj._hasSuggestions)thisObj.setNoSimpleMatchMessage();thisObj.loadingStopped();thisObj.selector.reset();thisObj._drawn=true}}},crtTimeout)}},drawResults:function(){this.selector.clearOptions();for(var i=0;i<this.dataProviders.length;i++){var results=this.getProviderResults(i);if(results&&results.length>0)this.drawProviderResults(this.dataProviders[i],results,results.length)}this.loadingStopped()},drawProviderResults:function(provider,
records,maxRes){this.selector.drawn=false;this._currentMessage=null;if(records&&records.length>0)if(maxRes>0){if(this.selector.options.length>0)this.selector.addOption(new Option("&nbsp;",""));this.selector.addOption(provider.formatSuggestionsTitle(new Option(provider.suggestionsTitle,"")));for(var i=0;i<maxRes;i++)this.selector.addOption(provider.formatSuggestion(records[i],this.input.value))}this.selector.show()},getProviderResults:function(index){try{var results=eval('this.resultsMap["'+index+
'"]');if(!isNaN(results.length))return results}catch(err){}return null}};Object.extend(Event,{KEY_BACKSPACE:8,KEY_TAB:9,KEY_RETURN:13,KEY_ESC:27,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_DELETE:46,KEY_SHIFT:16,KEY_CONTROL:17,KEY_CAPSLOCK:20,KEY_SPACE:32});
var UnifiedSearchMessages={locationDirective:"Please enter a facility name or an address (which could include "+"any of the following: street address, city, state, zip code) that you would like to search near",noSimpleMatch:'No simple matches. Edit your input or <a href="#" onMouseDown="UnifSearchEngine.submit()" >try matching alternative names of places</a>',loading:"Loading...",searching:"Searching...",retrieving:"Retrieving...",updating:"Updating...",centerOfState:"",withinState:"Within State",
facilityNames:"Facility Names",addresses:"Addresses",poweredByGoogle:"Powered by Google"};ValuesSynchronizer=Class.create();
ValuesSynchronizer.prototype={fieldIds:null,currentValue:null,initialize:function(fieldIds){this.fieldIds=fieldIds;try{if(this.fieldIds!=null&&this.fieldIds.length>0)for(var i=0;i<this.fieldIds.length;i++)Event.observe(this.fieldIds[i],"change",this.onChange.bindAsEventListener(this))}catch(err){}},onChange:function(event){var newValue;var sourceEl;if(!event.target)sourceEl=event.srcElement;else sourceEl=event.target;if(sourceEl.type=="checkbox")newValue=sourceEl.checked;else newValue=sourceEl.value;
if(this.currentValue!=newValue){this.currentValue=newValue;var thisObj=this;var edType=sourceEl.type;for(var i=0;i<this.fieldIds.length;i++)if($(thisObj.fieldIds[i]))this.setValue(edType,sourceEl,$(thisObj.fieldIds[i]))}},setValue:function(elType,sourceEl,targetEl){if(elType=="checkbox")targetEl.checked=sourceEl.checked;else if(elType=="select-one")targetEl.options.selectedIndex=sourceEl.options.selectedIndex;else targetEl.value=sourceEl.value}};SiteAttributesController=Class.create();
SiteAttributesController.prototype={initialize:function(){},selectLookingFor:function(clr){try{var intOpts=$("lookingFor").options;var crtAttrsId=null;for(var i=0;i<intOpts.length;i++){crtAttrsId="camping_"+intOpts[i].value+"_";if($(crtAttrsId)){if(intOpts.selectedIndex==i)$(crtAttrsId).style.display="block";else $(crtAttrsId).style.display="none";try{if($(crtAttrsId+"moreOptions").checked)$(crtAttrsId+"secattrs").style.display="block";else $(crtAttrsId+"secattrs").style.display="none"}catch(err){}}}}catch(err){}},
showMoreOptions:function(cb,divId){if(cb.checked)$(divId).style.display="block";else $(divId).style.display="none"},clearMoreOptions:function(form,divId){var fPref=divId.substring(0,divId.lastIndexOf("_"));var formElements=form.elements;for(i=0;i<formElements.length;i++)if(formElements[i].name.indexOf(fPref)){fieldType=formElements[i].type.toLowerCase();switch(fieldType){case "text":formElements[i].value="";break;case "checkbox":if(formElements[i].checked)formElements[i].checked=false;break;case "select-one":formElements[i].selectedIndex=
0;break;default:break}}}};UnifiedSearchEngine=Class.create();
UnifiedSearchEngine.prototype={suggestionsProviders:[],_responsesCounter:0,_persistentFields:",currentMaximumWindow,contractCode,parkId,siteTypeFilter,submitSiteForm,search,",autocomplete:null,siteAttributesController:new SiteAttributesController,initialize:function(locAutocOptions){try{if(locAutocOptions){this.suggestionsProviders=[new StatesSuggestionsProvider(UnifiedSearchMessages.withinState,states_geocodes),new AjaxSuggestionsProvider(UnifiedSearchMessages.facilityNames,"/ajax/AutoCompleteRecreation"),
new GeocodingSuggestionsProvider(UnifiedSearchMessages.addresses)];var thisObj=this;var threshold=locAutocOptions.threshold;if(locAutocOptions.suggestions[0]==0)threshold[0]=Number.MAX_VALUE;if(locAutocOptions.suggestions[1]==0)threshold[1]=Number.MAX_VALUE;if(locAutocOptions.suggestions[2]==0)threshold[2]=Number.MAX_VALUE;this.autocomplete=new CompositeAutoComplete(this.suggestionsProviders,locAutocOptions.inputElement,locAutocOptions.positionElement,{minQueryLength:threshold,suggestions:locAutocOptions.suggestions,
delay:locAutocOptions.triggerDelay,responseDelay:locAutocOptions.responseDelay});this.autocomplete.drawResults=function(){thisObj.drawResults()};this.autocomplete.submit=function(){thisObj.submit()}}new ValuesSynchronizer(["lengthOfStay","dayUseLengthOfStay"]);new ValuesSynchronizer(["campingDateFlex","dayUseFlex"]);this.restoreState();this.selectInterest();this.selectLookingFor()}catch(err){}},restoreState:function(){},drawResults:function(){this.autocomplete.selector.options=[];control0=this.autocomplete.options.suggestions[1];
control1=this.autocomplete.options.suggestions[2];var maxListResults=control0+control1;var firstProvResults=this.autocomplete.getProviderResults(1);var secProvResults=this.autocomplete.getProviderResults(2);var firstCount=firstProvResults?firstProvResults.length:0;var secondCount=secProvResults?secProvResults.length:0;var totalCount=firstCount+secondCount;if(control0<=0){firstCount=0;if(secondCount>maxListResults)secondCount=maxListResults}else if(control1<=0){if(firstCount>maxListResults)firstCount=
maxListResults;secondCount=0}else if(totalCount>maxListResults)if(firstCount>=control0)if(secondCount>=control1){firstCount=control0;secondCount=control1}else{firstCount=maxListResults-secondCount;if(firstCount>firstProvResults.length)firstCount=firstProvResults.length}else{secondCount=maxListResults-firstCount;if(secondCount>secProvResults.length)secondCount=secProvResults.length}var statesResults=this.autocomplete.getProviderResults(0);var statesResultsCount=statesResults?statesResults.length:0;
if(statesResultsCount>0||firstCount>0||secondCount>0){this.autocomplete.drawProviderResults(this.suggestionsProviders[0],statesResults,statesResultsCount);this.autocomplete.drawProviderResults(this.suggestionsProviders[1],firstProvResults,firstCount);this.autocomplete.drawProviderResults(this.suggestionsProviders[2],secProvResults,secondCount)}},getCurrentElementToHide:function(){var elToHide;if($("usearch_info"))elToHide="usearch_info";else if($("suggestions_content"))elToHide="suggestions_content";
else if($("usearch_results"))elToHide="usearch_results";return elToHide},submit:function(){var elToHide=this.getCurrentElementToHide();this.showProgressBar(UnifiedSearchMessages.searching,elToHide);$("unifSearchForm").submit()},clearAndSubmit:function(keepFields){if(keepFields)this._persistentFields=this._persistentFields+","+keepFields+",";this.clearSearch(true);this.submit()},clearSearch:function(noClearOnServ){this.clearErrorMessages();var formElements=$("unifSearchForm").elements;var prefMoreOptions;
var secAttrsPanel;for(i=0;i<formElements.length;i++){hadErr=this.clearFieldHighlight(formElements[i]);fieldType=formElements[i].type.toLowerCase();switch(fieldType){case "text":case "password":case "textarea":case "hidden":if(this._persistentFields.indexOf(","+formElements[i].name+",")<0)formElements[i].value="";break;case "radio":case "checkbox":if(formElements[i].checked){formElements[i].checked=false;pref=formElements[i].name.substring(0,formElements[i].name.indexOf("_moreOptions"));secAttrsPanel=
pref+"_secattrs";if($(secAttrsPanel))$(secAttrsPanel).style.display="none"}break;case "select-one":if(this._persistentFields.indexOf(","+formElements[i].name+",")<0)formElements[i].selectedIndex=0;break;case "select-multi":formElements[i].selectedIndex=-1;break;default:break}}if(!noClearOnServ)this.clearFacSearchForms();this.selectLookingFor(true);this.selectInterest();var thisObj=this;if($("locationCriteria"))setTimeout(function(){thisObj.autocomplete._dropNewSuggestions=false;thisObj.autocomplete.setLocationFocus()},
150)},clearFieldHighlight:function(elem){if($(elem).className.indexOf(" highlightedfield")>=0){$(elem).className=$(elem).className.replace(" highlightedfield","");return true}return false},clearErrorMessages:function(){if($("usearch_info")){var children=$("usearch_info").childNodes;for(var i=0;i<children.length;i++)if($(children[i]).className&&$(children[i]).className.indexOf("msg error")>=0)$(children[i]).style.display="none"}},clearFacSearchForms:function(){var actionURL="/ajax/FacilityViewDetails?section=clearFacSearch";
var ajaxRequest=new Ajax.Request(actionURL,{method:"post"})},incrementResponsesCounter:function(){this._responsesCounter=this._responsesCounter+1},resolveStates:function(divId,keyword,maxRes){if(maxRes>0){var thisObj=this;var query={keyword:keyword};this.suggestionsProviders[0].getSuggestions(query,function(objData){thisObj.incrementResponsesCounter();var limit=objData?objData.length:0;if(limit>maxRes)limit=maxRes;var dataStr="";if(limit>0){for(var i=0;i<limit;i++){var record=objData[i];var value=
thisObj.suggestionsProviders[0].formatSuggestion(record).value;var fn=thisObj.getSearchEngineId()+".selectResolvedAddress('"+value+"','"+i+"', 0)";var recStr='<div class="facility_suggestion">';recStr+='<a id="suggestion_0_'+i+'" href="javascript:'+fn+'" >';recStr+=thisObj.highlight(record.name,value,keyword);recStr+="<SPAN> "+UnifiedSearchMessages.centerOfState+"</SPAN>";recStr+="</a></div>";dataStr+=recStr}$(divId).innerHTML=dataStr;if($("suggestions_none")==null||$("suggestions_none").style.display==
"none")$("states_suggestions_list").style.display="block"}})}},showSuggestionsResult:function(tmout){var thisObj=this;thisObj.incrementResponsesCounter();var sgsInterv=setInterval(function(){if(thisObj._responsesCounter>=thisObj.suggestionsProviders.length){clearInterval(sgsInterv);thisObj.displaySuggestionsResults()}},150);setTimeout(function(){try{clearInterval(sgsInterv)}catch(err){}},tmout)},displaySuggestionsResults:function(){if($("states_suggestions_list").style.display=="none"&&$("facilities_suggestions_list").style.display==
"none"&&$("addresses_suggestions_list").style.display=="none"){$("suggestions_header").style.display="none";$("suggestions_none").style.display="block"}else{$("suggestions_header").style.display="block";$("suggestions_none").style.display="none"}$("contentProgressBar").innerHTML="";animationStarted=false;$("suggestions_content").style.display="block"},resolveAddresses:function(divId,keyword,maxRes){var thisObj=this;var resInterv=setInterval(function(){var query={keyword:keyword};if(geo)geo.geocode({"address":query.keyword+
",USA"},function(result,status){thisObj.incrementResponsesCounter();if(status==google.maps.GeocoderStatus.OK){objData=result;var dataStr="";var limit=objData.length;if(limit>maxRes)limit=maxRes;if(limit>0){for(var i=0;i<limit;i++){var record=objData[i];var value="::"+record.geometry.location.lng()+":"+record.geometry.location.lat()+":";var fn=thisObj.getSearchEngineId()+".selectResolvedAddress('"+value+"','"+i+"', 2)";var recStr='<div class="facility_suggestion">';recStr+='<a id="suggestion_2_'+i+
'" href="javascript:'+fn+'" >';recStr+=thisObj.highlight(record.formatted_address,value,keyword);recStr+="</a></div>";dataStr+=recStr}$(divId).innerHTML=dataStr;if($("suggestions_none")==null||$("suggestions_none").style.display=="none")$("addresses_suggestions_list").style.display="block"}}clearInterval(resInterv);return false})},100)},selectResolvedAddress:function(val,sgsId,provIndex){this.autocomplete.inputHidden.value=val;var elemId="suggestion_"+provIndex+"_"+sgsId;var elem=$(elemId);if(elem){var label=
elem.innerHTML;if(provIndex==0||provIndex==2){label=label.replace("<span>","");label=label.replace("</span>","");label=label.replace("<SPAN>","");label=label.replace("</SPAN>","")}else{label=label.replace("<SPAN>","<span>");label=label.replace("</SPAN>","</span>");var rDelim=label.indexOf("<span>");if(rDelim>=0)label=label.substring(0,rDelim)}label=label.replace("<strong>","");label=label.replace("</strong>","");label=label.replace("<STRONG>","");label=label.replace("</STRONG>","");this.autocomplete.input.value=
label.unescapeHTML()}this.submit(UnifiedSearchMessages.searching,"suggestions_content")},showProgressBar:function(msg,elToHideId){var elToHide=elToHideId;var message=msg;if(message==null)message=UnifiedSearchMessages.searching;if(elToHideId==null)elToHide=this.getCurrentElementToHide();animationStarted=false;showProgressBar("contentProgressBar",message,"",elToHide)},submitForm:function(){if(this.autocomplete)this.autocomplete._submitted=true},getSearchEngineId:function(){return""},highlight:function(label,
value,searchTerm){var re=searchTerm.replace(/^\s+|\s+$/g,"");var uVal=label.toUpperCase();var higl=uVal.replace(re.toUpperCase(),function(match){return"<strong>"+match+"</strong>"});return higl},highlightDates:function(){if($("lookingFor")){var lookingFor=$("lookingFor").options[$("lookingFor").options.selectedIndex].value;$("campingDate").className=$("campingDate").className+" highlightedfield";$("lengthOfStay").className=$("lengthOfStay").className+" highlightedfield"}},nextPage:function(){$("currentPage").value=
eval($("currentPage").value)+1;$("paging").value="true";this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},previousPage:function(){$("currentPage").value=eval($("currentPage").value)-1;$("paging").value="true";this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},showOnlyAvailableSites:function(){$("currentPage").value=0;$("paging").value="true";$("facilityAvailable").value="show_available_only";
this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},showAvailableAndUnavailableSites:function(){$("currentPage").value=0;$("paging").value="true";$("facilityAvailable").value="show_all";this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},filterResultsByType:function(type){if($("facilityType").value!=type)$("currentPage").value=0;$("facilityType").value=type;$("selectedLetter").value="ALL";
this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},filterResultsByLetter:function(elem){var letter=elem.innerHTML;if($("selectedLetter").value!=letter)$("currentPage").value=0;$("selectedLetter").value=letter;$("facilityAvailable").value="show_all";this.showProgressBar(UnifiedSearchMessages.updating,"usearch_results");$("unifSearchResultsForm").submit()},selectInterest:function(){try{var intOpts=$("interest").options;var crtCardId=null;for(var i=
0;i<intOpts.length;i++){crtCardId="interest_"+intOpts[i].value;if(intOpts.selectedIndex==i)$(crtCardId).style.display="block";else $(crtCardId).style.display="none"}}catch(err){try{if($("interest")){var crtCardId="interest_"+$("interest").value;$(crtCardId).style.display="block"}}catch(err){}}},selectLookingFor:function(clr){this.siteAttributesController.selectLookingFor(clr)},syncronyzeDates:function(el,targetId){setTimeout(function(){if($(targetId))$(targetId).value=el.value},50)},startLoadingDescription:function(elId){var maxDots=
6;var interv;try{var el=$("descld_"+elId);$("more_"+elId).style.display="none";interv=setInterval(function(){if(el.innerHTML.length>maxDots)el.innerHTML="";else el.innerHTML=el.innerHTML+"."},150)}catch(err){}return interv},descriptionLoaded:function(interv,elId){try{var el=$("descld_"+elId);el.innerHTML="";$("more_"+elId).style.display="inline";clearInterval(interv)}catch(err){}},showDetailedFacilityDescription:function(parkKey,parkId,contrCode){var detCont=$("facility_view_desc_detail_"+parkKey).innerHTML;
var thisObj=this;if(detCont==""){var interv=this.startLoadingDescription(parkKey);var actionURL="/ajax/FacilityViewDetails?section=description&parkId="+parkId+"&contractCode="+contrCode;var ajaxRequest=new Ajax.Request(actionURL,{method:"post",onComplete:function(result){thisObj.descriptionLoaded(interv,parkKey);var details=result.responseText;$("facility_view_desc_detail_"+parkKey).innerHTML=details;$("facility_view_description_"+parkKey).className="facility_view_description hide";$("facility_view_desc_detail_"+
parkKey).className="facility_view_desc_detail"}})}else{$("facility_view_description_"+parkKey).className="facility_view_description hide";$("facility_view_desc_detail_"+parkKey).className="facility_view_desc_detail"}},showSimpleFacilityDescription:function(parkKey){$("facility_view_desc_detail_"+parkKey).className="facility_view_desc_detail hide";$("facility_view_description_"+parkKey).className="facility_view_description"},showMapView:function(parkKey){$("viewType").value="view_map";this.switchViewType($("viewType").value);
this.displayMap();if(!map)initializeMap();if(parkKey)try{if(Object.keys(mapMarkers).length==0)bubbleToOpen=parkKey;else google.maps.event.trigger(mapMarkers[parkKey],"click")}catch(err){}},displayMap:function(){$("list_view_switch").className="view_switch first";$("map_view_switch").className="view_switch last selected";$("search_results_list").style.display="none";$("search_results_map").style.display="block"},showListView:function(parkId){$("viewType").value="view_list";this.switchViewType($("viewType").value);
this.displayList();pageTracker._trackEvent("Unified_Search_Results","List_View")},displayList:function(){$("list_view_switch").className="view_switch first selected";$("map_view_switch").className="view_switch last";$("search_results_map").style.display="none";$("search_results_list").style.display="block"},showFacilityOnMap:function(parkId){this.showMapView(parkId)},refreshViewType:function(){var viewType="view_list";if(document.location.href.indexOf("?viewType=")>=0){if(document.location.href.indexOf("?viewType=view_map")>=
0)viewType="view_map";if(viewType=="view_map")this.displayMap();else this.displayList()}},switchViewType:function(viewType,redirectURL,parkKey,coords){var actionURL="/ajax/FacilityViewDetails?section=switch_view_type&viewType="+viewType;if(parkKey)actionURL+="&parkKey="+parkKey;if(coords)actionURL+="&coords="+coords;var ajaxRequest=new Ajax.Request(actionURL,{method:"post",onComplete:function(result){if(redirectURL)document.location.href=redirectURL}})},getMapMarker:function(parkId){try{return $("usrpin_"+
parkId).getAttribute("src")}catch(err){return null}},getFacilityCard:function(parkId){try{return $("facility_view_card_"+parkId).innerHTML}catch(err){return null}}};var NORMALIZATION_MAPPINGS=[];
