﻿/*********
    Credits: 
    The tabstrip/multipage effect was done using a modification of javascript code from
    http://my.aspweb.cz/	7/5/2003 by Attila Szabo 
*********/

/***********************************************/
// event handler to switch tabs/pages
/***********************************************/
function TabPageClick(oBtn){
    //document.getElementById("uiTabPageDiv_Main_1").innerHTML="<h1>ho ho ho</h1>";

    //get module ID from hidden input tag
    var moduleID = document.getElementById("hidModuleId").getAttribute('value');
    //create a cookie with current tab as value
    createCookie(moduleID, oBtn.id, '1')
    
    var aNameParts = oBtn.id.split('_');
    var iBtnClickedIndex = parseInt( aNameParts[2] );         // the index of the clicked button
    
    // set all tabs as inactive
    // (note: assumes no whitespace in unordered list in html)
    for(i=0; i <= oBtn.parentNode.parentNode.childNodes.length-1; i++){
        oBtn.parentNode.parentNode.childNodes[i].className = "inactive";
    }
    // set current tab as 'active'
    oBtn.parentNode.className = "active"

    // cycle through the tabs and make corresponding <div> visible
    for(i=1;  i <= 5; i++ ){
        if(i == iBtnClickedIndex ){  
            document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ iBtnClickedIndex).style.display="block"; // show the clicked layer
            continue;
        }
        oBtn = document.getElementById("uiTabControl_"+ aNameParts[1] +"_"+ i);
        if(oBtn){
            document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ i).style.display="none";
            //oBtn.className = "inactive";
        }
        else{
            break;
        }
    }
}

/***********************************************/
// cookie support
// (to make sure the selected tab stays selected on postback)
// http://www.quirksmode.org/js/cookies.html
/***********************************************/
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);
}


/***********************************************/
// use this to hide all unused panes onload.
// if javascript is disabled in the browser, then all panes will display.
/***********************************************/
function initialize(){

    //get module ID from hidden input tag
    var moduleID = document.getElementById("hidModuleId").getAttribute('value');

    //edit this array to contain all 'pages/panes' in your multipage tabstrip
    var oPages = new Array()
    oPages[0] = "uiTabControl_Main_1"
    oPages[1] = "uiTabControl_Main_2"
    //oPages[2] = "uiTabPageDiv_Main_3" //and so on
    
    var cookieValue = readCookie(moduleID)
    //check for cookie and write new one if necessary
    if (cookieValue){
        //change to appropriate tab
        document.getElementById(cookieValue).parentNode.className="active";
        //hide panes that shouldn't be showing (ie all elements not associated with tab)
        for (i=0;i<oPages.length;i++){
            var aNameParts = oPages[i].split('_');
            var iBtnClickedIndex = parseInt( aNameParts[2] );         // the index of the clicked button
            if(oPages[i] == cookieValue){//show corresponding page
                document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ iBtnClickedIndex).style.display="block";
            }else{//hide corresponding page
                document.getElementById("uiTabPageDiv_"+ aNameParts[1] +"_"+ iBtnClickedIndex).style.display="none";
            }
        }
    }else{
        //otherwise load default tab
        document.getElementById("uiTabControl_Main_1").parentNode.className="active";
        //and default pane
        document.getElementById("uiTabPageDiv_Main_2").style.display="none";
    }
}