function setCookie(strName, strValue, exprDays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exprDays);
    var strValue = escape(strValue) + ((exprDays == null) ? '' : '; expires=' + exdate.toUTCString()) + '; path=/';

    document.cookie = strName + '=' + strValue;
}

function redirect(file, isPopup)
{
    if (isPopup) {
        window.open(file, 'popupWindow');
    } else {
        window.location = file;
    }
}

function numberFormat(number, decimals, dec_point, thousands_sep)
{
    number = (number + '').replace(',', '').replace(' ', '');

    var n = !isFinite(+number) ? 0 : +number,
        prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
        sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
        dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
        s = '',
        toFixedFix = function (n, prec) {
            var k = Math.pow(10, prec);
            return '' + Math.round(n * k) / k;
        };
    s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
    if (s[0].length > 3) {
        s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
    }
    if ((s[1] || '').length < prec) {
        s[1] = s[1] || '';
        s[1] += new Array(prec - s[1].length + 1).join('0');
    }

    return s.join(dec);
}

function showBlackWall()
{
    $('body').append('<div id="blackWall" onClick="hideBlackWall();">&nbsp;</div>');
    $('#blackWall').css('opacity', 0.8);
    $('#blackWall').fadeIn();
}

function hideBlackWall()
{
    $('#blackWall').fadeOut('fast', function () {
        $('#blackWall').remove();
    });

    $('.isPopup').fadeOut('fast', function () {
        $('.isPopup').remove();
    });

    var searchTable = $('#search-table');
    if (searchTable.length) {
        searchTable.fadeOut();
    }
}

function setElementPosition(elemntId, position, parentElementId)
{
    position = (position ? position : 'center');

    var htmlElement = $('#' + elemntId);

    if (htmlElement.length) {
        var tablePosition = new Array;

        if (position == 'center') {
            tablePosition['x'] = (($(window).width() - htmlElement.innerWidth()) / 2);
            tablePosition['y'] = (($(window).height() - htmlElement.innerHeight()) / 2);
        } else if (position == 'top-right') {
            tablePosition['x'] = ($(window).width() - htmlElement.innerWidth() - 200);
            tablePosition['y'] = 0;
        } else if (position == 'cursorLeft') {
            tablePosition['x'] = (mousePosition.pageX - htmlElement.innerWidth() - 10);
            tablePosition['y'] = (mousePosition.pageY + 10);
        } else if (position == 'toElementTopRight') {
            var parentElement = $('#' + parentElementId);
            var parentElementPos = parentElement.offset();

            tablePosition['x'] = (parentElementPos.left - htmlElement.innerWidth() + parentElement.innerWidth());
            tablePosition['y'] = parentElementPos.top;
        }

        htmlElement.css({
            left: tablePosition['x'] + 'px',
            top:  tablePosition['y'] + 'px'
        });
    }
}

function hideMessage()
{
    $('#alertMessage').remove();
}
