﻿// builds Flash object depending on detected Browser
function FlashObject(strFlashId, strFlashUrl, strWidth, strHeight, strStyle, strFlashVars, bAllowFullScreen, strBgColor) {

    if (strFlashUrl) {
        var doc = window.document;
        var MM_contentVersion = 8;
        var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;

        if (plugin) {
            var words = navigator.plugins["Shockwave Flash"].description.split(" ");
            for (var i = 0; i < words.length; ++i) {
                if (isNaN(parseInt(words[i]))) {
                    continue;
                }
                var MM_PluginVersion = parseInt(words[i]);
            }
            var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
        }
        else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE") >= 0 && (navigator.appVersion.indexOf("Win") != -1)) {
            doc.write('<scr' + 'ipt language="VBScript"\> \n');
            doc.write('on error resume next \n');
            doc.write('MM_FlashCanPlay = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
            doc.writeln('<\/scr' + 'ipt\> \n');
        }

        /* if (MM_FlashCanPlay) {*/
        if (true) {
            var bgColor = '#FFFFFF';
            if (strBgColor != null && strBgColor != '') {
                bgColor = strBgColor;
            }

            doc.write('<object ');
            doc.write('classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
            doc.write('id="' + strFlashId + '" ');
            doc.write('width="' + strWidth + '" ');
            if (strHeight != null && strHeight != '') {
                doc.write('height="' + strHeight + '" ');
            }
            if (strStyle != null && strStyle != '') {
                doc.write('style="' + strStyle + '" ');
            }
            doc.writeln('codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">');
            doc.writeln('<param name="movie" value="' + strFlashUrl + '" \/>');
            doc.writeln('<param name="quality" value="high" \/>');
            if (bAllowFullScreen == true) {
                doc.writeln('<param name="allowFullScreen" value="true" \/>');
            }
            doc.writeln('<param name="bgcolor" value="' + bgColor + '" \/>');
            doc.writeln('<param name="allowScriptAccess" value="sameDomain" \/>');
            doc.writeln('<param name="wmode" value="opaque" \/>');
            if (strFlashVars != null && strFlashVars != '') {
                doc.writeln('<param name="flashVars" value="' + strFlashVars + '" \/>');
            }
            doc.write('<embed ');
            if (strFlashVars != null && strFlashVars != '') {
                doc.write('flashVars="' + strFlashVars + '" ');
            }
            doc.write('wmode="opaque" ');
            doc.write('src="' + strFlashUrl + '" ');
            doc.write('quality="high" ');
            doc.write('bgcolor="' + bgColor + '" ');
            doc.write('width="' + strWidth + '" ');
            if (strHeight != null && strHeight != '') {
                doc.write('height="' + strHeight + '" ');
            }
            doc.write('name="' + strFlashId + '" ');
            doc.write('align="middle" ');
            doc.write('play="true" ');
            doc.write('loop="false" ');
            if (bAllowFullScreen == true) {
                doc.write('allowFullScreen="true" ');
            }
            doc.write('allowScriptAccess="sameDomain" ');
            doc.write('type="application/x-shockwave-flash" ');
            doc.write('pluginspage="http://www.adobe.com/go/getflashplayer">');
            doc.writeln('<\/embed>');
            doc.writeln('<\/object>');
        }
        else {
            doc.writeln('<p style="color:red; padding:10px;"><a href="http://www.adobe.com/" target="_blank" style="color:red;">FLASH-PLAYER 8 OR HIGHER REQUIRED: www.adobe.com<\/a><\/p>');
        }
    }
}

//create custom defaultButtons object, modified POINTS
// http://insite.phillfox.net/insite/2007/10/02/linkbutton-as-the-defaultbutton-fix-for-aspnet-20/
var defaultButtons = {
    registerButton: function(cId, bId, tId) {
        var oC = document.getElementById(cId);
        var oB = document.getElementById(bId);
        var oT = document.getElementById(tId);
        if (typeof (oC) !== 'undefined' && typeof (oB) !== 'undefined') {
            if (typeof (oC.addEventListener) !== 'undefined') {
                oC.addEventListener('keypress', function(e) {
                    defaultButtons.fireDefaultButton(e, oB, oT);
                }, false);
            } else if (typeof (oC.attachEvent) !== 'undefined') {
                oC.attachEvent('onkeypress', function(e) {
                    defaultButtons.fireDefaultButton(e, oB, oT);
                });
            }
        }
    },
    fireDefaultButton: function(e, lbtn, txtb) {
        if (!e.which && !e.keyCode) {
            return;
        } else {
            var k = (e.which || e.keyCode);
            try {
                // only eval href when TextBox has value
                if (k === 13 && txtb.value != '' && txtb.value.length > 0) {
                    lbtn.focus();
                    //                    eval(lbtn.href);
                    eval(lbtn.attributes["href"].value); // fixed for FF3.5.5
                    return true;
                }
            }
            catch (err) {
                return false;
            }
        }
    }
};
