﻿Poll = new Class({
    initialize: function(options) {


        this.divPollContent = $('divPollContent');
        this.divPollAnswer = $('PollAnswers');
        this.btnSend = $('btnSend');
        this.btnSend.addEvent('click', this.btnSend_Click.bind(this));


        this.btnResult = $('btnResult');
        this.btnResult.addEvent('click', this.btnResult_Click.bind(this));

        this.spnPollID = $('ctl00_ContentPlaceHolderLeft_spnPollID');



        this.oldCookies = Cookie.read('pID');
        //    alert(this.oldCookies);    
        if (this.oldCookies == this.spnPollID.get('html')) {

            this.divPollAnswer.hide();
            this.divPollContent.set('morph', { duration: 'long', transition: 'circ:out' });
            this.divPollContent.morph({ width: 300 });
            //alert('burayami geldin');
            this.DrawPoll();
        } //cookies check
        else {
            this.divPollAnswer.show();

            ///this.DrawPools = this.DrawPoll();
            //Cookie.write('pID', this.spnPollID.get('html'));
        }

    },

    btnSend_Click: function() {
        var rbs = $('PollAnswers').getElements('input[id^=ctl00_ContentPlaceHolderLeft_RBAnswers_]');

        for (var i = 0; i < rbs.length; i++) {
            if (rbs[i].checked == true) {
                Cookie.write('pID', this.spnPollID.innerHTML, { duration: 7 });


                //var calis=function(){this.DrawPoll()};

                //alert('yoksa burayami geldin');
                Lomo.Send('/serv.ashx', 'participateInPoll', 'pid=' + this.spnPollID.innerHTML + '&vote=' + rbs[i].defaultValue, function(result) { });

                //calis.bind(this);
                //calis();

            }
        }
        this.DrawPoll();
    },

    btnResult_Click: function() {
        this.DrawPoll();
    },

    DrawPoll: function() {
        this.divPollContent.innerHTML = '';
        var frmChart = new IFrame({
            src: "/chart.aspx?t=1",
            id: "frmPollChart",
            frameborder: "0",
            scrolling: 'no',
            styles: {
                width: 300,
                height: 250,
                overflow: 'hidden',
                marginwidth: '0px',
                marginheight: '0px',
                hspace: '0px',
                vspace: '0px'
            }
        });
        frmChart.inject($('divPollContent'));
    }
});

window.addEvent('domready', function() {
    var poll = new Poll();
});


