﻿    
        $(document).ready(function() {
            changeTab();
            $(".ShowInstituteNavBar a").each(function() {
                $(this).click(function() {
                    setTimeout("changeTab()", 100);
                });
            });
        });

        function IsNullOrEmpty(str) {
            if (str == null)
                return true;
            if (str == "")
                return true;
            return false;
        }

        function changeTab() {            
            if (IsNullOrEmpty(getPageType()))
                showTab(activeAnchor());
        }

        function isExists(type) {
            for (var key in tabs) {
                if (tabs[key].menu == type)
                    return true;
            }
            return false;
        }
        
        var tabs = {   general: { tab: "institutePage_general", menu: "general" },
                        programs: { tab: "institutePage_programs", menu: "programs" },
                        studentservices: { tab: "institutePage_studentservices", menu: "studentservices" },
                        scholarships: { tab: "institutePage_scholarships", menu: "scholarships" },                        
                        news: { tab: "institutePage_news", menu: "news" }};

        function showTab(tabName) {
            var id = null;
            var menuId = null;
            for (var key in tabs) {
                
                id = "#" + tabs[key].tab;
                menuId = "." + tabs[key].menu;
                
                if (key == tabName) {
                    $(id).show();
                    $(menuId).addClass("Selected");
                }
                else {
                    $(id).hide();
                    $(menuId).removeClass("Selected");
                }
            }
        }


        function getPageType() {
            var url = document.location;
            var pair = null;
            var strippedUrl = url.toString().split("?");
            if (strippedUrl.length > 1) {
                strippedUrl = strippedUrl[1];
                strippedUrl = strippedUrl.split("&");
                if (strippedUrl.length > 1) {
                    for (var key in strippedUrl) {
                        pair = strippedUrl[key].split("=");
                        if (pair.length == 2) {
                            if (pair[0].toLowerCase() == "type") {
                                return pair[1];
                            }
                        }
                    }
                }
            }
            return null;
        }

        function activeAnchor() {
            var anchorValue = "general";
            var url = document.location;
            var strippedUrl = url.toString().split("#");
            if (strippedUrl.length > 1)
                anchorValue = strippedUrl[1];

            return isExists(anchorValue) ? anchorValue : "general";            
        }
        
    
