﻿<!--

Mortenson.Poll = function()
{
};

var Poll = Mortenson.Poll;

Mortenson.Poll.ValidateAndMove = function(from, to)
{
    if (this.Validate(from))
    {
        var f = Ext.get(from);
        f.addClass('hide');
        var t = Ext.get(to);
        t.removeClass('hide');
    }

    var s = "";
    
}

Mortenson.Poll.ValidateAndSubmit = function(from, pID)
{
    if (this.Validate(from))
    {
        if (this.Validate(from))
        {
            this.SubmitPoll(pID);
        }
    }
}

Mortenson.Poll.Validate = function(div)
{
    var ret = false;
    var d = Ext.get(div);
    var cn = d.dom.childNodes;
    for(i = 0; i < cn.length; i++)
    {
        if(cn[i].type == 'radio')
        {
            if(cn[i].attributes["rdoPoll"].value != null && cn[i].attributes["rdoPoll"].value == 'true')
            {
                if (cn[i].checked)
                {
                    ret = true;
                    break;
                }
            }
        }
    }
    
    if (ret == false)
    {
        alert('Please select an option.');
    }
    
    return ret;
}

Mortenson.Poll.SubmitPoll = function(pID)
{    
    var s = "<options>";    
    var x = document.getElementsByTagName('input');
    for (i = 0; i < x.length; i++)
    {
        if(x[i].type == 'radio')
        {
            if(x[i].attributes["rdoPoll"].value != null && x[i].attributes["rdoPoll"].value == 'true')
            {
                if (x[i].checked)
                {
                    s += "<v qid=\"" + x[i].attributes["QuestionID"].value + "\" aid=\"" + x[i].value + "\"></v>";
                }
            }
        }
    }
    s += "</options>";
    Mortenson.AjaxAPI.MortensonAjax.PollSubmit(pID, s, Mortenson.Poll.SubmitPollProcess);
}
Mortenson.Poll.SubmitPollProcess = function(response)
{
    if (response.error)
    {
        alert(response.error.Message);
    }
    else
    {
        var divPoll = Ext.get("divPollData");
        var a = Ext.DomQuery.selectNode('data', response.value);
        divPoll.update(a.firstChild.nodeValue);
    }   
};

//-->