// ----- Toggle Tabs! -------------------------------
// ----- by Dustin Lundebrek - dustin@lundebrek.com -
// ----- August 2006 --------------------------------

// This script enables dynamic tabs with a minimum of extra HTML markup and zero configuration JavaScript

function tabs() {

  // initialize variables
  var tabNav = document.getElementById('tabNavigation'); // the base element of the navigation links
  var tabLinks = tabNav.getElementsByTagName('a');  // the navigation links
  var urlInternal = window.location + '';  // the url as a string
  var contentIDs = new Array();  // an array that will eventually hold IDs of the tabs
  var defaultTabId;
  
  // first, is there an internal link specified in the URL?
  if (urlInternal.indexOf('#') != -1) {  // if the url has a # sign...
    defaultTabId = urlInternal.replace(/.*#(.+)/,'$1');  // ...set defaultTabId to the value of the internal link
  }
  else {
    defaultTabId = null;  // otherwise, set defaultTabId to null
  }
  
  // second, initialize each navigation link
  for (var i = 0; i < tabLinks.length; i++) { // for each navigation link...
    contentIDs[i] = tabLinks[i].href.replace(/.*#(.+)/,'$1');  // set contentIDs[i] to the href of the value
    if (contentIDs[i] != defaultTabId) {  // if this tab is NOT specified in the url...
      document.getElementById(contentIDs[i]).style.display = 'none';  // ...hide this tab
    }
    else {
      tabLinks[i].className = 'selected';
    }
    
    tabLinks[i].onclick = function() {  // when a navigation link is clicked...
    
      for (x = 0; x < contentIDs.length; x++) {  // look at each tab ID
        if (contentIDs[x] == this.href.replace(/.*#(.+)/,'$1')) {  // if the id is equal to the HREF of the link (minus the #)...
          document.getElementById(contentIDs[x]).style.display = 'block'  // ...show the element with that id
          document.getElementById('ctl00_ContentPlaceHolder1_hf').value = contentIDs[x]
		 // alert(contentIDs[x])
        }
        else {
          document.getElementById(contentIDs[x]).style.display = 'none'; // otherwise, hide the element with that id
		  // alert("00000")
        }
      //  alert(contentIDs[x])
        for (y = 0; y < tabLinks.length; y++) {
          if (tabLinks[y] == this) {
            this.className = 'selected';
          //  alert(this)
          }
          else {
            tabLinks[y].className = '';
          }
        }
      }
      
      return false;  // stop the internal link
    }
  }
  
  if (defaultTabId == null) {  // if there is no default tab specified in the URL...
    document.getElementById(contentIDs[0]).style.display = 'block';  // ...show the first tab
    tabLinks[0].className = 'selected';  // and give the first tab's nav link class 'selected' (this isn't necessary, but you can style 'selected' to indicate which tab is selected)
  }
    
  window.scrollTo(0,0);  // scroll to the top of the page (for when there is an internal link)
  
}

window.onload = tabs;
