-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.js
377 lines (321 loc) · 12.5 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
var geocoder;
function change_marker(location,map){
newAddress(location);
}
function newAddress(results) {
var location = results.toString();
var result = location.split(',');
var result_latitude = result[0].split('(');
var result_longitude = result[1].split(')');
var cookie = "cod=" + result_latitude[1] + ":" + result_longitude[0];
document.cookie = cookie;
geo_locator();
}
function geo_location(){
window.document.getElementById('location').innerHTML = " ";
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var test = WM_readCookie("cod");
if(test == 'none'){
var cookie = "cod=" + position.coords.latitude + ":" + position.coords.longitude;
document.cookie = cookie;}
geo_locator();
});
} else {
alert("I'm sorry, but geolocation services are not supported by your browser.");
}}
function geo_locator(){
window.document.getElementById("species_recorded").innerHTML = '';
read_function('surveys.xml', "GET",function(){if(request.readyState == 4)
{if(request.status == 200){var last_modified = request.getResponseHeader("Last-Modified");
var last_modified_date = new Date(last_modified);showmap(request.responseXML);
}}});
}
function showmap(xml_data){
var new_lat = WM_readCookie('cod');
var display = new_lat.split(':');
var new_lat = shorten(display[0]);
var new_long = shorten(display[1]);
var location = "latitude " + new_lat + " longitude " + new_long;
initialize(xml_data,display[0],display[1],location);
}
function shorten(number){
var changes = number.substring(0,6);
return changes;
}
function more(latlng,location){
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var locality = results[1].formatted_address.toString();
locality = locality.replace(/3D/,"");
var cookie = "location=" + locality;
var cookie = escape(cookie)+ ";";
var loci = results[1].formatted_address.toString();
var loci = loci.split(',');
document.cookie = cookie;
var located = "<div style='float:right;width:280px;'>" + location + "</div>" + results[1].formatted_address;
window.document.getElementById('location').innerHTML = located;
//search_engine(loci[0]);
}});
}
function search_engine(located){
search_function(located, "GET",function(){
if(request.readyState == 4)
{if(request.status == 200){
var elemental = request.responseText;
window.document.getElementById("footer").innerHTML = elemental;
}}});
}
function initialize(xml_data,p1,p2,location) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(p1,p2);
more(latlng,location);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
title:"You are here"
});
marker.setMap(map);
//
google.maps.event.addListener(map, 'click', function(event) {
var location = event.latLng;
change_marker(location,map);
});
//
var already_added = new Array();
var feed_content = getItems(xml_data,"data");
var photo_content = feed_content.reverse();
for(var loop = 0; loop < photo_content.length; loop++){
var this_photo = photo_content[loop];
var new_latitude = getFirstValue(this_photo,"lat");
var new_longitude = getFirstValue(this_photo,"long");
var user = getFirstValue(this_photo,"name");
var user = legal_symbols(user);
var this_date = getFirstValue(this_photo,"time");
var modified_Date = this_date.substring(5,22);
if(navigator.userAgent.indexOf("Chrome") != -1){
var modified_Date = this_date.substring(5,16);
}
var address = getFirstValue(this_photo,"location");
var address = legal_symbols(address);
address = address.replace(/3D/,"");
var name = new_latitude + new_longitude + user;
var strings_attached = already_added.toString();
if(strings_attached.indexOf(name) == -1){
already_added.push(name);
var latlng = new google.maps.LatLng(new_latitude,new_longitude);
var details = user + " " + modified_Date;
var image = 'images/bullet.gif';
var marker = new google.maps.Marker({
position: latlng,
title: details,
icon: image
});
add_listener(marker,new_latitude,new_longitude,address,user,map);
}
}
user_details(p1,p2);
}
function add_listener(marker,new_latitude,new_longitude,address,user,map){
google.maps.event.addListener(marker, 'click', function() {
species_located(new_latitude,new_longitude,address,user);});
marker.setMap(map);
}
function species_located(new_latitude,new_longitude,address,user){
var element = document.cookie.indexOf("start=");
if(element != -1){
alert('Please finish entering your survey details');
return;
}
window.document.getElementById('location').innerHTML = " ";
read_function('surveys.xml', "GET",function(){if(request.readyState == 4)
{if(request.status == 200){
new_initialize(new_latitude,new_longitude,user,address,request.responseXML);
}}});
}
function new_initialize(lat,long,name,address,xml_data) {
var edit_lat = lat.substring(0,6);
var edit_long = long.substring(0,6);
var location = "latitude " + edit_lat + " longitude " + edit_long;
var latlng = new google.maps.LatLng(lat,long);
var myOptions = {
zoom: 14,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var loci = address.split(',');
var loci = loci[0];
var located = "<div style='float:right;width:280px;'>" + location + "</div>" + address;
window.document.getElementById('location').innerHTML = located;
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var marker = new google.maps.Marker({
position: latlng,
title:"Survey Location"
});
var feed_content = getItems(xml_data,"data");
marker.setMap(map);
var photo_content = feed_content.reverse();
for(var loop = 0; loop < photo_content.length; loop++){
var this_photo = photo_content[loop];
var new_latitude = getFirstValue(this_photo,"lat");
var new_longitude = getFirstValue(this_photo,"long");
var user = getFirstValue(this_photo,"name");
var user = legal_symbols(user);
var address = getFirstValue(this_photo,"location");
var address = legal_symbols(address);
var address = address.replace(/3D/,"");
var this_date = getFirstValue(this_photo,"time");
var modified_Date = this_date.substring(5,22);
if(navigator.userAgent.indexOf("Chrome") != -1){
var modified_Date = this_date.substring(5,16);
}
if((new_latitude != lat) && (new_longitude != long)){
var latlng = new google.maps.LatLng(new_latitude,new_longitude);
var details = user + " " + modified_Date;
var image = 'images/bullet.gif';
var marker = new google.maps.Marker({
position: latlng,
title: details,
icon: image
});
add_listener(marker,new_latitude,new_longitude,address,user,map);
}
}
new_locator(lat,long,name,loci);
}
function new_locator(lat,long,name,loci){
read_function('species.xml', "GET",function(){if(request.readyState == 4)
{if(request.status == 200){var last_modified = request.getResponseHeader("Last-Modified");
var last_modified_date = new Date(last_modified);get_species(request.responseXML,lat,long,name);
//search_engine(loci);
}}});
}
function get_species(xml_data,new_latitude,new_longitude,user){
var page_contents = "<table width='100%' style='border-collapse:collapse;'><tr><td class='top'>SPECIES RECORDED by " + user + "</td><td></td></tr>";
var photo_forward_content = getItems(xml_data,"data");
var photo_content = photo_forward_content.reverse();
var times = new Array();
for(var loop = 0; loop < photo_content.length; loop++){
var this_photo = photo_content[loop];
var old_latitude = getFirstValue(this_photo,"lat");
var old_longitude = getFirstValue(this_photo,"long");
var species = getFirstValue(this_photo,"name");
var species = legal_symbols(species);
var number = getFirstValue(this_photo,"number");
var number = legal_symbols(number);
var user_name = getFirstValue(this_photo,"user");
var user_name = legal_symbols(user_name);
var this_date = getFirstValue(this_photo,"time");
if((new_longitude == old_longitude) && (new_latitude == old_latitude) && (user == user_name)){
if(times.length < 1){
var time_stamp = Date.parse(this_date);
var new_date = new Date(time_stamp).toUTCString();
var modified_Date = new_date.substring(5,22);
if(navigator.userAgent.indexOf("Chrome") != -1){
var modified_Date = this_date.substring(5,16);
}
page_contents += "<tr><td class='title'>Date: " + modified_Date + "</td><td class='title'>COUNT</td></tr>";
times.push(time_stamp);
}
for(var loop2 = 0; loop2 < times.length; loop2++){
var time_stamp = Date.parse(this_date);
var new_date = new Date(time_stamp).toUTCString();
if(time_stamp < times[loop2]){
var modified_Date = new_date.substring(5,22);
if(navigator.userAgent.indexOf("Chrome") != -1){
var modified_Date = this_date.substring(5,16);
}
page_contents += "<tr><td class='title'>Date: " + modified_Date + "</td><td class='title'>COUNT</td></tr>";
times.splice(0,1);
times.push(time_stamp);
}}
page_contents += "<tr><td class='intro' style='text-transform:capitalize;'>" + species + "</td><td class='intro'>" + number + "</td></tr>";
}
}
page_contents += "<tr><td style='border-left:1px solid #000000;border-bottom:1px solid #000000;padding:3px;background-color:#f0f0f0;color:#000000;'><a href='#' onClick='geo_locator();return false;' style='text-decoration:underline;'>BACK TO YOUR LOCATION</a></td><td style='background-color:#f0f0f0;border-bottom:1px solid #000000;border-right:1px solid #000000;'></td></tr></table>";
window.document.getElementById("species_recorded").innerHTML = page_contents;
}
function getItems(xml_info,item_type){
var the_items_array = new Array();
var items_element = xml_info.getElementsByTagName(item_type)[0];
var items = items_element.getElementsByTagName("item")
for(var loop = 0; loop < items.length; loop++){
the_items_array[loop] = items[loop];
}
return the_items_array;
}
function search_function(file_url,read_type,the_function){
if(window.XMLHttpRequest){request = new XMLHttpRequest();}
else{request = new ActiveXObject("Microsoft.XMLHTTP");}
var the_url = "testing.php?locality=" + file_url + "&t=" + new Date().getTime();
if(request){request.open(read_type,the_url); request.onreadystatechange = the_function; request.send(null);
}else{
}
}
function legal_symbols(existing_users){
var change_me = existing_users.replace(/a_12/g,"'").replace(/b_12/g,"\"").replace(/c_12/g,">").replace(/d_12/g,"<").replace(/e_12/g,"&");
return change_me;}
function illegal_symbols(value_one){
var change_me = value_one.replace(/'/g,"a_12").replace(/"/g,"b_12").replace(/>/g,"c_12").replace(/</g,"d_12").replace(/&/g,"e_12").replace(/</,"d_12").replace(/&rt;/,"c_12");
return change_me;}
function WM_readCookie(name) {
var no_cookie = 'none';
if (document.cookie == ''){
return no_cookie;}
else {
var firstChar, lastChar;
var theBigCookie = document.cookie;
var theBigCookie = theBigCookie.split(';');
var length = theBigCookie.length + 1;
for(var loop = 0; loop < length; loop ++){
firstChar = theBigCookie[loop].indexOf(name);
if(firstChar != -1){
firstChar += name.length + 1;
lastChar = theBigCookie[loop].length;
return unescape(theBigCookie[loop].substring(firstChar, lastChar));
if(firstChar != 1){
return no_cookie;
} }
}
}}
function bg_image(){
var an_image = new Image();
an_image.src = 'images/momenu.gif';
window.document.getElementById("1").style.backgroundImage = "url(images/momenu.gif)";
}
function slideshow(index,number){
window.document.getElementById("" + number + "").style.backgroundImage = "url(images/momenu.gif)";
for(loop = 1;loop < 5;loop++){
if(loop != number){
window.document.getElementById("" + loop + "").style.backgroundImage = "url(images/menu.gif)";}
}
read_function('premier.xml',"GET",function(){
if(request.readyState == 4){if(request.status == 200){
show(request.responseXML,index);}
else{document.getElementById("script_content").innerHTML = "Sorry, there was a problem with the server";}}});
}
function show(xml_info,index){
var display = new Array();
var xml_elements = xml_info.getElementsByTagName("item");
for(var loop=0; loop < xml_elements.length; loop ++) {
var name = getFirstValue(xml_elements[loop], "title");
if(name == index){
var desc = getFirstValue(xml_elements[loop], "description");
document.getElementById("script_content").innerHTML = desc;}
}
}
function read_function(file_url,read_type,the_function){
if(window.XMLHttpRequest){request = new XMLHttpRequest();}
else{request = new ActiveXObject("Microsoft.XMLHTTP");}
var the_url = "xmlobtain.php?Filename=" + file_url + "&t=" + new Date().getTime();
if(request){request.open(read_type,the_url); request.onreadystatechange = the_function; request.send(null);
}else{
}
}