window.addEvent("domready", initPopUpSurvey);

function initPopUpSurvey() {
    //Cookie.dispose('surveyPopped');
    var surveyPopped = Cookie.read('surveyPopped');
    var surveyPopUpRate = 0.01; // only do the pop up 1% of the time.. (1 in every 100 visitor)
    var rand = Math.random();
    if (rand <= surveyPopUpRate && surveyPopped == null) {
        popUpSurvey();
    }
}

function popUpSurvey() {
    var surveyPopped = Cookie.read('surveyPopped');
    if (surveyPopped == null) {
        var popup = window.open(site_root + 'Survey', 'm10survey', 'width=500,height=657,resizable=no,scrollbars=no,tolbar=no,location=no,directories=no,menubar=no,copyhistory=no');
        if (!popup) {
            // the visitor has pop-up blocker active - so put on onclick on the mainwrapper so when the user clicks on anything on the page, it'll pop up
            $('mainwrapper').addEvent('click', popUpSurvey);
        } else {
            // survey has been popped up - prevent it from popping up again for this user
            surveyPopped = Cookie.write('surveyPopped', true);
        }
    }
}
