Ext.define('VariableExpression', {
    constructor: function(cfgXML){
        this.TargetVariableID = XmlHelper.getString(cfgXML, "targetVariableID");
        this.Expression = XmlHelper.getString(cfgXML, "expressionString");
    },
    evalExpression: function(){
        if (Author.VariableManager.hasVariable(this.TargetVariableID)) {
            //  var valueExpression = replaceVariableNameWithValue(this.Expression);
            var thisVar = Author.VariableManager.getVariableByID(this.TargetVariableID);
            if (thisVar.Type == AuthorVariableTypes.Numeric) {
               // Author.log(this.Expression);
                var newValue = ExpressionEngine.evalExpression(this.Expression);
                try{
                    newValue = eval(newValue);
                }catch(err){
                    Author.log(Ext.String.format("Can't evaluate {0} as numeric expression.",newValue));
                }
                if (isNaN(newValue)) {
                    Author.log("Try to assign " + newValue + " to a numeric variable " + thisVar.Name);
                }

                thisVar.setValue(newValue);
            }
            else {
                thisVar.setValue(ExpressionEngine.evalExpression(this.Expression));
            }
        }
        else {
            Author.log(this.TargetVariableID + " doesn't exist!");
        }
    },
    toString: function(){
        return this.TargetVariableID + " = " + this.Expression;
    }
});
Ext.define('VariableClass15', {
    extend: 'GeneralAction',
    constructor: function(cfgXML, o, actionSequence){
        this.ExpressionList = null;
        this.callParent([cfgXML, o, actionSequence]);
        this.ExpressionList = new Array();
        var expressions = cfgXML.getElementsByTagName("expression");
        for (var i = 0; i < expressions.length; i++) {
            var expression = new VariableExpression(expressions[i]);
            this.ExpressionList.push(expression);
        }
    },
    processAction: function(bg){
        for (var i = 0; i < this.ExpressionList.length; i++) {
            this.ExpressionList[i].evalExpression();
        }
        return {MoveOn: true, Interval: 0};
    }
});
