function show_weather(struct) {
  try {
    var temp = parseInt((parseInt(struct['weatherObservation']['temperature']) * 1.8) + 32);
    var humidity = parseInt(struct['weatherObservation']['humidity']);
    var wind = parseFloat(struct['weatherObservation']['windSpeed']);
    wind = parseInt(wind * 0.621371192); // I think that wind is kph.
    if (wind > 0) {
      wind = ', wind ' + wind + 'mph';
    } else {
      wind = '';
    }
    var clouds = struct['weatherObservation']['clouds'];
    if (clouds != 'n/a') {
      clouds = ', ' + clouds;
    } else {
      clouds = '';
    }
    var condition = struct['weatherObservation']['weatherCondition'];
    if (condition != 'n/a') {
      condition = ' with ' + condition;
    } else {
      condition = '';
    }
    $('weather').update(temp + '&deg;F' + wind + ', ' + humidity + '% humidity' + clouds + condition);
  } catch(e) {};
}

function search_results(struct) {
  if (struct['responseStatus'] == 200) {
    results_div = $('search_results').update('');
    struct['responseData']['results'].each(function(result) {
      var inner_div = new Element('div', {'class': 'search_result'});
      inner_div.appendChild(new Element('a', {'href': result['unescapedUrl'], 
                                              'target': '_blank'}).update(result['titleNoFormatting'] + ' <span class="small_google_result">' + result['visibleUrl'] + '</span>'));
      results_div.appendChild(inner_div);
    });
  }
  if ($('search_results').childNodes.length == 0) $($('search_results').parentNode.parentNode).remove();
}
// http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=muir%20woods%20site:.gov&callback=processResults

function vote(agree, type_id, park_id, id) {
  new Ajax.Request('/vote/' + park_id + '/' + type_id + '/' + agree + '/' + id, {asynchronous:true, evalScripts:true, method:'post'});
}

function add_url(park_id) {
  var url = $('url_suggest').value;
  var name = $('name_suggest').value;
  var desc = $('desc_suggest').value;
  new Ajax.Request('/submit_link/' + park_id, {asynchronous:true, evalScripts:true, method:'post', parameters:'url=' + encodeURIComponent(url) + '&name=' + encodeURIComponent(name) + '&desc=' + encodeURIComponent(desc)});
}

function accept_vote(agree, elem) {
  elem.className = (agree == 1) ? 'activity_yes activity' : 'activity_no activity';
  elem.select('div.activity_votes, span.unknown_amenity').each(function(el) {
    el.update('');
  });
}

function reject_vote(agree, elem) {
  alert("Sorry, unable to save vote.  Perhaps you have already voted on this activity?");
}
