﻿//用户登录
function _login() {
    var u = document.getElementById("user").value;
    var p = document.getElementById("pwd").value;

    $.ajax({
        type: "POST",
        url: "/Service/loginsystem.aspx",
        timeout: 20000,
        data: "u=" + u + "&p=" + p,
        error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
        success: function(msg) {
            if (msg == "error") {
                alert("用户名或密码错误,登录失败");
            } else {
                document.location = msg;
            }
        }
    });
}

//编辑学校简介
function _editschool() {
    jBox.open('iframe-upload', 'iframe', '/dlg/editSchool.aspx', '编辑学校介绍', 'width=600,height=350,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//编辑办学理念
function _editbxly() {
    jBox.open('iframe-upload', 'iframe', '/dlg/edityzjy.aspx', '编辑园长寄语与办学理念', 'width=600,height=350,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//编辑招生信息
function _editzsxx() {
    jBox.open('iframe-upload', 'iframe', '/dlg/editzsxx.aspx', '编辑招生信息', 'width=600,height=350,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//编辑学校联系方式
function _editlxfs() {
    jBox.open('iframe-upload', 'iframe', '/dlg/editlxfs.aspx', '学校联系方式', 'width=300,height=150,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//设置学校网站
function _confighomepage() {
    jBox.open('iframe-upload', 'iframe', '/dlg/cfghomepage.aspx', '设置学校网站', 'width=500,height=250,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//学校注册
function _regist() {
    jBox.open('iframe-upload', 'iframe', '/dlg/addschool.aspx', '开通学校平台', 'width=500,height=410,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//添加老师
function _addteacher() {
    jBox.open('iframe-upload', 'iframe', '/dlg/addTeacher.aspx', '添加老师', 'width=600,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//修改老师资料
function _editteacher(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/editTeacher.aspx?id='+id, '修改老师资料', 'width=600,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//修改密码
function _chpwd() {
    jBox.open('iframe-upload', 'iframe', '/dlg/chpwd.aspx', '修改登录密码', 'width=400,height=180,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//编辑一级评价标准
function _editlevel1(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/editLeval1.aspx?id=' + id, '编辑评价领域', 'width=500,height=280,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

function _editlevel2(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/editLeval2.aspx?id=' + id, '编辑评价领域', 'width=500,height=280,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//上传学校LOGO
function _upschoollogo() {
    jBox.open('iframe-upload', 'iframe', '/dlg/uplogo.aspx', '上传学校LOGO', 'width=650,height=420,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//为班级指定老师
function SetTeacherIntoClass(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/ClassTeacher.aspx?class=' + id, '指定老师', 'width=630,height=350,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//添加班级
function _addclass() {
    jBox.open('iframe-upload', 'iframe', '/dlg/addClass.aspx', '添加班级', 'width=380,height=280,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//学校端添加学生
function _addbaby() {
    jBox.open('iframe-upload', 'iframe', '/dlg/CreateNewBaby.aspx', '幼儿档案注册', 'width=520,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//教师端添加学生
function _addbaby2() {
    jBox.open('iframe-upload', 'iframe', '/dlg/CreateNewBaby2.aspx', '幼儿档案注册', 'width=520,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}
//学校端修改学生信息
function _editbaby(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/CreateNewBaby.aspx?t=1&i='+id, '幼儿档案修改', 'width=520,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//教师端修改学生信息
function _editbaby2(id) {
    jBox.open('iframe-upload', 'iframe', '/dlg/CreateNewBaby2.aspx?t=1&i='+id, '幼儿档案修改', 'width=520,height=320,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//生源类型
function _babytype() {
    jBox.open('iframe-upload', 'iframe', '/dlg/BabyType.aspx', '生源类型', 'width=450,height=260,center=true,minimizable=true,resize=false,draggable=true,model=true,scrolling=true');
}

//教师删除本班的学生
function _delbabybyteacher(id){
    if (confirm("是否要删除该学生？")) {
        $.ajax({
            type: "POST",
            url: "/Service/DelBabyByTeacher.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=" + id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    location.reload();
                } else {
                    alert(msg);
                }
            }
        });
    }
}
//删除老师
function _delteacher(id) {

    if (confirm("是否要删除老师？")) {
        $.ajax({
            type: "POST",
            url: "/Service/DelTeacher.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=" + id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    document.location = document.location;
                }
            }
        });
    }
}

//删除班级
function _delclass(id) {
    if (confirm("是否要删除该班级？")) {
        $.ajax({
            type: "POST",
            url: "/Service/DelClass.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=" + id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    document.location = document.location;
                } else {
                    alert(msg);
                }
            }
        });
    }
}

//删除孩子档案
function _delbaby(id,iyear) {
    if (confirm("是否要删除该学生？")) {
        $.ajax({
            type: "POST",
            url: "/Service/DelBaby.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=" + id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    GetRegistBabyList(iyear);
                } else {
                    alert(msg);
                }
            }
        });
    }
}

//转移孩子档案
function _movebaby(id, iyear) {
    if (confirm("是否要转出该学生的档案？")) {
        $.ajax({
            type: "POST",
            url: "/Service/MoveBaby.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=" + id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    GetRegistBabyList(iyear);
                } else {
                    alert(msg);
                }
            }
        });
    }
}

//提交用户的发言
function UserTalk() {
    var obj = document.getElementById("_usertalk");
    if (obj) {
        var v = obj.innerHTML;
        $.ajax({
            type: "POST",
            url: "/Service/saveusertalk.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "id=0&v=" + v,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    obj.innerHTML = "";
                    getActionHtml();
                } else {

                }
            }
        });
    } else {
        return false;
    }
}

//获取用户动态
function getActionHtml() {
    var obj = document.getElementById("divClassActive");
    if (obj) {
        var v = obj.innerHTML;
        $.ajax({
            type: "POST",
            url: "/Service/GetActionList.aspx",
            timeout: 20000,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                obj.innerHTML = msg;
            }
        });
    } else {
        return false;
    }
}

//初始化回复界面
function initre(obj,idex,id) {
    if (obj) {
        obj.style.height = "50px";
        obj.style.overflow = "auto";
        obj.contentEditable = true;
        obj.innerHTML = "";

        var toolbar = document.getElementById("tb"+idex);
        toolbar.innerHTML = "<img src='/images/btn_ok.gif' class='button' onclick='submitre("+idex+","+id+");'  />&nbsp;&nbsp;&nbsp;&nbsp;"+
            "<a href='javascript:void(0);' onclick='beginre(" + idex + ");'>取消</a>";
    }
}

//取消回复
function beginre(idex) {
    var obj = document.getElementById("re" + idex);
    if (obj) {
        obj.contentEditable = false;
        obj.innerHTML = "回复";
        obj.style.height = "16px";
        obj.style.overflow = "hidden";
        var toolbar = document.getElementById("tb" + idex);
        toolbar.innerHTML = "";
    }
}

//提交回复
function submitre(idex,id) {
    var obj = document.getElementById("re" + idex);
    if (obj) {
        var v = obj.innerHTML;
        $.ajax({
            type: "POST",
            url: "/Service/saveusertalk.aspx",
            timeout: 20000,
            async: false,   //ajax同步提交
            data: "v=" + v+"&id="+id,
            error: function() { alert('非常抱歉,服务器发生错误,请稍后再试'); },
            success: function(msg) {
                if (msg == "ok") {
                    getActionHtml();
                } else {

                }
            }
        });
    }
}

