"use strict";
/*
 * Utility helper functions for the client side
 */

define([], function () {
    Array.prototype.pushUnique = function (val) {
        if (this.indexOf(val) === -1) {
            this.push(val);
        }

        return this;
    };

    //return utility functions
    return {
        /*
         * Returns true if the two boundingbox overlap
         */
        overlap : function (boundingBoxA, boundingBoxB) {
            var result = false;

            if (boundingBoxA.x < boundingBoxB.x2 && boundingBoxA.x2 > boundingBoxB.x && boundingBoxA.y < boundingBoxB.y2 && boundingBoxA.y2 > boundingBoxB.y) {
                result = true;
            }

            return result;
        },

        /*
         * Loads a CSS file dinamically
         */
        loadCSS : function (filePath) {
            var css	= document.createElement('link');
            css.rel		= 'stylesheet';
            css.type	= 'text/css';
            css.media	= 'all';
            css.href	= filePath;
            document.getElementsByTagName("head")[0].appendChild(css);
        },

        flattenObject: function (obj) {
            var result = {},
                discover;

            discover = function (o, prefix) {
                var i;

                for (i in o) {
                    if (o.hasOwnProperty(i)) {
                        if (_.isObject(o[i]) && !_.isArray(o[i])) {
                            discover(o[i], prefix === "" ? i + "." : prefix + i + ".");
                        } else {
                            result[prefix + i] = o[i];
                        }
                    }
                }
            };

            discover(obj, "");

            return result;
        },

        formattedDate: function (date, format) {
            var result = '',
                currentDate = new Date(),
                delta;

            format = format || 'UTC';

            //toISOString --> 2013-04-17T19:40:00.574Z
            //toUTCString --> Wed, 17 Apr 2013 19:40:15 GMT

            if (_.isDate(date)) {
                if (format === 'UTC') {
                    result = date.toUTCString();
                } else if (format === 'elapsed') {
                    delta = (currentDate - date) / 1000;    //elapsed time in seconds

                    if (delta < 45) {       //0..45 sec
                        result = 'just now';
                    } else if (delta < 90) {    //45..90 sec
                        result = 'a minute ago';
                    } else if (delta < 45 * 60) {    //90 sec 45 min
                        result = Math.round(delta / 60) + ' minutes ago';
                    } else if (delta < 90 * 60) {    //45 min to 90 min
                        result = 'an hour ago';
                    } else if (delta < 22 * 3600) {       //90 min to 22 hours
                        result = Math.round(delta / 3600) + ' hours ago';
                    } else if (delta < 36 * 3600) {       //22 hours to 36 hours
                        result = 'a day ago';
                    } else if (delta < 25 * 86400) {       //36 hours to 25 days
                        result = Math.round(delta / 86400) + ' days ago';
                    } else if (delta < 45 * 86400) {       //25 days to 45 days
                        result = 'a month ago';
                    } else if (delta < 345 * 86400) {       //45 days to 345 days
                        result = Math.round(delta / 2592000) + ' months ago';
                    } else if (delta < 547 * 86400) {       //45 days to 547 days (1.5 years)
                        result = 'a year ago';
                    } else {       //548+ days (1.5 years)
                        result = Math.round(delta / 31536000) + ' years ago';
                    }
                }
            }

            return result;
        }
    }
});
@@ -708,384 +708,8 @@
 %7D,%0A%0A
-        /*%0A         * Loads a CSS file dinamically%0A         */%0A        loadCSS : function (filePath) %7B%0A            var css%09= document.createElement('link');%0A            css.rel%09%09= 'stylesheet';%0A            css.type%09= 'text/css';%0A            css.media%09= 'all';%0A            css.href%09= filePath;%0A            document.getElementsByTagName(%22head%22)%5B0%5D.appendChild(css);%0A        %7D,%0A%0A
     

remove loadCSS method - not needed any more