function MPT_TabPane(el, bUseCookie) {
	if(!hasSupport() || el == null) return;
	
	this.element = el;
	this.element.tabPane = this;
	this.pages = [];
	this.selectedIndex = null;
	this.lastPage = null;
	this.winW=0;
	this.winH=0;
	this.useCookie = bUseCookie != null ? bUseCookie : true;
	
	this.element.className = this.classNameTag + " " + this.element.className;
	
	this.tabRow = document.createElement("div");
	this.tabRow.className = "tab-row";
	el.insertBefore(this.tabRow, el.firstChild);

	var tabIndex = 0;
	if ( this.useCookie ) {
		tabIndex = Number(MPT_TabPane.getCookie("MPT_tab_" + this.element.id));
		if ( isNaN(tabIndex))
			tabIndex = 0;
	}
	this.selectedIndex = tabIndex;
	
	var cs = el.childNodes;
	var n;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab-page") {
			this.addTabPage(cs[i]);
		}
	}
}
MPT_TabPane.prototype = {
	classNameTag:		"dynamic-tab-pane-control",
	setSelectedIndex:	function (n){
		if(!this.pages[n].enabled) return;
		if(this.selectedIndex != n){
			if (this.selectedIndex != null && this.pages[this.selectedIndex] != null)
				this.pages[this.selectedIndex].hide();
			this.selectedIndex = n;
			this.pages[this.selectedIndex].show();
			
			if(this.useCookie)
				MPT_TabPane.setCookie( "MPT_tab_" + this.element.id, n );	// session cookie

			this.checkButtons(n);
		}
		if(this.pages[n].clickFunction)eval(this.pages[n].clickFunction);
	},
	
	getSelectedIndex:	function (){
		return this.selectedIndex;
	},
	
	addTabPage:	function (oElement, bEnabled) {
		if(!hasSupport()) return;
		
		if(oElement.tabPage == this)
			return oElement.tabPage;
	
		var n = this.pages.length;
		var tp = this.pages[n] = new MPT_TabPage(oElement, this, n);
		tp.tabPane = this;
		
		this.tabRow.appendChild(tp.tab);
				
		if(n==this.selectedIndex){tp.show()}else{tp.hide()};

		bEnabled = bEnabled != null ? bEnabled : true;
		if(bEnabled){tp.enable()}else{tp.disable()};

		return tp;
	},
	
	enable: function(n){
			this.pages[n].enable();
	},
	
	disable: function(n){
			this.pages[n].disable();
	},
	
	enableAll: function(){
		for (var i=0;i<this.pages.length;i++)
			this.pages[i].enable();
	},
	
	disableAll: function(){
		for (var i=0;i<this.pages.length;i++)
			this.pages[i].disable();
	},
	
	checkTabs: function (b){
		n = this.selectedIndex+1;
		if(!this.pages[n].locked){if(b){this.enable(n)}else{this.disable(n)}};
		this.pages[n].lastenabled=this.pages[n].enabled;
		for(i=n+1;i<this.LastPage;i++){
			if((b)&&(this.pages[i].lastenabled)){this.enable(i)}else{this.disable(i)};
		}
		this.disable(this.lastPage);
		tp1.checkButtons()
	},
	
	checkButtons: function(n){
		var o;
		n = n != null ? n : this.selectedIndex;
		if((o=document.getElementById("wizButtons"))!=null){
			if(o.parentNode!=this.element)return;
		}
		if((o=document.getElementById("btnPrev"))!=null){
			if((n>0)&&(n<this.lastPage)){o.disabled=false;}else{o.disabled=true};
		}
		if((o=document.getElementById("btnNext"))!=null){
			if((n<this.lastPage)&&(this.pages[n+1].enabled)){
				o.disabled=false;}else{o.disabled=true};
		}
		if((o=document.getElementById("btnFinished"))!=null){
			b=true;
			for(i=0;i<this.lastPage;i++){
				if(!this.pages[i].enabled)b=false;
			}
			if(!this.pages[this.lastPage].finished)b=false;
			if(this.selectedIndex>=this.lastPage)b=false;
			if(b){o.disabled=false;}else{o.disabled=true};
		}
		if((o=document.getElementById("btnHelp"))!=null){
			if(n<=this.lastPage){o.disabled=false;}else{o.disabled=true};
		}
	},
	
	resize: function() {
		if((this.winW==getWindowWidth())||(this.winH==getWindowHeight()))return;
		this.winW=getWindowWidth();this.winH=getWindowHeight();
		var e=this.element.id;lt=layer("wiz"+e);
		w=this.winW-(lt.getLeft()*2)-2;h=this.winH-lt.getTop()-3;
		if(isNC6){w=w-15;h=h-15}else{h=h-20};
		lt.size(w,h);
		if(isNC6){w=lt.getWidth()-3;h=lt.getHeight()-20;lt.style.overflow='hidden';};
		for(i=0;i<this.pages.length;i++){
			this.pages[i].element.style.width=w;this.pages[i].element.style.height=h;
			l=document.getElementById("wizMap"+e+i);
			if(l!=null){
				l.style.width=w-lt.getLeft()-7;l.style.height=h-lt.getTop()+9;
				l=document.getElementById("wizMapIframe"+e+i);
				if(l!=null){
					l.style.width=w-lt.getLeft()-9;l.style.height=h-lt.getTop()+6;
				}
			}
		}
	}
};
function MPT_TabPage(el, tabPane, nIndex){
	if (!hasSupport() || el == null) return;
	
	this.element = el;
	this.element.tabPage = this;
	this.index = nIndex;
	
	var cs = el.childNodes;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab") {
			this.tab = cs[i];
			break;
		}
	}
	var a = document.createElement( "A" );
	a.href = "javascript:void 0;";
	while (this.tab.hasChildNodes())
		a.appendChild(this.tab.firstChild);
	this.tab.appendChild(a);
	var oThis = this;
	this.tab._onclick = function () {oThis.select();};
	this.tab._onmouseover = function () {MPT_TabPage.tabOver(oThis);};
	this.tab._onmouseout = function () {MPT_TabPage.tabOut(oThis);};
	this.enabled = false;
}
MPT_TabPage.prototype = {
	enable: function (){
		this.tab.onclick = this.tab._onclick;
		this.tab.onmouseover = this.tab._onmouseover;
		this.tab.onmouseout = this.tab._onmouseout;
		this.enabled=true;
		if(this.index==this.tabPane.getSelectedIndex()){this.show()}else{this.hide()}
	},

	disable: function (){
		this.tab.onclick = function (){return true};
		this.tab.onmouseover = function(){return true};
		this.tab.onmouseout = function(){return true};
		this.enabled=false;
		var el = this.tab;
		var s = el.className + " disabled";
		s = s.replace(/ +/g, " ");
		el.className = s;
	},

	show:	function (){
		var el = this.tab;
		var s = el.className + " selected";
		s = s.replace(/ +/g, " ");
		el.className = s;
		this.element.style.display = "block";
	},

	hide:	function (){
		var el = this.tab;
		var s = el.className;
		s = s.replace(/ selected/g, "");
		s = s.replace(/ disabled/g, "");
		el.className = s;
		this.element.style.display = "none";
	},

	select:	function (){
		this.tabPane.setSelectedIndex(this.index);
	}
};
MPT_TabPage.tabOver = function (tabpage){
	var el = tabpage.tab;
	var s = el.className + " hover";
	s = s.replace(/ +/g, " ");
	el.className = s;
};
MPT_TabPage.tabOut = function (tabpage){
	var el = tabpage.tab;
	var s = el.className;
	s = s.replace(/ hover/g, "");
	el.className = s;
};
function setupAllTabs() {
	if ( !hasSupport() ) return;

	var all = document.getElementsByTagName( "*" );
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var tabPageRe = /tab\-pane/;
	var cn, el;

	for ( var i = 0; i < l; i++ ) {
		el = all[i]
		cn = el.className;

		if(cn=="") continue;
	
		if(tabPaneRe.test(cn) && !el.tabPane)
			new MPT_TabPane(el);
	
		else if(tabPageRe.test(cn) && !el.tabPage && tabPaneRe.test(el.parentNode.className))
		{
			el.parentNode.tabPane.addTabPage(el);
		}
	}
	tp1.checkButtons(tp1.selectedIndex);
	var o=window.frames['wizMapIframetabPane4'].window;
}
MPT_TabPane.setCookie = function ( sName, sValue, nDays ) {
	var expires = "";
	if (nDays) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};
MPT_TabPane.getCookie = function (sName){
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

MPT_TabPane.removeCookie = function (name){
	setCookie(name, "", -1);
};
function hasSupport() {
	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasSupport.support = ( typeof document.implementation != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) || ie55 )
			
	if (ie55) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function (sTagName) {
			if ( sTagName == "*" )
				return document.all;
			else
				return document._getElementsByTagName(sTagName);
		};
	}
	
	return hasSupport.support;
}

