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



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


//验证登陆时提交的密码和用户名
function validLogin()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("UserName").value).length == 0)
    {
        var T= false;
        msg = "Enter the ID";
    }
    else if(trim(document.getElementById("PassWord").value).length == 0)
    {
        var T= false;
        msg = "Enter the PassWord";
    }
    else if(trim(document.getElementById("Valid").value).length == 0)
    {
        var T= false;
        msg = "Enter the code shown";
    }
    else if(trim(document.getElementById("UserName").value).length < 3 || trim(document.getElementById("UserName").value).length > 12)
    {
        var T= false;
        msg = "the ID Length: 3-12";
    }
    else if(trim(document.getElementById("PassWord").value).length < 3 || trim(document.getElementById("PassWord").value).length > 12)
    {
        var T= false;
        msg = "the PassWord Length: 3-12";
    }
    if(T == false)
        alert(msg);
    return T;
}

//验证注册用户
function validReg_New()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("RegUserName").value).length == 0)
    {
        var T= false;
        msg = "Enter the ID";
    }
    else if(trim(document.getElementById("RegPassWord").value).length == 0)
    {
        var T= false;
        msg = "Enter the PassWord";
    }
    else if(trim(document.getElementById("RegUserName").value).length < 3 || trim(document.getElementById("RegUserName").value).length > 12)
    {
        var T= false;
        msg = "the ID Length: 3-12";
    }
    else if(trim(document.getElementById("RegPassWord").value).length < 3 || trim(document.getElementById("RegPassWord").value).length > 12)
    {
        var T= false;
        msg = "the PassWord Length: 3-12";
    }
    if(T == false)
        alert(msg);
    return T;
}

//验证注册用户
function validReg()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("UserName").value).length == 0)
    {
        var T= false;
        msg = "Enter the ID";
    }
    else if(trim(document.getElementById("PassWord").value).length == 0)
    {
        var T= false;
        msg = "Enter the PassWord";
    }
    else if(trim(document.getElementById("UserName").value).length < 3 || trim(document.getElementById("UserName").value).length > 12)
    {
        var T= false;
        msg = "the ID Length: 3-12";
    }
    else if(trim(document.getElementById("PassWord").value).length < 3 || trim(document.getElementById("PassWord").value).length > 12)
    {
        var T= false;
        msg = "the PassWord Length: 3-12";
    }
    if(T == false)
        alert(msg);
    return T;
}

//验证密码修改
function validEditPass()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("PassWord1").value).length == 0)
    {
        var T= false;
        msg = "Enter the Old PassWord";
    }
    else if(trim(document.getElementById("PassWord2").value).length == 0)
    {
        var T= false;
        msg = "Enter the New PassWord";
    }
    else if(trim(document.getElementById("PassWord3").value).length == 0)
    {
        var T= false;
        msg = "Enter the New PassWord again";
    }
    else if(trim(document.getElementById("PassWord1").value).length < 3 || trim(document.getElementById("PassWord1").value).length > 12)
    {
        var T= false;
        msg = "the Old PassWord Length: 3-12";
    }
    else if(trim(document.getElementById("PassWord2").value).length < 3 || trim(document.getElementById("PassWord2").value).length > 12)
    {
        var T= false;
        msg = "the New PassWord Length: 3-12";
    }
    else if(trim(document.getElementById("PassWord3").value).length < 3 || trim(document.getElementById("PassWord3").value).length > 12)
    {
        var T= false;
        msg = "the again PassWord Length: 3-12";
    }
    else if (document.getElementById("PassWord3").value != document.getElementById("PassWord2").value)
    {
       var T= false;
        msg = "the two passwords can't match"; 
    }
    if(T == false)
        alert(msg);
    return T;
}

//验证下单
function ValidOrder()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("RealName").value).length == 0)
    {
        var T= false;
        msg = "please fill in your name";
    }
    else  if(trim(document.getElementById("Address").value).length == 0)
    {
        var T= false;
        msg = "please fill in the address";
    }
    else  if(trim(document.getElementById("Tel").value).length == 0)
    {
        var T= false;
        msg = "please fill in the telephone no.";
    }
    if(T == false)
        alert(msg);
    return T;
}

//验证反馈
function ValidFeedback()
{
    var T = true;
    var msg;
    if(trim(document.getElementById("Title").value).length == 0)
    {
        var T= false;
        msg = "please fill in the title";
    }
    if(T == false)
        alert(msg);
    return T;
}