var isIE = window.document.all && !window.opera;

function tabcontrol(tabs, container_id, title, downloadstr) {
   this.curtab = null;
   this.tabber = null;
   this.tabpage = null;
   
   var obj = this;
   var firsttab = null;
   
   this.tabCallback = function(req) {
      var obj = req.args;
      var div = document.createElement('div');
      while (obj.tabpage.firstChild) obj.tabpage.removeChild(obj.tabpage.firstChild);
      div.innerHTML = req.responseText;
      obj.tabpage.appendChild(div);
   
      var runmenow = document.getElementById('runmenow');
      if (runmenow) {
         var script = runmenow.value;
         var parent = runmenow.parentNode;
         parent.removeChild(runmenow);
         eval(script);
      }
   };
   
   this.makeactive = function(o) {
      if (this.curtab) {
         this.curtab.className = 'tab';
      }
      this.curtab = o;
      o.className = 'tab_active';
      this.tabber.style.top = o.offsetTop+(isIE?o.parentNode.offsetTop:0);
      this.tabber.style.height = 25;
      this.tabber.style.left = o.offsetLeft + o.offsetWidth;
      ajaxget(o.href, this.tabCallback, this);
   };
   
   var container = document.getElementById(container_id);
   container.onmousedown = function(event) {
      var ev = window.event || event;
      if (ev.target == this) hideLightBox();
   };
   var tabbox = document.createElement('div');
   tabbox.className = 'tabbox';
   container.appendChild(tabbox);
   
   
   for (var n=0; n<tabs.length; n++) {
      var tab = document.createElement('div');
      if (n==0) firsttab = tab;
      tab.className = 'tab';
      tab.innerHTML = tabs[n].name;
      tab.href = tabs[n].href.replace(/amp;/g,'');
      //console.log(tab.href);
      
      tab.onmouseover = function() {
         this.className = this.className == 'tab_active' ? 'tab_active' : 'tab_hover';
      };
      
      tab.onmouseout = function() {
         this.className = this.className == 'tab_active' ? 'tab_active' : 'tab';
      };
      
      tab.onclick = function() {
         obj.makeactive(this);
      };
      
      tabbox.appendChild(tab);
   }
   
   
   var tabpage = document.createElement('div');
   tabpage.className = 'tabpage';
   container.appendChild(tabpage);
   
   var div = document.createElement('div');
   div.className = 'tabframe_tl';
   div.style.cssText = 'left:0;top:0';
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_t';
   div.style.cssText = 'left:10;top:0;width:'+(810-20);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_tr';
   div.style.cssText = 'left:' + (810-10) + ';top:0';
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_l';
   div.style.cssText = 'left:0;top:67;height:'+(600-67-67);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_r';
   div.style.cssText = 'left:'+(810-10)+';top:67;height:'+(600-67-67);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_bl';
   div.style.cssText = 'left:0;top:'+(600-67);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_b';
   div.style.cssText = 'left:10;top:'+(600-67)+';width:'+(810-20);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'tabframe_br';
   div.style.cssText = 'left:'+(810-10)+';top:'+(600-67);
   tabpage.appendChild(div);
   
   div = document.createElement('div');
   var basepath = getBasepath();
   div.style.cssText = 'position:absolute;left:0;top:580;width:100%;text-align:right';
   div.innerHTML = 'Downloads in cart: <span onclick="if (this.innerHTML != \'0\') { location.href=this.getAttribute(\'href\'); }" background="transparent" border="0px none" basepath="' + basepath + '" href="' + basepath + 'downloadcart.php?action=download" id="cartcount" style="display:table-cell;display:inline-block;width:40px;text-align:right;cursor:pointer;text-decoration:underline;padding-right:20px" title="View my download cart">0</span>';
   tabpage.appendChild(div);
   
   
   div = document.createElement('div');
   div.className = 'campaign_titlebox';
   div.appendChild(document.createTextNode(title));
   container.appendChild(div);
   
   div = document.createElement('div');
   div.className = 'frame_close';
   div.onmouseover = function() { this.className = 'frame_close_hover'; }
   div.onmouseout  = function() { this.className = 'frame_close'; }
   div.onclick = function() { hideLightBox(); }
   container.appendChild(div);
   
   
   
   this.tabpage = document.createElement('div');
   this.tabpage.className = 'tabcontent';
   tabpage.appendChild(this.tabpage);
   
   this.tabber = document.createElement('div');
   this.tabber.className = 'tabber';
   container.appendChild(this.tabber);
   
   this.makeactive(firsttab);
}      


