﻿Event.observe(window, 'load', function() {
    if ($('MiniBasket')) {
        new Ajax.Request('/ajax/MiniBasket.aspx?' + getTicks(), {
            method: 'get',
            onSuccess: function(transport) {
                $('MiniBasket').update(getContent(transport.responseText));
            }
        });
    };

    if ($('hotSpot')) {
        Event.observe($('hotSpot'), 'dblclick', getName);
    };

    if ($('Warning')) {
        Website.lightsOff();
        $('Warning').appear();
    };

    if ($('Message')) {
        Website.lightsOff();
        $('Message').appear();
    };
});

function getName() {
    document.location.href='/ajax/SetUser.aspx?username=' + prompt('What is your name?');
};

function getContent(s) {
    return s.substring(s.indexOf('<!--START-->'), s.indexOf('<!--END-->') + 10);
};

function formatCurrency(num, includeplus) {
    if (num < 0) {
        return '- £' + (num * -1).toFixed(2);
    };

    if (num > 0) {        
        return (includeplus ? '+ ': '') + '£' + num.toFixed(2);
    };

    return '£0.00';
};

function roundNumber(num, dec) {
    return num.toFixed(dec);
    //return Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
};

function getTicks() {
    return new Date().getTime();
};