﻿//Shedd Menu functions
//------------------------------------------


function onClientTabSelected(sender, args) {
    //Persist selected tab text 
    var tabValue = args.get_tab().get_value();
    //Save text to a cookie using JavaScript    
    saveTabIndex(tabValue);
}

//Cookie name 
var tabCookieName = "myCookieName";

function saveTabIndex(tabValue) {
    //Call JS function to save cookie name, tab text, 
    //and days before cookie should expire    
    setCookie(tabCookieName, tabValue, 1);
}

//Cookie operation helper function 
//Save the value to a cookie and set expiration date 
function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
        ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

//Variable to hold reference to tabstrip 
var tabstrip;
function onClientTabLoad(sender) {
    //Get reference to tabstrip    
    tabstrip = sender;
}

function loadTabIndex(tabstrip) {
    //If tabstrip reference isn't null 
    if (tabstrip != null) {
        //Get cookie value 
        var tabValue = getCookie(tabCookieName);
        //If text from the cookie exists 
        if (tabValue != "" || tabValue != null) {
            //Set tabstrip selected index 
            var tab = tabstrip.findTabByValue(tabValue);
            //Get tab object 
            if (tab != null) {
                tab.select(); //Select tab            
            }
        }
    }
}

//Cookie helper function 
//Gets a cookie based on supplied name and returns value 
//as a string 
function getCookie(c_name) {
    try {
        if (document.cookie.length > 0) {
            c_start = document.cookie.indexOf(c_name + "=");
            if (c_start != -1) {
                c_start = c_start + c_name.length + 1;
                c_end = document.cookie.indexOf(";", c_start);
                if (c_end == -1) c_end = document.cookie.length;
                return unescape(document.cookie.substring(c_start, c_end));
            }
        }
    } catch (err) { }

    //If there is an error or no cookie 
    //return an empty string 
    return "";
}

//pageLoad automatically called by ASPNET AJAX when page ready 
function pageLoad() {
    //Must do tab strip select here so that  
    //multipage is initialized and updated    
    loadTabIndex(tabstrip);
}

