﻿// ui.default.js
// Main javascript file included in Site.Master, accessible in the entire site.

/* creating our own namespace
* NOTE: do NOT use m980.locals here, only for locally-declared stuff on pages themselves.
*/
if (!m980) { var m980 = {}; }

/*
Copyright (c) Copyright (c) 2007, Carl S. Yestrau All rights reserved.
Code licensed under the BSD License: http://www.featureblend.com/license.txt
Version: 1.0.4
*/
// For Flash detection
m980.flash_detect = new function() {
    var self = this;
    self.installed = false;
    self.raw = "";
    self.major = -1;
    self.minor = -1;
    self.revision = -1;
    self.revisionStr = "";
    var activeXDetectRules = [
        {
            "name": "ShockwaveFlash.ShockwaveFlash.7",
            "version": function(obj) {
                return getActiveXVersion(obj);
            }
        },
        {
            "name": "ShockwaveFlash.ShockwaveFlash.6",
            "version": function(obj) {
                var version = "6,0,21";
                try {
                    obj.AllowScriptAccess = "always";
                    version = getActiveXVersion(obj);
                } catch (err) { }
                return version;
            }
        },
        {
            "name": "ShockwaveFlash.ShockwaveFlash",
            "version": function(obj) {
                return getActiveXVersion(obj);
            }
        }
    ];
    /**
    * Extract the ActiveX version of the plugin.
    * 
    * @param {Object} The flash ActiveX object.
    * @type String
    */
    var getActiveXVersion = function(activeXObj) {
        var version = -1;
        try {
            version = activeXObj.GetVariable("$version");
        } catch (err) { }
        return version;
    };
    /**
    * Try and retrieve an ActiveX object having a specified name.
    * 
    * @param {String} name The ActiveX object name lookup.
    * @return One of ActiveX object or a simple object having an attribute of activeXError with a value of true.
    * @type Object
    */
    var getActiveXObject = function(name) {
        var obj = -1;
        try {
            obj = new ActiveXObject(name);
        } catch (err) {
            obj = { activeXError: true };
        }
        return obj;
    };
    /**
    * Parse an ActiveX $version string into an object.
    * 
    * @param {String} str The ActiveX Object GetVariable($version) return value. 
    * @return An object having raw, major, minor, revision and revisionStr attributes.
    * @type Object
    */
    var parseActiveXVersion = function(str) {
        var versionArray = str.split(","); //replace with regex
        return {
            "raw": str,
            "major": parseInt(versionArray[0].split(" ")[1], 10),
            "minor": parseInt(versionArray[1], 10),
            "revision": parseInt(versionArray[2], 10),
            "revisionStr": versionArray[2]
        };
    };
    /**
    * Parse a standard enabledPlugin.description into an object.
    * 
    * @param {String} str The enabledPlugin.description value.
    * @return An object having raw, major, minor, revision and revisionStr attributes.
    * @type Object
    */
    var parseStandardVersion = function(str) {
        var descParts = str.split(/ +/);
        var majorMinor = descParts[2].split(/\./);
        var revisionStr = descParts[3];
        return {
            "raw": str,
            "major": parseInt(majorMinor[0], 10),
            "minor": parseInt(majorMinor[1], 10),
            "revisionStr": revisionStr,
            "revision": parseRevisionStrToInt(revisionStr)
        };
    };
    /**
    * Parse the plugin revision string into an integer.
    * 
    * @param {String} The revision in string format.
    * @type Number
    */
    var parseRevisionStrToInt = function(str) {
        return parseInt(str.replace(/[a-zA-Z]/g, ""), 10) || self.revision;
    };
    /**
    * Is the major version greater than or equal to a specified version.
    * 
    * @param {Number} version The minimum required major version.
    * @type Boolean
    */
    self.majorAtLeast = function(version) {
        return self.major >= version;
    };
    /**
    * Is the minor version greater than or equal to a specified version.
    * 
    * @param {Number} version The minimum required minor version.
    * @type Boolean
    */
    self.minorAtLeast = function(version) {
        return self.minor >= version;
    };
    /**
    * Is the revision version greater than or equal to a specified version.
    * 
    * @param {Number} version The minimum required revision version.
    * @type Boolean
    */
    self.revisionAtLeast = function(version) {
        return self.revision >= version;
    };
    /**
    * Is the version greater than or equal to a specified major, minor and revision.
    * 
    * @param {Number} major The minimum required major version.
    * @param {Number} (Optional) minor The minimum required minor version.
    * @param {Number} (Optional) revision The minimum required revision version.
    * @type Boolean
    */
    self.versionAtLeast = function(major) {
        var properties = [self.major, self.minor, self.revision];
        var len = Math.min(properties.length, arguments.length);
        for (i = 0; i < len; i++) {
            if (properties[i] >= arguments[i]) {
                if (i + 1 < len && properties[i] == arguments[i]) {
                    continue;
                } else {
                    return true;
                }
            } else {
                return false;
            }
        }
    };
    /**
    * Constructor, sets raw, major, minor, revisionStr, revision and installed public properties.
    */
    self.flash_detect = function() {

        var versionObj, version;
        if (navigator.plugins && navigator.plugins.length > 0) {
            var type = 'application/x-shockwave-flash';
            var mimeTypes = navigator.mimeTypes;
            if (mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description) {
                version = mimeTypes[type].enabledPlugin.description;
                versionObj = parseStandardVersion(version);
                self.raw = versionObj.raw;
                self.major = versionObj.major;
                self.minor = versionObj.minor;
                self.revisionStr = versionObj.revisionStr;
                self.revision = versionObj.revision;
                self.installed = true;
            }
        } else if (navigator.appVersion.indexOf("Mac") == -1 && window.execScript) {
            version = -1;
            for (var i = 0; i < activeXDetectRules.length && version == -1; i++) {
                var obj = getActiveXObject(activeXDetectRules[i].name);
                if (!obj.activeXError) {
                    self.installed = true;
                    version = activeXDetectRules[i].version(obj);
                    if (version != -1) {
                        versionObj = parseActiveXVersion(version);
                        self.raw = versionObj.raw;
                        self.major = versionObj.major;
                        self.minor = versionObj.minor;
                        self.revision = versionObj.revision;
                        self.revisionStr = versionObj.revisionStr;
                    }
                }
            }
        }
    } ();
}();
m980.flash_detect.JS_RELEASE = "1.0.4";

// For debugging only, remove after dev.
dd = function(stuff) {
    if (window.console && window.console.log) {
        console.log(stuff);
    }
};

// default URL to redirect user to if no other URL
// is available as a result of an AJAX request
m980.defaultRedirectURL = "/";

/*
* @desc processes links on history pages to prevent extra AJAX calls on 'sliding up' the history items in the list
* @param resp XHR object with server response
* @param element the link clicked
*/
m980.transformWagerLinks = function(resp, element) {
    $(element).parents('tr').addClass('active'); // set 'active' class on row just in case

    var id = '#' + (resp.get_updateTarget().id);
    var $id = $(id);
    $id.slideToggle('fast'); // show corresponding DIV

    // kill the link's original 'onclick' attribute, add ID of corresponding 
    //DIV to toggle and attach a new 'onclick' event
    $(element).attr("onclick", "").attr("href", id).click(function() {
        if (!$id.is(':animated')) {  // prevent animation queue buildup
            $id.slideToggle('fast'); // toggle the corresponding DIV
            $(this).parents('tr').toggleClass('active'); // toggle 'active' class on row
        }
        return false;
    });
};

/* TODO this one is very sensitive to markup changes! */
m980.open_active_menu_item = function() {
    var path = jQuery.url.attr("path");
    var leftMenuContainer = '#bd div.nav';
    $(leftMenuContainer).find('a[href$=' + path + ']').addClass('selected').parents('ul').eq(0).siblings('span').find('span').trigger('click');
};

m980.highlight_glossary_menu_item = function() {
    var path = jQuery.url.attr("path");
    var glossaryContainer = 'ul.glossaryMenu';
    $(glossaryContainer).find('a[href$=' + path + ']').addClass('selected');
};

// custom 'fade toggle' function
//jQuery.fn.fadeToggle = function(speed, easing, callback) {
//    return this.animate({ opacity: 'toggle' }, speed, easing, callback);
//};

// TODO document this code
m980.initUserMessages = function() {
    $("a#expColl").addClass("closed");

    if (parseInt($(".msgs").text(), 10) > 0) {
        $("span#mailIcon").css("display", "block");
    }

    $('dl.allStats').hide();

    $("div.tooltipContainer").hover(
      function() {
          $(this).stop().animate({ height: "148px" }, 300);
          $("a#expColl").addClass("opened").removeClass("closed");
      },
      function() {
          $(this).stop().animate({ height: "66px" }, 300);
          $("a#expColl").removeClass("opened").addClass("closed");
      }
    );
};

/* TODO this one is very sensitive to markup changes! */
m980.toggle_lines_menu_selected = function() {
    $('div.menu-tabs ul li a#sportsbook_games span, div.menu-tabs ul li a#sportsbook_periods span').click(function(event) {
        $(this).parent().addClass('selected').parent().siblings().children().removeClass('selected');
    });
};

/*
* @desc Site-wide status message functionality. Wrapper for blockUI plugin. Call this function when you want 
*       to display a message to the user, such as a 'loading...' message during an AJAX call. Once called, 
*       the message will not disappear unless msg_deactivate is executed.
* @param msg Optional message to be displayed. If not provided, default 'Loading...' message will be shown.
* @param style Optional class for additional styling of the span inside the message container.
* @author Max Kovalenkov
* @TODO remove this in favour of m980.msg_show
*/
function msg_show(msg, style) {
    var finalMsg = '<span>Loading...</span>';

    if (msg !== undefined) {
        if (style !== undefined) {
            finalMsg = '<span class="' + style + '">' + msg + '</span>';
        } else {
            finalMsg = '<span>' + msg + '</span>';
        }

        // IE6 centers the bar vertically for some reason (unless height of 100% is specified on the container,
        // in which case the content of the page is being blocked when the bar is showing).
        // P.S. we only want to hide message for IE6 in case of a custom error, because ajaxStop will hide the default one.
        if ($.browser.msie && /MSIE 6.0/.test(navigator.userAgent)) { /* TODO this is deprecated in jQuery 1.3.2 */
            setTimeout($.unblockUI, 3000);
        }
    }
    $.blockUI({
        css: {
            padding: 0,
            margin: 0,
            width: '100%',
            top: 0,
            left: 0,
            textAlign: 'center',
            color: '#000',
            border: 'none',
            cursor: 'default',
            backgroundColor: 'transparent'
        },
        showOverlay: false,
        message: finalMsg
    });
}

/*
* @desc Hides the status message component. Wrapper for blockUI plugin.
* @TODO remove this in favour of m980.msg_hide
*/
function msg_hide() {
    $.unblockUI();
}

/*
* @desc A wrapper for msg_show function used by elements generated by MVC
* @param resp The first variable in all AJAX callback functions automatically gets the XHR object assigned to it by MVC, so we cannot use msg_show directly. Later more functionality could be added here, perhaps checking in the response if a special server-side message is set and passing it on to msg_show to be displayed.
* @param msg See msg_show
* @param style See msg_show
* @TODO remove this in favour of m980.msg_activate
*/
function msg_activate(resp) { msg_show(); }

/*
* @desc Site-wide status message functionality. Wrapper for blockUI plugin. Call this function when you want 
*       to display a message to the user, such as a 'loading...' message during an AJAX call. Once called, 
*       the message will not disappear unless msg_deactivate is executed.
* @param msg Optional message to be displayed. If not provided, default 'Loading...' message will be shown.
* @param style Optional class for additional styling of the span inside the message container.
* @author Max Kovalenkov
*/
m980.msg_show = function(msg, style) {
    var finalMsg = '<span>Loading...</span>';

    if (msg !== undefined) {
        if (style !== undefined) {
            finalMsg = '<span class="' + style + '">' + msg + '</span>';
        } else {
            finalMsg = '<span>' + msg + '</span>';
        }

        // IE6 centers the bar vertically for some reason (unless height of 100% is specified on the container,
        // in which case the content of the page is being blocked when the bar is showing).
        // P.S. we only want to hide message for IE6 in case of a custom error, because ajaxStop will hide the default one.
        if ($.browser.msie && /MSIE 6.0/.test(navigator.userAgent)) { /* TODO this is deprecated in jQuery 1.3.2 */
            setTimeout($.unblockUI, 3000);
        }
    }
    $.blockUI({
        css: {
            padding: 0,
            margin: 0,
            width: '100%',
            top: 0,
            left: 0,
            textAlign: 'center',
            color: '#000',
            border: 'none',
            cursor: 'default',
            backgroundColor: 'transparent'
        },
        showOverlay: false,
        message: finalMsg
    });
};

/*
* @desc Hides the status message component. Wrapper for blockUI plugin.
*/
m980.msg_hide = function() {
    $.unblockUI();
};

/*
* @desc A wrapper for msg_show function used by elements generated by MVC
* @param resp The first variable in all AJAX callback functions automatically gets the XHR object assigned to it by MVC, so we cannot use msg_show directly. Later more functionality could be added here, perhaps checking in the response if a special server-side message is set and passing it on to msg_show to be displayed.
* @param msg See msg_show
* @param style See msg_show
*/
m980.msg_activate = function(resp) {
    msg_show();
};

/*
* @desc function which prepares left menu with subtree list items for accordion functionality
*/
m980.init_left_menu = function() {

    // function which assigns the same state to all 'input' siblings
    // of an element that was passed in.
    function checkAllBoxes(elem, status) {
        $(elem).siblings().find('input').each(function() {
            $(this).attr('checked', status);
        });
    }

    $("ul.makeLink li ul").siblings().addClass("linkItem").after("<span class='expCollPos'><span class='collapsed'></span></span>");
    $("ul.dyn:not(.makeLink) li ul").siblings().addClass("collapsed");
    $('ul.dyn ul').hide(); // the dyn class name is mandatory. The parent UL of the menu should have class="dyn"

    $("div.nav fieldset button.submit").hover(
      function() {
          $(this).addClass("active");
      },
      function() {
          $(this).removeClass("active");
      }
    );


    // bind a click event to links in the left menu
    $("ul.makeLink li span.expanded, ul.makeLink li span.collapsed").click(function(e) {
        $(this).toggleClass("collapsed").toggleClass("expanded");
        $(this).parent().next().slideToggle();
        return false;
    });

    $("ul.dyn li a").click(function(ev) {
        var $this = $(this);
        if (!$this.next().is(':animated')) { // prevent animation queue buildup
            if (($this.parent().children().length == 2) && ($this.parent().parent().hasClass('dyn'))) {
                ev.preventDefault();
                $this.toggleClass("collapsed").toggleClass("expanded");
                $this.next().slideToggle();
                return false;
            }
        } else {
            /* if user double-clicks on 'plus'/'minus', we need to prevent default behaviour, which is is causing a 'jump' to the top of the page */
            ev.preventDefault();
        }
    });

    var textDefault = 'select all';
    var textSelected = 'deselect all';

    var checkbox = "<li class='first'><input type='checkbox'/><span>" + textDefault + "</span></li>";

    // take all lists of size bigger than one inside a list with class 'dyn', 
    // and prepend a new list item to each, give this item class 'first'.
    $("ul.selection li ul").filter(function() {
        return $(this).children("li:has(input)").length > 1;
    }).prepend(checkbox);

    // bind a function to click event of every list item with class 'first' that's
    // inside a list with class 'dyn', get 'checked' attribute of the list item clicked, 
    // assign the same attribute to the rest of elements in the list.
    $("ul.selection li.first").click(function(e) {
        var $this = $(this);
        var status = $this.find('input').attr('checked');
        var twistedStatus = (e.target.tagName !== 'INPUT') ? !status : status;
        checkAllBoxes($this, twistedStatus);
        $this.find('span').html(twistedStatus ? textSelected : textDefault);
    });

    // toggles a checkbox when user clicks on a corresponding list item in the left menu
    $("ul.selection li ul li:has(input)").click(function(ev) {
        if (ev.target.tagName !== 'INPUT') {
            var box = $(this).children('input[type=checkbox]');
            box.attr('checked', (box.attr('checked') ? '' : 'checked'));
            return false;
        }
    });

    // TODO remove after DEV
    //$("input[name='sports']").attr('checked', true);
    //$('#liveodds_submit').trigger('click');
};

/*
* @desc onFailure function responsible for giving feedback to user. Utilized on user transaction history pages.
* @param resp XHR object with server response
*/
m980.historyOnFailure = function(resp) {
    var url;
    var code;
    if (resp === undefined) {// response is null, just show error and ask to refresh.
        m980.msg_show('An error occured, try refreshing.');
    } else {
        url = resp.get_response().getResponseHeader("RedirectUrl");
        code = resp.get_response().get_statusCode();

        if (url !== undefined && code !== undefined && code == '403') {
            window.location.href = url;
        } else if (url !== undefined && code !== undefined) { // not 403
            m980.msg_show('An error occured, try refreshing (error code ' + code + ').');
        } else {
            bwindow.location.href = m980.defaultRedirectURL; // redirect to default location
        }
    }
};

/* 
* @desc onSuccess and onFailure for wager links have to appear outside of the pages because 
* they are being embedded into other pages as components, therefore including them in the 
* page would create multiple duplicate functions on page render.
*/
m980.wagersListOnSuccess = function(resp) {
    if (typeof m980.transformWagerLinks == 'function') { m980.transformWagerLinks(resp, this); }
};

m980.wagersListOnFailure = function(resp) {
    m980.historyOnFailure(resp);
};

/*
* @desc This method is used inside the UserControl (LoyaltyPointTransactionsList.ascx)
* @author Vincent Hamelin 
* @date 23 Juin 2009
*/
m980.transactionListOnSuccess = function(resp) {
    if (typeof m980.transformWagerLinks == 'function') { m980.transformWagerLinks(resp, this); }
};

/*
* @desc This method is used inside the UserControl (LoyaltyPointTransactionsList.ascx)
* @author Vincent Hamelin 
* @date 23 Juin 2009
*/
m980.transactionListOnFailure = function(resp) {
    m980.historyOnFailure(resp);
};

m980.initialize_overlay = function() {
    Boxy.DEFAULTS.modal = true;

    var busy = false; // for not showing two boxies on accidental double-click

    $('a.overlay').click(function(e) {
        if (busy) { return false; } // if we're busy - bail out 
        busy = true; // block everyone else

        Boxy.load(this.href, {
            cache: true,
            title: (this.title ? this.title : "Overlay"),
            afterHide: function() { this.getContent().remove(); },
            afterShow: function() { busy = false; $('div.boxy-modal-blackout').bgiframe(); }
        });

        return false;
    });
};

/* all jQuery plugins should be inserted into this block */
(function($) {

    /*
    * @name rotator
    * @type jQuery
    * @return jQuery
    * @author Max Kovalenkov
    *
    * 
    * @example $('#trigger).rotator();
    * @desc This is the most basic way to attach the plugin. The options by default are as is specified in the 'defaults' object.
    * 
    * @example $('#trigger).rotator({ 
    *   delay: 1000,
    *   initialDelay: 3000,
    *   startItemCls: 'start'
    *   });
    * @desc initialize the rotator on container with ID 'trigger', one second between animations and with animations starting 
    *       three seconds after the page loads. The initial list item to begin from has class 'start'.
    *
    */
    $.fn.rotator = function(opts) {

        var options = $.extend($.fn.rotator.defaults, opts);

        return this.each(function() {

            var obj; // the element that the plugin is being attached to
            var timerId; // timer's ID which will be used to stop the timer that we set in setInterval

            var activated = false; // boolean that controls component's state
            var activating = false;

            obj = $(this);
            var lis = $(this).find('li'); // items on the list that will be rotating
            var divs = $(this).find('div#holder > div'); // TODO select based on the lis

            var activate = function(event) {
                activated = true;
                activating = false;
                if (!options.onActivate(obj)) {
                    return false;
                }

                timerId = setInterval(function() {
                    var activeItem = lis.filter('.on');
                    var i = lis.index(activeItem);
                    // is there a next item? if yes, get next. if not, get the first one.
                    var next = lis.eq(i + 1).length ? lis.eq(i + 1) : lis.filter(':first');
                    point(next);
                }, options.delay);
            };

            var deactivate = function(e) {
                activated = false;
                clearInterval(timerId);
            };

            var point = function(item, e) {
                if (item.hasClass("on")) { return false; }
                else {
                    lis.removeClass("on");
                    item.addClass("on");
                    var hash = item.find('a').attr('hash');
                    divs.fadeOut(600).filter(hash).fadeIn(600); // fade out all except the current
                }
            };

            // change visible item by click
            if ((/click|toggle/).test(options.trigger)) {
                lis.click(function(e) {
                    point($(this), e);
                    return false;
                });

                // TODO change visible item by focus/blur
            } else if (options.trigger == 'focus') {
                // activate by hover
            }

            obj.hover(function(e) {
                if (activated && !activating) { // if plugin is activated and reactivate on blur hasn't been fired
                    deactivate(e);
                }
            }, function(e) {
                if (!activated && !activating) { // if reactivate on blur hasn't already been fired
                    activating = true;
                    setTimeout(function(e) {
                        activate(e);
                    }, options.initialDelay);
                }
            });

            var startItem = lis.filter("." + options.startItemCls);

            var rand;
            if (startItem.length) {
                rand = startItem[0].id.substring(2);
                startItem.removeClass(options.startItemCls);
            }
            else {
                rand = (Math.floor(Math.random() * lis.length) + 1);
            }
            divs.eq(0).css("display", "none"); // the first block is set to be visible via CSS in case JS is off

            blockID = $("#th" + rand).addClass("on").find('a').attr('hash');
            $(blockID).css("display", "block");

            activate();

        }); // end this.each
    }; // end $.fn.rotator

    /*
    * Options for the rotator component
    *
    * Each one can be explicitly overridden by changing its value. 
    * For instance: $.fn.rotator.defaults.initialDelay = 12000;
    * would change the delay before the animations initiate upon page load to 12 seconds.
    *
    * Each one can also be overridden by passing an options map to the rotator method.
    * for example: $('a.example').rotator({ onActivate: 'beforeRotator' }); 
    * will trigger function called beforeRotator to run just before the rotator component is activated on all links with class 'example'
    *
    */
    $.fn.rotator.defaults = { // set up default options
        delay: 4000, // delay between animations during rotation
        initialDelay: 6000, // delay before the rotation begins
        effect: 'fade', // set to 'fade' to have a simple fade-in/fade-out
        trigger: 'click', // set to 'click' to force user to click to show corresponding details
        startItemCls: 'start', // has to be a name of CSS class
        onActivate: function(e) { return true; } // function run just before component is activated.
    };

})(jQuery);
/* end jQuery plugins block */


if (!m980.payout) { m980.payout = {}; }

/*
* @desc Check if the data set into a textbox is numeric, used especially for PAYOUT section 
* @param sText the string data that need to be validated
* @author Andry
*/
m980.payout.isPayoutNumeric = function(sText) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var IsDotAlreadyExist = false;
    var Char;
    if (sText.length > 0) {
        for (i = 0; i < sText.length && IsNumber === true; i++) {
            Char = sText.charAt(i);
            if (ValidChars.indexOf(Char) == -1) {
                IsNumber = false;
            }
            if (Char == ".") {
                if (IsDotAlreadyExist === true) {
                    IsNumber = false;
                }
                else {
                    IsDotAlreadyExist = true;
                }
            }
        }
    }
    else {
        IsNumber = false;
    }
    return IsNumber;
};

/*
* @desc Filter to allow only digit when the user enter data into a textbox.
*       Used especially for PAYOUT section.
* @param e define the key pressed event during the data entry
* @author Andry
*/
m980.payout.filterKey = function(e) {
    if (!e) { e = window.event; }

    var keyCode = e.which ? e.which : e.keyCode;
    var validKey = (keyCode >= 48 && keyCode <= 57) || (keyCode === 0) || (keyCode == 8) || (keyCode == 9) || (keyCode == 13) || (keyCode == 27) || (keyCode == 37) || (keyCode == 39) || (keyCode == 46);

    if (window.event) {
        e.returnValue = validKey;
    } else {
        if (validKey) {
            return true;
        } else {
            e.preventDefault();
            return false;
        }
    }
};

/*
* @desc Set all textboxes on the PAYOUT request page into empty string
* @author Andry
*/
m980.payout.resetAll = function() {
    $('#Fees').val('');
    $('#NetellerAccountNumber').val('');
    $('#ContactPhone').val('');
    $('#WTContactPhone').val('');
    $('#AccountName').val('');
    $('#RoutingNumber').val('');
    $('#AccountNumber').val('');
    $('#BankName').val('');
    $('#BankAddress').val('');
    $('#BankCity').val('');
    $('#BankPostalCode').val('');
    $('#BankPhone').val('');
    $('#BICCode').val('');
    $('#IBAN').val('');
    $('.field-validation-error').hide();
};

/*
* @desc Hide all div in the PAYOUT request  when a payment method is changed
* @author Andry
*/
m980.payout.hideAll = function() {
    $('#NT').hide();
    $('#FX').hide();
    $('#TR').hide();
    $('#BC').hide();
    $('#MethodInfo4Web').hide();
    $('#MethodError').hide();
    $('#AmountError').hide();
    $('#rules').hide();
    $('#customValidation').hide();
};

/*
* @desc Disabled all buttons depending of the configuration.
*       If ids is null or undefined or not an array then all buttons will be disabled.
*       If ids is an array, each item will be treated as an id. Each input will then be disabled
*       based on the ids.
*
*       This function must be called in the $(document).ready
* @param ids Array An array of the ids input to be disabled.
* @param actionName String The action name to be called when the form is submitted.
*/
function disableInput(ids, actionName) {
    $("form").submit(function(event) {
        var q = $(document);

        if (actionName !== undefined) {
            q = q.find("form[action*='" + actionName + "']");
        }

        if (ids !== undefined && ids !== null && $.isArray(ids)) {
            for (var index = 0; index < ids.length; index++) {
                q.find("#" + ids[index]).attr("disabled", "disabled");
            }
        } else {
            q.find(":button:enabled").attr("disabled", "disabled");
        }

        // show 'loading' icon and message if present.
        $(".loading", this).show();
        return true;
    });
}

if (!m980.seo) { m980.seo = {}; }

/*   SEO stuff - Requested by Bryan   */
/*
http://lyncd.com/2009/03/better-google-analytics-javascript/#comment-214
Inserts GA using DOM insertion of <script> tag and "script onload" method to
initialize the pageTracker object. Prevents GA insertion from blocking I/O!

As suggested in Steve Souder's talk. See:
http://google-code-updates.blogspot.com/2009/03/steve-souders-lifes-too-short-write.html
*/

/* acct is GA account number, i.e. "UA-5555555-1" ("UA-1356019-4") */
m980.seo.gaSSDSLoad = function(acct) {
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."),
      pageTracker,
      s;
    s = document.createElement('script');
    s.src = gaJsHost + 'google-analytics.com/ga.js';
    s.type = 'text/javascript';
    s.onloadDone = false;
    function init() {
        pageTracker = _gat._getTracker(acct);
        pageTracker._trackPageview();
    }
    s.onload = function() {
        s.onloadDone = true;
        init();
    };
    s.onreadystatechange = function() {
        if (('loaded' === s.readyState || 'complete' === s.readyState) && !s.onloadDone) {
            s.onloadDone = true;
            init();
        }
    };
    document.getElementsByTagName('head')[0].appendChild(s);
};
/*   SEO stuff - END   */

$(document).ready(function() {

    // reset some options of the blockUI plugin to be able to apply our own CSS rules in the stylesheet.
    //$.blockUI.defaults.css = {};
    //$.blockUI.defaults.showOverlay = false;

    if ($('div.tooltipHeader').length > 0) { // means user is logged in 
        m980.initUserMessages(); // create roller on "user  numbers" box
    }

    /* TODO check for existence of left menu - ask Mark */
    m980.open_active_menu_item();

    m980.highlight_glossary_menu_item();
    m980.toggle_lines_menu_selected();
    m980.initialize_overlay();

    // initialize the media rotator on all SectionDefault.Master pages.
    $('#feedRotator').rotator();

    // Dirty fix implemented to offset changset 8608 - the following block contains styles that used to be found in css/if-script-enable.css
    $('#bd .nav ul ul, div.flashAlt').css('display', 'none');
    $('#bd .nav ul ul.expanded').css('display', 'block');
    $('#bd .nav ul ul.expanded input').css('margin', '0.4em 0.25em 0.4em 0.4em');

    // For Flash detection
    if (!m980.flash_detect.installed) {
        //m980.msg_show("Flash is required to enjoy this site.");
        $("div.flashAlt").css({ 'display': 'block' });
    }

    m980.init_left_menu();

    m980.seo.gaSSDSLoad("UA-1356019-4"); // load Google Analytics

});