//Global variable for checking the variation inmfrastructure is enabled
var IsVariationEnabled=false;
var FilterOption1;
var FilterOption2;
(function ($) {

    $(document).ready(function () {

	
        $('#page').addClass('pagebg');
		
		// ---- Logo link redirec to the site home page
		if ($("#LanSRight select").length == 0)
		{
		$('#logo a').attr('href','/')
		$('#GlobalNav').css('width','504px')
		$('#LanguageNav').css('display','none')
		
		
		}

		if($('[id$="variationSelectorDropDown"]').val() != null)
		{
			IsVariationEnabled=true;			
		}		
		
		
        if ($('.pbrand').length < 1) {
            $('#bTop').hide();
        }

        /*
        START .ms-WPBody  object{ style related...
        This code segment is added to fixed the media web part displaying issue.
        first time released this on Client Release 2.2.1.0 of UTCFnS
        */

        //collect all objects under .ms-WPBody div
        if ($('.ms-WPBody  object') != null) {
            $('.ms-WPBody  object').each(function (index) {

                var objectType = $(this).attr('type');

                //Check object is a silverlight object
                if (objectType.indexOf("silverlight") != -1) {
                    //yes silverlight object
                    //get the parent (.ms-WPBody div) width and height

                    var parentWidth = $(this).parent().css('width');
                    var parentHeight = $(this).parent().css('height');

                    //set width height to the object	
                    $(this).css('width', parentWidth);
                    $(this).css('height', parentHeight);
                }

            });
        }

        /*
        END .ms-WPBody  object{ style related...
        */
        /*-------------------------StockQuoteWidget-------------------------------*/
        $('#StockTicker .link').removeAttr('onmouseout').removeAttr('onmouseover');
        var trayDisplay = null;
        var extraLength = 0;
        var trayLegal = document.getElementById('Legal Disclaimer');
        var trayNote = document.getElementById('*Note');
        var tempTray;
        var thisText = '';
        var tempHeight = 0;

        $(trayNote).removeAttr('onmouseout').removeAttr('onmouseover');
        $(trayLegal).removeAttr('onmouseout').removeAttr('onmouseover');

        $('#StockTicker .link').mouseover(function () {
            if (trayDisplay) {
                clearTimeout(trayDisplay);
            }

            if (tempTray) {
                tempTray.hide();
                tempTray = null;
            }

            thisText = $(this).text().replace(/\n+\s+/g, ' ');

            if ($(trayNote).attr('id') == thisText) {
                tempTray = $(trayNote);
            }
            else if ($(trayLegal).attr('id') == thisText) {
                tempTray = $(trayLegal);
            }

            showTray(tempTray);

        });
        $('#StockTicker .link').mouseleave(function () {
            trayDisplay = setTimeout(function () {
                if (tempTray)
                    hideTray(tempTray);
            }, 1000);
        });

        $(trayNote).bind('mouseover', function () {
            if (trayDisplay) clearTimeout(trayDisplay);
            showTray(tempTray);
        });
        $(trayNote).bind('mouseleave', function () {
            trayDisplay = setTimeout(function () {
                if (tempTray)
                    hideTray(tempTray);
            }, 1000);
        });

        $(trayLegal).bind('mouseover', function () {
            if (trayDisplay) clearTimeout(trayDisplay);
            showTray(tempTray);
        });
        $(trayLegal).bind('mouseleave', function () {
            trayDisplay = setTimeout(function () {
                if (tempTray)
                    hideTray(tempTray);
            }, 1000);
        });


        function showTray(tray)//display the tray
        {
            if (tempHeight == 0) tempHeight = $('#wrap').height();

            var trayVlength = tray.parents('.ContentRight').position().top + tray.parents('.ContentRight').height() + tray.height(); //total length required bu the tray
            var wrapHeight = $('#wrap').height();
            var wrapTop = $('#wrap').offset().top;

            if (trayVlength > wrapHeight)//if the tray need more space to display
            {
                if (extraLength < (trayVlength - wrapHeight))//previous extra space is less than new one
                {
                    $('#wrap').height(tempHeight); //set wrap to initial state
                    extraLength = trayVlength - tempHeight; //calculate extra space required by the wraper			
                    $('#wrap').height($('#wrap').height() + extraLength); //set the extra space to the wraper				
                    jQuery(document).scrollTop(jQuery(document).scrollTop() + (extraLength - 100)); //scroll the document automaticaly to the tray
                }
                else {
                    $('#wrap').height($('#wrap').height() - extraLength);
                }
            }

            tray.show();
        }

        function hideTray(tray)//hide the displaying tray
        {
            if (extraLength > 0)//if extra space required for the tray to display below prcedure will execute
            {
                $(document).scrollTop($(document).scrollTop() - (extraLength - 100)); //scroll the document to the previous position
                $('#wrap').height(tempHeight); //set the initial size to the wrap
                extraLength = 0;
                tempHeight = 0;
            }

            tray.hide();
        }

        /*-------------------------StockQuoteWidget-------------------------------*/

        /*------------------------Common Functions-------------------------------*/
        if ($.browser.msie) {
            try { document.execCommand("BackgroundImageCache", false, true); } catch (err) { };
            if (typeof (DD_belatedPNG) != 'undefined') {
                DD_belatedPNG.fix('img, a.close, .actions a, #MainNav ul, #MapSmall div, #MapLarge div, #slideshow .info');
                DD_belatedPNG.fix('.popup, .popup .top, .popup .content, .popup .bottom');
            }
        }

        //Through all the site print
        $("a.print").live('click', function () {
            var hostName = window.location.host;
            var protocolName = window.location.protocol;
            var rootSite = protocolName + "//" + hostName;
            var currentLocation = window.location.href;
            window.open(rootSite + "/Pages/print.aspx?pr=" + currentLocation);
        });

        //Used in download library
        $("a.printImage").live('click', function () {
            var hostName = window.location.host;
            var protocolName = window.location.protocol;
            var rootSite = protocolName + "//" + hostName;
            var currentLocation = window.location.href;
            var lowResImage = $(this).attr("lowResImageSrc");
            window.open(rootSite + "/Pages/printImage.aspx?pr=" + lowResImage);
        });

        $('#CalloutBox li').boxLinks();

        if ($('.slideshow2').length) {
            var slideshow = $('.slideshow2');


            slideshow.find('.slider').jCarouselLite({
                btnPrev: '.slideshow2 a.prev',
                btnNext: '.slideshow2 a.next',
                visible: 3
            });

            slideshow.find('.slider li').boxLinks();
        }


        // Right side column show and hide    
        if ($("#side2").children().size() > 0) {
            // Right side column show
            $("#side2").show();
        }
        else {
            // Right side column hide and width reset  
            $("#side2").hide();
            $("#wrapSec").width(910);
            $("#content").width(750);
            $("#ctl00_MSO_ContentDiv").width(910);
        }

        // Webpart management mepositioning
        if ($("td#MSOTlPn_MainTD")) {
            $('#WebpartManagement').html("");
            $('#MSOTlPn_MainTD').appendTo('#WebpartManagement');
        }

        // Register a JS function to be triggered when a pageload or an ajax response is occurred
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_pageLoaded(pageLoaded);

        // This method gets triggered in a page load or an ajax response
        function pageLoaded(sender, args) {
            var panels = args.get_panelsUpdated();

            // Only in an Ajax response
            if (panels.length > 0) {
                var hiddenAjaxResponseStatusElement = document.getElementById("AjaxResponseStatus");
                // Only if the Email Sender Control is available
                if (hiddenAjaxResponseStatusElement) {
                    // Only if the Email Sender Ajax Postback was successful
                    if (hiddenAjaxResponseStatusElement.value == "Success") {
                        // Hide the popup

                        p = $("#popupEmail")
                        popupHide(p);
                        $('#Preload').hide();
                        $("#popupEmail").css({ top: '', left: '' });
                    }
                }
            }
        }

        if ($('.ms-cui-tts').css('display') == undefined) {
            $('#MainImage').children('div').eq(3).css('display', 'none');
        }

        //Remove the empty p elements
        $('p').each(function () {
            if ($.trim($(this).html()).match(/&nbsp;/g)) {
                $(this).html($.trim($.trim($(this).html().replace("&nbsp;", " "))));
            }
        });

        //Remove &nbsp; from headers 
        $('h1').each(function () {
            if ($(this).html().match(/&nbsp;/g)) {
                var strNoSpaces = $(this).html().replace(/&nbsp;/g, '');
                $(this).html(strNoSpaces);
            }
        });

        /* --------------- Remove &nbsp; from page ( e )------------------*/
        $('#pdesc').each(function () {
            $(this).contents().filter(function () {
                if (this.nodeType == 3) {
                    $(this).wrap("<p></p>");
                }
            });

            var elements = $(this).children('div,p,span');

            if (elements.length > 0) {
                var stemp1 = elements.text().trim();
                elements.remove();
                $(this).children().remove();
                $(this).append('<p>' + stemp1 + '</p>');
            }
            $(this).show();
        });

        $('.product').each(function () {
            $(this).contents().filter(function () {
                if (this.nodeType == 3) {
                    $(this).wrap("<p></p>");
                }
            });

            var elements = $(this).children('div,p,span').filter(function () {
                if ($(this).hasClass('image1'))
                    return;
                else if ($(this).parent().hasClass('pbrand'))
                    return
                else
                    return $(this);
            });

            if (elements.length > 0) {
                var stemp1 = elements.text().trim();
                elements.remove();
                $(this).children('h3').eq(0).after('<p>' + stemp1 + '</p>');
            }
            $(this).show();
        });

        $('.brand').each(function () {
            $(this).contents().filter(function () {
                if (this.nodeType == 3) {
                    $(this).wrap("<p></p>");
                }
            });

            var elements = $(this).children('div,p').filter(function () {
                if ($(this).hasClass('image2'))
                    return;
                else
                    return $(this);
            });

            if (elements.length > 0) {
                var stemp1 = elements.text().trim();
                elements.remove();

                $(this).children('h3').eq(0).after('<div>' + stemp1 + '</div>');

            }
            $(this).show();
        });

        /* --------------- Remove &nbsp; from page ( E )------------------*/

        // Titile in editable area
        if (jQuery.browser.version == "7.0") {

            $("input[id$='TextField']").before("<br/>");
        }


        function createBreadcrumb(document, relatedPage) {
		//alert('createBreadcrumb');
            var currentWeb = document.location.href.split('?', 1)[0].split('/');
            var currentPage = currentWeb[currentWeb.length - 1].split('.')[0];

            if (relatedPage == "Press Releases") {
                // hack for showing the page title in the edit mode
                if ($("#PressReleaseLayout").find(':input').length > 0) {
                    currentPage = $("#PressReleaseLayout").find(':input').val();
                }
                else {
                    currentPage = $("#PressReleaseLayout").text();
                }
            }
            else if (relatedPage == "Case Studies") {
                // hack for showing the page title in the edit mode
                if ($("#CaseStudyPageLayout").find(':input').length > 0) {
                    currentPage = $("#CaseStudyPageLayout").find(':input').val();
                }
                else {
                    currentPage = $("#CaseStudyPageLayout").text();
                }
            }

            var currentWebPath;
                currentWebPath = document.location.href.split('?', 1)[0].split("/Pages/")[0].split("http://")[1].split('/');

            var breadcrumb = "";
            var currentUrl = "";
			if(IsVariationEnabled)
			{
				currentUrl = "http://" + currentWebPath[0]+"/"+currentWebPath[1];
			}
			else
			{
				currentUrl = "http://" + currentWebPath[0];
			}
            var isRootWeb = true;
            //Home node
            var home = "<a href = '" + currentUrl + "'>Home</a>&nbsp;&nbsp;&gt;&nbsp;";

            //Subweb nodes
            for (var iterator = 1; iterator < currentWebPath.length; iterator++) {
                isRootWeb = false;
				if(IsVariationEnabled && iterator==1) // Skip for the variation web
				{
					continue;
				}
                currentUrl += "/" + currentWebPath[iterator];
                if (iterator == 2) {
                    breadcrumb += "<td><table><tr><td><span id = 'SubSite" + iterator + "'><a href = '" + currentUrl + "'>" + currentWebPath[iterator] + "</a></span></td></tr></table></td>";
                }
                else {
					if(IsVariationEnabled){
						breadcrumb += "<td><table><tr><td><span id = 'SubSite" + iterator + "'>&nbsp;&nbsp;>&nbsp;&nbsp;<a href = '" + currentUrl + "'>" + currentWebPath[iterator] + "</a></span></td></tr></table></td>";
					}
					else{
					 breadcrumb += "<td><table><tr><td><span id = 'SubSite" + iterator + "'><a href = '" + currentUrl + "'>" + currentWebPath[iterator] + "</a></span></td></tr></table></td>";
					}
				}
            }
			
            //Landing page node
				var defaultUrl;
                var defaultTitle;
			
			    // hack for showing the page URL in the edit mode
                if ($("#DefaultUrl").find(':input').length > 0) {
                    defaultUrl = $("#DefaultUrl").find(':input').val();
                }
                else {
                    defaultUrl = $("#DefaultUrl").text().trim();
                }
				
				// hack for showing the page title in the edit mode
                if ($("#DefaultTitle").find(':input').length > 0) {
                    defaultTitle = $("#DefaultTitle").find(':input').val();
                }
                else {
                    defaultTitle = $("#DefaultTitle").text().trim();
                }

                if (defaultUrl == "" || defaultUrl == null) {
                    defaultUrl = "";
                }

                if (defaultTitle == "" || defaultTitle == null) {
                    defaultTitle = relatedPage;
                }

                if (defaultUrl.charAt(0) == '/') {
                    defaultUrl = "http://" + document.location.href.split("http://")[1].split("/")[0] + defaultUrl;
                }

                if (isRootWeb) {
                    breadcrumb += "<td><table><tr><td><span id = 'landingPage'><a href = '" + defaultUrl + "'>" + defaultTitle + "</a></span></td></tr></table></td>";
                }
                else {
                    breadcrumb += "<td><table><tr><td><span id = 'landingPage'>&nbsp;&nbsp;>&nbsp;&nbsp;<a href = '" + defaultUrl + "'>" + defaultTitle + "</a></span></td></tr></table></td>";
                }


            //current page node
            breadcrumb += "<td></td><td><table><tr><td><span id = 'Page'>" + currentPage + "</span></td></tr></table></td>";

            //replacing existing content
            $("td.breadcrumbs").each(function (index) {
                if (index == 0) {
                    $(this).attr('id', 'tdhome');
                    $(this)[0].innerHTML = '<span id="sphome">' + home + '</span>';
                }
                else if (index == 1) {
                    $(this)[0].innerHTML = '<table cellspacing="0"><tr>' + breadcrumb + '</tr></table>';
                }
            });			
        }

        //Press Release Bread Crumb Fix
        if ($("#PressReleaseLayout").length > 0) {
            createBreadcrumb(document, 'Press Releases');
        }

        //Case Study Bread Crumb Fix
        else if ($("#CaseStudyPageLayout").length > 0) {
            createBreadcrumb(document, 'Case Studies');
        }

        //Breadcrumbs--------------------------------------------------------------------------------------------------------------------------------------------

        RemoveLastNodeLink(); // remove the link from the last node and make is as a plain text node.


        $("td.breadcrumbs > a").remove(); //Remove unnecessary a tags

        var firstNode = $("td.breadcrumbs:eq(1)>table>tbody>tr>td:first a").text();

        //Check wheather the second breadcrumb contains a home text
        if (firstNode == "Home") {
            $("td.breadcrumbs:eq(1)>table>tbody>tr>td:first").remove(); //Remove home text and the
            $("td.breadcrumbs:eq(1)>table>tbody>tr>td:first").remove(); // '>' symbol
            $('td#tdhome span#sphome').html("<a href='/'></a>&nbsp;&nbsp;&gt;&nbsp;"); //Add '>' symbol to home tag
        }
        else {		
            if ($('#tdhome').length < 1) {
                if ($('.titlerow-table .breadcrumbs>table>tbody>tr>td').length == 1) {
                    $('td.breadcrumbs:eq(0)').attr('id', 'tdhome').html('<span id="sphome"><a href="/">Home</a></span>');
                }
                else {
                    $('td.breadcrumbs:eq(0)').attr('id', 'tdhome').html('<span id="sphome"><a href="/">Home</a>&nbsp;&nbsp;&gt;&nbsp;</span>');
                }
            }
            else {
                $('td#tdhome span#sphome').html("<a href='/'>Home</a>&nbsp;&nbsp;&gt;&nbsp;"); //Add '>' symbol to home tag
            }
        }
		//alert('before check');
		// Replacing Home text with variation text and remove the second node
		if(IsVariationEnabled)
		{
		//alert('In');
			SetVariationHomeText();
		}
		//alert('after check');
        ApplyBreadCrumbSeperator(); //Apply '>' symbol for empty nodes

        FixBreadCrumbWidth(); //Dynamically set the width of each breadcrumb node

		
        //Breadcrumbs--------------------------------------------------------------------------------------------------------------------------------------------

        //Remove empty image tags for fire and security products 
        $(".productsThumbnail").each(function () {
            if ($(this).attr("src").length == 0) {
                $(this).remove();
            }
        });

        $('#search input').each(function () {
            this._default = this.value;
            $(this).focus(function () {
                if (this.value == this._default)
                    this.value = '';
            }).blur(function () {
                if (this.value == '')
                    this.value = this._default;
            });
        });

        $("#LaunchHistoricalTimelineButton").click(function () {
            var HistoricalTimeline = $("#LaunchHistoricalTimelineButton").position();
            $("#LaunchHistoricalTimelinePopUp").removeClass("popupHide").css({ top: HistoricalTimeline.top - 35, left: HistoricalTimeline.left - 0 });
        });

        $("#LaunchRssButton").click(function (e) {
            var LaunchRss = $("#LaunchRssButton").position();
            $("#LaunchRssPopUp").removeClass("popupHide").css({ top: (LaunchRss.top + 35), left: (LaunchRss.left - 120) });
            e.preventDefault();
        });

        $('#GlobalNav .lang a').click(function () {
            $('#popupLang').removeClass('popupHide').css({ left: '50%', top: '200px' });
            $('#overlay').show();
            $(document.body).bind('click', bodyClick);
            return false;
        });

        var h = Math.max($(document).height(), $(window).height());
        $('#overlay').height(h - 90);

        $('.filters h6.toggle a').click(function () {
            var resourceKeys=new Array();
		    resourceKeys[0] ="FilterByText";
		    resourceKeys[1] ="FilterOptionsText";
            ToggleClasses(resourceKeys);
          return false;
        });

        //Sets the Related Documents description limit
        $('[id$="_descriptionTextBox"]').keypress(function () {
            limitNum = 50;
            if ($(this).val().length > limitNum) {
                $(this).val($(this).val().substring(0, limitNum));
            }
        });

        /*--------------------------Dropdown Box------------------------------*/
        var tSel = null;

        function cancelSel() {
            if (tSel) {
                clearTimeout(tSel);
                tSel = null;
            }
        }

        function setSel(w) {
            w = w || $('div.select1');
            tSel = setTimeout(function () {
                w.removeClass('select1Active');
            }, 200);
        }

        var zi = 99;

        $('.select1').each(function () {
            var s = $(this).hide();
            s.wrap('<div class="select1 selectArea-' + s[0].name + ' cf"></div>');
            var w = s.parents('.select1').css({ zIndex: zi-- });
            w.append('<a class="main" href="#"><span></span></a><ul></ul>');
            var a = w.find('a.main'), ul = w.find('ul'), l = 0;

            if (this.options != null) {
                for (var i = 0; i < this.options.length; i++) {
                    ul.append('<li><a href="#" class="index-' + i + '">' + this.options[i].text + '</a></li>');
                    l = Math.max(l, this.options[i].text.length);
                }

                $('.select1 a.main').unbind('click');
                $('.select1 a.main').bind('click', dropDownClicked);
                $('.select1 ul a').unbind('click');
                $('.select1 ul a').bind('click', dropDownElementClicked);

                a.find('span').html(this.options[this.selectedIndex].text);
            }

            function bodyClickSelect(ev) {
                var el = $(ev.originalTarget);
                if (!el.hasClass('select1') && !el.parents('div.select1').length) {
                    setSel();
                    $('.select1 a.main').unbind('click');
                    $('.select1 a.main').bind('click', dropDownClicked);
                }
            }

            function dropDownElementClicked() {
                var w = $(this).parents('.select1'), a = w.find('a.main'), ul = w.find('ul');
                var sl = w.find('select.select1');
                var i = parseInt(this.className.split('-')[1]);
                sl.selectedIndex = i;
                var options = sl.find('option');

                for (var index = 0; index < options.length; index++) {
                    if ($(options.get(index)).attr('selected') != false) {
                        options.removeAttr('selected');
                    }

                    if (index == i) {
                        $(options.get(index)).attr('selected', 'selected');
                    }
                }

                if (sl.attr('onchange') != null) {
                    sl.trigger('onchange');
                }
                else {
                    a.find('span').html(this.innerHTML);
                    w.removeClass('select1Active');

                    $(this).unbind('click');
                    a.unbind('click');
                    a.bind('click', dropDownClicked);
                }

                return false;
            }

            function dropDownClicked() {
                var a = $(this), w = a.parents('.select1'), ul = w.find('ul');
                ul.css('width', 150);

                if (w.hasClass('select1Active')) {
                    w.removeClass('select1Active');
                }
                else {
                    $(document.body).unbind('click', bodyClickSelect);
                    $(document.body).bind('click', bodyClickSelect);
                    a.unbind('click');
                    w.addClass('select1Active');
                    $('.select1 ul a').unbind('click');
                    $('.select1 ul a').bind('click', dropDownElementClicked);
                }
                return false;
            }
        });

		/*-------------------------------------------------------------*/
        /*----------------------Share Popup---------------------------*/
        //Display share popup	
        $("a.share").live('click', function (e) {
            $("#popupShare").removeClass("popupHide");
            var l;
            var t;

            //Share popup alignment inside the popup - Product Showcase.
            if ($(".pp_inline").hasClass("popupTabs")) {
                var self = $('.pp_inline p.actions"'), pos = self.position();
                l = pos['left'] - $("#popupShare").outerWidth();
                t = pos['top'] - 35;
            }
            else if ($(".pp_inline div.image p.actions").length > 0 || $(".pp_inline div.video p.actions").length > 0) {
                //Share popup alignment inside the popup - Download Library.
                if ($("#actions2").length > 0) {
                    var self = $("#actions2");
                    var pos = self.position();
                    l = pos['left'] - $("#popupShare").outerWidth() + 10;
                    t = pos['top'] - 29;
                }
                //Share popup alignment inside the popup -Case Study.
                else {
                    var self = $('.pp_inline p.actions"');
                    var pos = self.position();
                    l = pos['left'] - 84;
                    t = pos['top'] - 100;
                }
            }
            //Share popup alignment for general places.
            else {
                var self = $(this).parent(), pos = self.position();
                l = pos['left'] - $("#popupShare").outerWidth();
                t = pos['top'] - 35;
            }

            $("#popupShare").css({ top: t, left: l });
            $("#popupShare").show();
            e.preventDefault();
        });

        //Display e-mail popup
        $('.email a.emailpop').live('click', function (e) {
            // var hide = $('.popup a.close').parent('.popup');

            $('#popupShare').addClass('popupHide').css({ left: '', top: '' });
            ps = $('#popupShare')
            popupHide(ps);

            $("#popupEmail").removeClass("popupHide");

            var l;
            var t;

            //Email popup alignment inside the popup - Product Showcase.
            if ($(".pp_inline").hasClass("popupTabs")) {
                var self = $('.pp_inline p.actions"'), pos = self.position();
                l = pos['left'] - $("#popupEmail").outerWidth();
                t = pos['top'] - 35;
            }
            else if ($(".pp_inline p.actions").length > 0) {
                //Email popup alignment inside the popup - Download Library Images.
                if ($("#actions2").length > 0) {
                    var self = $(".pp_inline p.actions"), pos = self.position();
                    l = pos['left'] - $("#popupEmail").outerWidth() + 10;
                    t = (pos['top'] - $("#popupEmail").outerHeight()) + 100;
                }
                //Share popup alignment inside the popup -Case Study.
                else {
                    var self = $('.pp_inline p.actions"');
                    var pos = self.position();
                    l = pos['left'] - 84;
                    t = pos['top'] - $("#popupEmail").outerHeight();
                }
            }
            //Share popup alignment for general places.
            else {
                var self = $(this).parents('.popup').siblings('.actions'), pos = self.position();
                l = pos['left'] - $("#popupEmail").outerWidth();
                t = pos['top'] - 35;
            }
            $("#popupEmail").css({ top: t, left: l });
            $("#popupEmail").show();
            e.preventDefault();
        });

        //Hide e-mail popup
        $('.popup a.close').live('click', function () {

            var thisid = $(this).parent().attr('id');

            if (thisid.indexOf('EmailPopupUpdatePanel') > -1) {
                var temp = $('textarea[id $= "messageTextBox"]').val();

                $(':input', '#popupEmail')
				 .not(':button, :submit, :reset, :hidden')
				 .val('')
				 .removeAttr('checked')
				 .removeAttr('selected')
				 .removeAttr('style');
                $('span.error').hide();
                $(this).parent().children('textarea').attr('readonly', 'readonly');
                $('span[id$="_SuccessMessageLabel"]').hide();
                $('textarea[id $= "messageTextBox"]').val(temp);
                var p = $(this).parent().parent().parent();
                popupHide(p);
                return false;
            }

            var p = $(this).parent('.popup');
            popupHide(p);
            return false;
        });

        function bodyClick(ev) {
            var el = $(ev.originalTarget);
            if (!el.hasClass('popup') && !el.parents('.popup').length)
                popupHide();
        }

        function popupHide(p) {
            if (!p)
                p = $('.popup');
            p.addClass('popupHide').css({ left: '', top: '' });
            $(document.body).unbind('click', bodyClick);
            $('#overlay').hide();
        }

        /*----------------------Popup-------------------------*/
        var tPopup5 = null;
        $('.brand .image2 a').hover(function () {
            if (tPopup5)
                clearTimeout(tPopup5);
            popupHide();
            var self = $(this), id = self.parents('.brand')[0].id, p = $('#popup-' + id), pos = self.offset();
            var l = pos['left'] + self.outerWidth() - 10;
            var t = pos['top'] - 10;
            p.removeClass('popupHide').css({
                left: l + 'px',
                top: t + 'px'
            });
        }, function () {
            var self = $(this), id = self.parents('.brand')[0].id, p = $('#popup-' + id);
            tPopup5 = setTimeout(function () {
                popupHide(p);
            }, 400);
        });
        $('.popup5').hover(function () {
            if (tPopup5)
                clearTimeout(tPopup5);
        }, function () {
            var self = $(this);
            tPopup5 = setTimeout(function () {
                popupHide(self);
            }, 400);
        });


    }); //End of document.ready function	

    /*-----------------------Modal Popup-------------------------*/
    $.ShowPop = function (options) {
        var settings = {
            'width': 400,
            'height': 175,
            'message': 'null',
            'title': 'null',
            'button': 'yesno',
            'ismodel': true,
            'ifpositivefunction': 'null',
            'ifnegativefunction': 'null'
        };

        if (options) {
            $.extend(settings, options);
        }

        if ($(document).find('.popholder').length < 1) {
            $('body').append('	<div class="popholder"> \
							<div class="popoverlay"></div> \
							<div class="popwraper"> \
								<a class="btnclose" href="#">Close </a> \
								<div class="poptop"> \
									<div class="top_l"></div> \
									<div class="top_m"></div> \
									<div class="top_r"></div> \
								</div> \
								<div class="popmiddle"> \
									<div class="mid_l"></div> \
									<div class="mid_m"> \
										<div class="poptitle"></div> \
										<div class="popbody"></div> \
										<div class="popfooter"></div> \
									</div> \
									<div class="mid_r"></div> \
								</div> \
								<div class="popbottom"> \
									<div class="bot_l"></div> \
									<div class="bot_m"></div> \
									<div class="bot_r"></div> \
								</div> \
							</div> \
						</div>');
        }
        else {
            return;
        }

        $('.popwraper').width(settings.width);
        $('.top_m').width(settings.width - 20);
        $('.mid_m').width(settings.width - 20);
        $('.bot_m').width(settings.width - 20);

        $('.popwraper').height(settings.height);
        $('.mid_l').height(settings.height - 20);
        $('.mid_m').height(settings.height - 20);
        $('.mid_r').height(settings.height - 20);

        $('.poptitle').html(settings.title);
        $('.popbody').html(settings.message);

        $('.popholder').css('height', $(document).height()).css('top', '0px');

        if (settings.button == 'yesno') {
            $('.popfooter').append('<input id="btnno" class="popbutton" type="button" value="No"/>');
            $('.popfooter').append('<input id="btnyes" class="popbutton" type="button" value="Yes"/>');

            if (settings.ifpositivefunction != 'null')
                $('#btnyes').bind('mousedown', settings.ifpositivefunction);
            if (settings.ifnegativefunction != 'null')
                $('#btnno').bind('mousedown', settings.ifnegativefunction);

            $('#btnyes, #btnno').bind('mouseup', function () { $(document).find('.popholder').hide().remove(); $('html').css('overflow', 'auto'); });
        }
        else if (settings.button == 'ok') {
            $('.popfooter').append('<input id="btnok" class="popbutton" type="button" value="Ok"/>');

            if (settings.ifpositivefunction != 'null')
                $('#btnok').bind('mousedown', settings.ifpositivefunction);

            $('#btnok').bind('mouseup', function () { $(document).find('.popholder').hide().remove(); $('html').css('overflow', 'auto'); });
        }
        else if (settings.button == 'yes') {
            $('.popfooter').append('<input id="btnyes" class="popbutton" type="button" value="Yes"/>');

            if (settings.ifpositivefunction != 'null')
                $('#btnyes').bind('mousedown', settings.ifpositivefunction);

            $('#btnyes').bind('mouseup', function () { $(document).find('.popholder').hide().remove(); $('html').css('overflow', 'auto'); });
        }
        else if (settings.button == 'ok') {
            $('.popfooter').append('<input id="btnok" class="popbutton" type="button" value="Yes"/>');

            if (settings.ifpositivefunction != 'null')
                $('#btnok').bind('mousedown', settings.ifpositivefunction);

            $('#btnok').bind('mouseup', function () { $(document).find('.popholder').hide().remove(); $('html').css('overflow', 'auto'); });
        }
        else if (settings.button == 'yescancel') {
            $('.popfooter').append('<input id="btncancel" class="popbutton" type="button" value="Cancel"/>');
            $('.popfooter').append('<input id="btnyes" class="popbutton" type="button" value="Yes"/>');

            if (settings.ifpositivefunction != 'null')
                $('#btnyes').bind('mousedown', settings.ifpositivefunction);
            if (settings.ifnegativefunction != 'null')
                $('#btncancel').bind('mousedown', settings.ifnegativefunction);

            $('#btnyes, #btncancel').bind('mouseup', function () { $(document).find('.popholder').hide().remove(); $('html').css('overflow', 'auto'); });
        }

        if ($.browser.msie) {
            $('.popholder').show();
        }
        else {
            $('.popholder').fadeTo(300, 1);
            $('.popoverlay').fadeTo(1, 0.95);
            $('.popwraper').fadeTo(1, 1);
        }

        centerForm();
        $(document).css('overflow', 'hidden');

        $('.popholder').click(function () {
            if (!settings.ismodel) {
                $(document).find('.popholder').hide().remove();
                $('html').css('overflow', 'auto');
            }
        });

        $('.btnclose').click(function () {
            $(document).find('.popholder').hide().remove();
            $('html').css('overflow', 'auto');
        });

        $('.popwraper').click(function () {
            return false;
        });

        $(window).resize(function () {
            centerForm();
        });

        $(window).scroll(function () {
            centerForm();
        });

        function centerForm() {
            pHeight = $(window).height() / 2;
            pWidth = $(window).width() / 2;

            cHeight = $('.popwraper').height() / 2;
            cWidth = $('.popwraper').width() / 2;
            xpos = pWidth - cWidth;
            ypos = pHeight - cHeight;
            $('.popwraper').offset({ top: ypos + $(document).scrollTop(), left: xpos });
        }
    }

    /*------------------UTC Button----------------------*/
    $.fn.IsUtcButton = function (options) {
        var settings = {};

        if (options) {
            $.extend(settings, options);
        }

        $(this).css({ 'margin': '0px', 'background': 'none', 'border': '0px', 'padding': '0px', 'height': 'auto', 'width': 'auto', 'float': 'left', 'margin': '0px' });

        var btnholder = "<div class='btn_holder'></div>";
        var btnright = "<div class='btn_right'></div>";

        $(this).wrap(btnholder).parent().css(settings.holderstyle);

        $(this).css(settings.innerstyle);

        $(this).after(btnright);

        $(this).css('margin-left', settings.paddingleft);
        $(this).css('margin-right', (settings.paddingleft - 6));

        var pwidth = $(this).outerWidth() + ((settings.paddingleft * 2) - 6) + 6;
        $(this).parent().css('width', pwidth + 'px');

        var ctop = ($(this).parent().innerHeight() / 2) - ($(this).outerHeight() / 2);
        $(this).css('top', ctop);

        $(this).parent().mouseover(function () {
            $(this).css('background-position', '0px -32px');
            $(this).children('.btn_right').css('background-position', '0 -32');
        });

        $(this).parent().mouseout(function () {
            $(this).css('background-position', '0px 0px');
            $(this).children('.btn_right').css('background-position', '0px 0px');
        });
    }

    /*-----------------------Custom Plugins--------------------------*/
    $.fn.equalHeights = function (add) {
        var tallest = 0;
        $(this).each(function () {
            tallest = Math.max(tallest, $(this).outerHeight());
        });
        $(this).each(function () {
            var t = $(this), p = 0;
            $.each(['borderTopWidth', 'paddingTop', 'paddingBottom', 'borderBottomWidth'], function (i, n) {
                p += parseInt(t.css(n));
            });
            var h = tallest - p;
            if (add && add[this.id])
                h += add[this.id];
            if ($.browser.msie && $.browser.version <= 6)
                t.css({ 'height': h });
            t.css({ 'min-height': h });
        });
        return this;
    };

    //Used for the slider/////////////////////////////////////////////////////////
    $.fn.boxLinks = function (settings) {
        if (!this.length)
            return;

        var items = this, options = $.extend({
            trigger: 'a',
            classHover: 'hover',
            classFocus: 'focus'
        }, settings || {});

        items.filter(function () {
            return $(this).find(options.trigger).length > 0;
        }).each(function () {
            var self = $(this), t = self.css('cursor', 'pointer').find(options.trigger);
            $.data(this, 'trigger', t);
            $.data(t[0], 'parent', self);
        }).bind('mouseenter', function () {
            var t = $.data(this, 'trigger');
            $(this).addClass(options.classHover);
            window.status = t.attr('href');
        }).bind('mouseleave', function () {
            $(this).removeClass(options.classHover);
            window.status = '';
        }).bind('click', function (ev) {
            var t = $.data(this, 'trigger');
            t.trigger('click');
            ev.stopPropagation();
            return false;
        });

        items.find(options.trigger).bind('focus', function () {
            var parent = $.data(this, 'parent');
            parent.addClass(options.classFocus);
        }).bind('blur', function () {
            var parent = $.data(this, 'parent');
            parent.removeClass(options.classFocus);
        }).click(function (ev) {
            window.location = $(this).attr('href');
            ev.stopPropagation();
            return false;
        });

        return items;
    };


})(jQuery);

/*---------------async function to get the variation Home text ------------------*/
function SetVariationHomeText() {
	//alert('In');
	var loca = location.href;
	//alert(loca);
	var resourceFil = "UTC.FS.Framework.Common.Resources";
	var resourceK = "Home";
	InitXmlHttp();
	xmlhttp.onreadystatechange = XMLHttpRequestCompleted;
	xmlhttp.open("POST", "" + "/_layouts/UTC.FS.Framework.Common/JavascriptHandler/ScriptTranslator.ashx?currentUrl=" + loca + "&resourceFile=" + resourceFil + "&resourceKey=" + resourceK, true);
	xmlhttp.send(null);
}
		//Callback function 
function XMLHttpRequestCompleted() {
	if (xmlhttp.readyState == 4) {
		try {		
			var contents = xmlhttp.responseText.split(',');
			var appendHtml = "&nbsp;&nbsp;&gt;&nbsp";
			//get the variation web url
			var variationWebUrl="";
			if ($("#PressReleaseLayout").length > 0 || $("#CaseStudyPageLayout").length > 0) {
				var variationWebUrlArray = $("td.breadcrumbs:eq(1)>table>tbody>tr>td:first a").attr('href').split('/');
				variationWebUrl = "http://"+variationWebUrlArray[2]+"/"+variationWebUrlArray[3];

				var currentWebUrl = document.location.href.split('/');
				if (currentWebUrl[4] == "Pages")//checking the page reside on variation root
				{
				    jQuery('.titlerow-table #tdhome').css('width', '28px');
				    appendHtml = "";
				}				
			}
			else
			{				
				var currentWebUrl = document.location.href.split('/');
				variationWebUrl = "http://"+currentWebUrl[2]+"/"+currentWebUrl[3];				
				//$('td#tdhome span#sphome').html("<a href='"+variationWebUrl+"'>"+contents[0]+"</a>&nbsp;&nbsp;&gt;&nbsp");
				
				//Remove variation root web text
				var varationUrl = $("td.breadcrumbs:eq(1)>table>tbody>tr>td:first a").attr('href');
				if(varationUrl != null){
					if(variationWebUrl == varationUrl){
						$("td.breadcrumbs:eq(1)>table>tbody>tr>td:first").remove();
						appendHtml="";
						jQuery('.titlerow-table #tdhome').css('width','28px');						
					}
				}				
			}	
			 $('td#tdhome span#sphome').html("<a href='"+variationWebUrl+"'>"+contents[0]+"</a>"+appendHtml);
									
		}
		catch (e) {
			//alert( e.message);        
		}
	}

}

function InitXmlHttp() {
    // Attempt to initialize xmlhttp object
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        // Try to use different activex object
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (E) {
            xmlhttp = false;
        }
    }
    // If not initialized, create XMLHttpRequest object
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        xmlhttp = new XMLHttpRequest();
    }    
}
/*---------------async function to get the variation Home text end------------------*/
		
//Dynamic Fix for BreadCrumb alignment.
function FixBreadCrumbWidth() {

    jQuery('.titlerow-table').css('table-layout', 'fixed');
    jQuery('.titlerow-table .breadcrumbs table').css('table-layout', 'fixed');
    jQuery('.titlerow-table').width(jQuery('#content').innerWidth());

    var bread_links_holder = jQuery('.titlerow-table .breadcrumbs:eq(1)>table');

	//alert($('td#tdhome span#sphome').outerWidth());
	//alert(bread_links_holder.offset().left);
	if( jQuery('.titlerow-table #tdhome').width() != 28)
	{
		 if (jQuery('.titlerow-table .breadcrumbs>table>tbody>tr>td').length == 1) {
			 jQuery('.titlerow-table #tdhome').width('42px');
			 jQuery('.titlerow-table #tdhome').find('*').width('42px');
		 }
		 else {
			 jQuery('.titlerow-table #tdhome').width('47px');
			 jQuery('.titlerow-table #tdhome').find('*').width('47px');
		 }
	 }
	//bread_links_holder.offset().left = $('td#tdhome span#sphome').offset().left+$('td#tdhome span#sphome').outerWidth();
	//jQuery('.titlerow-table #tdhome').css('paddingRight','15px');

    jQuery('.titlerow-table #tdhome').find('a,span').css({ 'white-space': 'nowrap' });
    bread_links_holder.width(jQuery('.titlerow-table').width() - jQuery('.titlerow-table #tdhome').width());
    bread_links_holder.children('tbody').width(jQuery('.titlerow-table').width() - jQuery('.titlerow-table #tdhome').width());
    bread_links_holder.children('tbody').children('tr').width(jQuery('.titlerow-table').width() - jQuery('.titlerow-table #tdhome').width());
    bread_links_holder.parent().width(jQuery('.titlerow-table').width() - jQuery('.titlerow-table #tdhome').width());

    var b_links = 0;
    var b_links_width = 0;
    var bs_links_width = 0;
    var b_cells = jQuery('.titlerow-table .breadcrumbs:eq(1)>table>tbody>tr>td');

    b_cells.each(function () {
        children = jQuery(this).children().length;
        jQuery(this).find('a,span').css({ 'white-space': 'nowrap', 'width': 'auto' });

        if (children > 0) {
            var temp = jQuery(this).find('a,span');
            jQuery(this).html(temp.eq(0).wrap('<table><tr><td></td></tr></table>'));
            var childWidth = temp.eq(0).outerWidth();

            jQuery(this).width(childWidth);
            jQuery(this).find('*').width(childWidth);
            b_links++;
            b_links_width += childWidth;
            jQuery(this).addClass('blink');
        }
        else {
            jQuery(this).addClass('bslink');
            jQuery(this).width('17px');
            bs_links_width += 17;
        }
    });

    if (jQuery('.bslink').length == 1) {
        jQuery('.bslink:last').width('7px');
        jQuery('.bslink:last').text('');
        bs_links_width = 7;
    }
    else {
        if (jQuery('.bslink').length > 0) {
            jQuery('.bslink:last').width('7px');
            jQuery('.bslink:last').text('');
            bs_links_width -= 10;
        }
    }

    jQuery('.blink').css('overflow', 'hidden');

    var total_links_width = b_links_width + bs_links_width;
    var actual_links_width = 0;

    if (total_links_width > bread_links_holder.parent().width()) {
        actual_links_width = bread_links_holder.parent().width() - bs_links_width;
        actual_links_width -= 1; //hack for avoiding last charachter trimming.
        threshold_width = actual_links_width / b_links;
        var temp_smaller_width = 0;
        var temp_larger_width_count = 0;
		
		var temp_total_width = 0;
        jQuery('.blink').each(function (i) {

            var current_element_width = jQuery(this).width();

            //Current Element width is smaller than the threshold width
            if (current_element_width <= threshold_width) {
                temp_smaller_width += current_element_width;
				temp_total_width += current_element_width;
				
				threshold_width = (actual_links_width - temp_total_width)/ (b_links - (i+1));
				
            }
            else {
                temp_larger_width_count += 1;
				temp_total_width += threshold_width;
            }
        });
		
		threshold_width = actual_links_width / b_links;
		temp_total_width = 0;
        //Apply Width Dynamically
        jQuery('.blink').each(function (i) {
            var current_element_width = jQuery(this).width();
            if (current_element_width <= threshold_width) {
                var pWidth = jQuery(this).children("a,span").width();
                jQuery(this).width(pWidth);
                jQuery(this).find('*').width(pWidth);
				temp_total_width += current_element_width;
				threshold_width = (actual_links_width - temp_total_width) /(b_links - (i+1));
            }
            else {
			
				temp_total_width += threshold_width;
                var new_larger_width = (actual_links_width - temp_smaller_width) / temp_larger_width_count;
                jQuery(this).width(new_larger_width);
                jQuery(this).find('a,span').width(new_larger_width);
                var title = jQuery(this).text();
                jQuery(this).find('a,span').attr('title', jQuery.trim(title.substr(title.indexOf('>') + 1, title.length)));
                btrimText(jQuery(this).find('a,span'), '...', new_larger_width);
            }
        });

    }
    else {
        actual_links_width = bread_links_holder.parent().width() - bs_links_width;

        jQuery('.blink').each(function () {
            jQuery(this).width(jQuery(this).find('a,span').width());
            actual_links_width = actual_links_width - jQuery(this).find('a,span').width();
        });

        jQuery('.blink:last').width(parseInt(jQuery('.blink:last').width()) + actual_links_width);

        jQuery('.titlerow-table').find('a').each(function () {
            if (jQuery(this).text().trim() == '')
                jQuery(this).height(0);
        });
    }
}

//Remove the last node link
function RemoveLastNodeLink() {
    var LastText = jQuery(".breadcrumbs:eq(1)>table>tbody>tr>td:last").text(); //Get the last node text to remove the link

    if (jQuery(".breadcrumbs:eq(1)>table>tbody>tr>td").length == 1) {
        jQuery(".breadcrumbs:eq(1)>table>tbody>tr>td:last").remove(); //Remove last node
        jQuery(".breadcrumbs:eq(1)>table>tbody>tr").append("<td><table><tr><td><span>&nbsp;&nbsp;" + LastText + "</span></td></tr></table></td>"); //Add last node removing link
    }
    else {
        jQuery(".breadcrumbs:eq(1)>table>tbody>tr>td:last").remove(); //Remove last node
        jQuery(".breadcrumbs:eq(1)>table>tbody>tr").append("<td><table><tr><td><span>&gt;&nbsp;&nbsp;" + LastText + "</span></td></tr></table></td>"); //Add last node removing link	
    }
}

function ApplyBreadCrumbSeperator() {
    jQuery("td.breadcrumbs > table > tbody > tr > td:empty").each(function (index) {
        jQuery(this).html("&nbsp;&nbsp;&gt;&nbsp;&nbsp;");
    });
}

//Trim text in an element to a given character length
function btrimText(str, sep, len) {
    if (str.width() > len) {
        str.text(str.text() + sep);
        var temp = str.text().trim();

        while (str.width() > len) {
            temp = temp.substring(0, temp.length - 1);
            str.text(temp + sep);
        }
    }
}

function grab_param(name, url) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(url);
    if (results == null)
        return "false";
    else
        return results[1];
}

 function ToggleClasses(resourceK) {

            var loca = location.href;
			var resourceFil ="UTC.FS.Framework.Newsroom.Resources";
            InitXmlHttp2();
            xmlhttp.onreadystatechange = GetResourcesXMLHttpRequestCompleted;
            xmlhttp.open("POST", "" + "/_layouts/UTC.FS.Framework.Common/JavascriptHandler/ScriptTranslator.ashx?currentUrl="+loca+"&resourceFile="+ resourceFil+"&resourceKey="+ resourceK, true);
            xmlhttp.send(null);
        }

        function InitXmlHttp2() {
            // Attempt to initialize xmlhttp object
            try {
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                // Try to use different activex object
                try {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (E) {
                    xmlhttp = false;
                }
            }
            // If not initialized, create XMLHttpRequest object
            if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
                xmlhttp = new XMLHttpRequest();
            }
            // Define function call for when Request obj state has changed
            xmlhttp.onreadystatechange = GetResourcesXMLHttpRequestCompleted;
        }
        function GetResourcesXMLHttpRequestCompleted() {
            if (xmlhttp.readyState == 4) {
                try {
                 
				 var contents= xmlhttp.responseText.split(',');			
                           
                 var self =  $('.filters h6.toggle a').eq(0), div = self.parent().parent().find('div.toggle');
                 div[(self.hasClass('active') ? 'hide' : 'show')]();            
                 self.html((self.hasClass('active') ? contents[1] : contents[0]));            
                 self.toggleClass('active');
                }
                catch (e) {
                }
            }
        }

        


