﻿function CheckHeaderLogin(){
    var chlName = document.getElementById("txtHeaderLoginName").value;
    var chlPwd = document.getElementById("txtHeaderLoginPwd").value;
    var chlCode = document.getElementById("txtHeaderLoginCode").value;
    
//    var chlMsg = "";
//    
//    if(chlName == ""){
//        chlMsg = "- Please Enter Your Passport Account.\r";
//    }
//    if(chlPwd == ""){
//        chlMsg += "- Please Enter The Password.\r";
//    }
//    if(chlCode == ""){
//        chlMsg += "- Please Enter Authentication Code.";
//    }
    
//    if(chlMsg.length > 0){
//        alert(chlMsg);
//        return false;
//    }else{
//        return true;
//    }

    if(chlName == "" || chlPwd == "" || chlCode == ""){
        return false;
    }else{
        return true;
    }
}

function SubmitHeaderLogin(){
    if(CheckHeaderLogin()){
        document.getElementById("frmHeader").submit();
    }
}

function CheckPageLogin(){
    var cplName = document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").value;
    var cplPwd = document.getElementById("ctl00_ContentPlaceHolder1_txtPwd").value;
    var cplCode = document.getElementById("ctl00_ContentPlaceHolder1_txtCode").value;
    
    var cplMsg = document.getElementById("ctl00_ContentPlaceHolder1_lblMessage");
    cplMsg.innerText = "";
    
    if(cplName == ""){
        cplMsg.innerText = "Please Enter Your Passport Account.";
        return false;
    }
    if(cplPwd == ""){
        cplMsg.innerText = "Please Enter The Password.";
        return false;
    }
    if(cplCode == ""){
        cplMsg.innerText = "Please Enter Authentication Code.";
        return false;
    }
    
    return true;
}

function SubmitPageLogin(){
    return CheckPageLogin();
}
//以下——SG平台登录帐号后缀提示
function isFF(){
    return navigator.userAgent.indexOf("Firefox") != -1;
}

function CancelEnterSubmit(e){
    var key = window.event ? e.keyCode : e.which;
    if(key == 13){
        return false;
    }
}

var pressCount = 0;
var loginType = "c";

function GetKeyCode(e, lType){
    var divInput = document.getElementById("divInput");
    var txtInput = document.getElementById("ctl00_ContentPlaceHolder1_txtUserName");
    if (lType == "h") {
        txtInput = document.getElementById("txtHeaderLoginName");
        loginType = "h";
    } else {
        loginType = "c";
    }
    var tdSG = document.getElementById("tdSG");
    var tdNormal = document.getElementById("tdNormal");
    var top = txtInput.getBoundingClientRect().top + 20 + document.body.scrollTop;
    var height = txtInput.getBoundingClientRect().left + document.body.scrollLeft;
    divInput.style.top = top + "px";
    divInput.style.left = height + "px";
    var key = window.event ? e.keyCode : e.which;
    if(key != 37 && key != 38 && key != 39 && key != 40 && key != 13){
        if(txtInput.value != ""){
            divInput.style.display = "";
            if(isFF()){
                if(txtInput.value.lastIndexOf(".") == txtInput.value.length - 1){
                    tdSG.innerHTML = txtInput.value + "sg";
                }else if(txtInput.value.lastIndexOf(".s") == txtInput.value.length - 2 && txtInput.value.length > 1){
                    tdSG.innerHTML = txtInput.value + "g";
                }else if(txtInput.value.lastIndexOf(".sg") == txtInput.value.length - 3 && txtInput.value.length > 2){
                    ClearDIV();
                    GoToPwd();
                }else{
                    tdSG.innerHTML = txtInput.value + ".sg";
                }
                tdNormal.innerHTML = txtInput.value;
            }else{
                if(txtInput.value.lastIndexOf(".") == txtInput.value.length - 1){
                    tdSG.innerHTML = "<span style='font-weight:bold'>" + txtInput.value + "</span>sg";
                }else if(txtInput.value.lastIndexOf(".s") == txtInput.value.length - 2 && txtInput.value.length > 1){
                    tdSG.innerHTML = "<span style='font-weight:bold'>" + txtInput.value + "</span>g";
                }else if(txtInput.value.lastIndexOf(".sg") == txtInput.value.length - 3 && txtInput.value.length > 2){
                    ClearDIV();
                    GoToPwd();
                }else{
                    tdSG.innerHTML = "<span style='font-weight:bold'>" + txtInput.value + "</span>.sg";
                }
                tdNormal.innerHTML = "<span style='font-weight:bold'>" + txtInput.value + "</span>";
            }
        }else{
            tdSG.innerHTML = "";
            tdNormal.innerHTML = "";
            ClearDIV();
        }
    }
    if(key == 40){
        if(txtInput.value != ""){
            divInput.style.display = "";
            if(isFF()){
                pressCount++;
                UpDownForFF();
            }else{
                if(tdSG.style.backgroundColor == "white" && tdNormal.style.backgroundColor == "white"){
                    tdSG.style.backgroundColor = "#99836e";//"#ffcc00";
                    tdSG.style.color = "white";
                }else if(tdSG.style.backgroundColor == "#99836e"){
                    tdSG.style.backgroundColor = "white";
                    tdSG.style.color = "#572c0a";
                    tdNormal.style.backgroundColor = "#99836e";
                    tdNormal.style.color = "white";
                }else{
                    tdNormal.style.backgroundColor = "white";
                    tdNormal.style.color = "#572c0a";
                }
            }
        }
    }
    if(key == 38){
        if(txtInput.value != ""){
            divInput.style.display = "";
            if(isFF()){
                pressCount--;
                UpDownForFF();
            }else{
                if(tdSG.style.backgroundColor == "white" && tdNormal.style.backgroundColor == "white"){
                    tdNormal.style.backgroundColor = "#99836e";
                    tdNormal.style.color = "white";
                }else if(tdNormal.style.backgroundColor == "#99836e"){
                    tdNormal.style.backgroundColor = "white";
                    tdNormal.style.color = "#572c0a";
                    tdSG.style.backgroundColor = "#99836e";
                    tdSG.style.color = "white";
                }else{
                    tdSG.style.backgroundColor = "white";
                    tdSG.style.color = "#572c0a";
                }
            }
        }
    }
    if(key == 13){
        if(isFF()){
            if(pressCount == 1){
                txtInput.value = tdSG.innerHTML;
            }else if(pressCount == 2){
                txtInput.value = tdNormal.innerHTML;
            }
        }else{
            if(tdSG.style.backgroundColor == "#99836e"){
                txtInput.value = tdSG.innerText;
            }else if(tdNormal.style.backgroundColor == "#99836e"){
                txtInput.value = tdNormal.innerText;
            }
        }
        ClearDIV();
        GoToPwd();
    }
    if(key == 27){
        ClearDIV();
    }
}

function GetDivValue(obj){
    var divInput = document.getElementById("divInput");
    var txtInput = document.getElementById("ctl00_ContentPlaceHolder1_txtUserName");
    if (loginType == "h") {
        txtInput = document.getElementById("txtHeaderLoginName");
    }
    if(isFF()){
        txtInput.value = obj.innerHTML;
    }else{
        txtInput.value = obj.innerText;
    }
    ClearDIV();
    GoToPwd();
}

var tdID = "";

function SetTdBgColor(objParent, type){
    var obj = objParent.getElementsByTagName("td")[0];
    if(type == 1){
        obj.style.backgroundColor = "#99836e";
        obj.style.color = "white";
        tdID = obj.id;
    }else{
        obj.style.backgroundColor = "white";
        obj.style.color = "#572c0a";
        tdID = "";
    }
}

function HiddenDivInput(){
    var divInput = document.getElementById("divInput");
    var txtInput = document.getElementById("ctl00_ContentPlaceHolder1_txtUserName");
    if (loginType == "h") {
        txtInput = document.getElementById("txtHeaderLoginName");
    }
    if(isFF()){
        if(tdID != ""){
            var td = document.getElementById(tdID);
            txtInput.value = td.innerHTML;
        }
    }else{
        var tdSG = document.getElementById("tdSG");
        var tdNormal = document.getElementById("tdNormal");
        if(tdSG.style.backgroundColor == "#99836e"){
            txtInput.value = tdSG.innerText;
        }else if(tdNormal.style.backgroundColor == "#99836e"){
            txtInput.value = tdNormal.innerText;
        }
    }
    ClearDIV();
    GoToPwd();
}

function GoToPwd() {
    if (loginType == "h") {
        if (document.getElementById("txtHeaderLoginName").value != "") {
            document.getElementById("txtHeaderLoginPwd").focus();
        }
    } else {
        if (document.getElementById("ctl00_ContentPlaceHolder1_txtUserName").value != "") {
            document.getElementById("ctl00_ContentPlaceHolder1_txtPwd").focus();
        }
    }
}

function UpDownForFF(){
    var tdSG = document.getElementById("tdSG");
    var tdNormal = document.getElementById("tdNormal");
    if(pressCount == 1){
        tdSG.style.backgroundColor = "#99836e";
        tdSG.style.color = "white";
        tdNormal.style.backgroundColor = "white";
        tdNormal.style.color = "#572c0a";
    }else if(pressCount == 2){
        tdSG.style.backgroundColor = "white";
        tdSG.style.color = "#572c0a";
        tdNormal.style.backgroundColor = "#99836e";
        tdNormal.style.color = "white";
    }else if(pressCount == -1){
        pressCount = 2;
        tdSG.style.backgroundColor = "white";
        tdSG.style.color = "#572c0a";
        tdNormal.style.backgroundColor = "#99836e";
        tdNormal.style.color = "white";
    }else{
        pressCount = 0;
        tdSG.style.backgroundColor = "white";
        tdSG.style.color = "#572c0a";
        tdNormal.style.backgroundColor = "white";
        tdNormal.style.color = "#572c0a";
    }
}

function ClearDIV(){
    var divInput = document.getElementById("divInput");
    var tdSG = document.getElementById("tdSG");
    var tdNormal = document.getElementById("tdNormal");
    tdSG.style.backgroundColor = "white";
    tdSG.style.color = "#572c0a";
    tdNormal.style.backgroundColor = "white";
    tdNormal.style.color = "#572c0a";
    divInput.style.display = "none";
    pressCount = 0;
}
//以上——SG平台登录帐号后缀提示