function CssUtil() {
}

/**
 * Apply a CSS class name to a DOM node.
 * The CSS class is appended to any existing classes.
 * Removes any existing instances of the provided class name, to prevent duplicates.
 *
 * @param node the Node to apply the class to
 * @param className a String containing the CSS class name to apply
 */
CssUtil.addCssClass = function(node, className) {
  if (node) {
    CssUtil.removeCssClass(node, className); // Remove any existing instances of this class name.
    node.className += " " + className + " ";
  }
};

/**
 * Remove the specified CSS class name (if present) from a DOM node.
 *
 * @param node the Node to remove the class to
 * @param className a String containing the CSS class name to remove
 */
CssUtil.removeCssClass = function(node, className) {
  if (node) {
    node.className = node.className.replace(new RegExp("\\b" + className + "\\b", "g"), "");
  }
};

/**
 * Add or remove a CSS class, depending on the value of the provided boolean
 * 
 * @param node the Node to remove the class to
 * @param className a String containing the CSS class name to remove
 * @param test a boolean specifying whether to add (=true) or remove (=false) the class
 */
CssUtil.applyCssClass = function(node, className, test) {
  if (test) {
    CssUtil.addCssClass(node, className);
  } else {
    CssUtil.removeCssClass(node, className);
  }
};

/**
 * Check if a node has a particular CSS class name.
 *
 * @param node the Node to check
 * @param className a String containing the CSS class name to check for
 * @type boolean
 * @returns <code>true</code> if the Node has the class assigned, <code>false</code> if not.
 */
CssUtil.hasCssClass = function(node, className) {
  if (node) {
    var re = new RegExp("\\b" + className + "\\b", "g");
    return re.test(node.className);
  }
};

/**
 * Toggle a particular CSS class name on a node (add it if not there, remove it if it is).
 *
 * @param node the Node to check
 * @param className a String containing the CSS class name to check for
 */
CssUtil.toggleCssClass = function(node, className) {
  if (node) {
    var re = new RegExp("\\b" + className + "\\b", "g");
    if (re.test(node.className)) {
      node.className = node.className.replace(re, "");
    } else {
      node.className += " " + className + " ";
    }
  }
};

