﻿/********************************************************************************************/
/* LoginWin */
/********************************************************************************************/
var LoginWin = function() { }
//SiteType "netsite":main site,"school":school site,"blog":blog site
LoginWin.SiteType = "";
LoginWin.CallBackScript = "";
LoginWin.ShowLoginDlg = function() {
    var Html = '<div id="divLoginWin" class="LoginWin Font04">' +
            '<div style="width:160px; height:327px; float:left; padding-top:70px;"><img src="/Images/public/izzy.jpg" width="145" height="169" /></div>' +
            '<div style="width:220px; height:327px; float:left"><br /><br />' +
            '<span style="font-size:14px; font-weight:bold;">请登录</span><br /><br /><span id="spanHint" style="color:#FF0000"></span><br /><br />' +
            '用户名： <br /><input type="text" name="txtLoginName" id="txtLoginName" class="txtInput" style="width:150px;" maxlength="30" onclick="LoginWin.ClickLoginName();" onblur="LoginWin.BlurLoginName();" /><br /><br />' +
            '密码：<br /><input type="password" name="txtLoginPwd" id="txtLoginPwd" class="txtInput" style="width:150px;" maxlength="16" /><br /><br />' +
            '<div><div style="float:left;">验证码：<br /><input type="text" id="txtVerifyCode" class="txtInput" style="width:50px;" MaxLength="5" /></div>' +
            '<div style="float:left;width:70px;margin-left:10px;margin-top:13px;"><img id="imgVerify" src="/Login/VerifyCode.aspx" height="20" width="63" style="cursor:hand;" title="看不清，换一张。" onclick="this.src=this.src+\'?\';" /></div>' +
            '</div><div class="ClearBoth"></div>' +
	        '<input type="checkbox" name="chkSavePwd" id="chkSavePwd">记住密码&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.dadikid.net/login/forgotpwd.aspx">忘记密码</a><br />' +
            '<p><a href="javascript:void(null)" onclick="LoginWin.UserLogin();"><img src="/Images/public/btLogin.gif" border="0" /></a>&nbsp;' +
            '<a href="javascript:void(null)" onclick="LoginWin.CloseLoginWin();"><img src="/Images/public/btClose.gif" border="0" /></a></p>' +
            '</div>' +
            '<div style="width:1px; height:327px; float:left;background-color: #B7E292;"></div>' +
            '<div style="width:319px; height:327px;float:right;text-align:center">' +
            '<div style="width:100%;font-size:16px; font-weight:bold; text-align:center;">家园网----无障碍沟通</div><br /><br />' +
            '<div><img src="/Images/Contact/login_teacher.gif" width="236" height="108" /></div><br />' +
	        '<div><img src="/Images/Contact/login_parent.gif" width="236" height="108" /></div>' +
            '</div></div>';
    $(document.body).append(Html);
    $("#divLoginWin").floatdiv("middle");
    if (getCookie("netsiteuserinfo1") != null) {
        $("#txtLoginName").val(getCookie("netsiteuserinfo1"));
    }
    else {
        $("#txtLoginName").val("账号/手机/邮箱皆可登录");
    }
    if (getCookie("netsiteuserinfo2") != null) {
        $("#txtLoginPwd").val(getCookie("netsiteuserinfo2"));
    }
    if (getCookie("netsiteuserinfo3") != null) {
        $("#chkSavePwd").attr("checked", getCookie("netsiteuserinfo3"));
    }
}
LoginWin.ClickLoginName = function() {
    if ($("#txtLoginName").val() == "账号/手机/邮箱皆可登录")
        $("#txtLoginName").val("");
}
LoginWin.BlurLoginName = function() {
    if ($("#txtLoginName").val() == "")
        $("#txtLoginName").val("账号/手机/邮箱皆可登录");
}
LoginWin.CloseLoginWin = function() {
    CloseOpDiv("divLoginWin");
    $("#divLoginWin").remove();
}
LoginWin.UserLogin = function() {
    var ServiceUrl = "/Login/Login.ashx";
    var userid = $.trim($("#txtLoginName").val());
    if (userid == "") {
        $("#spanHint").html("请输入用户名。");
        return;
    }
    var userpwd = $.trim($("#txtLoginPwd").val());
    if (userpwd == "") {
        $("#spanHint").html("请输入密码。");
        return;
    }
    var verifycode = $.trim($("#txtVerifyCode").val());
    if (verifycode == "") {
        $("#spanHint").html("请输入验证码。");
        return;
    }
    var issavepwd = $("#chkSavePwd").attr("checked");
    $.ajax({
        type: "POST",
        url: ServiceUrl,
        data: { "action": "userlogin", "userid": userid, "userpwd": userpwd, "verifycode": verifycode, "cid": Math.round(Math.random() * 100) },
        error: function(xmlHttpRequest, error) {
            alert("登录失败。");
        },
        success: function(xml) {
            var ret = eval("(" + xml + ")");
            if (ret.state == "0") {
                if (ret.issafe == "False") {
                    location.href = "Login/AccountSafe.aspx";
                }
                if (issavepwd) {
                    setCookie("netsiteuserinfo1", userid);
                    setCookie("netsiteuserinfo2", userpwd);
                    setCookie("netsiteuserinfo3", issavepwd);
                } else {
                    delCookie("netsiteuserinfo1");
                    delCookie("netsiteuserinfo2");
                    delCookie("netsiteuserinfo3");
                }
                if (LoginWin.CallBackScript != "") {
                    setTimeout(function() { eval(LoginWin.CallBackScript); }, 0);
                }
                else {
                    LoginWin.ShowLoginInfo(ret);
                    LoginWin.CloseLoginWin();
                }
            } else {
                $("#spanHint").html(ret.error);
            }
        }
    });
}
LoginWin.ShowLoginInfo = function(ret) {
    var Leaderhtml = "";
    var Teacherhtml = "";
    var Parenthtml = "";
    switch (LoginWin.SiteType) {
        case "":
        case "netsite":
            Leaderhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a href=\"/Manage\">我的管理中心</a>";
            if (ret.classid != "0")
                Teacherhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a href=\"/Manage\">我的管理中心</a>";
            else
                Teacherhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a href=\"/Manage/\">我的管理中心</a>";
            Parenthtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a href=\"/Manage\">我的管理中心</a>&nbsp;&nbsp;<a href=\"http://blog.dadikid.net/" + ret.loginid + "/\">我的小家</a>";
            break;
        case "school":
            Leaderhtml = "<br /><br /><a target=\"_blank\" href=\"http://www.dadikid.net/\">家园网</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage\">我的管理中心</a>";
            if (ret.classid != 0)
                Teacherhtml = "<br /><br /><a target=\"_blank\" href=\"http://www.dadikid.net/\">家园网</a>&nbsp;&nbsp;<a href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage\">我的管理中心</a>";
            else
                Teacherhtml = "<br /><br /><a target=\"_blank\" href=\"http://www.dadikid.net/\">家园网</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage/\">我的管理中心</a>";
            Parenthtml = "<br /><br /><a target=\"_blank\" href=\"http://www.dadikid.net/\">家园网</a>&nbsp;&nbsp;<a href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage\">我的管理中心</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://blog.dadikid.net/" + ret.loginid + "/\">我的小家</a>";
            break;
        case "blog":
            Leaderhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"/Manage\">我的管理中心</a>";
            if (ret.classid != 0)
                Teacherhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage\">我的管理中心</a>";
            else
                Teacherhtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage/\">我的管理中心</a>";
            Parenthtml = "<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/\">我的幼儿园</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://" + ret.kidid + ".dadikid.net/Class/" + ret.classid + "/\">我的班级</a>&nbsp;&nbsp;<a target=\"_blank\" href=\"http://www.dadikid.net/Manage\">我的管理中心</a>";
            break;
    }
    if ($("#ctl00_lbLoginInfo").length > 0) {
        switch (ret.pkUserType) {
            case "3": //老师
                $("#ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Teacherhtml);
                break;
            case "4": //园长
                $("#ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Leaderhtml);
                break;
            case "5": //家长
                $("#ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Parenthtml);
                break;
        }
        $("#ctl00_lnkLogin").html('<a href="/login/logout.aspx">退出登录</a>');
    }
    else if ($("#ctl00_ctl00_lbLoginInfo").length > 0) {
        switch (ret.pkUserType) {
            case "3": //老师
                $("#ctl00_ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Teacherhtml);
                break;
            case "4": //园长
                $("#ctl00_ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Leaderhtml);
                break;
            case "5": //家长
                $("#ctl00_ctl00_lbLoginInfo").html("<b>" + ret.username + "</b>&nbsp;欢迎您！&nbsp;&nbsp;" + Parenthtml);
                break;
        }
        $("#ctl00_ctl00_lnkLogin").html('<a href="/login/logout.aspx">退出登录</a>');
    }
}

/********************************************************************************************/

function getRelativePath() {
    var url = location.href;
    var path = url.length - url.replace(/\//g, "").length - 4;
    var str = "";
    for (var i = 0; i < path; i++) {
        str += "../";
    }
    return str;
}
function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name) {
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]); return null;
}
function delCookie(name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = getCookie(name);
    if (cval != null) document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
}

//弹出提示框
function ShowTipsOkay(vIsOkay, vTitle, vContent) {
    var Html = "<div id=\"divTips\" style=\"width: 396px; display: none;\">" +
                "<div style=\"background: url(/Images/public/Box01_01.gif) no-repeat; height: 29px;\">" +
                    "<div class=\"Left\" style=\"margin-top: 10px; margin-left: 5px;\">" +
                        "<strong>" +
                            vTitle +
                        "</strong>" +
                    "</div>" +
                    "<div class=\"Right\" style=\"margin-top: 10px; margin-right: 5px;\">" +
                        "<img src=\"/Images/public/Icon_Close01.gif\" width=\"9\" height=\"9\" style=\"cursor: hand;\" onclick=\"CloseOpDiv('divTips');\">" +
                    "</div>" +
                    "<div class=\"ClearBoth\">" +
                    "</div>" +
                "</div>" +
                "<div style=\"background: url(/Images/public/Box01_02.gif) repeat-y; padding: 10px;height: 80px; line-height: 80px;\">" +
                    "<div class=\"Left\" style=\"margin-left: 20px;\">" +
                        "<img src=\"/Images/public/Icon-" + (vIsOkay ? "Okay" : "Wrong") + ".gif\" width=\"48\" height=\"49\">" +
                    "</div>" +
                    "<div class=\"Content\">" +
                        vContent +
                    "</div>" +
                "</div>" +
                "<div>" +
                    "<img src=\"/Images/public/Box01_03.gif\" width=\"396\" height=\"5\">" +
                "</div>" +
            "</div>";
    $(document.body).append(Html);
    $("#divTips").css("display", "block");
    $("#divTips").floatdiv("middle");
}

//全选CheckBox
var vCheckAll = true;
function CheckAll(vParentObjId) {
    if (vParentObjId != null) {
        $("#" + vParentObjId + ":checkbox").each(function() {
            $(this).attr("checked", vCheckAll);
        });
    }
    else {
        $(":checkbox").each(function() {
            $(this).attr("checked", vCheckAll);
        });
    }
    vCheckAll = (vCheckAll == true ? false : true);
}

//是否有选
function CheckObjSelected(vParentObjId) {
    var vSuccess = false;
    if (vParentObjId != null) {
        $("#" + vParentObjId + " :checkbox").each(function() {
            if ($(this).attr("checked")) {
                vSuccess = true;
            }
        });
    }
    else {
        $(":checkbox").each(function() {
            if ($(this).attr("checked")) {
                vSuccess = true;
                return;
            }
        });
    }
    if (vSuccess)
        return true;
    else {
        alert("请选择信息!");
        return false;
    }
}
/***************************************************************************/
Dialog = function() { }

Dialog.ButtonStyle = [];

//单个按钮关闭[{"Button":"OK","Event":""}]
//[{"Button":"HTML","Event":"三秒钟后自动关闭。"}];
//三个按钮[{"Button":"YES","Event":"alert('yes');"},{"Button":"NO","Event":"alert('no');"},{"Button":"CLOSE","Event":""}];

//HTML [{"Button":"HTML","Event":"提示：<a href='#'>我要注册</a>"}];
//[{"Button":"HTML","Event":"三秒钟后自动关闭。"}];
//{"Button":"YES","Event":""},{"Button":"NO","Event":""},{"Button":"CLOSE","Event":""}];

Dialog.ButtonIcon = [{ "Button": 1, "ICON": "/images/dlg/btTrue.gif" },
				   { "Button": 2, "ICON": "/images/dlg/btCancel.gif" },
				   { "Button": 3, "ICON": "/images/dlg/btTrue.gif" },
				   { "Button": 4, "ICON": "/images/dlg/btCancel.gif" },
				   { "Button": 5, "ICON": "/images/dlg/btclose.gif"}];

Dialog.getButtonIcon = function(bt) {
    var ret = "";
    $.each(Dialog.ButtonIcon, function(x, n) {
        if (n.Button == bt) {
            ret = n.ICON;
        }
    });
    return ret;
}

Dialog.AutoClose = function(t) { setTimeout("Dialog.Close(null);", t); }
Dialog.AutoLink = function(url, t) { setTimeout("location.href='" + url + "';", t); }

Dialog.MsgBox = function(title, msg, iconstyle) {
    if (title == "") { title = "消息对话框" };
    var icon = (iconstyle == 0 ? "ok.gif" : (iconstyle == 1 ? "error.gif" : "warning.gif"));
    var h = 140;
    var cid = "divDialog" + parseInt(Math.random() * 1000).toString();
    var Html = '<div id="' + cid + '" style="position:absolute;z-index:200;">' +
           '<div style="background-image:url(/Images/Dlg/top.gif); background-repeat:no-repeat; height:31px;width:400px;">' +
           '<div style="float:left; font-weight:bold; font-size:14px; margin-top:10px; margin-left:15px; color:#565656">' + title + '</div>' +
           '<div style="float:right; margin-right:15px;margin-top:10px;"><a href="javascript:void(null)" onclick="Dialog.Close(\'' + cid + '\');"><img src="/Images/Dlg/close.gif" border="0" /></a></div>' +
           '</div>' +
           '<div style="background-image:url(/Images/Dlg/bg.gif); background-repeat:repeat-y ; width:400px;height:' + h + 'px;">' +
           '<div style="float:left;width:70px;height:' + (h - 50).toString() + 'px; margin:10px; text-align:center"><br /><img src="/Images/Dlg/' + icon + '" /></div>' +
           '<div style="float:right;width:280px;height:' + (h - 50).toString() + 'px; margin:10px; font-family:宋体; font-size:13px; color:#565656; line-height:150%; text-indent:25px;overflow:auto;">' + msg + '</div>' +
           '<div style="clear:both;"></div>' +
           '<div style="width:400px;height:30px; text-align:center; margin-bottom:10px;">';
    $.each(this.ButtonStyle, function(x, n) {
        if (n.Event == "") n.Event = "Dialog.Close('" + cid + "')";
        if (n.Button == "") n.Button = 1;
        if (n.Button == 6)
            Html += n.Event
        else {
            //Html+='&nbsp;<a href="javascript:void(null)" onclick="'+n.Event+'"><img src="'+Dialog.getButtonIcon(n.Button)+'" border="0" /></a>';	
            var browser = navigator.appName
            var b_version = navigator.appVersion
            var version = b_version.split(";");
            var trim_Version = version[1].replace(/[ ]/g, "");
            if (browser == "Microsoft Internet Explorer" && trim_Version == "MSIE6.0") {
                Html += '&nbsp;<a href="#" onclick="' + n.Event + '"><img src="' + Dialog.getButtonIcon(n.Button) + '" border="0" /></a>';
            }
            else {
                Html += '&nbsp;<a href="javascript:void(null)" onclick="' + n.Event + '"><img src="' + Dialog.getButtonIcon(n.Button) + '" border="0" /></a>';
            }
        }

    });
    Html += '</div>' +
   	    '</div><div><img src="/Images/Dlg/bottom.gif" /></div></div> ';
    $(document.body).append(Html);
    $("#" + cid + "").css("display", "block");
    $("#" + cid + "").floatdiv("middle");
}

Dialog.Close = function(obj) {
    CloseOpDiv(obj);
    $("#" + obj).remove();
}
/***********************/
Dialog.ShowBox = function(title, Width, Height, Html) {
    var w = Width - 26;
    var h = Height - 44;
    var cid = "divDialog" + parseInt(Math.random() * 1000).toString();
    var HtmlStr = '<div id="' + cid + '" style="position:absolute;z-index:200;width:' + Width + 'px;height:' + Height + 'px;">' +
      '<table border="0" cellpadding="0" cellspacing="0" style="width:' + Width + 'px;height:' + Height + 'px;">' +
       	'<tr>' +
            '<td style="width: 14px; height: 31px;"><img src="/Images/Dlg/border_lt.gif" style="width: 14px; height: 31px" /></td>' +
       	    '<td valign="middle" style="background-image:url(/Images/Dlg/border_tb.gif); background-repeat:repeat-x;text-align:left;font-weight:bold; font-size:14px;color:#565656">' + title +
            '<div style="float:right;margin-top:-13;"><a href="javascript:void(null)" onclick="Dialog.Close(this);"><img src="/Images/Dlg/close.gif" border="0" /></a></div></td>' +
       	    '<td style="width: 10px; height: 31px;"><img src="/Images/Dlg/border_tr.gif" style="width: 10px; height: 31px;" /></td>' +
        '</tr>' +
       	'<tr>' +
            '<td style="background-image:url(/Images/Dlg/border_lb.gif); background-repeat:repeat-y;"></td>' +
       	    '<td align="left" valign="top" style="background-color:White;"><div style="overflow:auto; width:' + w + 'px;height:' + h + 'px;">' + Html + '</div></td>' +
            '<td style="background-image:url(/Images/Dlg/border_rb.gif); background-repeat:repeat-y;"></td>' +
       	'</tr>' +
        '<tr>' +
       	    '<td style="width: 14px; height: 11px;"><img src="/Images/Dlg/border_bl.gif"  style="width: 14px; height: 11px;" /></td>' +
            '<td style="background-image:url(/Images/Dlg/border_bb.gif); background-repeat:repeat-x;"></td>' +
       	    '<td style="width: 10px; height: 11px;"><img src="/Images/Dlg/border_br.gif" style="width: 10px; height: 11px;" /></td>' +
        '</tr>' +
    '</table>' +
    '</div>';
    $(document.body).append(HtmlStr);
    $("#" + cid).css("display", "block");
    $("#" + cid).floatdiv("middle");
}





