
// The Table to keep track of user current selection 
// during the life time of this dialog.
var g_pObjectsSelectionTable;
var g_pUpperFrame = window.top.frames[0];

/**
 *
 *	Responds to page onLoad event on NT Domains Browse dialog lower frame
 *
 */
function SCA_onLoadNTDomains()
{	
	// -- clone a LatestSupportedNTDomainsTable from the parent window browser
	g_pObjectsSelectionTable = window.top.opener.SCA_cloneLatestSupportedNTDomainsTable();
	
	// render the list to UI
	SCA_renderOtherSupportedObjectsList();
}


/**
 *
 *	[Private] Update UI list of supported NT Domains
 *
 */
function SCA_renderOtherSupportedObjectsList()
{	
	// retrieve <Table> tag we need
	var pTable = document.getElementById('OtherSupportedObjectsListTable');	
	
	// add objects to UI row by row
	var pObject, strExternalObjectID, strEscapedExternalObjectID, strDisplayName, strEscapedDisplayName, bIsSelected, bIsInDB;
	var strInputHTML, pRow, pCell;
	for (var nIndex=0; nIndex < g_pObjectsSelectionTable.ItemsCount; nIndex++)
	{
		pObject = g_pObjectsSelectionTable.GetEntry(nIndex)
		strExternalObjectID = pObject.ExternalObjectID;
		// Escape ' characters.
		strEscapedExternalObjectID = strExternalObjectID.replace( /[']/g,"\\'");  
		strDisplayName = pObject.DisplayName;
		// Escape ' characters.
		strEscapedDisplayName = strDisplayName.replace( /[']/g,"\\'");
		bIsSelected = pObject.IsSelected;
		bIsInDB = pObject.IsInDB;

		// create the entry only if it's not Available
		if (!pObject.IsAvailable)
		{
			strInputHTML = '<input type="checkbox" name="' + strExternalObjectID + '" ';
			if (bIsSelected)
				strInputHTML += 'checked ';		
			strInputHTML += '" onclick="SCA_onClickedCheckbox( \'' + strEscapedExternalObjectID + '\', \'' + strEscapedDisplayName + '\', this.checked )">\n';

			pRow = pTable.insertRow();
			pCell = pRow.insertCell();
			pCell.width = 1;			
			pCell.innerHTML = strInputHTML;
			pCell = pRow.insertCell();
			pCell.innerHTML = '<td><nobr>' + strDisplayName + '</nobr></td>';
		}
	}
}

/**
 *
 *	[Public] Handles user checking/unchecking an object
 *
 *	@param strID [in] - the ID that identifies the check box
 *
 *	@param strDisplayName [in] the display name of the node
 *
 *	@param bChecked [in] - whether the check box is checked or unchecked
 *
 */
function SCA_onClickedCheckbox( strID, strDisplayName, bChecked )
{
	// synch up Upper frame with the checked state in this frame
	g_pUpperFrame.SCA_setCheckboxState( strID, bChecked );
	
	// update the underlying data structure
	SCA_setObjectSelectedState( strID, strDisplayName, bChecked );
}

/**
 *
 *	[Public] To set the state of a checkbox in this frame.
 *
 *	@param strID [in] - the ID that identifies the check box
 *
 *	@param bChecked [in] - whether the check box is checked or unchecked
 *
 */
function SCA_setCheckboxState( strID, bChecked )
{
	if (document.SCA_frmOtherSupportedObjects.elements[strID])
	{
		document.SCA_frmOtherSupportedObjects.elements[strID].checked = bChecked;
	}
}

/**
 *
 *	Return current Objects Selection Table to the Tree frame
 *	so that it can update its checked-state upon reload after
 *	a round-trip.
 *
 */
function SCA_getObjectsSelectionTable()
{
	return g_pObjectsSelectionTable;
}

/**
 *
 *	Updates data structure caching current checked state
 *
 */
function SCA_setObjectSelectedState( strID, strDisplayName, bChecked )
{
	g_pObjectsSelectionTable.SetObjectSelectedState( strID, strDisplayName, bChecked );
}

/**
 *
 *	Responds to OK clicked on NT Domains Browse dialog
 *
 */
function SCA_onOkNTDomains()
{
	// pass our ObjectsSelectionTable back to the parent dialog
	window.top.opener.SCA_updateLatestSupportedNTDomains( g_pObjectsSelectionTable );
	
	window.top.close();
}



