﻿var surveys = null;
Type.registerNamespace("cancercompass.controls");
cancercompass.controls.Surveys = function() {
}
cancercompass.controls.Surveys.prototype = {
    initialize: function() {
        $("#btnSurveySubmit").click(function() {
            if ($.cookie("survey") == null) {
                $.cookie("survey", 1, { expires: 1 });   
                surveys.addResult($("input[name='rdoPoll']:checked").val());
            } 
            return false;
        });
    },
    addResult: function(surveyQuestionValueID) {
        $("div.survey").html("<p><img src='/images/loader.gif' /> Saving your vote</p>");
        $.ajax({
            type: "POST",
            url: "/common/webservices/survey.asmx/AddResult",
            data: "{'surveyQuestionValueID':'" + surveyQuestionValueID + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function() {
            },
            error: function(xhr) {
            },
            complete: function() {
                $("div[id*='pnlResults']").load("/survey-results.html", function(){
                    $("div[id*='pnlSurvey']").hide();                
                }).fadeIn('slow');
            }
        });
    }
}
$(document).ready(function() {
    surveys = new cancercompass.controls.Surveys;
    surveys.initialize();
});