var addFavoritesUrl = "/app/AddRemoveFavorites";

function addFavorites(type, urlFavorites) {
	$.ajax({
		type: "POST",
		url: urlFavorites,
		error: function () {
			alert("We're sorry, an error was encountered while adding your favorite "+type+".");
		},
		success: function(msg) {
			if (msg.indexOf("SUCCESS") >= 0) {
				showMessage("Selected "+type+" successfully added to Favorites.");
			} else if(msg.indexOf("FAILURE") >=0){
				index = msg.indexOf(":");
				text = (msg).substr(index+1);
				alert(text);
			}else{
				showMessage("Selected "+type+" is already a favorite.");
			}
		}
	});
}

function addStore(id) {
	showMessage("Adding store to Favorites...");
	addFavorites("store", addFavoritesUrl+"?si="+id+"&req=add"+"&rand="+Math.random());
}

function addBrand(id) {
	showMessage("Adding brand to Favorites...");
	addFavorites("brand", addFavoritesUrl+"?bi="+id+"&req=add"+"&rand="+Math.random());
}
