var MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
              "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];

// Removes whitespace characters from the beginning and end of a string
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

// Formats a date like this: "MM/DD/YYYY" => "MMM. DD, YYYY"
function formatDate(date) {
    try {
        var separatorInd1 = date.indexOf("/");
        var mm = date.substring(0, separatorInd1);
        var separatorInd2 = date.indexOf("/", separatorInd1 + 1);
        var dd = date.substring(separatorInd1 + 1, separatorInd2);
        var yyyy = date.substring(separatorInd2 + 1);
        return MONTHS[mm - 1] + ". " + dd + ", " + yyyy;
    } catch (ex) {
        return null;
    }
}

// Changes element background according to temperature:
//   Low temperature (<= 0) => Blue background,
//   High temperature (> 0) => Red background
function mapElementBackgroundToTemperature(element, temperature) {
    if (temperature > 0) {
        element.style.backgroundImage = "url(gfx/temperature_warm.png)";
    } else {
        element.style.backgroundImage = "url(gfx/temperature_cold.png)";
    }
}

