Miscellaneous useful javascript functions & improvements