function getBaseUrl(){var n=new RegExp(/^.*\//);document.getElementById("baseresult").innerHTML+=n.exec(window.location.href)}function getRootUrl(){document.getElementById("rootresult").innerHTML+=window.location.origin?window.location.origin+"/":window.location.protocol+"/"+window.location.host+"/";getBaseUrl()}function getRootWebSitePath(){var n=document.location.toString(),i=n.indexOf("/",n.indexOf("://")+3),t=n.substring(0,i)+"/",r=n.indexOf("/",n.indexOf(t)+t.length);return n.substring(0,r)}function GetMap(){var n=document.getElementById("myMap"),u=function(){n.style.height=window.innerHeight+"px"},t,i,r;u();t=new Microsoft.Maps.Location(31.391533,-99.17065);i=Microsoft.Maps.NavigationBarMode;map=browserQuery?new Microsoft.Maps.Map(n,{center:t,mapTypeId:Microsoft.Maps.MapTypeId.road,showTrafficButton:!0,zoom:6,enableClickableLogo:!1,showLocateMeButton:!1}):new Microsoft.Maps.Map(n,{center:t,mapTypeId:Microsoft.Maps.MapTypeId.road,navigationBarMode:i.minified,showTrafficButton:!0,zoom:6,enableClickableLogo:!1,showLocateMeButton:!1});dataLayer=new Microsoft.Maps.EntityCollection;map.entities.push(dataLayer);r=new Microsoft.Maps.EntityCollection;map.entities.push(r);infobox=new Microsoft.Maps.Infobox(new Microsoft.Maps.Location(0,0),{visible:!1,offset:new Microsoft.Maps.Point(0,20)});infobox.setMap(map);Microsoft.Maps.loadModule("Microsoft.Maps.WellKnownText")}function SearchFacilities(n){var t=document.getElementById("searchBox").value;if(!t){showErrorMsg("Address must be populated in order to perform a search.");return}clearMap(function(){});var u=$("#ddlWithinMile").val(),f=$("#ddlFacilityType").val(),e=f,i=-1,o={Distance:u,FacilityType:e,DistanceUnit:"mi",Output:"Json",SearchAddress:t},r="";n.preventDefault();$(this).prop("disabled",!0);$(".mapSearch-btn").prop("disabled",!0);$(".my-location").prop("disabled",!0);$.ajax({url:RootUrl+"Maps/SearchFacilitiesAsync/",data:JSON.stringify(o),type:"POST",contentType:"application/json; charset=utf-8",success:function(n){if(i=n.isSuccessful,i===1){var t=new Microsoft.Maps.Location(n.geoLatitude,n.geoLongitude);pushpin=new Microsoft.Maps.Pushpin(t,{title:"Location",subTitle:"Provided by Searched Address",icon:pinImageLocation,anchor:new Microsoft.Maps.Point(0,13)});map.entities.push(pushpin);r=JSON.parse(n.nearbyFacilities);DisplayData(r)}else showErrorMsg(n.errorMsg)},error:function(n,t,i){showErrorMsg(i)},complete:function(){$(this).prop("disabled",!1);$(".mapSearch-btn").prop("disabled",!1);$(".my-location").prop("disabled",!1)}})}function GetUsersLocation(){if(navigator.geolocation)navigator.geolocation.getCurrentPosition(getLocation,getLocationError,{enableHighAccuracy:!0,timeout:5e3,maximumAge:0});else showErrorMsg("Geolocation is not supported by this browser.")}function getLocation(n){loc=new Microsoft.Maps.Location(n.coords.latitude,n.coords.longitude);pushpin=new Microsoft.Maps.Pushpin(loc,{title:"Current Location",subTitle:"",icon:pinImageLocation,anchor:new Microsoft.Maps.Point(0,13)});map.entities.push(pushpin);map.setView({center:loc,zoom:15});reverseGeocode(loc)}function getLocationError(n){switch(n.code){case n.PERMISSION_DENIED:showErrorMsg("User denied the request for Geolocation.");break;case n.POSITION_UNAVAILABLE:showErrorMsg("Location information is unavailable.");break;case n.TIMEOUT:showErrorMsg("The request to get user location timed out.");break;case n.UNKNOWN_ERROR:showErrorMsg("An unknown error occurred.");break;default:showErrorMsg("An unknown error occurred.")}}function DisplayData(n){var u,e,t,r,o,s,f,h,c;if(dataLayer.clear(),infobox.setOptions({visible:!1}),u=[],e=[],n===null)showErrorMsg("Application error occurred. Please try again later.");else if(n.Results===null)showErrorMsg(n.Error);else if(n&&n.Results!==null&&n.Results.length>0){for(t=0;t<n.Results.length;t++){var l=t+1,a={pushpinOptions:{text:l.toString(),textOffset:new Microsoft.Maps.Point(0,4),icon:wicImageLocation,anchor:new Microsoft.Maps.Point(24,18)}},i=Microsoft.Maps.WellKnownText.read(n.Results[t].WKT,a);if(i.getLength)for(r=0;r<i.getLength();r++)i.get(r).Title=n.Results[t].Name,i.Description="Phone: <a class='infoBoxLink' href='tel:"+n.Results[t].Phone+"'>"+n.Results[t].Phone+"<\/a><br /> Distance: "+n.Results[t].Distance+' miles<br /><a target="_blank" class="infoBoxLink" href="http://bing.com/maps/default.aspx?rtp=~pos.'+n.Results[t].Latitude+"_"+n.Results[t].Longitude+"_"+encodeURIComponent(n.Results[t].Name)+'">Directions<\/a>',Microsoft.Maps.Events.addHandler(i.get(r),"click",DisplayInfobox),ResultsPanelItems(u,n.Results[t],t);else i.Title=n.Results[t].Name,i.Description="Phone: <a class='infoBoxLink' href='tel:"+n.Results[t].Phone+"'>"+n.Results[t].Phone+"<\/a><br /> Distance: "+n.Results[t].Distance+' miles<br /><a target="_blank" class="infoBoxLink" href="http://bing.com/maps/default.aspx?rtp=~pos.'+n.Results[t].Latitude+"_"+n.Results[t].Longitude+"_"+encodeURIComponent(n.Results[t].Name)+'">Directions<\/a>',Microsoft.Maps.Events.addHandler(i,"click",DisplayInfobox),e.push(new Microsoft.Maps.Location(n.Results[t].Latitude,n.Results[t].Longitude)),ResultsPanelItems(u,n.Results[t],t);for(dataLayer.push(i),o=document.getElementById("resultsPanel"),o.innerHTML=u.join(""),s=o.getElementsByClassName("title"),f=0;f<s.length;f++)s[f].onclick=resultClicked}h=Microsoft.Maps.LocationRect.fromLocations(e);map.setView({bounds:h,padding:100})}else n.Results.length===0?(c=document.getElementById("resultsPanel"),c.innerHTML="<b>No Results Found.<\/b><br />Please try your search again. <br /><br />"):n&&n.Error!==null&&showErrorMsg(n.Error)}function ResultsPanelItems(n,t,i){var u=t.StoreHours,f,r;u===null?u="Please refer to the location for hours.":$.trim(u).length===0&&(u="Please refer to the location for hours.");f="<br />"+u.replace(/[|]/g,"-");f=f.replace(/&{2}/g,"<br>");t.AddressLine===null&&(t.AddressLine=" ");t.City===null&&(t.City=" ");t.State===null&&(t.State=" ");t.PostalCode===null&&(t.PostalCode=" ");t.Phone===null&&(t.Phone=" ");n.push('<table class="table table-striped"><tr><td rowspan="3" style="width:14px">',i+1,".<\/td>");n.push('<td><h5><a class="title" href="javascript:void(0);" rel="',t.Name,'">',t.Name,"<\/a><\/h5><\/td>");n.push('<td class="text-right">',t.Distance,"&nbsp;mi<\/td><\/tr>");r='<tr><td colspan="2" class="listItem-address">'+t.AddressLine+"<br />";t.AddressLine2&&(r=r+t.AddressLine2+"<br />");r=r+t.City+", "+t.State+" "+t.PostalCode+"<br />";t.FacilityType.toLowerCase()==="clinic"&&t.WebSite!=null&&(r=r+'<br /><b>Website: <\/b><a class="infobox" target="_blank" href="'+t.WebSite+'">'+t.WebSite+"<\/a>");t.Email&&(r=r+'<br /> <b>Email:<\/b> <a class="infobox" href="mailto:'+t.Email+'">'+t.Email+"<\/a>");r=r+'<br /> <b>Phone: <\/b><a class="infobox" href="tel:'+t.Phone+'">'+t.Phone+"<\/a><br /> <b>Hours:<\/b> "+f;t.FacilityType.toLowerCase()==="clinic"&&(t.CallCenterUrl!=null&&(r=r+'<br /><br /> <b>Live Chat: <\/b><a class="infobox" href="'+t.CallCenterUrl+"&lge="+lang+'">Chat with WIC staff<\/a>'),t.CallCenterSms!=null&&(r=r+'<br /><br /> <b>Text Line: <\/b><a class="infobox" href="sms://+'+t.CallCenterSms+'">Text with WIC staff at '+t.CallCenterSms+"<\/a>"));r=r+"<\/td><\/tr>";n.push(r);n.push('<tr><td colspan="2"><a target="_blank" href="http://bing.com/maps/default.aspx?rtp=~pos.',t.Latitude,"_",t.Longitude,"_",encodeURIComponent(t.Name),'">Directions<\/a><\/td><\/tr>');n.push("<\/table>")}function resultClicked(n){for(var t,u=n.target.getAttribute("rel"),r=dataLayer.getPrimitives(),i=0;i<r.length;i++)if(t=r[i],t.Title!==u)t=null;else break;t&&map.setView({center:t.getLocation(),zoom:17})}function DisplayInfobox(n){var t,i;n.targetType==="pushpin"?(infobox.setLocation(n.target.getLocation()),t=new Microsoft.Maps.Point(0,15)):(i=Microsoft.Maps.LocationRect.fromLocations(n.target.getLocations()),infobox.setLocation(i.center),t=new Microsoft.Maps.Point(0,0));infobox.setOptions({htmlContent:infoboxTemplate.replace("{title}",n.target.Title).replace("{description}",n.target.Description)+closeButton,visible:!0,offset:t,height:40})}function reverseGeocode(n){if(searchManager){var t={location:n,callback:function(n){$("#searchBox").val(n.name)},errorCallback:function(n){showErrorMsg("Address lookup failed. Please refresh the page and try again."+n.toString())}};searchManager.reverseGeocode(t)}else Microsoft.Maps.loadModule("Microsoft.Maps.Search",function(){searchManager=new Microsoft.Maps.Search.SearchManager(map);reverseGeocode(n)})}function geocodeQuery(n){if(searchManager){var t={where:n,callback:function(n){if(n&&n.results&&n.results.length>0){var t=new Microsoft.Maps.Pushpin(n.results[0].location);map.entities.push(t);map.setView({bounds:n.results[0].bestView})}},errorCallback:function(){showErrorMsg("No results found.")}};searchManager.geocode(t)}else Microsoft.Maps.loadModule("Microsoft.Maps.Search",function(){searchManager=new Microsoft.Maps.Search.SearchManager(map);geocodeQuery(n)})}function showErrorMsg(n){var t="The following error(s) occurred:\n"+n;$("#alertModal").find(".modal-body p").text(t);$("#alertModal").modal("show");setTimeout(focusModal,500)}function focusModal(){$("#modalCloseButton").focus()}function clearMap(n){var t,i;for(dataLayer.clear(),closeInfobox(),document.getElementById("resultsPanel").innerHTML="",t=map.entities.getLength()-1;t>=0;t--)i=map.entities.get(t),i instanceof Microsoft.Maps.Pushpin&&map.entities.removeAt(t);n()}function closeInfobox(){infobox.setOptions({visible:!1})}function performSearch(n){var i=document.getElementById("searchBox").value,t;if(!i){showErrorMsg("Address must be populated in order to perform a search.");return}clearMap(function(){});t={where:document.getElementById("searchBox").value,count:1,callback:function(t){if(t&&t.results&&t.results.length>0&&t.results[0].location){GetNearbyLocations(n,t.results[0].location);var i=t.results[0].location;pushpin=new Microsoft.Maps.Pushpin(i,{title:"Location",subTitle:"Provided by Searched Address",icon:pinImageLocation,anchor:new Microsoft.Maps.Point(0,13)});map.entities.push(pushpin)}else map.setView({center:loc,zoom:12}),showErrorMsg("Unable to geocode query. Please try again later.")},errorCallback:function(){map.setView({center:loc,zoom:12});showErrorMsg("Invalid address entered or address not found. Address entered: "+document.getElementById("searchBox").value)}};searchManager.geocode(t)}function CallRESTService(n,t){var i;if(window.XMLHttpRequest)i=new XMLHttpRequest;else if(window.ActiveXObject)try{i=new ActiveXObject("Msxml2.XMLHTTP")}catch(r){try{i=new ActiveXObject("Microsoft.XMLHTTP")}catch(r){throw r;}}i.open("GET",n,!0);i.onreadystatechange=function(){i.readyState===4&&t(eval("("+i.responseText+")"))};i.send()}function GetNearbyLocations(n,t){radius=document.getElementById("ddlWithinMile").value;var i=baseWSUrl+t.latitude+"/"+t.longitude+"/"+radius+"/"+distanceUnits+"/"+n+"/json/?callback=?";CallRESTService(i,DisplayData)}function displayAlternateInfobox(n){var i=n,t;alert("altinfo. pin = "+n.Name);t="Phone: "+n.Phone+"<br /> Distance: "+n.Distance+'<br /><a target="_blank" class="infoBoxLink" href="http://bing.com/maps/default.aspx?rtp=~pos.'+n.Latitude+"_"+n.Longitude+"_"+encodeURIComponent(n.Name)+'">Directions<\/a>';infobox.setOptions({visible:!0,location:n.getLocation(),title:n.Name,description:t})}var map,infobox,dataLayer,radius,pushpin,loc,searchManager,distanceUnits="mi",baseWSUrl="http://HHSC4AVDWICWEB.hhsc.txnet.state.tx.us:8088/FindNearBy/",infoboxTemplate='<div class="customInfobox"><div class="title">{title}<\/div>{description}<\/div>',infoTitle,infoDescription,closeButton='<a href="javascript:closeInfobox()" class="customInfoboxCloseButton">X<\/a>',browserQuery=Modernizr.mq("(min-width: 480px)");$(document).ready(function(){$("#getLocation").click(function(){clearMap(function(){GetUsersLocation()})});document.getElementById("searchBox").onkeypress=function(n){n.which===13&&SearchFacilities(n)};$(".mapSearch-btn").on("click",function(n){SearchFacilities(n)})})