function set_sum_of_products()
{
    new Ajax.Request('list_sum.php', {method: 'post', 
		onSuccess: function(tr){
		var p = tr.responseText.evalJSON();
		var s = p.cost;
		if(p.unknown_price){s = s + ' + ismeretlen';}
		$('sum_position').innerHTML = s;}});
}
function product_quantity_changed(category, id, quantity_id)
{
    new Ajax.Request('list_manipulate.php',
		     {method:'post', parameters: {'category' : category, 'id' : id, 'quantity' : $(quantity_id).value, 'operation' : 'change'},
			     onLoading: function(tr){document.body.style.cursor='wait';},
			     onSuccess: function(tr){document.body.style.cursor='default';set_sum_of_products();}});
}


// add-on, add-off change
function ps3(p0, p1, p2){return '\'' + p0 + '\',\'' + p1 + '\',\'' + p2 + '\'';}
function change_to_add_off(divid, category, id)
{
    var e = new Element('img', {'id':divid, 'src':'media/atc_off.jpg'});
    e.onclick = function(){product_add_off(divid, category, id);};
    e.onmouseover = function(){document.body.style.cursor = 'pointer';};
    e.onmouseout = function(){document.body.style.cursor = 'default';};
    ($(divid)).replace(e);
}
function change_to_add_on(divid, category, id)
{
    var e = new Element('img', {'id':divid, 'src':'media/atc_on.jpg'});
    e.onclick = function(){product_add_on(divid, category, id);};
    e.onmouseover = function(){document.body.style.cursor = 'pointer';};
    e.onmouseout = function(){document.body.style.cursor = 'default';};
    ($(divid)).replace(e);
}
function product_add_on(divid, category, id)
{
    new Ajax.Request('list_manipulate.php',
		     {method: 'post', parameters: {'category':category, 'id':id, 'operation':'add_to_cart'},
			     onLoading: function(tr){document.body.style.cursor='wait';},
			     onSuccess: function(tr){change_to_add_off(divid, category, id);document.body.style.cursor='default';}});
}
function product_add_off(divid, category, id)
{
    new Ajax.Request('list_manipulate.php',
		     {method: 'post', parameters: {'category':category, 'id':id, 'operation':'delete'},
			     onLoading: function(tr){document.body.style.cursor='wait';},
			     onSuccess: function(tr){change_to_add_on(divid, category, id);document.body.style.cursor='default';}});
}

function remove_divid(divid){if($(divid)){$(divid).remove();}}
function check_section(divid){if($(divid).getElementsByTagName('tr').length == 1){remove_divid(divid);}}
function remove_and_check_section(divid, section_divid)
{
    remove_divid(divid);
    check_section(section_divid);
    set_sum_of_products();
}
function product_delete_from_cart(section_divid, divid, category, id)
{
    new Ajax.Request('list_manipulate.php',
		     {method: 'post', parameters: {'category':category, 'id':id, 'operation':'delete'},
			     onLoading: function(tr){document.body.style.cursor='wait';},
			     onSuccess: function(tr){remove_and_check_section(divid, section_divid);document.body.style.cursor='default';}})
}
function add_product_delete_from_cart(imgid, section_divid, divid, category, id){
    var e = $(imgid);
    e.onmouseover = function(){document.body.style.cursor = 'pointer';};
    e.onmouseout = function(){document.body.style.cursor = 'pointer';};
    e.onclick = function(){product_delete_from_cart(section_divid, divid, category, id);};
}

 
function delete_list()
{
    new Ajax.Request('list_delete.php', {method: 'post',
		onSuccess: function (tr) {remove_divid('chain_section'); remove_divid('front_sprocket_section'); remove_divid('back_sprocket_section'); remove_divid('color_chain_section');}});
    set_sum_of_products();
}



