function CTabs(tabs,current){
	this.tabs = tabs;
	this.currentSheet = current;
	this.onclick = null; //user handler
	this.document = null;
	
	
	this.isSelected = function(sheet){return this.currentSheet == sheet;}

	//change current Tab
	this.selectTab = function(sheet){
		this.currentSheet = sheet;
		this.stateUpdate();
	}

	//handle tab onclick
	this.click = function(oTab){
		var sheet = oTab.getAttribute('sheet');
		this.selectTab(sheet);
		
		if(this.onclick) this.onclick(row);
	}
	
	// all tabs state update
	this.stateUpdate = function(){
		var oThis = this;
		oTabs = this.document.getElementById(this.tabs);
		if(!oTabs) return;
		var oList = oTabs.getElementsByTagName('a');
		if(!oList) return;
		for (i=0; i<oList.length; i++){
			var oTab = oList.item(i)
			var sheet = oTab.getAttribute('sheet');
			if(typeof(sheet)=='string' && sheet!=''){
				if(this.currentSheet == sheet){
					this.showTab(sheet);
					isset = (oTab.className.indexOf(' current') >=0) || (oTab.className=='current');
					if (!isset) oTab.className += ' current';
				}else{
					this.hideTab(sheet);
					oTab.className = oTab.className.replace( ' current', '' );
					if(oTab.className=='current') oTab.className='';
				}
			}
		}
	}
		
	this.hideTab = function(id){
		e = this.document.getElementById(id)
		if(e) e.style.display = 'none';
	}
	this.showTab = function(id){
		e = this.document.getElementById(id)
		if(e) e.style.display = 'block';
	}

	this.init= function(){
		if(!this.tabs) return false;
		this.document = document;
		//this.document = (this.tabs.ownerDocument)?this.tabs.ownerDocument:this.tabs.document;
		var oThis = this;
		oTabs = this.document.getElementById(this.tabs);
		if(!oTabs) return;
		var oList = oTabs.getElementsByTagName('a');
		if(!oList) return;
		for (i=0; i<oList.length; i++){
			var oTab = oList.item(i);
			var sheet = oTab.getAttribute('sheet');
			if(this.currentSheet == null && typeof(sheet)=='string' && sheet!=''){
				this.currentSheet = sheet
			}
			oTab.onclick = function(){oThis.click(this);}
		}
		this.stateUpdate();
		return true;
	}
	
	this.init();
	return this;
}
