﻿// JScript File

//Configuration
var cartConfig = 
{
    basketContainerId           :  'fullShopingBasketPanel',
    sidbarBasketContainerId     :  'shopingBasketPanel',
    ajaxUpdate                  : null
}
//--

function addToCart(productId,number,resultType)
{
    /*document.location = '/process/Ajax/cart.asp?action=addtocart&result='+ resultType +'&product='+ productId + (number ? '&number='+number : '');
    return;*/
    
    jQuery.ajax({
        type:       'GET',
        url:        '/process/Ajax/cart.asp?action=addtocart&result='+ resultType +'&product='+ productId + (number ? '&number='+number : '') ,  
        dataType:   'html',
        error:      errorLoading,
        success:     loadHtml
     }); 
}

function updateCart(rowId,number,resultType)
{
    /*document.location = '/process/Ajax/cart.asp?action=updatecart&result='+ resultType +'&row='+ rowId + (number ? '&number='+number : '');
    return;*/
    
    jQuery.ajax({
        type:       'GET',
        url:        '/process/Ajax/cart.asp?action=updatecart&result='+ resultType +'&row='+ rowId + '&number='+number,  
        dataType:   'html',
        error:      errorLoading,
        success:     loadHtml
     }); 
}

function removeFromCart(rowId,resultType)
{
   jQuery.ajax({
        type:       'GET',
        url:        '/process/Ajax/cart.asp?action=removefromcart&result='+ resultType +'&row='+ rowId,  
        dataType:   'html',
        error:      errorLoading,
        success:     loadHtml
        
     });  
}

function copyFromHistory(orderId,resultType)
{
   jQuery.ajax({
        type:       'GET',
        url:        '/process/Ajax/cart.asp?action=copyfromhistory&result='+ resultType + '&order='+ orderId,  
        dataType:   'html',
        error:      errorLoading,
        success:     loadHtml
     });  
}

function refreshCart(resultType)
{
   jQuery.ajax({
        type:       'GET',
        url:        '/process/Ajax/cart.asp?result='+ resultType,  
        dataType:   'html',
        error:      errorLoading,
        success:     loadHtml
     });   
}

//panel Update functie
function loadHtml(data, textStatus)
{    
   var htmlObj = $(data);
   
   var basket = $('#basket', htmlObj);
   var sideBasket = $('#basket_sidebar', htmlObj); 
   
   if (basket.length == 1)      $('#'+ cartConfig.basketContainerId).html(basket.html());
   if (sideBasket.length == 1)  $('#'+ cartConfig.sidbarBasketContainerId).html(sideBasket.html());
   
   if (cartConfig.ajaxUpdate != null)
        cartConfig.ajaxUpdate()
}

function errorLoading(request,settings)
{
    alert(request.responseText); 
}









