﻿function survey()
{
    if ($("#surveyinvite").length > 0)
    {
        var ticks = new Date().getTime();
        $.get('/surveylauncher/check.aspx?time' + ticks + '&path=' + window.location.pathname, function(data)
        {
            $("#surveyinvite").html(data);
            var width = $(window).width();
            width = (width / 2) - 150;
            $(".surveyinvite").animate({ left: width + "px" }, 2000);
        });
    }
}

function survey_yes(path) {
    $.get('/surveylauncher/check.aspx?response=yes&path=' + path, function(data)
    {
        if (navigator && (navigator.userAgent.toLowerCase()).indexOf("chrome") > -1)
        {
            var div = "'#surveyinvite'";
            $("#surveyinvite2").html('<a href="/surveylauncher/redirect.aspx?url=' + data + '" target="_blank" onclick="$('+div+').toggle();">Click here to take survey</a>');
        }
        else
        {
            var newwin = window.open("", "Survey", 'width=800,height=600,scrollbars=yes ');

            if ((newwin == undefined) || (newwin.outerWidth == 0)) 
            {
                var div = "'#surveyinvite'";
                $("#surveyinvite2").html('<a href="/surveylauncher/redirect.aspx?url=' + data + '" target="_blank" onclick="$(' + div + ').toggle();">Click here to take survey</a>');
            }
            else
            {
                // newwin.opener = null;
                newwin.location = '/surveylauncher/redirect.aspx?url=' + data;
                newwin.width = 800;
                newwin.height = 600;
                $(".surveyinvite").animate({ left: "-700px" }, 2000);
            }
        }

    });
    return false;
}
function survey_no(path)
{
    $.get('/surveylauncher/check.aspx?response=no&path=' + path, function (data) {
        $(".surveyinvite").animate({ left: "-500px" }, 2000);
    });
    return false;
}
function survey_maybe(path)
{
    $.get('/surveylauncher/check.aspx?response=maybe&path=' + path, function (data) {
        $(".surveyinvite").animate({ left: "-500px" }, 2000);
    });
    return false;
}

$(function () { survey(); });
