﻿//function CheckClient(clienttype, username, sessionId, lobbyIP, lobbyPort, proxyIP, proxyPort, headerPath, footerPath, roomSidePath, accountInfoPath, resourcePath, resourceVersion) {

//    if (clienttype.toLowerCase() == 'java') {
//        OpenApplet("/Bridge.aspx", 800, 600);
//    } else if (clienttype.toLowerCase() == 'dotnet') {
//    
//        OpenClient(username, sessionId, lobbyIP, lobbyPort, proxyIP, proxyPort, headerPath, footerPath, roomSidePath, accountInfoPath, resourcePath, resourceVersion);
//    }

//}
// JScript File 800,600
function OpenApplet(url, opener, mode, width, height) {

    var params = new Array(url, opener, mode, width, height);
    GamePolicy(OpenAppletConfirmGamePolicy, params);
}

function OpenAppletConfirmGamePolicy(params) {

    var url = params[0];
    var opener = params[1];
    var mod = params[2];
    var width = params[3];
    var height = params[4];
    var generator = Math.random();

    if (width == undefined)
        width = 800;

    if (height == undefined)
        height = 600;
    var popup = window.open(url + "?rnd=" + generator + "&opener=" + opener + "&mode=" + mod, "PokerClient", "width=" + width + ", height=" + height + "location=no, status=no, resizable=yes, menubar=no, toolbar=no");

    popup.focus();

    return false;

}



//Downloadable client
function downloadClient(url) {
    var params = new Array(url);
    GamePolicy(downloadClientConfirmGamePolicy, params);
    return false;
}

function downloadClientConfirmGamePolicy(params) {
    var url = params[0];
    window.open(url, "ClickOnce", "width=600,height=600,location=no,status=no,menubar=no,toolbar=no");
    return false;
}

function OpenClient(username, sessionId, lobbyIP, lobbyPort, proxyIP, proxyPort, headerPath, footerPath, roomSidePath, accountInfoPath, resourcePath, customResourcePath, resourceVersion) {

    var params = new Array(username, sessionId, lobbyIP, lobbyPort, proxyIP, proxyPort, headerPath, footerPath, roomSidePath, accountInfoPath, resourcePath, customResourcePath, resourceVersion);
    GamePolicy(OpenClientConfirmGamePolicy, params);
    
}

function OpenClientConfirmGamePolicy(params) {

    var username = params[0];
    var sessionId = params[1];
    var lobbyIP = params[2];
    var lobbyPort = params[3];
    var proxyIP = params[4];
    var proxyPort = params[5];
    var headerPath = params[6];
    var footerPath = params[7];
    var roomSidePath = params[8];
    var accountInfoPath = params[9];
    var resourcePath = params[10];
    var customResourcePath = params[11];
    var resourceVersion = params[12];
    

    window.external.EnableEvents(false);
    window.external.SetHeader(headerPath);
    window.external.SetFooter(footerPath);
    window.external.SetRoomSide(roomSidePath);
    window.external.UpdateAccountInfo(accountInfoPath);

    //alert('Path: ' + resourcePath + '\nVersion: ' + resourceVersion + '\n');

    try {

        window.external.DownloadResourceExt(resourcePath, customResourcePath, resourceVersion);

    }
    catch (err) {
        alert("error dowinload");
        alert(err.description);
    }

    window.external.Logon3(username, sessionId, lobbyIP, lobbyPort, proxyIP, proxyPort);
    return false;
}
//function doWhenEnterPressed(evn) {
//    var enterWasPressed = false;
//    if (window.event && window.event.keyCode == 13) { // IE
//        enterWasPressed = true;
//    } else if (evn && (evn.keyCode == 13 || evn.which == 13)) { // FF
//        enterWasPressed = true;
//    }
//    if (enterWasPressed) {
//        alert('Enter pressed'); // your action code
//    }
//}

//document.onkeydown = function(evn) {
//    doWhenEnterPressed(evn);
//}


