/*
The SoftAd Group
Copyright (c) 2000-2004 The SoftAd Group, Inc.  All rights reserved
*/
// -------------------------------------------------------------------------------
// File name        : tabControl.js
// -------------------------------------------------------------------------------
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// This file contains all client-side scripting functions used by the tab control, 
// the file must be included in your page when you use the control.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------
// Copyright © 2000 The SoftAd Group, Inc.

var pageWidth = screen.availWidth-30;
var screenWidth = screen.availWidth-30;
var tabWin

// -------------------------------------------------------------------------------
// Function         : tabObj
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// This object is used to populate the tab control.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME         TYPE        DESCRIPTION
// scrollPX     integer     amount the tab control scrolls every timeout
// scrollSpeed  integer     speed the tab control scrolls every timeout
// width        integer     width of the tab control
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function tabObj(scrollPX,scrollSpeed,width)
{
  this.scrollSpeed = scrollSpeed;
  this.scrollPX = scrollPX;
  this.width = width;
  this.tabs = new Array();

  this.add=addTab;
  this.display=displayTabControl;
}

// -------------------------------------------------------------------------------
// Function         : tabControl
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// This object is used to manipulate the tab control once it has been drawn.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME         TYPE        DESCRIPTION
// scrollPX     integer     amount the tab control scrolls every timeout
// scrollSpeed  integer     speed the tab control scrolls every timeout
// width        integer     width of the tab control
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function tabControl(scrollPX,scrollSpeed,width)
{
  this.scrollSpeed = scrollSpeed;
  this.scrollPX = scrollPX;
  this.width = width;
  this.arrowWidth = 18;

  this.css = document.all.tabControl.style;
  this.obj = document.all.tabControl;
  this.parent = document.all.tabWin;
  this.x = this.css.pixelLeft;
  this.y = this.css.pixelTop;
  this.effect = null;

  this.clip=clipLyr;
  this.move=moveLyr;
  return this;
}

// -------------------------------------------------------------------------------
// Function         : tab
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// This object is used to store information on a particular tab
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME         TYPE        DESCRIPTION
// label        string      label name
// onclick      string      function fired when the user clicks a tab
// url          string      url the user is redirected to upon the click of a tab
// target       string      url the user is redirected to upon the click of a tab
// width        string      tab width
// selected     string      is the selected module
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function tab(label,onclick,url,target, labelwidth, selected)
{
  this.label = label;
  this.onclick = (onclick != null && onclick != "") ? onclick : "";
  this.url = (url != null && url != "")  ?  url: "";
  this.target = (target != null && target != "")  ?  target: "_top";
  this.labelwidth = (labelwidth != null && labelwidth != "")  ?  labelwidth: "";
  this.selected = (selected != null && selected != "")  ?  "Selected": "";
}

// -------------------------------------------------------------------------------
// Function         : addTab
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// This function is exposed as a method of the tabObj object, it adds a tab too 
// the elements collection.
// -------------------------------------------------------------------------------
// Parameters
// -------------------------------------------------------------------------------
// NAME         TYPE        DESCRIPTION
// img_off      string      path and filename to the tab off image
// img_on       string      path and filename to the tab ONMOUSEOVER image
// img_alt      string      text for the alt tag of an image
// onclick      string      function fired when the user clicks a tab
// url          string      url the user is redirected to upon the click of a tab
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function addTab(label,onclick,url,target, labelwidth, selected)
{
  this.tabs[this.tabs.length] = new tab(label,onclick,url,target, labelwidth, selected);
}

// -------------------------------------------------------------------------------
// Function         : displayTabControl
// Author           : Joe Slovinski
// Created on       : Friday, April 7, 2000
// 
// The displayTabControl function draws the tab control.
// -------------------------------------------------------------------------------
// Last Updated     : 
// Updated by       : 
// -------------------------------------------------------------------------------

function displayTabControl()
{
  var html = "";
  
  html = "<table border='0' cellspacing='0' cellpadding='0'><tr>";
  html = html + "<td valign='middle'><div id='left_arrow'><a href='javascript://' onmouseover='move_left()' onmouseout='stop()'><img src='/themes/default/en-us/common/admin/images/btn_scroll-left.gif' border=0 name='scroll_left'/></a></div></td>";
  html = html + "<td><div id='tabWin' style='position:relative;clip:rect(0,0,0,0);height:21'><div id='tabControl' style='position:absolute;'>";
  html = html + "<table border='0' cellspacing='0' cellpadding='0'><tr valign='bottom'>";

  for(i=0; i < this.tabs.length; i++)
  {
    html += '<td width="2"><img height="1" src="/themes/default/en-us/common/admin/images/clearpixel.gif" width="2"/></td><td>';
    var label= this.tabs[i].label;
    var onclick = this.tabs[i].onclick;
    var url = this.tabs[i].url;
    var target = this.tabs[i].target;
    var width = this.tabs[i].labelwidth ;
    var selected = this.tabs[i].selected; 
    
    html += "<table cellpadding='0' cellspacing='0' border='0'>";
    html += "<tr title='" + label + "' id='" + label + "' name='" + label + "' style='cursor:hand'";
    if(url != '' && selected != "yes"){
      html += " onclick='javascript:document.location.href=\"" +  url + "\"'";
    }
    html += ">";
    html += "<td><IMG BORDER='0' SRC='/themes/default/en-us/common/admin/images/tab_left";
    if(selected != ""){
    	html += "-active";
    }
    html +=".gif'/></td>";
    html += "<td nowrap='nowrap' class='clsCMCTab" + selected + "' width='" + width + "'>";
    if(url != '' && selected != "yes"){
      	html += "<a class='clsCMCTab" + selected + "' href='" + url + "' onclick='" + onclick + "'";
    	if(this.tabs[i].target) {
		html += " target='" + target + "'";
	}
	html += ">";
    }
    html += label;
    if(this.tabs[i].url != ''){
    	html += "</a>";
    }   
    html += "</td>";
   
    
    
    html += "<td><IMG BORDER='0' SRC='/themes/default/en-us/common/admin/images/tab_right";
    if(selected != ""){
    	html += "-active";
    }
    html += ".gif'/></td>"
    html += "</tr></table>";
    html += "</td>";
    
  }

  html = html + "</tr></table>";
  html = html + "</div>";
  html = html + "</div>";
  html = html + "</td>";
  html = html + "<td valign='middle'><div id='right_arrow'><a href='javascript://' onmouseover='move_right()' onmouseout='stop()'><img src='/themes/default/en-us/common/admin/images/btn_scroll-right.gif' border=0 name='scroll_right'></a></div></td>";
  html = html + "</tr></table>";
  try{
	  document.write(html);
  }catch(e){};

  tabWin = new tabControl(this.scrollPX,this.scrollSpeed,this.width);

  window.onresize=adjustWidth;

  if (!tabWin.width) { document.all.tabWin.style.width = document.body.clientWidth-(tabWin.arrowWidth*2)-document.body.leftMargin-document.body.rightMargin-18; }
  else { document.all.tabWin.style.width = tabWin.width ;}
  document.all.tabWin.style.overflow="hidden";
  tabWin.parent.style.clip = "rect(0," + (screenWidth-tabWin.arrowWidth) + ",85,0)";

}

function adjustWidth()
{
//alert(document.body.clientWidth)
  if (!tabWin.width) { if(document.body.clientWidth!=0) {document.all.tabWin.style.width = document.body.clientWidth-(tabWin.arrowWidth*2)-document.body.leftMargin-document.body.rightMargin;} }
  else { document.all.tabWin.style.width = tabWin.width }
}

// -------------------------------------------------------------------------------
// The below are layer manipulation functions used to set and scroll the tabs
// -------------------------------------------------------------------------------

function move_left(){
	if(tabWin.x<0){
		tabWin.move(tabWin.scrollPX,0);
		tabWin.effect=setTimeout("move_left()",tabWin.scrollSpeed);
	}
}

function move_right(){
	if(tabWin.x>-(tabWin.obj.offsetWidth-(tabWin.parent.style.pixelWidth))){
	tabWin.move(-tabWin.scrollPX,0)
		tabWin.effect=setTimeout("move_right()",tabWin.scrollSpeed); 
	}
}

function stop() 
{
  clearTimeout(tabWin.effect);
}

function clipLyr(t,r,b,l)
{
  this.css.clip="rect("+t+","+r+","+b+","+l+")";
}

function moveLyr(x,y)
{
  this.x=this.x+x;
  this.y=y;
  this.css.left=this.x;
  this.css.top=this.y;
}
