﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="BaseUI.js" />


var SurveyUI =
{
    Background: null,
    WindowLoad: function() {
        SurveyUI.Container = $get('svcontainer')
        SurveyUI.Background = document.createElement('div')
        BaseUI.SetClass(SurveyUI.Background, 'overlay')
        document.body.appendChild(SurveyUI.Background)

        if ((Sys.Browser.agent == Sys.Browser.InternetExplorer) && (Sys.Browser.version == 6)) {
            SurveyUI.Background.style.position = 'absolute'
            SurveyUI.Background.style.height = '100%'
            SurveyUI.Background.style.width = '100%'

            $addHandlers(window, { "resize": BaseUI.WindowResize,
                "scroll": BaseUI.WindowResize
            }, this)

            BaseUI.WindowResize()
        }
//        var show = SurveyUI.GetCookie("showSurvey")
//        var doNotShow = SurveyUI.GetCookie("surveyTaken")
//        // alert(doNotShow)
//        if (SurveyUI.GetCookie("surveyTaken") == null) {
//            if (SurveyUI.GetCookie("showSurvey") != null) {
//                if (show.toLowerCase() == "true") {
//                    SurveyUI.ShowSurvey()
//                }
//            }
//        }

    },

    GetCookie: function(cookie_name) {
        var results = document.cookie.match('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
        // alert(results)         
        if (results)
            return (unescape(results[2]));
        else
            return null;
    },

    ShowSurvey: function() {

        BaseUI.Expand(SurveyUI.Background)
        BaseUI.Expand(SurveyUI.Container)

        if (Sys.Browser.agent == Sys.Browser.Safari) {
            setTimeout('document.body.scrollTop = 0;', 100);
        }
        else {
            window.scrollTo(0, 0)
        }
        return false;
    },

    HideSurvey: function() {
        BaseUI.Collapse(SurveyUI.Background)
        BaseUI.Collapse(SurveyUI.Container)
        SurveyUI.FixIE()
        document.cookie = "surveyTaken = true;path=/";
    },

    TakeSurvey: function(aFormID) {
        BaseUI.Collapse(SurveyUI.Background)
        BaseUI.Collapse(SurveyUI.Container)
        SurveyUI.FixIE()
        GB_showCenter("", "/PopUpEktronForm.aspx?ekfrm=" + aFormID, 610, 810);
        document.cookie = "surveyTaken = true;path=/";
    },

    FixIE: function() {
        if ((Sys.Browser.agent == Sys.Browser.InternetExplorer) && (Sys.Browser.version == 6)) {
            SurveyUI.Background.style.position = 'absolute'
            SurveyUI.Background.style.height = '0%'
            SurveyUI.Background.style.width = '0%'

            $addHandlers(window, { "resize": BaseUI.WindowResize,
                "scroll": BaseUI.WindowResize
            }, this)

            BaseUI.WindowResize()
        }

    }
}

Sys.Application.add_load(SurveyUI.WindowLoad)


