function update_product( product, amount ) { 
    var ajaxutil = new DHTMLSuite.ajaxUtil();
    ajaxutil.sendRequest( '../webshop.php', 'action=update_product&pid='+product+'&amount='+amount, 'update_product_ajax' );
    //update_product_div_class( product, amount > 0 ? 1 : 0 );
    return 0;
}

function update_product_ajax( ajaxutil ) {
    var data = new Array();
    data = ajaxutil.response.split( '|' );
    return update_product_div_html( data );
}

function update_product_div_html( data ) {
    // data = array( productID, amount, currencyprefix, subtotal, total, timestamp );
    update_product_div_class( data[0], data[1] > 0 ? 1 : 0 );
    // Setting the  amount input boxes to the returned amount
    webshop = document.forms['webshop_form'];
    shopcart = document.forms['shopcart_form'];
    aform = shopcart ? shopcart : webshop;
    amountfield = 'amount_'+String( data[0] );
    if( (typeof aform[amountfield]['timestamp'] != "undefined") && aform[amountfield]['timestamp'] > data[5] ) { return 1; }
    aform[amountfield]['timestamp'] = data[5];
    webshop &&  (webshop[amountfield].value = data[1]);
    shopcart && (shopcart[amountfield].value = data[1]);
    // Setting the subtotal boxes to the returned subtotal
    document.getElementById( 'subtotal_'+data[0] ) && (document.getElementById( 'subtotal_'+data[0] ).innerHTML = data[2]+data[3]);
    document.getElementById( 'subtotalsc_'+data[0] ) && (document.getElementById( 'subtotalsc_'+data[0] ).innerHTML = data[2]+data[3]);
    // Setting the total boxes to the returned total
    document.getElementById( 'total' ) && (document.getElementById( 'total' ).innerHTML = data[2]+data[4]);
    document.getElementById( 'totalsc' ) && (document.getElementById( 'totalsc' ).innerHTML = data[2]+data[4]);
    return 0; 
}

function open_product_list( ) {
   productlist = window.open('../webshop.php?printable=1','productlist', 'left=100,top=0,width=750,height=2000,toolbar=0,status=0.location=0,resizable=1,scrollbars=1'); 
}

function update_product_div_class( pid, amount ) {
    (obj=getobject( 'subtotal_'+pid )) && (obj.className = (amount?"bold":""));
//    (obj=getobject( 'subtotalsc_'+pid )) && (obj.className = (amount?"bold":""));  
//  We dont do the ShopCart subtotal, because the list doesnt show products with amount 0.. shouldnt be bold
} 

function update_pid( pid, shopcart ) {
    shopcart = (shopcart ? 1 : 0);
//    amount = document.forms[(shopcart?'shopcart':'webshop')+'_form']['amount_'+pid].value;
    obj = getobject( (shopcart?'shopcart':'webshop')+'_form');
    amount = obj['amount_'+pid].value;
//alert( "Product "+pid+" has been ordered "+amount+" times" );
    return update_product( pid, amount );
}

function unroll_gid( icon, gid ) {
    togglediv( gid ); toggleclass( icon, 'icon hand minimize', 'icon hand expand' );
}
