﻿
if (typeof $ !== "undefined") {

    /*
        $(function(){
            $.wrapper({
                html: "Html you want to wrap",
                width: (width - 55),
                height: (height - 55),
                prefix: 'wrapper'
            });
        });
    */
    $.wrapper = function(opt) {
        var html = (opt.html == undefined ? '' : opt.html);
        var width = (opt.width == undefined ? 150 : opt.width);
        var height = (opt.height == undefined ? 150 : opt.height);
        var prefix = (opt.prefix == undefined ? 'wrapper' : opt.prefix);

        return [
            '<div class="' + prefix + '_t_l"><br /></div>',
            '<div class="' + prefix + '_t_c" style="width:' + width + 'px;"><br /></div>',
            '<div class="' + prefix + '_t_r"><br /></div>',
            '<div style="clear:both;"></div>',
            '<div class="' + prefix + '_m_l" style="height:' + height + 'px;"><br /></div>',
            '<div class="' + prefix + '_m_c" style="width:' + width + 'px;height:' + height + 'px;">', html, '</div>',
            '<div class="' + prefix + '_m_r" style="height:' + height + 'px;"><br /></div>',
            '<div style="clear:both;"></div>',
            '<div class="' + prefix + '_b_l"><br /></div>',
            '<div class="' + prefix + '_b_c" style="width:' + width + 'px;"><br /></div>',
            '<div class="' + prefix + '_b_r"><br /></div>'
        ].join('');
    }

    /*
        var form = {
            id: 'formID',
            action: 'url/submit/to/',
            fields: {
                hidFieldName1: 1,
                hidFieldName2: 2
            }
        };
    */
    $.submitOnTheFly = function(form) {
        var sb = new StringBuilder();

        for (var field in form.fields) {
            if (form.fields.hasOwnProperty(field)) {
                sb.append('<input type="hidden" id="' + field + '" name="' + field + '" value="' + form.fields[field] + '" />');
            }
        }

        var data = sb.toString();

        if (data.length > 0) {
            if ($('#' + form.id).length == 0) {
                $('body').append('<form id="' + form.id + '" action="' + form.action + '" method="post" />');
            }

            $('#' + form.id).html(data).submit();
        }
        return false;
    }
    
    $.fn.extend({
        /*--------------------------------------------------------------------------------------------------*/
        // $('#txt').enterKeydown(function(o) { alert(o.value); });
        enterKeydown: function(fn) {
            return this.keydown(function(e) {
                var key = 0;
                if (window.event) {
                    key = window.event.keyCode;
                }
                else if (e) {
                    key = e.keyCode;
                }
                if (key == 13) {
                    fn(this);
                    return false;
                }
            });
        }
    });

    $(function() {
        $('#nav > li')
            .bind('mouseover', function() {
                $(this).find('div').show();
            })
            .bind('mouseleave', function() {
                if ($(this).find('img').size() == 3) {
                    $(this).find('img:first').attr('src', $(this).find('img').attr('src').replace('_On', '_Off'));
                }
                $(this).find('div').hide();
            })
            .find('div')
            .bind('mouseleave', function() {
                $(this).hide();
            });

        // Eliminate flicker when toggling Show / Hide
        $('#jValSummary').find('td:nth-child(2)').css('verticalAlign', 'top');
    });

    function changeLanguage(lang, url) {
        $('#hidLanguage').val(lang);
        $('#frmLanguage').attr('action', url).submit();
    }

}

function MM_CheckFlashVersion(reqVerStr, msg) {
    with (navigator) {
        var isIE = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
        var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
        if (!isIE || !isWin) {
            var flashVer = -1;
            if (plugins && plugins.length > 0) {
                var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
                desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
                if (desc == "") flashVer = -1;
                else {
                    var descArr = desc.split(" ");
                    var tempArrMajor = descArr[2].split(".");
                    var verMajor = tempArrMajor[0];
                    var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
                    var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
                    flashVer = parseFloat(verMajor + "." + verMinor);
                }
            }
            // WebTV has Flash Player 4 or lower -- too low for video
            else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

            var verArr = reqVerStr.split(",");
            var reqVer = parseFloat(verArr[0] + "." + verArr[2]);

            if (flashVer < reqVer) {
                if (confirm(msg))
                    window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
            }
        }
    }
}