<!--
//////////////////
// PAGES OBJECT //
//////////////////

//Creating Pages object to represent the Pages in memory
var Pages = new Object;

//Pages variables
Pages.Container		= Element_ByID("pages_container");//Container for all the Tabs HTML objects

Pages.Objects_IDs	= new Array; //List array for the existing Pages objects' IDs (numeric). Contains all existing Page IDs
Pages.Objects		= new Array; //Associated array for the existing Pages objects (HTML::DIV)
//Pages.Handlers		= new Array; //Array for the existing Pages handlers (for handling events)

Pages.Comm		= new Object; //Pages communication handler - Not implemented (fully) yet - Keeps track of tabs Ajax communications
Pages.Comm.Statuses	= new Array; //Array for the Pages communication channels status flags


//Variables default value
Pages.ActivePageID	= null; //Which Page (by ID) is active

Pages.CommandExecState	= false; //Indicates if the system is executing (ajax) command

Pages.Comm		= new Object;
Pages.Comm.Statuses	= new Array;

Pages.EditMode		= true; //Indicates if a Pages are in edit mode



/*
Functions:
Add a page
delete a page
activate a page
	Show page
	Hide page

	
Page function:
Add -  Physically only, Data is created with Tab delete
Delete - Physically only, Data is deleted with Tab delete
Refresh
	Show
	Hide
*/






	
/////////////////////
// PAGES FUNCTIONS //
/////////////////////

	
Pages.Init = function() {}




Pages.Comm.UpdateCommIndicator = function()
{
}




Pages.Refresh = function()
{
	//Refreshing active page
	//Boxes.Refresh();
	//Page.Refresh();
	
}




Pages.AddPage = function(PageID)
{//Creates a new Page object (HTML::DIV)
	if (PageID<=0) {return false}; //Only pages with valid ID need a page
	
	var NewPage = CreatePageHTML(PageID);
	NewPage.Hide = Page_Hide;
	NewPage.Show = Page_Show;
	NewPage.Refresh = Page_Refresh;
	NewPage.Init = Page_Init;
	
	Pages.Container.appendChild(NewPage);
	
	Pages.Objects[PageID] = NewPage; //Adds Page (HTML::DIV) Object to Pages.Objects associated array
	Pages.Objects_IDs[Pages.Objects_IDs.length] = PageID; //Adds Page ID# (numeric) to Pages.Objects_IDs ordered list array

	NewPage.Init();
	
	//Free up memory
	NewPage = null;
	
}




Pages.ActivatePage = function(PageID)
{//Activates (shows) a page
	if (Pages.ActivePageID == PageID) {return}; //Page already active
	var NewPage = Pages.Objects[PageID];
	if (NewPage)
	{
		if (Pages.ActivePageID != null) {Pages.Objects[Pages.ActivePageID].Hide()}; //Hide current page
		Pages.Objects[PageID].Show();
		Pages.ActivePageID = PageID;
	}
	else
	{//Unexpected error - Page doesn't exist (After successful Tab activation). Notify user
		window.alert("Unexpected error - Page #"+PageID+" doesn't exist");
	}
	
	NewPage = null; //Free up memory
}











////////////////////
// PAGE FUNCTIONS //
////////////////////




function CreatePageHTML(PageID)
{
	var NewPage=document.createElement("DIV");
	NewPage.id = 'page_'+PageID;
	NewPage.PageID = PageID;
	NewPage.className = 'page';
	NewPage.style.display = 'none';
	var ContainersTableClass = "";
	if (Pages.EditMode) {ContainersTableClass = "containers_table_edit"};
	
	NewPage.innerHTML = "<table class=containers_table pages_table_nospace'>"+
	
			"	<tr class='pages_table_nospace'>"+
			"		<td class='container_cell pages_table_nospace' colspan=3><div class='container' id='container_header_"+PageID+"' container_id=0></div></td>"+
			"	</tr>"+
		
			"	<tr class='pages_table_nospace'>"+
			"		<td width=25% class='container_cell pages_table_nospace'><div class='container' id='container_left_"+PageID+"' container_id=1></div></td>"+
			
			"		<td width=50% class='container_cell pages_table_nospace'><div class='container' id='container_main_"+PageID+"' id='container_main_"+PageID+"' container_id=2></div></td>"+
			
			"		<td width=25% class='container_cell pages_table_nospace'><div class='container' id='container_right_"+PageID+"' container_id=3></div></td>"+
			"	</tr>"+
	
			"	<tr class='pages_table_nospace'>"+
			"		<td class='container_cell pages_table_nospace' colspan=3><div class='container' id='container_footer_"+PageID+"' container_id=4></div></td>"+
			"	</tr>"+
			
			"</table>";
	
	ContainersTableClass = null; //Free up memory
	return(NewPage);
}



Page_Init = function()
{//Initializing page: Setting containers; Adding terminators
	var ContainerName = ["Header","Left","Main","Right","Footer"];
	var IndexRun;
	
	this.Containers = new Array;
	for (IndexRun=0; IndexRun<=4; IndexRun++)
	{//...for each of the 5 containers
		this.Containers[IndexRun] = new Object; //Creating container
		this.Containers[IndexRun].ContainerID 	= IndexRun; //Setting container index
		this.Containers[IndexRun].Container	= Element_ByID("container_"+lc(ContainerName[IndexRun])+"_"+this.PageID); //Associating container object
		//Add Terminator boxs and associating with TerminatorBox param
		this.Containers[IndexRun].TerminatorBox = AppendBox(this.PageID,IndexRun, -this.PageID*10-2-IndexRun); //#1st param: PageID  ;  #2rd param: ContainerID(0..4)  ;  #3th param: BoxID  ;  #4th param: Title (no need);
		//"Terminator:"+lc(ContainerName[IndexRun])

		this.Containers[IndexRun].TerminatorBox.PageID=this.PageID; //Referencing back terminator's PageID
		this.Containers[IndexRun].TerminatorBox.ContainerID=IndexRun;  //Referencing back terminator's ContainerID
	};
	
	//Free up memory
	IndexRun = null;
	ContainerName = null;
}



/*

function IdentifyContainerID (ContainerObject)
{
	for (var IndexRun=0; IndexRun<=4; IndexRun++)
	{
		if (ContainerObject == Page.Containers[IndexRun].Container) return(IndexRun);
	}
	
	return (false);
}

*/

//A function for generating Event execution funcions
Page_Hide=function() {this.style.display="none"};
Page_Show=function() {this.style.display=""};
Page_Refresh=function() {this.Hide(); this.Show();};







-->
