﻿function isValidPassWord(PWD, sLength, toLength)
{
    if(PWD.toString().length >= sLength && PWD.toString().length <= toLength)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function isEmail(strEmail) 
{    
    if(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else    
        return false;
}

function isValidUserName(sUserName) 
{
    var valid = /^[a-zA-Z0-9_]{6,20}$/ 
    if (sUserName.search(valid) != -1)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function CheckExprSignUp(userName, pwd, email){
    
    if(!isValidUserName(userName)){
        return false;
    }
    if(!isValidPassWord(pwd, 6, 16)){
        return false;
    }
    if(!isEmail(email)){
        return false;
    }
}

function SubmitExprSignUp(){
    if(document.getElementById("txtExprPwdDummy")){
        return false;
    }

    var cesUserName = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprUserName").value;
    //var cesPwd = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprPwd").value;
    var cesPwd = document.getElementById("txtExprPwdReal").value;
    var cesEmail = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprEmail").value;
    
    if(cesUserName == "Pick a Login ID"){
        return false;
    }
    return CheckExprSignUp(cesUserName, cesPwd, cesEmail);
}

function InitExprSignUp(){
    var txtUserName = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprUserName");
    var txtPwd = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprPwd");
    var txtEmail = document.getElementById("ctl00_ContentPlaceHolder1_ExpressSignUp1_txtExprEmail");

    txtUserName.style.color = "gray";
    txtUserName.value = "Pick a Login ID";
    txtEmail.style.color = "gray";
    txtEmail.value = "Your email address";
    
    var td = txtPwd.parentNode;
    td.innerHTML = "<input id='txtExprPwdDummy' onfocus='PwdOnFocus(this.id)' type='text' class='td_02' value='Pick a password' style='color:gray' tabindex='2' />";
}

function PwdOnFocus(txtPwdID){
    var txtPwd = document.getElementById(txtPwdID);
    var td = txtPwd.parentNode;
    td.innerHTML = "<input id='txtExprPwdReal' name='txtExprPwdReal' onblur='PwdOnBlur(this.id)' type='password' class='td_02' maxlength='16' tabindex='2' />";
    document.getElementById("txtExprPwdReal").focus();
    document.getElementById("txtExprPwdReal").focus();//2个focus(),保证该文本框获得焦点
}

function PwdOnBlur(txtPwdID){
    var txtPwd = document.getElementById(txtPwdID);
    if(txtPwd.value == ""){
        var td = txtPwd.parentNode;
        td.innerHTML = "<input id='txtExprPwdDummy' onfocus='PwdOnFocus(this.id)' type='text' class='td_02' value='Pick a password' style='color:gray' tabindex='2' />";
    }
}

function UserNameOnBlur(txtUserNameID){
    var txtUserName = document.getElementById(txtUserNameID);
    if(txtUserName.value == "Pick a Login ID" || txtUserName.value == ""){
        txtUserName.style.color = "gray";
        txtUserName.value = "Pick a Login ID";
    }
}

function UserNameOnFocus(txtUserNameID){
    var txtUserName = document.getElementById(txtUserNameID);
    if(txtUserName.value == "Pick a Login ID" || txtUserName.value == ""){
        txtUserName.style.color = "black";
        txtUserName.value = "";
    }
}

function EmailOnBlur(txtEmailID){
    var txtEmail = document.getElementById(txtEmailID);
    if(txtEmail.value == "Your email address" || txtEmail.value == ""){
        txtEmail.style.color = "gray";
        txtEmail.value = "Your email address";
    }
}

function EmailOnFocus(txtEmailID){
    var txtEmail = document.getElementById(txtEmailID);
    if(txtEmail.value == "Your email address" || txtEmail.value == ""){
        txtEmail.style.color = "black";
        txtEmail.value = "";
    }
}
