﻿
function showTC(obj) {
    var d = new Date();
    var urlstr = "TechCenter.aspx?type=show&tcid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(obj) : obj) + "&d=" + d;
    //alert(urlstr);
    $.ajax({
        url: urlstr,
        type: "GET",
        datatype: "json",
        timeout: 20000,
        error: function() {
            alert("error");
        },
        success: function(str) {
            var rst = str.toString().length > 0;
            if (rst) {
                $$("tcContent").innerHTML = str;
            }
            else alert("数据库操作出错，请联系管理员");
        }
    });
}



function addTCname() {    
    
    var tcname = $$("catename").value;
    if (tcname == "") {
        alert("分类名称不能为空，请重新输入");
        return;
    }

    var sel_item = $$("sel_cate").options[$$("sel_cate").selectedIndex].value;
    if (sel_item == 0) {
        alert("请选择所属分类！");
        return;
    }
    var d = new Date();
    var urlstr = "../handler/tc.ashx?type=addCate&tcname=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(tcname) : tcname) +
                 "&pid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(sel_item) : sel_item) + "&d=" + d.getSeconds();
    $.ajax({
        url: urlstr,
        type: "GET",
        datatype: "json",
        timeout: 10000,
        error: function() {
            alert("error");
        },
        success: function(str) {
            var rst = str.toString();
            if (rst == "1") {
                alert("添加成功");
                //refresh_type();
                $$("close").click();
            }
            else if (rst == "2")
                alert("已经存在该分类");

            else alert("数据库操作出错，请联系管理员");
        }
    });
}

function refresh_type() {
    var d = new Date();
    var urlstr = "AddTechnology.aspx?type=refresh&d=" + d.getSeconds();
    $.ajax({
        url: urlstr,
        type: "GET",
        datatype: "json",
        timeout: 10000,
        error: function() {
            alert("error");
        },
        success: function(str) {
            var rst = str.toString().length > 0;
            if (rst) {
                var i = 0;
            }
            else alert("数据库操作出错，请联系管理员");
        }
    });
}

function sub_selected() {
    if ($$("isSubject").checked == true)
        $$("sub_child").style.display = "none";
    else {
        $$("sub_child").style.display = "block";
    }
}

function changeType() {    
    var selectedValue = $$("sel_type").options[$$("sel_type").selectedIndex].value;
    var d = new Date();
    var urlstr = "../handler/tc.ashx?type=changetype&tctype=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(selectedValue) : selectedValue) + "&d=" + d.getSeconds();
    
    $.ajax({
        url: urlstr,
        type: "GET",
        datatype: "json",
        timeout: 10000,
        error: function() {
            alert("error");
        },
        success: function(str) {
            var rst = str.toString().length > 0;
            if (rst) {
                $$("sel_subject").innerHTML = str;
            }
            else alert("数据库操作出错，请联系管理员");
        }
    });
}

function submitTechnology_Click() {
    var pagetype = $$("hd_pagetype").value;
    var tcid = $$("hd_id").value;
    var title = $$("Title").value;
    var abstracts = $$("Abstracts").value;
    var keyword = $$("Keywords").value;
    var sel_type = $$("sel_type").options[$$("sel_type").selectedIndex].value;
    var isSub = $$("isSubject").checked;
    var edit = FCKeditorAPI.GetInstance("FCKeditor1");
    var content = edit.GetHTML();
    //alert(content);
    if (title == "") {
        alert("标题不能为空");
        return;
    }
    if (keyword == "") {
        alert("关键字不能为空");
        return;
    }
    if (sel_type == 0) {
        alert("请选择技术分类");
        return;
    }
    var sub = 0;
    if (isSub == true)
        sub = 0;
    else {
        var hassub = $$("sel_sub").options[$$("sel_sub").selectedIndex].value;
        if (hassub == 0) {
            alert("请选择所属主题");
            return;
        }
        sub = hassub;
    }
    if (content == "") {
        alert("内容不能为空");
        return;
    }
    if (pagetype == "1") {
        var d = new Date();
        var urlstr = "../handler/tc.ashx?type=submit&title=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(title) : title) +
                "$abstracts=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(abstracts) : keyword) +
                "&keyword=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(keyword) : keyword) +
                "&seltype=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(sel_type) : sel_type) +
                "&issub=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(isSub) : isSub) +
                "&sub=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(sub) : sub) +
                "&content=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(content) : content) +
                "&d=" + d.getSeconds();

        $.ajax({
            url: urlstr,
            type: "GET",
            datatype: "html",
            timeout: 10000,
            error: function() {
                alert("error");
            },
            success: function(str) {
                var rst = (parseInt(str)) > 0;
                if (rst) {
                    window.location.href = "TechCenterList.aspx";
                }
                else alert("数据库操作出错，请联系管理员");
            }
        });
    }
    else {
        var d = new Date();
        var urlstr = "../handler/tc.ashx?type=update&tcid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(tcid) : tcid) +
                "&title=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(title) : title) +
                "$abstracts=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(abstracts) : keyword) +
                "&keyword=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(keyword) : keyword) +
                "&seltype=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(sel_type) : sel_type) +
                "&issub=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(isSub) : isSub) +
                "&sub=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(sub) : sub) +
                "&content=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(content) : content) +
                "&d=" + d.getSeconds();
                alert(urlstr);

        $.ajax({
            url: urlstr,
            type: "GET",
            datatype: "html",
            timeout: 10000,
            error: function() {
                alert("error");
            },
            success: function(str) {
                var rst = (parseInt(str)) > 0;
                if (rst) {
                    window.location.href = "TechCenterList.aspx";
                }
                else alert("数据库操作出错，请联系管理员");
            }
        });
    }
}

function delArticle(obj) {
    if (window.confirm("确认要删除吗？")) {
        if (obj != null) {
            var aid = obj;
            var urlstr = "../handler/tc.ashx?type=del&aid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(aid) : aid);
            $.ajax({
                url: urlstr,
                type: "GET",
                datatype: "html",
                timeout: 20000,
                error: function() {
                    alert("error");
                },
                success: function(str) {
                    var rst = (parseInt(str)) > 0;
                    if (rst) {
                        window.location.href = window.location.href;
                    }
                    else alert("数据库操作出错，请联系管理员");
                }
            });
        }
    }
}


function delTraining(obj)
{
    if (window.confirm("确认要删除吗？")) {
        if (obj != null) {
            var tid = obj;
            var urlstr = "../handler/tc.ashx?type=delt&tid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(tid) : tid);
            $.ajax({
                url: urlstr,
                type: "GET",
                datatype: "html",
                timeout: 20000,
                error: function() {
                    alert("error");
                },
                success: function(str) {
                    var rst = (parseInt(str)) > 0;
                    if (rst) {
                        window.location.href = window.location.href;
                    }
                    else alert("数据库操作出错，请联系管理员");
                }
            });
        }
    }

}

function refuse_ParticipateId(obj)
{
    if (obj != null) {
        var aid = obj;
        var urlstr = "../handler/tc.ashx?type=refuse&pid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(aid) : aid);
        $.ajax({
            url: urlstr,
            type: "GET",
            datatype: "html",
            timeout: 20000,
            error: function() {
                alert("error");
            },
            success: function(str) {
                var rst = (parseInt(str)) > 0;
                if (rst) {
                    window.location.href = window.location.href;
                }
                else alert("数据库操作出错，请联系管理员");
            }
        });
    }

}

function pass_ParticipateId(obj)
{
    if (obj != null) {
        var aid = obj;
        var urlstr = "../handler/tc.ashx?type=pass&pid=" + (is_ie && document.charset == 'utf-8' ? encodeURIComponent(aid) : aid);
        $.ajax({
            url: urlstr,
            type: "GET",
            datatype: "html",
            timeout: 20000,
            error: function() {
                alert("error");
            },
            success: function(str) {
                var rst = (parseInt(str)) > 0;
                if (rst) {
                    window.location.href = window.location.href;
                }
                else alert("数据库操作出错，请联系管理员");
            }
        });
    }

}
