//檢測用戶名是否被占用
function GetO(){
var AJax=false;
try {
AJax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
AJax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
AJax = false;
}
}
if (!AJax && typeof XMLHttpRequest!='undefined') {
AJax = new XMLHttpRequest();
}
return AJax;
}
function getResult(serverPage) {
var AJax = GetO();
var sep = (-1 < serverPage.indexOf("?")) ? "&" : "?"
var newurl = serverPage + sep + "__=" + encodeURIComponent((new Date()).toString());
AJax.open("GET", newurl, true);
AJax.onreadystatechange = function() {
if (ajax.readyState == 4 && AJax.status == 200) {
if(AJax.responseText==1){
ShowResult(1,"您的用戶名可以正常注冊")
AJaxResult=true;
}else{
ShowResult(0,"您的用戶名被占用了")
AJaxResult=false;
}
}
}
AJax.send(null);
}
function chkUsername(){
var sflag;//標記;
var sErr;//錯誤信息;
sflag=true;
var re=/^\w{2,20}$/;
if(!re.test(document.Form1.UserName.value)){
sflag=false;
sErr="用戶名只能輸入字母、數字或下劃線";
}
if (document.Form1.UserName.value.length>20||document.Form1.UserName.value.length<2){
sflag=false;
sErr="用戶名長度必須在2~20個字符之間";
}
if (document.Form1.UserName.value=="" ){
sErr="用戶名不能為空";
sflag=false;
}
//AJax檢測返回結果
if (!sflag) {
ShowResult(0,sErr)
}else{
getResult("../MemberCheck.ASPx?t=1&Name=" + document.Form1.UserName.value);
}
//document.getElementById("spname").innerHtml=ss;
}
function ShowResult(tag,str){
var obj = document.getElementById("spname");
if(tag==0){
obj.style.border="1px solid red";
obj.style.color="red";
}else{
obj.style.border="1px solid green";
obj.style.color="green";
}
obj.innerHtml=str;
obj.style.padding="1px";
}
//取AJax返回的用戶問題值
function getQuestionData(sPage){
var AJax = GetO();
var sep = (-1 < sPage.indexOf("?")) ? "&" : "?"
var newurl = sPage + sep + "__=" + encodeURIComponent((new Date()).toString());
AJax.open("GET", newurl, true);
AJax.onreadystatechange = function() {
if (ajax.readyState == 4 && AJax.status == 200) {
if(AJax.responseText==""){
document.getElementById("getstate").innerHtml="用戶不存在!"
}
else{
document.g.Question.value=AJax.responseText;
document.g.Question.readOnly=true;
document.getElementById("getpwdstep1").style.display="none";
document.getElementById("getpwdstep2").style.display="block";
document.getElementById("getstate").innerHtml="";
}
}
}
AJax.send(null);
}
function getUserQ(){
//改變報錯span的顯示樣式
document.getElementById("getstate").style.padding="1px 4px";
if (document.g.UserName.value==""){
document.getElementById("getstate").innerHtml="用戶名不能為空!"
}else{
document.getElementById("getstate").style.background="red";
document.getElementById("getstate").style.color="white";
document.getElementById("getstate").innerHtml="正在加載數據...";
//設置AJax
getQuestionData("../MemberCheck.ASPx?t=2&gName=" + document.g.UserName.value);
}
}
function login(n,p,t)
{
if(t==false){
document.getElementById("pLogin").style.display="none";
document.getElementById("LoginInfo").innerHtml="正在幫您登錄,請稍等...";
}
var request;
if(undefined == request){
request = new Request();
}
if(undefined == request._get){
//不支持AJax獲取數據;
if(t==false){
document.getElementById("pLogin").style.display="";
document.getElementById("LoginInfo").innerHtml="不能獲取數據";
}
}
else{
userName=n;
toPrev=t;
request.GetNoCache(loginPath + "LoginCheck.ASPx" + "?n=" + n + "&p=" + p,loginCheck);
}
}
function loginCheck(result)
{
if (result.readyState!=ReadyState.Complete)
return;
//成功獲取;
if (result.status==HttpStatus.OK && result.responseText != "")
{
//執行返回的語句;
//alert(result.responseText);
if (result.responseText=='1')
{
if(toPrev ==false){
document.getElementById("LoginInfo").innerHtml='<ul><li>歡迎' + userName + '</li><li><a href="' + loginPath + 'member/">管理</a></li><li><a href="' + loginPath + 'Logout.ASPx">退出</a></li></ul>';
}
else{
if(UrlPrev != ''){
document.location.href=UrlPrev;
}
else{
document.location.href=loginPath;
}
}
return;
}
else
{
if(document.location.href !="http://" + document.location.hostname + loginPath + "Member/Login.ASPx")
document.location.href=loginPath + "Member/Login.ASPx";
}
}
else
{
//失敗;
document.location.href=loginPath + "Member/Login.ASPx";
return;
}
}
function checkKey(caputureKey,n,p,t){
var key = window.event.keyCode;
if(key == caputureKey){
login(n,p,t);
}
}
function setLoginInfo(bLogin){
if(bLogin){
document.getElementById("LoginInfo").innerHtml='<ul><li>歡迎' + userName + '</li><li><a href="' + loginPath + 'member/">管理</a></li><li><a href="' + loginPath + 'Logout.ASPx">退出</a></li></ul>';
}
else{
}
}
function gotoUrl(s){
window.location.href=loginPath + 'Member/RegUser.Html';
}