﻿var $j = jQuery.noConflict();
var FirstKingoryTime = null;
var yyyy = null;
var MM = null;
var DD = null;
var HH = null;
var minites = null;
var Second = null;

function SetFirstKingoryTime(year, month, day, hourse, minite, ss) {
    FirstKingoryTime = new Date(year, parseInt(month) - 1, day, hourse, minite);
    yyyy = parseInt(year);
    MM = parseInt(month);
    DD = parseInt(day);
    HH = parseInt(hourse);
    minites = parseInt(minite);
    Second = parseInt(ss);
    setInterval(function() { SetTimeChange(); }, 1000);
}
function SetTimeChange() {
    Second++;
    if (parseInt(Second) < 60) {
        ShowKingoryTime();
    }
    else {
        Second = 0;
        GetKingoryTime();
    }
}
function GetKingoryTime() {
    minites++;
    if (parseInt(minites) == 60) {
        minites = 0;
        HH++;
        if (parseInt(HH) == 24) {
            HH = 0;
            DD++;
            var monthdays = CheckYear(parseInt(yyyy), parseInt(MM));
            if (parseInt(DD) > monthdays) {
                DD = 1;
                MM++;
                if (parseInt(MM) > 12) {
                    MM = 1;
                    yyyy++;
                }
            }
        }
    }
    ShowKingoryTime();
}

function ShowKingoryTime() {
    var kMM, kDD, kHH, kminites, ksecond;
    if (parseInt(Second) < 10) { ksecond = "0" + parseInt(Second).toString(); }
    else { ksecond = parseInt(Second).toString(); }
    if (parseInt(minites) < 10) { kminites = "0" + parseInt(minites).toString(); }
    else { kminites = parseInt(minites).toString(); }
    if (parseInt(HH) < 10) { kHH = "0" + parseInt(HH).toString(); }
    else { kHH = parseInt(HH).toString(); }
    if (parseInt(DD) < 10) { kDD = "0" + parseInt(DD).toString(); }
    else { kDD = parseInt(DD).toString(); }
    if (parseInt(MM) < 10) { kMM = "0" + parseInt(MM).toString(); }
    else { kMM = parseInt(MM).toString(); }
    if (parseInt(Second) == 0 && parseInt(minites) == 0 && parseInt(HH) == 0) {
        $j("#server_clock").html("" + GetEnglishMonth(kMM) + "-" + kDD + "-" + yyyy + "");
        $j("#zoom_time").html("00:00:00AM");
    }
    else {
        var AMOrPM = "AM";
        if (parseInt(HH) > 12) {
            AMOrPM = "PM";
        }
        $j("#zoom_time").html("" + kHH + ":" + kminites + ":" + ksecond + "" + AMOrPM + "");
    }
    //$j("#lastlogintimeInfo").html("" + kMM + "-" + kDD + "-" + yyyy + " " + kHH + ":" + kminites + ":" + ksecond + "(Kingory Time,GMT -8)");
}
//判断该月天数(y:年,m：月)
function CheckYear(y, m) {
    var days
    if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
        days = 31;
    } else if (m == 4 || m == 6 || m == 9 || m == 11) {
        days = 30;
    } else {
        days = (y % 4 == 0) ? 29 : 28;
    }
    return days;
}

function GetEnglishMonth(index) {
    var MonthName = index;
    switch (parseInt(index)) {
        case 1: MonthName = "Jan"; break;
        case 2: MonthName = "Feb"; break;
        case 3: MonthName = "Mar"; break;
        case 4: MonthName = "Apr"; break;
        case 5: MonthName = "May"; break;
        case 6: MonthName = "Jun"; break;
        case 7: MonthName = "Jul"; break;
        case 8: MonthName = "Aug"; break;
        case 9: MonthName = "Sept"; break;
        case 10: MonthName = "Oct"; break;
        case 11: MonthName = "Nov"; break;
        case 12: MonthName = "Dec"; break;
    }
    return MonthName;
}

//上一次校验时帐号文本框值
var current_account_name_old = "";
var regist_page = { Version: '1.0.0.0' };
regist_page.Page = Class.create({
    initialize: function(userName_id, password_id, password1_id, email_id, _accountInfo, btn_id, agreeID) {
        this.userName = $(userName_id);
        this.password = $(password_id);
        this.password1 = $(password1_id);
        this.eMail = $(email_id);
        this.btn = $(btn_id);
        this.accountInfo = $(_accountInfo);
        this.agree = $(agreeID);
        this.validate = new passportValidate.Page();
        this.Page_Validateor = true;
    },
    showMsg: function(str, account) {
        this.password.value = "";
        this.password1.value = "";

        load = function() {
            alert(str);
        }
        if (document.all) {
            window.attachEvent('onload', load)
        }
        else {
            window.addEventListener('load', load, false);
        }
    },
    set_btn_event: function(page_obj) {
        //通过ajax验证UserName
        this.userName.onblur = function() {
            current_account_name_old = page_obj.userName.value;
            if ($j.trim(current_account_name_old) != "") {
                var result = page_obj.validate.validateEmail(page_obj.userName.value);
                if (result != true) {
                    Show('rimind4');
                    page_obj.accountInfo.innerHTML = "<i>" + result + "</i>";
                }
                else {
                    KingoryWebSite1_0_1.Register.CheckUserNameIsExist(page_obj.userName.value, page_obj.validateUserNameIsExistCallBack);
                }
            }
            else {
                Hide('rimind4');
            }
        };
        this.btn.onclick = function() { return page_obj.submit_check(); };
    },
    //提交验证
    submit_check: function() {
        this.Page_Validateor = true;
        //this.validateUserName();
        this.validateEmail();
        this.validatePassword();
        this.validatePasswordConfirm();

        this.validateProtocol();
        if (this.Page_Validateor)
            this.btn.onclick = function() { return false; };

        return this.Page_Validateor;
    },
    //显示错误并返回this.Page_Validateor
    //Control相关控件 IsRight是否正确  Msg消息 
    ShowCheckControlResult: function(Control, IsRight, Msg) {
        if (this.Page_Validateor && !IsRight) { this.Page_Validateor = false; alert(Msg); Control.focus(); }
    },
    //验证用户名
    validateUserName: function() {
        if (this.Page_Validateor && $j.trim(this.userName.value) != "") {
            var result = this.validate.validateEmail(this.userName.value);
            if (result != true) { this.ShowCheckControlResult(this.userName, false, result); }
        }
        return this.Page_Validateor;
    },
    //验证UserName后CallBack
    validateUserNameIsExistCallBack: function(data) {
        if (data != null) { if (data.value != null) { if (data.value != "0") { Show('rimind4'); } registpage.accountInfo.innerHTML = data.value == "0" ? "<i>E-mail available.</i>" : "<i>E-mail already registered.</i>"; } }
    },
    //验证密码    
    validatePassword: function() {
        if (this.Page_Validateor) {
            var result = this.validate.checkPasssord(this.password.value, "Password");
            if (result != true) { this.ShowCheckControlResult(this.password, false, result); }
        }
    },
    //验证确认密码 
    validatePasswordConfirm: function() {
        if (this.Page_Validateor) {
            var result = "Password inconsistent!";
            if (this.password1.value != this.password.value) { this.ShowCheckControlResult(this.password1, false, result); }
        }
    },
    //验证电子邮件
    validateEmail: function() {
        if (this.Page_Validateor) {
            var result = this.validate.validateEmail(this.eMail.value);
            if (result != true) { this.ShowCheckControlResult(this.eMail, false, result); }
        }
    },
    validateEmailPage: function() {
        if (this.Page_Validateor && $j.trim(this.eMail.value) != "") {
            var result = this.validate.validateEmail(this.eMail.value);
            if (result != true) { Show('rimind4'); $('rimind4').innerHTML = "<i>Invalid E-mail address.</i>"; }
            else {
                $('rimind4').innerHTML = "<i>Valid E-mail address.</i>";
                Hide('rimind4');
            }
        }
        else {
            Hide('rimind4');
        }
    },
    //验证 验证码
    validateRandomCode: function() {
        if (this.Page_Validateor) {
            result = "Input the Code.";
            if (this.code.value.length == 0) {
                this.ShowCheckControlResult(this.code, false, result);
            }
        }
        return this.Page_Validateor;
    },
    validateProtocol: function() {
        if (this.Page_Validateor) {
            var result = this.agree.checked;
            if (result != true) { this.ShowCheckControlResult(this.agree, false, "You must agree to Kingory's user agreement first."); }
        }
    },
    change_code: function() {
        this.img_code.click();
    },
    ///初始化flash
    StartFlash: function(picspath, piclinks, gameurl) {
        var pics, links;
        if (picspath == "" || picspath == null) {
            pics = "swf/3.png|swf/2.png|swf/1.png";
        }
        else {
            pics = picspath;
        }
        if (piclinks == null || piclinks == "") {
            links = "javascript:void(0);|javascript:void(0);|javascript:void(0);";
        }
        else {
            links = piclinks;
        }
        swfobject.embedSWF("swf/newFocus.swf", "mainbanner", "608", "667", "9.0.0", "swf/expressInstall.swf", { pics: pics, links: links, speed: 5 }, { menu: "false", wmode: "transparent" });
        swfobject.embedSWF("swf/kingoryLogo.swf", "logo", "340", "120", "9.0.0", "swf/expressInstall.swf", '', { menu: "false", wmode: "transparent" });
        swfobject.embedSWF("swf/start.swf", "startmenu", "226", "569", "9.0.0", "swf/expressInstall.swf", { webstart: gameurl, webhome: "http://kingory.gameol.com/index.html", webforum: "http://bbs.gameol.com", webguide: "http://kingory.gameol.com/Faq.aspx?tid=6672f793-5551-4954-bdff-2b3cd0017273" }, { menu: "false", wmode: "transparent" });
    }
});



function Show(obj) {
    var divS = document.getElementById(obj);
    divS.style.display = "block";
}

function Hide(obj) {
    var divS = document.getElementById(obj);
    divS.style.display = "none";
}

function ShowLogin() {
    $show('Login');
}

function $e(z) { return document.getElementById(z); }
function $hide(z) { $e(z).style.display = "none"; }
function $show(z) { $e(z).style.display = "block"; }


