MLPath);
		    objects[0] = xmlDoc.documentElement.selectNodes("LoadVariationData/MatML_Doc/LoadVariation");
		 }
		 else
			objects[0] = xmlDoc.documentElement.selectNodes(ImportEnggData.ObjectXMLPath);
     }
      else
      {
          objects[0] = xmlDoc.documentElement.selectNodes(ImportEnggData.ObjectName);
      }
      for (var k = 0;k<objects.length;k++)
      {
      if (objects[k].length)
      {
         for (var i = 0; i < objects[k].length; i++)
         {
            objectName = objects[k].item(i).selectSingleNode("./BulkDetails/Name");
            var getObjectName = objectName.text;
            if (findObjectName)
               getObjectName = findObjectName;
               
            var objectType = null;
            objectQualifier = objects[k].item(i).selectSingleNode("./BulkDetails/PropertyData/Qualifier");
            var lvTempEnum = null;
            var lvConvCoeffEnum = null;

            if (objectQualifier)
            {
               var edApplet =  wb.AppletList.Applet( "EDApplet").App;
               var eds = edApplet.Script;
               objectType = eds.eda.LoadVariationVarEnums.getValue(objectQualifier.text);
               lvTempEnum = eds.eda.LoadVariationVarEnums.kLoadVariationVariableTemperature;
               lvConvCoeffEnum = eds.eda.LoadVariationVarEnums.kLoadVariationVariableConvectionCoefficient;
            }
            
            if (ImportEnggData.ObjectName == "LoadVariation" && objectType &&  objectType == lvConvCoeffEnum)
            {
               // Only get time dependent for a load variation
               var objectIndependents = objects[k].item(i).selectNodes("./BulkDetails/PropertyData/ParameterValue");
               if (objectIndependents && objectIndependents.length == 1)
               {
                  var objParam = objectIndependents[0].selectSingleNode("@parameter");
                  var objectMetaData = objects[k].item(i).selectSingleNode("./Metadata");
                  if (objectMetaData == null)
                  {
                     // Try 3.1 version
                     var objMatML = objects[k].item(i).parentNode;
                     if (objMatML)
                     {
                        objectMetaData = objMatML.selectSingleNode("./Metadata");
                     }
                  }
                  var objIndpendentParamDetails = objectMetaData.selectSingleNode("./ParameterDetails[@id='"+objParam.nodeValue+"']");
                  var independentType = eds.eda.LoadVariationVarEnums.getValue(objIndpendentParamDetails.text);
                  // Don't add temperature dependent convection coefficient to the load variation list
                  if (independentType == lvTempEnum)
                     continue;
					}
               
            }
            if (objectName && objectName.text == getObjectName)
            {
               if (importEnumFilter && importEnumFilter == objectType)
		            objArr.push(new dialog.Item(objectName.text, xmlFile, ""));
               else if (importEnumFilter == null)
		            objArr.push(new dialog.Item(objectName.text, xmlFile, ""));
		      }
         }
      }
      }
      return true;
   }
   catch(error)
   {
      return false;
   }
}


function EnggData.prototype.ReadFavorites ( xmlFile, objArr, dialog )
{
    try
    {
        // Check if there are favorites
        var prefMgr = wb.PreferenceMgr;
        var favObjects = null;
        try
        {
            favObjects = prefMgr.Preferences(ImportEnggData.ObjectPrefData.Defaults);
        }
        catch(e)
        {
        }
        if (!favObjects) return false;

        // Don't move above above, used to determine IF a favorite exists
        if (!objArr) return true;

        // Loop through the preferences and add the materials to the favorites
        var prefCount = favObjects.Count;
        for (var i=1; i <= prefCount; i++)
        {
            var favObject = favObjects.Item(i);
            var name = favObject.Value;
            var source = favObject.Source;
            ImportEnggData.ReadLibrary( source, objArr, dialog, name);
        }

        return true;
    }
    catch(error)
    {
        return false;
    }
}

function EnggData.prototype.ReadLegacy ( folder, objArr, dialog )
{
   try
   {
      var edApplet =  wb.AppletList.Applet( "EDApplet").App;
      var eds = edApplet.Script;

      var fso = CreateActiveXObject(str_FileSystemObjectProgId);
      // Is this a file on the system
      if (fso.FileExists(folder))
      {
         // A file path was passed in so check only this file. Also this condition may
         // only occur for a validation check so objArr must be null
         var file = fso.GetFile(folder);
         var validFile = ImportEnggData.isLegacy(file);

         if (validFile)
               return true;

         return false;
         // Strip out the name and only use the path
         folder = file.ParentFolder.Path;
      }

      // Is this a file folder on the system
		if (!fso.FolderExists(folder))
         return false;

		// Does this folder contain any DS XML files
		var xmlFolder = fso.GetFolder(folder);
      var fc = new Enumerator(xmlFolder.files);
      for (; !fc.atEnd(); fc.moveNext())
      {
         var file = fc.item();
         var validFile = ImportEnggData.isLegacy(file, objArr, dialog);

         if (!objArr && validFile) return true;
      }
      if (objArr.length > 0)
      {
         return true;
      }
      return false;
   }
   catch(error)
   {
      return false;
   //debugger;
   }
}

function EnggData.prototype.ReadAnsys( cdbFile, unitSys, objArr, dialog )
{
	try
	{
		if (cdbFile == "Favorites")
		{
			return	ImportEnggData.ReadFavorites(null, objArr,	dialog);
		}

		if (!fso.FileExists(cdbFile))
		{
			return false;
		}

		var	plugin =CreateActiveXObject( GenWBProgId("FEPlugin_ANSYS.AnsysContentHandler") );
		var	doc	=CreateActiveXObject( GenWBProgId("FEObjects.FEDocument") );
		var	settings =CreateActiveXObject( GenWBProgId("FEHelper.FEPluginSettings") );

		if( typeof( unitSys ) == "undefined" || unitSys == null )
			doc.UnitSystem = ed.Script.UnitSystem;
		else
			doc.UnitSystem = parseInt(unitSys);
			
		settings.MaterialsOnly = true;

		plugin.Init( doc, cdbFile, settings );
		plugin.Go();
		var materials = doc.Model.Materials;
		
		if ( materials.Count == 0 )
		   return false;

		if( !objArr) return true;
		
		// Look for the materials
		for (var i = 1; i <= materials.Count; i++)
		{
			var name = materials.Item(i).DisplayName;
			var mat = new dialog.Item(name, cdbFile, "");
		
			mat.DataObj = materials.Item(i).MaterialObject;
			objArr.push( mat);
		}
		return true;
	}
	catch(error)
	{
		return false;
	}
}

function EnggData.prototype.isLegacy ( file, objArr, dialog )
{
   try
   {
         var splitFile = file.Name.split(".");
         if (splitFile.length == 1) return false;
         var fileExt = splitFile[1];
         if (fileExt.toLowerCase() == "xml")
         {
            // Is this a Legacy XML file
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

            // Is this necessary
            xmlDoc.async = false;
            var bSuccess = xmlDoc.load(file.Path);
            if (!bSuccess)
            {
               return false;
            }

            // Check if this is an DS Material File
            if (xmlDoc.documentElement.nodeName.toLowerCase() != ImportEnggData.ObjectName.toLowerCase())
            {
	            // This is not a DS "Object" File
	            return false;
            }

            // If we find one good file and just checking source can return
            if (!objArr) return true;

            var objectName = xmlDoc.documentElement.selectSingleNode("info/name");
            if (objectName)
            {
   		      objArr.push(new dialog.Item(objectName.text, file.Path, ""));
   		      return true;
   		   }
   		   else
   		   {
   		      return false;
   		   }
         }
         return false;
   }
   catch(error)
   {
      return false;
   //debugger;
   }
}

function EnggData.prototype.ReadProject ( xmlFile, objArr )
{
   try
   {
         return false;
      xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

      // Is this necessary
      xmlDoc.async = false;
      var bSuccess = xmlDoc.load(xmlFile);
      if (!bSuccess)
      {
      }

      // Look for a MatML section

      // For each of the categories under the PropertyHierarchy tag build a section
      var children = xmlDoc.documentElement.childNodes;
	   for ( var child = children.nextNode(); child != null; child = children.nextNode() )
	   {
	      var i = 10;
	   }
	   return false;

   }
   catch(error)
   {
      return false;
   //debugger;
   }
}

function EnggData.prototype.GetImportDialogItems(dialog /* As ImportDialog */, source /* As ImportDialog.DataSource */)
{
   switch (source.Type)
   {
	   case "Favorites":
	      var dataItems = [];
         if ( ImportEnggData.ReadFavorites(null, dataItems, dialog) )
         {
	         source.Items = dataItems; // Populate the array of items for the given source
         }
         else
         {
            // We have a problem
         }
		   break;
	   case "Library":
	      var dataItems = [];
         if ( ImportEnggData.ReadLibrary(source.FullPath, dataItems, dialog) )
         {
	         source.Items = dataItems; // Populate the array of items for the given source
         }
         else
         {
            // We have a problem
         }
		   break;
	   case "Folder":
	      var dataItems = [];
         if ( ImportEnggData.ReadLegacy(source.FullPath, dataItems, dialog) )
         {
	         source.Items = dataItems; // Populate the array of items for the given source
         }
         else
         {
            // We have a problem
         }
		   break;
	   case "Project":
		   break;
       case "Ansys":
	     var dataItems = [];
         if ( ImportEnggData.ReadAnsys(source.FullPath, source.UnitSystem, dataItems, dialog) )
         {
	         source.Items = dataItems; // Populate the array of items for the given source
	         source.UnitSystem = source.UnitSystem;
         }
         else
         {
            // We have a problem
         }
		 break;
   }
}

function EnggData.prototype.ValidateNewDataSource(type, source) /* As Boolean */
{
   try {
      var validSource = false;
      // The value of this is the Object which is calling this method externally
      switch (type)
      {
	      case "Favorites":
            // Favorites Items?
            if ( ImportEnggData.ReadFavorites(source, null) )
            {
               validSource = true;
            }
            break;
	      case "Library":
            // Library file?
            if ( ImportEnggData.ReadLibrary(source, null) )
            {
               validSource = true;
            }
            break;
	      case "Folder":
            // Legacy folder?
            if ( ImportEnggData.ReadLegacy(source, null) )
            {
               validSource = true;
            }
            break;
	      case "Project":
            // Project
            if ( ImportEnggData.ReadProject(source, null) )
            {
               validSource = true;
            }
            break;
          case "Ansys":
            // ANSYS cdb file
            if ( ImportEnggData.ReadAnsys(source, null, null, null) )
            {
               validSource = true;
            }
            break;
      }

      if (!validSource) return false;
      
      return true;
   }
   catch(error)
   {
      return false;
   }
}

function EnggData.prototype.UpdateSources(dialog) /* As Object */
{
    try
    {
        var prefMgr = wb.PreferenceMgr;
        try
        {
            var prefGroup = prefMgr.PreferencesGroup(ImportEnggData.ObjectPrefData.Group);
            var prefPreferences = prefGroup.Preferences;
            var prefPreference = null;
            // Must iterate downward due to Item call based on ever decreasing size
            for (var i = prefPreferences.Count; i >= 1; i--)
            {
                prefPreference = prefPreferences.Item(i);
                if (prefPreference.PreferenceID == ImportEnggData.ObjectPrefData.Sources)
                {
                    prefPreferences.Remove(i);
                }
            }
        }
        catch(e)
        {
        }

        for(var i=0;i<dialog.DataSources.length;i++)
        {
            var dataSource = dialog.DataSources[i];
            var type = dataSource.Type;
            var source = dataSource.FullPath;
            var units = dataSource.UnitSystem;

            var validSource = false;
            // The value of this is the Object which is calling this method externally
            switch (type)
            {
                case "Library":
                    // Library file?
                    if ( ImportEnggData.ReadLibrary(source, null) )
                    {
                        validSource = true;
                    }
                    break;

                case "Folder":
                    // Legacy folder?
                    if ( ImportEnggData.ReadLegacy(source, null) )
                    {
                        validSource = true;
                    }
                    break;

                case "Project":
                    // Project
                    if ( ImportEnggData.ReadProject(source, null) )
                    {
                        validSource = true;
                    }
                    break;
                 case "Ansys":
                    // Ansys
                    if ( ImportEnggData.ReadAnsys(source, units, null, null) )
                    {
                        validSource = true;
                    }
                    break;
            }
            if (!validSource) continue;

            //
            // Add the source to the preference file
            var pPref	= prefPreferences.Add();

            pPref.NonTranslatableName = ImportEnggData.ObjectPrefData.SourcesName;

            pPref.Name = ImportEnggData.ObjectPrefData.SourceName;

            pPref.GroupName = ImportEnggData.ObjectPrefData.GroupName;

            pPref.PreferenceID = ImportEnggData.ObjectPrefData.Sources;

            pPref.PreferenceType = 7;

            pPref.GroupTitle = ImportEnggData.ObjectPrefData.GroupTitle;
            
            if( typeof( units ) != "undefined" && type == "Ansys" )
				pPref.UnitString = units;

            // For the value remove the last part of the source
            var edApplet =  wb.AppletList.Applet( "EDApplet").App;
            var eds = edApplet.Script;
            var fso = CreateActiveXObject(str_FileSystemObjectProgId);
            try
            {
               // Strip out any trailing slash for a folder
               var file = fso.GetFolder(source);
               source = file.Path;
            }
            catch(e)
            {
            }

            pPref.Value = source;
        }
        prefMgr.Save();        
    }
    catch(error)
    {
    return;
    }
}

function EnggData.prototype.ImportDialogReturn(source, item)
{
   var edApplet =  wb.AppletList.Applet( "EDApplet").App;
   var eds = edApplet.Script;

   var sourceFile = new String(item.Source);
   if( item.DataObj != null )
   {
	   switch (ImportEnggData.ObjectName)
	   {
	      case "Material":
            newObject = edApplet.ProjectLibrary.addMaterial(item.DataObj,1);
	         break;
	      case "Convection":
            newObject = edApplet.ProjectLibrary.addConvection(item.DataObj,1);
	         break;
	      case "LoadVariation":
            newObject = edApplet.ProjectLibrary.addLoadVariation(item.DataObj,1);
	         break;
	      case "BeamSection":
            newObject = edApplet.ProjectLibrary.addBeamSection(item.DataObj,1);
	         break;
	      default:
	         break;
	   }
   }
   else
   {
	   switch (importDialog.Type)
	   {
	      case "Material":
            newObject = CreateActiveXObject(GenWBProgId("AnsMaterial.Material"));
            newObject.Name = item.Name;
	         break;
	      case "Convection":
            newObject = CreateActiveXObject(GenWBProgId("AnsMaterial.LoadVariation"));
            newObject.Name = item.Name;
	         break;
	      case "LoadVariation":
            newObject = CreateActiveXObject(GenWBProgId("AnsMaterial.LoadVariation"));
            newObject.Name = item.Name;
	         break;
	      case "BeamSection":
            newObject = CreateActiveXObject(GenWBProgId("AnsMaterial.BeamSection"));
            newObject.Name = item.Name;
	         break;
	      default:
	         break;
	   }
      newObject.NameInSource = item.Name.toString();
      if (newObject)
         newObject.ReadMatML(sourceFile.toString());
   }

   importObject = newObject;
}

function EnggData.prototype.ValidateSource(source) /* As Boolean */
{
   try {
      var validSource = false;
      if ( ImportEnggData.ReadLibrary(source, null) || ImportEnggData.ReadLegacy(source, null) || ImportEnggData.ReadProject(source, null) /*|| ImportEnggData.ReadAnsys(source, null)*/ )
      {
         validSource = true;
      }
      return validSource;
   }
   catch(error)
   {
      return false;
   }
}


//
// Import Dialog
//
function DisplayImportDialog( type, multiSelect, enumFilter )
{
   importObject = null;
   
   if (multiSelect == null) multiSelect = true;
   importEnumFilter = enumFilter;

	//var evalStr = "var typeObj = new " + type;
	//eval(evalStr);
	ImportEnggData = null;
   
	//	Create the Import Dialog object
	importDialog = new ImportDialog();

    var edApplet =  wb.AppletList.Applet( "EDApplet").App;
    var eds = edApplet.Script;
    importDialog.eds = eds;
    importDialog.edApplet = edApplet;

	switch (type)
	{
	   case "MaterialData":
         var matlPrefData = {Group:"EDA_MaterialData", GroupName:"MaterialData", GroupTitle:"Default Material Sources", Sources:"PID_EDAMaterialSources", SourcesName:"MaterialSources", SourceName:"Material Source", Defaults:"PID_EDAMaterialDefaults"};
         ImportEnggData = new EnggData("Material", "MaterialData/MatML_Doc/Material", matlPrefData);
	      importDialog.Type = "Material";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Library";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Folder";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Ansys";

	      break;
	   case "ConvectionData":
         var convPrefData = {Group:"EDA_ConvectionData", GroupName:"ConvectionData", GroupTitle:"Default Convection Sources", Sources:"PID_EDAConvectionSources", SourcesName:"ConvectionSources", SourceName:"Convection Source", Defaults:"PID_EDAConvectionDefaults"};
         ImportEnggData = new EnggData("Convection", "ConvectionData/MatML_Doc/Material", convPrefData);
	      importDialog.Type = "Convection";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Library";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Folder";
	      break;
	   case "LoadVariationData":
         var lvPrefData = {Group:"EDA_LoadVariationData", GroupName:"LoadVariationData", GroupTitle:"Default LoadVariation Sources", Sources:"PID_EDALoadVariationSources", SourcesName:"LoadVariationSources", SourceName:"LoadVariation Source", Defaults:"PID_EDALoadVariationDefaults"};
         ImportEnggData = new EnggData("LoadVariation", "LoadVariationData/MatML_Doc/LoadVariation", lvPrefData);
	      importDialog.Type = "LoadVariation";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Library";
	      break;
	   case "BeamSectionData":
         var beamPrefData = {Group:"EDA_BeamSectionData", GroupName:"BeamSectionData", GroupTitle:"Default Beam Section Sources", Sources:"PID_EDABeamSectionSources", SourcesName:"BeamSectionSources", SourceName:"Beam Section Source", Defaults:"PID_EDABeamSectionDefaults"};
         ImportEnggData = new EnggData("BeamSection", "BeamSectionData/MatML_Doc/BeamSection", beamPrefData);
	      importDialog.Type = "BeamSection";
	      importDialog.DataSourcesAllowed[importDialog.DataSourcesAllowed.length] = "Library";
	      break;
	   default:
	      break;
	}
	if (!multiSelect)
	{
		importDialog.MultiSelect = false; // false: radio buttons; dialog returns 1 item
	   importDialog.MultiSource = false; // true: selection allowed across sources
	}

	// Populate the sources that can be imported from
   importDialog.DataSources = [];

   // Add the Favorites as the first item always
   if ( ImportEnggData.ReadFavorites("Favorites", null) )
   {
      importDialog.DataSources[importDialog.DataSources.length] = new importDialog.DataSource("Favorites", "Favorites");
   }

	var listSources = wb.PreferenceMgr.PreferenceList(ImportEnggData.ObjectPrefData.Sources);
   for (var i = 1; i <= listSources.Count; i++)
   {
      var source = listSources.Item(i);
      // Library file?
      if ( ImportEnggData.ReadLibrary(source, null) )
      {
         importDialog.DataSources[importDialog.DataSources.length] = new importDialog.DataSource("Library", source);
         continue;
      }
      else
      // Legacy folder?
      if ( (importDialog.Type == "Material" || importDialog.Type == "Convection") && ImportEnggData.ReadLegacy(source, null) )
      {
         importDialog.DataSources[importDialog.DataSources.length] = new importDialog.DataSource("Folder", source);
         continue;
      }
      else
      // Project
      if ( ImportEnggData.ReadProject(source, null) )
      {
        // importDialog.DataSources[importDialog.DataSources.length] = new importDialog.DataSource("Project", source);
         continue;
      }
      else
      // Ansys
      if ( importDialog.Type == "Material" && ImportEnggData.ReadAnsys(source, wb.PreferenceMgr.Preferences(ImportEnggData.ObjectPrefData.Sources).Item(i).UnitString, null, null) )
      {
		var idx = importDialog.DataSources.length;
		importDialog.DataSources[idx] = new importDialog.DataSource("Ansys", source);
		importDialog.DataSources[idx].UnitSystem = parseInt( wb.PreferenceMgr.Preferences(ImportEnggData.ObjectPrefData.Sources).Item(i).UnitString );
		continue;
      }

   }
	ImportDialog.prototype.GetImportDialogItems = ImportEnggData.GetImportDialogItems;
	importDialog.ValidateNewDataSource = ImportEnggData.ValidateNewDataSource;
	importDialog.UpdateSources = ImportEnggData.UpdateSources;

	if(importDialog.Show() != 1) // User didn't clicked OK
	{
        importObject = null;
	    edApplet.Script.endWaitCursor();
	    return importObject;
    }

	edApplet.Script.beginWaitCursor();
	importDialog.IterateSelectedItems(ImportEnggData.ImportDialogReturn);

	edApplet.Script.endWaitCursor();
	return importObject;
}
function ValidateSource( type, source )
{
	ImportEnggData = null;
   
    var edApplet =  wb.AppletList.Applet( "EDApplet").App;
    var eds = edApplet.Script;

	switch (type)
	{
	   case "MaterialData":
         var matlPrefData = {Group:"EDA_MaterialData", GroupName:"MaterialData", GroupTitle:"Default Material Sources", Sources:"PID_EDAMaterialSources", SourcesName:"MaterialSources", SourceName:"Material Source", Defaults:"PID_EDAMaterialDefaults"};
         ImportEnggData = new EnggData("Material", "MaterialData/MatML_Doc/Material", matlPrefData);
	      break;
	   case "ConvectionData":
         var convPrefData = {Group:"EDA_ConvectionData", GroupName:"ConvectionData", GroupTitle:"Default Convection Sources", Sources:"PID_EDAConvectionSources", SourcesName:"ConvectionSources", SourceName:"Convection Source", Defaults:"PID_EDAConvectionDefaults"};
         ImportEnggData = new EnggData("Convection", "ConvectionData/MatML_Doc/Material", convPrefData);
	      break;
	   case "LoadVariationData":
         var lvPrefData = {Group:"EDA_LoadVariationData", GroupName:"LoadVariationData", GroupTitle:"Default LoadVariation Sources", Sources:"PID_EDALoadVariationSources", SourcesName:"LoadVariationSources", SourceName:"LoadVariation Source", Defaults:"PID_EDALoadVariationDefaults"};
         ImportEnggData = new EnggData("LoadVariation", "LoadVariationData/MatML_Doc/LoadVariation", lvPrefData);
	      break;
	   case "BeamSectionData":
         var beamPrefData = {Group:"EDA_BeamSectionData", GroupName:"BeamSectionData", GroupTitle:"Default Beam Section Sources", Sources:"PID_EDABeamSectionSources", SourcesName:"BeamSectionSources", SourceName:"Beam Section Source", Defaults:"PID_EDABeamSectionDefaults"};
         ImportEnggData = new EnggData("BeamSection", "BeamSectionData/MatML_Doc/BeamSection", beamPrefData);
	      break;
	   default:
	      break;
	}
   return ImportEnggData.ValidateSource(source);
}


//
//	IMPORT MATERIAL / CONVECTION / ETC DIALOG
//
//	Dialog types:	"Material", "Convection"
//	Source types:	"Library", "Project", "Folder", "Favorites"
//
function ImportDialog(  )
{
//	Public fields
//
	this.IsUnix = (platform == "UNIX");
    this.Type = "Material";
	this.MultiSelect = true; // false: radio buttons; dialog returns 1 item
	this.MultiSource = true; // true: selection allowed across sources
	this.SyncChecked = true;
	this.SyncVisible = false;
	this.DataSources = []; // ImportDialog.DataSource[] most recent first
   this.DataSourcesAllowed = [];
	this.DefaultDataSourceType = "Library";
	this.DefaultLocations =
	{
		Library:	"",	/* If empty: Browse defaults to user's My Documents folder */
		Folder:		"",
		Favorites:	"",
		Ansys:		""
	};
	this.SelectedSource = null; // Read-only
//
//	Callback functions
//
	this.ValidateNewDataSource = null;
//
//	Private fields
//
	this.PathHelper =CreateActiveXObject(str_WBStartPageFileProgId);
	this.FileDialog =CreateActiveXObject(wb_wbFileDialogProgid);
	this.FolderDialog =CreateActiveXObject(wb_wbFolderDialogProgid);
	this.MyDocuments = GetMyDocumentsPath();

	this.Dialog =
	{
		Control:	CreateActiveXObject(str_WBHTMLDialogProgId),
		Width:		600,
		Height:		500,
		URL: installDirNoLocale + "html" + str_PathSeparator + "ImportDialog" + str_PathSeparator + "ImportDialog.htm"
	};

	this.AddDataSourceDialog =
	{
		Source:		null,
		Control:	CreateActiveXObject(str_WBHTMLDialogProgId),
		Width:		500,
		Height:		500,
		URL: installDirNoLocale + "html" + str_PathSeparator + "ImportDialog" + str_PathSeparator + "AddDataSourceDialog.htm",
		Caption:	StringTable("ID_AddDataSourceDialogCaption")
	};
}
//
//	Methods
//
function ImportDialog.prototype.GetImportDialogItems()
{
   return;
}

function ImportDialog.prototype.Show()
{
	var captionMap =
	{
		Material:	"ID_ImportMaterialDataDialogCaption",
		Convection:	"ID_ImportConvectionDataDialogCaption",
		LoadVariation:	"ID_ImportLoadVariationDataDialogCaption",
		BeamSection:	"ID_ImportBeamSectionDataDialogCaption"
	};
	var d = this.Dialog;
	return d.Control.DoDialog(wb.hWnd, d.URL, this, false/*MODAL*/, d.Width, d.Height, 0/*FLAGS*/, StringTable(captionMap[this.Type]));
}
function ImportDialog.prototype.GetSelectedItems() /* As ImportDialog.Item[] */
{
	var items = [];
	var i = this.SelectedSource.Items;
	for(var j =0 ;j< i.length ; j++) if(i[j].Selected) items[items.length] = i[j];
	return items;
}
function ImportDialog.prototype.GetAllSelectedItems() /* As ImportDialog.Item[] */
{
	var items = [];
	for(var s =0 ; s < this.DataSources.length ; s++)
	{
		var i = this.DataSources[s].Items;
		for(var j=0;j< i.length; j++) if(i[j].Selected) items[items.length] = i[j];
	}
	return items;
}
//	callback refers to a function with signature (ImportDialog.DataSource, ImportDialog.Item)
function ImportDialog.prototype.IterateSelectedItems(callback)
{
	for(var i =0 ; i< this.DataSources.length; i++)
	{
		var source = this.DataSources[i];
		for(var j =0 ;j < source.Items.length; j++)
		{
			var item = source.Items[j];
			if(item.Selected) callback(source, item);
		}
	}
}
function ImportDialog.prototype.ShowErrorMessage(message, caption, hWnd)
{
   var parentHWND = importDialog.hWnd;
   if (typeof(hWnd) != "undefined")
        parentHWND = hWnd;
	wbErrorMsgBox(message, caption, 0, parentHWND);
}
//
//	Object Definitions
//

function ImportDialog.prototype.DataSource(dataSourceType, fullPath, unitSys)
{
	this.Type = dataSourceType;
	this.FullPath = fullPath;
	this.Items = []; // ImportDialog.Item[]
	this.UnitSystem = unitSys;
}
function ImportDialog.prototype.Item(name, source, toolTip)
{
	this.Name = name;
	this.Source = source;
	this.ToolTip = toolTip? toolTip : "";
	this.Selected = false;
	this.DataObj = null;
}
