/**************************************************************************/
/*                                                                        */
/* Copyright (c) 2004, 2005 NoMachine, http://www.nomachine.com.          */
/*                                                                        */
/* NXMANAGER, NX protocol compression and NX extensions to this software  */
/* are copyright of NoMachine. Redistribution and use of the present      */
/* software is allowed according to terms specified in the file LICENSE   */
/* which comes in the source distribution.                                */
/*                                                                        */
/* Check http://www.nomachine.com/licensing.html for applicability.       */
/*                                                                        */
/* NX and NoMachine are trademarks of Medialogic S.p.A.                   */
/*                                                                        */
/* All rights reserved.                                                   */
/*                                                                        */
/**************************************************************************/

function selectTab(n,numPanel) {
// iterate all tab-panel pairs
    for(var i=0; i < numPanel; i++) {
        var panelDiv = window.document.getElementById("panel"+i);
        var tab = document.getElementById("tab"+i);
        z = panelDiv.style.zIndex;
        // if this is the one clicked and it isn't in front, move it to the front
        if (i == n) {
            z = numPanel; 
            visibility="visible"; 
        }
        // in all other cases move it to the original position
        else { 
               z = (numPanel-i-1)
               visibility="hidden";
        }
        panelDiv.style.zIndex = z;
        panelDiv.style.visibility = visibility;
        tab.style.zIndex = z;
    }
}

function selectLoginTab(n,numPanel) {
// iterate all tab-panel pairs
    for(var i=0; i < numPanel; i++) {
        var panelDiv = window.document.getElementById("panelLogin"+i);
        var tab = document.getElementById("tab"+i);
        z = panelDiv.style.zIndex;
        // if this is the one clicked and it isn't in front, move it to the front
        if (i == n) {
            z = numPanel; 
            visibility="visible"; 
        }
        // in all other cases move it to the original position
        else { 
               z = (numPanel-i-1)
               visibility="hidden";
        }
        panelDiv.style.zIndex = z;
        panelDiv.style.visibility = visibility;
        tab.style.zIndex = z;
    }
}

function selectTabB(n,numPanel) {
// where 2 panel groups are inside the same page. 
    for(var i=0; i < numPanel; i++) {
        var panelDiv = window.document.getElementById("panelB"+i);
        var tab = document.getElementById("tabB"+i);
        z = panelDiv.style.zIndex;
        // if this is the one clicked and it isn't in front, move it to the front
        if (i == n) {
            z = numPanel; 
            visibility="visible"; 
        }
        // in all other cases move it to the original position
        else { 
               z = (numPanel-i-1)
               visibility="hidden";
        }
        panelDiv.style.zIndex = z;
        panelDiv.style.visibility = visibility;
        tab.style.zIndex = z;
    }
}

function setlayer(i,layer){
        var tab = document.getElementById("tab"+i);
        tab.style.zIndex = layer;
}


function getPosNumber(pos){
    var pxLoc = pos.indexOf("px")
    return Number(pos.substring(0,pxLoc))
}

function leftShift(numPanel, numVisibleTab){
    var tab = document.getElementById("tab"+(numPanel-1));
    var dimTab = document.getElementById("tab"+(numPanel-1)).style.width;
// Estraggo la stringa px dalla dimTab
    dimTab = getPosNumber(dimTab);
    
    var PosLastTab = tab.style.left;
// Se l'ultimo tab �gi�visibile non devo eseguire lo shift
// L'attributo left �del tipo 200px
    var PosLastVisibleTab = (numVisibleTab - 1) * dimTab;
    if (PosLastTab == PosLastVisibleTab+"px") return;

// iterate all tab-panel pairs
    var PosTab = 0;
    for(var i=0; i<numPanel; i++) {
        // Prendo l'id del Tab corrente
        // Prendo la posizione dell'angono in alto a sinistra
        // Elimino dalla posizione il suffisso px
        // Shifto il Tab di una posizione a sinistra
        tab = document.getElementById("tab"+i);
        PosTab = tab.style.left;
        PosTab = getPosNumber(PosTab);
        PosTab = PosTab - dimTab;
        tab.style.left = PosTab+"px";
        if (PosTab == 0) IndexFirstVisTab = i
        if ((PosTab < 0) || (PosTab > (numVisibleTab - 1) * dimTab)){
                tab.style.visibility = "hidden";
                // Se il tab che sta uscendo da sinistra (left 0) �in primo piano 
                // Devo porre in primo piano il successivo
                if ((tab.style.zIndex == numPanel)&&(i<numPanel-1)) {
                    selectTab(i+1,numPanel);
                }
        }else{
                tab.style.visibility = "visible";
             }
    }
}

function rightShift(numPanel, numVisibleTab){
    var tab = document.getElementById("tab0");
    var PosFirstTab = tab.style.left;
    var dimTab = document.getElementById("tab"+(numPanel-1)).style.width;
// Estraggo la stringa px dalla dimTab
    dimTab =  getPosNumber(dimTab);
// Se il primo tab �in prima posizione non devo eseguire lo shift
// L'attributo left �del tipo 200px
    if (PosFirstTab == 0+"px") return;
    
// iterate all tab-panel pairs
    var PosTab = 0;
    for(var i=0; i < numPanel; i++) {
        // Prendo l'id del Tab corrente
        // Prendo la posizione dell'angono in alto a sinistra
        // Elimino dalla posizione il suffisso px
        // Shifto il Tab di una posizione a sinistra
        tab = document.getElementById("tab"+i);
        PosTab = tab.style.left;
        PosTab = getPosNumber(PosTab);
        
        PosTab = PosTab + dimTab;
        tab.style.left = PosTab+"px";
        if ((PosTab < 0) || (PosTab > (numVisibleTab - 1) * dimTab)){
                tab.style.visibility = "hidden";
                //Se il tab che sta uscendo �in primo piano
                //Devo porre in primo piano il successivo
                if ((tab.style.zIndex == numPanel) && (i>0)) {
                    selectTab(i-1,numPanel)
                }
        }else   tab.style.visibility = "visible";
        
    }
}

function WindowWitdh() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
//window.alert( 'Width = ' + myWidth );
//window.alert( 'Height = ' + myHeight );
//window.alert( 'MaxWidht = ' + maxSize );
  return myWidth; 
}
