// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homecomp_page of this code:
//     http://www.php-development.ru/javascripts/tab-view.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.


// ***** Auxiliary *************************************************************

function tabview_aux(TabViewId, CurrentId)
{
  var TabView = document.getElementById(TabViewId);

  // ***** Tabs *****

  //var list = TabView.firstChild;
  
  //var list = list.firstChild;  
  var list = document.getElementById("comp_tabs");
  while (list.className != "comp_tabs") list = list.nextSibling;
  
  var LineItem  = list.firstChild;
  
  var i    = 0;

  do
  {
	link = LineItem.firstChild;
    //alert(link.className);	
    if (link.tagName == "A" && link.className != 'notab')
    {
  
      i++;
      link.href         = "javascript:tabview_switch('"+TabViewId+"',"+i+");";
      link.className    = (i == CurrentId) ? "current" : "";
      link.blur();
      
    }
  }
  while (LineItem = LineItem.nextSibling);

  // ***** comp_pages *****

  var comppages = document.getElementById('comp_pages');

  while (comppages.className != 'comp_pages') comppages = comppages.nextSibling;
  var comppage  = comppages.firstChild;
  var i     = 0;

  do
  {
    if (comppage.className == 'comp_page')
    {
      i++;
      //if (comppages.offsetHeight) comppage.style.height = (comppages.offsetHeight-2)+"px";
      comppage.style.visibility  = (i == CurrentId) ? 'visible' : 'hidden';
    }
  }
  while (comppage = comppage.nextSibling);
}


// ***** Tab View **************************************************************

function tabview_switch(TabViewId, id) { tabview_aux(TabViewId, id); }
function tabview_initialize(TabViewId) { tabview_aux(TabViewId,  1); }

