function imgChange(id, img) {
    document.getElementById(id).src = img;
}

var process = false;

function addToCart(id) {
    var loading_text = '<br /><div align="center"><img src="images/loading7.gif" alt="" /></div><br />';
    
    qty = parseFloat($('qty_'+id).value);
    
    size = 0;
    if ( document.getElementById('size_'+id) )
    {
        var sel = document.getElementById('size_'+id);
        size = sel.options[sel.selectedIndex].value;
    }
    
    if ( isNaN(qty) || qty == 0 ) {
        alert('Specify please quantity.');
        return;
    }
    
    process = true;
    hideAddBtn("hide");
    $('qty_'+id).value = '';
    
    // Update
    $('shopping').innerHTML = loading_text;
    var pars = 'prod_id=' + id + '&qty=' + qty + '&size=' + size + '&rand=' + Math.random();
    new Ajax.Updater('shopping', 'app/ajax/shopping.php', {parameters: pars, asynchronous: true, evalScripts: true});
    
    new Effect.ScrollTo('top', {afterFinish: aFinish});
}

function hideAddBtn(wtf) {
    for ( i=1; i<999; i++ ) {
        if ( $('bt_'+i) ) {
            if ( wtf == "show" ) {
                $('btt_'+i).style.display = 'none';
                $('bt_'+i).style.display = '';
            } else {
                $('bt_'+i).style.display = 'none';
                $('btt_'+i).style.display = '';
            }
        } else {
            break;
        }
    }
}

function aFinish() {
    new Effect.Highlight('shopping', {afterFinish: eFinish});
}
function eFinish() {
    process = false;
    hideAddBtn("show");
}

