(function(){NewMind.registerNameSpace("NewMind.tourism");NewMind.registerNameSpace("NewMind.ETWP");NewMind.tourism.ProductMapDataSource=function(){this.isDynamic=true;this.SearchForm=null;this.LoadedProducts={}};NewMind.extend(NewMind.tourism.ProductMapDataSource,NewMind.mapping.MapDataSource);NewMind.tourism.ProductMapDataSource.prototype.init=function(){NewMind.ajax.itinUpdated.subscribe(this.onItinUpdated,this,true);this.overlay.markerAdded.subscribe(this.onMarkerAdded,this,true)};NewMind.tourism.ProductMapDataSource.prototype.onMarkerAdded=function(type,args,me){NewMind.mapping.addMarkerOkToShowDelegate(args[0],this.checkProductMarkerNotInExcursion);if(!this.checkProductMarkerNotInExcursion(args[0])){args[0].hide();setTimeout(function(){args[0].hide()},100)}};NewMind.tourism.ProductMapDataSource.prototype.setSearchForm=function(frm){this.SearchForm=frm};NewMind.tourism.ProductMapDataSource.prototype.getData=function(tranid,bbView){if(NewMind.env.search&&NewMind.env.search.numProds&&NewMind.env.search.numProds>NewMind.env.install.mapping.maxprods&&this.overlay.parentMap.mapstractionMap.getZoom()<10){this.doTooManyMessage();return{complete:true,error:1}}else{var llSW=new LatLng(bbView.sw.lat,bbView.sw.lon);var llNE=new LatLng(bbView.ne.lat,bbView.ne.lon);var osSW=llSW.toOSRef();var osNE=llNE.toOSRef();var strPostUrl;var bUsePost=false;var oData={};if(this.SearchForm){strPostUrl=this.SearchForm.action.replace(/\/searchresults/,"/ajax-products");oData=$(this.SearchForm).serializeArray()}else{if(NewMind.env.platform.type=="enterprise"){var intCtrlKey=NewMind.env.install.mapping.configurations[this.overlay.parentMap.getContainerID()].controlkey;if(NewMind.ETWP.ControlData[intCtrlKey]&&NewMind.ETWP.ControlData[intCtrlKey].TOv2QueryData){bUsePost=true;strPostUrl="/engine/MappingStubRetrieval.asp";$.extend(oData,{data:NewMind.ETWP.ControlData[intCtrlKey].TOv2QueryData,maxresults:NewMind.ajax.AJAX_MAPPING_DATA_MAXRESULTS})}else{if(NewMind.ETWP.ControlData[intCtrlKey]&&NewMind.ETWP.ControlData[intCtrlKey].SearchUrl){strPostUrl=NewMind.ETWP.ControlData[intCtrlKey].SearchUrl}else{strPostUrl=NewMind.ajax.CleanCurrentUrlForAjax()}if(strPostUrl.indexOf("?")===-1){strPostUrl+="?"}else{strPostUrl+="&"}var arrParams=[];arrParams.push("AsyncAction=search-stub");arrParams.push("PartialRenderControlList="+intCtrlKey);strPostUrl+=arrParams.join("&")}}else{strPostUrl=document.location.href;var iIndOfHash=strPostUrl.indexOf("#");if(iIndOfHash>-1){strPostUrl=strPostUrl.substring(0,iIndOfHash)}strPostUrl=strPostUrl.replace(/\/searchresults/,"/ajax-products");strPostUrl=strPostUrl.replace(/\/a-z/,"/ajax-az")}}if(NewMind.env.platform.type=="enterprise"){$.extend(oData,{dynMapN:bbView.ne.lon,dynMapE:bbView.ne.lat,dynMapS:bbView.sw.lon,dynMapW:bbView.sw.lat})}else{$.extend(oData,{dynMapN:Math.floor(osNE.northing),dynMapE:Math.floor(osNE.easting),dynMapS:Math.floor(osSW.northing),dynMapW:Math.floor(osSW.easting)})}var bCancel=(this.preGetData(strPostUrl,oData)===false);if(!bCancel){bComplete=false;var fnBoundSuccess=NewMind.bind(this.handleSuccess,this);var fnBoundFailure=NewMind.bind(this.handleFailure,this);var fncSubmit;if(bUsePost){fncSubmit=$.post}else{fncSubmit=$.get}fncSubmit(strPostUrl,oData,function(data,status){if(status=="success"){fnBoundSuccess(tranid,data)}else{fnBoundFailure(tranid)}})}}return{complete:(bCancel)}};NewMind.tourism.ProductMapDataSource.prototype.doTooManyMessage=function(){var mapEleId=this.overlay.parentMap.getContainerID();var jqMsg=$("#"+mapEleId+" .prodWarning");if(jqMsg.length===0){var eleMsg=$('<span class="prodWarning">Too many products to display, please zoom in to refine your search</span>').appendTo("#"+mapEleId).get(0);this.overlay.parentMap.beforeUpdate.subscribe(function(){$(eleMsg).hide(0)})}else{jqMsg.show(0)}};NewMind.tourism.ProductMapDataSource.prototype.preGetData=function(){};NewMind.tourism.ProductMapDataSource.prototype.handleSuccess=function(){var rawData=null;var iCounter=0;rawData=eval(arguments[1]);var result={tranid:arguments[0],error:0,data:[]};if(rawData.length>0){if(rawData[0].count){this.doTooManyMessage();result.error=1}else{while(rawData.length>0){var prodDataItem=rawData.pop();try{if(!this.LoadedProducts.hasOwnProperty("p"+prodDataItem.product_key.toString())){var mkr=this.getProdMarkerData(prodDataItem);this.LoadedProducts["p"+prodDataItem.product_key.toString()]=prodDataItem;result.data.push(mkr)}}catch(e){if(NewMind.mapping.DEBUG){throw e}}}}}this.overlay.dataReady(result)};NewMind.tourism.ProductMapDataSource.prototype.handleFailure=function(o){var result={tranid:arguments[0],error:1,data:[]};this.overlay.dataReady(result)};NewMind.tourism.ProductMapDataSource.prototype.getProdMarkerData=function(prodDataItem){var mkr={};if(prodDataItem.latitude!==null&&prodDataItem.longitude!==null&&NewMind.env.platform.type==="enterprise"){mkr.lat=prodDataItem.latitude;mkr.lon=prodDataItem.longitude}else{var osCoord=new OSRef(prodDataItem.eastings,prodDataItem.northings);var llCoord=osCoord.toLatLng();llCoord.OSGB36ToWGS84();mkr.lat=llCoord.lat;mkr.lon=llCoord.lng}mkr.label=prodDataItem.product_name;var strInfoBubble="";if(NewMind.env.platform.type==="enterprise"){}else{strInfoBubble+='<h4><a href="'+prodDataItem.detail_link+'">'+prodDataItem.product_name+"</a></h4>";strInfoBubble+='<p><img src="'+prodDataItem.image_path+'" style="float: left; margin: 0 4px 0 0;"/></p>';if(prodDataItem.short_desc!==""){strInfoBubble+="<p>"+prodDataItem.short_desc.substr(0,100)+"...</p>"}strInfoBubble+=prodDataItem.ep_add;if(prodDataItem.booklink!==""&&prodDataItem.bookimg!==""){strInfoBubble+='<p class="bookonline"><a rel="nofollow" href="'+prodDataItem.booklink+'" '+prodDataItem.bookjs+'><img src="/images/'+prodDataItem.bookimg+'" alt="Book '+prodDataItem.bookname+' Online"/></a></p>'}mkr.infoBubble=$("<div>"+strInfoBubble+"</div>").find("a.ep_Add").click(NewMind.ajax.itinButtonClickHandler).end().get(0)}var objIconData=this.getMarkerIcon(prodDataItem.prodtype_id);mkr.icon=objIconData.iconUrl;mkr.iconSize=objIconData.iconSize;mkr.iconAnchor=objIconData.iconAnchor;mkr.product=prodDataItem;return mkr};NewMind.tourism.ProductMapDataSource.prototype.getMarkerIcon=function(strProdType){return this.superclass.prototype.getMarkerIcon(strProdType)};NewMind.tourism.ProductMapDataSource.prototype.onItinUpdated=function(type,args,me){if(NewMind.env.platform.type=="enterprise"){return }var mkrs=this.overlay.LoadedMarkers;if(mkrs.length>0){for(var iMs=0;iMs<mkrs.length;iMs++){var mk=mkrs[iMs];if(this.checkProductMarkerNotInExcursion(mk)){if(this.overlay.getShowing()){mk.show()}}else{mk.hide()}}}};NewMind.tourism.ProductMapDataSource.prototype.checkProductMarkerNotInExcursion=function(oMkr){var bOkToShow=true;var prod=oMkr.getAttribute("product");for(var iEs=0;iEs<NewMind.env.excursion.length;iEs++){if(prod.product_key===NewMind.env.excursion[iEs].product_key){bOkToShow=false;break}}return bOkToShow};NewMind.tourism.ItineraryMapDataSource=function(){this.isDynamic=false;NewMind.ajax.itinUpdated.subscribe(this.onItinUpdated,this,true)};NewMind.extend(NewMind.tourism.ItineraryMapDataSource,NewMind.mapping.MapDataSource);NewMind.tourism.ItineraryMapDataSource.prototype.onItinUpdated=function(type,args,me){if(NewMind.env.platform.type=="enterprise"){return }this.overlay.reset();this.overlay.updateView()};NewMind.tourism.ItineraryMapDataSource.prototype.getData=function(bbView){var goodData=[];for(var iEC=0;iEC<NewMind.env.excursion.length;iEC++){var prodDataItem=NewMind.env.excursion[iEC];try{var mkr=NewMind.tourism.ProductMapDataSource.prototype.getProdMarkerData(prodDataItem);var objIconData=this.getMarkerIcon(prodDataItem.prodtype_id);mkr.icon=objIconData.iconUrl;mkr.iconSize=objIconData.iconSize;mkr.iconAnchor=objIconData.iconAnchor;$(mkr.infoBubble).addClass("itin");goodData.push(mkr)}catch(e){if(NewMind.mapping.DEBUG){alert(e)}}}return{complete:true,error:0,data:goodData}};NewMind.tourism.ItineraryMapDataSource.prototype.getMarkerIcon=function(strProdType){return this.superclass.prototype.getMarkerIcon(strProdType,"itn")};NewMind.tourism.ProductMarkerFilterWidget=function(prodMarkerOverlay,filterPaneElement){this.ProdMarkerOverlay=prodMarkerOverlay;prodMarkerOverlay.markerAdded.subscribe(this.onMarkerAdded,this,true);this.ProdMarkerOverlay.parentMap.mapstractionMap.addEventListener("moveend",this.onMapMove,this);this.FilterPane=filterPaneElement;this.FilterData={}};NewMind.tourism.ProductMarkerFilterWidget.prototype={discreteValuedFilters:{price:["less than &pound;50","between &pound;50 and &pound;100","greater than &pound;100"],grading:["1","2","3","4","5"]},onMarkerAdded:function(type,args,me){this.updateFilterData(args[0]);this.updateFilterList();NewMind.mapping.addMarkerOkToShowDelegate(args[0],this.checkWhetherMarkerShouldShow);if(!this.checkWhetherMarkerShouldShow(args[0])){args[0].hide()}},onFilterToggle:function(e,oVal){var elm=e;var bbViewPort=this.ProdMarkerOverlay.parentMap.mapstractionMap.getBounds();for(var iMk in oVal.markers){if(!oVal.markers.hasOwnProperty||oVal.markers.hasOwnProperty(iMk)){var prod=oVal.markers[iMk].getAttribute("product");if(elm.checked){oVal.markers[iMk].show();if(bbViewPort.contains(oVal.markers[iMk].location)&&this.checkWhetherMarkerShouldShow(oVal.markers[iMk])){$("div#mapProductList").find("ul").find("li.pk_"+prod.product_key).fadeIn()}}else{oVal.markers[iMk].hide();if(bbViewPort.contains(oVal.markers[iMk].location)){$("div#mapProductList").find("ul").find("li.pk_"+prod.product_key).fadeOut()}}}}},onMapMove:function(){this.updateFilterList()},checkWhetherMarkerShouldShow:function(oMkr){var bShowIt=true;if("applicableFilterVals" in oMkr){for(var iFv in oMkr.applicableFilterVals){if(!oMkr.applicableFilterVals.hasOwnProperty||oMkr.applicableFilterVals.hasOwnProperty(iFv)){if(!oMkr.applicableFilterVals[iFv].elmCheckbox.checked){bShowIt=false;break}}}}return bShowIt},updateFilterData:function(oNewMarker){var prod=oNewMarker.getAttribute("product");var aryFilters;switch(NewMind.env.page.prodtypes){case"ACCO":aryFilters=["category","price","bookable","grading"];break;case"DUMMY":break;default:aryFilters=["category"];break}var setBg=function(){$(this).css({backgroundColor:"#5899F5"});$(this).dequeue()};var clearBg=function(){$(this).css({backgroundColor:""});$(this).dequeue()};for(var iInd=0;iInd<aryFilters.length;iInd++){var sFilter=aryFilters[iInd];var bIgnore=false;var value="";switch(sFilter){case"category":value="";if(NewMind.env.page.catgrps.length>0){for(var iCg=0;iCg<NewMind.env.page.catgrps.length;iCg++){var cg=NewMind.env.page.catgrps[iCg];if((", "+cg.catkeys+", ").indexOf(", "+prod.topcategory_key+", ")>-1){value=cg.catgrpname;break}}}if(NewMind.env.page.cats !== undefined){if(NewMind.env.page.cats.length>0){for(var iC=0;iC<NewMind.env.page.cats.length;iC++){var cat=NewMind.env.page.cats[iC];if(cat.category_key===prod.topcategory_key){value=cat.category;break}}}}break;case"price":if(prod.min_price<50){value="less than &pound;50";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["price"]["lessthan50"]',value)}}else{if(prod.min_price>=50&&prod.min_price<100){value="between &pound;50 and &pound;100";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["price"]["between50and100"]',value)}}else{value="greater than &pound;100";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["price"]["greaterthan100"]',value)}}}break;case"bookable":if(prod.bookable===true){value=" bookable online";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["bookable"]["bookableonline"]',value)}}else{value="not bookable online";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["bookable"]["notbookableonline"]',value)}}break;case"grading":if(typeof prod.gradings==="undefined"){bIgnore=true}else{var intGradeNumber=0;if(!isNaN(prod.gradings)){if(prod.gradings>0){intGradeNumber=prod.gradings;intGradeNumber=parseInt(String(intGradeNumber).substring(String(intGradeNumber).length-1),10)}}for(var iGrading=0;iGrading<prod.gradings.length;iGrading++){var intGradeNumberTemp=prod.gradings[iGrading].grade_number;intGradeNumberTemp=parseInt(String(intGradeNumberTemp).substring(String(intGradeNumberTemp).length-1),10);if(intGradeNumberTemp>intGradeNumber){intGradeNumber=intGradeNumberTemp}}if(intGradeNumber>0){if(NewMind.env.platform.type=="enterprise"){value=intGradeNumber.toString()+" "+NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["grading"]["star(s)"]',"Star(s)")}else{value=intGradeNumber.toString()+" Star(s)"}}else{value="Awaiting Grading";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["grading"]["awaitinggrading"]',value)}}}break}if(!bIgnore){var objFData=this.FilterData[sFilter]||this.createFilterItem(sFilter);if(typeof (value)!=="string"||value===""){value="Other";if(NewMind.env.platform.type=="enterprise"){value=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["other"]',value)}}var oCat=objFData.values[value]||this.createValueItem(objFData,value);oCat.markers.push(oNewMarker);if(!oNewMarker.applicableFilterVals){oNewMarker.applicableFilterVals=[]}oNewMarker.applicableFilterVals.push(oCat);oCat.elmNumberSpan.innerHTML="("+oCat.markers.length.toString()+")";if(!oCat.elmCheckbox.checked){oNewMarker.hide()}objFData.values[value]=oCat;this.FilterData[sFilter]=objFData;if(NewMind.mapping.DisableFilterAnimation!==true){var jqEleP=$(oCat.elmNumberSpan.parentNode);if(jqEleP.queue("fx").length===0){try{jqEleP.queue(setBg).animate({backgroundColor:"#FFF"},1000).queue(clearBg)}catch(e){jqEleP.css({backgroundColor:""})}}}}}},createFilterItem:function(sFilterName){var oFilterItem={elmFieldset:undefined,values:{}};oFilterItem.elmFieldset=document.createElement("fieldset");this.FilterPane.appendChild(oFilterItem.elmFieldset);var eLeg=document.createElement("legend");var sTitle;if(NewMind.env.platform.type=="enterprise"){sTitle=NewMind.ETWP.GetResource('NewMind.env.lang.resources.searchresults["dynamicmapping"]["filters"]["'+sFilterName+'"]["title"]',sFilterName)}else{sTitle=sFilterName}eLeg.innerHTML=sTitle.replace(/^[a-z]/,function(a){return a.toUpperCase()});oFilterItem.elmFieldset.appendChild(eLeg);var eUl=document.createElement("ul");oFilterItem.elmFieldset.appendChild(eUl);var dVf=this.discreteValuedFilters[sFilterName];if(dVf){for(var iFv in dVf){if(!dVf.hasOwnProperty||dVf.hasOwnProperty(iFv)){oFilterItem.values[dVf[iFv]]=this.createValueItem(oFilterItem,dVf[iFv],true)}}}return oFilterItem},createValueItem:function(oFd,sValueName,bDontOrder){var oV={elmListItem:undefined,elmCheckbox:undefined,elmNumberSpan:undefined,markers:[]};oV.elmListItem=document.createElement("li");var eUl=oFd.elmFieldset.getElementsByTagName("ul")[0];var bAddedNode=false;if(!bDontOrder){for(var iLiNum=0;iLiNum<eUl.childNodes.length;iLiNum++){var cLi=eUl.childNodes[iLiNum];var cLbl=cLi.getElementsByTagName("label")[0];var cNameSpan=cLbl.getElementsByTagName("span")[0];if(cNameSpan.innerHTML>sValueName){eUl.insertBefore(oV.elmListItem,cLi);bAddedNode=true;break}}}if(!bAddedNode){eUl.appendChild(oV.elmListItem)}oV.elmCheckbox=document.createElement("input");oV.elmCheckbox.type="checkbox";oV.elmCheckbox.id="chk-prodfilter-"+NewMind.mapping.getNextInteger();oV.elmListItem.appendChild(oV.elmCheckbox);oV.elmCheckbox.checked=true;var eLbl=document.createElement("label");eLbl.setAttribute("for",oV.elmCheckbox.id);eLbl.innerHTML='<span class="filterValue">'+sValueName+'</span><span class="numOfProds">(0)</span>';oV.elmListItem.appendChild(eLbl);oV.elmNumberSpan=eLbl.getElementsByTagName("span")[1];var oT=this;$(oV.elmCheckbox).click(function(){oT.onFilterToggle(this,oV)});return oV},updateFilterList:function(){var bbViewPort=this.ProdMarkerOverlay.parentMap.mapstractionMap.getBounds();for(var sFilterName in this.FilterData){var oFilterData=this.FilterData[sFilterName];var iValsInView=0;for(var sValueName in oFilterData.values){var oValData=oFilterData.values[sValueName];var iProdsInView=0;for(var iMarkerNum in oValData.markers){if(!oValData.markers.hasOwnProperty||oValData.markers.hasOwnProperty(iMarkerNum)){if(bbViewPort.contains(oValData.markers[iMarkerNum].location)){iProdsInView++}}}if(iProdsInView>0){iValsInView++;oValData.elmNumberSpan.innerHTML="("+iProdsInView.toString()+")";oValData.elmListItem.style.display="block"}else{oValData.elmListItem.style.display="none"}}oFilterData.elmFieldset.style.display=((iValsInView>0)?"block":"none")}}};NewMind.tourism.ProductSearchResultsWidget=function(prodMarkerOverlay,filterPaneElement){this.ProdMarkerOverlay=prodMarkerOverlay;prodMarkerOverlay.markerAdded.subscribe(this.onMarkerAdded,this,true);this.ProdMarkerOverlay.parentMap.mapstractionMap.addEventListener("moveend",this.onMapMove,this)};NewMind.tourism.ProductSearchResultsWidget.prototype={onMarkerAdded:function(type,args,me){},onMapMove:function(){this.updateFilterList()},updateFilterList:function(){var bbViewPort=this.ProdMarkerOverlay.parentMap.mapstractionMap.getBounds();var llCenter=this.ProdMarkerOverlay.parentMap.mapstractionMap.getCenter();var aryDist=[];var iDist=0;for(var iMarkerNum=0;iMarkerNum<this.ProdMarkerOverlay.LoadedMarkers.length;iMarkerNum++){var markerData=this.ProdMarkerOverlay.LoadedMarkers[iMarkerNum];if(bbViewPort.contains(markerData.location)){if(NewMind.tourism.ProductMarkerFilterWidget.prototype.checkWhetherMarkerShouldShow(markerData)){aryDist[iDist]=[];aryDist[iDist][0]=markerData.getAttribute("product").product_key;var toPoint=markerData.location;var distance=llCenter.distance(toPoint);aryDist[iDist][1]=distance;iDist++}}else{this.toggleListItem(markerData,"remove")}}aryDist.sort(this.sortMultiDimensional);$("div#mapProductList").find("ul").find("li").remove();for(i=0;i<aryDist.length;i++){for(iListMarkerNum=0;iListMarkerNum<this.ProdMarkerOverlay.LoadedMarkers.length;iListMarkerNum++){var listmarkerData=this.ProdMarkerOverlay.LoadedMarkers[iListMarkerNum];if(listmarkerData.getAttribute("product").product_key===aryDist[i][0]){this.createListItem(listmarkerData)}}}},sortMultiDimensional:function(a,b){return((a[1]<b[1])?-1:((a[1]>b[1])?1:0))},createListItem:function(oNewMarker){var prod=oNewMarker.getAttribute("product");var intCtrlKey=NewMind.env.install.mapping.configurations[this.ProdMarkerOverlay.parentMap.getContainerID()].controlkey;var elmli='<li class="pk_'+prod.product_key+'"><a href="#map-'+intCtrlKey+'"><img src="'+oNewMarker.iconUrl+'" /></a><a href="#map-'+intCtrlKey+'">'+prod.product_name+"</a>, "+prod.address4+"</li>";$("div#mapProductList").find("ul").append(elmli).find("li.pk_"+prod.product_key).find("a").click(function(e){oNewMarker.openBubble()})},toggleListItem:function(oNewMarker,state){var prod=oNewMarker.getAttribute("product");var $listItm=$("div#mapProductList").find("ul").find("li.pk_"+prod.product_key);if(state==="hide"){$listItm.fadeOut()}else{if(state==="remove"){$listItm.fadeOut("slow").remove()}else{$listItm.fadeIn()}}}}})();
