﻿var gameloginexit = false;
function verificationResults(islogin) {
    if ($.trim(notice) == "") {
        var loginJson = eval(GetLoginVerify());
        var username = $.trim($("#username").val());
        var password = $.trim($("#password").val());
        var usercode = $.trim($("#usercode").val());
        var imgsrc = new URLParser($("#code").attr("src"));
        var urlcode = imgsrc.getParameter("c");
        if (username == "") {
            alert(loginJson.userempty);
            $("#username").focus();
            return false;
        }
        if (password == "") {
            alert(loginJson.passempty);
            $("#password").focus();
            return false;
        }
        if (usercode == "") {
            alert(loginJson.codeempty);
            $("#usercode").focus();
            return false;
        }
        if (usercode != urlcode) {
            alert(loginJson.codeerror);
            $("#usercode").focus();
            CreateImage();
            return false;
        }
        if (islogin) {
            $("#Main").remove();
            $("#flashview").remove();
            
            document.getElementById("gameflash").contentWindow.getLoing(username.toString().toLowerCase(), password.toString().toLowerCase(), SetGamelan());
            document.getElementById("gameflash").contentWindow.ChangeotherbackImage("bg");
            gameloginexit = true;
            tb_remove();
            SetGameHall();

        } else {
            $("#gameloginform").submit();
            tb_remove();
        }
        return true;
    }
    return false;
}

function GetGameLogin(path) {
    if ($.trim(path) != "msgame") {
        tb_show("", "GameLogin.aspx?lanname=" + lan + "&gamepath=" + path + "&rand=" + Math.random() + "&keepThis=true&bgauto=true&height=218&width=563", false);
        gamepath = path;
    }
}
function Getfremierclubforgetpass() {
    var val = $("#btnbetting1").val();
    $("#TB_ajaxContent").remove();
    $("#TB_title").remove();
    tb_show("", "Forgotpassword.aspx?lanname=" + lan + "&gamepath=" + gamepath + "&rand=" + Math.random() + "&bg=true&keepThis=true&TB_iframe=true&height=201&width=563", false);
 }

var jsonurl
function GameLogoStart() {
//    var index = parseInt(eval(GetGameLogoObject())[gamepath]) + 1;
//    try {
//        if (getbrowser()) {
//            __flash__addCallback(getswf("logo"), "Changegamelogo");
//        }
//        getswf("logo").Changegamelogo(index, SetGamelan().toString());
//    } catch (err) { alert(err.message); }
    CreateImage();
    $("#code").click(function() {
        CreateImage();
    });
    $("#gameflash").attr({ "src": "Game/" + gamepath + "/salon.html" });
    $("#username").keyup(function(e) {
        if (e.keyCode == 13)
            verificationResults(true);
    });
    $("#userpassword").keyup(function(e) {
        if (e.keyCode == 13)
            verificationResults(true);
    });
    $("#usercode").keyup(function(e) {
        if (e.keyCode == 13)
            verificationResults(true);
    });
    gameloginexit = false;
    $("#btnbetting").click(function() { verificationResults(true); });
    if (gamepath != "fremierclub")
        $("#btnbetting1").click(function() { verificationResults(false);  });
    else
        $("#btnbetting1").click(function() { Getfremierclubforgetpass(); });
}

function ChangeLanByFlash() {
    try {
        if (getbrowser()) {
            __flash__addCallback(getswf("nav"), "getLanChange");
        }
        getswf("nav").getLanChange(SetGamelan());
    } catch (err) { }
    try {
        if (getbrowser()) {
            __flash__addCallback(getswf("glogin"), "getLanChange");
        }
        getswf("glogin").getLanChange(SetGamelan());
    } catch (err) { }
}


function chooseIp(result) {
    if (result == "1") {
        $("#flashcontent").css({ "display": "none" });
        $("#usercenter").css({ "display": "block" });
        $(".glr_rightcode").css({ "display": "block" });
        $("#unetlogin").css({ "display": "block" });
        $(".gl_code").css({ "display": "block" });
        $("#username").focus();
        chooesgame = "1";
        CreateImage();
    }
    else {
        if (result == "0") {
            $("#flashcontent").html(chooseiperr);
            chooesgame = "1";
            isnavplay = true;
            Isonclick = false;
        }
    }
}

function loadOver() {
    $("#flashcontent").html(chooseip);
    chooesgame = "0";
}

function SetGameHall() {
    if (gameloginexit) {
        var w = "";
        var h = "";
        switch (getNavigatorVersion()) {
            case "IE:6.0":
                w = "99.99999%";
                break;
            case "IE:7.0":
                w = "100%";
                break;
            case "IE:8.0":
                w = "100%";
                break;
            default:
                w = "100%";
                break;
        }
        h = tb_getPageSize()[1];
        $("#gameflash").css({ "width": w, "height": "" + h + "px" });
        $("#Main").css({ "display": "none" });
        document.getElementById("Main").removeAttribute("div");
        
    }
}
window.onresize = function() { SetGameHall(); };

function GetgameLogindefault(gpath) {
    Switchtabes("gamelogin", "1");
    GetGameLogin(gpath);
}
