$(document).ready(function(){
    if ($.browser.msie)
    {
        if ($.browser.version <= 6)
        {
            try {document.execCommand("BackgroundImageCache", false, true);} catch(err){};
            if (window['DD_belatedPNG'] !== undefined)
                DD_belatedPNG.fix('img, #side2 li, .pngfix');
        }
    }

    $('#b2 span')
        .find('a.btn-print')
            .click(function() {
                window.print();
                return false;
            })
            .end()
        .find('a.btn-text_down, a.btn-text_reset, a.btn-text_up')
            .click(function() {
                var cont = $('#container');
                if(!cont.data('font_size')){
                    cont.data('font_size', 100);
                    cont.css('font-size', cont.data('font_size') + '%');
                }
                
                var newsize = 100;
                if ($(this).hasClass('btn-text_down')) {
                    newsize = cont.data('font_size')-10;
                }
                else if($(this).hasClass('btn-text_up')){
                    newsize = cont.data('font_size')+10;
                }
                
                cont.data('font_size', newsize);
                $(cont).css('font-size', newsize + '%');
                return false;
            })
            .end();
});



function isValid(value){
    return value.length > 0 && !isNaN(value);
}

function errorDialog(error_msg, element){
    $('<div class="ui-state-error"><p><span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-alert"><\/span>' + error_msg + '<\/p><\/div>').dialog({
        title: 'An error has occurred',
        modal: true,
        draggable: false,
        resizable: false,
        buttons: {
            Close: function() {
                $(this).dialog('close');
                element.focus();
            }
        },
        close: function() {
            element.focus();
        }
    });
}

function number_format(number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands  
    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;
        };
    // Fix for IE parseFloat(0.55).toFixed(0) = 0;
    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);
}
