


function init() {
    
    var t;

    var c =15;
    
    // Define various event handlers for Dialog
    var handleYes = function(e) {
        surveydialog.hide();
        YAHOO.util.Cookie.set("survey", true);  
       // window.location = 'https://www.survey.ed.ac.uk/_gogeo/';   
        window.open('https://www.survey.ed.ac.uk/_gogeo/');
        YAHOO.util.Dom.setStyle('surveydialog', 'display', 'none'); 
    };
    
    

    var handleNo = function(e) {
        surveydialog.hide();
        YAHOO.util.Dom.setStyle('surveydialog', 'display', 'none'); 
        
        var oneDay =    1000 * 60 * 60 * 24;
        var threeDays = 3 * oneDay;
        var today = new Date();
        var expires_date = new Date( today.getTime() + threeDays );
        /*
        if the expires variable is set, make the correct
        expires time, the current script below will set
        it for x number of days, to make it for hours,
        delete * 24, for minutes, delete * 60 * 24
        */
        
        YAHOO.util.Cookie.set("survey-no-thanks", "not-completed", {
            expires: expires_date
        });

    };


    
    function timedCount(){
        
        document.getElementById('counter').innerHTML = c;
        
        c = c-1;
        t = setTimeout(function (){timedCount();},1000);
        if(c ==0){
            stopCount();
            handleNo();
        }
    }


    function stopCount()
    {
        clearTimeout(t);

    }
    
    

  


    // Instantiate the Dialog
    var surveydialog = new YAHOO.widget.SimpleDialog("surveydialog", {
        width :"380px",
        height:"280px",
        fixedcenter :true,
        visible :false,
        draggable :false,
        close :false,
        modal :true,
        zIndex :10,
        underlay :"shadow",
        constraintoviewport :true,
        buttons : [ {
            text :"Take Survey",
            handler :handleYes,
            isDefault :true
        }]
    });

    // check for the survey cookie and render accordingly
    var tookSurvey = YAHOO.util.Cookie.get("survey");
    var surveyNoThanks = YAHOO.util.Cookie.get("survey-no-thanks");
    if ( tookSurvey == null && surveyNoThanks == null  ){
        timedCount();
        YAHOO.util.Dom.setStyle('surveydialog', 'display', 'block'); 
        surveydialog.render();
        surveydialog.show();
    };
    
    

}

YAHOO.util.Event.addListener(window, "load", init);
