// Project:       Stainless Steel in Construction
// Version:       3.0.36
// Company:       FreeSTYLE Software Ltd.
// Last revision: 07 December 2008

   var ActiveTab = '';
   
   function SetTabs ( TabId )
   {
      if ( ActiveTab != '' )
      {
         document.all ( ActiveTab ).style.display = 'none';
         ActiveTab = '';
      }
      if ( TabId )
      {
         ActiveTab = TabId;
         document.all ( ActiveTab ).style.display = 'block';
         var TabInd = parseInt ( ActiveTab, 10 );
         if ( ! isNaN ( TabInd ))
         {
            EnableTabs ( TabInd > 0 ? TabInd : -1 );
         }
      }
   }
   
   function EnableTabs ( active )
   {
      if ( ActiveTab == '' )
      {
         return;
      }
      for ( var i = 1; i <= TabsNumb; i ++ )
      {
         if (    i != active
              && document.all ( ActiveTab + i )
            )
         {
            document.all ( ActiveTab + i ).style.color = ( g_Main.Enablers & ( 1 << i )) ? TABEnabledColor : TABDisabledColor;
         }
      }
   }

   function EnableTab ( nTabId, Enable )
   {
      if (    ActiveTab != ''
           && document.all ( ActiveTab + nTabId )
         )
      {
         document.all ( ActiveTab + nTabId ).style.color = ( Enable != false ? TABEnabledColor : TABDisabledColor );
      }
   }

   function Switch2Tab ( nTabId, Validate )
   {
      var Body = window.top.frames ( "Body" );
      var Window = ( Switch2Tab.arguments.length > 2 ) ? Switch2Tab.arguments [2] : window;

      if ( isNaN ( nTabId ))
      {
         if ( Body.document.all ( "Wait" ))
         {
            Body.document.all ( "Wait" ).style.display = "block";
         }
         Body.navigate (( /home/gi.test ( nTabId )) ? "HomeB.asp" : nTabId + "B.htm" );
         g_Main.Status ();
      }
      else
      if (    nTabId >= 1
           && nTabId <= TabsNumb
           && (    Window != window
                || g_Main.Enablers & ( 1 << nTabId )
              )
         )
      {
         if ( typeof ( Body.SaveValues ) == "function" )
         {
            Body.SaveValues ();
         }

         var IsValid = true;
         if (    nTabId > g_Main.ActiveTab
              && Validate
              && typeof ( Body.IsValid ) == "function"
            )
         {
            IsValid = Body.IsValid ();
         }

         if ( IsValid )
         {
            var Param = "";
            g_Main.ValidateSilent ( nTabId );
            for ( var Ind = indLoading; Ind < nTabId; Ind ++ )
            {
               if ( ! g_Main.ValidPages [Ind] )
               {
                  Param  = "?Validate";
                  nTabId = Ind;
                  break;
               }
            }

            g_Main.ActiveTab = nTabId;
            var BodyURL = "";
            if ( nTabId >= indSecProp )
            {
               if ( g_Main.Method == CUSTOMSHAPES )
               {
                  if ( g_Main.IsDirty )
                  {
                     BodyURL = "Calc.asp?TabId=" + nTabId;
                  }
                  else
                  {
                     BodyURL = nTabId + 'B.asp';
                  }
               }
               else
               {
                  var Suff = ( nTabId == indSummary ? '' : 'n' );
                  if ( g_Main.IsDirty )
                  {
                     BodyURL = "Calc2.asp?TabId=" + nTabId + Suff;
                  }
                  else
                  {
                     BodyURL = nTabId + Suff + 'B.asp';
                  }
               }                  
            }
            else
            {
               BodyURL = nTabId + "B.htm" + Param;
            }

            if ( Body.document.all ( "Wait" ))
            {
               Body.document.all ( "Wait" ).style.display = "block";
            }
            Body.navigate ( BodyURL );
            g_Main.Status ();
         }
      }
      if ( Window.event )
      {
         Window.event.returnValue = false;
      }
   }

   function TabTitle ()
   {
      var sTabId = '' + window.event.srcElement.id;
      var nTabId = parseInt ( sTabId.substr ( 2 ));

      if (    ! isNaN ( nTabId )
           && nTabId >= 1
           && nTabId <= TabsNumb
         )
      {
         //----- If enabled -----
         if ( g_Main.Enablers & ( 1 << nTabId ))
         {
            if ( event.type == "mouseover" )
            {
               document.all ( sTabId ).style.cursor = "hand";
               document.all ( sTabId ).style.color  = TABHoverColor;
               g_Main.CommonStatusMsg ( 5 + nTabId );
            }
            else
            {
               document.all ( sTabId ).style.cursor = "default";
               document.all ( sTabId ).style.color  = TABEnabledColor;
               g_Main.Status ();
            }
         }
      }
      window.event.cancelBubble = true;
   }

   function OverTitle ( nGroup, nTabId, nEvent )
   {
      //----- If enabled -----
      if ( g_Main.Enablers & ( 1 << nTabId ))
      {
         var TabId = '' + nGroup + 'T' + nTabId;

         if ( nEvent == 1 )
         {
            document.all ( TabId ).style.cursor = "hand";
            document.all ( TabId ).style.color  = TABHoverColor;
            g_Main.CommonStatusMsg ( 5 + nTabId );
         }
         else
         {
            document.all ( TabId ).style.cursor = "default";
            document.all ( TabId ).style.color  = TABEnabledColor;
            g_Main.Status ();
         }
      }
      window.event.cancelBubble = true;
   }
