/*
********************************************************************************************************************************************************************
* Name              :
*
* Description       :
*
* Author(S)         : JSHUMAKER
*
* Creation Date     : 1/11/2007
*
* Version           : 1.0
*
*
* Modifications:
*    MOD ID          Date              Developer Name                   Description
*    ------------    --------------    -----------------------------    ----------------------------------------------------
*
* VSS Info:
*      $Archive:
*      $Author:
*              $Date:
*              $Revision:
*
*  COPYRIGHT 2005 TDCI Inc.
********************************************************************************************************************************************************************
*/

/*
Class: ControlCommand
Public Functions:
    Equals(Command)
        Command - A ControlCommand you want to compare this command to.
        Return - A boolean value indicating if the two commands are identical.

    SetName(Name)
        Name - A string representing the name the command should have.
    
    GetName()
        Return - A string representing the current name for the command.
    
    SetArgument(Argument)
        Argument - A string representing the argument the command should have.
        
    GetArgument()
        Return - A string representing the current argument for the command.
*/
ControlCommand = Class.create();
ControlCommand.prototype = 
{
    initialize: function(JSON)
    {
    
        if (JSON == null || JSON.length == 0)
        {
            this.Name = "";
            this.Arguments = new Array();
        }
        else
        {
            var Temp = eval("(" + JSON + ")");
            
            this.Name = Temp.Name;
            this.Arguments = Temp.Arguments;
        }
    },

    Equals: function(Command)
    {
        var Keys;
        var Index = 0;
        
        if (this.Name != Command.GetName())
        {
            return false;
        }
        
        Keys = Command.GetKeys();
        
        if (this.Arguments.length != Keys.length)
        {
            return false;
        }
        
        for (Index = 0; Index < Keys.length; Keys++)
        {
            if (Command.GetArgument(Keys[Index]) != this.GetArgument(Keys[Index]))
            {
                return false;
            }
        }
        
        return true;
    },
    
    toString: function()
    {
        var Builder = "";
        var Index = 0;
        
        Builder += this.Name;
        Builder += "^^^";
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            if (Index != 0)
            {
                Builder += "~~";
            }
            
            Builder += this.Arguments[Index].key;
            Builder += "`" + this.Arguments[Index].value;
        }
        
        return Builder;
    },
        
//Public Properties    
    SetName: function(Name)
    {
        this.Name = Name;
        
        return true;
    },
    
    GetName: function()
    {
        return this.Name;
    },

//Public Methods
    ContainsKey: function(Key)
    {
        var Index = 0;
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            if (this.Arguments[Index].key == Key)
            {
                return true;
            }
        }
        
        return false;
    },

    AddArgument: function(Key, Value)
    {
        var JSON = "";
        var Index = 0;
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            if (this.Arguments[Index].key == Key)
            {
                this.Arguments[Index].value = Value;
                return true;
            }
        }

        JSON = "({";
        JSON += "'key': '" + Key + "', ";
        JSON += "'value': '" + Value + "'";
        JSON += "})";
        
        this.Arguments[this.Arguments.length] = eval(JSON);
        return true;
    },
    
    RemoveArgument: function(Key)
    {
        var Index = 0;
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            if (this.Arguments[Index].key == Key)
            {
                this.Arguments[Index] = null;
                
                return true;
            }
        }
        
        return false;
    },
    
    GetKeys: function()
    {
        var Index = 0;
        var Keys = new Array();
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            Keys[Keys.length] = this.Arguments[Index].key;
        }
        
        return Keys;
    },
    
    GetArgument: function(Key)
    {
        var Index = 0;
        
        for (Index = 0; Index < this.Arguments.length; Index++)
        {
            if (this.Arguments[Index].key == Key)
            {
                return this.Arguments[Index].value;
            }
        }
        
        return null;
    }
};