﻿// Script for R/GA Site Survey

// Check and store what pageview this is
var expDays = 1000; // number of days the cookie should last 

function GetCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}
function SetCookie(name, value) {
    var argv = SetCookie.arguments;
    var argc = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = GetCookie(name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var exp = new Date();
exp.setTime(exp.getTime() + (expDays * 24 * 60 * 60 * 1000));
function amt() {
    var count = GetCookie('count')
    if (count == null) {
        SetCookie('count', '1')
        return 1
    }
    else {
        var newcount = parseInt(count) + 1;
        DeleteCookie('count')
        SetCookie('count', newcount, exp)
        return count
    }
}
function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function checkCount() {
    if (1 == 0) {
        var count = GetCookie('count');
        if (count == null) {
            count = 1;
            SetCookie('count', count, exp);

            //window.open(page, "", windowprops);
            // alert("Visit number: " + count);
        }
        else {
            count++;
            SetCookie('count', count, exp);
            if (count >= 2 && (GetCookie('suppresssurvey') != "true")) {
                overdiv = document.createElement("div");
                overdiv.setAttribute("id", "overdiv");
                modaldiv = document.createElement("div");
                modaldiv.setAttribute("id", "modal");
                dialogcontent = document.createElement("div");
                dialogcontent.setAttribute("id", "dialog");
                dialogcontent.innerHTML = "<a href='javascript:closeSurvey();' class='closebutton'>&nbsp;</a><h3>How are we doing?</h3><p>Come here often? Finding everything you’re looking for? Have an idea for how our site could be better?<br/><br/>We want to know. Please take our short survey when you are finished with your visit at BAM.org.<br/><br/>Thanks very much.</p><a href='javascript:openSurvey();'><img src='../Img/button_takesurvey.png' border=0/></a><a href='javascript:closeSurvey();' class='close'>No, Thanks</a>"


                document.body.appendChild(overdiv);
                document.body.appendChild(modaldiv);
                modaldiv.appendChild(dialogcontent);

            }
        }
    }
}
function openSurvey() {
    window.open('https://www.surveymonkey.com/s/25YSLMQ');
    window.focus();
    closePopup();
    pageTracker._trackEvent('Survey', 'Popup', 'Accept');

}
function closeSurvey() {
    closePopup();
    pageTracker._trackEvent('Survey', 'Popup', 'Decline');
}
function closePopup() {
    if (navigator.appName == "Microsoft Internet Explorer") {
        document.getElementById('overdiv').outerHTML = "";
        document.getElementById('modal').outerHTML = "";
    }
    else {
        document.body.removeChild(document.body.getElementById('overdiv'));
        document.body.removeChild(document.body.getElementById('modal'));
    }
    SetCookie('suppresssurvey', 'true', exp);
}

// End -->
// DeleteCookie('count');
// checkCount();


