var gTextBoxQuantity = 0;

function SleBasketAdd(pItemno, pQuantity, pUserId, pSessionId, pLanguageCode) {
    if (Page_ClientValidate()) {

        var lTextBoxQuantity = document.getElementById(pQuantity).value;
        gTextBoxQuantity = lTextBoxQuantity;

        reqviaproxy = AjaxService1.AddToBasket(pItemno, lTextBoxQuantity, pUserId, pSessionId, pLanguageCode,
                SleOnCompleteBasketAdd,
                SleOnTimeoutBasketAdd);

        SleUpdateProcuctCount(pUserId, pSessionId);

        return false;
    }
    else {
        document.getElementById(pQuantity).value = '1';
    }
}

function SleOnCompleteBasketAdd(results) {

    var lOldVal = document.getElementById('ctl00_BasketOverView1_LabelBasketCount').firstChild.data;
    var lNewVal = (parseInt(lOldVal) + parseInt(gTextBoxQuantity));
    document.getElementById('ctl00_BasketOverView1_LabelBasketCount').firstChild.data = lNewVal;

}
function SleOnTimeoutBasketAdd(results) {
    alert("Timout");
}




function SleBasketAddFromTextBox(pItemno, pQuantity, pUserId, pSessionId, pLanguageCode, pEvent, pSender) {
    //        if (!handled) {
    var evt = pEvent || window.event;
    if (!evt)
        return;
    // key bekommt den keyCode browserunabhängig zugewiesen
    var key = 0;
    // für mozilla/ff, wenn keycode==0 muss 'evt.which' abgefragt werden
    if (evt.keyCode) { key = evt.keyCode; }
    else if (typeof (evt.which) != 'undefined') { key = evt.which; }
    // return wurde gedrückt.
    if (key == 13) {
        if (Page_ClientValidate()) {

            //                    handled = false;
            var lTextBoxQuantity = document.getElementById(pQuantity).value;
            gTextBoxQuantity = lTextBoxQuantity;

            reqviaproxy = AjaxService1.AddToBasket(pItemno, lTextBoxQuantity, pUserId, pSessionId, pLanguageCode,
                SleOnTextBoxComplete,
                SleOnTextBoxTimeout);

            SleUpdateProcuctCount(pUserId, pSessionId);

            //document.getElementById(pBaskAddConfrimClientID).value = 'Produkt wurde in den Warenkorb gelegt.';
            return false;
        }
        else {
            document.getElementById(pQuantity).value = '1';
        }
        return false;
    }
    else {

    }
    //        }
    //        else {
    //            handled = false;
    //        }
}

function SleOnTextBoxComplete(results) {
    //        if (!handled) {
    //            handled = true;

    var lOldVal = document.getElementById('ctl00_BasketOverView1_LabelBasketCount').firstChild.data;
    var lNewVal = (parseInt(lOldVal) + parseInt(gTextBoxQuantity));
    document.getElementById('ctl00_BasketOverView1_LabelBasketCount').firstChild.data = lNewVal;

    //        }
}
function SleOnTextBoxTimeout(results) {
    alert("Timout");
}


function SleFavoritesAdd(pItemno, pQuantity, pUserId, pSessionId, pLanguageCode) {

    if (Page_ClientValidate()) {

        var lTextBoxQuantity = document.getElementById(pQuantity).value;

        reqviaproxy = AjaxService1.AddToFavorites(pItemno, lTextBoxQuantity, pUserId, pSessionId, pLanguageCode,
                SleOnCompleteFavorites,
                SleOnTimeoutFavorites);
        return false;
    }
    else {

    }
}

function SleOnCompleteFavorites(results) {
    
}
function SleOnTimeoutFavorites(results) {

}


function SleGotoItemDetail(pItemNo, pPagePath) {

    window.location = pPagePath + "ItemDetail.aspx?ItemNo=" + pItemNo;
}

function SleGotoItemDetailComplete(results) {

}
function SleGotoItemDetailTimeout(results) {
    alert("Timout");
}



function SleUpdateProcuctCount(pUserId, pSessionId) {

    var count = AjaxService1.GetBasketProductCount(pUserId, pSessionId,
                SleUpdateProcuctCountComplete,
                SleUpdateProcuctCountTimeout);


}

function SleUpdateProcuctCountComplete(results) {
    document.getElementById('ctl00_BasketOverView1_LabelBasketProcuctCount').firstChild.data = parseInt(results);

}
function SleUpdateProcuctCountTimeout(results) {
    alert("Timout");
}