﻿function createString(){
    var name = encodeURI($("#TxtName").val());
    var pwd = encodeURI($("#TxtPwd").val());
    var code = encodeURI($("#TxtCode").val());
    var str = {name:name,pwd:pwd,code:code};
    return str;
}

function doRequest(){
    var cookieEnabled = (navigator.cookieEnabled) ? true : false;
    if (!cookieEnabled) {
      alert("请开启浏览器COOKIE功能！");
      return;
    }
    if($("#TxtName").val()==""||$("#TxtPwd").val()=="")
        window.open('/SignIn/StudentLogin.aspx');
    else{
        $.get("/SignIn/Login.aspx",createString(),function(data){
            if(decodeURI(data) == "0")
            {
                $("#errorDIV").html("登陆失败！");
                $("#errorDIV").show();
                getnewcode('imgverify');
            }
            else if(decodeURI(data) == "-1")
            {
                $("#errorDIV").html("验证码错误！");
                $("#errorDIV").show();
                getnewcode('imgverify');
            }
            else
            {
                $("#loginDIV").hide();
                $("#welcomeDIV").show();
                $("#lblName").html(decodeURI(data));
            }
        });
    }
}

function bookmark(){
    var title=document.title
    var url=document.location.href
    if (window.sidebar) 
        window.sidebar.addPanel(title, url,"");
    else if( window.opera && window.print ){
        var mbm = document.createElement('a');
        mbm.setAttribute('rel','sidebar');
        mbm.setAttribute('href',url);
        mbm.setAttribute('title',title);
        mbm.click();
    }
    else if( document.all ) 
        window.external.AddFavorite( url, title);
}

function doRegister(){
    window.open('/SignIn/Register.aspx');
}

function doFindPwd(){
    window.open('/SignIn/StudentLogin.aspx');
}

function doQuit(){
    location.href="SignIn/Quit.aspx";
}

function doUser(){
    window.open('/Student/index.aspx');
}

function doST(){
    window.open('/LyricsCenter/index.aspx');
}

function doBM(){
    window.open('/SignIn/OnlineRegister1.aspx');
}

function doFF(){
    //window.open('/User/index.aspx');
}

function doSearch(){
    if(document.getElementById("TxtSearch").value.length <= 0)
        alert("请输入要搜索的关键词");
    else
    {
        var id = "";
        var x=document.getElementsByName("rd");
        if(x.length > 0)
        {
            for(var i=0; i<x.length; i++)
            {
                if(x[i].checked)
                {
                    id = x[i].value;
                    break;
                }
            }
        }
        var url = "";
        if(id == "1")
            url = "/News/SearchPage.aspx?str="+escape(document.getElementById("TxtSearch").value);
        if(id == "2")
            url = "/JobInfo/SearchPage.aspx?str="+escape(document.getElementById("TxtSearch").value);
        if(id == "3")
            url = "/Course/SearchPage.aspx?str="+escape(document.getElementById("TxtSearch").value);
        window.open(url);
    }
}

function SearchGetFouce(){
    if(document.getElementById("TxtSearch").value == "请输入关键词"){
        document.getElementById("TxtSearch").value = "";
    }
}

function getnewcode(Id){
    document.getElementById(Id).src="SignIn/CodePage.aspx?t="+(new Date()).getTime();//随机数保证验证码不缓存
}

function selectTag(showContent,selfObj){
	// 标签
	var tag = document.getElementById("pagetags").getElementsByTagName("li");
	var taglength = tag.length;
	for(i=0; i<taglength; i++){
	tag[i].className = "";
	}
	selfObj.parentNode.className = "selectTag";
	// 标签内容
	for(i=0; j=document.getElementById("tagContent"+i); i++){
	j.style.display = "none";
	}
	document.getElementById(showContent).style.display = "block";
}

function ClearError()
{
    $("#errorDIV").html("");
    $("#errorDIV").hide();
}

$(document).ready(function()
{
    $.get("/SignIn/CheckLogin.aspx","",
         function(data)
          {
            if(decodeURI(data)!="NO"){
                $("#loginDIV").hide();
                $("#welcomeDIV").show();
                $("#lblName").html(decodeURI(data));
            }else
            {
                $("#welcomeDIV").hide();
                $("#loginDIV").show();
            }
          });
})
