﻿function GetElem(id){return document.getElementById(id);}
function RequestLogin(m_vercode)
{
    if(GetElem('txtNickName').value=='' || GetElem('txtPwd').value=='')
    {
        alert('请填写用户名和密码！');
        return false;
    }
        GetElem('loginstate2').style.display='none';
    GetElem('loginstate3').style.display='';
    GetElem('nickname').innerHTML=GetElem('txtNickName').value;
    
    RequestLoginCommon(GetElem('txtNickName').value,GetElem('txtPwd').value,m_vercode,DispIsExistUser)

    return false;
}
function DispIsExistUser()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            if(xmlHttp.responseText=='0')
            {
                //window.location.href='/Index.shtml';
                GetElem('loginstate3').style.display='none';
                GetElem('loginstate1').style.display='';
                return;
            }
            else if(xmlHttp.responseText=='8')
            {
                window.alert('用户名或密码错误！');
            }
            else if(xmlHttp.responseText=='7')
            {
                window.alert('用户不存在！');
            }
           else if(xmlHttp.responseText=='4')
            {
                 window.alert('验证码错误，请核对后重新输入！');
            }    
            else
            {
                window.alert('异常错误，请联系本站客服！');
            }
            GetElem('loginstate2').style.display='';
            GetElem('loginstate1').style.display='none';
            GetElem('loginstate3').style.display='none';
            vercodex='1111';
        }
        else
        {
            location.replace("index.html");//此为临时使用，正常的为下面一句
            //alert('检测账号时发生错误！');
        }
    }
}
function SetTextSytle(id,InitValue)
{
    if(GetElem(id).value==InitValue)
    {
        GetElem(id).value='';
    }
    GetElem(id).style.color="black";
}
//推荐
function tuijian(title)
{
    var content='';
    var head='在神农网(www.shennong.com)上找到的信息：';
    var url=window.location.href;
    content+= head;
    content+=url;
    window.clipboardData.setData("Text",content);
    alert("此信息已经复制到剪贴板，\n赶快共享给你QQ、MSN和其它商业伙伴吧！: )");
}
//收藏
function shoucang(sURL, sTitle)
{
    //sTitle=='' ? sTitle='http://www.shennong.com/' : sTitle=sTitle ;
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}
//设为首页
function SetHome(obj,vrl){
try{
        obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
}
catch(e){
        if(window.netscape) {
                try {
                        netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                } 
                catch (e) { 
                        alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); 
                }
                var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
                prefs.setCharPref('browser.startup.homepage',vrl);
         }
}
}

function RequestLoginCommon(nickname,pwd,vercode,callback)
{
    createXMLHttpRequest();
    xmlHttp.onreadystatechange=callback;
    xmlHttp.open("GET",'/AjaxRequest/RequestLogin.aspx?UserID='+encodeURI(nickname)+'&Pwd='+encodeURI(pwd)+'&VerCode='+encodeURI(vercode),true);
    xmlHttp.setRequestHeader("If-Modified-Since","0");  
    xmlHttp.send(null);
    
    return false;
}

function HTMLEncode(html)
{
var temp = document.createElement ("div");
(temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
var output = temp.innerHTML;
temp = null;
return output;
}

function HTMLDecode(text)
{
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}



