/* obsluga porownan */

function compare_click(element, pID) {
	if($(element).is('.checked')) {
		ajax_compare(element, 'discard', pID);
	}
	else {
		ajax_compare(element, 'add', pID);
	}
}

function compare_toggle(element) {
	if($(element).is('.checked')) {
		$(element).removeClass('checked');
	}
	else {
		$(element).addClass('checked');
	}
}

function ajax_compare(element, action, pID) {
    advAJAX.get({
        url : "ajax_compare.php",
        timeout : 5000,
        retry: 2,
        retryDelay: 2000,
        parameters : { "action" : action,
                       "pID" : pID},
        onLoading: function(obj) { $(element).html('<img src="images/loading.gif" style="width: 15px; height: 15px; margin-left: 12px;" />'); },
        onSuccess : function(obj) { 
        	switch(obj.responseText.substring(0,3)) {
        		case 'ERR':
/*        			$(element).html(obj.responseText);*/
        			$(element).html('&nbsp;');
        			break;
        		case 'OK:':
        			$(element).html('&nbsp;');
        			compare_toggle(element);
        			break;
        	}
        },
        onError : function(obj) { alert("Error: " + obj.status); $(element).html('&nbsp;');}
        
    });
}

/* obsluga schowka */

function wishlist_click(element, pID) {
	if($(element).is('.checked')) {
		ajax_wishlist(element, 'remove_wishlist', pID);
	}
	else {
		ajax_wishlist(element, 'add_wishlist', pID);
	}
}

function wishlist_toggle(element) {
	if($(element).is('.checked')) {
		$(element).removeClass('checked');
	}
	else {
		$(element).addClass('checked');
	}
}

function ajax_wishlist(element, action, pID) {
    advAJAX.get({
        url : "ajax_wishlist.php",
        timeout : 5000,
        retry: 2,
        retryDelay: 2000,
        parameters : { "action" : action,
                       "products_id" : pID},
        onLoading: function(obj) { $(element).html('<img src="images/loading.gif" style="width: 15px; height: 15px; margin-left: 12px;" />'); },
        onSuccess : function(obj) { 
        	switch(obj.responseText.substring(0,3)) {
        		case 'ERR':
/*        			$(element).html(obj.responseText);*/
        			$(element).html('&nbsp;');
        			break;
        		case 'OK:':
        			$(element).html('&nbsp;');
        			wishlist_toggle(element);
        			break;
        	}
        },
        onError : function(obj) { alert("Error: " + obj.status); $(element).html('&nbsp;');}
        
    });
}
