/*---------------------------------------------------------------------------------------
 * Author: David Mohundro
 * Date Written: March 2004
 *
 * Description:
 * This file contains the JavaScript code for formlets on the Company Store
 *
 * Change Log:
 * xxxx/xx/xx xxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 *---------------------------------------------------------------------------------------*/

/*----------------------------------------------
 * formletObj(strID)
 *----------------------------------------------*/
function formletObj(strID)
{
	// Properties
	this.ID = strID;
	
	// Methods
	this.changeFormletTitle = changeFormletTitle;
	this.hideFormlet        = hideFormlet;
	this.hideFormletBody    = hideFormletBody;
	this.showFormlet        = showFormlet;
	this.showFormletBody    = showFormletBody;
	
	/*----------------------------------------------
	 * changeFormletTitle(strNewTitle)
	 *----------------------------------------------*/
	function changeFormletTitle(strNewTitle)
	{
		getFormletTitleContainer(this.ID).innerHTML = strNewTitle;
	}
	
	/*----------------------------------------------
	 * getFormletContainer(strID)
	 * [private]
	 *----------------------------------------------*/
	function getFormletContainer(strID)
	{
		return document.getElementById("frmlt" + strID);
	}
	
	/*----------------------------------------------
	 * getFormletBodyContainer(strID)
	 * [private]
	 *----------------------------------------------*/
	function getFormletBodyContainer(strID)
	{
		return document.getElementById("frmltBody" + strID);
	}
	
	/*----------------------------------------------
	 * getFormletTitleContainer(strID)
	 * [private]
	 *----------------------------------------------*/
	function getFormletTitleContainer(strID)
	{
		return document.getElementById("frmltTitle" + strID);
	}
	
	/*----------------------------------------------
	 * hideFormlet()
	 *----------------------------------------------*/
	function hideFormlet()
	{
		var objFormlet = getFormletContainer(this.ID);
		objFormlet.style.display = "none";
	}
	
	/*----------------------------------------------
	 * hideFormletBody()
	 *----------------------------------------------*/
	function hideFormletBody()
	{
		var objFormlet = getFormletBodyContainer(this.ID);
		objFormlet.style.display = "none";
	}
	
	/*----------------------------------------------
	 * showFormlet()
	 *----------------------------------------------*/
	function showFormlet()
	{
		var objFormlet = getFormletContainer(this.ID);
		objFormlet.style.display = "block";
	}
	
	/*----------------------------------------------
	 * showFormletBody()
	 *----------------------------------------------*/
	function showFormletBody()
	{
		var objFormlet = getFormletBodyContainer(this.ID);
		objFormlet.style.display = "inline";
	}	
}

/*----------------------------------------------
 * addNewFormlet(strID)
 *----------------------------------------------*/
function addNewFormlet(strID)
{
	eval(strID + " = new formletObj(\"" + strID + "\")");
}

/*----------------------------------------------
 * hideAllFormletBodies()
 *----------------------------------------------*/
function hideAllFormletBodies()
{
	var arrDivs = document.getElementsByTagName("DIV")
	var arrFormlets = new Array()
	var strID
	
	for (var i = 0; i < arrDivs.length; i++)
	{
		strID = arrDivs[i].id;
		if (strID.substring(0, 9) == "frmltBody")
		{
			strID = strID.substring(9);
			eval(strID).hideFormletBody();
		}
	}
}

/*----------------------------------------------
 * hideAllFormlets()
 *----------------------------------------------*/
function hideAllFormlets()
{
	var arrTables = document.getElementsByTagName("TABLE")
	var arrFormlets = new Array()
	var strID
	
	for (var i = 0; i < arrTables.length; i++)
	{
		strID = arrTables[i].id;
		if (strID.substring(0, 5) == "frmlt")
		{
			strID = strID.substring(5);
			eval(strID).hideFormlet();
		}
	}
}

/*----------------------------------------------
 * showHideFormlet(span, objFormlet)
 *----------------------------------------------*/
function showHideFormlet(span, objFormlet)
{
	if (span.innerHTML == "hide")
	{
		objFormlet.hideFormletBody()
		span.innerHTML = "show"
	}
	else
	{
		objFormlet.showFormletBody()
		span.innerHTML = "hide"
	}
}