//initialize the variables and call the tracker function
var expireDate = (new Date("1/1/2012")).toGMTString();
var timeout = 900;
var interval = 900;	// These are seconds. Increased to 15 minutes on 1/16/2009. SLR
Event.observe(window,'load',tracker,false);

function tracker() {
        doCookie();
        if((getCookie("surveyTime") == timeout) || (getCookie("surveyLater") == "yes" &&
        (getCookie("surveyTime")-timeout) % interval == 0)) {
                popup();
        }
        if(getCookie("surveyTime") <= timeout || (getCookie("surveyLater") == "yes" &&
        (getCookie("surveyTime")-timeout) % interval != 0)) {
                setTimeout("tracker()", 1000);
        }
}

function doCookie() {
        index = (document.cookie) ? document.cookie.indexOf("surveyTime") : -1;
        if(index == -1) {
                document.cookie = "surveyTime=0; expires=" + expireDate + ";path=/";
        } else {
                count = Number(getCookie("surveyTime")) + 1;
                document.cookie = "surveyTime=" + count + "; expires=" + expireDate + ";path=/";
        }
}

function getCookie(name) {
        if(document.cookie) {
                index = document.cookie.indexOf(name);
                if (index != -1) {
                        countbegin = (document.cookie.indexOf("=", index) + 1);
                        countend = document.cookie.indexOf(";", index);
                        if (countend == -1) {
                                countend = document.cookie.length;
                        }
                        count = document.cookie.substring(countbegin, countend);
                        return (count);
                }
        }
        return (0);
}

function popup() {
        new Insertion.Top($$('body')[0],'<div id="surveyContainer"></div>');
        new Ajax.Updater('surveyContainer','/survey.html?v=2', {method: "get"});
}

function yes() {
        document.cookie = "surveyLater=no; expires=Mon, 07-Jan-80 00:00:01 GMT;path=/";
        window.open("http://www.surveymonkey.com/s.aspx?sm=McjtVXd5sA9ecsP1grehUg_3d_3d", "popupWindow2","toolbar,directories,status,menubar,scrollbars,resizable,top="+screen.availTop+",left="+screen.availLeft+",width="+screen.availWidth+",height="+screen.availHeight);
        $('surveyContainer').remove();
}

function no() {
        document.cookie = "surveyLater=yes; expires=Mon, 07-Jan-80 00:00:01 GMT;path=/";
        new Ajax.Updater('surveyContainer','/survey2.html?v=2',{method:'get'});
}

function later() {
        document.cookie = "surveyLater=yes; expires=" + expireDate + ";path=/";
        $('surveyContainer').remove();
        tracker();
}

function yesPartTwo() {
        document.cookie = "surveyLater=yes; expires=Mon, 07-Jan-80 00:00:01 GMT;path=/";
        window.open("http://www.surveymonkey.com/s.asp?u=8500634095", "popupWindow4","toolbar,directories,status,menubar,scrollbars,resizable,top="+screen.availTop+",left="+screen.availLeft+",width="+screen.availWidth+",height="+screen.availHeight);
        $('surveyContainer').remove();
}

function noPartTwo() {
        document.cookie = "surveyLater=yes; expires=Mon, 07-Jan-80 00:00:01 GMT;path=/";
        $('surveyContainer').remove();
}