// JScript 文件
//验证一些提交的文本框



//去左空格; 
function ltrim(s){ 
return s.replace( /^\s*/, ""); 
} 
//去右空格; 
function rtrim(s){ 
return s.replace( /\s*$/, ""); 
} 
//去左右空格; 
function trim(s){ 
return rtrim(ltrim(s)); 
}


//验证登陆时提交的密码和用户名
function validLogin()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("UserName").value).length == 0)
        {
            var T= false;
            msg = "请填写用户名";
        }
        else if(trim(document.getElementById("PassWord").value).length == 0)
        {
            var T= false;
            msg = "请填写密码";
        }
        else if(trim(document.getElementById("Valid").value).length == 0)
        {
            var T= false;
            msg = "请填写验证码";
        }
        else if(trim(document.getElementById("UserName").value).length < 3 || trim(document.getElementById("UserName").value).length > 12)
        {
            var T= false;
            msg = "用户名长度为3-12位";
        }
        else if(trim(document.getElementById("PassWord").value).length < 3 || trim(document.getElementById("PassWord").value).length > 12)
        {
            var T= false;
            msg = "密码长度为3-12位";
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch (e)
    {
    }
    
}

//验证注册用户
function validReg_New()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("RegUserName").value).length == 0)
        {
            var T= false;
            msg = "请填写用户名";
        }
        else if(trim(document.getElementById("RegPassWord").value).length == 0)
        {
            var T= false;
            msg = "请填写密码";
        }
        else if(trim(document.getElementById("RegUserName").value).length < 3 || trim(document.getElementById("RegUserName").value).length > 12)
        {
            var T= false;
            msg = "用户名长度为3-12位";
        }
        else if(trim(document.getElementById("RegPassWord").value).length < 3 || trim(document.getElementById("RegPassWord").value).length > 12)
        {
            var T= false;
            msg = "密码长度为3-12位";
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch(e)
    {
    }
}

//验证注册用户
function validReg()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("UserName").value).length == 0)
        {
            var T= false;
            msg = "请填写用户名";
        }
        else if(trim(document.getElementById("PassWord").value).length == 0)
        {
            var T= false;
            msg = "请填写密码";
        }
        else if(trim(document.getElementById("UserName").value).length < 3 || trim(document.getElementById("UserName").value).length > 12)
        {
            var T= false;
            msg = "用户名长度为3-12位";
        }
        else if(trim(document.getElementById("PassWord").value).length < 3 || trim(document.getElementById("PassWord").value).length > 12)
        {
            var T= false;
            msg = "密码长度为3-12位";
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch(e)
    {
    }
}

//验证密码修改
function validEditPass()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("PassWord1").value).length == 0)
        {
            var T= false;
            msg = "请填写旧密码";
        }
        else if(trim(document.getElementById("PassWord2").value).length == 0)
        {
            var T= false;
            msg = "请填写新密码";
        }
        else if(trim(document.getElementById("PassWord3").value).length == 0)
        {
            var T= false;
            msg = "请填写密码确认";
        }
        else if(trim(document.getElementById("PassWord1").value).length < 3 || trim(document.getElementById("PassWord1").value).length > 12)
        {
            var T= false;
            msg = "旧密码为3-12位";
        }
        else if(trim(document.getElementById("PassWord2").value).length < 3 || trim(document.getElementById("PassWord2").value).length > 12)
        {
            var T= false;
            msg = "新密码长度为3-12位";
        }
        else if(trim(document.getElementById("PassWord3").value).length < 3 || trim(document.getElementById("PassWord3").value).length > 12)
        {
            var T= false;
            msg = "密码确认长度为3-12位";
        }
        else if (document.getElementById("PassWord3").value != document.getElementById("PassWord2").value)
        {
           var T= false;
            msg = "密码和密码确认不一致"; 
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch (e)
    {
    }
}

//验证下单
function ValidOrder()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("RealName").value).length == 0)
        {
            var T= false;
            msg = "请填写姓名";
        }
        else  if(trim(document.getElementById("Address").value).length == 0)
        {
            var T= false;
            msg = "请填写地址";
        }
        else  if(trim(document.getElementById("Tel").value).length == 0)
        {
            var T= false;
            msg = "请填写电话";
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch (e)
    {
    }
}

//验证反馈
function ValidFeedback()
{
    try
    {
        var T = true;
        var msg;
        if(trim(document.getElementById("Title").value).length == 0)
        {
            var T= false;
            msg = "请填写标题";
        }
        if(T == false)
            alert(msg);
        return T;
    }
    catch (e)
    {
    }
}