var lngFormElement;
var latFormElement;
var pubAddressXmlRpcRequest=null;
var pubAddressXmlRequestPending=null;
var pubAddressXmlRequestBlocked=null;
var pubAddressXmlRequestQueued=null;
var pubAddressXmlRequestKey="";
var pubMarker=null;
function pubMapAddressProcessXml(){
if(pubAddressXmlRpcRequest.readyState==4){
var _1=pubAddressXmlRpcRequest.responseXML.documentElement;
if(_1.tagName=="p"){
var _2=new GLatLng(parseFloat(_1.getAttribute("xlat")),parseFloat(_1.getAttribute("xlng")));
var _3=new GLatLng(parseFloat(_1.getAttribute("nlat")),parseFloat(_1.getAttribute("nlng")));
var _4=new GLatLngBounds(_3,_2);
var _5=(_2.lat()+_3.lat())/2;
var _6=(_2.lng()+_3.lng())/2;
map.setZoom(map.getBoundsZoomLevel(_4));
map.setCenter(new GLatLng(_5,_6));
}
pubAddressXmlRequestBlocked=setTimeout("pubAddressXmlRequestBlocked_timeout()",5000);
if(pubAddressXmlRequestPending){
clearTimeout(pubAddressXmlRequestPending);
pubAddressXmlRequestPending=null;
}
}
}
function pubMapAddressPcChange(_7){
if(GBrowserIsCompatible()){
if((pubAddressXmlRequestPending===null)&&(pubAddressXmlRequestBlocked===null)){
var _8="pcxml.php?k="+pubAddressXmlRequestKey+"&pc="+escape(_7.value);
pubAddressXmlRequestQueued=null;
pubAddressXmlRequestPending=setTimeout("pubAddressXmlRequestPending_timeout()",5000);
if(pubAddressXmlRpcRequest===null){
pubAddressXmlRpcRequest=GXmlHttp.create();
}
pubAddressXmlRpcRequest.open("GET",_8,true);
pubAddressXmlRpcRequest.onreadystatechange=pubMapAddressProcessXml;
pubAddressXmlRpcRequest.send(null);
}else{
pubAddressXmlRequestQueued=_7;
}
}
}
function pubAddressXmlRequestBlocked_timeout(){
pubAddressXmlRequestBlocked=null;
if(pubAddressXmlRequestQueued){
pubMapAddressHandlePostcodeChange(pubAddressXmlRequestQueued);
}
}
function pubAddressXmlRequestPending_timeout(){
pubAddressXmlRpcRequest.abort();
pubAddressXmlRequestPending=null;
if(pubAddressXmlRequestQueued){
pubMapAddressHandlePostcodeChange(pubAddressXmlRequestQueued);
}
}
function pubMapAddressHandleClick(_9,_a){
if(!_9){
if(pubMarker){
pubMarker.setPoint(_a);
}else{
pubMarker=new GMarker(_a,{icon:highIcon,draggable:true});
map.addOverlay(pubMarker);
pubMarker.enableDragging();
GEvent.addListener(pubMarker,"dragend",pubMapAddressHandleDragEnd);
}
lngFormElement.value=_a.lng();
latFormElement.value=_a.lat();
}
}
function pubMapAddressHandleDragEnd(){
lngFormElement.value=pubMarker.getPoint().lng();
latFormElement.value=pubMarker.getPoint().lat();
}
function pubMapHandleValChange(){
if((lat=parseFloat(latFormElement.value))&&(lng=parseFloat(lngFormElement.value))){
var _b=new GLatLng(lat,lng);
if(pubMarker){
pubMarker.setPoint(_b);
}else{
pubMarker=new GMarker(_b,{icon:highIcon,draggable:true});
map.addOverlay(pubMarker);
pubMarker.enableDragging();
GEvent.addListener(pubMarker,"dragend",pubMapAddressHandleDragEnd);
}
map.panTo(_b);
}
}
function pubMapAddressGetMarkers(){
if(map.getZoom()>14){
pubMapGetMarkers();
}
}
function pubMapSetupAddress(_c,_d,_e,_f,_10,_11,key,_13){
if(GBrowserIsCompatible()){
var _14=document.getElementById("mapplace");
var _15=document.createElement("div");
_15.setAttribute("id","map");
_15.setAttribute("class","formmap");
_15.setAttribute("className","formmap");
if(_d){
_14.parentNode.replaceChild(_15,_14);
}else{
_14.firstChild.nodeValue="Please use the map below to locate the pub precisely, by clicking and dragging the marker.";
_14.parentNode.appendChild(_15);
}
map=new GMap2(document.getElementById("map"));
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
var _16=new GLatLng(_f,_e);
map.setCenter(_16,_10);
pubMapType=PUB_MAP_TYPE_ADDR;
if(_d){
map.disableDragging();
pubAddressXmlRequestBlocked=true;
}else{
map.addControl(new GSmallMapControl());
GEvent.addListener(map,"click",pubMapAddressHandleClick);
pubAddressXmlRequestKey=escape(key);
lngFormElement=document.getElementById(_c+"_lng_ID");
latFormElement=document.getElementById(_c+"_lat_ID");
GEvent.addDomListener(lngFormElement,"change",pubMapHandleValChange);
GEvent.addDomListener(latFormElement,"change",pubMapHandleValChange);
GEvent.addListener(map,"moveend",pubMapAddressGetMarkers);
pubMapTooltip=document.createElement("div");
map.getPane(G_MAP_FLOAT_PANE).appendChild(pubMapTooltip);
pubMapTooltip.style.visibility="hidden";
if(_11){
lngFormElement.value=_e;
latFormElement.value=_f;
}
}
GEvent.addListener(map,"moveend",function(){
map.savePosition();
});
GEvent.addDomListener(window,"resize",function(){
map.returnToSavedPosition();
});
map.savePosition();
if(_11){
if(_13>0){
homePub=new Object();
homePub.id=_13;
homePub.latLng=_16;
homePub.name="";
}
if(_d){
map.addOverlay(new GMarker(_16,{icon:highIcon,clickable:false}));
}else{
pubMarker=new GMarker(_16,{icon:highIcon,draggable:true});
map.addOverlay(pubMarker);
pubMarker.enableDragging();
GEvent.addListener(pubMarker,"dragend",pubMapAddressHandleDragEnd);
pubMapAddressGetMarkers();
}
}
}
}

