// JavaScript Document
function addEvents() {
if(document.getElementById('location_edit_link').addEventListener) {
document.getElementById('location_edit_link').addEventListener('click',editLocation,false);}
if(document.getElementById('location_edit_link').attachEvent) {
document.getElementById('location_edit_link').attachEvent('onclick',editLocation);}}
function addTime() {
var falls = document.getElementById('falls_name').innerHTML;
var url = "http://waterfalls.jacobemerick.com/php/checktime.php?falls="+escape(falls)+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
document.getElementById('drive_time').innerHTML = xmlHttp.responseText;}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}
function editLocation() {
var currentLocation = document.getElementById('location').innerHTML;
var editLocationHtml = ' (save)
Provide an address, city/state, or zip';
document.getElementById('location_span').innerHTML = editLocationHtml;
if(document.getElementById('location_save_link').addEventListener) {
document.getElementById('location_save_link').addEventListener('click',saveLocation,false);}
if(document.getElementById('location_save_link').attachEvent) {
document.getElementById('location_save_link').attachEvent('onclick',saveLocation);}}
function saveLocation() {
var loc = document.getElementById('location_input').value;
var url = "http://waterfalls.jacobemerick.com/php/setcookie.php?loc="+escape(loc)+"&sid="+Math.random();
try {
xmlHttp=new XMLHttpRequest();}
catch(e) {
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
catch(e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
catch(e) {
alert("Your browser does not support AJAX. We cannot save a new location for you.");
return false;}}}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
if(xmlHttp.responseText=='Geocode Error') {
alert('There was an error with the address you entered. Please try again.');}
else {
document.getElementById('location_span').innerHTML = ''+xmlHttp.responseText+' (change)';
if(document.getElementById('drive_time')) {
addTime();}
addEvents();}}}
xmlHttp.open('get',url,true);
xmlHttp.send(null);
return true;}
if(document.addEventListener) {
document.addEventListener("DOMContentLoaded",addEvents,false);}
else {
if (document.all && !window.opera){
document.write('