var g_xWndHelp=null;
var g_bTOTD=false;

function pc_ShowHelpWnd(p_sTopic,p_bMustScrollDown)
{
	if(!p_sTopic){
		p_sTopic="home";
		var xWActive=g_xPitBoxes.GetActiveWindow();
		if(xWActive)
		{
			if(xWActive.m_sHelpID)
			{
				p_sTopic=xWActive.m_sHelpID;
			};
		};
	};
	if(!g_xWndHelp) {g_xWndHelp=new WndHelp;g_xWndHelp.Open();};
	g_xWndHelp.m_xWnd.Activate();
	g_xWndHelp.m_xWnd.GotoTopic(p_sTopic,p_bMustScrollDown);
};
/*
g_xPitBoxes.AddEventFilter("HelpKey",function(p_xE){
		if((p_xE.type=="keydown")||(p_xE.type=="keyup")||(p_xE.type=="keypress"))
		{
			if(p_xE.m_iKeyCode==112)
			{
				pit_StopE(p_xE);
				if(p_xE.type=="keyup")
				{
					pc_ShowHelpWnd();
				};
				return true;
			};
		};
		return false;
	},null);
if(document.body)
{
	document.body.onhelp=function(p_xE)
	{
		if(!p_xE){var p_xE=window.event;};
		pit_StopE(p_xE);
		return false;
	};
};
*/

function WndHelp()
{
	this.m_xWnd=null;

	this.Close=function() {if(this.m_xWnd) {this.m_xWnd.Close();};};
	this.Open=function()
	{
		var xThis=this;
		
		var iCW=g_xCanvas.m_iW;
		var iCH=g_xCanvas.m_iH;
		
		var iWW=Math.ceil(iCW*0.5);
		var iWH=Math.ceil(iCH*0.6);

		var xPlace=pc_GetWindowPlacement("help");
		var xW=this.m_xWnd=g_xCanvas.AddChild(new PCHelpWnd(xPlace[0],xPlace[1],xPlace[2],xPlace[3],g_L.pc_lbl_help));
		xW.OnClose=function()
		{
			var bMSD=g_xWndHelp.m_xWnd.m_bMustScrollDown;
			var sCT=g_xWndHelp.m_xWnd.m_sCurTopic;
			g_xWndHelp.m_xWnd.m_bClosed=true;
			g_xWndHelp=null;
			if(bMSD) {pc_ShowHelpWnd(sCT,true);};
		};

		var xBtn=xW.AddChild(new PCMainButton(0,0,120,20,"Home","Small"));
		xBtn.SetCmdID(1);
		xBtn.OnCmd=function(p_iCmd,p_xE)
		{
			pc_ShowHelpWnd();
			return false;
		};
		xW.AddChild(xBtn);
		xBtn=xW.AddChild(new PCMainButton(120,0,120,20,"Index","Small"));
		xBtn.SetCmdID(1);
		xBtn.OnCmd=function(p_iCmd,p_xE)
		{
			pc_ShowHelpWnd("index");
			return false;
		};
		xW.AddChild(xBtn);

		xBtn=xW.AddChild(new PCMainButton(240,0,120,20,"&lt;&lt;Prev","Small"));
		xBtn.SetCmdID(1);
		xBtn.OnCmd=function(p_iCmd,p_xE)
		{
			xW.GotoBack();
			return false;
		};
		xW.AddChild(xBtn);

		xBtn=xW.AddChild(new PCMainButton(360,0,120,20,"Next&gt;&gt;","Small"));
		xBtn.SetCmdID(1);
		xBtn.OnCmd=function(p_iCmd,p_xE)
		{
			xW.GotoForward();
			return false;
		};
		xW.AddChild(xBtn);

	};
};

function PCHelpWnd(p_iX,p_iY,p_iW,p_iH)
{
	PCHelpWnd.BaseCtor.call(this,"frmTopLvlWnd",p_iX,p_iY,p_iW,p_iH,g_L.pc_lbl_help,true,true);
	this.m_sTagName="div";
	if(!p_iX){p_iX=0;};
	if(!p_iY){p_iY=0;};
	if(!p_iW){p_iW=100;};
	if(!p_iH){p_iH=100;};
	
	this.m_iX=p_iX;
	this.m_iY=p_iY;
	this.m_iW=p_iW;
	this.m_iH=p_iH;
	
	this.AddTopLevelBehaviour(true,true,true,false,true);
	
	this.m_sPCWndType="help";
	
	this.m_xText=null;
	this.m_sDefaultTitle=g_L.pc_lbl_help;
	this.m_sTopicTitle="";
	this.m_sCurTopic="";
	this.m_xH1Handler=null;
	this.m_bMustScrollDown=false;
	
	this.m_asHistory=new Array();
	this.m_iHistoryIndex=-1;
};
Inherit(PCHelpWnd,PCTLWnd,"PCHelpWnd");

PCHelpWnd.prototype.OnResize=function()
{
	PCHelpWnd.Super.OnResize.call(this);
	this.m_xText.RefreshAttributes();
	this.RefreshAttributes();
};

PCHelpWnd.prototype.GotoBack=function()
{
	this.m_iHistoryIndex--;
	if((this.m_iHistoryIndex>=0)&&(this.m_iHistoryIndex<this.m_asHistory.length))
	{
		var sNewID=this.m_asHistory[this.m_iHistoryIndex];
		this.m_sCurTopic=sNewID;
		this.m_xText.LoadBBCode("/help/tpc_"+sNewID+".bbs",true);
	}
	else
	{
		this.m_iHistoryIndex++;
	};
};

PCHelpWnd.prototype.GotoForward=function()
{
	this.m_iHistoryIndex++;
	if((this.m_iHistoryIndex>=0)&&(this.m_iHistoryIndex<this.m_asHistory.length))
	{
		var sNewID=this.m_asHistory[this.m_iHistoryIndex];
		this.m_sCurTopic=sNewID;
		this.m_xText.LoadBBCode("/help/tpc_"+sNewID+".bbs",true);
	}
	else
	{
		this.m_iHistoryIndex--;
	};
};

PCHelpWnd.prototype.GotoTopic=function(p_sID,p_bMustScrollDown)
{
	this.m_bMustScrollDown=p_bMustScrollDown;
	
	if((this.m_asHistory.length>0)&&(this.m_iHistoryIndex>=0)&&(this.m_iHistoryIndex<this.m_asHistory.length-1))
	{
		this.m_asHistory.splice(this.m_iHistoryIndex+1,this.m_asHistory.length-(this.m_iHistoryIndex+1));
	};
	
	this.m_iHistoryIndex=this.m_asHistory.length;
	this.m_asHistory.push(p_sID);

	this.m_sTopicTitle=this.m_sDefaultTitle;
	if(!this.m_xText)
	{
//		pit_Log("Schedule ",p_sID);
		var xThis=this;
		window.setTimeout(function(){
			xThis.GotoTopic(p_sID,p_bMustScrollDown);
		},50);
		return;
	}
	else
	{
//		pit_Log("Go ",p_sID);
		this.m_sCurTopic=p_sID;
		
		this.m_xText.LoadBBCode("/help/tpc_"+p_sID+".bbs",true);
	};
	
	if(this.m_bMustScrollDown)
	{
		var xThis=this;
		var pChkScr=function(){
			if(xThis.m_bClosed) {return;};
			var iSP=0;
			var iSR=0;
			try {iSP=xThis.m_xText.m_xOutput.GetScrollPos();iSR=xThis.m_xText.m_xOutput.GetScrollRange();} catch(e) {return;};
			if(iSP>=iSR) {xThis.m_bMustScrollDown=false;} else {window.setTimeout(pChkScr,100);};
		};
		window.setTimeout(pChkScr,250);
	};
};

PCHelpWnd.prototype.RefreshAttributes=function()
{
	if(!this.m_xText)
	{
		var xT=this;
		this.m_xText=new PCBBCode(50,50,this.m_iW-100,this.m_iH-100);
		this.m_xText.m_sContentClass="pchelp";
		this.m_xH1Handler=this.m_xText.m_xRenderers["h1"];
		if(!this.m_xH1Handler)
		{
			this.m_xH1Handler=pit_GetDefaultBBCodeRenderer()["h1"];
		};
		this.m_xText.m_xRenderers["h1"]={In:function(p_xDest,p_sArgs,p_xCode,xRBehav)
		{
			if(p_xCode.content)
			{
				xT.m_sTopicTitle=xT.m_sDefaultTitle+" - "+p_xCode.content.join(" ");
				var iMax=Math.ceil(xT.m_iW/14);
				if(xT.m_sTopicTitle.length>iMax){xT.m_sTopicTitle=xT.m_sTopicTitle.substr(0,iMax)+"...";};
				if(xT.m_sTopicTitle!=xT.m_sText)
				{
						xT.SetText(xT.m_sTopicTitle);
				};
			};
			return xT.m_xH1Handler.In(p_xDest,p_sArgs,p_xCode,xRBehav);
		}};
		this.AddChild(this.m_xText);
	};
	PCHelpWnd.Super.RefreshAttributes.call(this);
	var xR=this.GetContentRect();
	this.m_xText.SetRect(xR.m_iX,xR.m_iY+20,xR.m_iW,xR.m_iH-20);
	this.m_xText.RefreshAttributes();
};

var g_xToolTipDiv=null;


function pc_HelpInitTooltips()
{
	g_xPitBoxes.OnHideToolTip=function()
	{
		if(g_xToolTipDiv)
		{
			g_xCanvas.MakeEl().removeChild(g_xToolTipDiv);
			g_xToolTipDiv=null;
		};	
	};
	g_xPitBoxes.OnShowToolTip=function(p_sID,p_iX,p_iY,p_hTargetBox)
	{
		if(g_xToolTipDiv)
		{
			g_xPitBoxes.OnHideToolTip();
		};
		var sToolTip
		if(p_sID.substr(0,1)=="@")
		{
			sToolTip=p_sID.substr(1);
		}
		else
		{
			sToolTip=g_xParsecToolTips[p_sID];
		};
		if(!sToolTip)
		{
			sToolTip="TOOLTIP MISSING: "+p_sID;
		};
		if(sToolTip.length>0)
		{
			var xTTD=document.createElement("div");
			xTTD.style.position="absolute";
	//		xTTD.style.left="0px";
	//		xTTD.style.top=(g_xCanvas.m_iH-20)+"px";
			xTTD.style.left=(p_iX+15)+"px";
			xTTD.style.top=(p_iY+5)+"px";
	//		xTTD.style.width=(g_xCanvas.m_iW)+"px";
			xTTD.style.width="auto";
			xTTD.style.height="auto";
			xTTD.style.fontSize="10px";
			xTTD.style.fontWeight="normal";
			xTTD.style.padding="2px";
			xTTD.style.color="#efb";
			xTTD.style.backgroundColor="#234";
			xTTD.style.border="solid 1px #8ab";
			xTTD.zIndex=999;
			pit_SetIH(xTTD,sToolTip);
			g_xToolTipDiv=xTTD;
			pit_SetTransparency(xTTD,0.66);
			g_xCanvas.MakeEl().appendChild(xTTD);
	//		pit_Log("ShowTT ",p_iX," ",p_iY," ",p_sID," ",p_hTargetBox);
		};
	};	
};

function pc_ShowTOTD()
{
	if(g_bTOTD){return;}
	g_bTOTD = true;
	if(!g_bShowTOTD){return;}
	var asTOTD=["totd_action_queue","totd_dyson_sphere","totd_level_up","totd_noob_safety","totd_security_warning","totd_sss"];
	pc_ShowHelpWnd(asTOTD[Math.floor(Math.random()*asTOTD.length)]);
}

function PCTutorial()
{
	this.m_xWnd=null;
	this.m_xDivT=null;
	this.m_xDivL=null;
	this.m_xDivR=null;
	this.m_xDivB=null;
	this.m_xDivTrack=null;
	this.m_iRX=0;
	this.m_iRY=0;
	this.m_iRW=0;
	this.m_iRH=0;
	this.m_iRLW=2;
	this.m_iDoneMask=0;
	this.m_iCurMode=0;
	
	this.DF_DLGFLEET		=(1<<0);
	this.DF_WNDFLEETINFO	=(1<<1);
	this.DF_WNDFLEETINFO2	=(1<<2);
	this.DF_WNDSHIPINFO		=(1<<3);
	this.DF_WNDSHIPINFO2	=(1<<4);
	this.DF_WNDMAP			=(1<<5);
	this.DF_WNDMAP2			=(1<<6);
	this.DF_WNDMAP3			=(1<<7);
	this.DF_WNDMAP4			=(1<<8);
	this.DF_WNDMAP5			=(1<<9);
	this.DF_WNDMAP6			=(1<<10);
	this.DF_WNDACTION		=(1<<11);
	this.DF_WNDACTION2		=(1<<12);
	this.DF_WNDMAP7			=(1<<13);
	this.DF_WNDMAP8			=(1<<14);
	this.DF_WNDTECH			=(1<<15);
	this.DF_START			=(1<<16);
	this.DF_WNDTECH2		=(1<<17);
	
	this.m_bBtnUpgPressed=false;
	this.m_bBtnTravelPressed=false;
	this.m_bStatSkipped=false;
	this.m_bBtnMinePressed=false;
	this.m_bBtnTechSavePressed=false;
	
	this.m_xCloseBtn=null;
	this.m_bCloseBtn=true;
	
	this.Close=function() {if(this.m_xWnd) {this.m_xWnd.Close();};};
	this.Open=function()
	{
		var xThis=this;
		var iW=500;
		var iH=200;
		var xPlace=pc_GetWindowPlacement("tut",iW,iH);
		var xW=this.m_xWnd=(new PCTLWnd("frmTopLvlWnd",xPlace[0],xPlace[1],iW,iH,g_L.pc_tut_title,false,false));
		
		xW.AddTopLevelBehaviour(true,false,this.m_bCloseBtn,false,true);
		
		g_xCanvas.AddChild(xW);
		xW.OnClose=function() {
			xThis.HideR();
			window.clearInterval(xThis.m_iTick);
			window.clearInterval(xThis.m_iTrack);
			xThis.m_xWnd=null;
		};
		xW.Activate();

		this.m_xText=new PCBBCode(4,4,xW.m_iW-20,xW.m_iH-44);
		xW.AddChild(this.m_xText);

		this.m_iTick=window.setInterval(function(){g_xTUT.Tick();},1000);
		this.m_iTrack=window.setInterval(function(){g_xTUT.Track();},100);
	};
	
	this.Track=function()
	{
		if(!this.m_xDivTrack) {return;};
		if(typeof(this.m_xDivTrack.offsetLeft)=="undefined") {this.HideR();return;};
		if(!this.m_xDivTrack.parentNode) {this.HideR();return;};
		var xP=pit_GetAbsPos(this.m_xDivTrack);
		this.m_xDivT.style.top=(xP.m_iY+this.m_iRY)+"px";
		this.m_xDivT.style.left=(xP.m_iX+this.m_iRX)+"px";
		this.m_xDivL.style.top=(xP.m_iY+this.m_iRY)+"px";
		this.m_xDivL.style.left=(xP.m_iX+this.m_iRX)+"px";
		this.m_xDivB.style.top=(xP.m_iY+this.m_iRY+this.m_iRH-this.m_iRLW)+"px";
		this.m_xDivB.style.left=(xP.m_iX+this.m_iRX)+"px";
		this.m_xDivR.style.top=(xP.m_iY+this.m_iRY)+"px";
		this.m_xDivR.style.left=(xP.m_iX+this.m_iRX+this.m_iRW-this.m_iRLW)+"px";
		this.m_xDivT.style.visibility="";
		this.m_xDivL.style.visibility="";
		this.m_xDivR.style.visibility="";
		this.m_xDivB.style.visibility="";
	};
	
	this.Tick=function()
	{
		if((this.m_iDoneMask&this.DF_START)==0)
		{
			if(g_xWndMainBar!=null)
			{
				this.ShowR(g_xWndMainBar.m_xWnd.GetBtn("tech").GetEl(),0,0,80,18);
				this.m_iDoneMask|=this.DF_START;
				this.m_iCurMode=this.DF_START;
				pit_Log("DF_START");
				this.m_xText.LoadBBCode("/help/tut_start.bbs",true);
				return;
			};
		};
		if((this.m_iDoneMask&this.DF_WNDTECH)==0&&(this.m_iDoneMask&this.DF_START)!=0)
		{
			if(g_xWndResearch!=null)
			{
				this.ShowR(g_xWndResearch.m_xWnd.GetEl(),446,130,20,20);
				this.m_iDoneMask|=this.DF_WNDTECH;
				this.m_iCurMode=this.DF_WNDTECH;
				pit_Log("DF_WNDTECH");
				this.m_xText.LoadBBCode("/help/tut_wndtech.bbs",true);
				return;
			};
		};
		if((this.m_iDoneMask&this.DF_WNDTECH2)==0&&(this.m_iDoneMask&this.DF_WNDTECH)!=0)
		{
			if(g_xWndResearch!=null)
			{
				if(this.m_bBtnTechSavePressed)
				{
					this.ShowR(g_xWndResearch.m_xWnd.GetEl(),458,4,20,20);
					this.m_iDoneMask|=this.DF_WNDTECH2;
					this.m_iCurMode=this.DF_WNDTECH2;
					pit_Log("DF_WNDTECH2");
					this.m_xText.LoadBBCode("/help/tut_wndtech2.bbs",true);
					return;
				};
			}
			else
			{
				this.m_iDoneMask|=this.DF_WNDTECH2;
				pit_Log("skip DF_WNDTECH2");
			};
		};
		if((this.m_iDoneMask&this.DF_DLGFLEET)==0&&(this.m_iDoneMask&this.DF_WNDTECH2)!=0)
		{
			if(g_xDlgFleet&&g_xDlgFleet.m_xWnd&&g_xDlgFleet.m_axFleet&&g_xDlgFleet.m_axFleet.length>0)
			{
				if(g_xWndResearch==null)
				{
					this.ShowR(g_xDlgFleet.m_xWnd.GetEl(),12,28,160,24);
					this.m_iDoneMask|=this.DF_DLGFLEET;
					this.m_iCurMode=this.DF_DLGFLEET;
					pit_Log("DF_DLGFLEET");
					this.m_xText.LoadBBCode("/help/tut_dlgfleet.bbs",true);
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDFLEETINFO)==0&&(this.m_iDoneMask&this.DF_DLGFLEET)!=0)
		{
			if(g_axFleetWnds&&g_axFleetWnds.length>0)
			{
				var xFW=g_axFleetWnds[0];
				var xFleet=xFW.GetCurFleet();
				if(xFleet&&xFleet.m_axShips&&xFleet.m_axShips.length>=2)
				{
					var bSkip=false;
					var sShip=null;
					for(var i=1;i<xFleet.m_axShips.length;i++)
					{
						var xS=xFleet.m_axShips[i];
						if(xS.m_iType==0) {sShip=xS.m_sName;break;} else {bSkip=true;};
					};
					var xSP=null;
					if(xFW.m_xPan&&xFW.m_xPan.m_axSubPanels&&xFW.m_xPan.m_axSubPanels.length>=2)
					{
						for(var i=1;i<xFW.m_xPan.m_axSubPanels.length;i++)
						{
							if(xFW.m_xPan.m_axSubPanels[i].m_sTitle==sShip)
							{
								xSP=xFW.m_xPan.m_axSubPanels[i];
								break;
							};
						};
					};
					
					if(sShip&&xSP)
					{
						this.ShowR(xSP.m_xBar.GetEl(),0,0,200,20);
						this.m_iDoneMask|=this.DF_WNDFLEETINFO;
						this.m_iCurMode=this.DF_WNDFLEETINFO;
						pit_Log("DF_WNDFLEETINFO");
						this.m_xText.LoadBBCode("/help/tut_wndfleetinfo.bbs",true);
						return;
					};
					if(bSkip)
					{
						this.m_iDoneMask|=this.DF_WNDSHIPINFO;
						this.m_iDoneMask|=this.DF_WNDSHIPINFO2;
						return;
					};
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDFLEETINFO2)==0&&(this.m_iDoneMask&this.DF_WNDFLEETINFO)!=0)
		{
			if(g_axFleetWnds&&g_axFleetWnds.length>0)
			{
				var xFW=g_axFleetWnds[0];
				var xFleet=xFW.GetCurFleet();
				if(xFleet&&xFleet.m_axShips&&xFleet.m_axShips.length>=2)
				{
					var sShip=null;
					for(var i=1;i<xFleet.m_axShips.length;i++)
					{
						var xS=xFleet.m_axShips[i];
						if(xS.m_iType==0) {sShip=xS.m_sName;break;};
					};
					var xSP=null;
					if(xFW.m_xPan&&xFW.m_xPan.m_axSubPanels&&xFW.m_xPan.m_axSubPanels.length>=2)
					{
						for(var i=1;i<xFW.m_xPan.m_axSubPanels.length;i++)
						{
							if(xFW.m_xPan.m_axSubPanels[i].m_sTitle==sShip)
							{
								xSP=xFW.m_xPan.m_axSubPanels[i];
								break;
							};
						};
					};
					
					if(sShip&&xSP&&xSP.m_xWnd.m_axSubBoxes.length>0)
					{
						for(var i=0;i<xSP.m_xWnd.m_axSubBoxes.length;i++)
						{
							if(xSP.m_xWnd.m_axSubBoxes[i].m_bBtnBody)
							{
								this.ShowR(xSP.m_xWnd.m_axSubBoxes[i].GetEl(),0,0,128,96);
								this.m_iDoneMask|=this.DF_WNDFLEETINFO2;
								this.m_iCurMode=this.DF_WNDFLEETINFO2;
								pit_Log("DF_WNDFLEETINFO2");
								this.m_xText.LoadBBCode("/help/tut_wndfleetinfo2.bbs",true);
								return;
							};
						};
					};
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDSHIPINFO)==0&&(this.m_iDoneMask&this.DF_WNDFLEETINFO2)!=0)
		{
			if(g_axFleetWndsShip&&g_axFleetWndsShip.length>0)
			{
				var xSW=g_axFleetWndsShip[0];
				var xFleet=xSW.GetCurFleet();
				if(xFleet&&xFleet.m_axShips&&xFleet.m_axShips.length>=2)
				{
					var iIdxS=-1;
					for(var i=0;i<xFleet.m_axShips.length;i++) {if(xFleet.m_axShips[i].m_iShipID==xSW.m_iShipID) {iIdxS=i;break;};};
					if(iIdxS!=-1)
					{
						var xS=xFleet.m_axShips[iIdxS];
						var xSP=null;
						var bSkip=false;
						if(xSW.m_xPan&&xSW.m_xPan.m_axSubPanels&&xSW.m_xPan.m_axSubPanels.length>=2)
						{
							for(var i=0;i<xSW.m_xPan.m_axSubPanels.length;i++)
							{
								if(i>3) {bSkip=true;break;};
								if(xSW.m_xPan.m_axSubPanels[i].m_xWnd.m_iModType==10)
								{
									if(xSW.m_xPan.m_axSubPanels[i].m_xWnd.m_iModLevel==0)
									{
										xSP=xSW.m_xPan.m_axSubPanels[i];
									}
									else
									{
										bSkip=true;
									};
									break;
								};
							};
						};
						if(xSP)
						{
							this.ShowR(xSP.m_xBar.GetEl(),0,0,200,20);
							this.m_iDoneMask|=this.DF_WNDSHIPINFO;
							this.m_iCurMode=this.DF_WNDSHIPINFO;
							pit_Log("DF_WNDSHIPINFO");
							this.m_xText.LoadBBCode("/help/tut_wndshipinfo.bbs",true);
							return;
						};
						if(bSkip)
						{
							this.m_iDoneMask|=this.DF_WNDSHIPINFO;
							this.m_iDoneMask|=this.DF_WNDSHIPINFO2;
							return;
						};
					};
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDSHIPINFO2)==0&&(this.m_iDoneMask&this.DF_WNDSHIPINFO)!=0)
		{
			if(g_axFleetWndsShip&&g_axFleetWndsShip.length>0)
			{
				var xSW=g_axFleetWndsShip[0];
				var xFleet=xSW.GetCurFleet();
				if(xFleet&&xFleet.m_axShips&&xFleet.m_axShips.length>=2)
				{
					var iIdxS=-1;
					for(var i=0;i<xFleet.m_axShips.length;i++) {if(xFleet.m_axShips[i].m_iShipID==xSW.m_iShipID) {iIdxS=i;break;};};
					if(iIdxS!=-1)
					{
						var xS=xFleet.m_axShips[iIdxS];
						var xSP=null;
						if(xSW.m_xPan&&xSW.m_xPan.m_axSubPanels&&xSW.m_xPan.m_axSubPanels.length>=2)
						{
							for(var i=0;i<xSW.m_xPan.m_axSubPanels.length;i++)
							{
								if(i>3) {break;};
								if(xSW.m_xPan.m_axSubPanels[i].m_xWnd.m_iModType==10&&xSW.m_xPan.m_axSubPanels[i].m_xWnd.m_iModLevel==0&&xSW.m_xPan.m_iActivePanel==i)
								{
									xSP=xSW.m_xPan.m_axSubPanels[i];
									break;
								};
							};
						};
						var xBtn=null;
						if(xSP&&xSP.m_xWnd.m_axSubBoxes.length>0)
						{
							for(var i=0;i<xSP.m_xWnd.m_axSubBoxes.length;i++)
							{
								if(xSP.m_xWnd.m_axSubBoxes[i].m_bBtnUpg)
								{
									xBtn=xSP.m_xWnd.m_axSubBoxes[i];
									break;
								};
							};
						};
					
						if(xBtn)
						{
							this.ShowR(xBtn.GetEl(),0,0,100,18);
							this.m_iDoneMask|=this.DF_WNDSHIPINFO2;
							this.m_iCurMode=this.DF_WNDSHIPINFO2;
							pit_Log("DF_WNDSHIPINFO2");
							this.m_xText.LoadBBCode("/help/tut_wndshipinfo2.bbs",true);
							return;
						};
					};
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP)==0&&(this.m_iDoneMask&this.DF_WNDSHIPINFO2)!=0)
		{
			if(g_xDlgFleet&&g_xDlgFleet.m_xWnd&&g_xDlgFleet.m_axFleet&&g_xDlgFleet.m_axFleet.length>0)
			{
				if(this.m_bBtnUpgPressed||g_axFleetWndsShip.length==0)
				{
					this.ShowR(g_xDlgFleet.m_xWnd.GetEl(),218,28,24,24);
					this.m_iDoneMask|=this.DF_WNDMAP;
					this.m_iCurMode=this.DF_WNDMAP;
					pit_Log("DF_WNDMAP");
					this.m_xText.LoadBBCode("/help/tut_wndmap.bbs",true);
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP2)==0/*&&(this.m_iDoneMask&this.DF_WNDMAP)!=0*/)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==3&&xMW.m_iPlanet!=-1&&xMW.m_iTutStation!=-1)
				{
					var xMW=g_axFleetMoveWnds[0];
					
					this.ShowR(xMW.m_xWnd.GetEl(),352,228,250,250);
					this.m_iDoneMask|=this.DF_WNDMAP2;
					this.m_iCurMode=this.DF_WNDMAP2;
					pit_Log("DF_WNDMAP2");
					this.m_xText.LoadBBCode("/help/tut_wndmap2.bbs",true);
					return;
				}
				else
				{
					this.m_iDoneMask|=this.DF_WNDMAP2;
					this.m_bStatSkipped=true;
					pit_Log("skip DF_WNDMAP2");
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP3)==0&&(this.m_iDoneMask&this.DF_WNDMAP2)!=0)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0&&(g_axStationWnds.length>0||this.m_bStatSkipped))
			{
				var xMW=g_axFleetMoveWnds[0];
				
				this.ShowR(xMW.m_xWnd.GetEl(),132,28,80,18);
				this.m_iDoneMask|=this.DF_WNDMAP3;
				this.m_iCurMode=this.DF_WNDMAP3;
				pit_Log("DF_WNDMAP3");
				this.m_xText.LoadBBCode("/help/tut_wndmap3.bbs",true);
				return;
			};
		};
		

		if((this.m_iDoneMask&this.DF_WNDMAP4)==0&&(this.m_iDoneMask&this.DF_WNDMAP7)==0&&(this.m_iDoneMask&this.DF_WNDMAP3)!=0)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==1&&xMW.m_iTutFleetPosX&&xMW.m_iTutFleetPosY&&xMW.m_xPan&&xMW.m_xPan.m_xPanIC)
				{
					this.ShowR(xMW.m_xPan.m_xPanIC.GetEl(),xMW.m_iTutFleetPosX-20,xMW.m_iTutFleetPosY-20,40,40);
					this.m_iDoneMask|=this.DF_WNDMAP4;
					this.m_iCurMode=this.DF_WNDMAP4;
					pit_Log("DF_WNDMAP4");
					this.m_xText.LoadBBCode("/help/tut_wndmap4.bbs",true);
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP5)==0&&(this.m_iDoneMask&this.DF_WNDMAP4)!=0)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==2&&xMW.m_iTutPlanetPosX&&xMW.m_iTutPlanetPosY&&xMW.m_xPan)
				{
					this.ShowR(xMW.m_xPan.GetEl(),xMW.m_iTutPlanetPosX-25,xMW.m_iTutPlanetPosY-25,50,50);
					this.m_iDoneMask|=this.DF_WNDMAP5;
					this.m_iCurMode=this.DF_WNDMAP5;
					pit_Log("DF_WNDMAP5");
					this.m_xText.LoadBBCode("/help/tut_wndmap5.bbs",true);
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP6)==0&&((this.m_iDoneMask&this.DF_WNDMAP4)!=0||(this.m_iDoneMask&this.DF_WNDMAP5)!=0))
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==3&&xMW.m_iPlanet!=-1)
				{
					this.ShowR(xMW.m_xBtnMove.GetEl(),0,0,80,18);
					this.m_iDoneMask|=this.DF_WNDMAP6;
					this.m_iCurMode=this.DF_WNDMAP6;
					pit_Log("DF_WNDMAP6");
					this.m_xText.LoadBBCode("/help/tut_wndmap6.bbs",true);
					return;
				};
			};
		};
		if((this.m_iDoneMask&this.DF_WNDACTION)==0&&(this.m_iDoneMask&this.DF_WNDMAP6)!=0)
		{
			if(g_xDlgFleet&&g_xDlgFleet.m_xWnd&&g_xDlgFleet.m_axFleet&&g_xDlgFleet.m_axFleet.length>0&&this.m_bBtnTravelPressed)
			{
				this.ShowR(g_xDlgFleet.m_xWnd.GetEl(),180,28,24,24);
				this.m_iDoneMask|=this.DF_WNDACTION;
				this.m_iCurMode=this.DF_WNDACTION;
				pit_Log("DF_WNDACTION");
				this.m_xText.LoadBBCode("/help/tut_wndaction.bbs",true);
				return;
			};
		};
		if((this.m_iDoneMask&this.DF_WNDACTION2)==0)
		{
			if(g_axFleetActionWnds.length>0)
			{
				this.HideR();
				this.m_iDoneMask|=this.DF_WNDACTION2;
				this.m_iCurMode=this.DF_WNDACTION2;
				pit_Log("DF_WNDACTION2");
				this.m_xText.LoadBBCode("/help/tut_wndaction2.bbs",true);
				return;
			};
		};
		if((this.m_iDoneMask&this.DF_WNDMAP7)==0&&(this.m_iDoneMask&this.DF_WNDACTION2)!=0)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==3&&xMW.m_iPlanet!=-1&&xMW.m_bTutCanMine)
				{
					this.ShowR(xMW.m_xWnd.GetEl(),548,134,16,16);
					this.m_iDoneMask|=this.DF_WNDMAP7;
					this.m_iCurMode=this.DF_WNDMAP7;
					pit_Log("DF_WNDMAP7");
					this.m_xText.LoadBBCode("/help/tut_wndmap7.bbs",true);
					return;
				};
			};
		};
		
		if((this.m_iDoneMask&this.DF_WNDMAP8)==0&&(this.m_iDoneMask&this.DF_WNDMAP7)!=0)
		{
			if(g_axFleetMoveWnds&&g_axFleetMoveWnds.length>0)
			{
				var xMW=g_axFleetMoveWnds[0];
				if(xMW.m_iCurrentView==3&&xMW.m_iPlanet!=-1&&this.m_bBtnMinePressed)
				{
					this.HideR();
					this.m_iDoneMask|=this.DF_WNDMAP8;
					this.m_iCurMode=this.DF_WNDMAP8;
					pit_Log("DF_WNDMAP8");
					this.m_xText.LoadBBCode("/help/tut_wndmap8.bbs",true);
					
					//tutorial is finished, add close button
					this.m_xCloseBtn=this.m_xWnd.AddChild(new PCMainButton(0,140,80,20,"Close","Small"));
					this.m_xCloseBtn.SetCmdID(1);
					var xThis=this;
					this.m_xCloseBtn.OnCmd=function(p_iCmd,p_xE)
					{
						xThis.Close();
						return;
					};
					return;
				};
			};
		};
		
		//pit_Log("T");
		//g_xTUT.ShowR(this.m_xWnd.GetEl(),12,28,160,24);
	};
	
	this.HideR=function()
	{
		this.m_xDivTrack=null;
		if(this.m_xDivT) {this.m_xDivT.parentNode.removeChild(this.m_xDivT);this.m_xDivT=null;};
		if(this.m_xDivL) {this.m_xDivL.parentNode.removeChild(this.m_xDivL);this.m_xDivL=null;};
		if(this.m_xDivR) {this.m_xDivR.parentNode.removeChild(this.m_xDivR);this.m_xDivR=null;};
		if(this.m_xDivB) {this.m_xDivB.parentNode.removeChild(this.m_xDivB);this.m_xDivB=null;};
	};
	this.ShowR=function(p_xParent,p_iX,p_iY,p_iW,p_iH)
	{
		this.HideR();
		this.m_iRX=p_iX;
		this.m_iRY=p_iY;
		this.m_iRW=p_iW;
		this.m_iRH=p_iH;
		var iLW=this.m_iRLW;
		
		var xD=this.m_xDivT=document.createElement("div");
		xD.style.position="absolute";xD.style.top=p_iY+"px";xD.style.left=p_iX+"px";
		xD.style.width=p_iW+"px";xD.style.height=iLW+"px";
		xD.style.backgroundColor="#f00";xD.style.visibility="hidden";

		var xD=this.m_xDivL=document.createElement("div");
		xD.style.position="absolute";xD.style.top=p_iY+"px";xD.style.left=p_iX+"px";
		xD.style.width=iLW+"px";xD.style.height=p_iH+"px";
		xD.style.backgroundColor="#f00";xD.style.visibility="hidden";

		var xD=this.m_xDivB=document.createElement("div");
		xD.style.position="absolute";xD.style.top=(p_iY+p_iH-iLW)+"px";xD.style.left=p_iX+"px";
		xD.style.width=p_iW+"px";xD.style.height=iLW+"px";
		xD.style.backgroundColor="#f00";xD.style.visibility="hidden";

		var xD=this.m_xDivR=document.createElement("div");
		xD.style.position="absolute";xD.style.top=p_iY+"px";xD.style.left=(p_iX+p_iW-iLW)+"px";
		xD.style.width=iLW+"px";xD.style.height=p_iH+"px";
		xD.style.backgroundColor="#f00";xD.style.visibility="hidden";
		
		document.body.appendChild(this.m_xDivT);
		document.body.appendChild(this.m_xDivL);
		document.body.appendChild(this.m_xDivB);
		document.body.appendChild(this.m_xDivR);
		this.m_xDivTrack=p_xParent;
	};
};

Inherit(PCTutorial,PCTLWnd,"PCTutorial");
var g_xTUT=new PCTutorial();
function pc_ShowTut(p_bCloseBtn)
{
	if(p_bCloseBtn==undefined){g_xTUT.m_bCloseBtn=true;}
	else{g_xTUT.m_bCloseBtn=p_bCloseBtn;};
	
	if(g_xTUT.m_xWnd) {g_xTUT.m_xWnd.Activate();}
	else {g_xTUT.Open();};
};
function pc_TutBtnUpgPressed() {g_xTUT.m_bBtnUpgPressed=true;};
function pc_TutBtnTravelPressed() {g_xTUT.m_bBtnTravelPressed=true;};
function pc_TutBtnMinePressed() {g_xTUT.m_bBtnMinePressed=true;};
function pc_TutBtnTechSavePressed() {g_xTUT.m_bBtnTechSavePressed=true;};

pit_ScriptDone("/js/pcwhelp.js");
