﻿var popup_area_id = "popup_area";
var overlay_id = "master_overlay";
var iframe_id = "iframe_hide";
var popup_id = "master_popup";

var popup_parent_id = "";

// composite ids, for jQuery calls
var PopupAreaID = "#" + popup_area_id;
var OverlayID = "#" + overlay_id;
var IframeID = "#" + iframe_id;
var PopupID = "#" + popup_id;

var ie6 = (jQuery.browser.msie && jQuery.browser.version < 7);

//appends div and iframe elements necessary to show popups on page to DOM
function AppendPopupElements() {
    $('body').append('<div id="' + popup_area_id + '"></div>');

    $(PopupAreaID).append('<div id="' + overlay_id + '"></div>');

    //append iframe to hide select elements in IE 6
    if (jQuery.browser.msie && jQuery.browser.version < 7) {
        $(PopupAreaID).append('<iframe id="' + iframe_id + '" frameborder="0" scrolling="no" src="javascript;"></iframe>');
    }

    $(PopupAreaID).append('<div id="' + popup_id + '"></div>');
}

function ShowPopup(id) {
    // bind keypress event to handle ESC key    
    document.onkeydown = function(e) {
        var keycode;

        if (e == null) // ie
        {
            keycode = event.keyCode;
        }
        else // mozilla
        {
            keycode = e.which;
        }

        if (keycode == 27) {
            ClosePopup();
        }
    };

    var oWidth;
    var oHeight;

    oWidth = $(window).width();

    if ($(window).height() >= $(document).height()) {
        oHeight = $(window).height();
    }
    else {
        oHeight = $(document).height();
    }

    $(OverlayID).css('width', oWidth);
    $(OverlayID).css('height', oHeight);

    // Similac specific, due to body styling
    var bodyStyleOffset = ($(window).width() - 1100) / 2;

    // IE 6 specific code
    if (ie6) {
        $(IframeID).css('width', oWidth);
        $(IframeID).css('height', oHeight);

        $(OverlayID).css('position', 'absolute');
        $(PopupID).css('position', 'absolute');
        // $(OverlayID).css('left', '-' + bodyStyleOffset);
//        $(OverlayID).css('left', Math.abs(bodyStyleOffset));
    }

    // show elements, and set master area invisible, to calculate dimensions

    $(PopupAreaID).css('visibility', 'hidden');

    $(PopupAreaID).css('display', 'block');
    $(OverlayID).css('display', 'block');

    if (ie6) {
        $(IframeID).css('display', 'block');
    }

    $(PopupID).css('display', 'block');

    //prepare popup contents

    popup_parent_id = '#' + $('#' + id).parent().attr('id');

    $(PopupID).append($('#' + id));

    var h = $(PopupID).height();
    var w = $(PopupID).width();

    $(PopupID).css('height', h + 'px');
    $(PopupID).css('width', w + 'px');

    var l = ($(window).width() / 2) - ($(PopupID).width() / 2) - bodyStyleOffset;
    var t = ($(window).height() / 2) - ($(PopupID).height() / 2);

    var st = $(window).scrollTop();

    t = t + st;

    $(PopupID).css('left', l + 'px');
    $(PopupID).css('top', t + 'px');

    $(PopupAreaID).css('visibility', 'visible');

    //$('div').ifixpng();  
}

function ClosePopup() {
    // hide elements
    $(PopupAreaID).css('display', 'none');
    $(OverlayID).css('display', 'none');

    if (ie6) {
        $(IframeID).css('display', 'none');
    }

    $(PopupID).css('display', 'none');

    $(popup_parent_id).append($(PopupID + "> div"));

}

function ShowProductPopup(contentID) {
    //$("a#leaveSite").attr("href", link);
    if (contentID == '1') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/Similac-sling-pack.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Similac Sling Pack</span>' +
                    '<p>' +
                        'Sure, it’s sleek and stylish, but that’s not all.' + ' Our sling is packed with valuable offers*, ' +
                        'special treats for baby and for you,' + ' and a FREE† sample of Similac Advance EarlyShield<sup>™</sup>.<br /> ' +
                        '<span class="foot_note"> *Offers may vary. <br /> † Available at participating hospitals</span>' +

                        '<a href=\"/free-diaper-bag\">Find out more ></a></p><br />');
        $('#popup_text').attr("class","Float_Left margin_top_15 margin_right_20 field_122 padding_bottom_20 margin_left_5");
    }
    else if (contentID == '2') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-coupons-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Coupons for Similac Formulas</span>' +
                    '<p>' +
                        'Check your mailbox for these special deliveries from StrongMoms.</p><br />');
    }
    else if (contentID == '3') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-free-sample-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Free Samples</span>' +
                    '<p>' +
                        'They’re great to have on hand for those middle-of-the-night surprises — or anytime.</p><br />');
    }
    else if (contentID == '4') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-pregnancy-journal-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Weekly Pregnancy Journal</span>' +
                    '<p>' +
                        'Sleek and compact, it’s easy to carry with you to record everything you’ll ' +
                        'want to track — from your growing belly to baby’s first kick.</p><br />');
    }
    else if (contentID == '5') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-travel-bag-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Similac Travel Bag</span>' +
                    '<p>' +
                        'Moisturizer? Check. Lip balm? Check. Make sure everything’s right where you ' +
                        'want it for the big day. Pack your Similac Travel Bag and head to the hospital ' +
                        'with confidence.</p><br />');
    }
    else if (contentID == '6') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-info-monitor-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Info You Can Use</span>' +
                    '<p>' +
                        'Look for them in your mailbox and your inbox. They’ll be there right when you need them.</p><br />');
    }
    else if (contentID == '7') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-pregnancy-guide-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Weekly Pregnancy Guide</span>' +
                    '<p>' +
                        'Nine months and lots to learn. From conception to delivery, our guides help keep you informed.</p><br />');
    }
    else if (contentID == '8') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-community-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Community</span>' +
                    '<p>' +
                        'No time like now to connect with moms like you! See what moms are talking ' +
                        'about, from stretch marks to slings. And join in the conversation!</p><br />');
    }
    else if (contentID == '9') {
        $('#popup_image').html('<img src="/SMS/images/benefits-of-membership/bom-feeding-concerns-popup.jpg" alt="" />');
        $('#popup_text').html('<span class="bold">Feeding Concerns</span>' +
                    '<p>' +
                        'Is your baby experiencing fussiness at feeding time? Help her feel better. ' +
                        'Troubleshoot feeding issues with our Similac Solutions&trade; tool.</p><br />');
    }

    ShowPopup('bom_product_popup');
}