﻿var showingGoldClubPromo = false;
function setupMuseumDonation() {
	setTimeout('showMuseumPromo()', 1500);
}
function showMuseumPromo() {
	if(getCookie('mcmuseumdonation') == "" && !showingGoldClubPromo) {
		$(".rightcartbox #museumPromo").addClass("museumPromo").append($("<div>")
			.append($("<img/>").attr("src" , "/Content/images/museum_donate_back.jpg" ))
			.append($("<p>The National Motorcycle Museum is supported by passionate riders like yourself. Would you like to donate $1 to the Museum?</p>"))
			.append($("<button>Yes</button>").attr("id","museumPromoYes").css("margin","2px 8px")
				.click(function() {
					setCookie('mcmuseumdonation','yes', 1);
					window.location = '/cart/additem/?productSku=museum';
				}))
			.append($("<button>No</button>").attr("id","museumPromoNo").css("margin","2px 8px")
				.click(function() {
					setCookie('mcmuseumdonation','no',1);
					$(this).parent().parent().hide("normal");
				})))
			.append($("<a>More Information</a>").attr("href","http://www.nationalmcmuseum.org/menu.html").attr("target","new"))
			.show("normal");
		return true;
	}
}
function setCookie(c_name,value,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
}
function getCookie(c_name) {
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start != -1) { 
			c_start = c_start + c_name.length + 1; 
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end == -1) c_end = document.cookie.length;
			return unescape(document.cookie.substring(c_start, c_end));
		} 
	}
	return "";
}
function promoteGoldClubMembership(cartData) {
    if(getCookie('goldcluboffer') == "") {
        showGoldClubPromo(cartData);
	}
}
function showGoldClubPromo(cartData) {
    var $div = $("<div />").attr("id", "gold-club-offer");
    $("body").append($div);

    $.ajax({ type: 'GET', url: '/Content/html/promo/GoldClubOffer.html', data: cartData, cache: false, success: function(response) {
        showingGoldClubPromo = true;

        $div.html(response);
        $div.dialog({
            bgiframe: true, resizable: false, height: 390, modal: true, width: 580, title: 'Special Savings Alert: Gold Club Membership', closeOnEscape: true,
            beforeclose: function(event, ui) {
                ClickedGoldClubOffer(false);
            },
            overlay: {
                backgroundColor: '#000',
                opacity: 0.75
            },
            buttons: {
                'No Thanks': function() { $(this).dialog('close'); ClickedGoldClubOffer(false); }
            }
        }).css("padding-top", "0");

        $div.find("#gold-club-offer-add-to-cart").click(function() { ClickedGoldClubOffer(true); });

        var goldClubFreeShipping = cartData.GoldClub.FreeShipping;

        var $netCost = $div.find("#gold-club-offer-net-cost");
        $netCost.html(jQuery.format($netCost.html(), cartData.GoldClubProduct.RegularPrice, cartData.GoldClubProduct.NetPrice));

        var $savings = $div.find("#gold-club-offer-savings");
        $savings.html(jQuery.format($savings.html(), cartData.GoldClubProduct.Savings));

        var $goldclub = $div.find("#gold-club-offer-gold-club");
        $goldclub.html(jQuery.format($goldclub.html(), cartData.GoldClub.Total, goldClubFreeShipping));

        var $standard = $div.find("#gold-club-offer-standard");
        $standard.html(jQuery.format($standard.html(), cartData.Standard.FreeShipping, cartData.Standard.Total));

        $(".gold-club-offer-free-shipping").each(function(i) {
            $(this).html(jQuery.format($(this).html(), goldClubFreeShipping));
        });
    }
    });
}
function ClickedGoldClubOffer(accepted) {
    setCookie('goldcluboffer', accepted ? 'yes' : 'no', null);
}
