﻿function PollsManager()
{
    var SetPollPopup = function()
    {
        //set top and left of popup div
        var doShowPoll = $j(".div_to_popup .doShowPoll").val();
        if (doShowPoll == "true")
        {
            var width = utility.GetWidth();
            var height = utility.GetHeight();
            $j(".div_to_popup").css("left", ((width / 2) - ($j(".div_to_popup").width() / 2)) + "px");
            $j(".div_to_popup").css("top", ((height / 2) - ($j(".div_to_popup").height() / 2)) + "px");

            $j(".div_to_popup").css("display", "");
            $j(".div_to_popup").addClass("pop");
            $j("#opacityDiv").css("display", "");
            $j(".div_to_popup .pollIframe").fadeIn("slow");
            $j(".graphIframe").css("display", "none"); 
            $j(".div_to_popup .closeImg").unbind();
            $j(".div_to_popup .closeImg").click(function()
            {
                //close the popup
                ClosePopUp();
                
                //Get pollId and userId
                var pollId = $j(".pollIdForRefuse").val();
                var userId = $j(".userIdForRefuse").val();

                //Create Instance to the WebService
                var externalPollService = Hashavim.Web.Polls.Service.ExternalPollService;

                //Call SetUserPollRefuse Webservice function
                externalPollService.SetUserPollRefuse(userId, pollId, OnSetUserPollRefuseComplete, OnSetUserPollRefuseError);

            });

            $j(".div_to_popup .noImage").click(function()
            {
                //close the popup
                ClosePopUp();

                //Get pollId and userId
                var pollId = $j(".pollIdForRefuse").val();
                var userId = $j(".userIdForRefuse").val();

                //Create Instance to the WebService
                var externalPollService = Hashavim.Web.Polls.Service.ExternalPollService;

                //Call SetUserPollRefuse Webservice function
                externalPollService.SetUserPollRefuse(userId, pollId, OnSetUserPollRefuseComplete, OnSetUserPollRefuseError);
            });

            $j(".div_to_popup .laterImage").click(function()
            {
                //close the popup
                ClosePopUp();
            });

            $j(".div_to_popup .continueImg").click(function()
            {
                //close the popup
                ClosePopUp();
            }); 
        }
    }

    var ClosePopUp = function()
    {
        //close the popup
        $j(".div_to_popup .pollIframe").fadeOut("slow");
        $j(".div_to_popup").css("display", "none");
        $j(".div_to_popup").removeClass("pop");
        $j("#opacityDiv").css("display", "none");
        $j(".graphIframe").css("display", ""); 
    }
    
    var OnSetUserPollRefuseComplete = function(args)
    {
        var result = args;
    }

    var OnSetUserPollRefuseError = function(args)
    {
        var result = args;
    }

    var Init = function()
    {
        SetPollPopup();
    }

    Init();
}
