﻿window.onunload = showSurvey;

var deploySurvey = true;
var surveyPeriod = 60;
var randomNum = Math.floor(Math.random() * surveyPeriod) + 1;
var csurvey = document.cookie;

function showSurvey() {
    if (deploySurvey == true) {
        if (BWWgetCookie("gags_survey") != "viewed" && randomNum == surveyPeriod) {
            var expiry = new Date();
            expiry.setFullYear(2009, 8, 11);
            BWWsetCookie("gags_survey", "viewed", expiry);
            var surveyWin = window.open("http://www.surveymonkey.com/s.aspx?sm=yPBOGZgcyg6SzHkQTELmAA_3d_3d", "surveyWin", "width=977,scrollbars,resizeable");
        }
    }
}

function surveyLater() {
    var expiry = new Date();
    expiry.setMinutes(expiry.getMinutes() + 10);
    BWWsetCookie("gags_survey", "viewed", expiry);
}

function BWWgetCookie(name) {
    var scookie = document.cookie;
    var index = scookie.indexOf(name + "=");

    if (index == -1) {
        return null;
    }

    index = scookie.indexOf("=", index) + 1;
    var endstr = scookie.indexOf(";", index);

    if (endstr == -1) {
        endstr = scookie.length;
    }

    return unescape(scookie.substring(index, endstr));
}

function BWWsetCookie(name, value, expiry) {
    if (value != null && value != "")
        document.cookie = name + "=" + escape(value) + "; expires=" + expiry.toGMTString() + "; path=/";
    csurvey = document.cookie;
}