GHT  = 1;
var TE_HTA_CENTER = 2;

var ds, wb, obj, stringTable, helper, sigDigits, scriptEngine, bModify;
var beta = 1;
var sortArr;
var is2DModel = false;
var ascending		= 0;
var descending		= 1;
var byText			= 0;
var byNumber		= 1;
var byDate			= 2;
var pageDone		= false;
var hasBehavior = false;
var hasNormalStiff = false;
var hasUpdateStiffness = false;
var hasThermalCond = false;
var hasElectricCond = false;
var hasInitialEffect = false;
var hasFrictionalRegion = false;
var hasOffset = false;
var hasPinballRadius = false;
var hasPinballFactor = false;
var hasConstraintType = false;
var hasTimeStepControl = false;
var hasDampingFactor = false;
var hasDetectionMethod = false;
var hasPenetrationTol = false;
var foundColumnSizeZero = false;
var UNIXselectStr = null;
var prefObj;
var autoModeCount = 0;
var manualModeCount = 0;
var sliderTolCount = 0;
var valueTolCount = 0;
var thicknessTolCount = 0;
var contactTableFlag = false;
var contactPropAcc = null;

var bListOneShowName, bListOneShowType, bListOneShowScope, bListOneShowFrictionCoeff, bListOneShowMode, bListOneShowTrim;
var bListOneShowBehavior, bListOneShowNormalStiff, bListOneShowUpdateStiffness, bListOneShowStatus, bListOneShowFormulation;
var bListOneShowInitialEffect, bListOneShowUserOffset, bListOneShowThermalCond, bListOneShowElectricCond, bListOneShowPinballRegion;
var bListOneShowPinballRadius, bListOneShowPinballFactor, bListOneShowConstraintType, bListOneShowTimeStepControl;
var bListOneShowDampingFactor, bListOneShowDetectionMethod, bListOneShowPenetrationTol;

//context menu items
var ID_GOTO_SELECTED_ITEMS  = 1000;
var ID_SHOW_NAME			= 2000;
var ID_SHOW_TYPE			= 3000;
var ID_SHOW_SCOPE			= 4000;
var ID_SHOW_FRICTIONCOEFF	= 5000;
var ID_SHOW_MODE			= 6000;
var ID_SHOW_BEHAVIOR		= 7000;
var ID_SHOW_NORMALSTIFF		= 8000;
var ID_SHOW_UPDATESTIFF		= 9000;
var ID_SHOW_STATUS			= 10000;
var ID_SHOW_FORMULATION		= 11000;
var ID_SHOW_INITIALEFFECT	= 12000;
var ID_SHOW_USEROFFSET		= 13000;
var ID_SHOW_THERMALCOND		= 14000;
var ID_SHOW_PINBALLREGION	= 15000;
var ID_SHOW_PINBALLRADIUS	= 16000;
var ID_SHOW_PINBALLFACTOR	= 17000;
var ID_SHOW_CONSTRAINTTYPE  = 18000;
var ID_SHOW_TRIM			= 19000;
var ID_SHOW_TIMESTEPCONTROL = 20000;
var ID_SHOW_ELECTRICCOND    = 21000;
var ID_SHOW_DAMPINGFACTOR   = 22000;
var ID_SHOW_DETECTIONMETHOD = 23000;
var ID_SHOW_PENETRATIONTOL  = 24000;
var ID_RESET_COLUMNS        = 25000;
var ID_RESET_COLUMN_WIDTHS  = 26000;

var columWidthsClass = new ColumWidthsClass();

var cbDataGrid1RowClick = null;
var cbDataGrid2RowClick = null;
var cbDataGrid3RowClick = null;
var cbGrid1DisplayContextMenu = null;
var cbGrid2DisplayContextMenu = null;
var cbGrid3DisplayContextMenu = null;

function ColumWidthsClass()
{
	this.Contact_Name_Width = 0;
	this.Contact_Type_Width = 0;
	this.Contact_ScopeGroup_Width = 0;
	this.Contact_ContactFrictionCoefficient_Width = 0;
	this.Contact_ContactMode_Width = 0;
	this.Contact_Behavior_Width = 0;
	this.Contact_ContactNormalStiffness_Width = 0;
	this.Contact_ContactRegionUpdateContactStiffness_Width = 0;
	this.Contact_VariableStatus_Width = 0;
	this.Contact_ContactRegionContactFormulation_Width = 0;
	this.Contact_ContactRegionInitialEffect_Width = 0;
	this.Contact_ContactRegionUserOffset_Width = 0;
	this.Contact_ContactRegionThermalConductance_Width = 0;
	this.Contact_ContactRegionElectricConductance_Width = 0;
	this.Contact_ContactPinballRegion_Width = 0;
	this.Contact_ContactPinballRadius_Width = 0;
	this.Contact_ContactPinballFactor_Width = 0;
	this.Contact_ContactRegionConstrainType_Width = 0;
	this.Contact_ContactTrim_Width = 0;
	this.Contact_ContactRegionTimeStepControl_Width = 0;
	this.Contact_ContactRegionDampingFactor_Width = 0;
	this.Contact_ContactRegionDetectionMethod_Width = 0;
	this.Contact_ContactRegionPenetrationTol_Width = 0;
    this.Contact_FirstVisit = true;
}

function window_onload() 
{
	var wbTemp = window.external;
	wb = wbTemp;
	ds = wbTemp.AppletList.Applet("DSApplet").App;
	obj = ds.Tree.GetObject(ds.Tree.FirstActiveObjectID);	
	stringTable = wbTemp.AppletList.WBApplet("DSApplet").StringTable;
	scriptEngine = wb.ScriptEngine.Engine;	
	if(ds.GUIState && ds.GUIState.GUIDriver)
	{
		ds.GUIState.GUIDriver.MenuListener.AddListener(3, this);
	}

	prefObj = wb.PreferenceMgr;
	pageName.innerText = obj.Name;

	asymNote.innerText = "";
	asymbreak.style.display = "none";		
	asymNote.style.display = "none";		
	
	sortArr	= new Array();
	sigDigits	= ds.AccessControl.ValueLength;
	helper		= ds.Script.WBUtilsHelper;

    contactTableTitle.innerText = stringTable.String("ID_ConnectionWorksheetContactInformation");
    jointDOFChecker.innerText = stringTable.String("ID_ConnectionWorksheetJointDOFChecker");
    jointTableTitle.innerText = stringTable.String("ID_ConnectionWorksheetJointInformation");
    meshConnectionTableTitle.innerText = stringTable.String("ID_ConnectionWorksheetMeshConnectionInformation");

	setTimeout("setList()", 250);

	cbGrid1DisplayContextMenu = DataGrid1.OnDisplayContextMenu;
	cbGrid1DisplayContextMenu.AddCOM(this, "Grid1_DisplayContextMenuDelegate");
	
	cbDataGrid1RowClick = DataGrid1.OnFixedRowClick;
	cbDataGrid1RowClick.AddCOM(this, "WBDataGridCtrl1_RowClickDelegate");
	
	cbDataGrid2RowClick = DataGrid2.OnFixedRowClick;
	cbDataGrid2RowClick.AddCOM(this, "WBDataGridCtrl2_RowClickDelegate");
		
	cbGrid2DisplayContextMenu = DataGrid2.OnDisplayContextMenu;
	cbGrid2DisplayContextMenu.AddCOM(this, "Grid2_DisplayContextMenuDelegate");

	cbDataGrid3RowClick = DataGrid3.OnFixedRowClick;
	cbDataGrid3RowClick.AddCOM(this, "WBDataGridCtrl3_RowClickDelegate");
		
	cbGrid3DisplayContextMenu = DataGrid3.OnDisplayContextMenu;
	cbGrid3DisplayContextMenu.AddCOM(this, "Grid3_DisplayContextMenuDelegate");

	contactPropAcc = scriptEngine.CreateActiveXObject(scriptEngine.GenWBProgId("WBControls.WBObjectBrowser"));
}

function setList()
{
    setGrid1List();
    setGrid2List();
    setGrid3List();
}

function setGrid1List()
{	
    setVarsGrid1();
    setListProps();
    setColumnHeadersGrid1();  
    addGrid1Items();
    ResizeGrid1Lists();
}

function setGrid2List()
{	
    fillJointDOFCheckerTable();

    setListProps();
    var appletMode = ds.AppletMode;
    if( appletMode != "idMeshing" )
        setColumnHeadersGrid2();
    addGrid2Items();
    ResizeGrid2Lists();
}

function setGrid3List()
{	
    setVarsGrid3();
    setListProps();
    setColumnHeadersGrid3();  
    addGrid3Items();
    ResizeGrid3Lists();
}

function fillJointDOFCheckerTable()
{
	// Check if there are any bodies in the model
	var numActiveBody = 0;
	var branch = ds.Tree.FirstActiveBranch;
	var protoGroup = branch.PrototypeGroup;
	var bodyGroups = protoGroup.BodyGroups;
	for(var idx = 1; idx <= bodyGroups.count; idx++)
	{
	    var bodyGroup = bodyGroups.Item(idx);
	    if(bodyGroup.Suppressed) continue;
	    numActiveBody++;
	}

	if(0 == numActiveBody) return;
	
	// Check if there are any joints in the model
	var jointObjs = obj.Joints;
	if(0 == jointObjs.count)
	{
		// Do not display the DOF checker title
		jointDOFChecker.style.display = "none";
		return;
	}
	
	jointDOFChecker.style.display = "";
	
	var oTBody = document.createElement("TBODY");
	var oTBody2 = document.createElement("TBODY");
	var oCaption = document.createElement("CAPTION");
	var oCaption2 = document.createElement("CAPTION");
	var oCaption3 = document.createElement("CAPTION");
	var oRow, oCell;
	var i, j;
	
	// If the table already has nodes, we must start by clearing them
	if( oTable.hasChildNodes() )
    {
        // Only has two children
        oTable.removeChild(oTable.firstChild);
        oTable.removeChild(oTable.lastChild);     
    }

	var body = new Array;
	body[0] = numActiveBody;
	if(1 == numActiveBody)
		body[1] = "Unsuppressed Part x 6 DOF";
	else
		body[1] = "Unsuppressed Parts x 6 DOF";
		
	body[2] = "=";
	var numBodyDOF = 6 * numActiveBody;
	body[3] = "+" + numBodyDOF;

	var numFixed         = 0;	var numFixedDOF         = 0;
	var numRevolute      = 0;	var numRevoluteDOF      = 0;
	var numTranslational = 0;	var numTranslationalDOF = 0;
	var numSlot          = 0;	var numSlotDOF          = 0;
	var numCylindrical   = 0;	var numCylindricalDOF   = 0;
	var numUniversal     = 0;	var numUniversalDOF     = 0;
	var numSpherical     = 0;	var numSphericalDOF     = 0;
	var numPlanar        = 0;	var numPlanarDOF        = 0;
	var numGeneral       = 0;	var numGeneralDOF       = 0;
    var num3DRadial      = 0;   var num3DRadialDOF      = 0;

	for(var i = 1; i <= jointObjs.count; i++)
	{
		var curJoint = jointObjs(i);
		if (curJoint.Suppressed) continue;

		// Check the state; it may be in suppressed state due to prototype suppressions
		if(curJoint.State == ds.Script.id_Suppressed) continue;

		switch(curJoint.JointType)
		{
            case ds.Script.id_FixedJoint:    
                numFixed++;
                break;               
            case ds.Script.id_RevoluteJoint:
                numRevolute++;
                break;
            case ds.Script.id_TranslationalJoint:
                numTranslational++;
                break;
            case ds.Script.id_SlotJoint:
                numSlot++;
                break;
            case ds.Script.id_CylindricalJoint:
                numCylindrical++;
                break;
            case ds.Script.id_UniversalJoint:
                numUniversal++;
                break;
            case ds.Script.id_SphericalJoint:
                numSpherical++;
                break;
            case ds.Script.id_PlanarJoint:
                numPlanar++;
                break;
            case ds.Script.id_GeneralJoint:
                numGeneral++;
                if(!curJoint.TranslationXFixedOrFree) numGeneralDOF++;
                if(!curJoint.TranslationYFixedOrFree) numGeneralDOF++;
                if(!curJoint.TranslationZFixedOrFree) numGeneralDOF++;
                if(!curJoint.RotationXFixedOrFree)    numGeneralDOF++;
                if(!curJoint.RotationYFixedOrFree)    numGeneralDOF++;
                if(!curJoint.RotationZFixedOrFree)    numGeneralDOF++;
                break;
            case ds.Script.id_3DRadialGap:
                num3DRadial++;
                if (!curJoint.TranslationZFixedOrFree) num3DRadialDOF++;
                if (!curJoint.RotationXFixedOrFree) num3DRadialDOF++;
                if (!curJoint.RotationYFixedOrFree) num3DRadialDOF++;
                if (!curJoint.RotationZFixedOrFree) num3DRadialDOF++;
                break;
		}
	}

	var rowNum = 0;
	var colNum = 4;
	var jointCell = new Array;

	if(numFixed)
	{
		jointCell[rowNum+",0"] = numFixed;
		jointCell[rowNum+",1"] = "Fixed constraint x 6 DOF";
		jointCell[rowNum+",2"] = "=";
		numFixedDOF = 6 * numFixed;
		jointCell[rowNum+",3"] = "-" + numFixedDOF;
		rowNum++;
	}

	if(numRevolute)
	{
		jointCell[rowNum+",0"] = numRevolute;
		jointCell[rowNum+",1"] = "Revolute joint x 5 DOF";
		jointCell[rowNum+",2"] = "=";
		numRevoluteDOF = 5 * numRevolute;
		jointCell[rowNum+",3"] = "-" + numRevoluteDOF;
		rowNum++;
	}

	if(numTranslational)
	{
		jointCell[rowNum+",0"] = numTranslational;
		jointCell[rowNum+",1"] = "Translational joint x 5 DOF";
		jointCell[rowNum+",2"] = "=";
		numTranslationalDOF = 5 * numTranslational;
		jointCell[rowNum+",3"] = "-" + numTranslationalDOF;
		rowNum++;
	}

	if(numSlot)
	{
		jointCell[rowNum+",0"] = numSlot;
		jointCell[rowNum+",1"] = "Slot joint x 2 DOF";
		jointCell[rowNum+",2"] = "=";
		numSlotDOF = 2 * numSlot;
		jointCell[rowNum+",3"] = "-" + numSlotDOF;
		rowNum++;
	}
	
	if(numCylindrical)
	{
		jointCell[rowNum+",0"] = numCylindrical;
		jointCell[rowNum+",1"] = "Cylindrical joint x 4 DOF";
		jointCell[rowNum+",2"] = "=";
		numCylindricalDOF = 4 * numCylindrical;
		jointCell[rowNum+",3"] = "-" + numCylindricalDOF;
		rowNum++;
	}

	if(numUniversal)
	{
		jointCell[rowNum+",0"] = numUniversal;
		jointCell[rowNum+",1"] = "Universal joint x 4 DOF";
		jointCell[rowNum+",2"] = "=";
		numUniversalDOF = 4 * numUniversal;
		jointCell[rowNum+",3"] = "-" + numUniversalDOF;
		rowNum++;
	}

	if(numSpherical)
	{
		jointCell[rowNum+",0"] = numSpherical;
		jointCell[rowNum+",1"] = "Spherical joint x 3 DOF";
		jointCell[rowNum+",2"] = "=";
		numSphericalDOF = 3 * numSpherical;
		jointCell[rowNum+",3"] = "-" + numSphericalDOF;
		rowNum++;
	}

	if(numPlanar)
	{
		jointCell[rowNum+",0"] = numPlanar;
		jointCell[rowNum+",1"] = "Planar joint x 3 DOF";
		jointCell[rowNum+",2"] = "=";
		numPlanarDOF = 3 * numPlanar;
		jointCell[rowNum+",3"] = "-" + numPlanarDOF;
		rowNum++;
	}

	if(numGeneral && numGeneralDOF)
	{
		jointCell[rowNum+",0"] = numGeneral;
		jointCell[rowNum+",1"] = "General joint";
		jointCell[rowNum+",2"] = "=";
		jointCell[rowNum+",3"] = "-" + numGeneralDOF;
		rowNum++;
	}

    if (num3DRadial && num3DRadialDOF) {
        jointCell[rowNum + ",0"] = num3DRadial;
        jointCell[rowNum + ",1"] = "3D Radial joint";
        jointCell[rowNum + ",2"] = "=";
        jointCell[rowNum + ",3"] = "-" + num3DRadialDOF;
        rowNum++;
    }

	if(0 == rowNum)
	{
		// Do not display the DOF checker title
		jointDOFChecker.style.display = "none";
		return;
	}

	// Insert a blank row before printing the free DOF row
	jointCell[rowNum+",0"] = "";
	jointCell[rowNum+",1"] = "";
	jointCell[rowNum+",2"] = "";
	jointCell[rowNum+",3"] = "";
	rowNum++;

	var freeDOF = new Array;
	freeDOF[0] = "";
	freeDOF[1] = "Free DOF";
	freeDOF[2] = "=";
	
	var remainDOF = numBodyDOF - numFixedDOF - numRevoluteDOF - numTranslationalDOF - numSlotDOF -
					numCylindricalDOF - numUniversalDOF - numSphericalDOF - numPlanarDOF - numGeneralDOF - num3DRadialDOF;

	if(remainDOF > 0)
		freeDOF[3] = "+" + remainDOF + " DOF";
	else if(remainDOF < 0)
		freeDOF[3] = remainDOF + " DOF";
	else if(remainDOF == 0)
		freeDOF[3] = "0 DOF";

	if(remainDOF <= 0)
	{
		// Set the innerText of the caption and position it at the bottom of the table.
		oTable.appendChild(oCaption);
		oCaption.innerText = "Warning: "
		oCaption.style.fontSize = "12";
		oCaption.style.color = "red";
		oCaption.align = "bottom";
		
		oTable.appendChild(oCaption2);
		oCaption2.innerText = "This model is possibly over constrained. Consider modifying joint definitions."
		oCaption2.style.fontSize = "12";
		oCaption2.align = "bottom";
	}

	oTable.appendChild(oCaption3);
	oCaption3.innerText = stringTable.String("ID_ConnectionWorksheetUseRedundancy");
	oCaption3.style.fontSize = "12";
	oCaption3.style.color = "red";
	oCaption3.align = "bottom";
	
	// Insert the created elements into oTable and set the font size.
	oTable.appendChild(oTBody);
	oTable.appendChild(oTBody2);
	oTable.style.fontSize = "12";
	oTBody2.style.fontWeight = 600;
	oTable.style.fontFamily = "Arial"

	// Insert a row for body DOF
	oRow = document.createElement("TR");
	oTBody.appendChild(oRow);

	// Create and insert cells into the body row.
	for(i = 0; i < colNum; i++)
	{
		oCell = document.createElement("TD");
		oCell.innerText = body[i];
		oRow.appendChild(oCell);
	}

	// Create and insert rows and cells into the joint rows
	for(i = 0; i < rowNum; i++)
	{
		oRow = document.createElement("TR");
		oTBody.appendChild(oRow);
		for(j = 0; j < colNum; j++)
		{
			oCell = document.createElement("TD");
			oCell.innerText = jointCell[i + "," + j];
			oRow.appendChild(oCell);
		}
	}

	// Insert a row for free DOF
	oRow = document.createElement("TR");
	oTBody2.appendChild(oRow);

	// Create and insert cells into the body row.
	for(i = 0; i < colNum; i++)
	{
		oCell = document.createElement("TD");
		oCell.innerText = freeDOF[i];
		oRow.appendChild(oCell);
	}
}

function refreshPage()
{
    setList();
}

function ResizeGrid1Lists()
{
    var totalHeightGrid1 = 0;
    var rowCount = DataGrid1.RowsCount;
    for (var i=1; i<=rowCount; i++)
    {
        totalHeightGrid1 += DataGrid1.RowHeight(i);
    }

    // Sami Sangili advised not to use ExpandColumnsToFit with data grid for a table with many columns.
    // Use AutoSize instead (kfp 10-20-2011).

    DataGrid1.style.height = totalHeightGrid1 + 20;

    if(columWidthsClass.Contact_FirstVisit == true || ds.AppletMode == "idMeshing" )
        DataGrid1.AutoSize();
    else
    {
        DataGrid1.AutoSize();
        
        // Use the saved widths
        for(var idx=1; idx<=DataGrid1.ColumnsCount; idx++)
        {
            var curCell = DataGrid1.Cell(1, idx); //(row,col)
            switch(curCell.Tag)
            {
                case "Name":
                    if(columWidthsClass.Contact_Name_Width > 0)
                        DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_Name_Width;
                    break;
                case "Type":
                    if(columWidthsClass.Contact_Type_Width > 0)
                        DataGrid1.ColumnWidth(idx) =  columWidthsClass.Contact_Type_Width;
                    break;
                case "Scope":
                    if(columWidthsClass.Contact_ScopeGroup_Width > 0)
                        DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ScopeGroup_Width;
                    break;
                case "FrictionCoefficient":
                    if(columWidthsClass.Contact_ContactFrictionCoefficient_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactFrictionCoefficient_Width;
                    break;
                case "ScopeMode":
                    if(columWidthsClass.Contact_ContactMode_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactMode_Width;
                    break;
                case "TrimContact":
                    if(columWidthsClass.Contact_ContactTrim_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactTrim_Width;
                    break;
                case "Behavior":
                    if(columWidthsClass.Contact_Behavior_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_Behavior_Width;
                    break;
                case "NormalStiffness":
                    if(columWidthsClass.Contact_ContactNormalStiffness_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactNormalStiffness_Width;
                    break;
                case "UpdateStiffness":
                    if(columWidthsClass.Contact_ContactRegionUpdateContactStiffness_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionUpdateContactStiffness_Width;
                    break;
                case "Status":
                    if(columWidthsClass.Contact_VariableStatus_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_VariableStatus_Width;
                    break;
                case "Formulation":
                    if(columWidthsClass.Contact_ContactRegionContactFormulation_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionContactFormulation_Width;
                    break;
                case "InterfaceTreatment":
                    if(columWidthsClass.Contact_ContactRegionInitialEffect_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionInitialEffect_Width;
                    break;
                case "Offset":
                    if(columWidthsClass.Contact_ContactRegionUserOffset_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionUserOffset_Width;
                    break;
                case "ThermalConductance":
                    if(columWidthsClass.Contact_ContactRegionThermalConductance_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionThermalConductance_Width;
                    break;
                case "ElectricConductance":
                    if(columWidthsClass.Contact_ContactRegionElectricConductance_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionElectricConductance_Width;
                    break;
                case "PinballRegion":
                    if(columWidthsClass.Contact_ContactPinballRegion_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactPinballRegion_Width;
                    break;
                case "PinballRadius":
                    if(columWidthsClass.Contact_ContactPinballRadius_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactPinballRadius_Width;
                    break;
                case "PinballFactor":
                    if(columWidthsClass.Contact_ContactPinballFactor_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactPinballFactor_Width;
                    break;
                case "ConstraintType":
                    if(columWidthsClass.Contact_ContactRegionConstrainType_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionConstrainType_Width;
                    break;
                case "TimeStepControls":
                    if(columWidthsClass.Contact_ContactRegionTimeStepControl_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionTimeStepControl_Width;
                    break;
                case "DampingFactor":
                    if(columWidthsClass.Contact_ContactRegionDampingFactor_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionDampingFactor_Width;
                    break; 
                case "DetectionMethod":
                    if(columWidthsClass.Contact_ContactRegionDetectionMethod_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionDetectionMethod_Width;
                    break; 
                case "PenetrationTolerance":
                    if(columWidthsClass.Contact_ContactRegionPenetrationTol_Width > 0)
                         DataGrid1.ColumnWidth(idx) = columWidthsClass.Contact_ContactRegionPenetrationTol_Width;
                    break; 
            }
        }
    }
}

function ResizeGrid2Lists()
{
    DataGrid2.AutoSize();
    var totalHeightGrid2 = 0;
    var rowCount = DataGrid2.RowsCount;
    for (var i=1; i<=rowCount; i++)
    {
        totalHeightGrid2 += DataGrid2.RowHeight(i);
    }
    
    DataGrid2.style.height = totalHeightGrid2 + 20;
}

function ResizeGrid3Lists()
{
    DataGrid3.AutoSize();
    var totalHeightGrid3 = 0;
    var rowCount3 = DataGrid3.RowsCount;
    for (var i = 1; i <= rowCount3; i++)
    {
        totalHeightGrid3 += DataGrid3.RowHeight(i);
    }
    
    DataGrid3.style.height = totalHeightGrid3 + 20;
}

function isPropertyPresent(propName)
{
    if(contactPropAcc)
    {
	    for(var i = 0; i < contactPropAcc.PropCount; i++)
	    {
		    var bsPropName = contactPropAcc.PropName(i);
		    if(propName == bsPropName)
			    return true;
	    }
	}
	return false;
}

function setVarsGrid1()
{
	//initially all are set to true
	bListOneShowName = true; bListOneShowType = true; bListOneShowScope = true; bListOneShowFrictionCoeff = true; bListOneShowMode = true; 
	bListOneShowBehavior = true; bListOneShowNormalStiff = true; bListOneShowUpdateStiffness = true; bListOneShowStatus = true; bListOneShowFormulation = true; 
	bListOneShowInitialEffect = true; bListOneShowUserOffset = true; bListOneShowThermalCond = true; bListOneShowElectricCond = true; bListOneShowPinballRegion = true; 
	bListOneShowPinballRadius = true; bListOneShowPinballFactor = true; bListOneShowConstraintType = true; bListOneShowTimeStepControl = true;
	bListOneShowTrim = true, bListOneShowDampingFactor = true, bListOneShowDetectionMethod = true, bListOneShowPenetrationTol = true;
	
	beta = prefObj.Preference("PID_Show_Beta_Options");
	if (!beta)
    	bListOneShowTrim = false;
	
	var settings = wb.GetLastFileName(ds.Script.str_GridSettingsContactFolder, "DSApplet");
	var widths = wb.GetLastFileName(ds.Script.str_GridColWidthContactFolder, "DSApplet");
	var widthNames = wb.GetLastFileName(ds.Script.str_GridColWidthNamesContactFolder, "DSApplet");
	if (obj.Parent.Is2DGeometry || obj.Parent.Parent.Is2DGeometry)
		is2DModel = true;

	if (settings.length != 0)
	{
		var settingsArray = settings.split(";");
		if( settingsArray.length == 23 )
		{
		    if( settingsArray[0] == "0" )
		        bListOneShowName = false;
		     
			if( settingsArray[1] == "0" )
			    bListOneShowType = false;
			
			if( settingsArray[2] == "0" )
			    bListOneShowScope = false;
			
			if( settingsArray[3] == "0" )
			    bListOneShowFrictionCoeff = false;

            if( settingsArray[4] == "0" )
            	bListOneShowMode = false;

			if( settingsArray[5] == "0" )
		        bListOneShowTrim = false;

			if( settingsArray[6] == "0" )
		        bListOneShowBehavior = false;
		     
			if( settingsArray[7] == "0" )
			    bListOneShowNormalStiff = false;
		     
			if( settingsArray[8] == "0" )
			    bListOneShowUpdateStiffness = false;
			
			if( settingsArray[9] == "0" )
			    bListOneShowStatus = false;
			
			if( settingsArray[10] == "0" )
			    bListOneShowFormulation = false;

            if( settingsArray[11] == "0" )
            	bListOneShowInitialEffect = false;

			if( settingsArray[12] == "0" )
		        bListOneShowUserOffset = false;
		     
			if( settingsArray[13] == "0" )
			    bListOneShowThermalCond = false;
		     
			if( settingsArray[14] == "0" )
			    bListOneShowElectricCond = false;
			
			if( settingsArray[15] == "0" )
			    bListOneShowPinballRegion = false;
			
			if( settingsArray[16] == "0" )
			    bListOneShowPinballRadius = false;

            if( settingsArray[17] == "0" )
            	bListOneShowPinballFactor = false;

			if( settingsArray[18] == "0" )
		        bListOneShowConstraintType = false;

			if( settingsArray[19] == "0" )
			    bListOneShowTimeStepControl = false;

			if (settingsArray[20] == "0")
			    bListOneShowDampingFactor = false;
		    
		    if (settingsArray[21] == "0")
			    bListOneShowDetectionMethod = false;

		    if (settingsArray[22] == "0")
			    bListOneShowPenetrationTol = false;
		}
	}			

	if (widths.length != 0 && widthNames.length != 0)
	{
	    var widthsArray = widths.split(";");
	    var namesArray = widthNames.split(";");
	    
	    if( namesArray.length == widthsArray.length)
	    {
	        for( var idx=0; idx<namesArray.length; idx++ )
	        {
	            switch(namesArray[idx])
	            {
                case "Name":
                    columWidthsClass.Contact_Name_Width = widthsArray[idx];
                    break;
                case "Type":
                    columWidthsClass.Contact_Type_Width = widthsArray[idx];
                    break;
                case "Scope":
                    columWidthsClass.Contact_ScopeGroup_Width = widthsArray[idx];
                    break;
                case "FrictionCoefficient":
                    columWidthsClass.Contact_ContactFrictionCoefficient_Width = widthsArray[idx];
                    break;
                case "ScopeMode":
                    columWidthsClass.Contact_ContactMode_Width = widthsArray[idx];
                    break;
                case "TrimContact":
                    columWidthsClass.Contact_ContactTrim_Width = widthsArray[idx];
                    break;
                case "Behavior":
                    columWidthsClass.Contact_Behavior_Width = widthsArray[idx];
                    break;
                case "NormalStiffness":
                    columWidthsClass.Contact_ContactNormalStiffness_Width = widthsArray[idx];
                    break;
                case "UpdateStiffness":
                    columWidthsClass.Contact_ContactRegionUpdateContactStiffness_Width = widthsArray[idx];
                    break;
                case "Status":
                    columWidthsClass.Contact_VariableStatus_Width = widthsArray[idx];
                    break;
                case "Formulation":
                    columWidthsClass.Contact_ContactRegionContactFormulation_Width = widthsArray[idx];
                    break;
                case "InterfaceTreatment":
                    columWidthsClass.Contact_ContactRegionInitialEffect_Width = widthsArray[idx];
                    break;
                case "Offset":
                    columWidthsClass.Contact_ContactRegionUserOffset_Width = widthsArray[idx];
                    break;
                case "ThermalConductance":
                    columWidthsClass.Contact_ContactRegionThermalConductance_Width = widthsArray[idx];
                    break;
                case "ElectricConductance":
                    columWidthsClass.Contact_ContactRegionElectricConductance_Width = widthsArray[idx];
                    break;               
                case "PinballRegion":
                    columWidthsClass.Contact_ContactPinballRegion_Width = widthsArray[idx];
                    break;
                case "PinballRadius":
                    columWidthsClass.Contact_ContactPinballRadius_Width = widthsArray[idx];
                    break;
                case "PinballFactor":
                    columWidthsClass.Contact_ContactPinballFactor_Width = widthsArray[idx];
                    break;
                case "ConstraintType":
                    columWidthsClass.Contact_ContactRegionConstrainType_Width = widthsArray[idx];
                    break;
                case "TimeStepControls":
                    columWidthsClass.Contact_ContactRegionTimeStepControl_Width = widthsArray[idx];
                    break;
                case "DampingFactor":
                    columWidthsClass.Contact_ContactRegionDampingFactor_Width = widthsArray[idx];
                    break;
                case "DetectionMethod":
                    columWidthsClass.Contact_ContactRegionDetectionMethod_Width = widthsArray[idx];
                    break;
                case "PenetrationTolerance":
                    columWidthsClass.Contact_ContactRegionPenetrationTol_Width = widthsArray[idx];
                    break;
	            }
	        }
	    }
        columWidthsClass.Contact_FirstVisit = false;
    }
    else
        columWidthsClass.Contact_FirstVisit = true;
    
	if (!beta)
    	bListOneShowTrim = false;

    var contactRegions = obj.ContactRegions;			
	var count = contactRegions.count;
	for(var i = 1; i <= count; i++)
	{
        if(contactPropAcc)
        {
            contactPropAcc.Object = contactRegions(i);

            for(var j = 0; j < contactPropAcc.PropCount; j++)
            {
                var propertyName = contactPropAcc.PropName(j);
                switch(propertyName)
                {
                    case "UserOffset":
                        hasOffset = true;
                        break;
                    case "FrictionCoeff":
                        hasFrictionalRegion = true;
                        break;
                    case "PinballFactor":
                        hasPinballFactor = true;
                        break;
                    case "PinballRadius":
                        hasPinballRadius = true;
                        break;
                    case "ConstraintType":
                        hasConstraintType = true;
                        break;
                    case "InitialEffect":
                        hasInitialEffect = true;
                        break;
                    case "SymmetricContact":
                        hasBehavior = true;
                        break;
                    case "UseAutoNormalStiffness":
                        hasNormalStiff = true;
                        break;
                    case "UpdateContactStiffness":
                        hasUpdateStiffness = true;
                        break;
                    case "UseAutoThermalConductance":
                        hasThermalCond = true;
                        break;
                    case "UseAutoElectricConductance":
                        hasElectricCond = true;
                        break;               
                    case "TimeStepControl":
                        hasTimeStepControl = true;
                        break;
                    case "DampingFactor":
                        hasDampingFactor = true;
                        break;
                    case "DetectionMethod":
                        hasDetectionMethod = true;
                        break;
                    case "UseAutoPenetrationTolerance":
                        hasPenetrationTol = true;
                        break;
                }
            }
        }

        contactPropAcc.Clear();
	}
}

function setVarsGrid3()
{
    var meshConnectionObjs = obj.MeshConnections;
    for(var i = 1; i <= meshConnectionObjs.count; i++)
    {
        var curMeshConObj = meshConnectionObjs(i);
        if(ds.Script.id_AutomaticContact == curMeshConObj.Mode)
            autoModeCount++;
        else
            manualModeCount++;

        if(ds.Script.id_ToleranceSlider == curMeshConObj.ToleranceType)
            sliderTolCount++;
        else if(ds.Script.id_ToleranceValue == curMeshConObj.ToleranceType)
            valueTolCount++;
        else if(ds.Script.id_ToleranceSheetThickness == curMeshConObj.ToleranceType)
            thicknessTolCount++;
    }
}

function setListProps()
{
	DataGrid1.Font.Name = stringTable.String("ID_VSFlexGridTahoma");
	DataGrid1.Font.Size = 8.25;
	DataGrid1.ListMode = true;
    DataGrid1.FixedRowsCount = 1;
    DataGrid1.FixedColumnsCount = 0;
    DataGrid1.BorderStyle = ccFixedSingle;

	DataGrid2.Font.Name = stringTable.String("ID_VSFlexGridTahoma");
	DataGrid2.Font.Size = 8.25;
	DataGrid2.ListMode = true;
    DataGrid2.FixedRowsCount = 1;
    DataGrid2.FixedColumnsCount = 0;
    DataGrid2.BorderStyle = ccFixedSingle;

	DataGrid3.Font.Name = stringTable.String("ID_VSFlexGridTahoma");
	DataGrid3.Font.Size = 8.25;
	DataGrid3.ListMode = true;
    DataGrid3.FixedRowsCount = 1;
    DataGrid3.FixedColumnsCount = 0;
    DataGrid3.BorderStyle = ccFixedSingle;
}

function setColumnHeadersGrid1()
{
    var bMeshingMode = (ds.AppletMode == "idMeshing");

    DataGrid1.ColumnsCount = 0;
    var indexRow=1;
    var indexCol=1;
        
	if( bListOneShowName )
	{
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_NameProperty");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Name";
        cell.Editable = false; indexCol++;
    }
 	if( bListOneShowType && !bMeshingMode )
 	{
	    DataGrid1.ColumnsCount++;
        var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_TypeProperty");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Type";
        cell.Editable = false; indexCol++;
	}
    if( bListOneShowScope )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ScopeGroup");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Scope";
        cell.Editable = false; indexCol++;
	}
    if(true == hasFrictionalRegion && bListOneShowFrictionCoeff && !bMeshingMode)
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactFrictionCoefficient");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "FrictionCoefficient";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowMode && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactModeProperty");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ScopeMode";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowTrim && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactTrimProperty");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "TrimContact";
        cell.Editable = false; indexCol++;
    }		    
    if( bListOneShowBehavior && hasBehavior && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_Behavior");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Behavior";
        cell.Editable = false; indexCol++;
    }		    
    if( bListOneShowNormalStiff && hasNormalStiff && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactNormalStiffness");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "NormalStiffness";
        cell.Editable = false; indexCol++;
    }	
    if( bListOneShowUpdateStiffness && hasUpdateStiffness && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionUpdateContactStiffness");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "UpdateStiffness";
        cell.Editable = false; indexCol++;
    }	
    if( bListOneShowStatus && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_VariableStatus");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Status";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowFormulation && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionContactFormulation");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Formulation";
        cell.Editable = false; indexCol++;
    }
    if (bListOneShowDetectionMethod && hasDetectionMethod && !bMeshingMode) {
        DataGrid1.ColumnsCount++;
        var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionDetectionMethod");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "DetectionMethod";
        cell.Editable = false; indexCol++;
    }
    if (bListOneShowPenetrationTol && hasPenetrationTol && !bMeshingMode) {
        DataGrid1.ColumnsCount++;
        var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionPenetrationTolerance");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "PenetrationTolerance";
        cell.Editable = false; indexCol++;
    }		
    if( hasInitialEffect && bListOneShowInitialEffect && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionInitialEffect");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "InterfaceTreatment";
        cell.Editable = false; indexCol++;
    }
    if( true == hasOffset && bListOneShowUserOffset )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionUserOffset") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utLENGTH) + ")";
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Offset";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowThermalCond && hasThermalCond && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionThermalConductance") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utFILM_COEFF) + ")";
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ThermalConductance";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowElectricCond && hasElectricCond && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionElectricConductance") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utELECTRIC_CONDUCTANCE_PER_UNIT_AREA) + ")";
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ElectricConductance";
        cell.Editable = false; indexCol++;
    }
    if (bListOneShowDampingFactor && hasDampingFactor && !bMeshingMode) 
    {
        DataGrid1.ColumnsCount++;
        var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactRegionDampingFactor");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "Damping";
        cell.Editable = false; indexCol++;
    }
    if( bListOneShowPinballRegion && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactPinballRegion");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "PinballRegion";
        cell.Editable = false; indexCol++;
    }
    if( true == hasPinballRadius && bListOneShowPinballRadius && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactPinballRadius") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utLENGTH) + ")";
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "PinballRadius";
        cell.Editable = false; indexCol++;
    }
    if( true == hasPinballFactor && bListOneShowPinballFactor && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ContactPinballFactor");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "PinballFactor";
        cell.Editable = false; indexCol++;
    }
    if( true == hasConstraintType && bListOneShowConstraintType && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ConstraintType");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ConstraintType";
        cell.Editable = false; indexCol++;
    }
    if( true == hasTimeStepControl && bListOneShowTimeStepControl && !bMeshingMode )
    {
	    DataGrid1.ColumnsCount++;
	    var cell = DataGrid1.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_TimeStepControls");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "TimeStepControls";
        cell.Editable = false; indexCol++;
    }
    
	for(var i=1; i<=DataGrid1.ColumnsCount ; i++)
	{
		sortArr[i] = descending;	
	}
}

function setColumnHeadersGrid2()
{
    var columnCount = 5;
    DataGrid2.ColumnsCount = columnCount;
    var indexRow = 1;
    var indexCol = 1;
    
    var cell = DataGrid2.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_NameProperty");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Name";
    cell.Editable = false; indexCol++;
        
    cell = DataGrid2.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_TypeProperty");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Type";
    cell.Editable = false; indexCol++;
    
    cell = DataGrid2.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_ScopeGroup");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Scope";
    cell.Editable = false; indexCol++;
    
    cell = DataGrid2.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_VariableStatus");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Status";
    cell.Editable = false; indexCol++;
    
    cell = DataGrid2.Cell(indexRow, indexCol);
    cell.Text = "";
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Empty";
    cell.Editable = false; indexCol++;
}

function setColumnHeadersGrid3()
{
    DataGrid3.ColumnsCount = 4;
    var indexRow = 1;
    var indexCol = 1;

    var cell = DataGrid3.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_NameProperty");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Name";
    cell.Editable = false; indexCol++;

    cell = DataGrid3.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_ScopeGroup");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Scope";
    cell.Editable = false; indexCol++;

    cell = DataGrid3.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_ContactModeProperty");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "ScopeMode";
    cell.Editable = false; indexCol++;

    cell = DataGrid3.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_VariableStatus");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "Status";
    cell.Editable = false; indexCol++;

    DataGrid3.ColumnsCount++;
    cell = DataGrid3.Cell(indexRow, indexCol);
    cell.Text = stringTable.string("ID_ToleranceType");
    cell.HorizontalTextAlignment = TE_HTA_LEFT;
    cell.Tag = "ToleranceType";
    cell.Editable = false; indexCol++;
    
    if(sliderTolCount > 0)
    {
        DataGrid3.ColumnsCount++;
        cell = DataGrid3.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ToleranceSlider");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ToleranceSlider";
        cell.Editable = false; indexCol++;
    }

    if(sliderTolCount > 0 || valueTolCount > 0)
    {
        DataGrid3.ColumnsCount++;
        cell = DataGrid3.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ToleranceValue") + " (" + ds.UnitSystem.UnitString(ds.Script.id_utLENGTH) + ")";
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ToleranceValue";
        cell.Editable = false; indexCol++;
    }

    if(thicknessTolCount > 0)
    {
        DataGrid3.ColumnsCount++;
        cell = DataGrid3.Cell(indexRow, indexCol);
        cell.Text = stringTable.string("ID_ThicknessScaleFactor");
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Tag = "ThicknessScaleFactor";
        cell.Editable = false; indexCol++;
    }
}

function addGrid1Items()
{		
    var contacts = obj.ContactRegions;
    var indexRow = 1;
	var nContacts = contacts.Count;
	DataGrid1.RowsCount = nContacts + 1; //+1 for the column headers

    if (nContacts == 0)//if no contact regions exist then hide the table
    {
        DataGrid1.style.display = "none";
        contactTableTitle.style.display = "none";
        contactTableFlag = false;
        return;
    }

    contactTableFlag = true;
    DataGrid1.style.display = "";
    contactTableTitle.style.display = "";

    var bMeshingMode = (ds.AppletMode == "idMeshing");

	for(var idx=1; idx <= nContacts; idx++)
	{
		curItem = contacts(idx);		
        indexRow++; //work with the newly added row
        var indexCol = 1;
        var cell;
        contactPropAcc.Object = curItem;

		if( bListOneShowName )
		{
		    cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = curItem.Name;
            cell.Tag = curItem.ID;
            cell.Editable = false; indexCol++;	
        }
        
		if( bListOneShowType && !bMeshingMode )
		{
			var typeStr = getTypeString(curItem);
		    cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = typeStr;
            cell.Editable = false; indexCol++;	
		}
		
		if( bListOneShowScope )
		{
			var scopeString = createContactScopeString(curItem);
		    cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = scopeString;
            cell.Editable = false; indexCol++;	
		}
		
 		if( true == hasFrictionalRegion && bListOneShowFrictionCoeff && !bMeshingMode )
		{
			var coeff;
			if(curItem.ContactType == ds.Script.id_FrictionalContact)
				coeff = curItem.FrictionCoeff;
			else
				coeff = stringTable.String("ID_NotApplicable");;
			
		    cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = coeff;
            cell.Editable = false; indexCol++;	
		}     
		  
		if( bListOneShowMode && !bMeshingMode )
		{
			var modeStr = stringTable.String("ID_NotApplicable");
			modeStr = getModeString(curItem);
		    
		    cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = modeStr;
            cell.Editable = false; indexCol++;				
		}
		
		if( bListOneShowTrim && !bMeshingMode )
		{		 
			var	trimStr = getTrimString(curItem);
			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = trimStr;
            cell.Editable = false; indexCol++;	
		}
		
		if( hasBehavior && bListOneShowBehavior && !bMeshingMode )
		{
			var behaviorString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("SymmetricContact"))
            {
				if(curItem.SymmetricContact == ds.Script.id_Asymmetric)
					behaviorString = stringTable.String("ID_Asymmetric");
				else if(curItem.SymmetricContact == ds.Script.id_Symmetric)
					behaviorString = stringTable.String("ID_Symmetric");
				else if(curItem.SymmetricContact == ds.Script.id_AutoAsymmetric)
				    behaviorString = stringTable.String("ID_AutoAsymmetric");
				else if (curItem.SymmetricContact == ds.Script.id_SymmetricContactProgramControlled)
				    behaviorString = stringTable.String("ID_ProgramControlled");
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = behaviorString;
            cell.Editable = false; indexCol++;
		}	
		
		if( hasNormalStiff && bListOneShowNormalStiff && !bMeshingMode )
		{
			var normalStiffnessStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UseAutoNormalStiffness"))
            {
                if(true == curItem.UseAutoNormalStiffness)
				    normalStiffnessStr = stringTable.String("ID_SolverTypeProgramChooses");
				else
				    normalStiffnessStr = helper.GetFixedLengthFormat(curItem.NormalStiffness, sigDigits);
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = normalStiffnessStr;
            cell.Editable = false; indexCol++;
		}  
		  
		if( hasUpdateStiffness && bListOneShowUpdateStiffness && !bMeshingMode )
		{
			var updateStiffnessStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UpdateContactStiffness"))
            {
                if (curItem.UpdateContactStiffness == ds.Script.id_UpdateStiffnessProgramControlled)
			        updateStiffnessStr = stringTable.String("ID_ProgramControlled");
			    else if(curItem.UpdateContactStiffness == ds.Script.id_Never)
				    updateStiffnessStr = stringTable.String("ID_ContactRegionNever");
			    else if(curItem.UpdateContactStiffness == ds.Script.id_EachEquilibriumIteration)
				    updateStiffnessStr = stringTable.String("ID_ContactRegionEachEquilibriumIteration");
			    else if(curItem.UpdateContactStiffness == ds.Script.id_EachIterationAggressive)
				    updateStiffnessStr = stringTable.String("ID_EachIterationAggressive");
			    else if(curItem.UpdateContactStiffness == ds.Script.id_EachSubstep)
				    updateStiffnessStr = stringTable.String("ID_ContactRegionEachSubstep");
	        }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = updateStiffnessStr;
            cell.Editable = false; indexCol++;
		}   
		 
		if( bListOneShowStatus && !bMeshingMode )
		{
			if(curItem.SuppressedForSolve == true)
				supStr = stringTable.String("ID_SuppressedProperty");
			else
				supStr = stringTable.String("ID_NotSuppressed");

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = supStr;
            cell.Editable = false; indexCol++;
		}
			
		if( bListOneShowFormulation && !bMeshingMode )
		{
			var formulationString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("ContactFormulation"))
            {
                if (curItem.ContactFormulation == ds.Script.id_AugmentedLagrange)
			        formulationString = stringTable.String("ID_ContactRegionAugmentedLagrange");
			    else if (curItem.ContactFormulation == ds.Script.id_PurePenalty)
			        formulationString = stringTable.String("ID_ContactRegionPurePenalty");
			    else if (curItem.ContactFormulation == ds.Script.id_MPC)
			        formulationString = stringTable.String("ID_ContactRegionMPC");
			    else if (curItem.ContactFormulation == ds.Script.id_LaGrange)
			        formulationString = stringTable.String("ID_ContactRegionLaGrange");
			    else if (curItem.ContactFormulation == ds.Script.id_FormulationProgramControlled)
			        formulationString = stringTable.String("ID_ProgramControlled");
			    else
			        formulationString = stringTable.String("ID_Beam");
			}

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = formulationString;
            cell.Editable = false; indexCol++;
        }

        if (bListOneShowDetectionMethod && hasDetectionMethod && !bMeshingMode)
        {
            var detectionMethodString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("DetectionMethod"))
            {
                if (curItem.DetectionMethod == ds.Script.id_DetectProgramControlled)
                    detectionMethodString = stringTable.String("ID_ProgramControlled");
                else if (curItem.DetectionMethod == ds.Script.id_DetectOnGaussPoint)
                    detectionMethodString = stringTable.String("ID_ContactRegionOnGaussPoint");
                else if (curItem.DetectionMethod == ds.Script.id_DetectNodalNormalFromContact)
                    detectionMethodString = stringTable.String("ID_ContactRegionNodalNormalFromContact");
                else if (curItem.DetectionMethod == ds.Script.id_DetectNodalNormalToTarget)
                    detectionMethodString = stringTable.String("ID_ContactRegionNodalNormalToTarget");
                else 
                    detectionMethodString = stringTable.String("ID_ContactRegionNodalProjectedNormalFromContact");
            }

            cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;
            cell.Text = detectionMethodString;
            cell.Editable = false;
            indexCol++;
        }

        if (hasPenetrationTol && bListOneShowPenetrationTol && !bMeshingMode)
        {
            var penetrationTolString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UseAutoPenetrationTolerance"))
            {
                if(curItem.UseAutoPenetrationTolerance == ds.Script.id_PenetrationToleranceProgramControlled)
                    penetrationTolString = stringTable.String("ID_ProgramControlled");
                else if(curItem.UseAutoPenetrationTolerance == ds.Script.id_PenetrationToleranceManual)
                    penetrationTolString = helper.GetFixedLengthFormat(curItem.PenetrationTolerance, sigDigits);
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = penetrationTolString;
            cell.Editable = false;
            indexCol++;
        }

		if( hasInitialEffect && bListOneShowInitialEffect && !bMeshingMode )
		{
			var initialEffectString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("InitialEffect"))
            {
                if(curItem.InitialEffect == ds.Script.id_IncludeGapPeneOffset)
				    initialEffectString = stringTable.String("ID_ContactRegionOffsetRampedEffects");
			    else if(curItem.InitialEffect == ds.Script.id_IncludeNone)
				    initialEffectString = stringTable.String("ID_ContactRegionAdjustedToTouch");
			    else
				    initialEffectString = stringTable.String("ID_ContactRegionOffsetNoRamping");
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = initialEffectString;
            cell.Editable = false; indexCol++;
		}	
		
		if( true == hasOffset && bListOneShowUserOffset && !bMeshingMode )
		{
			var offsetString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UserOffset"))
				offsetString = helper.GetFixedLengthFormat(curItem.UserOffset, sigDigits);

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = offsetString;
            cell.Editable = false; indexCol++;		
		}
		
		if( hasThermalCond && bListOneShowThermalCond && !bMeshingMode )
		{
			var thermalConductanceStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UseAutoThermalConductance"))
            {
                if(true == curItem.UseAutoThermalConductance)
				    thermalConductanceStr = stringTable.String("ID_SolverTypeProgramChooses");
			    else
				    thermalConductanceStr = helper.GetFixedLengthFormat(curItem.ThermalConductance, sigDigits);
		    }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = thermalConductanceStr;
            cell.Editable = false; indexCol++;	
		}

		if( hasElectricCond && bListOneShowElectricCond && !bMeshingMode )
		{
			var electricConductanceStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("UseAutoElectricConductance"))
            {
                if(true == curItem.UseAutoElectricConductance)
				    electricConductanceStr = stringTable.String("ID_SolverTypeProgramChooses");
			    else
				    electricConductanceStr = helper.GetFixedLengthFormat(curItem.ElectricConductance, sigDigits);
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = electricConductanceStr;
            cell.Editable = false; indexCol++;
        }

        if (bListOneShowDampingFactor && hasDampingFactor && !bMeshingMode)
        {
            var dampingFactorString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("DampingFactor"))
                dampingFactorString = curItem.DampingFactor;

            cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;
            cell.Text = dampingFactorString;
            cell.Editable = false; indexCol++;
        }

		if( bListOneShowPinballRegion && !bMeshingMode )
		{
			var pinballRegionStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("PinballType"))
            {
                if( curItem.PinballType == ds.Script.id_PinballProgramControlled )
				    pinballRegionStr = stringTable.String("ID_ProgramControlled");
			    else if( curItem.PinballType == ds.Script.id_PinballAutoDetectionValue )
				    pinballRegionStr = stringTable.String("ID_ContactAutoDetectionValue");
			    else if( curItem.PinballType == ds.Script.id_PinballFactor )
				    pinballRegionStr = stringTable.String("ID_ContactFactor");
			    else
				    pinballRegionStr = stringTable.String("ID_ContactRadius");
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = pinballRegionStr;
            cell.Editable = false; indexCol++;
		}

		if( true == hasPinballRadius && bListOneShowPinballRadius && !bMeshingMode )
		{
			var pinballRadiusStr = stringTable.String("ID_NotApplicable");			
            if(isPropertyPresent("PinballRadius"))
				pinballRadiusStr = helper.GetFixedLengthFormat(curItem.PinballRadius, sigDigits);

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = pinballRadiusStr;
            cell.Editable = false; indexCol++;
		}
		
		if( true == hasPinballFactor && bListOneShowPinballFactor && !bMeshingMode )
		{
			var pinballFactorStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("PinballFactor"))
				pinballFactorStr = helper.GetFixedLengthFormat(curItem.PinballFactor, sigDigits);

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = pinballFactorStr;
            cell.Editable = false; indexCol++;
		}

		if( true == hasConstraintType && bListOneShowConstraintType && !bMeshingMode )
		{
			var searchDirStr = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("ConstraintType"))
            {
				if(ds.Script.id_TargetNormalCoupleUtoROT == curItem.ConstraintType)
					searchDirStr = stringTable.String("ID_ContactTargetNormalCoupleUtoROT");
				else if(ds.Script.id_InsidePinballCoupleUtoROT == curItem.ConstraintType)
					searchDirStr = stringTable.String("ID_ContactInsidePinballCoupleUtoROT");
				else if(ds.Script.id_TargetNormalUncoupleUtoROT == curItem.ConstraintType)
					searchDirStr = stringTable.String("ID_ContactTargetNormalUncoupleUtoROT");
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = searchDirStr;
            cell.Editable = false; indexCol++;
		}

		if( true == hasTimeStepControl && bListOneShowTimeStepControl && !bMeshingMode )
		{
			var TimeStepControlString = stringTable.String("ID_NotApplicable");
            if(isPropertyPresent("TimeStepControl"))
            {
                if(curItem.TimeStepControl == ds.Script.id_None)
				    TimeStepControlString = stringTable.String("ID_None");
			    else if(curItem.TimeStepControl == ds.Script.id_AutomaticBisection)
				    TimeStepControlString = stringTable.String("ID_AutomaticBisection");
			    else
				    TimeStepControlString = stringTable.String("ID_PredictForImpact");
            }

			cell = DataGrid1.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;			
            cell.Text = TimeStepControlString;
            cell.Editable = false; indexCol++;
		}	
	}
}

function addGrid2Items()
{
    var jointObjects = obj.Joints;
    var indexRow = 1;
	var nJoints = jointObjects.Count;
	DataGrid2.RowsCount = nJoints + 1; //+1 for the column headers

    if (nJoints == 0)//if no contact regions exist then hide the table
    {
        DataGrid2.style.display = "none";
        jointTableTitle.style.display = "none";
        return;
    }
    
    DataGrid2.style.display = "";
    jointTableTitle.style.display = "";

    var bMeshingMode = (ds.AppletMode == "idMeshing");

	for(var idx=1; idx <= nJoints; idx++)
	{
		var curJoint = jointObjects(idx);		
        indexRow++; //work with the newly added row
        var indexCol = 1;
        
        var cell = DataGrid2.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;			
        cell.Text = curJoint.Name;
        cell.Tag = curJoint.ID;
        cell.Editable = false; indexCol++;	
        
        var typeString = "";
        switch ( curJoint.JointType )
        {
            case ds.Script.id_FixedJoint:    
                typeString = stringTable.String("ID_JointFixed");
                break;               
            case ds.Script.id_RevoluteJoint:
                typeString = stringTable.String("ID_JointRevolute");
                break;
            case ds.Script.id_TranslationalJoint:
                typeString = stringTable.String("ID_JointTranslational");
                break;
            case ds.Script.id_SlotJoint:
                typeString = stringTable.String("ID_JointSlot");
                break;
            case ds.Script.id_CylindricalJoint:
                typeString = stringTable.String("ID_JointCylindrical");
                break;
            case ds.Script.id_UniversalJoint:
                typeString = stringTable.String("ID_JointUniversal");
                break;
            case ds.Script.id_SphericalJoint:
                typeString = stringTable.String("ID_JointSpherical");
                break;
            case ds.Script.id_PlanarJoint:
                typeString = stringTable.String("ID_JointPlanar");
                break;
            case ds.Script.id_GeneralJoint:
                typeString = stringTable.String("ID_JointGeneral");
                break;                
            case ds.Script.id_BushingJoint:
                typeString = stringTable.String("ID_Bushing");
                break;
            case ds.Script.id_PointOnCurveJoint:
                typeString = stringTable.String("ID_PointOnCurve");
                break;
            case ds.Script.id_PlaneRadialGapJoint:
                typeString = stringTable.String("ID_JointPlaneRadialGap");
                break;
            case ds.Script.id_SphericalGapJoint:
                typeString = stringTable.String("ID_JointSphericalGap");
                break;
            case ds.Script.id_3DRadialGap:
                typeString = stringTable("ID_Joint3DRadialGap");
                break;
            default:
                typeString = "";
                break;              
        }
        cell = DataGrid2.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;			
        cell.Text = typeString;
        cell.Tag = curJoint.ID;
        cell.Editable = false; indexCol++;
                
        var scopingTypeString = "";
        switch ( curJoint.JointScopingType )
        {
            case ds.Script.id_JointScopingTypeBodyToBody:    
                scopingTypeString = stringTable.String("ID_JointBodyScopingBody");
                break;               
            case ds.Script.id_JointScopingTypeBodyToGround:
                scopingTypeString = stringTable.String("ID_JointBodyScopingGround");
                break;
            default:
                scopingTypeString = "";
                break;              
        }
        cell = DataGrid2.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;			
        cell.Text = scopingTypeString;
        cell.Tag = curJoint.ID;
        cell.Editable = false; indexCol++;        

        var statusString = "";
        if(curJoint.SuppressedForSolve == true)
				statusString = stringTable.String("ID_SuppressedProperty");
			else
				statusString = stringTable.String("ID_NotSuppressed");
        cell = DataGrid2.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;			
        cell.Text = statusString;
        cell.Tag = curJoint.ID;
        cell.Editable = false; indexCol++;     

    }
}

function addGrid3Items()
{
    var meshConnectionObjs = obj.MeshConnections;
    var indexRow = 1;
	var nMeshConnections = meshConnectionObjs.Count;
	DataGrid3.RowsCount = nMeshConnections + 1; //+1 for the column headers

    if(nMeshConnections == 0) //if no mesh connection exist then hide the table
    {
        DataGrid3.style.display = "none";
        meshConnectionTableTitle.style.display = "none";
        return;
    }

    DataGrid3.style.display = "";
    meshConnectionTableTitle.style.display = "";

    var bMeshingMode = (ds.AppletMode == "idMeshing");

	for(var idx = 1; idx <= nMeshConnections; idx++)
	{
		var curMeshCon = meshConnectionObjs(idx);		
        indexRow++; //work with the newly added row
        var indexCol = 1;
        
        var cell = DataGrid3.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Text = curMeshCon.Name;
        cell.Tag = curMeshCon.ID;
        cell.Editable = false; indexCol++;

		var scopeString = createMeshConnectionScopeString(curMeshCon);
	    cell = DataGrid3.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Text = scopeString;
        cell.Editable = false; indexCol++;

		var modeStr = getModeString(curMeshCon);
	    cell = DataGrid3.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Text = modeStr;
        cell.Editable = false; indexCol++;	

        var statusString = "";
        if(curMeshCon.SuppressedForSolve == true)
			statusString = stringTable.String("ID_SuppressedProperty");
		else
			statusString = stringTable.String("ID_NotSuppressed");

        cell = DataGrid3.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Text = statusString;
        cell.Editable = false; indexCol++;

        var modeType = curMeshCon.Mode;
        var toleranceType = curMeshCon.ToleranceType;
        var tolTypeString = stringTable.String("ID_NotApplicable");
        if(ds.Script.id_ToleranceSlider == toleranceType)
            tolTypeString = stringTable.String("ID_Slider");
        else if(ds.Script.id_ToleranceValue == toleranceType)
            tolTypeString = stringTable.String("ID_Value");
        else
            tolTypeString = stringTable.String("ID_UseSheetThickness");
                    
        cell = DataGrid3.Cell(indexRow, indexCol);
        cell.HorizontalTextAlignment = TE_HTA_LEFT;
        cell.Text = tolTypeString;
        cell.Editable = false; indexCol++;

        if(sliderTolCount > 0)
        {
            var tolSliderString = stringTable.String("ID_NotApplicable");
            if(ds.Script.id_ToleranceSlider == toleranceType)
                tolSliderString = helper.GetFixedLengthFormat(curMeshCon.DetectionTolerance, sigDigits);

            cell = DataGrid3.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;
            cell.Text = tolSliderString;
            cell.Editable = false; indexCol++;
        }

        if(sliderTolCount > 0 || valueTolCount > 0)
        {
            var tolValueString = stringTable.String("ID_NotApplicable");
            if(ds.Script.id_ToleranceSlider == toleranceType || ds.Script.id_ToleranceValue == toleranceType)
                tolValueString = helper.GetFixedLengthFormat(curMeshCon.ToleranceValue, sigDigits);

            cell = DataGrid3.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;
            cell.Text = tolValueString;
            cell.Editable = false; indexCol++;
        }

        if(thicknessTolCount > 0)
        {
            var scaleFactorString = stringTable.String("ID_NotApplicable");
            if(ds.Script.id_ToleranceSheetThickness == toleranceType)
                scaleFactorString = helper.GetFixedLengthFormat(curMeshCon.ThicknessScaleFactor, sigDigits);

            cell = DataGrid3.Cell(indexRow, indexCol);
            cell.HorizontalTextAlignment = TE_HTA_LEFT;
            cell.Text = scaleFactorString;
            cell.Editable = false; indexCol++;
        }
    }
}

function createMeshConnectionScopeString(contactRegion)
{
	var scopeString = "";
	var masterType = contactRegion.MasterGeometryScopeType
	var slaveType = contactRegion.SlaveGeometryScopeType

	if(masterType == 0 || slaveType == 0)
		return scopeString ;

	if(masterType == ds.Script.id_ShellFace)
		scopeString = stringTable.String("ID_ContactGeometryShellFace");
	else if(masterType == ds.Script.id_ShellEdge)
		scopeString = stringTable.String("ID_ContactGeometryShellEdge");

	scopeString = scopeString + ", ";

	if(slaveType == ds.Script.id_ShellFace)
		scopeString = scopeString + stringTable.String("ID_ContactGeometryShellFace");
	else if(slaveType == ds.Script.id_ShellEdge)
		scopeString = scopeString + stringTable.String("ID_ContactGeometryShellEdge");

	return scopeString;
}

function getModeString(contact)
{
	var str = "";
	switch(contact.Mode)
	{
		case 0: //manual
			str = stringTable.String("ID_Manual");
			break;	
		case 1:	//automatic
			str = stringTable.String("ID_Automatic");
			break;
		default:
			str = "";
			break;
	}
	return str;
}

function getTrimString(contact)
{
	var str = "";
	switch(contact.TrimContact)
	{
		case 0: //manual
			str = stringTable.String("ID_ProgramControlled");
			break;	
		case 1:	//automatic
			str = stringTable.String("ID_On");
			break;
		case 2:	//automatic
			str = stringTable.String("ID_Off");
			break;
		default:
			str = "";
			break;
	}
	return str;
}

function getTypeString(contact)
{
	var str = "";
	switch(contact.ContactType)
	{
		case 1: //bonded
		    {
		        if( AreAllEnvironmentSolversMBD() )
			        str = stringTable.String("ID_ContactRegionBondedContact_Beta");
			    else
			        str = stringTable.String("ID_ContactRegionBondedContact");
			}
			break;	
		case 2:	//frictionless
			str = stringTable.String("ID_ContactRegionFrictionlessContact");
			break;
		case 3: //Frictional
			str = stringTable.String("ID_ContactRegionFrictionalContact");
			break;
		case 4:	//Rough
		    {
		        if( AreAllEnvironmentSolversMBD() )
			        str = stringTable.String("ID_ContactRegionRoughContact_Beta");
			    else
			        str = stringTable.String("ID_ContactRegionRoughContact");
			}
			break;
		case 5: //no separation
		    {
		        if( AreAllEnvironmentSolversMBD() )
			        str = stringTable.String("ID_ContactRegionNoSeperationContact_Beta");
			    else
			        str = stringTable.String("ID_ContactRegionNoSeperationContact");
			}
			break;
		case 6: //spot weld
			str = stringTable.String("ID_ContactSpotWeld");
			break;
		case 7: //general weld
			str = stringTable.String("ID_ContactGeneralWeld");
			break;
		default:
			str = "";
			break;
	}
	return str;
}		

function window_onunload()
{
	//save the column heading settings to the registry
	if(contactTableFlag)
	{
	    saveGridSettings();
	    contactTableFlag = false;
	}

	obj = null;
	
	if(ds && ds.GUIState && ds.GUIState.GUIDriver)
        ds.GUIState.GUIDriver.MenuListener.RemoveListener(3);

	if (cbGrid1DisplayContextMenu)
	{
		cbGrid1DisplayContextMenu.RemoveCOM(this, "Grid1_DisplayContextMenuDelegate");
		cbGrid1DisplayContextMenu = null;
	}

	if (cbDataGrid1RowClick)
	{
		cbDataGrid1RowClick.RemoveCOM(this, "WBDataGridCtrl1_RowClickDelegate");
		cbDataGrid1RowClick = null;
	}

	if (cbDataGrid2RowClick)
	{
		cbDataGrid2RowClick.RemoveCOM(this, "WBDataGridCtrl2_RowClickDelegate");
		cbDataGrid2RowClick = null;
	}
	
	if (cbGrid2DisplayContextMenu)
	{
		cbGrid2DisplayContextMenu.RemoveCOM(this, "Grid2_DisplayContextMenuDelegate");
		cbGrid2DisplayContextMenu = null;
	}

	if (cbDataGrid3RowClick)
	{
		cbDataGrid3RowClick.RemoveCOM(this, "WBDataGridCtrl3_RowClickDelegate");
		cbDataGrid3RowClick = null;
	}
	
	if (cbGrid3DisplayContextMenu)
	{
		cbGrid3DisplayContextMenu.RemoveCOM(this, "Grid3_DisplayContextMenuDelegate");
		cbGrid3DisplayContextMenu = null;
	}
	if(contactPropAcc)
	{
		contactPropAcc.Clear();
		contactPropAcc = null;
	}
}

function saveGridSettings()
{  
    if( ds.AppletMode == "idMeshing" )
        return;

    var widths = "";  var columnNames = "";
    for(var idx=1; idx<=DataGrid1.ColumnsCount; idx++)
    {
        var curCell = DataGrid1.Cell(1, idx); //(row,col)
        
        columnNames += curCell.Tag;
        widths += DataGrid1.ColumnWidth(idx);
        
        if( idx<DataGrid1.ColumnsCount ) 
        {
            columnNames += ";";
            widths += ";";
        }
    }

    var settings = "";

	if( bListOneShowName == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowType == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowScope == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
    if( bListOneShowFrictionCoeff == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowMode == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowTrim == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowBehavior == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowNormalStiff == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowUpdateStiffness == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowStatus == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
    if( bListOneShowFormulation == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowInitialEffect == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowUserOffset == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowThermalCond == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowElectricCond == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowPinballRegion == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
    if( bListOneShowPinballRadius == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowPinballFactor == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowConstraintType == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
  	if( bListOneShowTimeStepControl == true) 
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if (bListOneShowDampingFactor == true)
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowDetectionMethod == true)
	    settings += "1" + ";";
	else
	    settings += "0" + ";";
	if( bListOneShowPenetrationTol == true)
	    settings += "1";
	else
	    settings += "0";

	wb.PutLastFileName(ds.Script.str_GridSettingsContactFolder, settings, "DSApplet");
	wb.PutLastFileName(ds.Script.str_GridColWidthNamesContactFolder, columnNames, "DSApplet");
    wb.PutLastFileName(ds.Script.str_GridColWidthContactFolder, widths, "DSApplet");
}

function exportDataToFile( fileName )
{
	var fileText = createTextForFile();
	ds.Script.WriteTextInFile(fileName, fileText);
}

function createTextForFile()
{
    var fileText = "";
    
    var numRows = DataGrid1.RowsCount;
    var numCols = DataGrid1.ColumnsCount;
    
    var cell = DataGrid1.Cell(1,1);
    
    for( var iRow = 1; iRow <= numRows; iRow++ )
    {
        for( var iCol = 1; iCol <= numCols; iCol++ )
        {
           cell = DataGrid1.Cell(iRow, iCol);
           fileText += cell.Text;
           fileText += "\t";       
        }
        fileText += "\n";
    }
	
	fileText += "\n";
	fileText += "\n";
	    
	numRows = DataGrid2.RowsCount;
    numCols = DataGrid2.ColumnsCount;
    
    var cell = DataGrid2.Cell(1,1);
    
    for( var iRow = 1; iRow <= numRows; iRow++ )
    {
        for( var iCol = 1; iCol <= numCols; iCol++ )
        {
           cell = DataGrid2.Cell(iRow, iCol);
           fileText += cell.Text;
           fileText += "\t";       
        }
        fileText += "\n";
    }
       
    return fileText;
}

function createContactScopeString(contactRegion)
{
	var contactString = "";
	var sourceType = contactRegion.SourceGeometryScopeType
	var targetType = contactRegion.TargetGeometryScopeType

	if(sourceType == 0 || targetType == 0)
		return contactString ;

	if(sourceType == ds.Script.id_SolidFace)
		contactString = stringTable.String("ID_ContactGeometrySolidFace");
	else if(sourceType == ds.Script.id_SolidEdge)
		contactString = stringTable.String("ID_ContactGeometrySolidEdge");
	else if(sourceType == ds.Script.id_ShellFace)
		contactString = stringTable.String("ID_ContactGeometryShellFace");
	else if(sourceType == ds.Script.id_ShellEdge)
		contactString = stringTable.String("ID_ContactGeometryShellEdge");
	else if(sourceType == ds.Script.id_BeamEdge)
		contactString = stringTable.String("ID_ContactGeometryBeamEdge");
	else if(sourceType == ds.Script.id_BeamPoint)
		contactString = stringTable.String("ID_ContactGeometryBeamPoint");

	contactString = contactString + ", ";

	if(targetType == ds.Script.id_SolidFace)
		contactString = contactString + stringTable.String("ID_ContactGeometrySolidFace");
	else if(targetType == ds.Script.id_SolidEdge)
		contactString = contactString + stringTable.String("ID_ContactGeometrySolidEdge");
	else if(targetType == ds.Script.id_ShellFace)
		contactString = contactString + stringTable.String("ID_ContactGeometryShellFace");
	else if(targetType == ds.Script.id_ShellEdge)
		contactString = contactString + stringTable.String("ID_ContactGeometryShellEdge");
	else if(targetType == ds.Script.id_BeamEdge)
		contactString = contactString + stringTable.String("ID_ContactGeometryBeamEdge");
	else if(targetType == ds.Script.id_BeamPoint)
		contactString = contactString + stringTable.String("ID_ContactGeometryBeamPoint");

	return contactString;
}

function CanShowGotoGrid1()
{
    if( DataGrid1.SelectedRowsCount > 0 )
        return true;
    
	return false;
}

function CanShowGotoGrid2()
{
    if( DataGrid2.SelectedRowsCount > 0 )
        return true;
    
	return false;
}

function CanShowGotoGrid3()
{
    if( DataGrid3.SelectedRowsCount > 0 )
        return true;
    
	return false;
}

function WBDataGridCtrl2_RowClickDelegate(sender, args)
{
    WBDataGridCtrl2_RowClick(args.Cell.Row, args.Cell.Column);
}

function WBDataGridCtrl2_RowClick(currentRow, currentCol) 
{
    var cell = DataGrid2.Cell(currentRow, currentCol);
    var rowToStart = DataGrid2.FixedRowsCount+1;
    var rowToEnd = DataGrid2.RowsCount;
    
	//certain columns should sort numerically, the others alphabetically
	if( DataGrid2.RowsCount > 2)  //can only sort if there are more than one item in the list
	{
		//use numeric sorting
		sortVal = sortArr[currentCol];
		DataGrid2.SortColumn(currentCol, sortVal, byText, rowToStart, rowToEnd);
		if(sortArr[currentCol] == ascending)
			sortArr[currentCol] = descending;
		else
			sortArr[currentCol] = ascending;
	}
}

function WBDataGridCtrl1_RowClickDelegate(sender, args)
{
    WBDataGridCtrl1_RowClick(args.Cell.Row, args.Cell.Column);
}

function WBDataGridCtrl1_RowClick(currentRow, currentCol) 
{
    var cell = DataGrid1.Cell(currentRow, currentCol);
    var rowToStart = DataGrid1.FixedRowsCount+1;
    var rowToEnd = DataGrid1.RowsCount;
    
	//certain columns should sort numerically, the others alphabetically
	if( DataGrid1.RowsCount > 2)  //can only sort if there are more than one item in the list
	{
		//use numeric sorting
		sortVal = sortArr[currentCol];
		DataGrid1.SortColumn(currentCol, sortVal, byText, rowToStart, rowToEnd);
		if(sortArr[currentCol] == ascending)
			sortArr[currentCol] = descending;
		else
			sortArr[currentCol] = ascending;
	}
}

function WBDataGridCtrl3_RowClickDelegate(sender, args)
{
    WBDataGridCtrl3_RowClick(args.Cell.Row, args.Cell.Column);
}

function WBDataGridCtrl3_RowClick(currentRow, currentCol) 
{
    var cell = DataGrid3.Cell(currentRow, currentCol);
    var rowToStart = DataGrid3.FixedRowsCount+1;
    var rowToEnd = DataGrid3.RowsCount;
    
	//certain columns should sort numerically, the others alphabetically
	if( DataGrid3.RowsCount > 2)  //can only sort if there are more than one item in the list
	{
		//use numeric sorting
		sortVal = sortArr[currentCol];
		DataGrid3.SortColumn(currentCol, sortVal, byText, rowToStart, rowToEnd);
		if(sortArr[currentCol] == ascending)
			sortArr[currentCol] = descending;
		else
			sortArr[currentCol] = ascending;
	}
}

function Grid1_DisplayContextMenuDelegate(sender, args)
{
	Grid1_DisplayContextMenu(args.X, args.Y);
}

function Grid1_DisplayContextMenu(x,y)
{
	ds.GUIState.GUIDriver.MenuListener.AddListener(4345, this);
	
	var menuItem;
	
	var menuLoader = new ds.Script.dynamicMenuLoader();
	var meshingFilter = ds.Script.GetMeshingFilter();
    var meshingAlbionSimAddinFilter = ds.Script.GetMeshingAlbionSimAddinFilter();
    var albionSimAddinFilter = ds.Script.GetAlbionSimAddinFilter();	
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_WorksheetGoToSelectedItems"), "", "4345", "CommandContainer1_onclick", ID_GOTO_SELECTED_ITEMS);
    menuLoader.AddVisibilityCallback(menuItem, "3", "CanShowGotoGrid1", null);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
	
	menuLoader.AddSeparator(null);
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_NameProperty"), "", "4345", "CommandContainer1_onclick", ID_SHOW_NAME);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_NAME);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	

	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_TypeProperty"), "", "4345", "CommandContainer1_onclick", ID_SHOW_TYPE);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_TYPE);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ScopeGroup"), "", "4345", "CommandContainer1_onclick", ID_SHOW_SCOPE);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_SCOPE);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
		
	if (hasFrictionalRegion)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactFrictionCoefficient"), "", "4345", "CommandContainer1_onclick", ID_SHOW_FRICTIONCOEFF);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_FRICTIONCOEFF);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
	}
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactModeProperty"), "", "4345", "CommandContainer1_onclick", ID_SHOW_MODE);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_MODE);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
		
	if (beta)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactTrimProperty"), "", "4345", "CommandContainer1_onclick", ID_SHOW_TRIM);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_TRIM);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
	}

	if (hasBehavior)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_Behavior"), "", "4345", "CommandContainer1_onclick", ID_SHOW_BEHAVIOR);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_BEHAVIOR);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}

	if (hasNormalStiff)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactNormalStiffness"), "", "4345", "CommandContainer1_onclick", ID_SHOW_NORMALSTIFF);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_NORMALSTIFF);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
	}

	if (hasUpdateStiffness)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionUpdateContactStiffness"), "", "4345", "CommandContainer1_onclick", ID_SHOW_UPDATESTIFF);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_UPDATESTIFF);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}

	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_VariableStatus"), "", "4345", "CommandContainer1_onclick", ID_SHOW_STATUS);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_STATUS);
    menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
    menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
    menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionContactFormulation"), "", "4345", "CommandContainer1_onclick", ID_SHOW_FORMULATION);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_FORMULATION);
    menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
    menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
    menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);

    if (hasDetectionMethod) {
        menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionDetectionMethod"), "", "4345", "CommandContainer1_onclick", ID_SHOW_DETECTIONMETHOD);
        menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_DETECTIONMETHOD);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    }

    if(hasPenetrationTol)
    {
        menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionPenetrationTolerance"), "", "4345", "CommandContainer1_onclick", ID_SHOW_PENETRATIONTOL);
        menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_PENETRATIONTOL);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    }

	if (hasInitialEffect)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionInitialEffect"), "", "4345", "CommandContainer1_onclick", ID_SHOW_INITIALEFFECT);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_INITIALEFFECT);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}
	
	if (hasOffset)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionUserOffset"), "", "4345", "CommandContainer1_onclick", ID_SHOW_USEROFFSET);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_USEROFFSET);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}

	if (hasThermalCond)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionThermalConductance"), "", "4345", "CommandContainer1_onclick", ID_SHOW_THERMALCOND);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_THERMALCOND);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
	}
	
	if (hasElectricCond)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionElectricConductance"), "", "4345", "CommandContainer1_onclick", ID_SHOW_ELECTRICCOND);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_ELECTRICCOND);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    }

    if (hasDampingFactor) 
    {
        menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactRegionDampingFactor"), "", "4345", "CommandContainer1_onclick", ID_SHOW_DAMPINGFACTOR);
        menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_DAMPINGFACTOR);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    }
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactPinballRegion"), "", "4345", "CommandContainer1_onclick", ID_SHOW_PINBALLREGION);
	menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_PINBALLREGION);
    menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
    menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
    menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    	
	if (hasPinballRadius)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactPinballRadius"), "", "4345", "CommandContainer1_onclick", ID_SHOW_PINBALLRADIUS);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_PINBALLRADIUS);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}
	
	if (hasPinballFactor)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ContactPinballFactor"), "", "4345", "CommandContainer1_onclick", ID_SHOW_PINBALLFACTOR);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_PINBALLFACTOR);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}
	
	if (hasConstraintType)
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ConstraintType"), "", "4345", "CommandContainer1_onclick", ID_SHOW_CONSTRAINTTYPE);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_CONSTRAINTTYPE);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}
	
	if ( hasTimeStepControl )
	{
		menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_TimeStepControls"), "", "4345", "CommandContainer1_onclick", ID_SHOW_TIMESTEPCONTROL);
		menuLoader.AddCheckStateCallback(menuItem, "4345", "MenuItemCheckCallback", ID_SHOW_TIMESTEPCONTROL);
        menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
        menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
        menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);			
	}
	
	menuLoader.AddSeparator(null);
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ResetColumns"), "", "4345", "CommandContainer1_onclick", ID_RESET_COLUMNS);
    menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
    menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
    menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);

	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_ResetColumnWidths"), "", "4345", "CommandContainer1_onclick", ID_RESET_COLUMN_WIDTHS);
    menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
    menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
    menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);
    			
	menuLoader.ShowMenu(ds.GUIState.GUIDriver, x, y);
    menuLoader = null;

	ds.GUIState.GUIDriver.MenuListener.RemoveListener(4345);
}

function Grid2_DisplayContextMenuDelegate(sender, args)
{
	Grid2_DisplayContextMenu(args.X, args.Y);
}

function Grid2_DisplayContextMenu(x,y)
{
	ds.GUIState.GUIDriver.MenuListener.AddListener(4345, this);
	
	var menuItem;
	
	var menuLoader = new ds.Script.dynamicMenuLoader();
	var meshingFilter = ds.Script.GetMeshingFilter();
    var meshingAlbionSimAddinFilter = ds.Script.GetMeshingAlbionSimAddinFilter();
    var albionSimAddinFilter = ds.Script.GetAlbionSimAddinFilter();	
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_WorksheetGoToSelectedItems"), "", "4345", "CommandContainer2_onclick", ID_GOTO_SELECTED_ITEMS);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
    menuLoader.AddVisibilityCallback(menuItem, "3", "CanShowGotoGrid2", null);
		
	menuLoader.ShowMenu(ds.GUIState.GUIDriver, x, y);
    menuLoader = null;

	ds.GUIState.GUIDriver.MenuListener.RemoveListener(4345);
}

function Grid3_DisplayContextMenuDelegate(sender, args)
{
	Grid3_DisplayContextMenu(args.X, args.Y);
}

function Grid3_DisplayContextMenu(x,y)
{
	ds.GUIState.GUIDriver.MenuListener.AddListener(4345, this);
	
	var menuItem;
	
	var menuLoader = new ds.Script.dynamicMenuLoader();
	var meshingFilter = ds.Script.GetMeshingFilter();
    var meshingAlbionSimAddinFilter = ds.Script.GetMeshingAlbionSimAddinFilter();
    var albionSimAddinFilter = ds.Script.GetAlbionSimAddinFilter();	
	
	menuItem = menuLoader.AddMenuItem(null, stringTable.string("ID_WorksheetGoToSelectedItems"), "", "4345", "CommandContainer3_onclick", ID_GOTO_SELECTED_ITEMS);
	menuLoader.AddVisibilityFilter(menuItem, meshingFilter);
	menuLoader.AddVisibilityFilter(menuItem, meshingAlbionSimAddinFilter);
	menuLoader.AddVisibilityFilter(menuItem, albionSimAddinFilter);	
    menuLoader.AddVisibilityCallback(menuItem, "3", "CanShowGotoGrid3", null);
		
	menuLoader.ShowMenu(ds.GUIState.GUIDriver, x, y);
    menuLoader = null;

	ds.GUIState.GUIDriver.MenuListener.RemoveListener(4345);
}

function MenuItemCheckCallback(menuID)
{
	var numItemID = new Number(menuID).valueOf();

	switch(numItemID)
	{
		case ID_SHOW_NAME :
			return bListOneShowName;

		case ID_SHOW_TYPE :
			return bListOneShowType;

		case ID_SHOW_SCOPE :
			return bListOneShowScope;

		case ID_SHOW_FRICTIONCOEFF :
			return bListOneShowFrictionCoeff;

		case ID_SHOW_MODE :
			return bListOneShowMode;

		case ID_SHOW_TRIM :
			return bListOneShowTrim;

		case ID_SHOW_BEHAVIOR :
			return bListOneShowBehavior;

		case ID_SHOW_NORMALSTIFF :
			return bListOneShowNormalStiff;

		case ID_SHOW_UPDATESTIFF :
			return bListOneShowUpdateStiffness;

		case ID_SHOW_STATUS :
			return bListOneShowStatus;

		case ID_SHOW_FORMULATION :
			return bListOneShowFormulation;

		case ID_SHOW_INITIALEFFECT :
			return bListOneShowInitialEffect;

		case ID_SHOW_USEROFFSET :
			return bListOneShowUserOffset;

		case ID_SHOW_THERMALCOND :
			return bListOneShowThermalCond;

		case ID_SHOW_ELECTRICCOND :
			return bListOneShowElectricCond;

		case ID_SHOW_PINBALLREGION :
			return bListOneShowPinballRegion;

		case ID_SHOW_PINBALLRADIUS :
			return bListOneShowPinballRadius;

		case ID_SHOW_PINBALLFACTOR :
			return bListOneShowPinballFactor;

		case ID_SHOW_CONSTRAINTTYPE :
			return bListOneShowConstraintType;

		case ID_SHOW_TIMESTEPCONTROL :
		    return bListOneShowTimeStepControl;

		case ID_SHOW_DAMPINGFACTOR:
		    return bListOneShowDampingFactor;

		case ID_SHOW_DETECTIONMETHOD:
		    return bListOneShowDetectionMethod;

		case ID_SHOW_PENETRATIONTOL:
		    return bListOneShowPenetrationTol;
	}

	return false;
}

function CommandContainer1_onclick( menuID )
{
	var numItemID = new Number(menuID).valueOf();
	
	if(ID_GOTO_SELECTED_ITEMS == numItemID)
	{
		//make a string of selected ids
		var numInList = DataGrid1.SelectedRowsCount;
		var selectStr = "";
		for( var i=1; i<=numInList; i++ )
		{
			var currentRow = DataGrid1.SelectedRow(i);

			var key = DataGrid1.Cell(currentRow, 1).Tag;
			
			if( "" != selectStr )
				selectStr += ",";
				
			selectStr += key;
		}

		UNIXselectStr = selectStr;
		window.setTimeout("UNIXBugTimeoutToSelectItemsInDS()", 50);

		return;
	}

	if( ID_RESET_COLUMNS == numItemID )
	{	
		//on reset, all go back to true
		bListOneShowName = true; bListOneShowType = true; bListOneShowScope = true; bListOneShowFrictionCoeff = true; bListOneShowMode = true; 
		bListOneShowBehavior = true; bListOneShowNormalStiff = true; bListOneShowUpdateStiffness = true; bListOneShowStatus = true; bListOneShowFormulation = true; 
		bListOneShowInitialEffect = true; bListOneShowUserOffset = true; bListOneShowThermalCond = true; bListOneShowElectricCond = true; bListOneShowPinballRegion = true; 
		bListOneShowPinballRadius = true; bListOneShowPinballFactor = true; bListOneShowConstraintType = true;
        bListOneShowTrim = true; bListOneShowTimeStepControl = true; bListOneShowDampingFactor = true; bListOneShowDetectionMethod = true; bListOneShowPenetrationTol = true;

	    if (!beta)
    	    bListOneShowTrim = false;

        columWidthsClass.Contact_FirstVisit = true;
	    saveGridSettings();
        setGrid1List();
 	    return;
	}
	else if(ID_RESET_COLUMN_WIDTHS == numItemID)
	{
	    columWidthsClass.Contact_FirstVisit = true;
        ResizeGrid1Lists();
	    return;
	}
	
	var bFound = true;
	switch(numItemID)
	{
		case ID_SHOW_NAME :
			bListOneShowName = !bListOneShowName;
			break;
		case ID_SHOW_TYPE :
			bListOneShowType = !bListOneShowType;
			break;
		case ID_SHOW_SCOPE :
			bListOneShowScope = !bListOneShowScope;
			break;
		case ID_SHOW_FRICTIONCOEFF :
			bListOneShowFrictionCoeff = !bListOneShowFrictionCoeff;
			break;
		case ID_SHOW_MODE :
			bListOneShowMode = !bListOneShowMode;
			break;
		case ID_SHOW_TRIM :
			bListOneShowTrim = !bListOneShowTrim;
			break;
		case ID_SHOW_BEHAVIOR :
			bListOneShowBehavior = !bListOneShowBehavior;
			break;
		case ID_SHOW_NORMALSTIFF :
			bListOneShowNormalStiff = !bListOneShowNormalStiff;
			break;
		case ID_SHOW_UPDATESTIFF :
			bListOneShowUpdateStiffness = !bListOneShowUpdateStiffness;
			break;
		case ID_SHOW_STATUS :
			bListOneShowStatus = !bListOneShowStatus;
			break;
		case ID_SHOW_FORMULATION :
			bListOneShowFormulation = !bListOneShowFormulation;
			break;
		case ID_SHOW_INITIALEFFECT :
			bListOneShowInitialEffect = !bListOneShowInitialEffect;
			break;
		case ID_SHOW_USEROFFSET :
			bListOneShowUserOffset = !bListOneShowUserOffset;
			break;
		case ID_SHOW_THERMALCOND :
			bListOneShowThermalCond = !bListOneShowThermalCond;
			break;
		case ID_SHOW_ELECTRICCOND :
			bListOneShowElectricCond = !bListOneShowElectricCond;
			break;
		case ID_SHOW_PINBALLREGION :
			bListOneShowPinballRegion = !bListOneShowPinballRegion;
			break;
		case ID_SHOW_PINBALLRADIUS :
			bListOneShowPinballRadius = !bListOneShowPinballRadius;
			break;
		case ID_SHOW_PINBALLFACTOR :
			bListOneShowPinballFactor = !bListOneShowPinballFactor;
			break;
		case ID_SHOW_CONSTRAINTTYPE :
			bListOneShowConstraintType = !bListOneShowConstraintType;
			break;
		case ID_SHOW_TIMESTEPCONTROL :
			bListOneShowTimeStepControl = !bListOneShowTimeStepControl;
			break;
        case ID_SHOW_DAMPINGFACTOR:
            bListOneShowDampingFactor = !bListOneShowDampingFactor;
            break;
        case ID_SHOW_DETECTIONMETHOD:
            bListOneShowDetectionMethod = !bListOneShowDetectionMethod;
            break;
        case ID_SHOW_PENETRATIONTOL:
            bListOneShowPenetrationTol = !bListOneShowPenetrationTol;
            break;
		default :
		    bFound = false;
			return;
	}
    
    if( bFound )
    {
        columWidthsClass.Contact_FirstVisit = true;
	    saveGridSettings();
        setGrid1List();
    }
}

function CommandContainer2_onclick( menuID )
{
	var numItemID = new Number(menuID).valueOf();
	
	if(ID_GOTO_SELECTED_ITEMS == numItemID)
	{
		//make a string of selected ids
		var numInList = DataGrid2.SelectedRowsCount;
		var selectStr = "";
		for( var i=1; i<=numInList; i++ )
		{
			var currentRow = DataGrid2.SelectedRow(i);

			var key = DataGrid2.Cell(currentRow, 1).Tag;
			
			if( "" != selectStr )
				selectStr += ",";
				
			selectStr += key;
		}

		UNIXselectStr = selectStr;
		window.setTimeout("UNIXBugTimeoutToSelectItemsInDS()", 50);

		return;
	}
}

function CommandContainer3_onclick( menuID )
{
	var numItemID = new Number(menuID).valueOf();
	
	if(ID_GOTO_SELECTED_ITEMS == numItemID)
	{
		//make a string of selected ids
		var numInList = DataGrid3.SelectedRowsCount;
		var selectStr = "";
		for(var i = 1; i <= numInList; i++)
		{
			var currentRow = DataGrid3.SelectedRow(i);
    		var key = DataGrid3.Cell(currentRow, 1).Tag;
			if("" != selectStr)
				selectStr += ",";
				
			selectStr += key;
		}

		UNIXselectStr = selectStr;
		window.setTimeout("UNIXBugTimeoutToSelectItemsInDS()", 50);
		return;
	}
}

function UNIXBugTimeoutToSelectItemsInDS()
{
	if(UNIXselectStr && UNIXselectStr != "")
		ds.Script.SelectItems(UNIXselectStr);
}

function behaviorApplicable(curItem)
{
    var hasEdge = false;
	if( curItem.SourceGeometryScopeType == ds.Script.id_ShellEdge ||
	    curItem.SourceGeometryScopeType == ds.Script.id_SolidEdge ||
	    curItem.SourceGeometryScopeType == ds.Script.id_BeamEdge )
	    hasEdge = true;
	if( curItem.TargetGeometryScopeType == ds.Script.id_ShellEdge ||
	    curItem.TargetGeometryScopeType == ds.Script.id_SolidEdge ||
	    curItem.TargetGeometryScopeType == ds.Script.id_BeamEdge )
	    hasEdge = true;

    if( hasEdge == false )
        return true;
    if( hasEdge == true && is2DModel == true )
        return true;
    
    return false;
}

function AreAllEnvironmentSolversMBD()
{
    var childList = ds.Tree.FirstActiveModel.Environments;
	if(childList.Count == 0)
		return false;
		
    for(i=1; i<=childList.Count; i++)
	{
		var child = childList.Item(i);
		if( child == null )
		    return false;
		 
		if( "MBD" != child.SolverTargetName )
		    return false;
	}
	
	return true;
}

//-->
        </SCRIPT>
    </HEAD>
    <BODY LANGUAGE="javascript" onload="return window_onload()" onunload="return window_onunload()">
        <DIV class="gradient">
            <H1 id="pageName">&nbsp;</H1>
        </DIV>
        <br id="asymbreak">
        <DIV id="asymNote" class="asym">
        </DIV>
        <center>
            <br id="linebreak">
            <p id="contactTableTitle" class="titletext">SHOULD NOT DISPLAY</p>

            <OBJECT id="DataGrid1" style="LEFT: 3px; WIDTH: 97%; TOP: 34px; HEIGHT: 93%" height="93%" width="97%"
				classid=CLSID:0B696001-60F3-4E4D-8EDD-E9EAE6DBDF12 VIEWASTEXT></OBJECT>
			</OBJECT>
            
            <br id="linebreak">
            <p id="jointDOFChecker" class="titletext"></p>
			<TABLEHOLDER>
				<!-- Placeholder for the table -->
				<DIV ID="oTableContainer"></DIV>
			</TABLEHOLDER>
			<SCRIPT LANGUAGE="JScript">
				var oTable = document.createElement("TABLE");
				oTableContainer.appendChild(oTable);
			</SCRIPT>
            <p id="jointTableTitle" class="titletext"></p>
           
            <OBJECT id="DataGrid2" style="LEFT: 3px; WIDTH: 97%; TOP: 34px; HEIGHT: 93%" height="93%" width="97%"
				classid=CLSID:0B696001-60F3-4E4D-8EDD-E9EAE6DBDF12 VIEWASTEXT></OBJECT>
			</OBJECT>
			
            <p id="meshConnectionTableTitle" class="titletext"></p>
            <OBJECT id="DataGrid3" style="LEFT: 3px; WIDTH: 97%; TOP: 34px; HEIGHT: 93%" height="93%" width="97%"
				classid=CLSID:0B696001-60F3-4E4D-8EDD-E9EAE6DBDF12 VIEWASTEXT></OBJECT>
			</OBJECT>

        </center>
    </BODY>
</HTML>
