//************************************************************************************
// CXSims.CxPageLayout Objects - Specifies the Page Layout and Components
// The script create the innerHTML for the Page, using the following HTML files 
// - outerborder : defining the border, width, and location of the page
// - header : defining the page's header
// - menus  : defining the sites menu system
// - footer : defining the footer of the page (optional)
// By: CXS Consulting, Inc.
// Date: May 2008
// Version: 1.0
//*************************************************************************************
//
// Prefined CSS Styles for CxPageLayout
var cxPageBodyStyle = "PageBody"			// defining the background color for the PageBody
var cxPageInnerBodyStyle = "PageInnerBody"  // defining the background color for the PageBody
var cxPageSpacerStyle = "PageSpacer"		// defining the background color for the Spacer
var cxJsImageFolder = "_js/images"            // Basefolder for Control Symbol Images
//
//*************************************************************************************
// CxPageLayout Class - the main class that manages the page layout in columns and frames
//*************************************************************************************
//
function CxPageLayout(sParentFolder)
{
	this.mError = null;

	this.objName="CxPageLayout"+CxPageLayout.count++;
	eval(this.objName+"=this");
	this.PageCaption = null;
	this.SpacerWidth = 0;
	this.SpacerHeight = 0;
	this.PageWidth = null;
	if ((sParentFolder != null) && (sParentFolder != "")) 
		this.ParentFolder = sParentFolder;
	else
		this.ParentFolder = "";
	
	this.PageCells = [];
	this.ControlSymbols = [];
	
	this.ColumnWidths = [];
	this.NumColumns = 0;
	this.NumRows = 0;

	/*this.PageBody = null;
	this.PageBody = document.getElementById(sBodyID);
	if (this.PageBody == null)
		this.Error = "Unable to Document's Body Element["+sBodyID+"]"; */
	
	// Set or add to the error message
	this.SetError=function(sErrMsg)
	{
		if (sErrMsg == null)
			return;
			
		if (sErrMsg instanceof Error)
		{
			var Ex = sErrMsg;
			this.SetError(Ex.filename+"; "+Ex.linenumber+"; "+Ex.message)
			return;
		}
		
	  	if ((sErrMsg != null) && (sErrMsg != ""))
	  	{
	  	  if (this.mError == null)
	  	  	this.mError = sErrMsg
	  	  else
	  	  	this.mError += "<br>"+sErrMsg;
	  	}
	}	
	
	this.HasError=function()
	{
		return ((this.mError != null) && (this.mError != ""));
	}
	
	//Show the Error on the document
	this.ShowError=function(sErrMsg)
	{
		this.SetError(sErrMsg);
		
	  	if (this.mError != null) 
	  	{
	  	  document.write("<p>PAGELAYOUT ERROR: "+this.mError+"</p>");
	  	}
	}	
	
	// Set the page's width
	this.SetPageWidth = function(sWidth)
	{
		try
		{
			var iWidth = getIntNumber(sWidth,"PageWidth");
			if (isPercentVal(sWidth))
				throw new Error("PageWidth cannot be Percentage value");
			
			this.PageWidth = iWidth;
		}
		catch(ex)
		{
			this.SetError(ex);
		}
	}
	
	// Set the Page Format, which will format the page in PageCells
	this.SetPageFormat = function(iNumCols, bAddBlock, iLeftCol, iColSpan, sAlign)
	{
		this.NumColumns = 0;
		this.NumRows = 0;
		this.PageCells = [];
		this.ColumnWidths = [];
		var bSuccess = false;
		try
		{
			if ((iNumCols != null) && (!isNaN(iNumCols)) && (iNumCols > 0))
			  this.NumColumns = iNumCols;
			  
			this.NumRows = (this.NumColumns == 0)? 0: 1;
		
			if (this.NumColumns == 0)
				return true;
			
			
			var pLeftCol = this.NumColumns+1;
			var pTopRow = 0;
			var pColSpan = 1;
			var pAlign = "top";
			if ((bAddBlock !=null) && (bAddBlock))
			{
				if ((iLeftCol != null) && (!isNaN(iLeftCol)) && (iLeftCol >= 0))
				  pLeftCol = iLeftCol;
				  
				if ((iColSpan != null) && (!isNaN(iColSpan)) || (iColSpan > 1))
				  pColSpan = iColSpan;
				
				if (sAlign != null) 
				{
					var sVal = sAlign.toString().toLowerCase()
					if (sVal.indexOf("center") >= 0) 
						pAlign = "center"
					else if (sVal.indexOf("bottom") >= 0) 
						pAlign = "bottom";
				}
				
				if (pLeftCol > this.NumColumns-1)
					throw new Error("DisplayBlock.LeftCol["+this.NumColumns+"] is out of bounds");
					
				if (pLeftCol+pColSpan > this.NumColumns)
					throw new Error("DisplayBlock.ColumnSpan["+pColSpan+"] is out of bounds");
				
				this.NumRows = 2;
				pTopRow = 0;
				if (pAlign == "center")
					this.NumRows = 3;

				if (pAlign != "top")
					pTopRow = 1;
			}
			
			// Set all coumns to equal width
			var sWidth = (100/this.NumColumns).toFixed(0)+"%";
			for (var iCol=0; iCol < this.NumColumns; iCol++)
			{	
				this.ColumnWidths.push(sWidth);
			}
			
			for (var iRow =0; iRow < this.NumRows; iRow++)
			{
				var pColumns = [];
				for (var iCol=0; iCol < this.NumColumns; iCol++)
				{
					var pNewCell = null;
					if (iRow == 0) 
					{			
						if ((iCol < pLeftCol) || (iCol > (pLeftCol+pColSpan-1)))
							pNewCell = new CxPageCell(this,this.NumRows,1);
						else if (iRow == pTopRow) 
						{
							if (iCol == pLeftCol)
							{
								pNewCell = new CxPageCell(this,1,pColSpan); 
							}
						}
						else
							pNewCell = new CxPageCell(this,1,1);												
					}
					else if (iRow == pTopRow) 
					{
						if (iCol == pLeftCol)
						{
							sWidth  = ((pColSpan*100)/this.NumColumns).toFixed(0)+"%";
							pNewCell = new CxPageCell(this,1,pColSpan);
						}
					}
					else
					{
						sWidth  = (100/this.NumColumns).toFixed(0)+"%";
						if ((iCol >= pLeftCol) && (iCol <= (pLeftCol+pColSpan-1)))
							pNewCell = new CxPageCell(this,1,1);												
					}
					
					pColumns.push(pNewCell);
					if (pNewCell != null)
					{
						pNewCell.RowIndex = iRow;
						pNewCell.ColIndex = iCol;
					}
				}
				this.PageCells.push(pColumns);
			}	
			bSuccess = true;		
		}
		catch (ex)
		{
			this.PageCells = [];
			this.ColumnWidths = [];
			this.NumColumns = 0;
			this.NumRows = 0;
			this.SetError(ex);
			bSuccess = false;
		}	
		return bSuccess;
	}
	
	// Set Individua Column With as points (e.g., "100") or as a precentage of
	// the Page witdh (e.g., "20%"). iCol is the zero-base column index.
	this.SetColumnWidth = function(iCol, sWidth)
	{
		var sNewWidth = "";
		var bSuccess = false;
		var iColWidth = 0;
		try
		{
			if ((iCol == null) || (isNaN(iCol)) || (sWidth == null) || (sWidth == "")) 
				throw new Error("Invalid Column Index or Width");
			
			if ((iCol < 0) || (iCol > this.ColumnWidths.Length-1))
				throw new Error("Column Index is out of bounds");
			
			iColWidth = getIntNumber(sWidth,"ColumnWidth");
			var isPerc = isPercentVal(sWidth);
			if (isPerc) 
			{
				if ((iColWidth < 0) || (iColWidth > 100))
				throw new Error("Column Width is out of bounds[0..100%]");
			}
			else if (iColWidth < 0) 
				throw new Error("Column Width cannot be negative");
				
			this.ColumnWidths[iCol] = sWidth;
			bSuccess = true;
		}
		catch(ex)
		{
			this.SetError(ex);		
		}
		return bSuccess;
	}

	// Add the header Element
	// sWidth & sHeight is assumed to be text. sWidth should by the number of pixels
	// and sHeight should be a percent (e.g. '80%').  The style (i.e., the background color
	// for the spacer is set in the style sheet parameter 'PageSpacer') 
	// Default Width=0 (no spacer), Default Height=90%
	this.SetColumnSpacer = function(sWidth, sHeight)
	{	
		this.SpacerWidth= 0;
		this.SpacerHeight = 0;
		try
		{
			var dWidth = 0;
			if ((sWidth != null) && (sWidth != ""))
			{
				if (isPercentVal(sWidth))
					throw new Error("Spacer Width cannot be a percentage value");
					
			 	dWidth = getIntNumber(sWidth,"Width"); 
			}
			this.SpacerWidth = dWidth;
		 	if (this.SpacerWidth == 0)
		 	  return;

			var dHeight = 90;
			if ((sHeight != null) && (sHeight != ""))
			{
				if (!isPercentVal(sHeight))
					throw new Error("Spacer Height must be a percentage value");
					
			  	dHeight = getIntNumber(sHeight,"Height");
			}
			
			this.SpacerHeight = (dHeight >= 100)? 100: ((dHeight < 0)? 0: dHeight);
			
		}
		catch(ex)
		{
			this.SetError(ex)
		}
	}
	
	// Get the Image Source for sSymbol - preload the symbol images
	this.GetControlSrc = function(sSymbol)
	{
		var pSymbol = null;
		var pSymbolSrc = null;
		try
		{
			if ((sSymbol == null) || (sSymbol == ""))
			  return null;
			  
			if (this.ControlSymbols.length > 0)
			{
				for (var iSym = 0; iSym < this.ControlSymbols.length; iSym ++)
				{
					var pSym = this.ControlSymbols[iSym];
					if ((pSym != null) && (sSymbol == pSym.mame))
					{
						pSymbol = pSym;
						break;
					}
				}
			}
			
			if (pSymbol == null)
			{
				var sSrc = null;
				var sSymFile = sSymbol+".gif";
			  var sSrcPath = GetRelativePath(cxJsImageFolder, this.ParentFolder);
		
				if ((sSrcPath != null) && (sSrcPath.length = 0))
					throw new Error("Cannot Create Path for Src["+sSymFile+"]");
					
	 	     	sSrc = sSrcPath +"/"+sSymFile 
				
				var tempImage = new Image();
				tempImage.src = sSrc;

				var iLength = this.ControlSymbols.push(new Object());
				var pSymbol = this.ControlSymbols[iLength-1];

				pSymbol.src = sSrc;
				pSymbol.name = sSymbol;
			}
			
			
			if (pSymbol != null)
				pSymbolSrc = pSymbol.src;		
			
		}
		catch(ex)
		{
			throw new Error("GetControlSrc Error: "+ex.Message);
		}
		
		return pSymbolSrc;
	}
	
	// Get the PageCell in the gridcell. Return null if the indices is out of bounds
	// or the PageCell is not defined.
	this.GetPageCell = function(iRow,iCol)
	{
		var pCell = null;
		if ((iRow < 0) || (iRow >= this.PageCells.length))
			return pCell;
		
		var pColumns = this.PageCells[iRow];
		if ((pColumns == null) || (iCol >= pColumns.length) || (iCol < 0))
			return pCell;
			
		pCell = pColumns[iCol];
		return pCell;
	}
	
	//Get a column in row(iRow)'s width as a percent of the available page width
	//(i.e., after conidering the fixed width columns
	this.GetCellWidth = function(iPerc)
	{
		if (this.PageWidth == null) 
			throw new Error("PageWidth is unassigned");
			
		var iPgWidth = this.PageWidth;
		var iColCnt = this.NumColumns;
		var iSumPerc = 0;
		var sWidth = "";
		var iWidth = 0;
		
		if (iColCnt == 0)
			return iPgWidth;
			
		for (var iCol = 0; iCol < iColCnt; iCol++)
		{
			if (iCol > 0)
				iPgWidth -= this.SpacerWidth;

			var sWidth = this.ColumnWidths[iCol];
			if ((sWidth != null) && (sWidth != ""))
			{
				iWidth = getIntNumber(sWidth,"ColumnWidth");
				if (isPercentVal(sWidth))
					iSumPerc += iWidth;
				else
					iPgWidth -= iWidth;
			}
		}
		
		if (iPgWidth < 0)
			return 0;
		else if (iSumPerc <= 0)
			return (iPgWidth*iPerc/100);		
		else 
			return (iPgWidth*iPerc/iSumPerc);		
	}
	
	// Add the header Element
	// sWidth & sHeight is assumed to be text. sWidth should by the number of pixels
	// and sHeight should be a percent (e.g. '80%').  The style (i.e., the background color
	// for the spacer is set in the style sheet parameter 'PageSpacer') 
	// Default Width=0 (no spacer), Default Height=90%
	this.GetSpacerHTML = function(iRowSpan)
	{
		var sHTML = "";
		var iSpan = ((iRowSpan == null) || (isNaN(iRowSpan)))? 1: iRowSpan;
		try
		{
			if (this.SpacerWidth == 0)
				return sHTML;
				
			var dSpace = (this.SpacerHeight >= 100)? 0:(100-this.SpacerHeight)/2;
						
			sHTML = "<td width='"+this.SpacerWidth+"' valign=middle" +((iSpan > 1)? " rowspan=" : "") +iSpan +">";			
			sHTML += "<table border='0' cellpadding='0' cellspacing='0' width='"+this.SpacerWidth+"' height='100%'>";
			if (this.SpacerHeight >= 100)
				sHTML += "<tr class='PageSpacer' height='"+this.SpacerHeight+"%'><td></td></tr>";
			else
			{
				sHTML += "<tr height='"+dSpace +"%'><td></td></tr>";
				sHTML += "<tr class='PageSpacer' height='"+this.SpacerHeight+"%'><td></td></tr>";
				sHTML += "<tr height='"+dSpace+"%'><td></td></tr>";
			}
			sHTML += "</table></td>";
		}
		catch(ex)
		{
			this.SetError(ex)
			sHTML = "";
		}
		
		return sHTML;
	}
	
	// Call to add the Page's innerHTML to the document
	this.AddHTML = function()
	{
		if (this.HasError())
			return false;
		
		var bSuccess = false;
		try
		{
			var iColCnt = this.NumColumns;
			var iRowCnt = this.NumRows
			
			var sBodyStart = "<table id='"+this.objName+"' class='"+cxPageInnerBodyStyle+"'";
			sBodyStart += " border='0' cellpadding='0' cellspacing='0' width='100%'>"; // 
			//sBodyStart += "<tr valign=top>";
			
			var sBodyEnd = "</table>";
			
			var sBodyHTML = "";
			var sSpacer = "";
			var pLastCol = null;		
			if ((iColCnt == 0) || (iRowCnt == 0))
			{
				sBodyHTML = "<tr><td></td></tr>";
			}
			else
			{
				for (var iRow = 0; iRow < iRowCnt; iRow++)
				{
					// Start Row 
					sBodyHTML += "<tr valign=top>";
					pLastCol = null;
					for (var iCol = 0; iCol < iColCnt; iCol++)
					{
						var pCell = this.GetPageCell(iRow,iCol);						
						if (pCell != null)
						{
							// Add Spacer between Columns (if defined)
							if (iCol > 0) 							
							{
								sSpacer="";
								if (iRow == 0)
								{
									if ((pLastCol == null) || (pLastCol.RowSpan < pCell.RowSpan))
										sSpacer = this.GetSpacerHTML(pCell.RowSpan);
									else
										sSpacer = this.GetSpacerHTML(pLastCol.RowSpan);
								}
								else if (pLastCol != null)
									sSpacer = this.GetSpacerHTML(pCell.RowSpan);
	
								sBodyHTML += sSpacer; //this.GetSpacerHTML(1);
							}							

							// Get and Add the Cells HTML
							var sCellHTML = pCell.GetHTML();
							if ((sCellHTML == "") && (this.mError != null))
							{
								throw new Error("Add PageLayout Failed");
							}
							

							//alert("Cell["+iRow+","+iCol+"]= "+sCellHTML);
							sBodyHTML += sCellHTML;
						
						}
						pLastCol = pCell;
					}
					
					// End Row
					sBodyHTML += "</tr>";
				}
				//alert("BodyHTM= "+sBodyHTML);					
			}
			
			//alert(this.SpacerHTML);
			
			//alert(sBodyStart);
			//alert(sBodyHTML);
			//alert(sBodyEnd);
			
			document.write(sBodyStart);
			document.write(sBodyHTML);
			document.write(sBodyEnd);
			
			bSuccess = true;			
		}
		catch (ex)
		{
			this.ShowError(ex);
		}		
		return bSuccess;		
	}
	
	//
	// Call the UpdateFrameDisplays method of each Cell
	//
	this.UpdateFrameDisplays = function()
	{
		try
		{
			var iColCnt = this.NumColumns;
			var iRowCnt = this.NumRows
			if ((iColCnt > 0) && (iRowCnt > 0))
			{
				for (var iRow = 0; iRow < iRowCnt; iRow++)
				{
					for (var iCol = 0; iCol < iColCnt; iCol++)
					{
						var pCell = this.GetPageCell(iRow,iCol);						
						if (pCell != null)
							pCell.UpdateFrameDisplays();
					}
				}				
			}			
		}
		catch(ex)
		{}
		
		return true;
	}
}
CxPageLayout.count=0;

//
//*************************************************************************************
// CxPageCell Class - Defines the proporties and generate the HTML for each column
// on the page - it owns a set of Frames to display in the column
//
// The constructor of CxPageCell is not called directly. 
// New columns are added to the page by calling CxPageLayout's AddColumn(sWidth) method,
// which creates a new CxPageCell instance and return the instance.
//*************************************************************************************
//
function CxPageCell(pPageLayout, pRowSpan, pColSpan)
{
	this.objName="CxPageCell"+CxPageCell.count++;
	this.PageLayout = pPageLayout;
	this.ColumnID = this.objName;
	this.RowIndex = -1;
	this.ColIndex = -1;
	//if (pPageLayout != null)
	//	this.ColumnID = pPageLayout.objName+"_"+ this.objName;

	this.RowSpan = 1;
	if ((pRowSpan != null) && (!isNaN(pRowSpan)) && (pRowSpan > 1))
		this.RowSpan = pRowSpan;
	this.ColSpan = 1;
	if ((pColSpan != null) && (!isNaN(pColSpan)) && (pColSpan > 1))
		this.ColSpan = pColSpan;
	this.Class = null;
	this.FrameSpacing = 0;
	this.Frames = [];
	
	// Get the number of frames added to the Column
	this.FrameCount = function()
	{
		var iCount = 0;
		if (this.Frames != null) 
		   iCount = this.Frames.length;
		return iCount;
	}
		
	// Set the Column Formatiing Parameters
	this.SetFormat= function(sClass, iFrameSpacing)
	{
		if ((sClass != null) && (sClass != ""))
			this.Class = sClass;
		
		if ((iFrameSpacing!= null) && (!isNaN(iFrameSpacing))  && (iFrameSpacing> 0))
			this.FrameSpacing = iFrameSpacing;
	}
	
	// Add a pFrame:CxFrame object to the Column and assign link to this column
	this.AddFrame = function(pFrame)
	{
		try
		{
			if (pFrame == null) 
				return;
				
			var iLength = this.Frames.push(pFrame);
			pFrame.FrameID = this.objName+"_"+pFrame.objName;
			pFrame.FrameIndex = iLength-1;
			pFrame.Column = this;
			pFrame.PageLayout = this.PageLayout;
		}
		catch(ex)
		{
			if (this.PageLayout != null)
				this.PageLayout.SetError(ex);
			else
				throw ex;
		}
	}
	
	// Get the width of the PageCell
	this.GetWidth = function()
	{	
		var iWidth = 0;
		var iPercWidth = 0;
		var iSpacer = 0;
		try
		{
			iSpacer = this.PageLayout.SpacerWidth;
			
			for (var iCol = this.ColIndex; iCol < (this.ColIndex+this.ColSpan); iCol++)
			{
				var pColWidth = this.PageLayout.ColumnWidths[iCol];
				if (isPercentVal(pColWidth))
				{
					var iPerc = getIntNumber(pColWidth,"Column Width");
					if (iPerc > 100)
						throw new Error("Column["+iCol+"].Width is more than 100%");
						
					iPercWidth += iPerc;
				}
				else
				{
					iWidth += getIntNumber(pColWidth,"Width");
				}
				
				if (iCol > this.ColIndex)
					iWidth += iSpacer;
					
			}
				
			if (iPercWidth > 0)
				iWidth += this.PageLayout.GetCellWidth(iPercWidth);			
		}
		catch(ex)
		{
			throw ex;
		} 
		return iWidth;
	}
	
	// Get the inner HTML for displaying the column
	this.GetHTML = function()
	{
		var sHTML = "";
		var sColStart = "";
		var sColEnd = "";
		var sFrameHTML = "";
		try
		{
			var iCellWidth = this.GetWidth();
			var iColSpan = this.ColSpan;
			if ((iColSpan > 1) && (this.PageLayout != null) && (this.PageLayout.SpacerWidth > 0))
				iColSpan += (iColSpan-1);
				
			var sRowSpan = (this.RowSpan > 1)? " rowspan=" + this.RowSpan: "";
			var sColSpan = (iColSpan > 1)? " colspan=" + iColSpan: "";
									
			// Add Page Cell
			sColStart = "<td" + sRowSpan+sColSpan + "  style='width:"+iCellWidth.toFixed(0)+"px;'>";
			sColStart += "<div id='"+this.ColumnID+"'";
			
			if ((this.Class != null) && (this.Class != ""))
				sColStart += " class='"+this.Class+"'";
			
			sColStart += " style='width:100%;'>";
					
			// Close ColumnBody
			sColEnd = "</div></td>";
						
			// Add the Columns Frames
			var iFrameCnt = this.FrameCount();
			if (iFrameCnt > 0) 
			{
				for (var iFrame = 0; iFrame < iFrameCnt; iFrame++)
				{
					var pFrame = this.Frames[iFrame];
					if (pFrame == null)
						continue;
						
					var sHTML = pFrame.GetHTML();
					if ((sHTML == null) || (sHTML == ""))
						continue;
					
					if ((iFrame > 0) && (this.FrameSpacing > 0))
						sFrameHTML += "<div style='font-size:"+this.FrameSpacing.toFixed(0)+"pt; width:100%;'></div>";
					
					sFrameHTML += "<div id='"+this.ColumnID+"_"+pFrame.objName+"'";
					sFrameHTML += " style='width:100%;'>";
					sFrameHTML += sHTML;	
					sFrameHTML += "</div>";						
				}
			}
		}
		catch(ex)
		{
			throw ex
		}
		
		//alert(sColStart +sColEnd);
		return sColStart + sFrameHTML + sColEnd ;
	}	
/*	
	// Called to update the Column Controls 
	//(pPgState = 0:DefaultView; 1:NormalView; 2:PrintView)
	this.OnUpdate = function(pPgState)
	{
		var iFrameCnt = this.FrameCount();
		if (iFrameCnt > 0) 
		{
			for (var iFrame = 0; iFrame < iFrameCnt; iFrame++)
			{
				var pFrame = this.Frames[iFrame];
				if (pFrame == null)
					continue;
					
				pFrame.OnUpdate(pPgState);				
			}
		}
	}
*/	

	//
	// Call the UpdateFrameDisplay method of each CxFrame
	//
	this.UpdateFrameDisplays = function()
	{
		try
		{
			var iFrameCnt = this.FrameCount();
			if (iFrameCnt > 0) 
			{
				for (var iFrame = 0; iFrame < iFrameCnt; iFrame++)
				{
					var pFrame = this.Frames[iFrame];
					if (pFrame != null)
						pFrame.UpdateFrameDisplay();				
				}
			}
		}
		catch(ex)
		{}
		
		return true;
	}

}
CxPageCell.count = 0;

//
//*************************************************************************************
// CxPageCell Class - Defines the proporties and generate the HTML for each column
// on the page - it owns a set of Frames to display in the column
//*************************************************************************************
//
function CxFrame()
{
	this.objName="CxFrame"+CxFrame.count++;
	eval(this.objName+"=this");

	this.Column = null;
	this.FrameID = this.objName;
	this.FrameIndex = -1;
	this.PageLayout = null;
	
	var mHeaderClass = null;
	var mBodyClass = null;
	var mFooterClass = null;
	
	var mCaptionText = null;
	var mCaptionHRef = null;
	var mCaptionClass = null;
	var mCaptionTip = null;
	var mCaptionIsAction = false;
	var mControlHeight = 10;	
	
	var mFrameHeight = null;
	var mFrameSrc = null;
	var mFrameScroll = "no";

	var mMinHeight = null;
	var mMaxHeight = null;
	
	var mbDoPrint = false;
	var mbDoExpand = false;

	// Get the Frame's Body Element
	this.GetBodyElement = function()
	{
		return document.getElementById(this.objName+"_body");
	}
	
	// Set the Frame's Style Classes
	this.SetStyles = function(sHeaderClass, sBodyClass, sFooterClass)
	{
		mHeaderClass = ((sHeaderClass == null) || (sHeaderClass == ""))? null: sHeaderClass;
		mBodyClass = ((sBodyClass== null) || (sBodyClass== ""))? null: sBodyClass;
		mFooterClass = ((sFooterClass== null) || (sFooterClass== ""))? null: sFooterClass;
	}
	
	//
	// Set the Header Controls 
	// bPrint = if (true), it will display a print friendly version of the Frame's contents
	//          be opening a new window with url = pFrame.src+"?mode='print'.
	// bExpand = if (true), add an Expand All and Collaps All control that will trigger
	//          the click event of Script(ExpandAll) and Script(CollapsAll) in the Frame's
	//          content document (i.e., if defined).
	//
	this.SetControls = function(bPrint,bExpand)
	{
		mbDoPrint = (bPrint == null)? false: bPrint;
		mbDoExpand = (bExpand == null)? false: bExpand;
	}
	
	//
	// Set the Frame's Caption, Caption Class, and its hRef if it is a hiperlink
	// if (bIsAction), the sHRef = script to run onClick
	this.SetCaption = function(sCaption,sClass,sHRef,sTip,bIsAction)
	{
		try
		{
			mCaptionText = ((sCaption == null) || (sCaption == ""))? null: sCaption;
			if (mCaptionText == null)
			{
				if ((mCaptionText == null) || (mCaptionText == ""))
					throw new Error("Caption cannot be undefined");
				mCaptionHRef = null;
				mCaptionClass = null;
				mCaptionTip = null;
			}
			else
			{
				mCaptionHRef = ((sHRef == null) || (sHRef == ""))? null: sHRef;
				mCaptionClass = ((sClass == null) || (sClass == ""))? null: sClass;
				mCaptionTip = ((sTip == null) || (sTip == ""))? null: sTip;
				mCaptionIsAction = (bIsAction == null)? false: (bIsAction == true);
			}
		}
		catch(ex)
		{
			ex.message = "Frame.SetCaption Error; "+ex.message;
			throw ex;
		}		
	}
	
	// Set the ExpandingFrame's Control Symbol Size (20,15,12,10, or 8) - Default = 10
	this.SetControlHeight= function(pHeight)
	{
		try
		{
			if ((pHeight != null) && (!isNaN(pHeight)))
			{
				var iHeight = pHeight;
				if (iHeight == 20)
					mControlHeight = 20;
				else if (iHeight == 15)
					mControlHeight = 15;
				else if (iHeight == 12)
					mControlHeight = 12;
				else if (iHeight == 8)
					mControlHeight = 8;
			}
		}
		catch (ex)
		{
			ex.message = "Frame.SetControlHeight Error: "+ex.message;
			throw ex;
		}
	}
	
	// Get the Set ControlHeight
	this.GetControlHeight = function()
	{
		return mControlHeight;
	}
	
	// Initiate Frames Parameters 
	// sSrc = Initial HRef to a child page
	// pHeight = Height or initial height of the frame (Default = 10)
	// sScroll = flag control the display of the vertical or horizontal 
	//           or both no scrollbars (Default = 'no'
	this.InitiateFrame = function(sSrc, pHeight, sScroll)
	{
		try
		{
			mFrameSrc = ((sSrc == null) || (sSrc == ""))? null: sSrc;
			
			mFrameHeight = 10;				
			if ((pHeight != null) && (!isNaN(pHeight)) && (pHeight > mFrameHeight))
				mFrameHeight = pHeight; 
				
			mFrameScroll = ((sScroll == null) || (sScroll == ""))? "no": sScroll;			
		}
		catch (ex)
		{
			ex.message = "InitialFrame Error: "+ex.message;
			throw ex;
		}
	}
	
	// Called to set the Frame Element's Height
	this.SetHeight = function(pHeight)
	{
		try
		{
			var iHeight = ((pHeight == null) || (isNaN(pHeight)) || (pHeight < 10))? 10: pHeight; 
			var pFrameElem = this.GetElement("Frame");
			if (pFrameElem != null)
			{
				pFrameElem.height = iHeight;
			}
			mFrameHeight = iHeight;
		}
		catch (ex)
		{
			ex.message = "SetFrameHeight Error: "+ex.message;
			throw ex;
		}
	}
	
	// Get the current Height of the frame 
	// default = 10;
	this.GetHeight = function()
	{
		return (mFrameHeight == null)? 10: mFrameHeight; 
	}

	// Set the Frame's Caption, Caption Class, and its hRef if it is a hiperlink
	this.GetCaptionHTML = function()
	{
		var sHTML = "";
		try
		{
			if ((mCaptionText == null) || (mCaptionText == ""))
				return sHTML;
				
			var sCtrlHTML = this.GetCaptionCtrl();
			
			sHTML = "<table border='0' width='100%' cellpadding=0 cellspacing=0>";
			sHTML += "<tr><td><span id="+this.ElementID("Caption");
			if (mCaptionClass != null)
				sHTML += " class='"+mCaptionClass+"'";
			
			var sShowTip =  "";
			var sClearTip =  "";
			if ((mCaptionTip != null) && (mCaptionHRef == null))
			{
				sHTML += " title='"+mCaptionTip+"'";
				sHTML += " onmouseover=\"window.defaultStatus=this.title;\"";
				sHTML += " onmouseout=\"window.defaultStatus='';\"";
			}
				
/*			if (mCaptionHRef != null)				
			{
				sHTML += " href='"+mCaptionHRef +"'" ;
				sHTML += " onmouseover=\"this.style.textDecoration='underline'; this.style.cursor='hand';";
				sHTML += sShowTip+"\"";
				sHTML += " onmouseout=\"this.style.textDecoration='none'; this.style.cursor='default';";
				sHTML += sClearTip+"\"";
			} 
*/			
			sHTML += ">"+mCaptionText+"</span></td>";
			//sHTML += "<td align=right width=10%>";
			sHTML += sCtrlHTML;
			sHTML += "</tr></table>";			
		}
		catch(ex)
		{
			ex.message = "Frame.GetCaptionHTML Error; "+ex.message;
			throw ex;
		}
		
		return sHTML;
	}	
	
	//
	// Returns the HTML code to display the ActionButton and link set its eventhandlers
	//
	this.GetControlHTML = function(sID, sSrcID, sAction, sTitle, bShow)
	{
		var sCode = "";
		try
		{
			var iCtrlHeight = this.GetControlHeight();
			var sCtrlSrc = this.PageLayout.GetControlSrc(iCtrlHeight.toString()+sSrcID);
			var sCtrlID = this.ElementID(sID);
			
			if ((sCtrlSrc != null) && (sCtrlID != null))
			{
				sCode += "<img border='0' id='"+sCtrlID+"' src='"+sCtrlSrc+"'";
				if (sTitle!=null)
					sCode += " title='"+sTitle+"'";
				sCode += " onMouseover=\"this.style.textDecoration='underline'; this.style.cursor='hand';";
				sCode += " window.defaultStatus=this.title;\"";
				sCode += " onMouseout=\"this.style.textDecoration='none'; this.style.cursor='default';";
				sCode += " window.defaultStatus=''\"";
				if (sAction!=null)
				{
					if ((sAction == "next") && (mCaptionIsAction==true))
						sCode += " onClick=\"" + mCaptionHRef +"\"";
					else
						sCode += " onClick=\"" + this.objName + ".OnAction('"+sAction+"'); return true;\"";
				}
				
				if (bShow != null)
				{
					sCode += " style=\"display='";
					if (bShowPlus)
						sCode += "none'\"";
					else
						sCode += "block'\"";
				}
				sCode += ">";
			}
		}
		catch(ex)
		{
			sCode= "";
		}
		return sCode
	}
	
	//
	// Get the 'Next' cantrol to goto the Caption Link
	//
	this.GetCaptionLinkCtrl = function()
	{
		if (mCaptionHRef == null)
			return "";
		else
		{
			var sTip = (mCaptionTip == null)? "Go to "+mCaptionHRef: mCaptionTip;			
			return this.GetControlHTML("CaptionLink","next","next",sTip);
		}
	}
	//
	// Get the HTML for the Print Control. Return "" if (not mbDoPrint)
	//
	this.GetPrintCtrl = function()
	{
		if (!mbDoPrint)
			return "";
		else
			return this.GetControlHTML("Print","print","print",
											"Open a print friendly version of this sections contents");		
	}
	
	//
	// Get the HTML for the Print Control. Return "" if (not mbDoExpand)
	//
	this.GetExpandCtrl = function()
	{
		if (!mbDoExpand)
			return "";
		else
			return this.GetControlHTML("Expand","expand","expandall",
										"Expand all Collapsible text blocks of the section\'s contents");		
	}	
	
	//
	// Get the HTML for the Print Control. Return "" if (not mbDoExpand)
	//
	this.GetCollapsCtrl = function()
	{
		if (!mbDoExpand)
			return "";
		else
			return this.GetControlHTML("Collaps","collaps","collapsall",
									"Collaps of all Collapsible text blocks of the section\'s contents");		
	}	
	
	//
	// Get the HTML for the Print Control. Return "" if (not mbDoExpand)
	//
	this.GetCtrlSpacer = function(sID, bDoShow)
	{
		var sCode = "";
		if ((sID == null) || (sID == ""))
			return sCode;
			
		try
		{
			var iCtrlHeight = this.GetControlHeight();
			var sCtrlSrc = this.PageLayout.GetControlSrc(iCtrlHeight.toString()+"spacer");
			var sCtrlID = this.ElementID(sID);
			
			if ((sCtrlSrc != null) && (sCtrlID != null))
			{
				sCode += "<img border='0' id='"+sCtrlID+"' src='"+sCtrlSrc+"'";
				if (bDoShow != null)
				{
					sCode += " style=\"display='";
					if (bDoShow)
						sCode += "none'\"";
					else
						sCode += "block'\"";
				}
				sCode += ">";
			}
		}
		catch(ex)
		{
			sCode= "";
		}
		return sCode;
	}	
	
	// Get the Frame CaptionCtrl. The base calss returns an empty string
	this.GetCaptionCtrl = function()
	{
		var sCode = "";
		try
		{
			var sPrintCode = this.GetPrintCtrl();
			var sExpandCode = this.GetExpandCtrl();
			var sCollapsCode = this.GetCollapsCtrl();
			var sNextCode = this.GetCaptionLinkCtrl();
			
			var bShowExpand = ((sCollapsCode != null) && (sCollapsCode != "") &&
												 (sExpandCode != null) && (sExpandCode != ""));		
			var bShowPrint = ((sPrintCode != null) && (sPrintCode != ""));
			var bShowNext = ((sNextCode != null) && (sNextCode != ""));
			
			if ((bShowExpand==false) && (bShowPrint==false) && (bShowNext==false))
				return "";
				
			var sSpacerCode1 = this.GetCtrlSpacer("SpPrint");
			var sSpacerCode2 = this.GetCtrlSpacer("SpNext");
			var bShowSpacer2 = ((bShowNext==true) && (bShowExpand==true) &&
												 ((sSpacerCode2 != null) && (sSpacerCode2 != "")));					
			var bShowSpacer1 = ((bShowPrint==true) && ((bShowNext==true) || (bShowExpand==true)) &&
												 ((sSpacerCode1 != null) && (sSpacerCode1 != "")));					

//			alert("Print: "+sPrintCode);
			
			sCode = "<td><table border='0' cellpadding=0 cellspacing=0 align=right>";
			sCode += "<tr valign=middle>";	
			
			if (bShowPrint)
				sCode += "<td style='padding-left:1px;padding_right:1px;'>"+sPrintCode+"</td>";
				
			if (bShowSpacer1)
				sCode += "<td>"+sSpacerCode1+"</td>";
				
			if (bShowNext)
				sCode += "<td style='padding-left:1px;padding_right:1px;'>"+sNextCode+"</td>";
				
			if (bShowSpacer2)
				sCode += "<td>"+sSpacerCode2+"</td>";

			if (bShowExpand)
			{
				sCode += "<td style='padding-left:1px;padding_right:1px;'>"+sCollapsCode+"</td>";
				sCode += "<td style='padding-left:1px'>"+sExpandCode+"</td>";
			}
		
			sCode += "</tr></table></td>";
		}
		catch(ex)
		{
			sCode = "";
			throw new Error("GetCaptionCtrl Error: "+ex.message);
		}
		
		return sCode;
	}
	
	// Get the Frame's Footer HTMl (Default = null)
	this.GetBodyHTML = function()
	{	
		var sHTML = "";
		var sStyle = "";
		try
		{
			var sFrameID = this.ElementID("Frame");
			sHTML += "<iframe name='"+sFrameID+"' id='"+sFrameID+"'";
			if (mFrameSrc != null)
				sHTML += " src=\""+mFrameSrc +"\"";
			
			if (mFrameScroll != null)
				sHTML += " scrolling='"+mFrameScroll+"'";
			else
				sHTML += " scrolling='no'";
			
			sStyle = "width:100%;";
			var iHeight = this.GetHeight();
			if (iHeight != null)
				sStyle += "height:"+iHeight.toFixed(0)+"px;";
				
			sHTML += " style='"+sStyle+"' border='0' frameborder='0' boderwidth='0'></iframe>";
		}
		catch(ex)
		{
			ex.message = "Frame.GetBodyHTML Error; "+ex.message;
			throw ex;
		}
		return sHTML;
	}
	
	// Get the Frame's Footer HTMl (Default = null)
	this.GetFooterHTML = function()
	{
		return null;
	}
	
	// Get the Frame's HTML
	this.GetHTML = function()
	{ 
		var sHTML = "";
		try
		{
			sHTML += "<table border='0' cellpadding='0' cellspacing='0' width='100%' valign='top'>";// 
			
			var sCaptionHTML = this.GetCaptionHTML();
			var sFrameID = this.ElementID("Frame");
			// Add the Header if defined
			if (sCaptionHTML != null)
			{
				sHTML += "<tr><td"+((mHeaderClass != null)? " class="+mHeaderClass: "") +" width='100%'>";
				sHTML += sCaptionHTML;
				sHTML += "</td></tr>";
			}
			
			sHTML += "<tr><td"+((mBodyClass != null)? " class="+mBodyClass: "") +">";
			
			var sBodyHtml = this.GetBodyHTML();
			if (sBodyHtml != null)
				sHTML += sBodyHtml;
			
			sHTML += "</td></tr>";
			
			// Add the Footer if defined
			var sFooterHTML = this.GetFooterHTML();
			if ((sFooterHTML !=  null) && (sFooterHTML != ""))
			{
				sHTML += "<tr><td"+((mFooterClass != null)? " class="+mFooterClass: "") +">";
				sHTML += sFooterHTML;
				sHTML += "</td></tr>";
			}
				
			sHTML += "</table>";
			
			//alert(sHTML);
		}
		catch(ex)
		{
			ex.message = "Frame.GetHTML Error; "+ex.message;
			throw ex;
		}
		return sHTML;
	}
	
	// Return the ElementID for Control(sName)
	this.ElementID = function(sName)
	{
		return this.FrameID+"_"+sName;
	}
	
	// Return the docuemnet's element that represents the control
	this.GetElement = function(sName)
	{
		var pElement = null;
		var sID = this.ElementID(sName);
		if (sID != null)
			pElement = document.getElementById(sID);
		return pElement;
	}
	
	// Return the docuemnet's element that represents the control
	this.ShowElement = function(sName, bVisible)
	{
		var pElement = this.GetElement(sName);
		var pStyle = (pElement != null)? pElement.style: null;
		var sDisplay = (bVisible)? "block": "none";
		if (pStyle != null)
			pStyle.display=sDisplay;

		return true;
	}
	
	// Called to update the Column Controls 
	//(pPgState = 0:DefaultView; 1:NormalView; 2:PrintView)
	this.OnUpdate = function()
	{
		return true;	
	}
	
	//
	// Event Handler for the CaptionControls based on sAction.
	// 
	this.OnAction = function(sAction)
	{
		if (sAction == "print")
			this.OpenPrintWindow();
		else if ((sAction == "expandall") || (sAction == "collapsall"))
			this.FireContentsDocScript(sAction);
		else if (sAction == 'next')
			this.OpenNextWindow();			
		
		return true;
	}
	
	//
	// Open a New Window displaying the Caption Link 
	//
	this.OpenNextWindow = function()
	{
		try
		{	
			var sUrl = mCaptionHRef;
			if (sUrl == null)
				return true;
				
			var sFeatures = ",menubar=yes,toolbar=yes,location=yes,status=yes,"+
											"hotkeys=yes,directories=no,dependent=no";
			
			window.open(sUrl,this.objName+"_CaptionLink","\""+sFeatures+"\"");
		}
		catch(ex)
		{
			alert("Open Next Error: - "+ex.message);
		}
		return true;
	}
	
	//
	// Open a New Window with print friendly version of the Frame's Contents
	// using a URL=mFrameSrc+"?mode=print" 
	//
	this.OpenPrintWindow = function()
	{
		try
		{
			if (mFrameSrc == null)
				throw new Error("Contents URL is undefined");

			var pFrame = this.GetElement("Frame");
			if (pFrame == null)
				throw new Error("Unable to locate Frame["+this.ElementID("Frame")+"]");
			
			var sUrl = mFrameSrc+"?mode=print";
			var sFeatures = "width="+pFrame.clientWidth.toFixed(0)+
											",menubar=yes,toolbar=yes,location=no,hotkeys=no,directories=no,dependent=yes";
			
			var pWindow = window.open(sUrl,"Print_Window","\""+sFeatures+"\"");
			if (pWindow != null)
				pWindow.print();
		}
		catch(ex)
		{
			alert("Print Error: - "+ex.message);
		}
		return true;
	}
	
	//
	// Get a reference to the Frame Element's contentWindow's Document
	// Locate Script[sAction] in this document and if it exist
	// call the its Click method. Script[sAction] should include
	// a onClick eventhandler that calls the document's 
	// DisplayManager.ExpandAll/CollapsAll/UpdateDisplay scripts.
	this.FireContentsDocScript = function(sAction)
	{
		try
		{
			var pFrame = this.GetElement("Frame");
			if ((pFrame == null) || (pFrame.contentWindow == null))
				return;
//				throw new Error("Unable to get access to Frame["+this.ElementID("Frame")+"]'s contents");
			
			var pContentsDoc = pFrame.contentWindow.window.document;
			if (pContentsDoc == null)
				return;
	
			var pScript = pContentsDoc.getElementById(sAction);
			if (pScript != null)
				pScript.click();
		}
		catch(ex)
		{
			alert("Expand/Collaps Error: - "+ex.message);
		}
		return true;
	}
	
	//
	//	Fire the Frame's ContentDocument.Script[UpdateDisplay].Click
	//
	this.UpdateFrameDisplay = function()
	{
		return this.FireContentsDocScript("UpdateDisplay");
	}
	
	//
	//	Update the Frame Settings after the Page has been loaded.
	//
	this.UpdateFrame = function(sCaption,sSrc,bPrint,bExpand)
	{
		try
		{
			var pCaption = this.GetElement("Caption");
			if ((sCaption != null) && (pCaption != null))
				pCaption.innerHTML=sCaption;
				
			var pFrame = this.GetElement("Frame");
			if ((sSrc != null) && (pFrame != null))
			{
				mFrameSrc = sSrc;
				pFrame.src = mFrameSrc;
			}
				
			var bDoPrint = (bPrint == null)? false: (bPrint==true);
			var bDoExpand = (bExpand == null)? false: (bExpand==true);
			this.ShowElement("Print",bDoPrint);
			this.ShowElement("Collaps",bDoExpand);
			this.ShowElement("Expand",bDoExpand);			
		}
		catch(ex)
		{
			alert("Update Frame Error:"+ex.message);
		}
	}
}
CxFrame.count=0;

//
//*************************************************************************************
// Class CxExpandingFrame:CxFrame - A subclass of CxFrame the has +|- controls that allow
// the user to expand/reduce the height of the frame within a set range.
//*************************************************************************************
// ControlHeights (12,10 or 8 pt); default = 10
function CxExpandingFrame()
{
	this.inheritFrom = CxFrame;
	this.inheritFrom();
		
	var mMinHeight = null;
	var mMaxHeight = null;
	var mDeltaHeight = null;
		
	// Set the Frames Height Range[pHmin..pH,ax] and the initial value of
	// this.Height.  The this.DeltaH = (pHmax-pHmin)/5 with a minimum of 10px.
	// Min(pHmin) = 10. iHeight = pHmin+3*mDeltaHeight
	// Return the initial height
	this.SetHeightRange= function(pHmin, pHmax)
	{		
		mMinHeight = null;
		mMaxHeight = null;
		mDeltaHeight = null;
		
		var iHeight = null;
		try
		{
			if ((pHmin == null) || (isNaN(pHmin)) ||
				(pHmax == null) || (isNaN(pHmax)))
				throw new Error("Invalid Height Range definition");
			
			mMinHeight = pHmin.valueOf();
			if (mMinHeight < 10)
				mMinHeight = 10;
				
			mDeltaHeight = 10;
			if (pHmax > (mMinHeight + (5*10)))
			{
				mDeltaHeight = Math.round((pHmax - mMinHeight)/5);
				mMaxHeight = (5*mDeltaHeight);
			}
			else
			{
				mDeltaHeight = 10;
				mMaxHeight = mMinHeight + (5*mDeltaHeight);
			}
			
			iHeight = mMinHeight + (3*mDeltaHeight);
			var iHo = this.GetHeight();
			if (iHo != null) 
			{
				if ((iHo > mMinHeight) && (iHo <= mMaxHeight))
				{
					iHeight = mMinHeight;
					for (var i = 1; i <= 5; i++)
					{
						if (iHeight+mDeltaHeight > iHo)
							break;
						else
							iHeight += mDeltaHeight;
					}
				}
			}
			
			this.SetHeight(iHeight);
		}
		catch (ex)
		{
			this.PageLayout.SetError(ex);
		}
	}

	// Get the Maximum Frame Height
	this.GetMaxHeight = function()
	{
		return mMaxHeight;
	}
	
	// Get the Minimum Frame Height
	this.GetMinHeight = function()
	{
		return mMinHeight;
	}
	
	// Get the Height Increment
	this.GetDeltaHeight = function()
	{
		return mDeltaHeight;
	}
	
	//
	// Get the HTML for the Grow Control. Return "" if (not mbDoPrint)
	//
	this.GetGrowCtrl = function(bDoShow)
	{
		return this.GetControlHTML("Grow","plus","grow",
											"Increase the height of this section\'s contents window",bDoShow);		
	}
	
	//
	// Get the HTML for the Grow Control. Return "" if (not mbDoPrint)
	//
	this.GetShrinkCtrl = function(bDoShow)
	{
		return this.GetControlHTML("Grow","plus","grow",
											"Reduce the height of this section\'s contents window",bDoShow);		
	}
	
	// Expand the Frame's Height. Hide Grow Control element when max height is reached
	this.Expand = function()
	{
		var bPlus = false;
		var bMinus = false;
		var bSpacer = false;
		try
		{
			var iDelta = (mDeltaHeight == null)? 10: mDeltaHeight;
			var iMinHeight = (mMinHeight == null)? 10: mMinHeight;
			var iMaxHeight = (mMaxHeight == null)? iMinHeight: mMaxHeight;

			var iHeight = this.GetHeight();
			if (iHeight != null)
			{
				iHeight = ((iHeight+iDelta) >= iMaxHeight)? iMaxHeight: iHeight+iDelta;
				bPlus = (iHeight < iMaxHeight);
				bMinus = (iHeight > iMinHeight);
				bSpacer = ((bPlus == true) && (bMinus==true))

				this.SetHeight(iHeight);
			}
			this.ShowElement("Grow",bPlus);
			this.ShowElement("Shrink",bMinus);
			this.ShowElement("Spacer",bSpacer);				
		}
		catch(ex)
		{
			alert ("Frame Expand Error: "+ex.message);
		}	
			
		return true;
	}
	
	// Shrink the Frame's Height. Hide Shrink Control element when min height is reached
	this.Shrink = function()
	{
		var bPlus = false;
		var bMinus = false;
		var bSpacer = false;
		try
		{
			var iDelta = (mDeltaHeight == null)? 10: mDeltaHeight;
			var iMinHeight = (mMinHeight == null)? 10: mMinHeight;
			var iMaxHeight = (mMaxHeight == null)? iMinHeight: mMaxHeight;

			var iHeight = this.GetHeight();
			if (iHeight != null)
			{
				iHeight = ((iHeight-iDelta) <= iMinHeight)? iMinHeight: iHeight-iDelta;
				bPlus = (iHeight < iMaxHeight);
				bMinus = (iHeight > iMinHeight);
				bSpacer = ((bPlus == true) && (bMinus==true))

				this.SetHeight(iHeight);
			}
			this.ShowElement("Grow",bPlus);
			this.ShowElement("Shrink",bMinus);
			this.ShowElement("Spacer",bSpacer);				
		}
		catch(ex)
		{
			alert ("Frame Shrink Error: "+ex.message);
		}	
			
		return true;
	}

	//	
	// Override to Get the Frame CaptionCtrl for the ExpandingFramme
	//
	this.GetCaptionCtrl = function()
	{
		var sCode = "";
		var sTmp = "";
		var iHeight = this.GetHeight();
		var iMaxHeight = this.GetMaxHeight();
		var iMinHeight = this.GetMinHeight();
		var iCtrlHeight = this.GetControlHeight();
		
		var bShowPlus = (iHeight < iMaxHeight);
		var bShowMinus = (iHeight > iMinHeight);
		var bShowSpacer = ((bShowPlus==true) && (bShowMinus==true));

		try
		{
			var sPrintCode = this.GetPrintCtrl();
			var sExpandCode = this.GetExpandCtrl();
			var sCollapsCode = this.GetCollapsCtrl();
			var sSpacerCode1 = this.GetCtrlSpacer("SpPrint1");
			
			var sGowCode = this.GetGrowCtrl(bShowSpacer);
			var sShrinkCode = this.GetShrinkCtrl(bShowSpacer);
			var sSpacerCode2 = this.GetCtrlSpacer("SpPrint2");
			var sSpacerCode3 = this.GetCtrlSpacer("SpGrow",bShowSpacer);
			
			var bShowExpand = ((sCollapsCode != null) && (sCollapsCode != "") &&
													(sExpandCode != null) && (sExpandCode != ""));		
			var bShowPrint = ((sPrintCode != null) && (sPrintCode != ""));
			var bShowSpacer = ((bShowPrint==true) && (bShowExpand==true) &&
													((sSpacerCode != null) && (sSpacerCode != "")));					
			var bShowGrow = ((sGowCode != null) && (sGowCode != "") &&
													(sShrinkCode != null) && (sShrinkCode != ""));		
			var bShowSpacer2 = (((bShowPrint==true) || (bShowExpand==true)) && (bShowGrow) &&
													((sSpacerCode2 != null) && (sSpacerCode2 != "")));					
			var bShowSpacer3 = ((bShowGrow == true) &&
													((sSpacerCode3 != null) && (sSpacerCode3 != "")));					
			
			if ((bShowExpand==false) && (bShowPrint==false) && (bShowGrow==false))
				return "";
				
			sCode = "<td><table border='0' cellpadding=0 cellspacing=0 align=right>";
			sCode += "<tr valign=middle>";	
			
			if (bShowGrow)
			{
				sCode += "<td>"+sGowCode+"</td>";
				if (bShowSpacer3)
					sCode += "<td>"+sSpacerCode3+"</td>";
				sCode += "<td>"+sShrinkCode+"</td>";
			}
			
			if (bShowSpacer2)
					sCode += "<td>"+sSpacerCode2+"</td>";
			
			if (bShowPrint)
				sCode += "<td>"+sPrintCode+"</td>";
				
			if (bShowSpacer1)
				sCode += "<td>"+sSpacerCode1+"</td>";

			if (bShowExpand)
			{
				sCode += "<td>"+sCollapsCode+"</td>";
				sCode += "<td>"+sExpandCode+"</td>";
			}
		
			sCode += "</tr></table></td>";
		}
		catch(ex)
		{
			sCode = "";
			throw new Error("GetCaptionCtrl Error: "+ex.message);
		}
		
		return sCode;
	}

	//
	// Override the CxFrane's OnAction to add additional functionality
	//
	this.OnAction = function(sAction)
	{
		if (sAction == "print")
			this.OpenPrintWindow();
		else if ((sAction == "expandall") || (sAction == "collapsall"))
			this.FireExpandScript(sAction);
		else if (sAction == 'next')
			this.OpenNextWindow();			
		else if (sAction == "grow")
			bSuccess = this.Expand();
		else if (sAction == "shrink")
			bSuccess = this.Shrink();

		return true;
	}
}

//
//*************************************************************************************
// Class CxQuickLinkFrame:CxFrame - A subclass of CxFrame the Contains the Page's QuickLinks.
//*************************************************************************************
//
function CxQuickLinkFrame()
{
	this.inheritFrom = CxFrame;
	this.inheritFrom();
	
	var mpQLinks = null;
	
	//Set the Frame's QuickLinks
	this.SetQuickLinks = function(pQLinks, pHeight)
	{
		if ((typeof(pQLinks) != "object") || (pQLinks == null))
			return false;
			
		mpQLinks = pQLinks;
		mpQLinks.ShowCaption = false;
		
		var iHeight = null;				
		if ((pHeight != null) && (!isNaN(pHeight)))
			mpQLinks.height = pHeight;
			
		return true;
	}	
	
	//Get reference to the Frame's QuickLinks
	this.GetQuickLinks =  function()
	{
		return mpQLinks;
	}

	// Get the Frame's HTML
	// Override the CxFrame's method
	this.GetBodyHTML = function()
	{ 
		var sHTML = "";
		try
		{
			var pLinks = this.GetQuickLinks();
			if (pLinks == null)
				throw new Error("QuickLinks are not defined.");
				
			sHTML = pLinks.GetHTML();
		}
		catch(ex)
		{
			ex.message = "Frame.GetBodyHTML Error; "+ex.message;
			throw ex;
		}
		return sHTML;
	}
}

//
//*************************************************************************************
// Utility Routines used by all classes
//*************************************************************************************
//

// Return an Integer number form aVal. 
// sPar=the parameter name - for error handling.
function getIntNumber(aVar,sPar)
{
	var sParName = (sPar == null)? "Value": sPar;
		
	if (aVar == null)
		throw new Error(sParName + " is unassigned");
	else if (isNaN(aVar))
	{
		if (aVar == "")
			throw new Error(sParName + " is an empty string");
			
		var aIsNaN = ["0","1","2","3","4","5","6","7","8","9",".","-"];
		var sVal = "";
		for (var iCh = 0; iCh < aVar.length; iCh++)
		{
			var sChar = aVar.charAt(iCh);
			if (sChar in aIsNaN)
				sVal += sChar;
		}
		
		if (sVal == "")
			throw new Error(sParName + "["+aVar+"] is not a number");
		
		return parseInt(sVal); 
	}
	else
	{
	  return parseInt(aVar.toString())
	}
}

// Check if strin sVal represents an percentage value
function isPercentVal(sVal)
{
	if ((sVal == null) || (!isNaN(sVal)) || (sVal == "")) 
	  return false;
	  
	if (sVal.charAt(sVal.length-1) == "%")
	{
		var sSubVal = (sVal.length == 1)? "": sVal.substring(0,sVal.length-2);
		return (!isNaN(sSubVal));
	}
	else
		return false;
}
