1// Create xmlhttprequest object
2var xmlhttp = createXmlHttpRequestObject();
3var country;
4var state;
5var county;
6var locality;
7var deplocality;
8var saveLat;
9var saveLong;
10var page;
11var modeAll = false;
12  document.write('<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;" type="text/javascript"></script>');
13
14function initPage(alias) {
15  page = alias;
16}
17
18function reverseGeocode(latitude,longitude, btn){
19  var geocoder = new GClientGeocoder();
20  var latlng = new GLatLng(latitude, longitude);
21  hideButton('location');
22  addSampleUIHtml('focus-btn', 'Show a Closer Focus');
23  addSampleUIHtml('userInput', ' ');
24  saveLat  = latitude;
25  saveLong = longitude;
26
27  geocoder.getLocations(latlng, function(addresses) {
28    if(addresses.Status.code != 200) {
29      alert("reverse geocoder failed to find an address for " + latlng.toUrlValue());
30    } else {
31      var googleAddr = new GoogleAddress(addresses.Placemark[0]) ;
32      country = googleAddr.CountryNameCode;
33      state   = googleAddr.AdministrativeAreaName;
34      county  = googleAddr.SubAdministrativeAreaName;
35      locality = googleAddr.LocalityName;
36      deplocality = googleAddr.DependentLocalityName;
37
38      if (locality === undefined)
39        locality = deplocality;
40
41      xmlhttp.open("GET","lib/plugins/geonav/server/get_continent.php?q="+country+"&p="+page,true);
42      modeAll=false;
43      xmlhttp.onreadystatechange = displayContinent;
44      xmlhttp.send();
45    }
46    });
47}
48
49function processGeoCoderResult(response) {
50  if (response.Status.code == 200) {
51    var googleAddr = new GoogleAddress(response.Placemark[0]) ;
52        var zip = googleAddr.PostalCodeNumber ;
53        var latitude = googleAddr.coordinates[1] ;
54        var longitude =  googleAddr.coordinates[0] ;
55    }
56  }
57
58function displayContinent() {
59  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
60      document.getElementById("dokuwiki__content").innerHTML=xmlhttp.responseText;
61      exchangeHandler('focus-btn', buttonClick, readCountry);
62      jQuery('#bar__bottomleft').hide();
63    }
64}
65
66function readCountry(e) {
67    var element = e.target;
68    zoomIn(3500000);
69    xmlhttp.open("GET","lib/plugins/geonav/server/get_country.php?q="+country+"&p="+page,true);
70    xmlhttp.onreadystatechange = displayCountry;
71    modeAll=false;
72    xmlhttp.send();
73}
74
75function readState(e) {
76    var element = e.target;
77    zoomIn(500000);
78    xmlhttp.open("GET","lib/plugins/geonav/server/get_state.php?ctry="+country+"&q="+state+"&p="+page,true);
79    xmlhttp.onreadystatechange = displayState;
80    modeAll=false;
81    xmlhttp.send();
82}
83
84function readCounty(e) {
85    var element = e.target;
86    zoomIn(19000);
87    xmlhttp.open("GET","lib/plugins/geonav/server/get_county.php?ctry="+country+"&q="+state+"&county="+county+"&p="+page,true);
88    xmlhttp.onreadystatechange = displayCounty;
89    modeAll=false;
90    xmlhttp.send();
91}
92
93function readLocality(e) {
94    var element = e.target;
95    zoomIn(2000);
96    xmlhttp.open("GET","lib/plugins/geonav/server/get_locality.php?ctry="+country+"&q="+state+"&county="+county+"&locality="+locality+"&p="+page,true);
97    xmlhttp.onreadystatechange = displayLocality;
98    modeAll=false;
99    xmlhttp.send();
100}
101
102function displayCountry() {
103  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
104    document.getElementById("dokuwiki__content").innerHTML=xmlhttp.responseText;
105    // execute any scripts from page
106    var myDiv = document.getElementById("dokuwiki__content");
107    var myscripz = myDiv.getElementsByTagName('script');
108    for(var i=myscripz.length; i--;){
109          eval(myscripz[i].innerHTML);
110    }
111    // manage buttons
112     exchangeHandler('focus-btn', readCountry, readState);
113  }
114}
115
116function displayState() {
117  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
118    document.getElementById("dokuwiki__content").innerHTML=xmlhttp.responseText;
119    // execute any scripts from page
120    var myDiv = document.getElementById("dokuwiki__content");
121    var myscripz = myDiv.getElementsByTagName('script');
122    for(var i=myscripz.length; i--;){
123          eval(myscripz[i].innerHTML);
124    }
125    // manage buttons
126     exchangeHandler('focus-btn', readState, readCounty);
127  }
128}
129
130function displayCounty() {
131  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
132    document.getElementById("dokuwiki__content").innerHTML=xmlhttp.responseText;
133    // execute any scripts from page
134    var myDiv = document.getElementById("dokuwiki__content");
135    var myscripz = myDiv.getElementsByTagName('script');
136    for(var i=myscripz.length; i--;){
137          eval(myscripz[i].innerHTML);
138    }
139    // manage buttons
140     exchangeHandler('focus-btn', readCounty, readLocality);
141  }
142}
143
144function displayLocality() {
145  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
146    document.getElementById("dokuwiki__content").innerHTML=xmlhttp.responseText;
147    // execute any scripts from page
148    var myDiv = document.getElementById("dokuwiki__content");
149    var myscripz = myDiv.getElementsByTagName('script');
150    for(var i=myscripz.length; i--;){
151          eval(myscripz[i].innerHTML);
152    }
153    // manage buttons
154    exchangeHandler('focus-btn', readLocality, readLocality);
155    hideButton('focus-btn');
156  }
157}
158
159// creates an XMLHttpRequest instance
160function createXmlHttpRequestObject() {
161     // will store the reference to the XMLHttpRequest object
162     var xmlHttp;
163     // this should work for all browsers except IE6 and older
164     try
165     {
166        // try to create XMLHttpRequest object
167        xmlHttp = new XMLHttpRequest();
168     }
169      catch(e)
170     {
171       // assume IE6 or older
172       try
173     {
174       xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
175     }
176      catch(e) { }
177    }
178     // return the created object or display an error message
179      if (!xmlHttp)
180        alert("Error creating the XMLHttpRequest object.");
181     else
182      return xmlHttp;
183}
184
185function GoogleAddress(placeMark, curDepth)
186{
187  if(curDepth == null || isNaN(curDepth))
188    curDepth = 1 ;
189  else if (++curDepth == 10) // just to be safe do not recurse more than 10 times
190    return ;
191
192  for (var attr in placeMark)
193  {
194      if ((typeof(placeMark[attr]) != 'object') || (placeMark[attr] instanceof Array))
195      {
196          this[attr] = placeMark[attr] ;
197      } else {  // recurse thru sub-objects
198          GoogleAddress.call(this, placeMark[attr], curDepth) ;
199      }
200  }
201}
202