function favorite(moduleId, moduleTypeId, eProfileId)
{
	var labelBlockID="#addToWalletLabel-" + moduleId;
	var labelBlock=jQuery(labelBlockID);
	if (labelBlock.text() == "Add To Wallet") {
		makeFavorite="1";
	} else {
		makeFavorite="0";

	}
    url = "/api";
    queryString  = "method=Favorite.SetFavorite";
    queryString += "&callback=favoriteMade";
    queryString += "&moduleId=" + moduleId;
    queryString += "&moduleTypeId=" + moduleTypeId;
    queryString += "&e_id=" + eProfileId;
    queryString += "&add=" + makeFavorite;
    loadConnectokJSON(url,queryString,'script');
}
function favoriteMade(data)
{
  //dealBlock = jQuery('#widgetDisplay'+data->moduleId);
  	var dealBlockID="#widgetDisplay" + data.moduleId;
  	var labelBlockID="#addToWalletLabel-" + data.moduleId;

	var dealBlock=jQuery(dealBlockID);
	var labelBlock=jQuery(labelBlockID);

	var inWalletText = " Offers";
	if (data.count == 1) inWalletText = " Offer";
    jQuery("#offersInWallet").text(data.count+inWalletText);
    jQuery(".offersInWalletCount").text(data.count+inWalletText);

	dealBlock.toggleClass("inWallet");
	if (labelBlock.text() == "Add To Wallet") {
		labelBlock.text("In Wallet");
	} else {
		labelBlock.text("Add To Wallet");
	}

    //this bit of code handles the print offers link. It adds or removes a class as needed to handle when it prints and when it pops up a message instead.
    //the class is used by the nothingToPrint function a bit farthur down the page.
	var printLinkID="#printOffersLink";
	var printLinkClass="nothingToPrint";
	if (jQuery(printLinkID).hasClass(printLinkClass)&&(data.count>0)){
	    jQuery(printLinkID).removeClass(printLinkClass);
	} else if (!jQuery(printLinkID).hasClass(printLinkClass)&&(data.count==0)){
	    jQuery(printLinkID).addClass(printLinkClass);

	}


}
jQuery(document).ready(function(){
    jQuery(".dealsSelectAll").click(function (){

        var addToWalletInput = "input.toolbarAddToWallet-checklist";
        var selectAllCheckedStatus = this.checked;
        var oldCheckedStatusx;

            jQuery(addToWalletInput).each(function() {
                oldCheckedStatus = this.checked;
                this.checked = selectAllCheckedStatus;
                if (oldCheckedStatus != selectAllCheckedStatus)
                    this.onchange();
            });

            jQuery(".dealsSelectAll").each(function() {
                this.checked = selectAllCheckedStatus;
            });

    });


//    jQuery(".nothingToPrint").click(function () {
//        if (jQuery(this).hasClass("nothingToPrint")){
//            alert("There is nothing to print. Please add one or more deals to your wallet, then try again.");
//            return false;
//        }
//    });

});


