// JScript source code
var wb;
var edApplet;
var eds;
var eda;

function edMaterialScope ()
{
   this.leftPane = null;
   this.leftPaneMinSize = 300;
   this.rightPane = null;
   this.currentView = "";
   this.timeInterval = 0;
   this.document = null;
   this.Graph = null;

}

var edmatl = null;
edmatl = new edMaterialScope();

edMaterialScope.prototype.resize = function()
{
//debugger;
	eda.LeftPaneWidth = document.all.left.width;
   if (edmatl && event.srcElement.clientWidth < edmatl.leftPaneMinSize)
   {
		EDMaterialWorksheet.cols = "" + edmatl.leftPaneMinSize + ",*";
      event.returnValue = false;
   }
   else if (eda.PropImgScript)
      eda.PropImgScript.UpdateImages();
      
   return false;
}

edMaterialScope.prototype.window_onload = function ()
{
//debugger;
   // Go get the WB, Engg Data Applet; Script; and namespace
	wb			=  window.external;
	edApplet =  wb.AppletList.Applet( "EDApplet").App;
	eds = edApplet.Script;
   eda = eds.eda;

   eda.OverloadDefaultEvents(document);
	if (eda.LeftPaneWidth != -1)
		EDMaterialWorksheet.cols = "" + eda.LeftPaneWidth + ",*";
   eda.MaterialScope = edmatl;
   eda.ActiveScript = edmatl;
   this.Graph = eds.CreateActiveXObject(eds.GenWBProgId("WBGraphUtility.WBGraph"));

   // This determines Internet Explorer's major version number,
   // or 0 for others. It works by finding the "MSIE " string and
   // extracting the version number following the space, up to the decimal
   // point, ignoring the minor version number
   var ieVersion = 0;
   var ua = window.navigator.userAgent;
   var msie = ua.indexOf ( "MSIE " );

   if ( msie > 0 )      // The version for Internet Explorer is available
      ieVersion = parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
      
   if(ieVersion < 6)
   {
	   edmatl.timeInterval = window.setInterval("edmatl.PageLoaded()", 250);
	}
	else
	{
	   edmatl.PageLoaded();
	}
}

edMaterialScope.prototype.window_onunload = function ()
{
   eda.MaterialScope = null;
   if (eda.ActiveScript == edmatl)
      eda.ActiveScript = null;

   this.document = null;
   this.currentView = "";
   this.Graph = null;
}

edMaterialScope.prototype.PageLoaded = function ()
{
	try
	{
		if( !isNaN(edmatl.timeInterval) )
			window.clearInterval(edmatl.timeInterval);
		edmatl.timeInterval = 0;
      if ( left )
      {
         edmatl.document = document;
         edmatl.SwitchView("summary");
      }
	}
	catch (e)
	{
	//debugger;
		if( !isNaN(edmatl.timeInterval))
			window.clearInterval(edmatl.timeInterval);
		edmatl.timeInterval = window.setInterval("edmatl.PageLoaded()", 250);
	}
}


edMaterialScope.prototype.SwitchView = function ( view )
{
	try
	{
//	   if (this.currentProp == && this.currentView == view) return;
	   switch (view)
	   {
	      case "summary":
	         //this.document.all.EDMaterialWorksheet.cols="40%,60%";
            this.document.all.left.src = eda.HTMLDirNoLocale + "PropertySummary.htm";
            this.document.all.right.src = eda.HTMLDirNoLocale + "PropertySummaryWorksheet.htm";
            break;
         case "edit":
            this.document.all.left.src = eda.HTMLDirNoLocale + "PropertyEditor.htm";
            this.document.all.right.src = eda.HTMLDirNoLocale + "PropertyGraphwSummary.htm";
	         //this.document.all.EDMaterialWorksheet.cols="30%,70%";
            break;
         default:
            break;
      }
      this.currentView = view;
	}
	catch (e)
	{
		//debugger;
	}
}

edMaterialScope.prototype.AddProperty = function (enumValue)
{
   try
   {
      var matl = eda.DataViewScript.ActiveItem;
      var prop = matl.getProperty(enumValue);
      if (!prop)
      {
		prop = matl.addProperty(enumValue,"");
         // Set a value to make the property available
         prop.Variables.Item(1).Value(1) = 0.0;
      }
      // Make sure that the item is not suppressed as well
      prop.isSuppressed = false;
      /*
      if (prop.Variables.Count > 1)
      {
         // This is tabular data so switch to edit
         this.SwitchView("edit");
      }
      else
      {
         // This is a constant value so switch to summary
         this.SwitchView("summary");
      }
      */
         this.RefreshView();
   }
   catch (error)
   {
//debugger;
   }
}


edMaterialScope.prototype.RefreshView = function ()
{
   try
   {
      if (eda.PropSummaryScript)
         eda.PropSummaryScript.UpdateSummary();
      if (eda.PropImgScript)
         eda.PropImgScript.UpdateImages();
      if (eda.VarDataScript)
		   eda.VarDataScript.RefreshView();
   }
   catch (error)
   {
//debugger;
   }
}

edMaterialScope.prototype.GotoSummary = function ( )
{
	try
	{
      this.SwitchView("summary");
	}
	catch (e)
	{
	}
}

edMaterialScope.prototype.updateBreadcrumbs = function ( node )
{
	try
	{
	   if (eda.PropSummaryScript)
	         eda.PropSummaryScript.updateBreadcrumbs(node);
	}
	catch (e)
	{
	}
	try
	{
      if (eda.VarDataScript)
	         eda.VarDataScript.updateBreadcrumbs(node);
	}
	catch (e)
	{
	}
}


