//*********************************************************************
//*********************************************************************
//
// GT API - Global Teach Application Programming Interface
//
//*********************************************************************
//*********************************************************************

var GTCat;
var GTTPlan;

GTCat			= new c_Cat;
GTTPlan		= new c_TPlan;
	
function c_Cat()
{
	// Member functions
	this.Select				= c_Cat_Select;				// Show a training material in the catalog view
}

function c_TPlan()
{
	// Member functions
	this.Open					= c_TPlan_Open;				// Open a training plan and show introduction
	this.Select				= c_TPlan_Select;			// Show a training material in the TPlan view
}

// *******************************************************
// c_Cat.Select()
//
// p_sItemId				Item Id of the training material to show.
// p_sParentItemId  Parent item of the training material to show (may be empty).
// Returns					-
//
// Show a training material in the catalog view. The catalog view
// jumps to the selected training material and shows its description.
//
// p_sParentItemId=root specifies the root of the catalog
//
function c_Cat_Select( p_sItemId, p_sParentItemId )
{
  if ( p_sParentItemId == 'any' ) p_sParentItemId = '';
	Navigate("/Pages/Catalog.aspx?id=" + p_sItemId + "&parentId=" + p_sParentItemId );
}

// *******************************************************
// c_TPlan.Select()
//
// p_sTPlanId				Item of the training plan to show.
// p_sItemId				Item Id of the training material (lesson) to show (may be empty).
// p_sParentItemId  [not used].
// Returns					-
//
// Show a training material (lesson) in the training plan view. 
// The selected training plan is opened. The training plan view jumps
// to the selected training material (lesson) and shows its description.
//
// p_sParentItemId=root specifies the root of the training plan
//
function c_TPlan_Select( p_sTPlanId, p_sItemId, p_sParentItemId )
{
	Navigate("/Pages/TPlan.aspx?id=" + p_sItemId + "&parentId=" + p_sTPlanId );
}

// *******************************************************
// c_TPlan.Open()
//
// p_sTPlanId		Item of the training plan to show.
// Returns			-
//
// Open a training plan.
//
function c_TPlan_Open( p_sTPlanId )
{
	Navigate("/Pages/TPlan.aspx?parentId=" + p_sTPlanId );
}

// *******************************************************
// Navigate to corresponding main page in pages
//
function Navigate(p_sUrl)
{
  var currentUrl = window.location.href;
  var endIndex = currentUrl.toLowerCase().indexOf("/pages");
  var baseUrl = currentUrl.substring(0, endIndex);
	window.location.href = baseUrl + p_sUrl;
}

