//Helper methods for albion

function AlbionDuplicateEnvironment(envID, withoutResults)
{
    var idDuplicated = -1;
    
    try
    {
        var arrEnvObjectIds = PopulateEnvironmentIds();
        
        if(IsTreeViewValid())
        {
            tv.SelectedItem = tv.Nodes("a" + envID);
        }
        else
        {
            ds.Tree.ClearActiveObjects();
            ds.Tree.AddActiveObjectID(envID);
        }
        
        doDuplicate(withoutResults);
        
        var arrNewEnvironmentIds = PopulateNewEnvironmentIds(arrEnvObjectIds);
        
        if(arrNewEnvironmentIds.length > 0)
        {
            idDuplicated = arrNewEnvironmentIds[0];
        }
   }
   catch(err)
   {
        echo("Error in AlbionDuplicateEnvironment : " + err.description);
   }
    
   return idDuplicated;
}

function AlbionGetFindAnswersType(id)
{
    var kFAUnknown = 0;
    var findAnswersType = kFAUnknown;
    
    try
    {
        findAnswersType = ds.Tree.StateEngineObject.FindAnswersType(id);
    }
    catch(err)
    {
        echo("Error in AlbionGetFindAnswersType : " + err.description);
    }
   
   return findAnswersType;
}

function AlbionExtractSimulationParameters()
{
    try
    {
        if(ds.Tree.ParameterSetItf == null)
        {
            return;
        }
        
        var paramSet = ds.Tree.ParameterSetItf;
        var paramCount = paramSet.Count;
        
        var indexParam = 0;
        for(indexParam=0; indexParam < paramCount; indexParam++)
        {
            var param = paramSet(indexParam);

            ds.CreateParameter(param);
            
            var attributes = param.Attributes;

            var attribCount = attributes.Count;
            var indexAttrib = 0;
            for (indexAttrib = 0; indexAttrib < attribCount; indexAttrib++)
            {
                var attribute = attributes(indexAttrib);
                if(attribute == null)
                {
                    continue;
                }

                ds.AddParamAttribute(param, attribute);
            }
        } 
    }
    catch(err)
    {
        echo("Error in AlbionExtractSimulationParameters : " + err.description);
    }
}

function echo(message,caption)
{
    if("undefined" == typeof(caption))
    {
        caption = "AnsysWB";
    }
    
    WBScript.Out(message,true,caption);	
}

//Helper methods for albion
