
// /////////////////////////////////////////////////////////////
//	This Script defines the Function Table (FncTbl) Object /
// /////////////////////////////////////////////////////////////

//	Simple check string for blanks function

function IsBlank(CheckStr)
{
    for(i = 0; i < CheckStr.length; i++)
	if(CheckStr.charAt(i) != " ")
	    break;

    if(i >= CheckStr.length)
	return(true);
    else
	return(false);
}

//	Add a "row" to the function table

function AddFunc(MlsxName,CompassName)
{
    if(IsBlank(MlsxName) || IsBlank(CompassName))
    {
	alert("Attempt to add blank value to function table, skipping!");
	return;
    }

    this.MlsxName[this.length]    = MlsxName;
    this.CompassName[this.length] = CompassName;
    this.Priv[this.length]        = true;

    this.length++;
}

//	Look up and return privilege (BOOL true or false) for a function

function HasPriv(MlsxName)
{
    for(i = 0; i < this.length; i++)
	if(MlsxName.toUpperCase() == this.MlsxName[i].toUpperCase())
	    break;

    if(i >= this.length)
	return(true);

    return(this.Priv[i]);
}

//	Set the privilege for a function, by Compass Function Name

function SetPrivByCompassName(CompassName,Priv)
{
    for(i = 0; i < this.length; i++)
	if(CompassName.toUpperCase() == this.CompassName[i].toUpperCase())
	    break;

    if(i >= this.length)
	return;

    this.Priv[i] = Priv;

    return;
}

//	Set the privilege for a function, by MlsXplorer Function Name

function SetPrivByMlsxName(MlsxName,Priv)
{
    for(i = 0; i < this.length; i++)
	if(MlsxName.toUpperCase() == this.MlsxName[i].toUpperCase())
 	    break;

    if(i >= this.length)
	return;

    this.Priv[i] = Priv;

    return;
}

//	Function Table Constructor

function FncTbl()
{
//	Properties

    this.length      = 0;
    this.MlsxName    = new Array();
    this.CompassName = new Array();
    this.Priv        = new Array();

//	Methods

    this.AddFunc     = AddFunc;
    this.HasPriv     = HasPriv;
    this.SetPrivByCompassName = SetPrivByCompassName;
    this.SetPrivByMlsxName = SetPrivByMlsxName;
}
