﻿var linkClicked = false;
function GetKeycodePrices() {
    $('.keycodePriceData').hide();
    $('.keycodePrice').click(function() {
        var current = this;
        var baseNumber = $(current).attr('id');
        $(current).siblings('.keycodePriceDataWrapper').children('.keycodePriceData').toggle();
        if ($(current).siblings('.keycodePriceDataWrapper').children('.keycodePriceData').text() == '') {
            $.getJSON('/KeycodeAjax.ashx', { func: 'get_keycode_pricing', baseNumber: baseNumber },
	            function(result) {
	                $(current).siblings('.keycodePriceDataWrapper').children('.keycodePriceData').html(DisplayKeycodePrice(result));
	            }
	        );
        }
        linkClicked = true;
        pageTracker._trackPageview("/KeycodeAjax.ashx");
        
    });
}
function DisplayKeycodePrice(data) {
    var result = '<img class="closeKeycodePopup" src="http://s.stpost.com/g3/assets/images/hover-close.gif" onclick="HidePopup()"/>';
    for (var i in data.promos) {
        result += '<div class="keycodePriceMessage">' + data.promos[i].id + ':</div><div class="keycodePriceDisplay"> Your price: $' + data.promos[i].price.toFixed(2) + '</div>';
    }
    return result;
}
function HidePopup() {
    $('.keycodePriceData').hide();
}