if(self!=top)top.location.href=self.location.href;function callAjax(target,params,post)
{if(post==undefined)post=true;var target="/scripts/"+target+".php";var req=new AjaxRequest();if(post)req.setMethod("POST");req.loadXMLDoc(target,params);}
function logEvent(func,details)
{if(encodeURIComponent){var params="function="+encodeURIComponent(func)+"&details="+encodeURIComponent(details);callAjax("logEvent",params);}}
var timer;function suggestTown(input)
{if(encodeURIComponent){var params="q="+encodeURIComponent(input);callAjax("suggestTown",params,false);}}
window.onload=function()
{if(self.location.href.match(/\/admin\//))return;if(encodeURIComponent){var links=document.getElementsByTagName('a');for(var i=0;i<links.length;i++){if(links[i].href.charAt(0)=='#')continue;if(!links[i].href.match(/gdaypubs\.com\.au/)){links[i].onclick=function(){var params="src="+encodeURIComponent(location.href)+"&target="+encodeURIComponent(this.href);callAjax("record_outbound",params);return true;}}}}}
function notifyAdmin(name,newpos)
{if(encodeURIComponent){if(confirm("Do you want us to move the marker for "+name+" to this new location?")){var promptText="What are the reasons for this move? (required)";if(comments=prompt(promptText)){var params="name="+encodeURIComponent(name)+"&newpos="+encodeURIComponent(newpos)+"&comments="+encodeURIComponent(comments);callAjax("notifyAdmin",params);}}}}
function moveUpDiv(child)
{var parent=document.getElementById('pub_listing');parent.insertBefore(child,parent.firstChild);}
function openInfoWindow(position,content,title)
{logEvent('openInfoWindow',(title)?title:position.toString());if(infowindow)infowindow.close();infowindow=new g.InfoWindow();infowindow.setContent(content);infowindow.setPosition(position)
infowindow.open(map);}
var rotateMode=true;function showAddress(address,name,photo)
{var search_address=address.replace(/\n/g,',');logEvent('showAddress',search_address);geocoder.geocode({address:search_address},function(results,status)
{if(status==g.GeocoderStatus.OK){var latlng=results[0].geometry.location;if(pubGeoXml){pubZoom(latlng);}else{mapZoom(latlng);}
var title=name;var image=new g.MarkerImage("/maps/red-pushpin.png",new g.Size(32,32),new g.Point(0,0),new g.Point(9,31));var shadow=new g.MarkerImage('/maps/pushpin-shadow.png',new g.Size(59,32),new g.Point(0,0),new g.Point(9,31));var marker=new g.Marker({map:map,position:latlng,shadow:shadow,icon:image,title:title,draggable:true});var myHTML='<h2>'+title+'</h2>';myHTML+='<table border="0" cellpadding="5" cellspacing="0">';myHTML+='<tr style="vertical-align: top; text-align: center;">';myHTML+='<td><img src="'+photo+'" border="0" alt=""></td>';myHTML+='<td>';myHTML+='<p>'+address.replace(/\n/g,"<br>")+'</p>';myHTML+='<p><a href=\"#streetview\" onclick=\"rotateMode = false; showStreetView(new g.LatLng('+latlng.lat()+','+latlng.lng()+'));\">show street view</a></p>';myHTML+='</td>';myHTML+='</tr>';myHTML+='</table>';myHTML+='<p><small>If you know where this marker belongs please drag it to the correct location.</small></p>';openInfoWindow(latlng,myHTML,title);g.event.addListener(marker,"click",function(){openInfoWindow(latlng,myHTML,title);});g.event.addListener(marker,"dragend",function(e){notifyAdmin(title,e.latLng);});}else{alert(address+" not found");}});}
function townZoom()
{if(pubGeoXml){pubGeoXml.setMap(null);townGeoXml.setMap(map);map.setMapTypeId(g.MapTypeId.TERRAIN);map.setZoom(11);}
document.getElementById('c2').style['display']='none';document.getElementById('c1').style['display']='block';}
function mapZoom(latlng)
{map.setMapTypeId(g.MapTypeId.ROADMAP);map.setCenter(latlng);if(map.getZoom()<16)map.setZoom(16);}
function pubZoom(latlng)
{logEvent('pubZoom',latlng.toString());if(pubGeoXml){if(infowindow)infowindow.close();townGeoXml.setMap(null);pubGeoXml.setMap(map);mapZoom(latlng);}
document.getElementById('c1').style['display']='none';document.getElementById('c2').style['display']='block';}
var targetLatLng;function showStreetView(latlng)
{logEvent('showStreetView',latlng.toString());targetLatLng=latlng;pubZoom(latlng);sv.getPanoramaByLocation(latlng,100,displayStreetView);}
function displayStreetView(data,status)
{if(status==g.StreetViewStatus.OK){map.set('streetViewControl',true);document.getElementById('streetview').style['display']='block';document.getElementById('c1').style['display']='none';document.getElementById('c2').style['display']='none';panorama.setPosition(data.location.latLng);panorama.setVisible(true);}else{map.set('streetViewControl',false);document.getElementById('streetview').style['display']='none';document.getElementById('c1').style['display']='none';document.getElementById('c2').style['display']='block';panorama.setVisible(false);alert("Sorry, we couldn't find a camera within 100m of your selected location.");}}
function hideCamera()
{if(!panorama.getVisible()){logEvent('hideCamera','-');map.set('streetViewControl',false);document.getElementById('streetview').style['display']='none';document.getElementById('c2').style['display']='block';}}
function bearing(from,to)
{if(from==null)return false;var a,b,c,d,e;var toRad=function(input){return input*Math.PI/180;}
a=toRad(from.lat());b=toRad(from.lng());c=toRad(to.lat());d=toRad(to.lng());with(Math){e=-atan2(sin(b-d)*cos(c),cos(a)*sin(c)-sin(a)*cos(c)*cos(b-d));if(e<0.0)e+=PI*2.0;e=e*180.0/PI;}
return parseFloat(e.toFixed(1));}
function cameraMoved()
{if(rotateMode){var heading=bearing(panorama.getPosition(),targetLatLng);if(heading)panorama.setPov({heading:heading,pitch:0,zoom:1});}}
function hideLocation()
{document.getElementById('geoloc').style['display']="none";document.cookie="hideLocation=true; path=/";}
function AjaxRequest()
{var req;var method="GET";var nocache=false;var handler;this.loadXMLDoc=function(url,params)
{if(window.XMLHttpRequest){try{req=new XMLHttpRequest();}catch(e){req=false;}}else if(window.ActiveXObject){try{req=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{req=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){req=false;}}}
if(req){if(!handler)handler=processReqChange;req.onreadystatechange=handler;if(nocache){params+=(params!='')?'&'+(new Date()).getTime():(new Date()).getTime();}
if(method=="POST"){req.open("POST",url,true);req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');req.send(params);}else{if(params)url+="?"+params;req.open(method,url,true);req.send(null);}
return true;}
return false;}
this.setMethod=function(newmethod){method=newmethod.toUpperCase();}
this.nocache=function(){nocache=true;}
this.setHandler=function(fn){handler=fn;}
this.getResponse=function(){return req;}
var getNodeValue=function(parent,tagName)
{var node=parent.getElementsByTagName(tagName)[0];return(node&&node.firstChild)?node.firstChild.nodeValue:'';}
var processReqChange=function()
{if(req.readyState==4&&req.status==200){var response=req.responseXML.documentElement;var commands=response.getElementsByTagName('command');for(var i=0;i<commands.length;i++){method=commands[i].getAttribute('method');switch(method)
{case'alert':var message=getNodeValue(commands[i],'message');window.alert(message);break;case'setvalue':var target=getNodeValue(commands[i],'target');var value=getNodeValue(commands[i],'value');if(target&&value!=null){document.getElementById(target).value=value;}
break;case'setdefault':var target=getNodeValue(commands[i],'target');if(target){document.getElementById(target).value=document.getElementById(target).defaultValue;}
break;case'focus':var target=getNodeValue(commands[i],'target');if(target){document.getElementById(target).focus();}
break;case'setcontent':var target=getNodeValue(commands[i],'target');var content=getNodeValue(commands[i],'content');if(target&&content!=null){document.getElementById(target).innerHTML=content;}
break;case'setstyle':var target=getNodeValue(commands[i],'target');var property=getNodeValue(commands[i],'property');var value=getNodeValue(commands[i],'value');if(target&&property&&value){document.getElementById(target).style[property]=value;}
break;case'setproperty':var target=getNodeValue(commands[i],'target');var property=getNodeValue(commands[i],'property');var value=getNodeValue(commands[i],'value');if(value=="true")value=true;if(value=="false")value=false;if(target){document.getElementById(target)[property]=value;}
break;default:window.console.log("Error: unrecognised method '"+method+"' in processReqChange()");}}}}}
var newWindow;function openWindow(path,width,height,scroll)
{if(!scroll)scroll="no";newWindow=window.open(path,"myWindow","scrollbars="+scroll+",width="+width+",height="+height);if(self.focus)newWindow.window.focus();}
