﻿function getprice(price) {
    price = price;
    price = price.replace('.', '');
    price = price.replace(' ', '');
    return (price - 0);
}
function buyitem(id, price, name, pageid, obj, noi) {
   
    var noi = noi || 1;
    cart.AddToBasketPriceAndParent(id, name,noi, getprice(price), pageid, function () { added(obj); getcart(); });
}
function buyitem2(id, price, name, pageid, obj) {
    cart.AddToBasketPriceAndParent(id, name, 1, getprice(price)*18, pageid, function () { added2(obj); getcart(); });
}
function buymultiitem(id, price, name, pageid, obj) {
    var e = document.getElementById(id);
    cart.AddToBasketPriceAndParent(e.options[e.selectedIndex].value, name + " - " + e.options[e.selectedIndex].text, document.getElementById('ctl00_cph1_exNoi').value, getprice(price), pageid, function () { added(obj); getcart(); });
}

function buymultiitemEn(id, price, name, pageid, obj) {
    var e = document.getElementById(id);
    cart.AddToBasketPriceAndParent(e.options[e.selectedIndex].value, name + " - " + e.options[e.selectedIndex].text, document.getElementById('ctl00_cph1_exNoi').value, getprice(price), pageid, function () { addedEn(obj); getcart(); });
}
function buyitemEn(id, price, name, pageid, obj, noi) {

    var noi = noi || 1;
    cart.AddToBasketPriceAndParent(id, name, noi, getprice(price), pageid, function () { addedEn(obj); getcart(); });
}



function added(obj) {
    var parent = obj.parentNode;
    new Effect.Highlight(parent, { startcolor: '#111111', endcolor: '#04a0db' });
    var p = document.createElement('span');
    p.className = 'addedprod';
    p.innerHTML = 'Produkten lagd i <a href="/ordersida__14">kundkorgen</a>';
    parent.appendChild(p);
}

function addedEn(obj) {
    var parent = obj.parentNode;
    new Effect.Highlight(parent, { startcolor: '#111111', endcolor: '#04a0db' });
    var p = document.createElement('span');
    p.className = 'addedprod';
    p.innerHTML = 'Product added to cart <a href="/en/order-overview__1599">cart</a>';
    parent.appendChild(p);
}

function added2(obj) {
    window.location = '/se/ordersida__14?spec=1';
}
function getcart() {
    cart.GetLimitedCart(gotcart);
}
function gotcart(res) {
    //console.log(res);
    /*
    if (res.Count == 1) {
    window.scroll(0, 2000);
    setTimeout(function() { $('cartcont').appear(); }, 120);
    }
    */
    if (res.Count > 0)
        $('cartcont').style.display = 'block';
    var noi = $('cnoi');
    if (noi) {
        noi.innerHTML = res.Count + '';
    }

}
