var isChrome = (navigator.userAgent.indexOf("Chrome") != -1) ? true : false;
var mdcLastSearchKeyWord = null;
$(document).ready(
	function() {  
	    $('#mdcLink').mdcInsertSeperatorImgOrBr('Seperator.gif', 700);
	    $('#mdcWelcome').mdcInsertSeperatorImg('Seperator.gif');
	    $('#mdcMyMoodys').mdcInsertSeperatorImg('Seperator.gif');
	    $('#mdcFootNav').mdcInsertSeperatorImg('FooterSeperator.gif');
	    $('#mdcPolicy').mdcInsertSeperatorImg('FooterSeperator.gif');
	    $('#Menu2>li>a>img').mdcSwitchImage();
	    $('#Menu1>li>a>img').mdcSwitchImage2();
	    $('#mdcGuided div.mdcRefine>ul>li>ul').mdcInsertShowMore(12);
	    // For vintage dimension only.
	    $('#mdcGuided div.mdcRefine ul.mdcVintageDim').mdcInsertShowMore(4);
	    $('#mdcBackPrevious>a').click(function() { $.mdc.clearPreviousPageCookie(); });
	    $('#mdcSearch>div>input').blur(function() { if (!$.mdc.MouseOnTypeAhead) $('#mdcTypeAheadSpace, #mdcTypeAheadSpaceBottom, #mdcTypeAheadSpaceRight').addClass('mdcHide'); }).focus(function() { if ($(this).val().length >= 1 && $(this).val() != $(this).attr('mdcSearchValue')) $('#mdcTypeAheadSpace, #mdcTypeAheadSpaceBottom, #mdcTypeAheadSpaceRight').removeClass('mdcHide'); });
	    $('#mdcTypeAheadSpace').hover(function() { $(this).addClass('mdcShow'); }, function() { $(this).removeClass('mdcShow'); });
	    $('#mdcSearch>div>input').keydown(function(event) {
	        if (event.which != 13 && event.which != 38 && event.which != 40 && $("#mdcTypeAheadContainer").length == 0) { $.mdc.typeAheadIndex = -1; return; }
	        if (event.which == 38 || event.which == 40) {
	            var aLinkLength = $("#mdcTypeAheadContainer tr").length;
	            if (typeof $.mdc.typeAheadIndex != "undefined") {
	                $("#mdcTypeAheadContainer tr").eq($.mdc.typeAheadIndex).removeClass('mdcTypeAheadSelected');
	            }
	            if (event.which == 38) {//Key is Arrow-Up
	                $.mdc.typeAheadIndex = ((typeof $.mdc.typeAheadIndex == "undefined") || $.mdc.typeAheadIndex < 0) ? (aLinkLength - 1) : (($.mdc.typeAheadIndex - 1 + aLinkLength) % aLinkLength);
	            }
	            if (event.which == 40) {
	                $.mdc.typeAheadIndex = (typeof $.mdc.typeAheadIndex == "undefined") ? 0 : (($.mdc.typeAheadIndex + 1) % aLinkLength);
	            }
	            $("#mdcTypeAheadContainer tr").eq($.mdc.typeAheadIndex).addClass('mdcTypeAheadSelected');
	        }
	        if (event.which == 13) {
	            if ($.mdc.typeAheadIndex >= 0) {
	                $.mdc.pushPreviousPageCookie();
	                document.location = $("#mdcTypeAheadContainer tr>td>input").eq($.mdc.typeAheadIndex).val();
	                $('#mdcSearch>div>input').unbind('keydown');
	                event.preventDefault();
	            }
	        }
	    }).keyup(function(event) {
	        var aKeyWord = $(this).val();
	        if (mdcLastSearchKeyWord == aKeyWord)
	            return;
	        mdcLastSearchKeyWord = aKeyWord;
	        $.mdc.typeAhead(event, aKeyWord, $(this).attr('contextCountry'));
	    });
	    $('#mdcSearch>div>input').mdcTriggerButtonClickInput($('#mdcSearch>div>a'), 'Search entire site');
	    $('#mdcContainer .mdcSearchWithin input').mdcTriggerSiblingClickInput('Search within results');
	    /*For Local Language*/
	    $('#mdcContainer .mdcSearchWithin_es input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_pt input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_it input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_fr input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_de input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_ru input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_tr input').mdcTriggerSiblingClickInput('Search within results');
	    $('#mdcContainer .mdcSearchWithin_cs input').mdcTriggerSiblingClickInput('Search within results');

	    $('#Menu1>li:eq(0)>ul>li:eq(8)>a').click(function() { $.mdc.pushPreviousPageCookie(); });

	    $('#mdcTypeAheadSpace').mouseover(function() { $.mdc.MouseOnTypeAhead = true; }).mouseout(function() { $.mdc.MouseOnTypeAhead = false; });
	    $('#mdcHomeLink').hover(function() { $('#mdcHomeLink div').removeClass('mdcHide'); }, function() { $('#mdcHomeLink div').addClass('mdcHide'); });

	    /* Preload Images*/
	    if (document.images) {
	        preload_image_object = new Image();
	        // set image url
	        image_url = new Array();
	        image_url[0] = "/_Layouts/Mdc/Images/LoginOver.gif";

	        var i = 0;
	        for (i = 0; i <= 0; i++) { preload_image_object.src = image_url[i]; }
	    }
	    //Region click
	    var regionSelected = $('#mdcRegion option:selected');
	    $('#mdcRegion select').change(function() { if ($(this).val() == regionSelected.val()) { return; } window.open($(this).val()) });
	    $('#mdcSetAlertForCriteriaImg').mdcSwitchImage();
	    $('#mdcDateFilterButtonImg').mdcSwitchImage();

	    //Cross Link 
	    var regionVal = $('#clwRegion').attr('regionVal');
	    if (regionVal != undefined && regionVal != '' && regionVal != 'en' && regionVal != 'zh') {
	        $('#GlobNavBreadcrumbs ul.BrowseRepeaterUL a').addClass('isCrossLink');
	        $('a').click(
				function() {
				    var selfObj = $(this);
				    if (!selfObj.hasClass('isCrossLink') || $.mdc.CrossLanguageWarning.IsNewWindow(this)
							|| selfObj.attr('id') == "kampylink" || selfObj.attr('id') == "searchBarLink" || selfObj.attr('id') == "purchaseReportBtn"
							|| $.mdc.CrossLanguageWarning.IsFile(this))
				        return;
				    if (null == selfObj.attr("crossHref") || 'undefined' == selfObj.attr("crossHref")) {
				        selfObj.attr("crossHref", selfObj.attr("href"));
				        if (null == selfObj.attr("target") || 'undefined' == selfObj.attr("target"))
				            selfObj.attr("crossTarget", "_self");
				        else
				            selfObj.attr("crossTarget", selfObj.attr("target"));
				    }
				    $.mdc.CrossLanguageWarning.CrossClick(this, selfObj.attr("crossHref"));
				});
	    }

	    $('#clwYes').hover($.mdc.CrossLanguageWarning.hoverEnter, $.mdc.CrossLanguageWarning.hoverLeave);
	    $('#clwYes').mousedown($.mdc.CrossLanguageWarning.mousedown);
	    $('#clwNo').hover($.mdc.CrossLanguageWarning.hoverEnter, $.mdc.CrossLanguageWarning.hoverLeave);
	    $('#clwNo').mousedown($.mdc.CrossLanguageWarning.mousedown);

	    window.onscroll = moveRatingFactorsArea;

	    $(document).mouseup(
	    	function(event) {
	    	    if ($('#clwYes').hasClass('mdcBtnSelected')) { $('#clwYes').removeClass('mdcBtnSelected'); }
	    	    if ($('#clwNo').hasClass('mdcBtnSelected')) { $('#clwNo').removeClass('mdcBtnSelected'); }

	    	});

	    $('#mdcRatingsGroupTable tr.mdcRatingsTitleRow>td:nth-child(3)').css('text-align', 'center').html('<img src="/_layouts/Mdc/Images/ExpandOff.gif" />');
	    $('#mdcRatingsGroupTable tr.mdcRatingsTitleRow>td:nth-child(3)>img').mdcSwitchImage();
	    $('#mdcRatingsGroupTable tr.mdcRatingsTitleRow>td:nth-child(3)>img')
            .toggle(function() { $(this).parent().parent().next().toggleClass('mdcHide'); $(this).attr('src', '/_layouts/Mdc/Images/CollapsOff.gif'); },
            function() { $(this).parent().parent().next().toggleClass('mdcHide'); $(this).attr('src', '/_layouts/Mdc/Images/ExpandOff.gif'); });
	    if ($('#mdcRatingsGroupTable tr.mdcRatingsTitleRow').length == 1) {
	        $('#mdcRatingsGroupTable tr.mdcRatingsTitleRow>td:nth-child(3)>img').click();
	    }
	    $(document).mouseover(
        function(event) {
            var $target = $(event.target);
            var elementId = $target.attr("id");
            if (elementId != 'MdcLinkButtonContainer' && elementId != 'CurrentLinkButton' && elementId != 'SocialArrow' && elementId != 'mdcCurrentLinkButton' && $target.parents('#MdcLinkButtonContainer').length == 0 && elementId != 'gigyaSocialPopUpControl' && $target.parents('#gigyaSocialPopUpControl').length == 0) {
                $('#gigyaSocialPopUpControl').addClass('mdcHide');
            }
        });

	    $('#MdcLinkButtonContainer').bind('mouseover', socialLinkPopUp);

	    $(document).click(
            function(event) {
                var $target = $(event.target);
                var elementId = $target.attr("id");
                if (elementId != 'LoginText' && elementId != 'mdcLoginPopUpControl' && $target.parents('#mdcLoginPopUpControl').length == 0) {
                    $('#mdcLoginPopUpControl').addClass('mdcHide');
                }
            });

	    $('#mdcMenu > li').bind('mouseover', mdcMenuOpenTimer);
	    $('#mdcMenu > li').bind('mouseout', mdcMenuCloseTimer);
	    $(document).click(function(event) {
	        if ($(event.target).parents(".mdcMenuLayer").length == 0)
	            mdcMenuClose();
	    });

	    $('#mdcMenu .mdcMenuLayerContent').each(function() {
	        var aMenuColWidth = 195;
	        var aMarginLeft = 10;
	        var aMarginRight = 20;
	        var $target = $(this);
	        var aTabId = $target.parent().parent().attr("id");
	        if (aTabId == "mdcProductsSolutionsTab")
	            aMenuColWidth = 192;

	        if (!isIE6())
	            $target.width(1000 + 'px');
	        var aColArray = $target.find('.Col');
	        var aTotalWidth = 0;
	        for (var i = 0; i < aColArray.length; i++) {
	            aTotalWidth += aMenuColWidth + aMarginRight;
	        }
	        var aWidth = aTotalWidth;

	        //compute the width of News & Events
	        var aTopMenuWidth = $target.parent().siblings('.TopMenu').width() - aMarginLeft - 2;
	        if (aColArray.length == 1 && $(aColArray[0]).width() < aTopMenuWidth) {
	            aWidth = aTopMenuWidth;
	        }
	        else {
	            for (var i = 0; i < aColArray.length; i++)
	                $(aColArray[i]).width(aMenuColWidth + 'px');
	        }
	        $target.width(aWidth + 'px');
	    });

	    $('#mdcMenu .mdcMenuLayer .Col').each(function() {
	        var aMenuColWidth = 195;
	        var aTabId = $(this).parent().parent().parent().attr("id");
	        if (aTabId == "mdcProductsSolutionsTab")
	            aMenuColWidth = 192;

	        var aHrArray = $(this).find("li.Hr");
	        if (aHrArray.length == 0)
	            return;
	        var aMaxLinkLength = 0;
	        var aLinkArray = $(this).find("a");
	        for (var i = 0; i < aLinkArray.length; i++) {
	            if ($(aLinkArray[i]).width() > aMaxLinkLength)
	                aMaxLinkLength = $(aLinkArray[i]).width();
	        }
	        if (aMaxLinkLength != 0 && aMaxLinkLength < aMenuColWidth)
	            aHrArray.width(aMaxLinkLength + 'px');
	    });
	    $('#mdcMenu .mdcMenuLayer').bgiframe();
	    $('#mdcLoginPopUpControl').bgiframe();
	    $("#mdcLoginPage").keydown(function(event) {
	        if (event.which == 13) {
	            $('#mdcLoginControl .mdcEnterBtn').click();
	            event.preventDefault();
	        }
	    });
	    $("#mdcLoginPopUpControl").keydown(function(event) {
	        if (event.which == 13) {
	            $('#mdcLoginPopUpControl .mdcEnterBtn').click();
	            event.preventDefault();
	        }
	    });
	    $("#mdcLoginLinkSocialControl").keydown(function(event) {
	        if (event.which == 13) {
	            $('#mdcLoginLinkSocialControl a.mdc-blue-btn').clickLink();
	            event.preventDefault();
	        }
	    });

	    $.mdc.CouponExpirationNotify.PopUp();
	}
);

jQuery.mdc.researchAlert = {
    GetDimensionInfo: function() {
        return $('#mdcDimensionDetailInfo').text();
    },
    SetAlertForCriteria: function(theUrl) {
        if (null == theUrl || "" == theUrl) {
            var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
            var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
            var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

            var sWidth, sHeight;
            sWidth = document.body.offsetWidth;
            sHeight = document.body.offsetHeight;
            //var backgroundDiv = $('<div id="backgroundDiv" style="position:absolute; top:0; left:0; background:0xffffff; filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75); opacity:0.5;width:' 
            //		+ sWidth + 'px; height:' + sHeight + 'px; z-index:10000;"></div>');
            var bgObj = document.getElementById('backgroundDivForSetAlert');
            if (null == bgObj) {
                bgObj = document.createElement("div");
                // <div   id="bgDiv"   style="position:absolute;   top:0;   background-color:#777;   filter:progid:DXImagesTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);   opacity:0.6;   left:0;   width:918px;   height:768px;   z-index:10000;"> </div>   
                bgObj.setAttribute("id", "backgroundDivForSetAlert");
                bgObj.style.position = "absolute";
                bgObj.style.top = "0";
                bgObj.style.left = "0";
                bgObj.style.background = "#ffffff";
                bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
                bgObj.style.opacity = "0.5";
                bgObj.style.width = sWidth + "px";
                bgObj.style.height = sHeight + "px";
                bgObj.style.zIndex = "10000";
                document.body.appendChild(bgObj);
            }
            bgObj.style.display = "";

            var popUpObj = document.getElementById('mdcSetAlertPopUpDiv');
            if (null == popUpObj) {
                popUpObj = document.createElement("div");
                popUpObj.setAttribute("id", "mdcSetAlertPopUpDiv");
                popUpObj.style.position = "absolute";
                popUpObj.style.left = "50%";
                popUpObj.style.top = "50%";
                popUpObj.style.marginLeft = "-270px";
                popUpObj.style.marginTop = -120 + document.documentElement.scrollTop + "px"; ;
                popUpObj.style.width = "700px";
                popUpObj.style.height = "400px";
                popUpObj.style.zIndex = "10002";
                document.body.appendChild(popUpObj);
            }
            //Must after OuterDiv has been added to DOM
            if (isIE && isWin && !isOpera)
                popUpObj.innerHTML = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="mdcSetAlertPopUp" width="700" height="400" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"><param name="loop" value="false"/><param name="movie" value="/_Layouts/Mdc/Swfs/AlertPopUp_8.0.0.0.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#869ca7" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="transparent" /></object>';
            else
                popUpObj.innerHTML = '<embed id="mdcSetAlertPopUp" src="/_Layouts/Mdc/Swfs/AlertPopUp_8.0.0.0.swf" quality="high" bgcolor="#869ca7" width="700" height="400" name="mdcSetAlertPopUp" align="middle" play="true" loop="false" quality="high" allowscriptaccess="sameDomain" wmode="transparent" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer"></embed>';
            popUpObj.style.display = "";
            document.getElementById('mdcSetAlertPopUp').focus();
        }
        else
            location.href = theUrl;
    }
}

function closeSetAlert() {
    var bkDiv = document.getElementById('backgroundDivForSetAlert');
    bkDiv.style.display = "none";
    var popUp = document.getElementById('mdcSetAlertPopUpDiv');
    popUp.style.display = "none";
}

function sessionTimeout() {
    var aUrl = window.location;
    aUrl = unescape(aUrl);
    var aHeader = 'http://';
    var beginIndex = aUrl.indexOf(aHeader);
    if (-1 != beginIndex) {
        aUrl = aUrl.substring(beginIndex, aUrl.indexOf('/', beginIndex + aHeader.length));
        aUrl += "/login.aspx?ReturnUrl=";
        aUrl += window.location;
        self.location = aUrl;
    }
}

function moveRatingFactorsArea() {
    var popUpObj = document.getElementById('mdcRatingFactorsGridPopUpDiv');
    var bgObj = document.getElementById('backgroundDivForRatingFactorsGrid');

    currentScrollTop = document.documentElement.scrollTop;

    if (popUpObj !== null && popUpObj.style.display != "none") {
        var y = (document.documentElement.scrollTop + (document.documentElement.clientHeight - popUpObj.offsetHeight) / 2) + "px";
        var screenHeight = document.documentElement.clientHeight;
        var top = parseInt(Math.abs(screenHeight - popUpObj.offsetHeight) / 2);

        if (initPopUpObjTop == popUpObj.style.top) {
            previousScrollTop = 0;
            initPopUpObjTop = "-1px";
        }
        else {
            if (currentScrollTop >= previousScrollTop) //scroll down 
            {
                if (popUpObj.offsetTop + parseInt(popUpHeight) < r[3]) {
                    popUpObj.style.top = popUpObj.offsetTop + currentScrollTop - previousScrollTop + "px";
                }
                else if (popUpObj.offsetTop + parseInt(popUpHeight) - r[3] < Math.abs(currentScrollTop - previousScrollTop)) {
                    popUpObj.style.top = popUpObj.offsetTop + popUpObj.offsetTop + parseInt(popUpHeight) - r[3] + "px";
                }

            }
            else //scroll up 
            {
                if (popUpObj.offsetTop + currentScrollTop - previousScrollTop > r[2]) {
                    popUpObj.style.top = popUpObj.offsetTop + currentScrollTop - previousScrollTop + "px";
                }
                //else
                //popUpObj.style.top = r[2];
            }
        }

        var screenWidth = document.documentElement.offsetWidth;
        var left = parseInt(Math.abs(screenWidth - parseInt(popUpObj.style.width)) / 2);
        if (screenWidth < parseInt(popUpObj.style.width))
            popUpObj.style.left = "0px";
        else
            popUpObj.style.left = left + document.documentElement.scrollLeft + "px";
        previousScrollTop = document.documentElement.scrollTop;
    }
}

function closeRatingFactors() {
    var bkDiv = document.getElementById('backgroundDivForRatingFactorsGrid');
    bkDiv.style.display = "none";
    var popUp = document.getElementById('mdcRatingFactorsGridPopUpDiv');
    popUp.style.display = "none";
    document.body.removeChild(popUp);
}

jQuery.mdc.showLoginErrorMsg = function(errorMsg) {
    if (errorMsg) {
        thePage.loginErrorMsg = {
            style: 'ErrorMessage',
            message: errorMsg
        };
    }
    if (thePage.loginErrorMsg) {
        var mdcLoginErrorMsgDiv = $('div[id^="mdcLoginErrorMsgControl"]');
        mdcLoginErrorMsgDiv.removeClass().addClass(thePage.loginErrorMsg.style).mdcShow();
        mdcLoginErrorMsgDiv.find('div.mdcErrorText').each(function() {
            this.innerHTML = thePage.loginErrorMsg.message; //fix jquery.html() bug
        });

        mdcLoginErrorMsgDiv = $('div[id^="mdcLoginPopUpErrorMsgControl"]');
        mdcLoginErrorMsgDiv.mdcShow();
        mdcLoginErrorMsgDiv.find('td.mdcErrorText').html(thePage.loginErrorMsg.message);

        $('div[class^="mdcLoginSuccess"]').mdcHide();
        $('div#mdcLoginAtagControl div.atagUserName').removeClass('atagUserName');
        $('div#mdcLoginControl div.mdcGigyaLine').removeClass('mdcGigyaLine').addClass('mdcGigyaLineForPopUpHint');
        $('div#mdcLoginControl div.mdcGigyaStatement').removeClass('mdcGigyaStatement').addClass('mdcGigyaStatementForPopUpHint');
    }
};

jQuery.mdc.socialLoginRegPopUp = {
    show: function() {
        $('#socialLoginLinkPanel').mdcShow();
    },
    hide: function() {
        $('#socialLoginLinkPanel').mdcHide();
    },
    init: function(gigyaObj) {
        try {
            if (gigyaObj) {
                $('#socialLoginLinkPanel input[id$=hfGigyaData]').val($.stringifyJSON(gigyaObj));
            } else {
                var curGigyaObjStr = $('#socialLoginLinkPanel input[id$=hfGigyaData]').val();
                if (curGigyaObjStr) {
                    gigyaObj = $.toJSON(curGigyaObjStr);
                }
            }
            if (gigyaObj && gigyaObj.user) {
                $('#socialLoginLinkPanel #mdcSocialWelcome span').text(gigyaObj.user.firstName + ' ' + gigyaObj.user.lastName);
                $('#socialLoginLinkPanel').prependTo($('#mdcRightDecorator'));
            }
        } catch (err) { }
        return this;
    }
};

jQuery.mdc.atagOverview = {
    SetRatingFactorsGrid: function() {

        var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
        var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
        var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
        var isFF = (navigator.userAgent.indexOf("Firefox") != -1) ? true : false;

        r = [0, document.documentElement.scrollWidth, 0, document.documentElement.scrollHeight]
        //to judge if the init scroll, that is the grid move to the init position through move the scrollbar
        scrollCount = 0;

        var closeBtnHTML = '<div><a href="#" style="text-decoration:none" onclick="closeRatingFactors()"><img src="/_layouts/Mdc/Images/Close.gif" alt="Close"/></a></div>';

        var sWidth, sHeight;
        sWidth = document.body.offsetWidth;
        sHeight = document.body.offsetHeight;

        var bgObj = document.getElementById('backgroundDivForRatingFactorsGrid');

        if (null == bgObj) {
            bgObj = document.createElement("div");

            bgObj.setAttribute("id", "backgroundDivForRatingFactorsGrid");
            bgObj.style.position = "absolute";
            bgObj.style.top = "0";
            bgObj.style.left = "0";
            bgObj.style.background = "#ffffff";
            bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
            bgObj.style.opacity = "0.5";
            bgObj.style.width = "100%";
            bgObj.style.height = document.documentElement.scrollHeight + "px";
            bgObj.style.zIndex = "10000";
            document.body.appendChild(bgObj);
        }
        bgObj.style.display = "";

        //set popup div height and width
        var ratingFactorGridObj = document.getElementById('mdcRatingFactorsContent');
        var ratingFactorGridContent = ratingFactorGridObj.innerHTML;
        var tableObj = ratingFactorGridObj.getElementsByTagName('table');

        var gridWidth = 660;
        gridWidth = +$("#mdcRatingFactorsContent>table").css("width").replace("px", "") + 50;
        var gridHeight = $("#mdcRatingFactorsContent").height();

        //var gridHeight = ratingFactorGridObj.offsetHeight;	    

        var contentDivWidth = gridWidth + "px";
        var contentDivheight = gridHeight + "px";

        var shadowDivWidth = gridWidth + 20 + "px";
        var shadowDivHeight = gridHeight + 20 + "px";

        var outerDivWidth = shadowDivWidth;
        var outerDivHeight = shadowDivHeight;

        var moveable = false;
        var popUpObj = document.getElementById('mdcRatingFactorsGridPopUpDiv');


        if (null == popUpObj) {
            var bodyHeight = document.body.clientHeight;
            var bodyWidth = document.body.clientWidth;

            popUpObj = document.createElement("div");
            popUpObj.setAttribute("id", "mdcRatingFactorsGridPopUpDiv");
            popUpObj.style.position = "absolute";
            popUpObj.style.width = outerDivWidth;
            popUpObj.style.height = outerDivHeight;
            popUpObj.style.overflow = "hidden";
            popUpObj.style.zIndex = "10002";
            popUpWidth = popUpObj.style.width;
            popUpHeight = popUpObj.style.height;

            var screenWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft;
            var screenHeight = document.documentElement.clientHeight;
            var left = parseInt(Math.abs(screenWidth - parseInt(popUpWidth)) / 2);
            var top = parseInt(Math.abs(screenHeight - parseInt(popUpHeight)) / 2);
            //popUpObj.style.top = (top + document.documentElement.scrollTop) + "px";
            popUpObj.style.left = left + document.documentElement.scrollLeft + "px";
            popUpObj.style.top = document.documentElement.scrollTop + document.documentElement.clientHeight * 0.1 + "px";
            initPopUpObjTop = popUpObj.style.top;

            //start drag
            popUpObj.onmousedown = function(event) {

                if (!event)
                    event = window.event;
                if (isIE)
                    popUpObj.setCapture(false);
                else if (isFF)
                    window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);

                x0 = event.clientX;
                y0 = event.clientY;

                x1 = popUpObj.offsetLeft;
                y1 = popUpObj.offsetTop;

                moveable = true;

            };
            //stop drag
            popUpObj.onmouseup = function(event) {
                if (moveable) {
                    if (isIE)
                        popUpObj.releaseCapture();
                    else if (isFF)
                        window.releaseEvents(Event.MOUSEMOVE | Event.MOUSEUP);

                    moveable = false;
                }
            };

            //start drag
            popUpObj.onmousemove = function(event) {
                if (!event)
                    event = window.event;
                if (moveable) {
                    var x = x1 + event.clientX - x0;
                    var y = y1 + event.clientY - y0;

                    if (x < r[0])
                        popUpObj.style.left = 0 + "px";
                    else if ((x + parseInt(popUpWidth)) > r[1])
                        popUpObj.style.left = r[1] - parseInt(popUpWidth) + "px";
                    else
                        popUpObj.style.left = x1 + event.clientX - x0 + "px";


                    if (y < r[2])
                        popUpObj.style.top = 0 + "px";
                    else if ((y + parseInt(popUpHeight)) > r[3])
                        popUpObj.style.top = r[3] - parseInt(popUpHeight) + "px";
                    else
                        popUpObj.style.top = y1 + event.clientY - y0 + "px";

                }
            };

            document.body.appendChild(popUpObj);
        }
        //Must after OuterDiv has been added to DOM

        popUpObj.innerHTML = '<div id="ratingFactorOutMostDiv" style="width:' + outerDivWidth + '; height:' + outerDivHeight + ';"><div id="ratingFactorShadowDiv" style="width:' + shadowDivWidth + ';height:' + shadowDivHeight + ';"></div><div id="ratingFactorContentDiv" style="width:' + contentDivWidth + ';height:' + contentDivheight + ';"><div class="ratingFactorBorderLine"><div class="ratingFactorBorderDiv"><div><div style="background:#FFFFFF; padding-left: 20px; float: left;width:200px;"><div style="height: 20px;"></div><div class="ratingFactorTitle">Rating Factors</div></div><div style="background: #FFFFFF; padding-right: 10px;float: right;width:17px;"><div style="height: 10px;"></div>' + closeBtnHTML + '</div></div><div class="ratingFactorBorderDivContent"><div style="height: 20px; background:#FFFFFF;"></div><div id="mdcRatingFactorsContent">' + ratingFactorGridContent + '</div></div></div></div></div></div>';
        $('#ratingFactorOutMostDiv').bgiframe();
        popUpObj.style.display = "";
        document.getElementById('mdcRatingFactorsGridPopUpDiv').focus();

        var contentDivHeight = $('.ratingFactorBorderDiv').height();
        $('#ratingFactorContentDiv').height(contentDivHeight);
        var shadowDivHeigth = contentDivHeight + 30;
        $('#ratingFactorShadowDiv').height(shadowDivHeigth);
        $('#ratingFactorOutMostDiv').height(shadowDivHeigth);
        $('#mdcRatingFactorsGridPopUpDivpopUpObj').height(shadowDivHeigth);
        $('#mdcRatingFactorsGridPopUpDiv').height(shadowDivHeigth);
    }

}

jQuery.mdc.CrossLanguageWarning = {
    hoverEnter: function() {
        if ($(this).hasClass('mdcBtnSelected')) return; $(this).addClass('mdcBtnHover');
    },
    hoverLeave: function(obj) {
        if ($(this).hasClass('mdcBtnSelected')) return; $(this).removeClass('mdcBtnHover');
    },
    mousedown: function() {
        $(this).removeClass('mdcBtnHover');
        $(this).addClass('mdcBtnSelected');
    },
    IsFile: function(obj) {
        var theUrl = $(obj).attr("href");
        var dotPos = theUrl.lastIndexOf(".");
        if (dotPos != -1) {
            var suffix = theUrl.substring(dotPos + 1).toLowerCase();
            if (suffix == "doc" || suffix == "docx" || suffix == "pdf" || suffix == "xls" || suffix == "xlsx" || suffix == "ppt" || suffix == "pptx" ||
                suffix == "jpg" || suffix == "bmp" || suffix == "gif" || suffix == "tiff" || suffix == "txt")
                return true;
        }
        return false;
    },
    IsNewWindow: function(obj) {
        var theTarget = $(obj).attr("target");
        if ('_blank' == theTarget)
            return true;
        else
            return false;
    },
    OpenDialog: function() {
        tb_show("", "#TB_inline?inlineId=mdcCrossLanguageWarning&width=480&modal=true&TB_modal_class=CrossLang_TB_modal"); //
        $("#TB_overlay").css({ 'background-color': '#ffffff', 'filter': 'alpha(opacity=50)', '-moz-opacity': '0.5', 'opacity': '0.5' });
        $("#TB_window").css({ 'border': '0px solid #cccccc' });
        $("#TB_window").css({ 'background-color': 'transparent' });
        $("#TB_ajaxContent").css({ "padding": "0px 0px 0px 0px" });
    },

    CrossClick: function(obj, theUrl) {
        $(obj).attr("href", "javascript:void(0)");
        $(obj).attr("target", "");
        $('#clwUrl').val(theUrl);
        $('#clwWindow').val($(obj).attr("crossTarget"));

        if ($.mdc.CrossLanguageWarning.ReadCookie("rememberCrossLanguage") == "Yes")
            $.mdc.CrossLanguageWarning.ToUrl();
        else
            $.mdc.CrossLanguageWarning.OpenDialog();
    },

    IsUSSite: function() {
        var regionVal = $('#clwRegion').attr('regionVal');
        if (regionVal != "" && regionVal != "en")
            return false;
        else
            return true;
    },

    CancelCross: function() {
        if ($('#rememberCrossLanguage').attr("checked")) {
            $.mdc.CrossLanguageWarning.WriteCookie("rememberCrossLanguage", "Yes");
        }
        if ($('#clwId').val() == "typeAhead")
            $('#mdcSearch>div>input').blur();
        $.mdc.CrossLanguageWarning.ClearHiddenVal();
        tb_remove();
    },

    BtnCrossClick: function(obj, idVal) {
        $('#clwId').val(idVal);
        if ($.mdc.CrossLanguageWarning.ReadCookie("rememberCrossLanguage") == "Yes") {
            $(obj).click();
        }
        else
            $.mdc.CrossLanguageWarning.OpenDialog();
    },

    ToUrl: function() {
        if ($('#rememberCrossLanguage').attr("checked")) {
            $.mdc.CrossLanguageWarning.WriteCookie("rememberCrossLanguage", "Yes");
        }
        var idVal = $('#clwId').val();
        if (idVal == "findAnalystBtn") {
            $('#findAnalystBtn').click();
        }
        else if (idVal == "searchBarLink") {
            $('#searchBarLink').click();
        }
        else if (idVal == "typeAhead") {
            $('tr.typeAheadCrossLink').click();
        }
        else if (idVal == "purchaseReportBtn") {
            $('#purchaseReportBtn').click();
            $.mdc.CrossLanguageWarning.ClearHiddenVal();
            tb_remove();
        }
        else {
            if ('_blank' == $('#clwWindow').val()) {
                window.open($('#clwUrl').val());
                $.mdc.CrossLanguageWarning.ClearHiddenVal();
            }
            else
                window.location.href = $('#clwUrl').val();
        }
    },

    ClearHiddenVal: function() {
        $('#clwUrl').val("");
        $('#clwWindow').val("");
        $('#clwId').val("");
        $('#rememberCrossLanguage').attr("checked", false);
    },

    ReadCookie: function(theCookieName) {
        var aCookie = "" + document.cookie;
        var aFirstIndex = aCookie.indexOf(theCookieName + "=");
        if (aFirstIndex == -1 || theCookieName == "")
            return "";
        var aEndIndex = aCookie.indexOf(';', aFirstIndex);
        if (aEndIndex == -1)
            aEndIndex = aCookie.length;
        return aCookie.substring(aFirstIndex + theCookieName.length + 1, aEndIndex);
    },

    WriteCookie: function(theCookieName, theCookieValue) {
        var aExpireTime = new Date(new Date().getTime() + 1000 * 60 * 30);
        document.cookie = theCookieName + "=" + theCookieValue + ";expires=" + aExpireTime.toGMTString() + ";path=/";
    }
};

var opentimeout = 400;
var closetimeout = 600;
var mdcTimer = 0;
var mdcMenuLayer = 0;

function mdcMenuOpen(sender) {
    mdcMenuCancelTimer();
    mdcMenuClose();
    $(sender).addClass("hover");
    mdcMenuLayer = $(sender).find('.mdcMenuLayer').eq(0).css('visibility', 'visible');
}

function mdcMenuClose() {
    mdcMenuCancelTimer();
    if (mdcMenuLayer) {
        mdcMenuLayer.css('visibility', 'hidden');
        $("#mdcMenu > li").removeClass("hover");
    }
}

function mdcMenuOpenTimer() {
    mdcMenuCancelTimer();
    var func = function(li) { return function() { mdcMenuOpen(li) } } (this);
    mdcTimer = window.setTimeout(func, opentimeout);
}

function mdcMenuCloseTimer() {
    mdcMenuCancelTimer();
    mdcTimer = window.setTimeout(mdcMenuClose, closetimeout);
}

function mdcMenuCancelTimer() {
    if (mdcTimer) {
        window.clearTimeout(mdcTimer);
        mdcTimer = null;
    }
}

function isIE6() {
    if (typeof navigator.userAgent.split(";")[1] == "undefined") return false;
    return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 6.0") == "-1" ? false : true;
}

function isIE7() {
    if (typeof navigator.userAgent.split(";")[1] == undefined) return false;
    return navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie 7.0") == "-1" ? false : true;
}

jQuery.mdc.CouponExpirationNotify = {
    PopUp: function() {
        if ($('#mdcCouponNotifyOutside').length > 0) {
            $('#mdcCouponNotifyOutside').height($('#mdcCouponNotifyInside').outerHeight());
            $('#mdcCouponNotifyInside').toggleClass('mdcHide');
            $('#mdcCouponNotifyOutside').toggleClass('mdcHide');
            $('#mdcCouponNotifyInside').center();
            $('#mdcCouponNotifyOutside').center();
            $('#mdcBorderOutside').css("z-index", "1");
            $('#mdcBorderInside').css("z-index", "1");
        }
    }
};

