function callbacks(xhr, id)
{
	if (xhr.substring(0,5) == "error"){
		var reponse = xhr.replace('error', '');
		showError(reponse);
	}else{
		if (id == 1 || id == 6){// add
			addCB(xhr, id);
		}else{
		   nohide = false;
		   if (id == 3){// remove
			   updateCart(xhr);
		   }else if (id == 4){// cancel last delete & navigation
			   updateCart(xhr);
		   }else if (id == 5){// add to wishlist
                $j.unblockUI({
                    onUnblock: function(){
                       hidePopUpLoading();
                       var reponse = xhr.split('login-form');
                       if (reponse.length > 1){// customer not logged in
                           showLoginPopUp();
                       }else{// customer logged in
                           hideAll();
                           refreshWishList(xhr);
                       }
                    }
                });
		   }else if (id == 7){// remove from wishlist
                $j.unblockUI({
                    onUnblock: function(){
                       hidePopUpLoading();
                       hideAll();
                       refreshWishList(xhr);
                    }
                });
		   }else if (id == 8){// Compare
                $j.unblockUI({
                    onUnblock: function(){
                       hidePopUpLoading();
                       hideAll();
                       refreshCompare(xhr);
                    }
                });
		   }else if (id == 9){// Compare Pop Up
                $j.unblockUI({
                    onUnblock: function(){
                       refreshComparePopUp(xhr);
                    }
                });
		   }
	   }
	   $j(".imagezoom").hide();
	}
}

function addCB(xhr, id){
 		hidePopUpLoading();
 		
 		if (xhr.substring(0,7) == "options"){
 			optionsPopUp(xhr, id, 'options');
 		}
 		else if (xhr.substring(0,5) == "super"){
            $j.unblockUI({
                onUnblock: function(){
                    showAllNormal();
                    showPopUpRedirecting();
                    var reponse = xhr.replace('super', '');
                    window.location = reponse;
                }
            });
 		}
 		else if (xhr.substring(0,12) == "configurable"){
 			optionsPopUp(xhr, id, 'configurable');
 		}
 		else if (xhr.substring(0,7) == "grouped"){
            optionsPopUp(xhr, id, 'grouped');
 		}
 		else if (xhr.substring(0,6) == "bundle"){
 			optionsPopUp(xhr, id, 'bundle');
 		}
 		else{
            $j.unblockUI({
                onUnblock: function(){
                    showPopUp();

                    if(id == 6 || $j("#callbackId").attr('value') == 6){

                        split = xhr.split('##ajax_splitting##');
                        xhr = split[1];
                        reponse = split[0].replace('<div class="block block-wishlist">', '');

                        var sidebar = $j("#wishlist_sidebar");
                        sidebar.html(reponse);
                        wishlist_opacity_more();
                        refreshWishlistLinks();
                    }

                    updateCart(xhr);
                    truncateOptions();
                }
            });
        }
}

function updateCart(xhr){
	reponse = xhr.replace('<div id="cart_sidebar" class="block block-cart">', '');

	var sidebar = $j("#cart_sidebar");
	sidebar.html(reponse);

	cart_opacity_more();
}

function optionsPopUp(xhr, id, type){
    $j.unblockUI({
        onUnblock: function(){
            showAllNormal();
            var reponse = xhr.replace(type, '<input type="hidden" id="callbackId" value="'+id+'" />');
            reponse = reponse.replace('<div class="product-info-box"></div>', '');
            $j("#ajaxaddtocart_popup_options_in").html(reponse);
            showPopUpOptions();
            $j("#ajaxaddtocart").css("max-height", height());
            $j("#ajaxaddtocart").css("top", center("ajaxaddtocart_popup_options"));
        }
    });
}

