﻿// JScript 文件
var isIe = (document.all) ? true : false;
//是否登录
var flag = 0;
//Session里的值
var session_Code;
//设置select的可见状态 
function setSelectState(state) {
    var objl = document.getElementsByTagName('select');
    for (var i = 0; i < objl.length; i++) {
        objl[i].style.visibility = state;
    }
}
function mousePosition(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft, y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//弹出方法 
function showMessageBox(wTitle, content, pos, wWidth) {
    closeWindow();
    var bWidth = parseInt(document.documentElement.scrollWidth);
    var bHeight = parseInt(document.documentElement.scrollHeight);
    if (isIe) {
        setSelectState('hidden');
    }
    var back = document.createElement("div");
    back.id = "back";
    var styleStr = "top:0px;left:0px;position:absolute;background:#666;width:" + bWidth + "px;height:" + bHeight + "px;";
    styleStr += (isIe) ? "filter:alpha(opacity=0);" : "opacity:0;";
    back.style.cssText = styleStr;
    document.body.appendChild(back);
    showBackground(back, 50);
    var mesW = document.createElement("div");
    mesW.id = "mesWindow";
    mesW.className = "mesWindow";
    mesW.innerHTML = "<div class='mesWindowContent' id='mesWindowContent'>" + content + "</div>";

    var left = (screen.width / 2) - 250;
    var top = (screen.height / 2) - 300;

    styleStr = "left:" + left + "px;top:" + top + "px;position:absolute;width:" + wWidth + "px;";
    mesW.style.cssText = styleStr;
    document.body.appendChild(mesW);
}
//让背景渐渐变暗 
function showBackground(obj, endInt) {
    if (isIe) {
        obj.filters.alpha.opacity += 1;
        if (obj.filters.alpha.opacity < endInt) {
            setTimeout(function() { showBackground(obj, endInt) }, 5);
        }
    } else {
        var al = parseFloat(obj.style.opacity); al += 0.01;
        obj.style.opacity = al;
        if (al < (endInt / 100))
        { setTimeout(function() { showBackground(obj, endInt) }, 5); }
    }
}
//关闭窗口 
function closeWindow() {
    if (document.getElementById('back') != null) {
        document.getElementById('back').parentNode.removeChild(document.getElementById('back'));
    }
    if (document.getElementById('mesWindow') != null) {
        document.getElementById('mesWindow').parentNode.removeChild(document.getElementById('mesWindow'));
    }

    if (isIe) {
        setSelectState('');
    }
}
//测试弹出 
//function testMessageBox(ev) 
//{ 
//var objPos = mousePosition(ev); 
//messContent="<div style='padding:20px 0 20px 0;text-align:center'><table width='458' height='270' align='center' cellspacing='0' style='border:4px solid #26B8F1; background-color:White;'>  <tr>    <td height='30' style=' background:url(../image/login_r2_c2.jpg) no-repeat 1px 1px;'><table width='100%' height='100%' border='0' cellspacing='0'>      <tr>        <td width='94%' valign='middle'>&nbsp;&nbsp;<span class='STYLE1'>用户登录</span></td>        <td width='6%'><img src='../image/未命名-1.gif' width='9' height='9' onclick='closeWindow();'/></td>      </tr>    </table></td>  </tr>  <tr>    <td height='90' valign='bottom'><table width='100%' height='70' border='0' cellspacing='0'>      <tr>        <td width='26%' align='right'><span class='STYLE2'>用户名：</span></td>        <td width='45%'>          <input id='Text1' type='text'/></td>        <td width='29%' class='STYLE3'><a href='../../reg/reg.html'>新用户注册</a></td>      </tr>      <tr>        <td width='26%' align='right'><span class='STYLE2'>密&nbsp;&nbsp;码：</span></td>        <td width='45%'><input name='password' type='password' id='Password1'/></td>        <td width='29%' class='STYLE3'><a href='../../reg/Get_Pwd.aspx'>忘记密码？</a></td>      </tr>    </table></td>  </tr>  <tr>    <td height='25' align='center'><input id='RadioButtonList1_0' type='radio' name='RadioButtonList1' value='0'/><label for='RadioButtonList1_0'>个人用户</label><input id='RadioButtonList1_1' type='radio' name='RadioButtonList1' value='1' /><label for='RadioButtonList1_1'>企业用户</label><input id='RadioButtonList1_2' type='radio' name='RadioButtonList1' value='2' checked='checked' /><label for='RadioButtonList1_2'>高校用户</label></td>  </tr>  <tr>    <td height='60' align='center'><img src='../image/login.00jpg_r2_c2.jpg' width='100' height='33' onclick='validatelogon()' /></td>  </tr>  <tr>    <td height='27' align='right' class='STYLE3' style=' background-color:#F3F9FD'><a href='../../Default.aspx'>学程网首页</a>&gt;&gt; &nbsp;&nbsp;&nbsp;</td>  </tr></table></div>"; 
//showMessageBox('用户登录',messContent,objPos,350);
//}

function testMessageBox(ev) {
    var objPos = mousePosition(ev);
    messContent = "<div style='padding:20px 0 20px 0;text-align:center;'><table width='458' height='270' align='center' cellspacing='0' style='border:4px solid #26B8F1; background-color:White;'>  <tr>    <td height='30' style=' background:url(seschool/image/login_r2_c2.jpg) no-repeat 1px 1px;'><table width='100%' height='100%' border='0' cellspacing='0'>      <tr>        <td width='94%' align='left'>&nbsp;&nbsp;<span class='STYLE1'>用户登录</span></td>        <td width='6%'><img src='seschool/image/未命名-1.gif' alt='关闭' style='cursor:pointer;' width='9' height='9' onclick='closeWindow();'/></td>      </tr>    </table></td>  </tr>  <tr>    <td height='90' valign='bottom'><table width='100%' height='70' border='0' cellspacing='0'>      <tr>        <td width='26%' align='right'><span class='STYLE2'>用户名：</span></td>        <td width='45%'>          <input id='Text1' type='text'/></td>        <td width='29%' class='STYLE3'><a href='reg/reg.html'>新用户注册</a></td>      </tr>      <tr>        <td width='26%' align='right'><span class='STYLE2'>密&nbsp;&nbsp;码：</span></td>        <td width='45%'><input name='password' type='password' id='Password1' style='width=150px;'/></td>        <td width='29%' class='STYLE3'><a href='reg/Get_Pwd.aspx'>忘记密码？</a></td>      </tr>    </table></td>  </tr>  <tr>    <td height='25' align='center'><input id='RadioButtonList1_0' type='radio' name='RadioButtonList1' value='0' checked='checked' /><label for='RadioButtonList1_0'>个人用户</label><input id='RadioButtonList1_1' type='radio' name='RadioButtonList1' value='1'  /><label for='RadioButtonList1_1'>企业用户</label><input id='RadioButtonList1_2' type='radio' name='RadioButtonList1' value='2' /><label for='RadioButtonList1_2'>高校用户</label></td>  </tr>  <tr>    <td height='60' align='center'><img id='login' src='seschool/image/login.00jpg_r2_c2.jpg' width='100' height='33' style='cursor:pointer;' alt='登陆' onclick='validatelogon()' /></td>  </tr>  <tr>    <td height='27' align='right' class='STYLE3' style=' background-color:#F3F9FD'><a href='Default.aspx'>学程网首页</a>&gt;&gt; &nbsp;&nbsp;&nbsp;</td>  </tr></table></div>";
    showMessageBox('用户登录', messContent, objPos, 350);
    document.getElementById("Text1").focus();
}

function validatelogon() {
    var loginname = document.getElementById("Text1").value;
    var password = document.getElementById("Password1").value;

    if (loginname == "") {
        alert("请输入用户名！");
        document.getElementById("Text1").focus();
        return false;
    }
    if (password == "") {
        alert("请输入密码！");
        document.getElementById("Password1").focus();
        return false;
    }

    $.post("seschool/view/i_login.aspx", { name: $("#Text1").val(), pwd: $("#Password1").val(), type: $("input[type='radio'][checked]").val() }, function(data) {
        if (data == "") {
            alert('用户名或密码错误，请重新登录！');
            document.getElementById("Text1").value = "";
            document.getElementById("Password1").value = "";
            document.getElementById("Text1").focus();
        }

        else {
            if ($("input[type='radio'][checked]").val() == "0") {
                location.href = "person/per_Character.aspx";
            }
            else {
                alert("对不起，该功能只对个人用户开放！");
            }
        }
    });

}