﻿function SetOptionSelect(optionId, hfId) {
    var oid = document.getElementById(optionId);

}

function OptionRadioClick(tableClientId, optionClientId, questionId, hfClientId) {
    var sepqstr = "@";
    var sepostr = "$";
    var radios = document.getElementById(tableClientId).getElementsByTagName('input');
    var optionId;
    for (var i = 0; i < radios.length; i++) {
        var rr = radios[i];
        if (rr.type == "radio") {
            rr.checked = false;
            if (rr.id == optionClientId) {
                rr.checked = true;
                optionId = rr.value;
            }
        } else {
            continue;
        }
    }

    var optVStr = questionId + sepostr + optionId + sepqstr;
    var hf = document.getElementById(hfClientId);
    var hfvalue = hf.value;
    if (hfvalue == "") {    //存储值为空
        hfvalue = optVStr;
    }
    else {//存储值不为空
        var indexa = hfvalue.indexOf(questionId + sepostr); //查找是否已存在点击的按钮值
        if (indexa != -1) {//存在，替换原有值
            var indexb = hfvalue.indexOf(sepqstr, indexa);
            if (indexb != -1) {
                var rstr = hfvalue.substring(indexa, indexb+1);
                hfvalue = hfvalue.replace(rstr, optVStr);

            }
            else {
                hfvalue = optVStr;
            }

        }
        else {//不存在，添加到后面
            hfvalue += optVStr;
        }
    }
    hf.value = hfvalue;
    //alert(hf.value);

}
function OptionCheckClick(optionClientId,questionId, optionId, hfClientId) {
    var sepqstr = "@";
    var sepostr = "$";
    var check = document.getElementById(optionClientId);
    var optVStr = questionId + sepostr + optionId + sepqstr;
    var hf = document.getElementById(hfClientId);
    var hfvalue = hf.value;
    if (hfvalue == "") {    //存储值为空,选中则添加到存储值
        if (check.checked) {
            hfvalue = optVStr;
        }
    }
    else {//存储值不为空
        var indexa = hfvalue.indexOf(optVStr); //查找是否已存在点击的按钮值
        if (indexa != -1) {//存在，如果未选中则替换为""
            if(check.checked==false)
            {
                hfvalue = hfvalue.replace(optVStr,"");
            }
        }
        else {//不存在，如果选中则添加到后面
        if(check.checked)
            hfvalue += optVStr;
        }
    }
    hf.value = hfvalue;
    //alert(hf.value);

}