﻿function google_preview(){var latitude=$("#latitude","#registrationDialog").val();var longitude=$("#longitude","#registrationDialog").val();var mark_latitude=$("#mark_latitude","#registrationDialog").val();var mark_longitude=$("#mark_longitude","#registrationDialog").val();var google_zoom=$("#google_zoom","#registrationDialog").val();$('<div id="googleDialog" class="messageDialog"></div>').appendTo('body').hide();$('#googleDialog').load('google_preview.html',function(){$('.google_container',this).each(function(){src='http://maps.google.com/staticmap?center='+latitude+','+longitude+'&zoom='+google_zoom+'&size='+$(this).css('width').replace('px','')+'x'+$(this).css('height').replace('px','')+'&maptype=mobile&markers='+mark_latitude+','+mark_longitude+',redc&key='+global_googlekey;$(this).attr('src',src);});$('#googleDialog').dialog({buttons:{"Закрыть":function(){$('#googleDialog').dialog("close").dialog("destroy").remove();}},width:'780',height:'auto',resizable:false,closeOnEscape:true,title:'Отображение карты в мобильных телефонах'});});};function reload_google_address(){var str='';var address=$("#adressOrg","#registrationDialog").val();$('#google_address').val(address);};function init_map(map,message_id,update){map.addControl(new GSmallMapControl());map.enableScrollWheelZoom();$('#google_tab').data('map_init',0);GEvent.addListener(map,"click",function(overlay,latlng){if(latlng){map.clearOverlays();marker=new GMarker(latlng);map.addOverlay(marker);$('#mark_latitude').val(latlng.lat());$('#mark_longitude').val(latlng.lng());$('#google_zoom').val(map.getZoom());}});GEvent.addListener(map,"zoomend",function(){$('#google_zoom').val(map.getZoom());});GEvent.addListener(map,"moveend",function(){var point=map.getCenter();$('#latitude').val(point.lat());$('#longitude').val(point.lng());});};function reload_map(address,map,message_id,update){var geocoder=new GClientGeocoder();if(address!=""&&update!=true){if(geocoder){geocoder.getLocations(address,function(response){map.clearOverlays();if(!response||response.Status.code==602){$('#'+message_id).html('адрес не найден');}else if(response.Status.code!=200&&response.Status.code!=602){$('#'+message_id).html("Ошибка: "+response.Status.code+" Возможно адрес имеет некорректный вид.");}else{place=response.Placemark[0];point=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);zoom=Math.round(place.AddressDetails.Accuracy/9*23);map.setCenter(point,zoom);marker=new GMarker(point);map.addOverlay(marker);$('#latitude, #mark_latitude').val(point.lat());$('#longitude, #mark_longitude').val(point.lng());$('#google_zoom').val(map.getZoom());$('#'+message_id).html(' ');}});}}if(update==true){map.clearOverlays();point=new GLatLng($("#latitude","#registrationDialog").val(),$("#longitude","#registrationDialog").val());mark_point=new GLatLng($("#mark_latitude","#registrationDialog").val(),$("#mark_longitude","#registrationDialog").val());google_zoom=parseInt($("#google_zoom","#registrationDialog").val());marker=new GMarker(mark_point);map.addOverlay(marker);var markerBounds=new GLatLngBounds();var markerPoint=new GLatLng($("#mark_latitude","#registrationDialog").val(),$("#mark_longitude","#registrationDialog").val());markerBounds.extend(markerPoint);if(google_zoom<=0){google_zoom=map.getBoundsZoomLevel(markerBounds);$("#google_zoom","#registrationDialog").val(google_zoom);}if(!$("#mark_latitude","#registrationDialog").val()|| !$("#mark_longitude","#registrationDialog").val()){var center=markerBounds.getCenter();map.setCenter(center,google_zoom);}else{map.setCenter(point,google_zoom);}}return false;}
