
function preloadImage(src)
{
    var img = new Image();
    img.src = src;
}

function addButtonStateEvents(image, anchor, downSrc, overSrc)
{
    var image = $(image);
    image.src_normal = image.src;
    
    var anchor = $(anchor);
    
    if (typeof(downSrc) != 'undefined' && downSrc.length > 0)
    {
        image.src_down = downSrc;
        preloadImage(downSrc);
        anchor.addEvent('mousedown', buttonMousedown.bindWithEvent(image));
        anchor.addEvent('mouseup', buttonMouseup.bindWithEvent(image));
    }
    if (typeof(overSrc) != 'undefined' && overSrc.length > 0)
    {
        image.src_over = overSrc;
        preloadImage(overSrc);
        anchor.addEvent('mouseover', buttonMouseover.bindWithEvent(image));
        anchor.addEvent('mouseout', buttonMouseout.bindWithEvent(image));
    }
}

function addButtonAnchor(image, anchor)
{
    var image = $(image);
    var anchor = $(anchor);
    
    if (image.src_down)
    {
        anchor.addEvent('mousedown', buttonMousedown.bindWithEvent(image));
        anchor.addEvent('mouseup', buttonMouseup.bindWithEvent(image));
    }
    
    if (image.src_over)
    {
        anchor.addEvent('mouseover', buttonMouseover.bindWithEvent(image));
        anchor.addEvent('mouseout', buttonMouseout.bindWithEvent(image));
    }
}

function buttonMouseover(event)
{
    if (this.src_over)
        this.src = this.src_over;
}

function buttonMouseout(event)
{
    if (this.src_normal)
        this.src = this.src_normal;
}
           
function numbersOnly(event)
{
    //Allow numbers, backspace, tab, reverse tab and return
    if (window.event)
        key = window.event.keyCode;
    else
        key = event.which;
    
    if ((key < 48 || key > 57) && key != 8 && key != 9 && key != 25 && key != 13 && key != 0 && key != 118)
        return false;
    else
        return true;
}