﻿function SelectAll(objName, isDelete) {
    delList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdDelete);
    subList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdSubcribed);

    delList.value = isDelete ? stringEmpty : delList.value;
    subList.value = !isDelete ? stringEmpty : subList.value;

    if (objName) {
        arrName = stringEmpty;
        if (isDelete)
            arrName = GetArrayID(del).split(separator);
        //else
        //arrName = GetArrayID(sub).split(separator);        
        for (i = 0; i < arrName.length - 1; i++) {
            document.getElementById('ctl00_MyAccountContentPlaceHolder_' + arrName[i]).checked = objName.checked;
            arrValue = arrName[i].split(separator1);
            //if(isDelete)
            //{
            if (objName.checked) {
                delList.value = delList.value + arrValue[1] + separator;
            }
            //}
            //else
            //{
            subList.value = subList.value + arrValue[1] + separator1 + objName.checked + separator;
            //}

        }
    }
}

function GetArrayID(type) {
    objNamList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + checkBoxName);
    arrName = objNamList.value.split(separator);
    strName = stringEmpty;
    for (i = 0; i < arrName.length - 1; i++) {
        strName += arrName[i].indexOf(type) != -1 ? arrName[i] + separator : stringEmpty;
    }
    return strName;
}

function Select(chkID, isDelete) {
    isCheck = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + chkID).checked;

    arrName = stringEmpty;
    chkName = stringEmpty;

    delList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdDelete);
    subList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdSubcribed);

    TestSelectAll(isDelete);

    arrValue = chkID.split(separator1);
    //if(isDelete)
    //{

    delList.value = reset_hd(delList.value, arrValue[1]);
    if (isCheck)
        delList.value = delList.value + arrValue[1] + separator;
    //}
    //else
    //{        
    subList.value = reset_hd(subList.value, arrValue[1] + separator1 + !isCheck);
    subList.value = subList.value + arrValue[1] + separator1 + isCheck + separator;
    //}    

}

function reset_hd(arrValues, value) {
    var arrValues = arrValues.split(separator);
    res = stringEmpty;
    for (i = 0; i < arrValues.length - 1; i++) {
        if (arrValues[i] != value)
            res = res + arrValues[i] + separator;
    }
    return res;
}

function TestSelectAll(isDelete) {
    //    if(isDelete)
    //    {
    arrName = GetArrayID(del).split(separator);
    chkName = chkDelName;
    //    }
    //    else
    //    {
    //        arrName = GetArrayID(sub).split(separator);        
    //        chkName = chkSubName;
    //    }

    isCheckAll = true;
    for (i = 0; i < arrName.length - 1; i++) {
        if (!document.getElementById('ctl00_MyAccountContentPlaceHolder_' + arrName[i]).checked) {
            isCheckAll = false;
            break;
        }
    }
    document.getElementById('ctl00_MyAccountContentPlaceHolder_' + chkName).checked = isCheckAll;
}

function commandQuestion(isDelete) {
    delList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdDelete);
    subList = document.getElementById('ctl00_MyAccountContentPlaceHolder_' + hdSubcribed);
    if (isDelete) {
        if (delList.value == stringEmpty) {
            alert(noneSelection);
            return false;
        }
        return confirm(delQuestion);
    }
    else {
        if (subList.value == stringEmpty) {
            alert(noneSelection);
            return false;
        }
        return confirm(subQuestion);
    }
}

