var geocoder=null;
var map=null;
var locationMarker=null;
var center=null;
var hideClassName="iAmHereButtonGray";
function queryAddress(A){if(geocoder){geocoder.getLocations(A,function(B){processFoundLocation(B,true);
map.setCenter(locationMarker.getLatLng())
})
}}function submitForm(A){form=$(A);
if(!$("btn.set").hasClass(hideClassName)){form.submit()
}}function pointOnMap(A,B,C){queryAddress(A);
point=new GLatLng(B,C);
locationMarker.setLatLng(point);
map.setCenter(locationMarker.getLatLng())
}function addFakeButtons(){$("addContentButton").style.display="none";
$("addMessageButton").style.display="none";
var B=document.createElement("a");
B.setAttribute("class","addContentButton addContentButtonGray");
B.setAttribute("id","addContentButtonFake");
B.setAttribute("name","addContentButtonFake");
B.setAttribute("href","#");
$("addCntDiv").appendChild(B);
var A=document.createElement("a");
A.setAttribute("class","addMessageButton addMessageButtonGray");
A.setAttribute("id","addMessageButtonFake");
A.setAttribute("name","addMessageButtonFake");
A.setAttribute("href","#");
$("addMsgDiv").appendChild(A)
}function addRealButtons(){$("addContentButton").style.display="block";
$("addMessageButton").style.display="block";
if($("addContentButtonFake")){$("addContentButtonFake").style.display="none"
}if($("addMessageButtonFake")){$("addMessageButtonFake").style.display="none"
}}function processFoundLocation(D,B){var A=$("addressNotFound");
var J=$("cPanAddressNotFound");
var F=$("cPanAddress");
var C=$("btn.set");
var G=$("addMessageButton");
var H=$("observeLink");
if(!D||D.Status.code!=200){if(A!=null){A.removeClass("hide-class");
J.removeClass("hide-class");
F.addClass("hide-class");
addFakeButtons();
H.addClass("hide-class")
}if(C!=null){C.addClass(hideClassName)
}if(B){$("location.name").set("value","")
}}else{place=D.Placemark[0];
point=new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
var I=$("address");
if(B){locationMarker.setLatLng(point)
}else{if(I!=null){I.set("value",place.address);
F.set("text",place.address);
I.set("text",place.address)
}}if(I!=null){F.set("text",place.address)
}I.set("value",place.address);
if(A!=null){A.addClass("hide-class");
J.addClass("hide-class");
F.removeClass("hide-class");
addRealButtons();
H.removeClass("hide-class")
}if(C!=null){C.removeClass(hideClassName)
}$("location.lon").setProperty("value",locationMarker.getLatLng().lng());
$("location.lat").setProperty("value",locationMarker.getLatLng().lat());
$("location.name").setProperty("value",(place.address).toString().trim());
$("location.address.fullAddress").setProperty("value",(place.address).toString().trim());
$("location.address.accuracy").setProperty("value",place.AddressDetails.Accuracy);
country=$("location.address.country");
region=$("location.address.region").setProperty("value","");
city=$("location.address.city");
street=$("location.address.street");
postalCode=$("location.address.postalCode");
country.setProperty("value","");
region.setProperty("value","");
city.setProperty("value","");
street.setProperty("value","");
postalCode.setProperty("value","");
for(var E=0;
E<D.Placemark.length;
E++){place=D.Placemark[E].AddressDetails;
switch(place.Accuracy){case 1:country.setProperty("value",place.Country.CountryName.toString().trim());
break;
case 2:case 3:country.setProperty("value",place.Country.CountryName.toString().trim());
region.setProperty("value",place.Country.AdministrativeArea.AdministrativeAreaName);
break;
case 4:country.setProperty("value",place.Country.CountryName.toString().trim());
region.setProperty("value",place.Country.AdministrativeArea.AdministrativeAreaName);
city.setProperty("value",$defined(place.Country.AdministrativeArea.SubAdministrativeArea)?place.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName:$defined(place.Country.AdministrativeArea.Locality)?place.Country.AdministrativeArea.Locality.LocalityName:"");
break;
case 5:postalCode.setProperty("value",$defined(place.PostalCode)?place.PostalCode.PostalCodeNumber:place.Country.AdministrativeArea.SubAdministrativeArea?place.Country.AdministrativeArea.SubAdministrativeArea.PostalCode.PostalCodeNumber:place.Country.AdministrativeArea.PostalCode.PostalCodeNumber);
break;
case 6:case 7:case 8:case 9:street.setProperty("value",($defined(place.Country.AdministrativeArea.SubAdministrativeArea)?place.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName:place.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName));
break;
default:}}}}function initializeGMapDragable(){if($("gmap")){map=new GMap2(document.getElementById("gmap"));
lng=$("location.lon").get("value");
lat=$("location.lat").get("value");
var A=new GLatLng(lat,lng);
var B=new GMapTypeControl();
map.addControl(B);
map.setCenter(A,13);
map.addControl(new GLargeMapControl());
locationMarker=new GMarker(A,{draggable:true});
geocoder=new GClientGeocoder();
GEvent.addListener(locationMarker,"dragend",function(){geocoder.getLocations(locationMarker.getLatLng(),function(C){processFoundLocation(C,false)
})
});
GEvent.addListener(map,"click",function(C,D){if(D!=null){locationMarker.setLatLng(D);
geocoder.getLocations(locationMarker.getLatLng(),function(E){processFoundLocation(E,false)
})
}});
map.addOverlay(locationMarker)
}}function initializeGMap(){map=new GMap2(document.getElementById("gmapstatic"));
lng=$("location.lon").get("value");
lat=$("location.lat").get("value");
center=new GLatLng(lat,lng);
map.setCenter(center,13);
map.addControl(new GLargeMapControl());
var A=new GMarker(center,{draggable:false});
map.addOverlay(A);
if(!Browser.Engine.presto){if($("drawCircleRange")){loadEShapes(map,center)
}}fillGMap(map)
}function testRandom(){randSign=Math.random()>0.5?1:-1;
rand=Math.random()*0.001*randSign;
return rand
}function fillGMap(A){contents=$$("form[name=mapMarker]");
for(i=0;
i<contents.length;
i++){lat=parseFloat(contents[i]["lat"].value)+parseFloat(testRandom());
lon=parseFloat(contents[i]["lon"].value)+parseFloat(testRandom());
text=contents[i]["text"].value;
type=contents[i]["type"].value;
ident=contents[i]["ident"].value;
imageURL=contents[i]["imageURL"].value;
point=new GLatLng(lat,lon);
if(type=="post"){placePostMarker(lat,lon,text,"#"+ident)
}if(type=="user"){placeUserMarker(lat,lon,text,"#"+ident,imageURL)
}}}function placeUserMarker(E,F,A,D,C){markerOptions={icon:makeGIcon(C),title:A};
var B=new GMarker(new GLatLng(E,F),markerOptions);
B.txt=A;
map.addOverlay(B);
GEvent.addListener(B,"click",function(){window.location=D
});
return B
}function placePostMarker(D,E,A,C){markerOptions={icon:makeGIcon()};
A='<a href="'+C+'">'+A+"</a>";
var B=new GMarker(new GLatLng(D,E),markerOptions);
B.txt=A;
map.addOverlay(B);
GEvent.addListener(B,"click",function(){B.openInfoWindowHtml(B.txt)
});
return B
}function makeGIcon(B){var A=new GIcon(G_DEFAULT_ICON);
if(B!==undefined){A.iconSize=new GSize(24,24);
A.image=B
}else{A.iconSize=new GSize(32,32);
A.shadowSize=new GSize(59,32);
A.shadow="http://maps.google.com/mapfiles/kml/pal2/icon13s.png";
A.image="http://maps.google.com/mapfiles/kml/pal2/icon13.png"
}return A
}function loadCircle(){range=$("drawCircleRange").get("value");
calculateZoomLevel(map,range);
newPoliCyrcle=GPolygon.Circle(center,range,"#2788B8",1,0.5,"#0788B8",0.5);
map.addOverlay(newPoliCyrcle)
}function loadEShapes(C,A){var B=document.getElementsByTagName("head")[0];
eshapesscript=document.createElement("script");
eshapesscript.id="eshapes.js";
eshapesscript.type="text/javascript";
eshapesscript.src="../scripts/eshapes.js";
eshapesscript.onreadystatechange=function(){if(this.readyState=="complete"){loadCircle()
}};
eshapesscript.onload=loadCircle;
B.appendChild(eshapesscript);
return true
}function loadMaps(){google.load("maps","2",{"callback":initializeGMapDragable})
}function loadMapsStatic(){google.load("maps","2",{"callback":initializeGMap})
}function initGoogleMapV2Loader(){if($("gmap")){loadMaps()
}if($("gmapstatic")){loadMapsStatic()
}}function calculateZoomLevel(B,A){width=B.getSize().width;
height=B.getSize().height;
zoom=16;
maxDistanceInPixels=(height>width?width:height)/2;
for(z=16;
z>0;
z--){zoom=z;
visibleDistance=((maxDistanceInPixels/2)*Math.pow(2,(17-z)));
if(A<visibleDistance){break
}}B.setZoom(zoom)
};