var BranchFinderViewModel={};BranchFinderViewModel.x=ko.observable(0);BranchFinderViewModel.y=ko.observable(0);BranchFinderViewModel.commandGetPosition=function(){onMapLoad()};
function onMapLoad(){if(MainViewModel.checkInternetConnection()){$("#map_canvas").html('<div class="Loader ui-loader ui-corner-all ui-body-d ui-loader-verbose"><img src="Images/jquery.mobile/ajax-loader.gif" /><h1>'+Culture.translations().stringTextWaitingForGPSSignal+"</h1></div>");max_height();var a=document.createElement("script");a.setAttribute("type","text/javascript");a.setAttribute("src","http://maps.googleapis.com/maps/api/js?sensor=true&callback=getGeolocation");document.getElementsByTagName("head")[0].appendChild(a)}}
function getGeolocation(){Log("*getGeolocation*");navigator.geolocation.getCurrentPosition(loadMap,geoError,{maximumAge:6E5,timeout:6E5,enableHighAccuracy:!0})}
function loadMap(a){Log("*loadMap*: "+a.coords.latitude+" "+a.coords.longitude);var d,c,b;if(0<DefaultBranchData.length){d=Math.sqrt(Math.pow(DefaultBranchData[0].x-a.coords.latitude,2)*Math.pow(DefaultBranchData[0].y-a.coords.longitude,2));c=0;for(var e=1;e<DefaultBranchData.length;e++)b=Math.sqrt(Math.pow(DefaultBranchData[e].x-a.coords.latitude,2)*Math.pow(DefaultBranchData[e].y-a.coords.longitude,2)),d>b&&(d=b,c=e);a=new google.maps.LatLng(DefaultBranchData[c].x,DefaultBranchData[c].y);d={zoom:12,
center:a,mapTypeId:google.maps.MapTypeId.ROADMAP};b=document.getElementById("map_canvas");d=new google.maps.Map(b,d);a=new google.maps.Marker({position:a,map:d});b=document.createElement("div");b.innerHTML=DefaultBranchData[c].firm+"<br>"+DefaultBranchData[c].country+"<br>"+DefaultBranchData[c].city+"<br>"+DefaultBranchData[c].street+" "+DefaultBranchData[c].number;(new google.maps.InfoWindow({content:b})).open(d,a)}}
function geoError(){Log("*geoError*");alert(Culture.translations().stringTextGPSProblem)}function max_height(){var a=$('#BranchFinderPage div[data-role="header"]').outerHeight(!0),d=$('#BranchFinderPage div[data-role="footer"]').outerHeight(!0),c=$(window).height(),b=$('#BranchFinderPage div[data-role="content"]'),e=b.height(),f=b.outerHeight(!0),a=c-a-d-f+e;e<b.get(0).scrollHeight?b.height(b.get(0).scrollHeight):b.height(a)};
