/**
 * A collection of utility methods used elsewhere in cws
 * $Id: utils.js,v 1.2 2008/02/04 13:31:13 kmj Exp $
 */
/*jslint browser: true */

var utils = {

    /**
     * Used to determine if a string is zero-length (empty) or not
     * @param {String} val the input string to test
     * @return true or false
     * @type boolean
     */
    isEmpty: function(val){
        return val.length === 0 ? true : false;
    },
    
    /**
     * Normalizes the line-breaks used in different browsers/platforms
     * @param {String} The text to normalize
     * @return The normalized text
     * @type String
     */
    normalizeCRLF: function(string){
        if (typeof(string) == 'string') {
            return string.replace(/\r\n/g, "\n").replace(/\n\r/g, "\n").replace(/\r/g, "\n");
        }
        else {
            throw new Error("Method 'normalizeCRLF' requires string input");
        }
    },
    
    /**
     * Abstraction of the different browsers' methods of returning the height of the window
     * @return The window height
     * @type integer
     */
    windowHeight: function(){
        var windowHeight = 0;
        if (typeof(window.innerHeight) == 'number') {
            windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && document.documentElement.clientHeight) {
                windowHeight = document.documentElement.clientHeight;
            }
            else 
                if (document.body && document.body.clientHeight) {
                    windowHeight = document.body.clientHeight;
                }
        }
        return windowHeight;
    }
    
};

