
function _checkAll(layer, bcheck) {
    for (var i = 0; i < layer.childNodes.length; i++) {
        if (layer.childNodes[i].childNodes.length > 0) {
            _checkAll(layer.childNodes[i], bcheck);
        }
        else {
            if (layer.childNodes[i].type == "checkbox") {
                layer.childNodes[i].checked = bcheck;
            }
        }
    }
}

//删除
function delall(url) {

    $.messager.confirm('确定删除', '确定要删除么，删除后无法恢复?', function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += layer[i].value + ",";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择删除的内容!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);
            var t = document.getElementById("table_id");
            if (t != null) {
                table_id = t.value;
            }
            $.post(url, { ContentIDCollection: check_value, table_id: table_id }, function (msg) {
                if (msg) {
                    window.location.reload();
                } else {
                    $.messager.alert('温馨提示', '删除失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}
//删除
function delall(url) {

    $.messager.confirm('确定删除', '确定要删除么，删除后无法恢复?', function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += layer[i].value + ",";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择删除的内容!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);
            var t = document.getElementById("table_id");
            if (t != null) {
                table_id = t.value;
            }
            $.post(url, { ContentIDCollection: check_value, table_id: table_id }, function (msg) {
                if (msg) {
                    window.location.reload();
                } else {
                    $.messager.alert('温馨提示', '删除失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}

//更新
function updateall(url) {

    $.messager.confirm('确定更新', '确定要更新分类么?', function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += layer[i].value + ",";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择更新的内容!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);
            var t = document.getElementById("table_id");
            if (t != null) {
                table_id = t.value;
            }
            var s_classid = $("#u_class  option:selected").val();
            var s_add = $("#u_add  option:selected").val();
          
            $.post(url, { ContentIDCollection: check_value, table_id: table_id,s_class:s_classid,s_add:s_add }, function (msg) {
                if (msg) {
                    $.messager.alert('温馨提示', '更新成功', 'warning');
                    window.location.reload();
                } else {
                    $.messager.alert('温馨提示', '更新失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}


//更新
function updateall_get(url) {

    $.messager.confirm('确定操作', '确定此操作么?', function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += layer[i].value + ",";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择更新的内容!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);
            var t = document.getElementById("table_id");
            if (t != null) {
                table_id = t.value;
            }
            var s_classid = $("#u_class  option:selected").val();
            var s_add = $("#u_add  option:selected").val();

            $.post(url, { ContentIDCollection: check_value, table_id: table_id, s_class: s_classid, s_add: s_add }, function (msg) {
                if (msg) {
                    $.messager.alert('温馨提示', '更新成功', 'warning');
                    window.location.reload();
                } else {
                    $.messager.alert('温馨提示', '更新失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}
//发送消息(媒体)
function sendradio(url) {
    var layer = document.getElementsByName("ContentIDCollection");
    var mediaid = document.getElementsByName("ContentMediaID");
    var table_id = "";
    var check_value = "";
    var checkmedia_value = '';

    for (var i = 0; i < layer.length; i++) {
        if (layer[i].checked) {
            check_value += "'" + layer[i].value + "',";
        }
    }

    for (var i = 0; i < mediaid.length; i++) {
        if (mediaid[i].checked) {
            checkmedia_value += mediaid[i].value + ",";
        }
    }

    if (check_value == "") {
        $.messager.alert('温馨提示', '请选择素材!', 'warning');
        return false;
    }
    check_value = check_value.substring(0, check_value.length - 1);
    checkmedia_value = checkmedia_value.substring(0, checkmedia_value.length - 1);
    var mediatypevalue = $("#mediatype_" + checkmedia_value).val();
    var mediaidvalue = $("#mediaid_" + checkmedia_value).val()

    var win = $.messager.progress({
        title: '数据发送',
        msg: '数据正在发送中，请稍等 ...'
    });

    $.post(url, { ContentIDCollection: check_value, mediatype: mediatypevalue, mediaid: mediaidvalue }, function (msg) {

        if (msg.indexOf("ok") >= 0) {
            $.messager.progress('close');
            $.messager.alert('温馨提示', '发送成功', 'info');
           
        }
        else {
            $.messager.progress('close');
            $.messager.alert('温馨提示', '发送失败：' + msg, 'warning');
           
        }

    });
}
//素材
function loadmaterial(url) {

    $.messager.confirm('确定同步', '确定要同步数据吗?', function (r) {
        if (r) {
            $.post(url, {}, function (msg) {
                if (msg.indexOf("ok") >= 0) {
                    $.messager.progress('close');
                    window.location.reload();
                  
                } else {
                    $.messager.progress('close');
                    $.messager.alert('温馨提示', '同步失败：' + msg, 'warning');

                }

            })
        }
    });

    return false;
}
//同步
function submiturl(url, title, content) {
    $.messager.confirm(title, content, function (r) {
        if (r) {
            $.post(url, {}, function (msg) {
                if (msg == 'ok') {
                    $.messager.alert('温馨提示', '操作成功：' + msg, 'info');

                } else {
                    $.messager.alert('温馨提示', '同步失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}
//同步好友
function get_userlist(url) {

    $.messager.confirm('同步数据', '确定要同步数据吗?', function (r) {

        var win = $.messager.progress({
            title: '数据操作',
            msg: '数据同步中，请稍等 ...'
        });
        if (r) {
            $.post(url, {}, function (msg) {
                if (msg.indexOf("ok") >= 0) {
                    $.messager.progress('close');
                    $.messager.alert('温馨提示', '操作成功：' + msg, 'info');
                    window.location.reload();

                } else {
                    $.messager.progress('close');
                    $.messager.alert('温馨提示', '同步失败：' + msg, 'warning');
                }

            })
        } else {
            $.messager.progress('close');
        }

    });

    return false;
}

//同步分组
function reloadusergroup(url) {

    $.messager.confirm('确定同步', '确定要同步分组吗?', function (r) {
        if (r) {
            var win = $.messager.progress({
                title: '数据操作',
                msg: '数据同步中，请稍等 ...'
            });
            $.post(url, {}, function (msg) {
                if (msg.indexOf("ok") >= 0) {
                    $.messager.progress('close');
                    window.location.reload();
                } else {
                    $.messager.progress('close');
                    $.messager.alert('温馨提示', '同步失败：' + msg, 'warning');
                }

            });
        } else {
            $.messager.progress('close');
        }
    });

    return false;
}
//发送消息(文本)
function senddata(url) {
    $.messager.confirm('发送信息', '确定要发送信息么?', function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += "'" + layer[i].value + "',";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择要发送的组!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);

            var t = document.getElementById("table_id");

            if (t != null) {
                table_id = t.value;
            }

            var content = $("#textarea_txt").val();
            var win = $.messager.progress({
                title: '正在发布',
                msg: '正在发布中，请稍等 ...'
            });
            $.post(url, { ContentIDCollection: check_value, table_id: table_id, content: content }, function (msg) {
                if (msg.indexOf("ok") >= 0) {
                    $.messager.alert('温馨提示', '发送成功!', 'info');
                    $.messager.progress('close');

                } else {
                    $.messager.alert('温馨提示', '发送失败：' + msg, 'warning');
                    $.messager.progress('close');
                }

            })
        }
    });

    return false;
}

//添加回复消息
function replytext(url) {

    var title = $("#inputtitle").val();
    var inputkeyword = $("#inputkeyword").val();
    var radio_state = $('input[name="radio_state"]:checked').val();
    var textarea_txt = $("#textarea_txt").val();
    var mediatypevalue = '';
    var mediaidvalue = '';
    var inputkey = $("#inputkey").val();
    if (title == "" || inputkeyword == "" || radio_state == '' || textarea_txt == '') {
        $.messager.alert('温馨提示', '必填信息不能为空!', 'warning');
        return false;
    }

    $.post(url, { title: title, inputkeyword: inputkeyword, radio_state: radio_state, textarea_txt: textarea_txt, mediatypevalue: mediatypevalue, mediaid: mediaidvalue, inputkey: inputkey }, function (msg) {
        if (msg.indexOf("ok") >= 0) {
            $.messager.confirm('温馨提示', '添加成功，是否继续添加?', function (r) {
                if (r) {
                    location.reload();
                } else {
                    location.href = 'g_product.aspx?t=reply';
                }
            });

        } else {
            $.messager.alert('温馨提示', '添加失败：' + msg, 'warning');
        }

    })
}
function replymedia(url) {

    var title = $("#inputtitle").val();
    var inputkeyword = $("#inputkeyword").val();
    var radio_state = $('input[name="radio_state"]:checked').val();
    var textarea_txt = '';
    if (title == "" || inputkeyword == "" || radio_state == '') {
        $.messager.alert('温馨提示', '必填信息不能为空!', 'warning');
        return false;
    }
    var layer = document.getElementsByName("ContentIDCollection");
    var check_value = "";
    for (var i = 0; i < layer.length; i++) {
        if (layer[i].checked) {
            check_value += layer[i].value + ",";
        }
    }
    if (check_value == "") {
        $.messager.alert('温馨提示', '请选择素材!', 'warning');
        return false;
    }
    check_value = check_value.substring(0, check_value.length - 1);

    var mediatypevalue = $("#mediatype_" + check_value).html();
    var mediaidvalue = $("#mediaid_" + check_value).val();

    $.post(url, { title: title, inputkeyword: inputkeyword, radio_state: radio_state, textarea_txt: textarea_txt, mediatypevalue: mediatypevalue, mediaid: mediaidvalue }, function (msg) {
        if (msg.indexOf("ok") >= 0) {
            $.messager.confirm('温馨提示', '添加成功，是否继续添加?', function (r) {
                if (r) {
                    location.reload();
                } else {
                    location.href = 'g_product.aspx?t=reply';
                }
            });

        } else {
            $.messager.alert('温馨提示', '添加失败：' + msg, 'warning');
        }

    })

}
function replynews(url) {
    var title = $("#inputtitle").val();
    var inputkeyword = $("#inputkeyword").val();
    var radio_state = $('input[name="radio_state"]:checked').val();
    if (title == "" || inputkeyword == "" || radio_state == '') {
        $.messager.alert('温馨提示', '必填信息不能为空!', 'warning');
        return false;
    }
    var layer = document.getElementsByName("ContentIDCollection");
    var check_value = "";
    for (var i = 0; i < layer.length; i++) {
        if (layer[i].checked) {
            check_value += layer[i].value + ",";
        }
    }
    if (check_value == "") {
        $.messager.alert('温馨提示', '请选择素材!', 'warning');
        return false;
    }
    check_value = check_value.substring(0, check_value.length - 1);

    $.post(url, { title: title, inputkeyword: inputkeyword, radio_state: radio_state, check_value: check_value }, function (msg) {
        if (msg.indexOf("ok") >= 0) {
            $.messager.confirm('温馨提示', '添加成功，是否继续添加?', function (r) {
                if (r) {
                    location.reload();
                } else {
                    location.href = 'g_product.aspx?t=reply';
                }
            });

        } else {
            $.messager.alert('温馨提示', '添加失败：' + msg, 'warning');
        }

    })

}

//添加用户到组
function usertogroup(url, title, content) {

    $.messager.confirm(title, content, function (r) {
        if (r) {
            var layer = document.getElementsByName("ContentIDCollection");
            var table_id = "";
            var check_value = "";
            for (var i = 0; i < layer.length; i++) {
                if (layer[i].checked) {
                    check_value += layer[i].value + ",";
                }
            }
            if (check_value == "") {
                $.messager.alert('温馨提示', '请选择用户!', 'warning');
                return false;
            }
            check_value = check_value.substring(0, check_value.length - 1);

            var t = document.getElementById("table_id");

            if (t != null) {
                table_id = t.value;
            }

            $.post(url, { ContentIDCollection: check_value, table_id: table_id }, function (msg) {
                if (msg) {
                    window.location.reload();
                } else {
                    $.messager.alert('温馨提示', '添加失败：' + msg, 'warning');
                }

            })
        }
    });

    return false;
}


