/**
 * Get an element via it's ID
 *
 * @param string The ID of the element you want to fetch
 *
 * @return Returns false on error, and the element object with success
 */
function getObj(id)
{
    var obj = null;

    if(document.getElementById)
        obj = document.getElementById(id);
    else if(document.all)
        obj = document.all[id];
    else if(document.layers)
        obj = document.layers[id];

    return obj;
}





/**
 * Add a new cookie
 *
 * @param string    The name of the cookie
 * @param string    The value of the cookie
 * @param mixed     A pre-set date object or an integer representing the number of days. Default value creates a 'session' cookie.
 * @param string    The domain access of the cookie. Defaults to the current domain.
 * @param string    The path access of the cookie. Defaults to the entire site, "/".
 */
function setCookie(name, value, expires, domain, path)
{
    //------------------------------
    // Build expiry
    //------------------------------
    // Date object
    if(expires.toGMTString)
        expires = '; expires=' + expires.toGMTString();

    // Integer, assume its number of days
    else if(typeof(expires) == 'integer')
    {
        var date = new Date();
		date.setTime( date.getTime() + (expires * 86400) );
		expires = '; expires=' + date.toGMTString();
    }

    // Session cookie
    else
        expires = '';


    //------------------------------
    // Build domain
    //------------------------------
    if(domain)
        domain = '; domain=' + domain;
    else
        domain = '';


    //------------------------------
    // Build path
    //------------------------------
    if(path)
        path = '; path=' + path;
    else
        path = '; path=/';


    //------------------------------
    // Make cookie
    //------------------------------
    document.cookie = name + '=' + escape(value) + expires + domain + path;
}





/**
 * Read the value of a cookie.
 *
 * @param string The name of the cookie you want to gain the value of
 *
 * @return mixed The value of the cookie if it was found, and null if it was not
 */
function readCookie(name)
{
    var doc_cookies = document.cookie.split(';');
    search = name + '=';

    for(var i = 0; i < doc_cookies.length; i++)
    {
        cookie = doc_cookies[i];

        if(cookie.indexOf(search) != -1)
            return unescape(cookie.substring(search.length));
    }

    return null;
}

