var flashOldPosition = null;

var documentWidth = 0;
var documentHeight = 0;
var clientWidth = 0;
var clientHeight = 0;

var flashWidth = 1240;
var flashHeight = 730;

var showInBrowser = false;

function f_clientWidth() {
        return f_filterResults (
                window.innerWidth ? window.innerWidth : 0,
                document.documentElement ? document.documentElement.clientWidth : 0,
                document.body ? document.body.clientWidth : 0
        );
}
function f_clientHeight() {
        return f_filterResults (
                window.innerHeight ? window.innerHeight : 0,
                document.documentElement ? document.documentElement.clientHeight : 0,
                document.body ? document.body.clientHeight : 0
        );
}

function f_filterResults(n_win, n_docel, n_body) {
        var n_result = n_win ? n_win : 0;
        if (n_docel && (!n_result || (n_result > n_docel)))
                n_result = n_docel;
        return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function startApplication(targetPage, isIE) {
        var popupWidth = 0;
        var popupHeight = 0;
        var popupFlashWidth = 0;
        var popupFlashHeight = 0;
        screenWidth = screen.width;
        screenHeight = screen.height;
        documentWidth = f_clientWidth();
        documentHeight = f_clientHeight();
//      alert("SW:" + screenWidth + "x" + screenHeight + " DW:" + documentWidth + "x" + documentHeight);
        if ((screenWidth >= flashWidth) && (screenHeight >= flashHeight)) {
                if ((documentWidth >= flashWidth) && (documentHeight >= flashHeight)) {
                        showInBrowser = true;
                } else {
                        showInBrowser = false;
                        popupWidth = flashWidth + 16;
                        popupHeight = flashHeight + (isIE ? 60 : 20);
                        popupFlashWidth = flashWidth;
                        popupFlashHeight = flashHeight;
                }
        } else {
                showInBrowser = false;
                popupWidth = screenWidth;
                popupHeight = screenHeight;
                popupFlashWidth = popupWidth - 16;
                popupFlashHeight = popupHeight - (isIE ? 60 : 20);
        }

        if ((showInBrowser == false) && (flashWidth > 0) && (flashHeight > 0)) {
                if ((screenWidth < flashWidth) || (screenHeight < flashHeight)) {
                        var widthRatio = screenWidth / flashWidth;
                        var heightRatio = screenHeight / flashHeight;
                        var ratio = widthRatio < heightRatio ? widthRatio : heightRatio;
                        popupFlashWidth = Math.round(ratio * flashWidth);
                        popupFlashHeight = Math.round(ratio * flashHeight);
                }
        }
        if (showInBrowser == true) {
        	window.location = targetPage + "?flashWidth=" + flashWidth + "&flashHeight=" + flashHeight;
        } else {
	        var popupWindow = window.open(targetPage + "?flashWidth=" + popupFlashWidth + "&flashHeight=" + popupFlashHeight, "popup", "resizable=no,toolbar=0,status=no,scrollbars=no,titlebar=0,width=" + popupWidth + ",height=" + popupHeight);
	        if (popupWindow != null) {
	          popupWindow.focus();
	        }
        }

}

