﻿var CNETSpecificationAjaxTabs = CNETSpecification.extend({
	
	
  // set up the tabs, but only if needed. Specs will always be created but accessories and marketing information will
  // only be set up if there is CNET data to fill them. This info is given by the values of 
  //   - CNETSpecification.header.hasMarketing
  //   - CNETSpecification.header.hasAccessories
  
  showMainSpecsInTab     : true,
  showExtendedSpecsInTab : true,
  showMarketingInTab     : true,
  showAccessoriesInTab   : true,
  
  display: function (withinDiv) 
  {
      this.removeAllChildren($(withinDiv));
            
      var main =  document.createElement("ul");
      main.id="maintab";
      main.className="shadetabs";
      

      // uncomment if marketing needs to be show in tab
      if(this.header.has.marketing && this.showMarketingInTab) 
      {
         main.appendChild(this.newTab("marketing", "General"));
      }
      
      
      if(this.showMainSpecsInTab)
        main.appendChild(this.newTab("specs", "Tech Sheet"));
      
      if(this.showExtendedSpecsInTab)
        main.appendChild(this.newTab("detailedspecs", "Full Tech Sheet"));
            
      if(this.header.has.accessories && this.showAccessoriesInTab) 
      {
         main.appendChild(this.newTab("accessories", "Related Products"));
      }
      
      
      var ajaxcontent =  document.createElement("div");
      ajaxcontent.id = "ajaxcontentarea";
      ajaxcontent.className = "contentstyle";
      

      $(withinDiv).appendChild(main);
      $(withinDiv).appendChild(ajaxcontent);
      
      
  },
  
  
  newTab: function(what, title) 
  {
      var tab = document.createElement("li");
      tab.className = "selected";
      var link = document.createElement("a");
      link.id = what+"Href";
      link.href = this.servletURL+"?what="+what+"&lang="+this.language+"&format=HTML&Prod="+this.product;
      link.rel = "ajaxcontentarea";
      link.appendChild(document.createTextNode(title));
      tab.appendChild(link);
      return tab;
  },
  

	removeAllChildren: function(node)
	{
		var child = node.lastChild;
		while (child != null) {
			this.removeAllChildren(child);
			node.removeChild(child);
			child = node.lastChild;
		}
	}
});

