﻿$(document).ready(function() {
    //InvokeSurvey();
});

//survey window which will prompt if user decides to take survey
var surveyWindow = null;

function InvokeSurvey() {
    var promptUser = readCookie('surveyPrompted');
    if (promptUser != "true") {
        $("div.survey-prompt").dialog({
            resizable: false,
            height: 335,
            width: 400,
            modal: true,
            bgiframe: true
        });
        //set cookie so user won't get prompted again for another month
        var now = new Date();
        now.setUTCMonth(now.getUTCMonth() + 1);
        document.cookie = 'surveyPrompted=true; expires=' + now.toUTCString() + '; path=/';
    }

}
function readCookie(name) {
    var cookieName = name + "=";
    var cookieArray = document.cookie.split(';');
    for (var i = 0; i < cookieArray.length; i++) {
        var cookie = cookieArray[i];
        while (cookie.charAt(0) == ' ') cookie = cookie.substring(1, cookie.length);
        if (cookie.indexOf(cookieName) == 0) return cookie.substring(cookieName.length, cookie.length);
    }
    return null;
}
function promptSurveyWindow() {

    var surveyURL = "/survey-window.aspx";

    //specify survey window features
    //set 1 to enable a particular feature, 0 to disable
    var windowFeatures = "width=800,height=510,scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0";

    surveyWindow = window.open(surveyURL, "", windowFeatures);
    surveyWindow.blur();
    window.focus();
    
    $("div.survey-prompt").dialog("close");
}
function closeSurveyPrompt() {
    $("div.survey-prompt").dialog("close");
}

