// JavaScript Document
$.noConflict();
jQuery.fn.hasAttr = function (id, name) {
    if (this.attr(id) == name)
        return true;
    return false;
};
jQuery(document).ready(function ($) {


    $('.scfRadioButtonList').each(function () {

        var radiolisthtml = "<div class='radiooptions'>";

        $(this).find('td').each(function () {
            radiolisthtml += "<label>" + $(this).html() + "</label>";

        })
        radiolisthtml += "</div>";
        $(this).before(radiolisthtml);
        $(this).remove();
    })




    //Main menu Hover function
    function addMega() {
        $(this).addClass("active");
    }
    function removeMega() {
        $(this).removeClass("active");
    }
    var megaConfig = {
        interval: 100,
        over: addMega,
        timeout: 100,
        out: removeMega
    };

    if ($('ul#mainNavList li li').length != 0) {
        $("ul#mainNavList > li:not(:first)").hoverIntent(megaConfig);
    }

    //styling the langauge selectbox
    if ($('#langSelect').length != 0) {
        $('#langSelect').sSelect({ ddWidth: 68 });
    }

    //Home page billboard slideshow function using jquery cyclic plugin
    if ($('#homeslideshow').length != 0) {
        $('#homeslideshow').cycle({
            fx: 'fade',
            timeout: 6310,
            prev: '#prev',
            next: '#next',
            pager: '#slidenav',
            pagerAnchorBuilder: function (idx, slide) {
                // return selector string for existing anchor 
                return '#slidenav li:eq(' + idx + ') a';
            }
        });
        $('#billBoard #slidenav a').click(function () {
            $('#homeslideshow').cycle('pause');
        })
    }

    //Home page video scrolling
    if ($('#video_slider ul').length > 1) {
        $('#video_slider').cycle({
            fx: 'scrollHorz',
            timeout: 0,
            prev: '.prevVideo',
            next: '.nextVideo'
        });
    }
    //Products Page minibillboard
    if ($('#minibillBoard .productImages').length != 0) {
        $('#minibillBoard .productImages').cycle({
            fx: 'fade',
            timeout: 4750,
            prev: '.leftarrow',
            next: '.rightarrow',
            pager: '#minipagerNav ul',
            pagerAnchorBuilder: function (idx, slide) {
                // return selector string for existing anchor 
                return '#minipagerNav ul li:eq(' + idx + ') a';
            }
        });
        $('#minipagerNav a').click(function () {
            $('#minibillBoard .productImages').cycle('pause');
        })
    }
    //Change the checkBox style in the vents page
    if ($('.checkoptionBlock').length != 0) {
        $('.checkoptionBlock').find('label').attr('for', '')
        StylingCheckbox()
    }
    //set the column heights equally					   
    var $columnOne = $('#container .col1').height();
    var $columnTwo = $('#container .col2').height();
    var $columnThree = $('#container .col3').height();
    var maxNumber = Math.max($columnOne, $columnTwo, $columnThree);
    $('#container .col1').css("height", maxNumber + "px");
    $('#container .col2').css("height", maxNumber + "px");
    $('#container .col3').css("height", maxNumber + "px");

    //product device page tabs
    if ($('.productinfoTabs').length != 0) {
        $('.tabData').hide();
        $('.tabData').eq(0).show();

        $('.productinfoTabs #tabs a').click(function () {
            var tabid = $(this).attr('href');
            $('#tabs').find('li').removeClass('active').removeClass('prevTab');
            $(this).parent().addClass('active')
            $(this).parent().prev().addClass('prevTab')
            $('.tabData').hide();
            $(tabid).show();
            return false;
        })

        var preselectedtab = document.location.hash.substr(1, document.location.hash.length);
        if (preselectedtab != '' && $('#' + preselectedtab).length != 0) {
            $('.productinfoTabs #tabs a[href="#' + preselectedtab + '"]').click()
        }
    }

    // set class on the tab previous to the active tab
    if ($('.traininginfoTabs').length != 0) {
        $('#tabs li.active').prev().addClass('prevTab');
    }

    //metaLinks hover
    $('#metaLinks img').hover(function () {
        $(this).css('opacity', '0.6')
    }, function () { $(this).css('opacity', '1') })

    //Product Device page scrolling function
    if ($('#imgpagerNav').length != 0) {
        $('#imgpagerNav').cycle({
            fx: 'scrollHorz',
            timeout: 0,
            prev: '.leftarrow',
            next: '.rightarrow'
        });

        $('.imgpagerNav a').click(function () {
            $('.imgpagerNav li').removeClass('activeSlide');
            $(this).parent().addClass('activeSlide')
            var curimage = $(this).attr('href');
            if ($(this).find('img').attr('longdesc') != '' || $(this).find('img').attr('longdesc') != null) {
                $('.imgzoomPanel img').attr('longdesc', $(this).find('img').attr('longdesc'))
            }

            $('.imgzoomPanel img').fadeOut(500, function () {
                $('.imgzoomPanel img').attr('src', curimage)
                $('.imgzoomPanel img').fadeIn();

            })
            return false;
        })

    }

    //locations dropdown menu
    $('.locations_ddmenu a.locationlink').hover(function () {
        $(this).parent().find('.subNavList').show();
        $(this).parent().hover(function () { }, function () {
            $(this).parent().find('.subNavList').hide();
        })
    })

    //products device related products more links
    $('.relativeproductMod .moreLink, .expandInfo .moreLink').click(function () {
        if ($(this).hasClass('moreLink')) {
            $(this).parent().find('.Morelinks').slideDown();
            $(this).addClass('lessLink').removeClass('moreLink').html('Less')
        } else {
            $(this).parent().find('.Morelinks').slideUp();
            $(this).removeClass('lessLink').addClass('moreLink').html('More')

        }
        return false;
    })

    //zoom image functionlity
    if ($('.imgzoomPanel').length != 0) {
        $('.imgzoomPanel a.zoomicon').haeOverlay('imagePanelzoom', 'popclose');
        $('.imgzoomPanel a.zoomicon').click(function () {
            var imgnew = $('<img>');
            imgnew.attr('src', $('.activeSlide').find('img').attr('longdesc'));
            $('.popImgloading').html('');
            $('.popImgloading').append(imgnew);
        })
    }

    //video popup function
    if ($('#videopod').length != 0) {
        $('#videopod li a').haeOverlay('videoPlayerpopup', 'popclose');
        $('#videopod li a').click(function () {
            //            var obj = document.createElement('object');
            //            obj.setAttribute('id', 'myExperience');
            //            obj.setAttribute('class', 'BrightcoveExperience');

            var playerobject = '<object id="myExperience" class="BrightcoveExperience"><param name="bgcolor" value="#FFFFFF" />';
            playerobject += '<param name="width" value="' + $('#videoPlayerWidth').val() + '" />';
            playerobject += '<param name="height" value="' + $('#videoPlayerHeight').val() + '" />';
            playerobject += '<param name="playerID" value="' + $('#videoPlayerID').val() + '" />';
            playerobject += '<param name="playerKey" value="' + $('#videoPlayerKey').val() + '" />';
            playerobject += '<param name="isVid" value="true" />';
            playerobject += '<param name="isUI" value="true" />';
            playerobject += '<param name="dynamicStreaming" value="true" />';
            playerobject += '<param name="@videoList" value="' + $(this).attr('plid') + '" />';
            playerobject += '<param name="@videoList.featured" value="' + $(this).attr('vid') + '" /></object>';
            //$('#videoPlayerWrapper object').html(playerobject);

            document.getElementById('videoPlayerWrapper').innerHTML = playerobject;

            brightcove.createExperiences();

            $('#videoPlayerpopup h3').html($(this).attr('header'));
        });
    }

    if ($('#videoPlayerpopup .popclose').length != 0) {
        $('#videoPlayerpopup .popclose').click(function () {
            $('#videoPlayerWrapper').html('');
        });
    }

    //success stories page more functionality	
    if ($('#moredetialedlist .moreLink').length != 0) {

        $('#moredetialedlist .moreLink').click(function () {
            if ($(this).hasClass('moreLink')) {
                $('.moreContent').hide()
                $('.lessLink').removeClass('lessLink').addClass('moreLink').html('More')
                $(this).parent().find('.moreContent').slideDown();
                $(this).addClass('lessLink').removeClass('moreLink').html('Less')
            } else {
                $(this).parent().find('.moreContent').slideUp();
                $(this).removeClass('lessLink').addClass('moreLink').html('More');
            }
            return false;
        })
    }

    //locations paage tabs functionality
    if ($('#locations_tabs').length != 0) {
        $('.tabs-panel').hide();
        $('.tabs-panel').eq(0).show();
        var currenttab = document.location.hash;
        if (document.location.hash != '' && $(currenttab).length != 0) {
            $('.vertical_tabs_panel').hide();
            $(currenttab).show();
            $('.locations_vertical_tabs li').removeClass('active');
            $("a[href=" + currenttab + "]").parent().addClass('active');
        } else {
            $('.vertical_tabs_panel').hide();
            $('.vertical_tabs_panel').eq(0).show();
            $('.locations_vertical_tabs li').removeClass('active');
            $('.locations_vertical_tabs li').eq(0).addClass('active');
        }
        $('.locations_vertical_tabs li a').click(function () {
            var tabcontainer = $(this).attr('href');
            if ($(tabcontainer).length != 0 && $(this).parent().parent().hasClass('locations_vertical_tabs')) {
                $(this).parent().parent().find('.active').removeClass('active')
                $('.vertical_tabs_panel').hide();
                $(tabcontainer).show();
                $(this).parent().addClass('active');
            }
            else if ($(tabcontainer).length != 0) {
                $(this).parent().parent().find('.active').removeClass('active')
                $('.tabs-panel').hide();
                $(tabcontainer).show();
                $(this).parent().addClass('active');
            }
            return false;
        })
    }

    //training page filters select Box 
    if ($('.traininginfoFilters').length != 0) {
        $('.traininginfoFilters select').sSelect({ ddWidth: 182 });
        //intially if device or software select box have any selected value
        if ($('.info' + $('#deviceSelect').val()).length != 0) {
            $('.deviceBlock').hide();
            $('.info' + $('#deviceSelect').val()).show();
        }
        else if ($('.info' + $('#softwareSelect').val()).length != 0) {
            $('.deviceBlock').hide();
            $('.info' + $('#softwareSelect').val()).show();
        }
        else {
            $('.deviceBlock').show();
        }
        //device selectbox on change function
        $('#deviceSelect').change(function () {
            if ($('.info' + $('#deviceSelect').val()).length != 0) {
                $('.deviceBlock').hide();
                $('.info' + $('#deviceSelect').val()).show();
            }
            else {
                $('.deviceBlock').show();
            }
        })
        // software selectbox on change function
        $('#softwareSelect').change(function () {
            if ($('.info' + $('#softwareSelect').val()).length != 0) {
                $('.deviceBlock').hide();
                $('.info' + $('#softwareSelect').val()).show();
            }
            else {
                $('.deviceBlock').show();
            }
        })
    }


    //searc results paging select box
    if ($('.pagingselect').length != 0) {
        $('.pagingselect').sSelect({ ddWidth: 40 });
    }

    //search results page odd rows
    if ($('.resultsListing').length != 0) {
        $('.resultsListing li:odd').addClass('oddrow')
    }

    //quality faqs 
    if ($('.qrquicklinks').length != 0) {
        $('.qrquicklinks a').click(function () {
            var divname = $(this).attr('href');
            if ($(divname).length != 0) {
                var elpos = $(divname).offset().top;

                $('html, body').stop().animate({ scrollTop: elpos }, 'slow');

            }
            return false;
        })


    }
    $('.backtotop').click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });

    //kc documents javascript
    if ($('.resource_listing').length != 0) {
        $('.resource_listing:odd').addClass('altrow')
        $('.subcatDetails').hide();
        $('.subcatDetails').each(function () {
            $(this).find('.sub_resource_listing:odd').addClass('altrow')

        })

        $('.resource_listing .cat-name span').click(function () {

            var nextsub = $(this).parent().parent().next('.subcatDetails')

            if ($(nextsub).is(':visible')) {
                $(nextsub).slideUp();
                $(this).removeClass('active')
            } else {
                $(nextsub).slideDown();
                $(this).addClass('active')

            }

        })
        $('.resource_listing').eq(2).find('.cat-name span').click()

    }

    //forum latest post expand and collapse

    $('.kc-latest-posts span.collapse, .kc-statisitcs span.collapse').click(function () {
        if ($(this).next('ul').is(':visible')) {
            $(this).next('ul').slideUp();
            $(this).addClass('expand')
        } else {
            $(this).next('ul').slideDown();
            $(this).removeClass('expand')

        }


    })

    //forums expand collapse blocks
    $('.expandBlock span.collapse').click(function () {
        if ($(this).next('.expandInfo').is(':visible')) {
            $(this).next('.expandInfo').slideUp();
            $(this).addClass('expand')
        } else {
            $(this).next('.expandInfo').slideDown();
            $(this).removeClass('expand')

        }

    })

    // contact popup functionlity
    if ($('#contactpopup').length != 0) {
        if ($('a.showcontact').length != 0) {
            $('a.showcontact').haeIframeOverlay('contactpopup', 'popclose', 'popupFrame', $('a.showcontact').attr('href'));
        }
    }

    // feedback popup functionality
    if ($('#contactpopup').length != 0) {
        if ($('a.feedbackpopup').length != 0) {
            $('a.feedbackpopup').haeOverlay('contactpopup', 'popclose');
        }
    }

    //translate page select box
    if ($('.translateSelect').length != 0) {
        $('.translateSelect select').sSelect({ ddWidth: 182 });
    }

    //special characters methhod adding to existing plugin
    if ($.validator) {
        $.validator.addMethod("specialchars", function (value, element) { return this.optional(element) || /^[a-zA-Z0-9_\.\,\-\%\$\@\ \/\&\;]+$/i.test(value); }, "Special Charactors Not Allowed!");
    }


    $('#products a, #solutions a, #learningcenter a, #about a, .cs_sidebarBody a').filter(function () {
        return !($(this).attr('href').toLowerCase().match('^http'));
    }).click(function () {

        var context = "us";
        //var externallink = 0;
        var internationalcontext = window.location.href.toLowerCase().indexOf("/international") != -1;
        var internationalurl = $(this).attr("href").toLowerCase().indexOf("/international") != -1;

        //if ($(this).attr('href').toLowerCase().match('^http'))
        //    externallink = 1;

        if (internationalcontext)
            context = "international";

        if (context == "international" && !internationalurl) {
            alert('You are leaving the International site.');
        }
        // Check haecontext : for External site.
        else if (context == "us" && internationalurl) {
            alert('You are leaving the US site.');
        }
    });

    //    if (window.location.href.toLowerCase().indexOf("/international") != -1) {
    //        $("a[href^='/']").filter(function () {

    //            var returnValue = ($(this).attr("href").toLowerCase().indexOf("/international") == -1);
    //            if (returnValue) returnValue = ($(this).attr("href") != '#');
    //            if (returnValue) returnValue = !($(this).hasClass("showcontact"));
    //            if (returnValue) returnValue = !($(this).hasClass("leftarrow"));
    //            if (returnValue) returnValue = !($(this).hasClass("rightarrow"));
    //            if (returnValue) returnValue = ($(this).attr("href").toLowerCase().indexOf("/~/media/Images/") == -1);
    //            return returnValue;
    //        }).click(function () {
    //            alert('You are leaving the international site');
    //        });
    //    }
});

function StylingCheckbox() {
    (function ($) {
        jQuery('input[type=checkbox]').each(function () {
            var currentcheckbox = $(this);
            $(this).hide();
            var stylecheckbox;
            var stylecheckboxlabel = currentcheckbox.next();
            if ($(this).prop('checked') == true) {
                stylecheckbox = $('<span class="stylecheckbox checked"></span>').insertBefore(this);
            }
            else {
                stylecheckbox = $('<span class="stylecheckbox"></span>').insertBefore(this);
            }

            stylecheckbox.click(function () {
                var parentDiv = stylecheckbox.parent().attr('rel');
                if (stylecheckbox.parent().hasClass('checkall')) {

                    if (stylecheckbox.hasClass('checked')) {
                        $('#' + parentDiv).find('span.stylecheckbox').removeClass('checked')
                        $('#' + parentDiv).find('input[type=checkbox]').removeAttr('checked');
                    } else {
                        $('#' + parentDiv).find('span.stylecheckbox').addClass('checked')
                        $('#' + parentDiv).find('input[type=checkbox]').attr('checked', 'checked');
                    }
                } else {
                    if (stylecheckbox.hasClass('checked')) {
                        stylecheckbox.removeClass('checked');
                        $(currentcheckbox).removeAttr('checked');
                        $('#' + parentDiv).find('.checkall').find('span.stylecheckbox').removeClass('checked');
                        $('#' + parentDiv).find('.checkall').find('input[type=checkbox]').removeAttr('checked');
                    }
                    else {
                        if ($(currentcheckbox).hasClass('radiooption'))
                            ResetAllStylingCheckbox();
                        stylecheckbox.addClass('checked');
                        $(currentcheckbox).attr('checked', 'checked');
                    }
                }

            });

            stylecheckboxlabel.click(function () {
                var parentDiv = stylecheckbox.parent().attr('rel');

                if (stylecheckbox.parent().hasClass('checkall')) {
                    if (stylecheckbox.hasClass('checked')) {
                        $('#' + parentDiv).find('span.stylecheckbox').removeClass('checked')
                        $('#' + parentDiv).find('input[type=checkbox]').removeAttr('checked');
                    } else {
                        $('#' + parentDiv).find('span.stylecheckbox').addClass('checked')
                        $('#' + parentDiv).find('input[type=checkbox]').attr('checked', 'checked');
                    }
                } else {

                    if (stylecheckbox.hasClass('checked')) {
                        stylecheckbox.removeClass('checked');
                        $(currentcheckbox).removeAttr('checked');
                        $('#' + parentDiv).find('.checkall').find('span.stylecheckbox').removeClass('checked');
                        $('#' + parentDiv).find('.checkall').find('input[type=checkbox]').removeAttr('checked');
                    }
                    else {
                        if ($(currentcheckbox).hasClass('radiooption'))
                            ResetAllStylingCheckbox();
                        stylecheckbox.addClass('checked');
                        $(currentcheckbox).attr('checked', 'checked');
                    }
                }
            });
        });
    })(jQuery);
}

function ResetAllStylingCheckbox() {
    (function ($) {
        jQuery('input[type=checkbox]').each(function () {
            var currentcheckbox = $(this);
            var stylecheckbox = currentcheckbox.prev();
            if (stylecheckbox.hasClass('checked')) {
                stylecheckbox.removeClass('checked');
                $(currentcheckbox).removeAttr('checked')
            }
        })
    })(jQuery);
}

//iframeOverlay
(function ($) {
    $.fn.haeIframeOverlay = function (maindivid, cancelclass, iframeid, url) {
        if ($('#' + iframeid).length != 0) {
            $(this).click(function () {
                $('#' + iframeid).attr('src', url);
            });
            this.haeOverlay(maindivid, cancelclass);
        }
    };
})(jQuery);

//modalOverlay 
(function ($) {
    $.fn.haeOverlay = function (maindivid, cancelclass) {
        // initialize
        this.each(function () {
            var modalpopup;
            $(this).click(function () {
                modalpopup = $('#' + maindivid);
                var popheight = modalpopup.height();
                var popwidth = modalpopup.width();
                var docheight = $(document).height();
                var docwidth = $(document).width();
                var winheight = $(window).height();
                var scrollTop = $(window).scrollTop();
                var settop = (winheight - popheight) / 2;
                var setleft = (docwidth - popwidth) / 2;
                settop = scrollTop + 50;
                if (modalpopup.not(':visible')) {
                    modalpopup.css({ 'marginTop': settop, 'marginLeft': setleft });
                    $('.overlay').height(docheight);
                    $('.overlay').width(docwidth);
                    $('.overlay').show();
                    $('.overlay').css({ opacity: 0 }).animate({ opacity: 0.50 });
                    modalpopup.show();
                    $(modalpopup).find('.' + cancelclass).click(function () {
                        modalpopup.hide();
                        $('.overlay').hide().fadeOut();
                        return false;
                    })
                }
                else {
                    modalpopup.hide();
                    $('.overlay').hide();
                }
                return false;
            })
            $('.overlay').click(function () {
                modalpopup.hide();
                $('.overlay').hide().fadeOut();
                return false;
            })
        });
        return this;
    };
})(jQuery);

//registration form validations
//function CheckRegistrationForm() {
//    $("#userregistrationform").validate({
//        rules: {
//            password: {
//                required: true,
//                minlength: 6
//            },
//            confirmpassword: {
//                required: true,
//                minlength: 6
//            },
//            username: {
//                required: true,
//                maxlength: 50
//            }
//        },
//        errorPlacement: function (error, element) {
//            element.parent().prev().append(error)
//        }
//    })
//    return $("#userregistrationform").valid();
//}

// search functions
function fnCheckKeycode(e) {
    var keycode;
    if (window.event) // IE
        keycode = e.keyCode;
    else if (e.which) // Netscape/Firefox/Opera
        keycode = e.which;
    if (keycode == 13) fnCallSearch();

    return (keycode != 13);
}

var defaultSearchText = "";

function fnCallSearch() {
    (function ($) {
        var objsearchText = $('.srchForm input.text');
        var objSearchOption = $('#searchOptions input:checked');
        var searchText;
        var searchPage = "/search/search.aspx?";
        if (objSearchOption.length > 0) searchPage = objSearchOption.val();
        if (objsearchText.length > 0) {
            searchText = objsearchText.val();
            // make sure that a new search string has been entered ...
            if (searchText !== defaultSearchText) {
                searchText = searchText.replace(/>/gi, " >");
                searchText = searchText.replace(/</gi, "< ");
                objsearchText.value = searchText;
                // load the search results page ...
                window.location.href = searchPage + "searchtext=" + searchText.replace('alert', '').replace('confirm', '');
            }
        }
    })(jQuery);
}

function fnClearField(inputField) {
    if (inputField.value == inputField.defaultValue) {
        inputField.value = "";
        inputField.style.color = "#58585A";
    }
}

jQuery(document).ready(function ($) {
    defaultSearchText = $('.srchForm input.text').val();
});

function fnStickFooter() {
    (function ($) {
        var windowHeight = $(window).height();
        var bodyHeight = $('#bodyWrapper').outerHeight();
        if (windowHeight > bodyHeight) {
            var contentHeight = $('#maincontent').height();
            $('#maincontent').css('min-height', contentHeight + (windowHeight - bodyHeight));
        }
    })(jQuery);
}

jQuery(document).ready(function ($) {
    fnStickFooter();
    $(window).resize(fnStickFooter);
    // expand the height of the what's new box
    if ($('.latest-info').length != 0) {
        $('.latest-info').css('height', $('.latest-info').parent().css('height'));
    }
    // expand the height of the video box
    if ($('.videoBlock').length != 0) {
        var blockHeight = $('.videoBlock').parent().css('height');
        if (blockHeight == '0px') blockHeight = $('.videoBlock').parent().parent().css('height');
        $('.videoBlock').css('height', blockHeight);
    }
    // extend the title bar when the title wraps
    if ($('.contentHeader h1').length != 0) {
        if ($('.contentHeader').height() > 40) {
            $('#container').prepend('<div id="containerSpacerDiv" style="background-color:#c60c30;margin:0 -22px"></div>');
            $('.contentHeader').css('margin-top', '-' + String($('.contentHeader').height() - 32) + 'px');
            $('.rightPanel').css('margin-top', '-' + String($('.contentHeader').height() - 32) + 'px');
            $('#containerSpacerDiv').css('height', String($('.contentHeader').height() - 32) + 'px');
            $('#container').css('backgroundPosition', '0 ' + String($('.contentHeader').height() - 32) + 'px');
        }
    }
    // make sure the body hieghts are the same on the customer support page
    if ($('.cs_contentBody').length != 0 && $('.cs_sidebarBody').length != 0) {
        if ($('.cs_contentBody').height() > $('.cs_sidebarBody').height()) {
            $('.cs_sidebarBody').css('height', String($('.cs_contentBody').height()) + 'px');
        }
        else if ($('.cs_sidebarBody').height() > $('.cs_contentBody').height()) {
            $('.cs_contentBody').css('height', String($('.cs_sidebarBody').height()) + 'px');
        }
    }
});

function fnReStyleMiniCalendar() {
    (function ($) {
        if ($('#divMonthView .navCalendarDiv').length != 0) {
            // clean of the inline style applied to the mini calendar
            $('#divMonthView .navCalendarDiv').removeAttr('style')
            $('#divMonthView .navCalendar').removeAttr('style').attr('cellspacing', '3');
            $('#divMonthView .navCalendar td').each(function () {
                if ($(this).attr('style').indexOf('border:solid') !== -1) {
                    $(this).addClass('navCurrentDate');
                }
            });
            $('#divMonthView .navCalendar td').removeAttr('style');
            $('#divMonthView .navCalendar td a').removeAttr('style');
            $('#divMonthView .navCalendar td.navCalendarTextEvents a, #divWeekView .navCalendar td.navWeekdaysEvents a').each(function () {
                var orgHref = $(this).attr('href');
                orgHref = orgHref.substr(0, orgHref.lastIndexOf("'"));
                var dateNumber = orgHref.substr(orgHref.lastIndexOf("'") + 1);
                $(this).attr('href', '/About/News and Events/Calendar/Events.aspx?eventDate=' + dateNumber);
            });
            $('#divMonthView .navCalendar td.navNextPrev a').each(function () {
                var orgHref = $(this).attr('href');
                orgHref = orgHref.substr(0, orgHref.lastIndexOf("'"));
                var dateNumber = orgHref.substr(orgHref.lastIndexOf("'") + 2);
                $(this).attr('href', '/About/News and Events/Calendar/Events.aspx?mode=month&eventStart=' + dateNumber);
            });
            $('#divMonthView .navCalendar td.navWeekdaysEvents a, #divMonthView .navCalendar td.navWeekdays a').each(function () {
                var orgHref = $(this).attr('href');
                orgHref = orgHref.substr(0, orgHref.lastIndexOf("'"));
                var dateNumber = orgHref.substr(orgHref.lastIndexOf("'") + 1);
                $(this).attr('href', '/About/News and Events/Calendar/Events.aspx?eventStart=' + dateNumber);
            });
            $('#divMonthView .navCalendar td.navCalendarText, #sidebar-right .navCalendar td.navWeekdays').each(function () {
                $(this).children('a').removeAttr('href');
            });
            $('#divMonthView .navCalendar').show();
        }
    })(jQuery);
}

function fnReStyleHaeCalendar() {
    (function ($) {
        $('#divMonthView .haeCalendar td.haeCalSelected a').each(function () {
            var orgHref = $(this).attr('href');
            orgHref = orgHref.substr(0, orgHref.lastIndexOf("'"));
            var dateNumber = orgHref.substr(orgHref.lastIndexOf("'") + 1);
            $(this).attr('href', '/About/News and Events/Calendar/Events.aspx?eventDate=' + dateNumber + '&eventSource=' + escape(window.location));
        });
        $('#divMonthView .haeCalendar td.haeCalNextPrev a').each(function () {
            var orgHref = $(this).attr('href');
            orgHref = orgHref.substr(0, orgHref.lastIndexOf("'"));
            var dateNumber = orgHref.substr(orgHref.lastIndexOf("'") + 2);
            $(this).attr('href', '/About/News and Events/Calendar/Events.aspx?mode=month&eventStart=' + dateNumber);
            $(this).click(function () {
                var c = fnGetQueryString("c");
                var ir = fnGetQueryString("ir");
                var href = $(this).attr('href');
                if (c != null && c.length > 0)
                    $(this).attr('href', href + '&c=1');
                if (ir != null && ir.length > 0)
                    $(this).attr('href', href + '&ir=1');
            })
        });
        $('#divMonthView .haeCalendar td.haeCalWeekday, #divMonthView .haeCalendar td.haeCalWeekend').each(function () {
            $(this).children('a').removeAttr('style');
            $(this).children('a').removeAttr('href');
        });
    })(jQuery);
}

function fnGetQueryString(name) {
    name = String(name).replace(/[.*+?|()[\]{}\\]/g, '\\$&');

    var match = RegExp('[?&]' + name + '=([^&]*)')
            .exec(window.location.search);

    return match ?
    decodeURIComponent(match[1].replace(/\+/g, ' '))
    : null;
}

function EndRequestHandler(sender, args) {
    if (args.get_error() == undefined) {
        fnReStyleMiniCalendar();
    }
}

jQuery(document).ready(function ($) {
    fnReStyleHaeCalendar();
    if (typeof (Sys) !== 'undefined') {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    }
});

jQuery(document).ready(function ($) {
    if ($('#videopod .actionlink a').length == 0) {
        $('#videopod .actionlink').remove();
    }
});
