function TabBar(){
	this.ID=null;
	this.VariableName=null;
	this.TabCssClass=null;
	this.TabDisabledCssClass=null;
	this.TabHoverCssClass=null;
	this.TabSelectedCssClass=null;
	this.RightImage=new EndImage();
	this.LeftImage=new EndImage();
	this.Width=100;
	this.Height=50;
	this.TabBarHeight=26;
	this.TabPaneHeaderHeight=10;
	this.TabPaneFooterHeight=10;
	this.TabPaneHeaderCssClass=null;
	this.TabPaneFooterCssClass=null;
	this.TabPaneCssClass=null;
	this.OnClick=_onclick;//private
	this.OnHover=_onHover;//private
	this.OnLoad=_onLoad;//private
	this.SetOnClick=_setOnClick;
	this.TabCollection=new TabCollection();
	this.Resize=_resize;
	this.HideTab = _hideTab;
	this.ShowTab = _showTab;
	this.SetTabEnabled=_setTabEnabled;
	this.SetSelectedTab=_setSelected;
	this.SetTabText=_setTabText;
	this.GetSelectedTab=_getSelectedTab;
	this.GetVisibleCount=_getVisibleCount;
	
	var _funcOnClick=null;
	var _currentlySelectedTabIndx=null;
	
	function _setOnClick(func){
		_funcOnClick=func;
	}
	function _setTabEnabled(tabindx,value){
		var tab=this.TabCollection.TabArray[tabindx];
		tab.Enabled=value;
		if(value){
			document.getElementById(this.ID+'_lImg'+tabindx).src=tab.LeftImage.ImagePath;
			document.getElementById(this.ID+'_rImg'+tabindx).src=tab.RightImage.ImagePath;
			document.getElementById(this.ID+'_mid'+tabindx).className=tab.CssClass;
		}else{
			document.getElementById(this.ID+'_lImg'+tabindx).src=tab.LeftImage.DisabledImagePath;
			document.getElementById(this.ID+'_rImg'+tabindx).src=tab.RightImage.DisabledImagePath;
			document.getElementById(this.ID+'_mid'+tabindx).className=tab.DisabledCssClass;
		}
	}
	function _setTabText(tabindx,value){
		var tab=this.TabCollection.TabArray[tabindx];
		tab.Text=value;
		var tabdiv=document.getElementById(this.ID + "_mid" + tabindx);
		tabdiv.innerHTML=value;
	}
	function _setSelected(indx){
		__changetab(indx,this);		
	}
	
	function _getSelectedTab(){
		if(_currentlySelectedTabIndx==null)
			_currentlySelectedTabIndx=0;
		return this.TabCollection.TabArray[_currentlySelectedTabIndx];
	}
	
	function _resize(w,h){
		var main=document.getElementById(this.ID);
		var pane_header=document.getElementById(this.ID+'_paneheader');
		var pane_footer=document.getElementById(this.ID+'_panefooter');
		if(w){
			main.style.width=w+'px';
			pane_header.style.width=(w-2)+'px';
			pane_footer.style.width=(w-2)+'px';
		}
		if(h){
			main.style.height=h+'px';
		}
		var tabpane;
		for(var t=0;t<this.TabCollection.TabArray.length;t++){
			tabpane=document.getElementById(this.ID+'_pane'+t);
			if(w)
				tabpane.style.width=(w-2)+'px';
			if(h)
				tabpane.style.height=(h-this.TabBarHeight - this.TabPaneHeaderHeight - this.TabPaneFooterHeight)+'px';
		}
    }
	
	function _onclick(tabindx){
		__changetab(tabindx,this);
	}
	function __changetab(tabindx,thisObj){
		var tab=thisObj.TabCollection.TabArray[tabindx];
		if(!tab.Enabled)
			return;
		if(tab.URL!=null && tab.URL!=''){
			thisPage.Navigate(tab.URL);
			return;
		}
		if(_currentlySelectedTabIndx!=null){
			var ctab=thisObj.TabCollection.TabArray[_currentlySelectedTabIndx];
			ctab.Selected=false;
			if(ctab.Enabled){
			document.getElementById(thisObj.ID+'_lImg'+_currentlySelectedTabIndx).src=ctab.LeftImage.ImagePath;
			document.getElementById(thisObj.ID+'_rImg'+_currentlySelectedTabIndx).src=ctab.RightImage.ImagePath;
			document.getElementById(thisObj.ID+'_mid'+_currentlySelectedTabIndx).className=ctab.CssClass;
			}else{
				document.getElementById(thisObj.ID+'_lImg'+_currentlySelectedTabIndx).src=ctab.LeftImage.DisabledImagePath;
				document.getElementById(thisObj.ID+'_rImg'+_currentlySelectedTabIndx).src=ctab.RightImage.DisabledImagePath
				document.getElementById(thisObj.ID+'_mid'+_currentlySelectedTabIndx).className=ctab.DisabledCssClass;
			}
			
			document.getElementById(thisObj.ID+'_tab'+_currentlySelectedTabIndx).style.top=thisObj.UnSelectedTabTopOffset+'px';
			document.getElementById(thisObj.ID+'_pane'+_currentlySelectedTabIndx).style.display='none';
		}
		tab.Selected=true;
		document.getElementById(thisObj.ID+'_lImg'+tabindx).src=tab.LeftImage.SelectedImagePath;
		document.getElementById(thisObj.ID+'_rImg'+tabindx).src=tab.RightImage.SelectedImagePath;
		document.getElementById(thisObj.ID+'_mid'+tabindx).className=tab.SelectedCssClass;
		document.getElementById(thisObj.ID+'_tab'+tabindx).style.top='0px';
		document.getElementById(thisObj.ID+'_pane'+tabindx).style.display='block';
		_currentlySelectedTabIndx=tabindx;
		if(_funcOnClick)
			_funcOnClick(tab,document.getElementById(thisObj.ID+'_pane'+tabindx));
	}
	
	function _hideTab(tabIndex)
	{
	    var thisObj = this;
	    document.getElementById(thisObj.ID+'_lImg'+tabIndex).style.display='none';
		document.getElementById(thisObj.ID+'_rImg'+tabIndex).style.display='none';
		document.getElementById(thisObj.ID+'_mid'+tabIndex).style.display='none';
		document.getElementById(thisObj.ID+'_tab'+tabIndex).style.display='none';
		document.getElementById(thisObj.ID+'_pane'+tabIndex).style.display='none';
		document.getElementById(thisObj.ID+'_tab'+tabIndex).style.top=thisObj.UnSelectedTabTopOffset+'px';
		
	}
	
	function _showTab(tabIndex)
	{
	    var thisObj = this;
	    document.getElementById(thisObj.ID+'_lImg'+tabIndex).style.display='block';
		document.getElementById(thisObj.ID+'_rImg'+tabIndex).style.display='block';
		document.getElementById(thisObj.ID+'_mid'+tabIndex).style.display='block';
		document.getElementById(thisObj.ID+'_tab'+tabIndex).style.display='block';
		document.getElementById(thisObj.ID+'_pane'+tabIndex).style.display='block';
	//	document.getElementById(thisObj.ID+'_tab'+tabIndex).style.top='0px';
	}
	
	function _onHover(over,tabindx){
		var tab=this.TabCollection.TabArray[tabindx];
		if(tab.Selected || !tab.Enabled)
			return;
		var lImg=document.getElementById(this.ID+'_lImg'+tabindx);
		var rImg=document.getElementById(this.ID+'_rImg'+tabindx);
		var m=document.getElementById(this.ID+'_mid'+tabindx);
		if(over){
			if(tab.LeftImage.HoverImagePath!=null)
				lImg.src=tab.LeftImage.HoverImagePath;
			if(tab.RightImage.HoverImagePath!=null)
				rImg.src=tab.RightImage.HoverImagePath;
			if(tab.HoverCssClass!=null)
				m.className=tab.HoverCssClass;
		}else{
			lImg.src=tab.LeftImage.ImagePath;
			rImg.src=tab.RightImage.ImagePath;
			m.className=tab.CssClass;
		}
	}
	function _onLoad(){
		for(var t=0;t<this.TabCollection.TabArray.length;t++){
			if(this.TabCollection.TabArray[t].Selected){
				_currentlySelectedTabIndx=t;
				break;
			}
			
		}
	}
	function _getVisibleCount(){
		var cnt=0;
		for(var t=0;t<this.TabCollection.TabArray.length;t++){
			if(this.TabCollection.TabArray[t].Visible){
				cnt++;
			}
		}
		return cnt;
	}
}

function TabCollection(){
	this.TabArray=new Array();
}

function Tab(){
	this.Text='';
	this.CssClass=null;
	this.HoverCssClass=null;
	this.SelectedCssClass=null;
	this.DisabledCssClass=null;
	this.RightImage=new EndImage();
	this.LeftImage=new EndImage();
	this.Enabled=true;
	this.Selected=false;
	this.Width=100;
	this.CommandArgument=null;
	this.Index=null;
	this.URL=null;
}

