﻿//根据ID获取对象
function ID$(al) {
    if (document.getElementById) {
        return eval('document.getElementById("' + al + '")');
    } else if (document.layers) {
        return eval("document.layers['" + al + "']");
    } else {
        return eval('document.all.' + al);
    }
}

TagsOpr = function(obj, txt, display) {
    obj.title = txt;
}

//用户名输入框移开的时候调用的事件
function CheckUserNameFunc(type) {
    var input = ID$(type == "default" ? "UserName" : "UserName1");
    //验证
    if ('' == input.value) {
        TagsOpr(input, "用户名不能为空", "block");
        return false;
    } else if (4 > input.value.length || 50 < input.value.length) {
    TagsOpr(input, "用户名长度应在4-50间", "block");
        return false;
    }
    if (ID$("ca1").className == "cula1") {
        loginYanZheng(input.value); //用户名验证 调用ajaxpage的代码
    } else {
        emailValidate(input.value, input);
    }
    TagsOpr(input, '', "none");
    return true;
}

//密码输入框移开的时候调用的事件
function checkpwd(type) {
    var pwd = ID$(type == "default" ? 'UserPwd' : 'UserPwd1');
    //设置输出信息
    var msg="";

    //验证
    if (pwd.value == '') {
        msg = "密码不能为空";
    } else if (pwd.value.length < 6) {
        msg = "密码长度不能少于6位";
    } else if (pwd.value.length > 16) {
        msg = "密码长度不能超过16位";
    }
    if (msg.length > 0) {
        return false;
    }
    return true;
}

String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
} 

//移入用户输入框的时候调用的事件
function userfocus() {
    var error = ID$("guestAccountError");
    error.className = "tips";
    TagsOpr(error, "请输入用户名字", "block");
    userfocusbool = false;
}
//移入密码输入框的时候调用的事件
function pwdfocus() {
    var error = ID$("guestPwdError");
    TagsOpr(error, "请输入用户密码", "block");
    error.className = "tips";
    pwdfocusbool = false;
}
//登录调用的事件
function ok(type) {
    if (CheckUserNameFunc(type) && checkpwd(type)) {
        var input = ID$(type == "default" ? "UserName" : "UserName1"); //调用ajax验证用户是否可用
        loginYanZheng(input.value);
        document.forms[0].action += "&url=" + document.referrer;
        return true;
    }
    pwdfocusbool = userfocusbool = false;
    return false;
}