function wbYesNo (message, caption, additionalFlags)
{
  // Popup a Yes/No dialog
  // Return 1(Yes), 0(No)
  if (typeof(caption) != "string") 
		caption = "";
  
  var buttonType = 4; // Yes|No;
  buttonType += 32; // Icon Questionmark

  //Filter is used to add additional info to the buttonType
  if (typeof (additionalFlags) != "undefined")
    buttonType = buttonType | additionalFlags;

  switch (WBScript.Out (message, true, caption, buttonType, WB.hWnd))
  {
	case 6: return  1; // Yes
	case 7: return  0; // No
  }
  
  return 0;
}

function wbWarningMsgBox(message,caption,additionalFlags)
{
	var buttonType = 0;

	var MBBT_OK					= 0;
	var MBBT_ICONWARNING		= 48;
	var MBBT_DEFBUTTON1			= 0;

	//Select the No of buttons
	buttonType = buttonType + MBBT_OK;

	//Select the Icon type
	buttonType = buttonType + MBBT_ICONWARNING;

	//Select the default button
	buttonType = buttonType + MBBT_DEFBUTTON1;

    //Filter is used to add additional info to the buttonType
    if (typeof (additionalFlags) != "undefined")
        buttonType = buttonType | additionalFlags;

	WBScript.Out(message,true,caption,buttonType,WB.hWnd);
}

var szYNMessage = "This utility will fix corruption in the mesh.  After it runs, the user MUST CLEAN the dsdb, then SAVE and EXIT the program (Ignore any problems).  Then RESUME the database, CLEAN, SAVE, and EXIT again.  Not following this procedure will lead to further corruption.  Do you want to continue?  (Valid in WB 10.0 and above, for use on corrupted 8.1, 9.0 and 9.0SP1 dbs)";
var szYNCaption = "Mesh Scrub";
var iRetVal = wbYesNo( szYNMessage, szYNCaption );
if( iRetVal == 1 )
{
    var szStartMessage = "This may take a few minutes.  You will be informed when the procedure is finished."
    var szStartCaption = "Mesh Scrub starting";
    wbWarningMsgBox( szStartMessage, szStartCaption );

    WB.DoWaitCursor(1);

    var iAssembly = DS.Tree.FirstActiveBranch.Model.PrototypeGroup.Assembly;
    var iParts = iAssembly.Parts(true);
    var iNumParts = iParts.Count;

    var iMesh = DS.Tree.FirstActiveBranch.Environment.AssemblyMesh;

    var iMeshPartIds = iMesh.ConfigurationPartIds;
    var iNumMeshParts = iMeshPartIds.Count;

    var vInvalidPartIds = new Array();
    var iArrayIndex = 0;

    for ( i = 1; i <= iNumMeshParts; i++ )
    {
        var iMeshPartId = iMeshPartIds(i);

        // check the validity of this part
        var bValid = false;
        for ( j = 1; ( j <= iNumParts ) && ( bValid == false ); j++ )
        {
            var iPart = iParts.Item(j);

            if ( iMeshPartId == iPart.Id )
                bValid = true;
        }

        if ( bValid == false )
        {
            vInvalidPartIds[iArrayIndex] = iMeshPartId;
            iArrayIndex++;
        }
    }

    // Any ids stored in vInvalidPartIds must be removed from the mesh.

    try
    {
        var iNumInvalids = vInvalidPartIds.length;
        for ( i = 0; i < iNumInvalids; i++ )
        {
            iMesh.RemovePart( vInvalidPartIds[i], 0 );
        }
  
        iMesh.Commit( 2048 );

        WB.DoWaitCursor(2);
        DS.Graphics.Redraw(0);

        var szMessage = "The mesh has been cleaned.  Now, CLEAN the dsdb at Model Level, SAVE your project, and then EXIT the program.  You can then restart Workbench and load your dsdb."
        var szCaption = "Mesh Scrub complete";
        wbWarningMsgBox( szMessage, szCaption );
    }
    catch (error)
    {
        var szErrMessage = "The mesh failed to clean.  Try CLEANING the dsdb at Model Level, SAVE your project, and then EXIT the program.  You can then restart Workbench and load your dsdb."
        var szErrCaption = "Mesh Scrub failed";
        wbWarningMsgBox( szErrMessage, szErrCaption );
    }
}
else
{
    var szEndMessage = "The mesh scrub was cancelled."
    var szEndCaption = "Mesh Scrub complete";
    wbWarningMsgBox( szEndMessage, szEndCaption );
}