﻿// This file displays a div overlay to a user prompting them to take a survey

// REQUIREMENTS:
// If a user clicks yes, they don't see the popup again
// if a user clicks never, they don't see the popup again
// if a user clicks later, they see the popup on their first visit after 24 hours have elapsed.


// WHEN TO DISPLAY THE POPUP:
// if a user just came from the homepage, display with this URL: http://www.zoomerang.com/Survey/WEB22BDPW9Q4NK
// if a user just came from one of the content pages (cocoa science, muscle recovery, products), display with this URL: http://www.zoomerang.com/Survey/WEB22BDPWSQ4YX

// define the callSurvey function

function callSurvey(referringPage) {

    if ($.cookie("survey_hide") == null) {
        var ContentPageLink = "http://www.zoomerang.com/Survey/WEB22BDPW9Q4NK";
        var homePageLink = "http://www.zoomerang.com/Survey/WEB22BDPWSQ4YX";
        var contentPage = false;
        var homepage = false;
        switch (referringPage) {
            case "Default.aspx":
                homepage = true;
                break;
            case "cocoa-science/":
            case "muscle-recovery/":
            case "products/":
                contentPage = true;
                break;
            default:
                //do nothing
                break;
        }

        var link;
        if (contentPage || homepage) {

            if (contentPage)
                link = ContentPageLink;
            else
                link = homePageLink;


            $(".now a").attr("href", link);
            $("#survey").overlay({
                left: 'center',
                top: 'center',
                load: true,
                mask: {
                    color: '#000000',
                    opacity: 0.7
                },
                closeOnClick: false
            });

        }
    }


}

function surveyNow() {
    surveyNever(); // no sense rewriting the method here....
}

function surveyLater() {
    $.cookie("survey_hide", 'yes', { expires: 1, path: "/" });
    closeSurvey();
}
function surveyNever() {
    $.cookie("survey_hide", 'yes', { expires: 1000, path: "/" });
    closeSurvey();
}

function closeSurvey() {
    var api = $("#survey").data("overlay");
    api.close();
}
