/*
geminiCMS4_3 - The Tell Projekt: natura Shop
(c)2007 by Frank Reimering Software Systems
warenkorb.js
*/

function delBasket(wgid) {
    Check = window.confirm('Wollen Sie den Warenkorb wirklich leeren ?');
    if(Check) {
        startLoading();
        new Ajax.Request(
            "Core/backend/Warenkorb/warenkorb.php",
            {
                method: 'post',
                postBody: 'cmd=empty&wgid='+wgid,
                onComplete: function(req) {
                    //$("debug").innerHTML   = req.responseText;
                    //$("content").innerHTML = req.responseText;
                    stopLoading();
                    
                    updateBasket();
                    var aid = 1;
                    showWarenkorb(wgid,aid);


                },
                onError: function() {
                    showMessage("Es trat ein Fehler bei der Daten&uuml;bertragung auf.");
                }
            }
        )
    }
}

function deleteWarenkorbArtikel(wgid,aid,pos) {
    Check = window.confirm('Wollen Sie Artikel wirklich aus dem Warenkorb nehmen ?');
    if(Check) {
        startLoading();
        new Ajax.Request(
            "Core/backend/Warenkorb/warenkorb.php",
            {
                method: 'post',
                postBody: 'cmd=del&wgid='+wgid+'&aid='+aid+'&pos='+pos,
                onComplete: function(req) {
                    //$("debug").innerHTML   = req.responseText;
                    //$("content").innerHTML = req.responseText;

                    updateBasket();
                    showWarenkorb(wgid,aid);
                    stopLoading();
                },
                onError: function() {
                    showMessage("Es trat ein Fehler bei der Daten&uuml;bertragung auf.");
                }
            }
        )
    }
}

function changeWarenkorbArtikel(wgid,aid,pos) {

    var line = "aid_"+aid;
    var anzahl = $F(line);
    //alert(formdata.anzahl);

    if(anzahl > 0) {
        startLoading();
        new Ajax.Request(
            "Core/backend/Warenkorb/warenkorb.php",
            {
                method: 'post',
                postBody: 'cmd=change&wgid='+wgid+'&aid='+aid+'&pos='+pos+'&menge='+anzahl,
                onComplete: function(req) {
                    //$("debug").innerHTML   = req.responseText;

                    var text = '';
                    var data = req.responseText.parseJSON();
                    var status = data.elem.status;
                    if(status > 0) {
                        text = data.elem.text;
                    }
                    updateBasket();
                    showWarenkorb(wgid,aid,text);
                    stopLoading();
                },
                onError: function() {
                    showMessage("Es trat ein Fehler bei der Daten&uuml;bertragung auf.");
                }
            }
        )
    }
    else {
        deleteWarenkorbArtikel(wgid,aid,pos)
    }
}

function showWarenkorb(wgid,aid,text) {
    startLoading();
    new Ajax.Request(
        "Core/backend/Warenkorb/warenkorb.php",
        {
           method: 'post',
           postBody: 'cmd=showbasket',
           onComplete: function(req) {
                //$("debug").innerHTML   = req.responseText;
                $("content").innerHTML = req.responseText;
                
                if(text) {
                    if(text.length > 0) {
                        $("w_msg").style.display = "block";
                        $("w_msg").innerHTML = text;
                    }
                }
                stopLoading();


           },
           onError: function() {
                showMessage("Es trat ein Fehler bei der Daten&uuml;bertragung auf.");
           }
        }
    )
}

function updateBasket() {

    //$("debug").innerHTML = "WgId:"+wgid+"<br />Aid:"+aid;

    startLoading();
    new Ajax.Request(
        "Core/backend/Warenkorb/warenkorb.php",
        {
           method: 'post',
           postBody: 'cmd=basketinfo',
           onComplete: function(req) {
                //$("debug").innerHTML   = req.responseText;
                $("shop_receipt").innerHTML = req.responseText;
                stopLoading();
                
                
           },
           onError: function() {
                showMessage("Es trat ein Fehler bei der Daten&uuml;bertragung auf.");
           }
        }
    )
}


