﻿//used for radio button yes/no questions with feedback if yes
function RadioQuestion(jQuestion, txtValidatorID, fileValidatorID, showDetailsOnYes) {

    //need to wire up events
    this.radioShow = jQuestion.find((showDetailsOnYes ? ".jRadioShow" : ".jRadioHide"));
    this.radioHide = jQuestion.find((showDetailsOnYes ? ".jRadioHide" : ".jRadioShow"));
    this.details = jQuestion.find(".jDetailsDiv");
    this.txtValidatorID = txtValidatorID;
    this.fileValidatorID = fileValidatorID;
    //try to find the validators
    this.txtValidator = document.getElementById(this.txtValidatorID);
    this.fileValidator = document.getElementById(this.fileValidatorID);
    
    var _this = this;

    this.radioShow.click(function() {
        _this.details.show();
        //use MS client validation to enable
        if (_this.txtValidator != null) {
            ValidatorEnable(_this.txtValidator, true);
        }
        if (_this.fileValidator != null) {
            ValidatorEnable(_this.fileValidator, true);
        }


    });
    this.radioHide.click(function() {
        _this.details.hide();
        //use MS client validation to disable validator
        if (_this.txtValidator != null) {
            ValidatorEnable(_this.txtValidator, false);
        }
        if (_this.fileValidator != null) {
            ValidatorEnable(_this.fileValidator, false);
        }
    });
}
RadioQuestion.prototype.DoSomething = function() {
    //do nothing for some reason if this is not here JS does not recognize this as an object!
}

//This requires that the property NamingContainerId is set on the
//validation object in the code behind by using the: ClientScriptManager..::.RegisterExpandoAttribute Method
var questionValidationHelper = {

    DoValidateButtons: function(sender, args) {
        args.IsValid = ($("#" + sender.NamingContainerId + " .radioButtons input:checked").val() != undefined);
    },
    DoValidateReason: function(sender, args) {
        args.IsValid = ($("#" + sender.NamingContainerId + " .radioButtons input:checked").val() != undefined && $("#" + sender.NamingContainerId + " .jDetailsDiv textarea").val().length > 0);
    },
    DoValidateFileUploaded: function(sender, args) {
        //if the user has uploaded a file
        args.IsValid = ($("#" + sender.NamingContainerId + " .jFileStatus span").html().length > 0);
    }
}
