﻿/// Reference is for intellisense only
/// <reference path="../../Scripts/jquery-1.4.1-vsdoc.js" />
//$(document).ready(function () { $(":input[type='radio'][class='inputCheckedDummy']").each(function () { validateRadioButtons(this); }); });
//function validateRadioButtons(inputId) {
//    var name = $(inputId).attr('name');
//    if ($("input[name='" + name + "'][type='radio']:checked").length > 0)
//        toggleRadioButtons(inputId);
//}


//disabled for performance $(document).ready(function () { $(":input[type='radio'][class='inputCheckedDummy']").click(function () { toggleRadioButtons(this); }); });
//Attached in QuestionTable.CreateRadioButton
function toggleRadioButtons(inputId) {

    var name = $(inputId).attr('name');

    //Set class to red for all radiobutton in the same group
    $("input[name='" + name + "'][type='radio']")
        .parent() //div
        .parent() //td - table cell
        .css("background", "#F77");
        //.removeClass('inputChecked')
        //.addClass('inputUnchecked');

    //Set class to green for the selected radiobutton
    $("input[name='" + name + "'][type='radio']:checked")
        .parent() //div
        .parent() //td - table cell
        .css("background", "#7F7");
//        .removeClass('inputUnchecked')
//        .addClass('inputChecked');
}


//Attached in QuestionTable.CreateCheckbox, validate checkboxes onload
//$(document).ready(function () { $(":input[type='checkbox'][class='inputCheckedDummy']").each(function () { toggleCheckboxes(this); }); });

//disabled for performance $(document).ready(function () { $(":input[type='checkbox'][class='inputCheckedDummy']").click(function () { toggleCheckboxes(this); }); });
//Attached in QuestionTable.CreateCheckbox, validate checkboxes onload
function toggleCheckboxes(inputId) {

    var checkbox = $(inputId);
    var color = checkbox.is(":checked") || checkbox.attr("checked") ? "#7F7" : "#FFF";

    $(inputId).parent().parent().css("background", color);
}



// Groupvalidator Counters

//original counter texts
var counterText = new Array();
var counters = new Array();

function aggregateTotal(groupValidatorId) {
    var textboxes = $('.' + groupValidatorId);

    var total = 0;
    textboxes.each(function (i, t) {
        if ($(t).val() != '')
            total = total + TryParseFloat($(t).val());
    });

    var label = $('span[id$="' + groupValidatorId + '_lblTotalCounter"]');
    //var label = $(":aspnet('" + groupValidatorId + "_lblTotalCounter')");
    var labelId = label.attr('id');

    counters[labelId] = total.toString();

    var html = ReplaceAll(counterText[labelId], '{counter}', total.toString());
    label.html(html);
}

$(document).ready(function () { CleanAndStoreCounterPlaceholders(); });
function CleanAndStoreCounterPlaceholders() {
    var labels = $('span[id$="_lblTotalCounter"]');

    var total = 0;
    labels.each(function (i, t) {
        var labelId = $(t).attr('id');
        var labelText = $(t).html();
        counterText[labelId] = labelText;

        if (counters[labelId] == null) {
            counters[labelId] = 0;
            $(t).html(ReplaceAll($(t).html(), '{counter}', '0'));
        }
        else {
            $(t).html(ReplaceAll($(t).html(), '{counter}', counters[labelId]));
        }
    });
}
