function AtlasIframe(uri) {
    var timestamp = new Date();

    var qs = "?qstr=random=" + Math.ceil(Math.random() * 99999999) + timestamp.getUTCFullYear() + timestamp.getUTCMonth()
    + timestamp.getUTCDate() + timestamp.getUTCHours() + timestamp.getUTCMinutes() + timestamp.getUTCSeconds() + timestamp.getUTCMilliseconds();

    var uriPlus = uri + qs;

    var script = document.createElement('iframe');
    script.src = uriPlus;

    document.getElementsByTagName('body')[0].appendChild(script);
    
    return true;
}

function SimpleIframe(uri) {
    var script = document.createElement('iframe');
    script.src = uri;
    document.getElementsByTagName('body')[0].appendChild(script);
    return true;
}

function AtlasClick(atlasUrl, redir) {
    AtlasIframe(atlasUrl);
    setTimeout(function () { parent.document.location = redir; }, 300); //wait for 300ms before doing the redirect
    return false;
}

function AtlasClick2(atlasUrl, redir) {
    SimpleIframe(atlasUrl);
    setTimeout(function () { parent.document.location = redir; }, 300); //wait for 300ms before doing the redirect
    return false;
}

function MediaMindClick(ClickID, redir) {
    var ebRand = Math.random()+'';
    ebRand = ebRand * 1000000;
    document.getElementsByTagName('body')[0].appendChild('<script src=HTTP://bs.serving-sys.com/BurstingPipe/ActivityServer.bs?cn=as&amp;ActivityID=' + ClickID + '&amp;rnd=' + ebRand + '></script>');
    setTimeout(function () { parent.document.location = redir; }, 300); //wait for 300ms before doing the redirect
    return false;
}


function ChangeFeaturedVideo() {
    var index = readCookie('FeaturedRotatingVideoListItemIndex');

    if (index != null) {
        index = parseInt(index);
        index = index + 1;
        var maxIndex = parseInt(SwitchFeaturedListItem('FeaturedRotatingVideoList', 'FeaturedRotatingVideoListItem', index));
        if (index > maxIndex) {
            index = 0;
        }
        createCookie('FeaturedRotatingVideoListItemIndex', index, 100);

    } else {
        createCookie('FeaturedRotatingVideoListItemIndex', 1, 100);
        SwitchFeaturedListItem('FeaturedRotatingVideoList', 'FeaturedVideoCustomerListItem', 1);
    }
}

function SwitchFeaturedListItem(ulList, liItemClass, makeActive) {
    var list = document.getElementById(ulList);
    var listItems = list.getElementsByTagName('li');
    var listItemsCounter = 0;

    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++) {
        if (listItems[itemIndex].className == liItemClass) {

            if (listItemsCounter == makeActive - 1) {
                listItems[itemIndex].style.display = 'block';
            } else {
                listItems[itemIndex].style.display = 'none';
            }
            listItemsCounter = listItemsCounter + 1;
        }
    }
    return listItemsCounter - 1;
}



function ChangePage(hideID, showID) {

    var displayDiv = document.getElementById(hideID);
    displayDiv.style.display = 'none';

    displayDiv = document.getElementById(showID);
    displayDiv.style.display = 'block';
    
    /*
    $(document).ready(function () {
        $('#' + hideID).slideUp('slow', function () {$('#' + showID).slideDown('slow');});
    })
    */
    return false;
}
function printPage() {
    window.print();
}
function emailPage() {
    
}

function AdvanceSearch() {
    var ShareingList = document.getElementById('advanceSearchOptions');
    if (ShareingList.style.display != 'block') {
        ShareingList.style.display = 'block';
    } else {
        ShareingList.style.display = 'none';
    }
    return false;

}

function InternationalSites() {
    var ShareingList = document.getElementById('InternationalSites');
    if (ShareingList.style.display != 'block') {
        ShareingList.style.display = 'block';
    } else {
        ShareingList.style.display = 'none';
    }
    return false;

}
function InternationalSitesClose() {
    var ShareingList = document.getElementById('InternationalSites');
    ShareingList.style.display = 'none';
    return false;
}

function sharePage() {
    var ShareingList = $("#ShareingList");
    ShareingList.toggle();

    ShareingList.mouseleave(function () {
        ShareingList.hide();
    });

    return false;
}

function sharePageClose() {
    var ShareingList = document.getElementById('ShareingList');
    ShareingList.style.display = 'none';
    return false;
}

function onSilverlightError(sender, args) {

    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    }
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;

    var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";

    errMsg += "Code: " + iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError") {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError") {
        if (args.lineNumber != 0) {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " + args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

function goHome() {
    document.location.href = "http://crm.dynamics.com";
}

function cssInclude(direction) {
    var browser_version = parseInt(navigator.appVersion);
    var browser_type = navigator.appName;
    if (direction == 'rtl') {
        if (browser_type != 'Microsoft Internet Explorer') {
            return '<link REL="stylesheet" HREF="/css/layoutrtol.css" TYPE="text/css" media="screen" />';
        } else {
            return '';
        }
    } else {
        if (browser_type != 'Microsoft Internet Explorer') {
            return '<link REL="stylesheet" HREF="/css/layout.css" TYPE="text/css" media="screen" />';
        } else {
            return '';
        }
    }
    

}

function SwitchFeaturedPartners(ulList, liItemClass, makeActive) {
    var list = document.getElementById(ulList);
    var listItems = list.getElementsByTagName('li');
    var listItemsCounter = 0;

    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++) {
        if (listItems[itemIndex].className == liItemClass) {

            if (listItemsCounter == makeActive - 1) {
                listItems[itemIndex].style.display = 'block';
            } else {
                listItems[itemIndex].style.display = 'none';
            }
            listItemsCounter = listItemsCounter + 1;
        }
    }
    return listItemsCounter - 1;
}
    

function SwitchRollOver(Content, ContentMenu, position) {
    SwitchRollOverContent(Content, position);
    SwitchRollOverContentMenu(ContentMenu, position);
}
function SwitchRollOverContent(ulList, makeActive) {
    var list = document.getElementById(ulList);
    var listItems = list.getElementsByTagName('li');
    var listItemsCounter = 0;
    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++)
    {
        if (listItems[itemIndex].className == 'RollOverContentItemLI') {

            if (listItemsCounter == makeActive - 1) {
                listItems[itemIndex].style.display = 'block';
            } else {
                listItems[itemIndex].style.display = 'none';
            }
            listItemsCounter = listItemsCounter + 1;
        }
    }
}

function SwitchRollOverContentMenu(ulList, makeActive) {
    var list = document.getElementById(ulList);
    var listItems = list.getElementsByTagName('li');
    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++) {
        if (itemIndex == makeActive - 1) {
            var listItemAnchor = listItems[itemIndex].getElementsByTagName('a');
            listItemAnchor[0].className = 'SelectedItem';
        } else {
            var listItemAnchor = listItems[itemIndex].getElementsByTagName('a');
            listItemAnchor[0].className = '';
        }
    }
}

function Gold_Box_Menu(ulMenuList, ulList, makeActive) {
    
    var list = document.getElementById(ulList);
    var menuList = document.getElementById(ulMenuList);
    var listItems = list.getElementsByTagName('li');
    var menuListItems = menuList.getElementsByTagName('li');
    var listItemsCounter = 0;

    for (itemIndex = 0; itemIndex < listItems.length; itemIndex++) {
        
        if (listItems[itemIndex].id.substr(0,15) == 'Selected_Option') {

            if (listItemsCounter == makeActive - 1) {
                listItems[itemIndex].style.display = 'block';
                var listItemAnchor = menuListItems[listItemsCounter].getElementsByTagName('a');
                if (listItemAnchor.length > 0) {
                    listItemAnchor[0].className = 'ActiveSelection';
                }
            } else {
                listItems[itemIndex].style.display = 'none';
                var listItemAnchor = menuListItems[listItemsCounter].getElementsByTagName('a');
                if (listItemAnchor.length > 0) {
                    listItemAnchor[0].className = '';
                }
            }
            listItemsCounter = listItemsCounter + 1;
        }
    }

    return false; /* dont follow the default attribute on the element*/
}
function ModalOverlay(id) {
    el = document.getElementById(id);
    if (el != null) {
        el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
    }
}

function writeLocaleCookie(CRMCountry, CRMLocale) {
    /*alert('writeLocaleCookie: ' + CRMCountry + ' '  + CRMLocale);*/
    createCookie("CRMCountry", CRMCountry, 100);
    createCookie("CRMLocale", CRMLocale, 100);
    return true;
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else var expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name, "", -1);
}

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}


function RelatedInformation() {
//    //$(document).ready(function () {
//    $(window).load(function () {

//        /*Related Information Scroller*/

//        if ($("#ContentContainer").length != 0) {
//            //alert($("#ContentContainer").length);

//            var totalHeight = 0;
//            var currentPosition = 0;
//            var scrollSpeed = 500;

//            totalHeight = $("#ContentContainer").height();

//            var relatedInfoItems = new Array();

//            $("#RelatedInformationBoxContent ul li").each(
//                function (index) {
//                    relatedInfoItems[index] = $(this).height() + 10; //$(this).outerHeight();
//                    //alert(relatedInfoItems[index]);
//                }
//            );

//            //Hide the Related Information up arrow
//            $("#imgRIUp").hide();

//            //alert((totalHeight - $('#RelatedInformationBoxContent').height()));

//            //Hide the down arrow if all content is showing. Issue Tracker #6986
//            if ((totalHeight - $('#RelatedInformationBoxContent').height()) <= 2) {
//                $("#imgRIDown").hide();
//            }


//            //find the total height of the RelatedInformationBoxContent div
//            //$("#RelatedInformationBoxContent ul").each(
//            //    function () {
//            //        totalHeight += $(this).height();
//            //    }
//            //);

//            var index = 0;
//            function getNextPosition() {
//                //index++;

//                //alert("index: " + index + " " + relatedInfoItems[index]);
//                return relatedInfoItems[index++];

//            }

//            function getPreviousPosition() {

//                //alert(index);
//                index--;
//                return relatedInfoItems[index];
//            }


//            $('.RelatedInformationDown').click(function () {
//                var $RelatedInformationBoxContent = $('#RelatedInformationBoxContent');

//                if (!$RelatedInformationBoxContent.is(':animated')) {
//                    //var pScroll = $RelatedInformationBoxContent.height();
//                    //var pScroll = 100;
//                    var pScroll = getNextPosition();



//                    currentPosition += pScroll;
//                    //alert(currentPosition + " " + totalHeight);
//                    if (currentPosition < totalHeight) {
//                        $RelatedInformationBoxContent.animate({ scrollTop: '+=' + pScroll + 'px' }, scrollSpeed, 'linear', function() {
//                            // Animation complete.
//                            var elem = $RelatedInformationBoxContent;
//                            //alert(elem[0].scrollHeight - elem.scrollTop() + " == " + elem.outerHeight());
//                            if (elem[0].scrollHeight - elem.scrollTop() == elem.height()) {
//                                // We're at the bottom.
//                                $("#imgRIDown").hide();
//                            }
//                          }

//                        
//                        );
//                        $("#imgRIUp").show();
//                    }

//                    //alert((currentPosition + (pScroll * 2)) + " " + totalHeight);
//                    //if (currentPosition /*+ (pScroll * 2)*/ >= totalHeight) {
//                    //    $("#imgRIDown").hide();
//                    //}

//                    //Rewind                    
//                    //    $RelatedInformationBoxContent.animate({ scrollTop: '+=' + (totalHeight * -1) }, 1000, 'linear');

//                }
//            });


//            $('.RelatedInformationUp').click(function () {
//                var $RelatedInformationBoxContent = $('#RelatedInformationBoxContent');

//                if (!$RelatedInformationBoxContent.is(':animated')) {

//                    //var pScroll = $RelatedInformationBoxContent.height();
//                    //var pScroll = 100;
//                    var pScroll = getPreviousPosition();
//                    alert(currentPosition);
//                    if (currentPosition != 0) {
//                        currentPosition -= pScroll;
//                        if (currentPosition >= 0) {
//                            $RelatedInformationBoxContent.animate({ scrollTop: '-=' + pScroll + 'px' }, scrollSpeed, 'linear');
//                            $("#imgRIDown").show();
//                        }

//                        if (currentPosition == 0) {
//                            $("#imgRIUp").hide();
//                        }
//                    }
//                }
//            });

//            //Rollover 
//            $("#imgRIUp").hover(
//                function () {
//                    $(this).attr("src", "/images/layout/relatedInfoYellowArrowUp.png");
//                },
//                  function () {
//                      $(this).attr("src", "/images/layout/relatedInfoYellowArrowUp.png");
//                  }
//            );

//            $("#imgRIDown").hover(
//                function () {
//                    $(this).attr("src", "/images/layout/CRM-RelatedInfoBox-DownArrowHover.jpg");
//                },
//                  function () {
//                      $(this).attr("src", "/images/layout/CRM-RelatedInfoBox-DownArrow.jpg");
//                  }
//            );
//        }
//        /*END Related Information Scroller*/
//    });
    }


    function FeaturedPartner() {

        $(window).load(function () {
        //$(document).ready(function () {

            $('.carouselContainer').css('display', 'block');

            if ($('#carouselButtonLeft').length != 0) {
                var shift = 180; //How may pixels to move right or left
                var ulWidth = 0;
                var scrollSpeed = 500; //How fast to scroll
                var currentPosition = 0;

                $("#carouselButtonLeft").hide();

                //This is a hack in order to display the last li in the list. Goes with the hack in bindRightButton() below
                $("#carousel ul").append('<li><div class="carouselContent"><div class="carouselContentImage"></div><div class="carouselContentText"></div></div></li>');

                $("#carousel ul .carouselContent").each(function (i) {
                    ulWidth += $(this).outerWidth(true);

                    var img = $(this).children(".carouselContentImage").children("img");
                    var paddingTop = ($(this).children(".carouselContentImage").height() - img.height()) / 2;
                    //img.css("padding-top", paddingTop);
                    img.css({ 'padding-top': paddingTop });
                });

                $("#carousel ul").css("width", ulWidth);

                function bindLeftButton() {
                    $("#carouselButtonLeft").click(function () {
                        //var newPos = $("#carousel ul").position().left + shift;
                        var newPos = currentPosition + shift;
                        currentPosition += shift;

                        if (newPos > 0) newPos = 0;

                        $("#carouselButtonLeft").unbind();

                        $("#carousel ul").animate({
                            left: newPos + "px"
                        }, scrollSpeed, function () {
                            bindLeftButton();
                        });

                        if (newPos < 0) {
                            $("#carouselButtonLeft").show();
                        }
                        else {
                            $("#carouselButtonLeft").hide();
                        }

                        if ($("#carousel ul").width() + newPos > $("#carousel").width() * 2) {
                            $("#carouselButtonRight").show();
                        }

                    });
                }


                function bindRightButton() {
                    $("#carouselButtonRight").click(function () {
                        currentPosition -= shift;
                        //currentPosition = $("#carousel ul").position().left - shift;

                        //the "(shift * 2)" is a hack along with the extra empty li addition above                       
                        if ((($("#carousel ul").width() + currentPosition) - (shift * 2)) == 0) {
                            $("#carouselButtonRight").hide();
                        }

                        $("#carouselButtonRight").unbind();

                        $("#carousel ul").animate({
                            left: currentPosition + "px"
                        }, scrollSpeed, function () {
                            bindRightButton();
                        });

                        $("#carouselButtonLeft").show();
                    });


                }

                bindRightButton();
                bindLeftButton();
            }

        });
        /*Carousel*/
    }


    function Flipper() {
        $(document).ready(function () {
            if ($('.flipPanel').length != 0) {
                /* The following code is executed once the DOM is loaded */
                $('.flipPanelFront').bind("click", function () {
                    var elem = $(this);

                    if (elem.data('flipped')) {
                        elem.revertFlip();
                    }
                    else {
                        elem.flip({
                            direction: 'tb',
                            speed: 150,
                            bgColor: '#D5E3F0',
                            color: '#D5E3F0',
                            onBefore: function () {
                                elem.html(elem.siblings('.flipPanelBack').html());
                                elem.toggleClass('flipPanelBackFlipped');
                            }
                        });

                        elem.data('flipped', true);
                    }
                });
            }
        });
    }

    function jModal() {
        var countryCloseText = 'Close';
        var crmCountry = readCookie("CRMCountry");
        var supportedCountries = {
            'Australia':'Close'
            , 'Austria': 'Schließen'
            , 'Belgium': 'Sluit'
            , 'Brazil': 'Fechar'
            , 'Canada':'Close'
            , 'Chile': 'Cerrar'
            , 'Colombia': 'Cerrar'
            , 'Czech Republic': 'Zavrít'
            , 'Denmark': 'Luk'
            , 'Finland': 'Sulje'
            , 'France': 'Fermer'
            , 'Germany': 'Schließen'
            , 'Greece': '??e?s?µ?'
            , 'Hong Kong':'Close'
            , 'Hungary': 'Bezárás'
            , 'India': '???'
            , 'Ireland':'Close'
            , 'Israel': '????'
            , 'Italy': 'Chiudi'
            , 'Japan': '????'
            , 'Luxembourg':'Close'
            , 'Malaysia':'Close'
            , 'Mexico': 'Cerrar'
            , 'Netherlands': 'Sluit'
            , 'New Zealand':'Close'
            , 'Norway': 'Lukk'
            , 'Poland': 'Zamknij'
            , 'Portugal': 'Fechar'
            , 'Puertor Rico':'Close'
            , 'Romania': 'Inchide'
            , 'Singapore':'Close'
            , 'Spain': 'Cerrar'
            , 'Sweden': 'Stäng'
            , 'Swizterland': 'Schließen'
            , 'United Kingdom':'Close'
            , 'United States': 'Close'
        };

        if (crmCountry != null) {
            countryCloseText = supportedCountries[crmCountry];
        }


        $(document).ready(function () {
            //Grab the user defined modal content and create the divs needed by the jquery modal code
            $(".userModalContent").each(function (index) {
                var id = $(this).attr('id');
                var closeModalClass = "closeModal";

                if (id.indexOf('VideoPlayer') > 0) {
                    closeModalClass = "closeModalVideoPlayer";
                }

                var m = '<div id="' + id + '" class="window"><span class="' + closeModalClass + '"><a href="#" title="' + countryCloseText + '" class="close"><img src="/images/layout/modalWindowCloseBtn.png" alt="' + countryCloseText + '" /></a></span>' +
                    $('#' + id).html() + '</div>';

                $(m).appendTo('#boxes');
            });

            //select all the a tag with name equal to modal
            $('a[name=modal]').click(function (e) {

                //Cancel the link behavior
                e.preventDefault();
                //Get the A tag
                var id = $(this).attr('href');

                //alert(id); 

                showModal(id);

                //                //Get the screen height and width
                //                var maskHeight = $(document).height();
                //                var maskWidth = $(window).width();

                //                //Set height and width to mask to fill up the whole screen
                //                $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

                //                //transition effect		
                //                //$('#mask').fadeIn(200);
                //                $('#mask').fadeTo("slow", 0.7);

                //                //Get the window height and width
                //                var winH = $(window).height();
                //                var winW = $(window).width();

                //                //Set the height and width equal to the content
                //                $(id).fadeIn(1000); //$(id).show();
                //                $(id).css('width', $(id + " .modalContent").width());
                //                $(id).css('height', $(id + " .modalContent").height());

                //                //Set the popup window to center
                //                $(id).css('top', winH / 2 - $(id).height() / 2);
                //                $(id).css('left', winW / 2 - $(id).width() / 2);

                //transition effect
                //$(id).fadeIn(500/*2000*/);

            });

            //            function showModal(id) {
            //                //Get the screen height and width
            //                var maskHeight = $(document).height();
            //                var maskWidth = $(window).width();

            //                //Set height and width to mask to fill up the whole screen
            //                $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

            //                //transition effect		
            //                //$('#mask').fadeIn(200);
            //                $('#mask').fadeTo("slow", 0.7);

            //                //Get the window height and width
            //                var winH = $(window).height();
            //                var winW = $(window).width();

            //                //Set the height and width equal to the content
            //                $(id).fadeIn(1000); //$(id).show();
            //                $(id).css('width', $(id + " .modalContent").width());
            //                $(id).css('height', $(id + " .modalContent").height());

            //                //Set the popup window to center
            //                $(id).css('top', winH / 2 - $(id).height() / 2);
            //                $(id).css('left', winW / 2 - $(id).width() / 2);
            //            }

            //if close button is clicked
            $('.window .close').click(function (e) {
                //Cancel the link behavior
                e.preventDefault();
                removeVideoSrc();
                $('#mask, .window').hide();
            });

            //if mask is clicked
            $('#mask').click(function () {
                removeVideoSrc();
                $(this).hide();
                $('.window').hide();
            });


            //if window is clicked
            //JMW Removing for now because the user can not 
            //interact with the content in the modal if present
            /*$('.window').click(function () {
            $(this).hide();
            $('#mask').hide();
            });*/

            $(window).resize(function () {
                if ($('#mask').is(':visible')) {
                    //Get the screen height and width
                    var maskHeight = $(document).height();
                    var maskWidth = $(window).width();

                    //Set height and width to mask to fill up the whole screen
                    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });
                }
            });

            //Removes the src from the video modal so it doesn't continue to play in the background.
            function removeVideoSrc() {
                if ($('#videoframePlayer').is(':visible')) {
                    $('#videoframePlayer').attr('src', "");
                }

                //alert($('#silverlightControlHostCustomerVideos').text());
                $('#silverlightControlHostCustomerVideos').html('');

                //                if ($('#silverlightControlHostCustomerVideos').is(':visible')) {
                //                    $('#silverlightControlHostCustomerVideos').attr('src', "");
                //                }
            }
        });
    }

    //Moved outside of document.ready so the Geo Modal can access
    function showModal(id) {

        //Get the screen height and width
        var maskHeight = $(document).height();
        var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen
        $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect		
        //$('#mask').fadeIn(200);
        $('#mask').fadeTo("slow", 0.7);

        //Get the window height and width
        var winH = $(window).height();
        var winW = $(window).width();

        //Set the height and width equal to the content
        $(id).fadeIn(200); //$(id).show();
        //alert($(id + " .modalContent").width());
        $(id).css('width', $(id + " .modalContent").width());
        $(id).css('height', $(id + " .modalContent").height());

        //Set the popup window to center
        $(id).css('top', winH / 2 - $(id).height() / 2);
        $(id).css('left', winW / 2 - $(id).width() / 2);
    }

    // Any elements on a page with the class equalHeight will have
    // their height adjusted to equal the tallest element.
    function equalHeight()
    {
        $(document).ready(function () {
            var tallest = 0;
            $(".equalHeight").each(function () {
                if ($(this).height() > tallest) {
                    tallest = $(this).height();
                }
            });

            $(".equalHeight").each(function () {
                //alert(index + " " + tallest);
                $(this).css({ 'height': tallest });
            });

        });
    }


    //Highlights the box on mouseover
    function featuredCustomers() {
        $(document).ready(function () {

            if ($('.logoBorder').length != 0) {

                //                $('.logoBorder').mouseover(function () {
                //                    $(this).toggleClass('logoBorderHover', true);
                //                });

                //                $('.logoBorder').mouseout(function () {
                //                    $(this).toggleClass('logoBorderHover', false);
                //                });


                //Industry Checkboxes
                $('.industryItem').click(function () {
                    $(this).toggleClass('industryItemChecked');


                    var cbId = '#cb' + $(this).attr('id');

                    if ($(cbId).attr('checked')) {
                        $(cbId).attr('checked', false)
                    }
                    else {
                        $(cbId).attr('checked', true)
                    }

                });

                //Search button rollover
                $('.searchBtn').mouseover(function () {
                    $(this).toggleClass('searchBtnHover', true);
                });

                $('.searchBtn').mouseout(function () {
                    $(this).toggleClass('searchBtnHover', false);
                });


                $('.VideoBlock').mouseover(function () {
                    $(this).find(".logoBorder").toggleClass('logoBorderHover', true);
                });

                $('.VideoBlock').mouseout(function () {
                    $(this).find(".logoBorder").toggleClass('logoBorderHover', false);
                });

                $('.VideoBlock').click(function () {
                    var url = $(this).find('.featuredLink').attr("href");
                    if ((url != null) && (url != url.length > 0)) {
                        window.location.href = url;
                    }
                });

            }

        });           // End ready

    }

    function region(urlImage, regionName) {
        this.urlImage = urlImage;
        this.regionName = regionName;
    }
    var regionDetailsList = new Array(7);
    regionDetailsList[0] = new region('/images/maps/map.png', 'Worldwide');
    regionDetailsList[1] = new region('/images/maps/NorthAmerica.jpg', 'NorthAmericaCountries');
    regionDetailsList[2] = new region('/images/maps/SouthAmerica.jpg', 'SouthAmericaCountries');
    regionDetailsList[3] = new region('/images/maps/AfricaMiddleEast.jpg', 'MiddleEastAfricaCountries');
    regionDetailsList[4] = new region('/images/maps/Europe.jpg', 'EuropeCountries');
    regionDetailsList[5] = new region('/images/maps/Asia.jpg', 'AsiaCountries');
    regionDetailsList[6] = new region('/images/maps/SouthPacific.jpg', 'SouthPacificCountries');
    var backgroundImage = regionDetailsList[0].urlImage;
    function SwapIn(regionID) {
        $('#ImgBase').attr('src', regionDetailsList[regionID].urlImage);
    }
    function SwapOut() {
        $('#ImgBase').attr('src', backgroundImage);
    }
    function ChangeLocale() {
        var url = $('#' + countryList).val();

        if (url != "") {
            window.location = url;
        }
        return false;
    }
    function ChangeCountryList(regionID) {
        for (regionIndex = 0; regionIndex < regionDetailsList.length; regionIndex++) {
            $('#' + regionDetailsList[regionIndex].regionName).hide();
        }

        $('#' + regionDetailsList[regionID].regionName).show();
        $('#SelectRegionList').val(regionID);

        backgroundImage = regionDetailsList[regionID].urlImage;
        countryList = regionDetailsList[regionID].regionName;
        SwapIn(regionID);
        return false;
    }
    function ChangeRegion() {
        ChangeCountryList($("#SelectRegionList").val());
        return false;
    }


    /*********************************************************************
    * Get an object, this function is cross browser
    * *** Please do not remove this header. ***
    * This code is working on my IE7, IE6, FireFox, Opera and Safari
    * 
    * Usage: 
    * var object = get_object(element_id);
    *
    * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
    **/
    function get_object(id) {
        var object = null;
        if (document.layers) {
            object = document.layers[id];
        } else if (document.all) {
            object = document.all[id];
        } else if (document.getElementById) {
            object = document.getElementById(id);
        }
        return object;
    }
    /*********************************************************************/

    /*********************************************************************
    * No onMouseOut event if the mouse pointer hovers a child element 
    * *** Please do not remove this header. ***
    * This code is working on my IE7, IE6, FireFox, Opera and Safari
    * 
    * Usage: 
    * <div onMouseOut="fixOnMouseOut(this, event, 'JavaScript Code');"> 
    *		So many childs 
    *	</div>
    *
    * @Author Hamid Alipour Codehead @ webmaster-forums.code-head.com		
    **/
    function is_child_of(parent, child) {
        if (child != null) {
            while (child.parentNode) {
                if ((child = child.parentNode) == parent) {
                    return true;
                }
            }
        }
        return false;
    }
    function fixOnMouseOut(element, event, JavaScript_code) {
        var current_mouse_target = null;
        if (event.toElement) {
            current_mouse_target = event.toElement;
        } else if (event.relatedTarget) {
            current_mouse_target = event.relatedTarget;
        }
            
        if (!is_child_of(element, current_mouse_target) && element != current_mouse_target) {
            eval(JavaScript_code);
        }
    }
    /*********************************************************************/

    function show_message(message) {
        get_object('status').innerHTML = message;
    }

    
    function SetCountryLocale() {

        if (document.location.href.toLowerCase().indexOf("/en-apac") > -1 || document.location.href.toLowerCase().indexOf("/es-latam") > -1) {
        
            var crmCountry = readCookie("CRMCountry");
        
            var regionalCountries;
            if(document.location.href.toLowerCase().indexOf("/es-latam") > -1){
                regionalCountries = new Array('peru', 'chile', 'colombia', 'costa rica', 'trinidad');
            }
            else{
                regionalCountries = new Array('singapore', 'malaysia');
            }
            var CountryLocale = false;
            if (crmCountry != null) {
                crmCountry = crmCountry.toLowerCase();
                for (var i = 0; i < regionalCountries.length; i++) {
                    var country = regionalCountries[i];
                    if (crmCountry.indexOf(country) >= 0) {
                        CountryLocale = true;
                        break;
                    }
                }
            }
            var countryLocaleElement = document.getElementById("CountryLocale");

            if ((crmCountry != null) && (countryLocaleElement != null) && (CountryLocale ==true) ) {
                    countryLocaleElement.innerHTML = crmCountry;
            }
        }

        
    }
