/*
 * Copyright (c) 2009 Discovery Health Systems.
 * The information contained in this file is the intellectual property of Discovery Health Systems (the owner).
 * No part of this file may be changed, copied or removed by persons other than the owner or persons
 * authorised to do so by the owner.
 */

/**
 * JQuery Utility functions to help with object retrieval, interigation and debugging.
 */
var JQueryUtils = jQuery.extend({
    /**
     * Creates a jquery id selector and searches the DOM for a jQuery object using the new id selector .
     * @param id The id value to constuct a valid jquery id selector from.
     * @return JQueryObject The jquery retrieved from the DOM that matches the id. Null if nothing is found.
     */
    jqo:function(id) {
        return $('#' + id);
    },
    /**
     * Get the id attribute of an jquery object.
     * @param obj The jQuery object to get the id attribute from.
     * @return String The id of the jQuery object, this could be null or empty.
     */
    getId:function(obj) {
        return obj.attr('id');
    },
    /**
     * Convenience function to alert the id attribute of a jQuery object).
     * @param obj The object to alert the id attribute from.
     */
    alertId:function(obj) {
        alert('Object id: ' + (obj.attr('id') ? obj.attr('id') : '<undefined>'));
    },
    /**
     * Convenience function to alert the class attribute of a jQuery object).
     * @param obj The object to alert the class attribute from.
     */
    alertClass:function(obj) {
        alert('Object css-class: ' + (obj.attr('class') ? obj.attr('class') : '<undefined>'));
    }
});
/**
 * String Utility functions to help with string manipilation and testing.
 */
var StringUtils = jQuery.extend({
    /**
     * Checks if a string contains the specified search string.
     * @param str The string to search for the specified search string.
     * @param searchStr The search string to check for in the specified string.
     * @return boolean True if the string contains the search string.
     */
    contains:function(str, searchStr) {
        if (str && searchStr) {
            return (str.search(searchStr) >= 0);
        } else {
            return false;
        }
    },
    /**
     * Substrings a string returning the string part after the specified seperator.
     * @param str The string to substring.
     * @param seperator The seperator to substring on.
     * @return String The string part after the seperator.
     */
    substringAfter:function(str, seperator) {
        if (str && seperator) {
            return str.split(seperator)[1];
        } else {
            return str;
        }
    },
    /**
     * Substrings a string returning the string part before the specified seperator.
     * @param str The string to substring.
     * @param seperator The seperator to substring on.
     * @return String The string part before the seperator.
     */
    substringBefore:function(str, seperator) {
        if (str && seperator) {
            return str.split(seperator)[0];
        } else {
            return str;
        }
    }
});
