/*
 * $id$
 */

jQuery.noConflict();

/****************************  MATH fns ************************************/
function nullValue(val1, val2)
{
    return (val1 == null) ? val2 : val1;
}

function mathMax(val1, val2)
{
    return (val1 > val2) ? val1 : val2;
}

function mathMin(val1, val2)
{
    return (val1 < val2) ? val1 : val2;
}

function mathAbs(val)
{
    return (val < 0) ? -val : val;
}

function mathBoundary(val, lower, upper)
{
    return mathMin(mathMax(val, lower), upper);
}

function inBoundary(val, lower, upper)
{
    return (val >= lower) && (val <= upper);
}


/****************************  DATE fns ************************************/

var MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;

function formatDate(d, sep)
{
    if(sep == null)
    {
        sep = '.';
    }
    return d.getDate() + sep + (d.getMonth() + 1) + sep + d.getFullYear();
}

function truncateDate(d)
{
    return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
}

function getDateCount(date1, date2)
{
    return Math.floor(((date2 == undefined) ? date1 : (date2 - date1)) / MILLISECONDS_PER_DAY);
}

function dateEquals(date1, date2)
{
    return date1.getTime() == date2.getTime();
}


/****************************  DOM & document fns ************************************/
function showElement(elem, show)
{
    elem.style.visibility = ((show == undefined) || show) ? 'visible' : 'hidden';
}

function hideElement(elem, hide)
{
    elem.style.visibility = ((hide == undefined) || hide) ? 'hidden' : 'visible';
}

function getTextNode(elem, text)
{
    var node = document.createTextNode(((text == undefined) || (text == '')) ? ' ' : text);
    elem.appendChild(node);
    return node;
}

function setText(elem, text)
{
    elem.replaceData(0, elem.length, text);
}

function clearWindowTimeout(timeout)
{
    if(timeout != undefined)
    {
        clearTimeout(timeout);
    }
}

