ESHA.namespace("util");

ESHA.util.formatISO8601Date = function(dateObject) {
    var year = dateObject.getFullYear();

    var month = dateObject.getMonth() + 1;
    if (month < 10) {
        month = "0" + month;
    }

    var day = dateObject.getDate();
    if (day < 10) {
        day = "0" + day;
    }

    return (year + "-" + month + "-" + day);
}

ESHA.util.isIE = function() {
    return (navigator.userAgent.toLowerCase().indexOf('msie') != -1);
}

/**
 * Returns -1, 0, or 1 as x is negative, zero, or positive.
 */
ESHA.util.signum = function(x) {
    if (x < 0) {
        return -1;
    } else if (x > 0) {
        return 1;
    } else {
        return 0;
    }
}

/**
 * Determines whether an HTMLElement, or any of its ancesotrs, has the given
 * className.
 *
 * @param el the element to test
 * @param className the class name to search for
 * @return a boolean value
 */
ESHA.util.hasAncestorClass = function(el, className) {
    if (el == null) {
        return false;
    } else if (YAHOO.util.Dom.hasClass(el, className)) {
        return true;
    } else {
        return ESHA.util.hasAncestorClass(el.parentNode, className);
    }
}
