/*

    Copyright 2003-2007 Purdue University. 

    Developed by: Peter Turbek, Department of Mathematics, Computer Science, and Statistics, Purdue University Calumet.


    This file is part of CaluMath.

    CaluMath is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    CaluMath is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/


//This is the main file for the CaluMath Page Maker. It is placed at the end of the CaluMath Page Maker document. //



CaluMath.PM.MATHBUTTONFUNCTION =function(){ 

   if(CM_TopWindow.CM_EditMode != true && arguments[1] ==undefined && (CaluMath.PM.MATHSELECT == null || CaluMath.PM.MATHSELECT.options ==null || CaluMath.PM.MATHSELECT.selectedIndex==null) ){  
      var selectedvalue= arguments[0]; 
      var selectedlabel= CaluMath.PM.PageMakerObjectLabelName(selectedvalue);
      if(selectedvalue=="text"){
         CaluMath.PM.HidePageControls(); 
         if(window.CaluMath.PM.VIEWAREABUTTON != null && window.CaluMath.PM.VIEWAREABUTTON.parentNode != null){
            CaluMath.PM.VIEWAREABUTTON.onclick();
         };

         return CaluMath.PM.WriteAndEdit(); 
      };
   }
   else if(CM_TopWindow.CM_EditMode != true && arguments[1] ==undefined){  
      var selectedoption=CaluMath.PM.MATHSELECT.options[CaluMath.PM.MATHSELECT.selectedIndex];
      var selectedlabel= selectedoption.label;
      var selectedvalue= selectedoption.value;
//      var htmltag= selectedvalue;
   }
   else if(CM_TopWindow.CM_EditMode != true && arguments[1] =="table"){  
      var selectedvalue= arguments[0];
      var selectedlabel= CaluMath.PM.PageMakerObjectLabelName(selectedvalue);
//      var htmltag= selectedvalue;
      if(selectedvalue=="text"){
         CaluMath.PM.HidePageControls(); 
         if(window.CaluMath.PM.VIEWAREABUTTON != null && window.CaluMath.PM.VIEWAREABUTTON.parentNode != null){
            CaluMath.PM.VIEWAREABUTTON.onclick();
         };

         return CaluMath.PM.WriteAndEdit(); 
      };
   }
   else if(CM_TopWindow.CM_EditMode != true  && arguments[1] =="no"){
      //Comment: This means that CaluMath.PM.MATHBUTTON.onclick is not being called from a CaluMath.PM.MATHSELECT option, but from somewhere else. 
      var selectedlabel= arguments[0].label;
      var selectedvalue= arguments[0].value;
//      var htmltag= selectedvalue;
   }
   else{  
      var tempobject=arguments[0]; 
      var selectedvalue=tempobject.type; 
      var selectedlabel =CaluMath.PM.PageMakerObjectLabelName(tempobject); 
   };
   CaluMath.PM.HidePageControls(); 

   if(window.CaluMath.PM.VIEWAREABUTTON != null && window.CaluMath.PM.VIEWAREABUTTON.parentNode != null){
      CaluMath.PM.VIEWAREABUTTON.onclick();
   };
      if(selectedvalue =="definedconstant"){ 
         tempobject=CaluMath.PM.ObjectStandardBeginning("definedconstant", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "definedconstant", selectedlabel, "Constant"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){ 
            randomcontainerElement.parentNode.removeChild(randomcontainerElement);
            cancelbuttonElement.standardonclick();
         };

         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           var definedconstantindex=CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.definedconstantlist,CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name"),0);
           CaluMath.PM.PlotlistObject.definedconstantlist=CaluMath.PM.PlotlistObject.definedconstantlist.slice(0,definedconstantindex).concat(CaluMath.PM.PlotlistObject.definedconstantlist.slice(definedconstantindex+1));
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           randomcontainerElement.parentNode.removeChild(randomcontainerElement);
           deletebuttonElement.standardonclick();
         };
         var p3randomElement=document.createElement("input");
         p3randomElement.setAttribute("type","button");
         p3randomElement.setAttribute("value","Create A Random Number");
         var randomcontainerElement=document.createElement("div");
         CaluMath.PM.BUTTONCONTAINER.insertBefore(randomcontainerElement, finishbuttonElement);


         randomcontainerElement.appendChild(p3randomElement);

            var p4randomElement=document.createElement("input");
            p4randomElement.setAttribute("type","button");
            p4randomElement.setAttribute("value","Create The Random Number");
            p4randomElement.style.display="none";
            randomcontainerElement.insertBefore(p4randomElement, p3randomElement);
            randomcontainerElement.appendChild(document.createElement("br"));
            randomcontainerElement.appendChild(document.createElement("br"));

         p3randomElement.onclick=function(){
            var randomselectmenu = document.createElement("select");
            randomcontainerElement.insertBefore(randomselectmenu,p3randomElement);
            CaluMath.PM.MakeSelectMenu(randomselectmenu, CaluMath.PM.RANDOMNUMBERLIST);

            var lowerinputElement=document.createElement("input");
            lowerinputElement.setAttribute("type","text");
            lowerinputElement.setAttribute("size","10");
            randomcontainerElement.insertBefore(lowerinputElement,p3randomElement);

            var upperinputElement=document.createElement("input");
            upperinputElement.setAttribute("type","text");
            upperinputElement.setAttribute("size","10");
            randomcontainerElement.insertBefore(upperinputElement,p3randomElement);

            var tempinstructions= '<p style="font-size:20px; width:750px"><br>Choose the type of Random Number you want to create. Enter the lower and upper bounds for the random number in the two boxes below. Then click the Create The Random Number button</p>'.cm_html("cm_insertafter=displayleft");
            randomcontainerElement.insertBefore(tempinstructions.cm_node[0],randomcontainerElement.firstChild);

            p4randomElement.style.display="inline";
            p3randomElement.style.display="none";
          
            p4randomElement.onclick=function(){
               var randomselectchoice=randomselectmenu.options[randomselectmenu.selectedIndex].value;
               var lowerchoice=lowerinputElement.value;
               var upperchoice=upperinputElement.value;
               if(lowerchoice.match(/\w/)==null || upperchoice.match(/\w/)==null ){
                  return cm_alert("You must enter a lower and upper bound for your random number");
               };
               try{
                  var lowerevaluated = lowerchoice.cm_evalmath();
                  var upperevaluated = upperchoice.cm_evalmath();
                  if(lowerevaluated > upperevaluated){
                     return cm_alert("Your lower bound is greater than your upper bound.");
                  };
               }
               catch(e){
//                  return cm_alert("I don't think you entered numbers for the lower and upper bounds");
                  if(window.confirm("There may be a problem with your input. If you made a mistake entering the lower and upper bounds, click Cancel. If your entries refer to constants that will not be defined until the page loads, click OK.")){
                  }
                  else{
                     return;
                  };
               };

               CaluMath.PM.PageMakerdefinedconstantDefault.required.definition.input.value=randomselectchoice+'('+lowerchoice+','+upperchoice+')';
               lowerinputElement.parentNode.removeChild(lowerinputElement);
               upperinputElement.parentNode.removeChild(upperinputElement);
               randomselectmenu.parentNode.removeChild(randomselectmenu);
               tempinstructions.remove();
               p3randomElement.style.display="inline";
               p4randomElement.style.display="none";
               window.location.hash="#endofdocument"; 
            };
            CM_TopWindow.location.hash="#endofdocument"; 
         };
         CM_TopWindow.location.hash= "#endofdocument"; 

         finishbuttonElement.onclick=function(){
            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("definedconstant",tempobject);
            if(tempstring == null){
               return;
            };

            var nameinput= temprequired.name;
            var definitioninput= temprequired.definition;

            //Comment: Important!! CaluMath.PM.AddToListsdefinedconstant and CaluMath.PM.AddToListsdefinedfunction have special routines that add the constant or function to the PlotlistObject.definedconstant list or PlotlistObject.definedfunction lists and return the index of CaluMath.PM.PageMakerArray that corresponds to any previous version of the function. Therefore tempindex is used to place the object correctly to overwrite its previous CaluMath.PM.PageMakerObjectArray.
            var insertindex=CaluMath.PM.AddToListsdefinedconstant(tempobject, temprequired);

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
                  if(insertindex==null || CaluMath.PM.PlotlistObject.definedconstantlist.length==0 ){
                     var tempinsertionindex=CaluMath.PM.FindScriptInsertionPoint();
                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,tempinsertionindex).concat(tempobject).concat(CaluMath.PM.PageMakerObjectArray.slice(tempinsertionindex)); 
                  }
                  else{
                     CaluMath.PM.PageMakerObjectArray[insertindex]=tempobject;
                  };
            };

            CaluMath.PM.SetWriteTag(tempobject);
            window[nameinput]=.123456789;
            randomcontainerElement.parentNode.removeChild(randomcontainerElement);
            finishbuttonElement.standardcleanup();
         };


      }   
      else if(selectedvalue =="variablename"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("variablename", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         

         //Comment: We warn them that changing the name of a constant during editing is not allowed.


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "variablename", selectedlabel, "Named Object"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){ 
            cancelbuttonElement.standardonclick();
         };

         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("variablename",tempobject);
            if(tempstring == null){
               return;
            };

            var nameinput= temprequired.name;
            var definitioninput= temprequired.definition;

            if(CM_TopWindow.CaluMath.PM.IgnoreMathInputChecks !=true){
            //Comment: We try to define the variable in CM_TopWindow. The string is exactly the same as scriptobject.writestring below. 
               try{
               }
               catch(e){
                  return cm_alert("There is a problem with your input. If your input contains quotes or backslashes, you should double check them. If you want to name a word or phrase, make sure the phrase is enclosed in single quotes. Any single quotes that the phrase contains must be preceded by a backslash. You must type four backslashes to have one backslash appear.");
               };
            };


            //Comment: CaluMath.PM.AddToListsvariablename and CaluMath.PM.AddToListsdefinedfunction have special routines that add the constant or function to the PlotlistObject.variablename list or PlotlistObject.definedfunction lists and return the index of CaluMath.PM.PageMakerArray that corresponds to any previous version of the function. Therefore tempindex is used to place the object correctly to overwrite its previous CaluMath.PM.PageMakerObjectArray.
            var insertindex=CaluMath.PM.AddToListsvariablename(tempobject, temprequired);

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
                  if(insertindex==null || CaluMath.PM.PlotlistObject.variablenamelist.length==0 ){
                     var tempinsertionindex=CaluMath.PM.FindScriptInsertionPoint();
                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,tempinsertionindex).concat(tempobject).concat(CaluMath.PM.PageMakerObjectArray.slice(tempinsertionindex)); 
                  }
                  else{
                     CaluMath.PM.PageMakerObjectArray[insertindex]=tempobject;
                  };
            };

            //Comment: VERY IMPORTANT!!!! The settings for tempobject are correct in the current window and the object can be edited. However, when the settings are written to String by CaluMath.PM.PageMakerObjectToString (in order to be parsed in the newly saved window), the settings for any escaped single quotes would be incorrect without a further adjustment. This adjustment is taken care of in the CaluMath.PM.PageMakerObjectToString routine. 
            CaluMath.PM.ReplacePageMakerObjectSetting(tempobject, "definition", ["definition",definitioninput]);


            CaluMath.PM.SetWriteTag(tempobject);
            try{
               window[nameinput]= eval(definitioninput);
            }
            catch(e){
               window[nameinput]= "An object not created yet."
            }

            finishbuttonElement.standardcleanup();
         };
      }   
      else if(selectedvalue=="definedfunction"){
         tempobject=CaluMath.PM.ObjectStandardBeginning("definedfunction", arguments[0]);

         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "definedfunction", selectedlabel, "Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            var definedfunctionindex=CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.definedfunctionlist,CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name"),0);
            CaluMath.PM.PlotlistObject.definedfunctionlist=CaluMath.PM.PlotlistObject.definedfunctionlist.slice(0,definedfunctionindex).concat(CaluMath.PM.PlotlistObject.definedfunctionlist.slice(definedfunctionindex+1));
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            //Comment: CaluMath.PM.CreateSettingsArray examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("definedfunction",tempobject);
            if(tempstring == null){
               return;
            };
            var nameinput= temprequired.name;
            var variableinput= temprequired.cm_variable;
            var definitioninput= temprequired.definition;
            if( !definitioninput.match(/\'/) && !definitioninput.match(/\"/)){  
               window[nameinput]=CaluMath.PM.PlaceholderFunction;
            }
            else{
               window[nameinput]=CaluMath.PM.PlaceholderStringFunction;
            };


            //Comment: CaluMath.PM.AddToListsdefinedconstant and CaluMath.PM.AddToListsdefinedfunction have special routines that add the constant or function to the PlotlistObject.definedconstant list or PlotlistObject.definedfunction lists and return the index of CaluMath.PM.PageMakerArray that corresponds to any previous version of the function. Therefore tempindex is used to place the object correctly to overwrite its previous CaluMath.PM.PageMakerObjectArray.
            var insertindex=CaluMath.PM.AddToListsdefinedfunction(tempobject, temprequired);

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
                  if(insertindex==null || CaluMath.PM.PlotlistObject.definedfunctionlist.length==0 ){
                     var tempinsertionindex=CaluMath.PM.FindScriptInsertionPoint();
                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,tempinsertionindex).concat(tempobject).concat(CaluMath.PM.PageMakerObjectArray.slice(tempinsertionindex)); 
                  }
                  else{
                     CaluMath.PM.PageMakerObjectArray[insertindex]=tempobject;   
                  };
            };
            CaluMath.PM.SetWriteTag(tempobject); 

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="splitfunction"){
         tempobject=CaluMath.PM.ObjectStandardBeginning("splitfunction", arguments[0]);

         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "splitfunction", selectedlabel, "Split Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            var definedfunctionindex=CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.definedfunctionlist,CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name"),0);
            CaluMath.PM.PlotlistObject.definedfunctionlist=CaluMath.PM.PlotlistObject.definedfunctionlist.slice(0,definedfunctionindex).concat(CaluMath.PM.PlotlistObject.definedfunctionlist.slice(definedfunctionindex+1));
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("splitfunction",tempobject);
            if(tempstring == null){
               return;
            };

            var nameinput= temprequired.name;
            var variableinput= temprequired.variable;

            var splitfunctiondefinitionstring = "";
            var splitconditionstring = "";
            makesplitfunctiondefinitionloop:
            for(var i=1; i<7; i++){
               if(temprequired["definition"+i].length != 0){
                  splitfunctiondefinitionstring= splitfunctiondefinitionstring+","+temprequired["definition"+i];
                  if(temprequired["condition"+i].length != 0){
                     splitfunctiondefinitionstring= splitfunctiondefinitionstring+","+temprequired["condition"+i];
                     splitconditionstring= splitconditionstring + "( "+temprequired["condition"+i]+ " ) || "
                  }
                  else{
                     if(splitconditionstring.length == 0){
                        splitfunctiondefinitionstring= splitfunctiondefinitionstring+", 0==0";
                     }
                     else{
                        splitfunctiondefinitionstring= splitfunctiondefinitionstring+", !(" + splitconditionstring.replace(/\|\|\s*$/,"")+")";
                     }
                      break makesplitfunctiondefinitionloop;
                  };
               }
               else{
                  break makesplitfunctiondefinitionloop;
               };
            };
            splitfunctiondefinitionstring=splitfunctiondefinitionstring.replace(/\,\s*$/,"");
            splitfunctiondefinitionstring=splitfunctiondefinitionstring.replace(/^\s*\,/,"");

            try{
               if(tempobject.cm_getsetting("cm_inputarray").length ==0){
                  var tempfunction= (nameinput+"("+variableinput+") := splitfunction("+splitfunctiondefinitionstring+")").cm_parsefunction(); 
                  eval(tempfunction);
                  var proceedindicator="yes";
               }
               else{
                  eval(tempobject.cm_getsetting("cm_inputarray")).cm_parsepiecewiselinearfunction(nameinput);
                  var proceedindicator="yes";
               };
            }
            catch(e){
                  if(window.confirm("There may be a problem with your input. Do you want to continue anyway?")){
                     var proceedindicator="yes";
                  };
            };
            //Comment: We need to keep all of the above to make sure that the splitfunction is entered without an error. This is all repeated when the splitfunction is written to with cm_writehtml.
            
            if(proceedindicator=="yes"){
            //Comment: CaluMath.PM.AddToListsdefinedconstant and CaluMath.PM.AddToListsdefinedfunction have special routines that add the constant or function to the PlotlistObject.definedconstant list or PlotlistObject.definedfunction lists and return the index of CaluMath.PM.PageMakerArray that corresponds to any previous version of the function. Therefore tempindex is used to place the object correctly to overwrite its previous CaluMath.PM.PageMakerObjectArray.
            var insertindex=CaluMath.PM.AddToListsdefinedfunction(tempobject, temprequired);

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
                  if(insertindex==null || CaluMath.PM.PlotlistObject.definedfunctionlist.length==0 ){
                     var tempinsertionindex=CaluMath.PM.FindScriptInsertionPoint();
                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,tempinsertionindex).concat(tempobject).concat(CaluMath.PM.PageMakerObjectArray.slice(tempinsertionindex)); 
                  }
                  else{
                     CaluMath.PM.PageMakerObjectArray[insertindex]=tempobject;   
                  };
            };


            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
            };
         };
      }
      else if(selectedvalue=="discretefunctionfrompointsarray"){
         tempobject=CaluMath.PM.ObjectStandardBeginning("discretefunctionfrompointsarray", arguments[0]);

         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "discretefunctionfrompointsarray", selectedlabel, "Function From Array"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            var discretefunctionindex=CaluMath.PM.ArrayIndex(discretefunctionlist,CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name"),0);
            discretefunctionlist=discretefunctionlist.slice(0,discretefunctionindex).concat(discretefunctionlist.slice(discretefunctionindex+1));
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            //Comment: CaluMath.PM.CreateSettingsArray examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("discretefunctionfrompointsarray",tempobject);

            //Comment: CaluMath.PM.AddToListsdefinedconstant and CaluMath.PM.AddToListsdefinedfunction have special routines that add the constant or function to the PlotlistObject.definedconstant list or PlotlistObject.definedfunction lists and return the index of CaluMath.PM.PageMakerArray that corresponds to any previous version of the function. Therefore tempindex is used to place the object correctly to overwrite its previous CaluMath.PM.PageMakerObjectArray.
            var insertindex=CaluMath.PM.AddToListsdiscretefunctionfrompointsarray(tempobject, temprequired);

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
                  if(insertindex==null || CaluMath.PM.PlotlistObject.definedfunctionlist.length==0 ){
                     var tempinsertionindex=CaluMath.PM.FindScriptInsertionPoint();
                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,tempinsertionindex).concat(tempobject).concat(CaluMath.PM.PageMakerObjectArray.slice(tempinsertionindex)); 
                  }
                  else{
                     CaluMath.PM.PageMakerObjectArray[insertindex]=tempobject;   
                  };
            };


            CaluMath.PM.SetWriteTag(tempobject); 

            finishbuttonElement.standardcleanup();

         };
      }
//Comment: DRAW AXES DRAW AXES DRAW AXES DRAW AXES DRAW AXES DRAW AXES DRAW AXES DRAW AXES DRAW AXES
      else if(selectedvalue=="newplot"){ 

         if(CM_TopWindow.CaluMath.PM.InsertionArray.length >0 && CM_TopWindow.CaluMath.PM.InsertionArray.lastobject().type != "newwindow" &&  CaluMath.PM.PlotlistObject.iframelist.length==0){
//            TABLEFORHTMLCASMATHOPTIONS.style.visibility="visible";
            CaluMath.PM.MENUSTABLEFORHTMLCASMATHOPTIONS.style.visibility="visible";
            return alert("You are trying to dynamically create a set of axes, however you did not create an iframe to put it in. Please construct your iframe first. Note that iframes cannot be constructed during a buttonaction, or routines.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("newplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            //Comment: If we are in CM_EditMode, we want to see if they are putting the axes in a new location or keeping it in the same location.
            var oldinsertoption= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption");
            var oldinserttarget= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget");
            var oldcaswindow= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow");
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", [[oldcaswindow, oldcaswindow]], oldcaswindow, [["Window","help/individual_help.html#requiredcm_caswindow"], "Axes Appear In This Window","same"]]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_insertoption", "menu", [["current point", "n/a"],["insert in", "cm_insertin"]], oldinsertoption, [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Axes Placement","same"]]);
            CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakernewplotDefault.options.cm_insertoption.menu,oldinsertoption, "value");
            if(CaluMath.PM.PlotlistObject[oldcaswindow] != null && CaluMath.PM.PlotlistObject[oldcaswindow].staticobjectlist != null){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[oldcaswindow].staticobjectlist), oldinserttarget, [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Place Axes Inside This Object","same"]]);
            }
            else{
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", CaluMath.PM.PlotlistObject.iframelist,CaluMath.PM.PlotlistObject.iframelist[0][0],"Window"]);
            };
         };
         if(!CM_TopWindow.CM_EditMode){
            if(CaluMath.PM.InsertionArray.length >0){
               if(CaluMath.PM.InsertionArray.lastobject().type=="newwindow"){
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", [[CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"),CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name")]], CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"), [["Window","help/individual_help.html#requiredcm_caswindow"], "Axes Appear In This Window","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_insertoption", "menu", [["current point", "n/a"],["insert in", "cm_insertin"]], "current point", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Axes Placement","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name")].staticobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Place Axes Inside This Object","same"]]);
               }
               else{
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", CaluMath.PM.PlotlistObject.iframelist,CaluMath.PM.PlotlistObject.iframelist[0][0],[["Window","help/individual_help.html#requiredcm_caswindow"], "Axes Appear In This Window","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_insertoption", "menu", [["insert in selected iframe", "n/a"]], "insert in selected iframe", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Axes Placement","same"]]);
                   CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_inserttarget", "menu", [["n/a", "n/a"]], "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Place Axes Inside This Object","same"]]);
               };
            }
            else{
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", [["CM_MainWindow","CM_MainWindow"]], "CM_MainWindow", [["Window","help/individual_help.html#requiredcm_caswindow"], "Axes Appear In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_insertoption", "menu", [["current point", "n/a"],["insert in", "cm_insertin"]], "current point", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Axes Placement","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject["CM_MainWindow"].staticobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Place Axes Inside This Object","same"]]);
            };
         }
         else if(CaluMath.PM.IsEntirelyInStaticObjects(tempobject)=="no"){
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_caswindow", "menu", CaluMath.PM.PlotlistObject.iframelist,CaluMath.PM.PlotlistObject.iframelist[0][0],[["Window","help/individual_help.html#requiredcm_caswindow"], "Axes Appear In This Window","same"]]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_insertoption", "menu", [["insert in selected iframe", "n/a"]], "insert in selected iframe", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Axes Placement","same"]]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakernewplotDefault, "options", ["cm_inserttarget", "menu", [["n/a", "n/a"]], "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Place Axes Inside This Object","same"]]);
         };


         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "newplot", selectedlabel, "Axes"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var parentobject= tempobject.parent;
              var childindex= CaluMath.PM.ArrayIndex(parentobject.childarray, tempobject); 
              parentobject.childarray.splice(childindex,1);
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("newplot",tempobject);
            if(tempstring == null){
               return;
            };

           if((CaluMath.PM.InsertionArray.length != 0 && CaluMath.PM.InsertionArray.lastobject() == "newwindow") || CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject) !="yes" ){
              if(!CM_TopWindow.CM_EditMode){
                 CaluMath.PM.InsertStaticObject(tempobject); 
              }
              else if(CaluMath.PM.IsEntirelyInStaticObjects(tempobject)=="yes"){
                 CaluMath.PM.InsertStaticObject(tempobject,  oldinsertoption, oldinserttarget, oldcaswindow);
              };

           };



            //Comment: We have to be careful with newplot with regards to lists. newplot contains sublists of things plotted in it. These would get wiped out if the newplot list was recreated. Therefore we only want to create the newplot list when the object is constructed, not when it is modified. 
            if(!CM_TopWindow.CM_EditMode){
            };
            CaluMath.PM.AddToListsnewplot(tempobject, temprequired);

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="rescaleaxes"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("rescaleaxes", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         CaluMath.PM.PageMakerrescaleaxesDefault.required["newplot"].menu.onchange=function(){
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["width", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "width"), "Width In Inches Of Plot", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["height", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "height"), "Height In Inches Of Plot", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_xstart", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xstart"), "Beginning X Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_xfinish", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xfinish"), "Ending X Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_ystart", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_ystart"), "Beginning Y Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_yfinish", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_yfinish"), "Ending Y Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_yaxisat", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_yaxisat"), "X Coordinate of Y Axis", CaluMath.PM.IsEvalMath]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerrescaleaxesDefault, "required", ["cm_xaxisat", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xaxisat"), "X Coordinate of Y Axis", CaluMath.PM.IsEvalMath]);
         };
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "rescaleaxes", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerrescaleaxesDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerrescaleaxesDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("rescaleaxes",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="functionplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("functionplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         CaluMath.PM.PageMakerfunctionplotDefault.required["newplot"].menu.onchange=function(){
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerfunctionplotDefault, "required", ["cm_xstart", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xstart"), "Beginning X Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerfunctionplotDefault, "required", ["cm_xfinish", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xfinish"), "Ending X Value", CaluMath.PM.IsNumber]);
         };
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "functionplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerfunctionplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerfunctionplotDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("functionplot",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="discretefunctionplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("discretefunctionplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         CaluMath.PM.PageMakerdiscretefunctionplotDefault.required["newplot"].menu.onchange=function(){
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdiscretefunctionplotDefault, "required", ["cm_xstart", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xstart"), "Beginning X Value", CaluMath.PM.IsNumber]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdiscretefunctionplotDefault, "required", ["cm_xfinish", "input", 10, CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.newplotlist[this.options.selectedIndex][2], "cm_xfinish"), "Ending X Value", CaluMath.PM.IsNumber]);
         };
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "discretefunctionplot", selectedlabel, "Discrete Function Plot"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerdiscretefunctionplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerdiscretefunctionplotDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("discretefunctionplot",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="updatablefunctionplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("updatablefunctionplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "updatablefunctionplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerupdatablefunctionplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerupdatablefunctionplotDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("updatablefunctionplot",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };



            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="updatefunctionplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("updatefunctionplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var stopupdatefunctionplot = CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "updatablefunctionplotlist", "This Updatable Graph", "no"); 

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "updatefunctionplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerupdatefunctionplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerupdatefunctionplotDefault.required.newplot.menu.onfocus=null;
         };

         if(stopupdatefunctionplot == "yes"){
            alert("You have not created any Updatable Graphs. You cannot update them without doing this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("updatefunctionplot",tempobject);
            if(tempstring == null){
               return;
            };


            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.AssignParents();
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };


            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="updateareabetweenfunctionsplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("updateareabetweenfunctionsplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var stopupdateareabetweenfunctionsplot = CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "updatablefunctionplotlist", "This Updatable Graph", "no"); 

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "updateareabetweenfunctionsplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerupdateareabetweenfunctionsplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerupdateareabetweenfunctionsplotDefault.required.newplot.menu.onfocus=null;
         };

         if(stopupdateareabetweenfunctionsplot == "yes"){
            alert("You have not created any Updatable Graphs. You cannot update them without doing this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("updateareabetweenfunctionsplot",tempobject);
            if(tempstring == null){
               return;
            };


            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.AssignParents();
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };


            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="updateblanksegments"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("updateblanksegments", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var stopupdateblanksegments = CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "updatablefunctionplotlist", "This Updatable Graph", "no"); 

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "updateblanksegments", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerupdateblanksegmentsDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerupdateblanksegmentsDefault.required.newplot.menu.onfocus=null;
         };

         if(stopupdateblanksegments == "yes"){
            alert("You have not created any Updatable Graphs. You cannot update them without doing this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("updateblanksegments",tempobject);
            if(tempstring == null){
               return;
            };


            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.AssignParents();
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };


            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="updatetangentplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("updatetangentplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var stopupdatetangentplot =CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "updatablefunctionplotlist", "This Updatable Graph", "no"); 

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "updatetangentplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerupdatetangentplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerupdatetangentplotDefault.required.newplot.menu.onfocus=null;
         };

         if(stopupdatetangentplot == "yes"){
            alert("You have not created any Updatable Graphs. You cannot update them without doing this first.");
            cancelbuttonElement.onclick();
         };
         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("updatetangentplot",tempobject);
            if(tempstring == null){
               return;
            };


            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.AssignParents();
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].updatablefunctionplotlist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };


            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="slidingscale"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("slidingscale", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var stopslidingscales=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "cansupportbuttonslist", [["Graph", "help/individual_help.html#requiredgraph"], "Draw Tangent On This Graph", "same"], "no"); 

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "slidingscale", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerslidingscaleDefault.required.newplot.menu.onfocus=null;
//            CaluMath.PM.PageMakerslidingscaleDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerslidingscaleDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakerslidingscaleDefault.required.graph.menu.onfocus=null;
         };

/*
         //Comment: Near the top of the slidingscale section, we defined canaddslidingscales to be false, if there are no objects in any plot that can have a slidingscale drawn on them. In this case we want to exit the slidingscale screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stopslidingscales=="yes"){
            alert("You have not graphed anything yet that you can add Tangents to. Please do this first.");
            cancelbuttonElement.onclick();
         };
*/

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("slidingscale", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ //alerttest("slidingscale added");
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="activateslidingscale"){


         tempobject=CaluMath.PM.ObjectStandardBeginning("activateslidingscale", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var stopactivateslidingscale=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "slidingscale", "slidingscalelist", "Activate This Sliding Scale", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activateslidingscale", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopactivateslidingscale=="yes"){
//            alert("You have not created a sliding scale yet, so you cannot activate it. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         if(CaluMath.PM.PlotlistObject.slidingscalelist.length==0){
            alert("You must create a Sliding Scale before you can Activate it.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activateslidingscale",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivateslidingscale"){


         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivateslidingscale", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var stopdeactivateslidingscale=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "slidingscale", "slidingscalelist", "Activate This Sliding Scale", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivateslidingscale", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopdeactivateslidingscale=="yes"){
//            alert("You have not created a sliding scale yet, so you cannot deactivate it. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         if(CaluMath.PM.PlotlistObject.slidingscalelist.length==0){
            alert("You must create a Sliding Scale before you can Deactivate it.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivateslidingscale",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="arcplot"){

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("arcplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "arcplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerarcplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerarcplotDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("arcplot",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="labelvertex"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("labelvertex", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "labelvertex", selectedlabel, "Label A Vertex"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerlabelvertexDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerlabelvertexDefault.required.newplot.menu.onfocus=null;
         };

         var defaultobject = CaluMath.PM.PageMakerlabelvertexDefault;
         if(defaultobject.required["newplot"] != null ){
          //Comment: We then assign an onchange function that changes the list of functions to those associated with the chosen plot and buttontype. 
            defaultobject.required["newplot"].menu.onchange=function(){
               var optionsmenu= defaultobject.required["newplot"].menu.options;
               var selectedIndex= defaultobject.required["newplot"].menu.selectedIndex;
               CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddverticeslist, "Label Vertex On A Particular Graph", null, "no concat"));
               if(defaultobject.required["graph"] != null && optionsmenu[selectedIndex].value==tempobject.cm_getsetting("newplot")){
                   CaluMath.PM.MakeDefaultOption(defaultobject.required["graph"].menu, tempobject.cm_getsetting("graph"), "value"); 
               };
            };   
            //Comment": We actually invoke the onchange function to make sure the currently displayed menus are correct.
            defaultobject.required["newplot"].menu.onchange();
         };


         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("labelvertex",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="labelallvertices"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("labelallvertices", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This causes the default beginning and ending values displayed to change depending on the plot that is clicked. 
         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "labelallvertices", selectedlabel, "Label All Vertices"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerlabelallverticesDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerlabelallverticesDefault.required.newplot.menu.onfocus=null;
         };

         var defaultobject = CaluMath.PM.PageMakerlabelallverticesDefault;
         if(defaultobject.required["newplot"] != null ){
          //Comment: We then assign an onchange function that changes the list of functions to those associated with the chosen plot and buttontype. 
            defaultobject.required["newplot"].menu.onchange=function(){
               var optionsmenu= defaultobject.required["newplot"].menu.options;
               var selectedIndex= defaultobject.required["newplot"].menu.selectedIndex;
               CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddverticeslist, "Label Vertex On A Particular Graph", null, "no concat"));
               if(defaultobject.required["graph"] != null && optionsmenu[selectedIndex].value==tempobject.cm_getsetting("newplot")){
                   CaluMath.PM.MakeDefaultOption(defaultobject.required["graph"].menu, tempobject.cm_getsetting("graph"), "value"); 
               };
            };   
            //Comment": We actually invoke the onchange function to make sure the currently displayed menus are correct.
            defaultobject.required["newplot"].menu.onchange();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("labelallvertices",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="animationplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         //Comment: This is a standard beginning for math objects. Note that we call CaluMath.PM.MakeOptions here instead of in the beginning of this file, since we need current options for newplotlist and definedfunctionlist.

         tempobject=CaluMath.PM.ObjectStandardBeginning("animationplot", arguments[0]);

         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "animationplot", selectedlabel, "Graph of Function"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakeranimationplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakeranimationplotDefault.required.newplot.menu.onfocus=null;

         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("animationplot",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired) ){  
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="tangent"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("tangent", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stoptangents=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "canaddtangentslist", [["Graph", "help/individual_help.html#requiredgraph"], "Draw Tangent On This Graph", "same"], "yes"); 

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "tangent", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakertangentDefault.required.newplot.menu.onfocus=null;
            CaluMath.PM.PageMakertangentDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakertangentDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakertangentDefault.required.graph.menu.onfocus=null;
         };


         //Comment: Near the top of the tangent section, we defined canaddtangents to be false, if there are no objects in any plot that can have a tangent drawn on them. In this case we want to exit the tangent screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stoptangents=="yes"){
            alert("You have not graphed anything yet that you can add Tangents to. Please do this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("tangent", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ //alerttest("tangent added");
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].canaddtangentslist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].canaddtangentslist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="movepoint"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("movepoint", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopmovepoint= CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "pointslist", "Move This Point", "no"); 

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "movepoint", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakermovepointDefault.required.newplot.menu.onfocus=null;
//            CaluMath.PM.PageMakermovepointDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakermovepointDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakermovepointDefault.required.graph.menu.onfocus=null;
         };


         //Comment: Near the top of the movepoint section, we defined pointplotlist to be false, if there are no objects in any plot that can have a movepoint drawn on them. In this case we want to exit the movepoint screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stopmovepoint=="yes"){
            alert("You have not graphed any points yet. Please do this before you try to move them.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("movepoint", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ //alerttest("movepoint added");
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="movetextplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("movetextplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopmovetextplot= CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "textplotlist", "Move This Text Plot", "no"); 

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "movetextplot", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };


         //Comment: Near the top of the movetextplot section, we defined textplotplotlist to be false, if there are no objects in any plot that can have a movetextplot drawn on them. In this case we want to exit the movetextplot screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stopmovetextplot=="yes"){
            alert("You have not graphed any Text Plots yet. Please do this before you try to move them.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("movetextplot", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ //alerttest("movepoint added");
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="moverectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("moverectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopmoverectangle= CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "Move This Point", "no"); 

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "moverectangle", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakermoverectangleDefault.required.newplot.menu.onfocus=null;
//            CaluMath.PM.PageMakermoverectangleDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakermoverectangleDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakermoverectangleDefault.required.graph.menu.onfocus=null;
         };


         //Comment: Near the top of the moverectangle section, we defined rectangleplotlist to be false, if there are no objects in any plot that can have a moverectangle drawn on them. In this case we want to exit the moverectangle screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stopmoverectangle=="yes"){
            alert("You have not graphed any rectangles yet. Please do this before you try to move them.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("moverectangle", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ //alerttest("moverectangle added");
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="highlight"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("highlight", arguments[0]);


         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stophighlights= CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "canaddhighlightslist", [["Graph", "help/individual_help.html#requiredgraph"], "Highlight Point On This Graph", "same"], "yes"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "highlight", selectedlabel, "Graph of Highlight"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerhighlightDefault.required.newplot.menu.onfocus=null;
//            CaluMath.PM.PageMakerhighlightDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerhighlightDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakerhighlightDefault.required.definedfunction.menu.onfocus=null;
         };

         //Comment: Near the top of the highlight section, we defined canaddhighlights to be false, if there are no objects in any plot that can have points highlighted. In this case we want to exit the highlight screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stophighlights == "yes"){
            alert("You have not drawn a graph of any object that can have points highlighted on it in any set of axes. You cannot draw any highlights without doing this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("highlight",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.AssignParents();
               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].canaddhighlightslist.cm_obtainindex(temprequired.graph,0);
               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].canaddhighlightslist[childindex][2];
               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };
//            CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired);


            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="rectangleplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("rectangleplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "rectangleplot", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerrectangleplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("rectangleplot",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="activatedragrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("activatedragrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopactivatedragrectangle=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "List Of Rectangles", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activatedragrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         if(stopactivatedragrectangle=="yes"){
            alert("You have not graphed rectangles yet, so you cannot drag any rectangles. Please do this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activatedragrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivatedragrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivatedragrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivatedragrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivatedragrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivateclickableaxes"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivateclickableaxes", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivateclickableaxes", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivateclickableaxes",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="activatestretchrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("activatestretchrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopactivatestretchrectangle=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "List Of Rectangles", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activatestretchrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         if(stopactivatestretchrectangle=="yes"){
            alert("You have not graphed rectangles yet, so you cannot stretch any rectangles. Please do this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activatestretchrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivatestretchrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivatestretchrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
//         var stopdeactivatestretchrectangle=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "Stop Dragging This Rectangle", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivatestretchrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopdeactivatestretchrectangle=="yes"){
//            alert("You have not graphed rectangles yet, so you cannot stretch any rectangles. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivatestretchrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="activateviewrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("activateviewrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

  //       var stopactivateviewrectangle=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "Drag This Rectangle", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activateviewrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopactivateviewrectangle=="yes"){
//            alert("You have not graphed rectangles yet, so you cannot view any rectangles. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activateviewrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivateviewrectangle"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivateviewrectangle", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
//         var stopdeactivateviewrectangle=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "rectangleslist", "Stop Dragging This Rectangle", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivateviewrectangle", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopdeactivateviewrectangle=="yes"){
//            alert("You have not graphed rectangles yet, so you cannot view any rectangles. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivateviewrectangle",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="pointplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("pointplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "pointplot", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerpointplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("pointplot",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="activatecapturedragpath"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("activatecapturedragpath", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activatecapturedragpath", selectedlabel, "Draggable Objects"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activatecapturedragpath",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivatecapturedragpath"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivatecapturedragpath", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivatecapturedragpath", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivatecapturedragpath",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="activatedragpoint"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("activatedragpoint", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopactivatedragpoint=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "pointslist", "List Of Points", "no"); 


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "activatedragpoint", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         if(stopactivatedragpoint=="yes"){
            alert("You have not graphed points yet, so you cannot drag any points. Please do this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("activatedragpoint",tempobject);
            if(tempstring == null){
               return;
            };

//CM_PageMakeractivatedragpointDefault.required.graph.menu.size

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deactivatedragpoint"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("deactivatedragpoint", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
//         var stopdeactivatedragpoint=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "pointslist", "Stop Dragging This Point", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "deactivatedragpoint", selectedlabel, "Graph Of A Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

//         if(stopdeactivatedragpoint=="yes"){
//            alert("You have not graphed points yet, so you cannot drag any points. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("deactivatedragpoint",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="cm_alert"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("cm_alert", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         CaluMath.PM.PageMakercm_alertDefault.required.text.input.value= tempobject.cm_getsetting("text").replace(/\&lt\;/g, "<").replace(/\&gt\;/g, ">");
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "cm_alert", selectedlabel, "Alert"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("cm_alert",tempobject);
            if(tempstring == null){
               return;
            };
       
            var tempenteredstring=tempobject.cm_getsetting("text").cm_escapebackslashes().replace(/\'/g, "CM_SINGLEQUOTE").replace(/\"/g, "CM_DOUBLEQUOTE").cm_replaceendoflinecharacters().cm_replaceinequalitysymbols().replace(/\&lt\;\s*br\s*\&gt\;/g,"<br>");
            tempobject.cm_setrequired("text", tempenteredstring);

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
//               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };
 
            //Comment: The entry is automatically considered to be text, so it does not need to be enclosed in quotes of any kind. Single and Double Quotes can be used in any fashion in the entry without causing an error. 
            CaluMath.PM.SetWriteTag(tempobject);  
//            tempobject.childarray[0].writestring= 'Here is a cm_alert : ';
//            tempobject.beginstring= tempobject.childarray[1].beginstring+temprequired.alerttype+'("';
//            tempobject.writestring=temprequired.text.cm_escapedoublequotes();  
//            tempobject.endstring= '".cm_unescapequotes().cm_javascript())\; ' +tempobject.childarray[1].endstring; 
 
         
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="javascript"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("javascript", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var temptextarea=document.createElement("textarea");
         document.getElementById("displayleft").appendChild(temptextarea);
         temptextarea.setAttribute("rows",10);
         temptextarea.setAttribute("cols",120);

         if(CM_TopWindow.CM_EditMode){
            var tempnumberofrows=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"command").match(/CM_NEWLINEREPLACEMENT/g);
            if(tempnumberofrows != null){
               tempnumberofrows=tempnumberofrows.length;
            }
            else{
               tempnumberofrows=0;
            };
            temptextarea.setAttribute("rows",Math.max(3+tempnumberofrows + (3/2)*CaluMath.PM.GetPageMakerObjectSetting(tempobject,"command").length/80,10));
            temptextarea.value=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"command").replace(/CM_NEWLINEREPLACEMENT/g,"\n").cm_unescapequotes();
         };

         window.location.hash="#endofdocument"; 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "javascript", selectedlabel, "JavaScript Command"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            temptextarea.parentNode.removeChild(temptextarea);
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              temptextarea.parentNode.removeChild(temptextarea);

         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("javascript",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
            };
           
//            tempobject.cm_requiredarray=[["command", temptextarea.value.replace(/\n/g," ").cm_escapequotes()]];
            tempobject.cm_requiredarray=[["command", temptextarea.value.cm_replaceendoflinecharacters().cm_escapequotes()]];

            //Comment: When entering a JavaScript command, Single Quotes must be used to denote strings. For example, A='Here is "Steve\'s House"' will be OK. Several commands can be entered, using a semicolon between them. Subsequent commands can be on new lines or on the same line. 

            temptextarea.parentNode.removeChild(temptextarea);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="comment"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("comment", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var temptextarea=document.createElement("textarea");
         document.getElementById("displayleft").appendChild(temptextarea);
         temptextarea.setAttribute("rows",10);
         temptextarea.setAttribute("cols",120);

         if(CM_TopWindow.CM_EditMode){
            var tempnumberofrows=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"comment").match(/CM_NEWLINEREPLACEMENT/g);
            if(tempnumberofrows != null){
               tempnumberofrows=tempnumberofrows.length;
            }
            else{
               tempnumberofrows=0;
            };
            temptextarea.setAttribute("rows",Math.max(3+tempnumberofrows + (3/2)*CaluMath.PM.GetPageMakerObjectSetting(tempobject,"comment").length/80,10));
            temptextarea.value=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"comment").replace(/CM_NEWLINEREPLACEMENT/g,"\n").cm_unescapequotes();
         };

         window.location.hash="#endofdocument"; 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "comment", selectedlabel, "Comment"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            temptextarea.parentNode.removeChild(temptextarea);
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              temptextarea.parentNode.removeChild(temptextarea);

         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("comment",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
            };
           
            tempobject.cm_requiredarray=[["comment", temptextarea.value.cm_replaceendoflinecharacters().cm_escapequotes()]];


            temptextarea.parentNode.removeChild(temptextarea);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="addhtml"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("addhtml", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var temptextarea=document.createElement("textarea");
         document.getElementById("displayleft").appendChild(temptextarea);
         temptextarea.setAttribute("rows",10);
         temptextarea.setAttribute("cols",120);

         if(CM_TopWindow.CM_EditMode){
            var tempnumberofrows=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"addhtml").match(/CM_NEWLINEREPLACEMENT/g);
            if(tempnumberofrows != null){
               tempnumberofrows=tempnumberofrows.length;
            }
            else{
               tempnumberofrows=0;
            };
            temptextarea.setAttribute("rows",Math.max(3+tempnumberofrows + (3/2)*CaluMath.PM.GetPageMakerObjectSetting(tempobject,"addhtml").length/80,10));
            temptextarea.value=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"addhtml").cm_unescapequotes().cm_unescapebackslashes().replace(/CM_HTMLOPENINGTAGREPLACEMENT/g,"<").replace(/CM_NEWLINEREPLACEMENT/g,"\n");
         };

         window.location.hash="#endofdocument"; 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addhtml", selectedlabel, "Add Html"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            temptextarea.parentNode.removeChild(temptextarea);
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              temptextarea.parentNode.removeChild(temptextarea);

         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("addhtml",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
            };
           
//            tempobject.cm_requiredarray=[["addhtml", temptextarea.value.replace(/\r/g,"").replace(/\n/g,"CM_NEWLINE").cm_escapebackslashes().cm_escapequotes()]];
            tempobject.cm_requiredarray=[["addhtml", temptextarea.value.cm_replaceendoflinecharacters().cm_escapebackslashes().cm_escapequotes().replace(/\</g,"CM_HTMLOPENINGTAGREPLACEMENT")]];

            temptextarea.parentNode.removeChild(temptextarea);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="headhtml"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("headhtml", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var temptextarea=document.createElement("textarea");
         document.getElementById("displayleft").appendChild(temptextarea);
         temptextarea.setAttribute("rows",10);
         temptextarea.setAttribute("cols",120);

         if(CM_TopWindow.CM_EditMode){
            var tempnumberofrows=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"headhtml").match(/CM_NEWLINEREPLACEMENT/g);
            if(tempnumberofrows != null){
               tempnumberofrows=tempnumberofrows.length;
            }
            else{
               tempnumberofrows=0;
            };
            temptextarea.setAttribute("rows",Math.max(3+tempnumberofrows + (3/2)*CaluMath.PM.GetPageMakerObjectSetting(tempobject,"headhtml").length/80,10));
            temptextarea.value=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"headhtml").cm_unescapequotes().cm_unescapebackslashes().replace(/CM_HTMLOPENINGTAGREPLACEMENT/g,"<").replace(/CM_NEWLINEREPLACEMENT/g,"\n");
         };

         window.location.hash="#endofdocument"; 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "headhtml", selectedlabel, "Head Html"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            temptextarea.parentNode.removeChild(temptextarea);
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              temptextarea.parentNode.removeChild(temptextarea);

         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("headhtml",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               var tempindex=CaluMath.PM.HeadHtmlInsertionPoint();
               CaluMath.PM.PageMakerObjectArray.splice(tempindex,0,tempobject);
            };
           
            tempobject.cm_requiredarray=[["headhtml", temptextarea.value.cm_replaceendoflinecharacters().cm_escapebackslashes().cm_escapequotes().replace(/\</g,"CM_HTMLOPENINGTAGREPLACEMENT")]];


            temptextarea.parentNode.removeChild(temptextarea);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="textplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("textplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
//         if(CM_TopWindow.CM_EditMode){
//            if(CaluMath.PM.PageMakertextplotDefault.required.newplot != null){
//               CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.onfocus=function(){
//                  cm_alert("You cannot change the axis or the graph that the object is associated with while in Edit Mode. If you want, delete the object, and then associate it to whatever axis or graph that you want.");
//                  CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.blur();
//                  if(CaluMath.PM.PageMakertextplotDefault.required.definedfunction != null){
//                     CaluMath.PM.PageMakertextplotDefault.required.definedfunction.menu.blur();
//                    CaluMath.PM.PageMakertextplotDefault.required.definedfunction.menu.onfocus=CaluMath.PM.PageMakertextplotDefault.required.definedfunction.menu.blur;
//                  };
//                  CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.onfocus=CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.blur;
//               };
//               if(CaluMath.PM.PageMakertextplotDefault.required.definedfunction != null){
//                  CaluMath.PM.PageMakertextplotDefault.required.definedfunction.menu.onfocus =CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.onfocus;
//               };
//            };
//         };

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "textplot", selectedlabel, "Text Plot"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            if(CaluMath.PM.PageMakertextplotDefault.required.newplot != null && CaluMath.PM.PageMakertextplotDefault.required.newplot.menu != null){
               CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.onfocus=null;
            };
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              if(CaluMath.PM.PageMakertextplotDefault.required.newplot != null && CaluMath.PM.PageMakertextplotDefault.required.newplot.menu != null){
                 CaluMath.PM.PageMakertextplotDefault.required.newplot.menu.onfocus=null;
              };
         };

         var temponchangefunction= function(){
            var selectedIndex= CaluMath.PM.PageMakertextplotDefault.required["graph"].menu.selectedIndex;
               if(selectedIndex !=0){
                  CaluMath.PM.PageMakertextplotDefault.required.cm_ycoordinate.input.value="default";
               }
               else if(CaluMath.PM.PageMakertextplotDefault.required.cm_ycoordinate.input.value.match(/default/)){
                  CaluMath.PM.PageMakertextplotDefault.required.cm_ycoordinate.input.value="";
               };
         };


         if( CaluMath.PM.PageMakertextplotDefault.required["newplot"] != null ){
          //Comment: We then assign an onchange function that changes the list of functions to those associated with the chosen plot and buttontype. 
            CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu.onchange=function(){
               var optionsmenu= CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu.options;
               var selectedIndex= CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu.selectedIndex;
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertextplotDefault, "required", ["graph", "menu", [["none","none"]].concat(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddtextplotslist), "none", [["Graph", "help/individual_help.html#requiredgraph"], "Highlight Point On This Graph", "same"]]);
               CaluMath.PM.PageMakertextplotDefault.required["graph"].menu.onchange=temponchangefunction;
            //Comment: We actually invoke the onchange function to make sure the currently displayed menus are correct.
            };
            CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu.onchange();

            //Comment: We actually invoke the onchange function to make sure the currently displayed menus are correct.
            CaluMath.PM.PageMakertextplotDefault.required["graph"].menu.onchange();
         };

         CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu.onchange();

         if(CM_EditMode){
               CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertextplotDefault.required["newplot"].menu, tempobject.cm_getsetting("newplot"),"value");
               CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertextplotDefault.required["graph"].menu, tempobject.cm_getsetting("graph"),"value");
               if(CaluMath.PM.PageMakertextplotDefault.required["graph"].menu.options.selectedIndex>0){
                  CaluMath.PM.PageMakertextplotDefault.required.cm_ycoordinate.input.value="default";
               };
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("textplot",tempobject);
            if(tempstring == null){
               return;
            };
            if(temprequired.graph == "none" && temprequired.cm_ycoordinate == "default"){
               //Comment: The onchange function automatically puts "default" as the y value if a graph is chosen. This will pass the default check, and is correct for defined functions, since they do not require a y value. However, a y value needs to inputted if no defined function is given. 
               return cm_alert('Since your textplot is for a set of axes, and not the graph of a function, you must include a y value, and not the word "default."') 
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               if(temprequired.graph=="none"){
//                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.push(tempobject);
               }
               else{
                  CaluMath.PM.PlotlistObject[temprequired.newplot].canaddtextplotslist[CaluMath.PM.PlotlistObject[temprequired.newplot].canaddtextplotslist.cm_obtainindex(temprequired.graph,0)][2].childarray.push(tempobject);
               };
            };

            //Comment: The entry is automatically treated as text. You do not need to enclose the entry in quotes of any kind. Single and Double quotes can be used in the entry and will appear as typed. 

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="labelplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("labelplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that they cannot change the axis on which the label is drawn. 
//         if(CM_TopWindow.CM_EditMode){
//            CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.onfocus=function(){
//               cm_alert("You cannot change the axis that the label is drawn on while in Edit Mode. If you want, delete the label, and then draw it on the axes that you want.");
//               CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.blur();
//               CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.onfocus=CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.blur;
//            };
//         };

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "labelplot", selectedlabel, "Label An Axis Coordinate"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakerlabelplotDefault.required.newplot.menu.onfocus=null;
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("labelplot",tempobject);
            if(tempstring == null){ 
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
//            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
                  CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
//               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="linearplot"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("linearplot", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "linearplot", selectedlabel, "Line Segment Graph"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("linearplot",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };


            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="addlinearplotsegment"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addlinearplotsegment", arguments[0]);


         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var stopaddlinearplotsegments= CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "linearplotlist", "Line Segment Graph"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addlinearplotsegment", selectedlabel, "Segment"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         //Comment: Near the top of the addlinearplotsegment section, we defined canaddaddlinearplotsegments to be false, if there are no objects in any plot that can have segments added. In this case we want to exit the addlinearplotsegment screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(stopaddlinearplotsegments == "yes"){
            alert("You have not drawn any Line Segment Graphs in any set of axes. You cannot add segments to a Line Segment Graph without doing this first.");
            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
            var tempstring=CaluMath.PM.CreateSettingsArrays("addlinearplotsegment",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 

               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
//               CaluMath.PM.AssignParents();
//               var childindex= CaluMath.PM.PlotlistObject[temprequired.newplot].linearplotlist.cm_obtainindex(temprequired.graph,0);
//               var tempparent=CaluMath.PM.PlotlistObject[temprequired.newplot].linearplotlist[childindex][2];
//               tempparent.childarray=tempparent.childarray.concat(tempobject);
            };
            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };   
      }
      else if(selectedvalue=="linkedddd"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("link", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         try{
           CaluMath.PM.PageMakerlinkDefault.required.address.input.setAttribute("type","file");
         }
         catch(e){CaluMath.Html.NullFunction();
         };

         if(CM_TopWindow.CM_EditMode){
            var oldaddress=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"address");
         };  
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "link", selectedlabel, "Link"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("link",tempobject);
            if(tempstring == null){
               return;
            };

            if(tempobject.cm_getsetting("address").length==0 && CM_EditMode){
               tempobject.cm_setrequired("address", tempobject.oldaddress);
            }
            else if(tempobject.cm_getsetting("exactaddress")=="no"){
               var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
               var address=tempobject.cm_getsetting("address").replace(/\\/g,"/").replace(/^[\/\"\/]/,'');
               while(pathname.charAt(0)==address.charAt(0)){
                  pathname=pathname.slice(1); 
                  address=address.slice(1);
               };
               if(pathname.match(/\//)){
                  var numberofforwardslashes= pathname.split("/").length;
                  var tempdots="";
                  for(var i=1; i<numberofforwardslashes; i++){
                     tempdots=tempdots+"../";
                  };
                  tempdots= tempdots+address;
                  tempobject.cm_setrequired("address", tempdots);  
               }
               else{
                  tempobject.cm_setrequired("address", address);
               };
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);  

            tempobject.childarray[0].writestring ="Here is "+temprequired.name+", a Link to the file "+temprequired.address+". ";
            tempstring=tempstring + 'name='+temprequired.name+'"';
            tempobject.beginstring= tempobject.beginstring+'\'<a href=CaluMath.PM.DOUBLEQUOTE'+temprequired.address+'CM_DOUBLEQUOTE >';
            tempobject.writestring=temprequired.description.cm_escapequotes();  
            tempobject.endstring= '<CaluMath.PM.FORWARDSLASHa>\'.cm_unescapequotes().cm_javascript().cm_html("'+tempstring+')\; ' +tempobject.endstring; 


            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="image" || selectedvalue=="link"){
         if(selectedvalue=="image"){
            var tempobject=CaluMath.PM.ObjectStandardBeginning("image", arguments[0]);
            try{
               CaluMath.PM.PageMakerimageDefault.required.address.input.setAttribute("type","file");
            }
            catch(e){CaluMath.Html.NullFunction();
            };
         }
         else{
            var tempobject=CaluMath.PM.ObjectStandardBeginning("link", arguments[0]);
            try{
               CaluMath.PM.PageMakerlinkDefault.required.address.input.setAttribute("type","file");
            }
            catch(e){ CaluMath.Html.NullFunction();
            };
         }
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            tempobject.oldaddress=tempobject.cm_getsetting("address");
         };  
         if(selectedvalue=="image"){
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "image", selectedlabel, "Image"); 
         }
         else{
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "link", selectedlabel, "Link"); 
         };
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            if(selectedvalue=="image"){
               var tempstring=CaluMath.PM.CreateSettingsArrays("image",tempobject);
            }
            else{
               var tempstring=CaluMath.PM.CreateSettingsArrays("link",tempobject);
            };
            if(tempstring == null){
               return;
            };
            if(tempobject.cm_getsetting("address").length==0 && CM_EditMode){
               tempobject.cm_setrequired("address", tempobject.oldaddress);
            }
            else if(tempobject.cm_getsetting("exactaddress")=="no"){
               var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
               var address=tempobject.cm_getsetting("address").cm_unescapequotes().cm_unescapebackslashes().replace(/\\/g,"/").replace(/^[\/\"\/]/,'');
               var addressmatch=address.match(/CaluMath/);
               if(addressmatch == null && address != "reload"){
                  alert("Your "+selectedvalue+" is not located somewhere in the CaluMath folder. In this case you must use the Exact Address option.");  
               }
               else{
                  if(address != "reload"){
                     address=address.slice(addressmatch.index+9); 
                     tempobject.cm_setrequired("address",address);
                  }
                  else{
                     tempobject.cm_setrequired("address",address);
                  };
               };
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="changelinks"){

         var tempobject=CaluMath.PM.ObjectStandardBeginning("changelinks", arguments[0]);
         try{
            CaluMath.PM.PageMakerchangelinksDefault.required.address.input.setAttribute("type","file");
         }
         catch(e){ CaluMath.Html.NullFunction();
         };
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "link", selectedlabel, "Link"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("changelinks",tempobject);
            if(tempstring == null){
               return;
            };

            if(tempobject.cm_getsetting("exactaddress")=="no"){
               var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
               var address=tempobject.cm_getsetting("address").cm_unescapequotes().cm_unescapebackslashes().replace(/\\/g,"/").replace(/^[\/\"\/]/,'');
               var addressmatch=address.match(/CaluMath/);
               if(addressmatch == null){
                  alert("Your "+selectedvalue+" is not located somewhere in the CaluMath folder. In this case you must use the Exact Address option.");  
               }
               else{
                  address=address.slice(addressmatch.index+9); 
                  tempobject.cm_setrequired("address",address);
               };
            };

            var tempaddress=tempobject.cm_getsetting("oldaddress");
            var tempnewaddress=tempobject.cm_getsetting("address");
            var tempdescription=tempobject.cm_getsetting("description");
            var templist = CaluMath.PM.PlotlistObject.linkslist;
            var templistlength=templist.length;
            if(tempdescription.length ==0){
               for(var i=0; i<templistlength; i++){
                  if(templist[i][2].cm_getsetting("address")==tempaddress){
                     templist[i][2].cm_setrequired("address", tempnewaddress);
                     templist[i][0]=tempnewaddress;
                     templist[i][1]=tempnewaddress;
                  };
               };
            }
            else{
                for(var i=0; i<templistlength; i++){
                  if(templist[i][2].cm_getsetting("address")==tempaddress){
                     templist[i][2].cm_setrequired("address", tempnewaddress);
                     templist[i][2].cm_setrequired("description", tempdescription);
                     templist[i][0]=tempnewaddress;
                     templist[i][1]=tempnewaddress;
                  };
               };
            };
         
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="changeimages"){

         var tempobject=CaluMath.PM.ObjectStandardBeginning("changeimages", arguments[0]);
         try{
            CaluMath.PM.PageMakerchangeimagesDefault.required.address.input.setAttribute("type","file");
         }
         catch(e){ CaluMath.Html.NullFunction();
         };
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "image", selectedlabel, "Image"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("changeimages",tempobject);
            if(tempstring == null){
               return;
            };

            if(tempobject.cm_getsetting("exactaddress")=="no"){
               var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
               var address=tempobject.cm_getsetting("address").cm_unescapequotes().cm_unescapebackslashes().replace(/\\/g,"/").replace(/^[\/\"\/]/,'');
               var addressmatch=address.match(/CaluMath/);
               if(addressmatch == null){
                  alert("Your "+selectedvalue+" is not located somewhere in the CaluMath folder. In this case you must use the Exact Address option.");  
               }
               else{
                  address=address.slice(addressmatch.index+9); 
                  tempobject.cm_setrequired("address",address);
               };
            };

            var tempaddress=tempobject.cm_getsetting("oldaddress");
            var tempnewaddress=tempobject.cm_getsetting("address");
            var tempdescription=tempobject.cm_getsetting("description");
            var templist = CaluMath.PM.PlotlistObject.imageslist;
            var templistlength=templist.length;
            if(tempdescription.length ==0){
               for(var i=0; i<templistlength; i++){
                  if(templist[i][2].cm_getsetting("address")==tempaddress){
                     templist[i][2].cm_setrequired("address", tempnewaddress);
                     templist[i][0]=tempnewaddress;
                     templist[i][1]=tempnewaddress;
                  };
               };
            }
            else{
                for(var i=0; i<templistlength; i++){
                  if(templist[i][2].cm_getsetting("address")==tempaddress){
                     templist[i][2].cm_setrequired("address", tempnewaddress);
                     templist[i][2].cm_setrequired("description", tempdescription);
                     templist[i][0]=tempnewaddress;
                     templist[i][1]=tempnewaddress;
                  };
               };
            };
         
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="hideandunhidegraph"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("hideandunhidegraph", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "hideandunhidegraph", selectedlabel, "Hide And Unhide Graph"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };


         var temparray=CaluMath.PM.PlotlistObject.namedobjectlist.concat(CaluMath.PM.PlotlistObject.graphlist);
        

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("hideandunhidegraph",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };


//            var tempindex = CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.graphlist,temprequired.graph,0); 
//            var tempgraph= CaluMath.PM.PlotlistObject.graphlist[tempindex][2];
            //Comment: We want the value, not the label below. Therefore the index is 1. For hideandunhide (HTML case) the index is a 0, I can't recall why though at the moment. 
            var tempindex = CaluMath.PM.ArrayIndex(temparray,temprequired.graph,1); 
            var tempgraph= temparray[tempindex][2];
            tempobject.cm_setrequired("graphfullname", CaluMath.PM.GetPageMakerGraphFullName(tempgraph));

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="removegraph"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("removegraph", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "removegraph", selectedlabel, "Remove Graph"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("removegraph",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly a child of another element. If it does not automatically place the object, then it means we are not in a buttonaction or routine or conditional or other such special object. In this case we return an alert that they cannot use removegraph except for things like buttonactions or conditionals...., not in normal mode. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){ 
               cm_alert("You cannot use remove graph unless you are in a button action, routine, conditional, or similar mode. If you merely do not like the way a graph appears in your page and you want to delete it, choose Edit Page, click on item corresponding to the graph, and delete the object.");
               cancelbuttonElement.onclick();
               return ;
            };

            var tempindex = CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.graphlist,temprequired.graph,0); 
            var tempgraph= CaluMath.PM.PlotlistObject.graphlist[tempindex][2];
            tempobject.cm_setrequired("graphfullname", CaluMath.PM.GetPageMakerGraphFullName(tempgraph));

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="nameclickedpoint"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("nameclickedpoint", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "nameclickedpoint", selectedlabel, "Name Clicked Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempobjectparent=tempobject.parent; 
            var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
            tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("nameclickedpoint",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: nameclickedpoint should never be used outside of a button action (or inside a subobject contained in a buttonaction. Therefore this option of "no" should never come up.
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
//               cm_alert("There is a problem. nameclickedpoint should only be used in a buttonaction or an object contained in a buttonaction.")
               if(confirm("There is a problem. "+CaluMath.PM.PageMakerObjectLabelName("nameclickedpoint")+" should only be used in a Button Action or an object contained in a Button Action. Click OK if you know what you are doing (for example, you are going to cut and paste it into a Button Action), otherwise click Cancel.")){
                  CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
               }
               else{
                  return cancelbuttonElement.onclick();
               };
            };
            //Comment: This causes the phony value [0,0] to be given in CM_TopWindow. We need this so that some value is defined for the clicked point name and doesn't cause an error. 
            eval(temprequired.name+'=[0,0]');  
            eval(temprequired.name+'.x=0');
            eval(temprequired.name+'.y=0');

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="nameanimationvalue"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("nameanimationvalue", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "nameanimationvalue", selectedlabel, "Name Clicked Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempobjectparent=tempobject.parent; 
            var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
            tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.animationplotlist==null || CaluMath.PM.PlotlistObject.animationplotlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any animations. Please do so before trying to name an Animation Running Value.");
            return cancelbuttonElement.onclick();
         };


         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("nameanimationvalue",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: nameanimationvalue should never be used outside of a button action (or inside a subobject contained in a buttonaction. Therefore this option of "no" should never come up.
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
//               cm_alert("There is a problem. nameanimationvalue should only be used in a buttonaction or an object contained in a buttonaction.")
//               return cancelbuttonElement.onclick();
               if(confirm("There is a problem. "+CaluMath.PM.PageMakerObjectLabelName("nameanimationvalue")+" should only be used in a Routine associated with an Animation. Click OK if you know what you are doing (for example, you are going to cut and paste it into a Routine), otherwise click Cancel.")){
                  CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
               }
               else{
                  return cancelbuttonElement.onclick();
               };
            };
            //Comment: This causes the phony value [0,0] to be given in CM_TopWindow. We need this so that some value is defined for the clicked point name and doesn't cause an error. 
            eval(temprequired.name+'=[0,0]');  
            eval(temprequired.name+'.x=0');
            eval(temprequired.name+'.y=0');

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="namedraggedvalue"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("namedraggedvalue", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "namedraggedvalue", selectedlabel, "Name Clicked Point"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempobjectparent=tempobject.parent; 
            var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
            tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("namedraggedvalue",tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: namedraggedvalue should never be used outside of a button action (or inside a subobject contained in a buttonaction. Therefore this option of "no" should never come up.
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
//               cm_alert("There is a problem. namedraggedvalue should only be used in a buttonaction or an object contained in a buttonaction.")
//               return cancelbuttonElement.onclick();
               if(confirm("There is a problem. "+CaluMath.PM.PageMakerObjectLabelName("namedraggedvalue")+" should only be used in a Routine associated with Dragging Objects. Click OK if you know what you are doing (for example, you are going to cut and paste it into a Routine), otherwise click Cancel.")){
                  CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
               }
               else{
                  return cancelbuttonElement.onclick();
               };
            };
            //Comment: This causes the phony value [0,0] to be given in CM_TopWindow. We need this so that some value is defined for the clicked point name and doesn't cause an error. 
            eval(temprequired.name+'=[0,0]');  
            eval(temprequired.name+'.x=0');
            eval(temprequired.name+'.y=0');

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="comparison"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("comparison", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "comparison", selectedlabel, "Comparison"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick= function(){
            if(CM_TopWindow.CaluMath.PM.InsertionArray.length != 0 && CM_TopWindow.CaluMath.PM.InsertionArray.lastobject().type =="conditional"){
               return cm_alert("You are in the middle of a Conditional. If you cancel the comparison, the Conditional will cause an error. Please finish the comparison (even if you put in data that you do not want). You can modify the comparison or delete the conditional later.");
            }
            else{
               cancelbuttonElement.standardonclick();
            };
         };    

         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempobjectparent=tempobject.parent; 
            var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
            tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
//            CaluMath.PM.PageMakercomparisonDefault.required.newplot.menu.onfocus=null;
         };


         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("comparison",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
            };

            //Comment: when checking comparisons with non numeric data, you must use the equals option instead of =. You also need to enclose the right hand side in quotes if it is a String. It does not appear that it matters which quotes are used. 
            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="tangentclickbutton" || selectedvalue=="highlightclickbutton" || selectedvalue=="pointclickbutton" || selectedvalue=="removeclickbutton" || selectedvalue=="endremoveclickbutton" || selectedvalue=="calculatorbutton" || selectedvalue=="javascriptbutton" || selectedvalue=="enterbutton" || selectedvalue=="input" || selectedvalue=="output" || selectedvalue=="select" || selectedvalue=="inputtext" || selectedvalue=="inputarea" || selectedvalue=="button"  || selectedvalue=="clickbutton" || selectedvalue=="boxes" || selectedvalue=="dropdownmenu"  ){

         //Comment: Recall that the local variable selectedvalue, defined at the very top of CaluMath.PM.MATHBUTTON.onclick is the variable causing the cases. 

         try{
            tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         }
         catch(e){
            cm_alert("An error is being encountered at this point. Are you sure that you have axes plotted before you tried to construct buttons that control things being plotted on the axes?");
//            return [PAGECONTROLCONTAINER.style.display="block", PAGEASSISTCONTAINER.style.display="none"];
              return [CaluMath.PM.DisplayPageControls()]; 

         };
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         var defaultobject = eval("CaluMath.PM.PageMaker"+selectedvalue+"Default");


         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];

         if(selectedvalue=="boxes" || selectedvalue=="dropdownmenu" ){
            var tempexpandbutton=document.createElement("input");
            tempexpandbutton.setAttribute("type","button");
            tempexpandbutton.setAttribute("value","Double The Size Of The Choices Box");
            document.body.insertBefore(tempexpandbutton,document.getElementById("endofdocumentcontainer")) 
            tempexpandbutton.onclick=function(){
               CaluMath.PM.PageMakerboxesDefault.required.cm_choices.input.setAttribute("size", ''+(2*CaluMath.PM.PageMakerboxesDefaultctSetting.required.cm_choices.input.getAttribute("size")));
            };
         };
         cancelbuttonElement.onclick=function(){
            if(defaultobject.required.newplot != null && defaultobject.required.newplot.menu != null){
//               defaultobject.required.newplot.menu.onfocus=null;
            };
            if(selectedvalue=="boxes" || selectedvalue=="dropdownmenu"  ){
               tempexpandbutton.parentNode.removeChild(tempexpandbutton);
            };   
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
              if(defaultobject.required.newplot != null && defaultobject.required.newplot.menu != null){
//                 defaultobject.required.newplot.menu.onfocus=null;
              };
              if(selectedvalue=="boxes" || selectedvalue=="dropdownmenu"  ){
                 tempexpandbutton.parentNode.removeChild(tempexpandbutton);
              };   
         };
 
         if(defaultobject.required["newplot"].menu.options.length==0){
            alert("You have not drawn any axes yet. You must do this first before trying to construct a "+CaluMath.PM.PageMakerObjectLabelName(selectedvalue)+".");
             return cancelbuttonElement.onclick();
         };  


         if(defaultobject.required["newplot"] != null ){
          //Comment: We then assign an onchange function that changes the list of functions to those associated with the chosen plot and buttontype. 
            defaultobject.required["newplot"].menu.onchange=function(){
               var optionsmenu= defaultobject.required["newplot"].menu.options;
               var selectedIndex= defaultobject.required["newplot"].menu.selectedIndex;
               if(selectedvalue=="tangentclickbutton" ){ //alerttest([graphmenu, optionsmenu[selectedIndex].value, [["none","none"]].concat(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddtangentslist)]);
                  CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddtangentslist, "Draw Tangents On A Particular Graph"));
               }
               else if(selectedvalue=="highlightclickbutton"){
                  CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].canaddhighlightslist, "Highlight Points On A Particular Graph"));
               }
               else if(selectedvalue=="inputarea" || selectedvalue=="inputtext" || selectedvalue=="button" || selectedvalue=="clickbutton" || selectedvalue=="boxes" || selectedvalue=="dropdownmenu" ){
                  if(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value] != null){
//                     if(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist != null || CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist.length==0){ 
//                     if(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist != null && CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist.length==0){ 
                     if(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist != null && CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist.length >0){ 
                        if(selectedvalue=="inputarea"){
                           CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist, "Have Text Box Belong To A Particular Graph"));
                        }
                        else if(selectedvalue=="inputtext"){
                           CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist, "Have Text Area Belong To A Particular Graph"));
                        }
                        else if(selectedvalue=="button" || selectedvalue=="clickbutton"){
                           CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist, "Have Button Belong To A Particular Graph"));
                        }
                        else if(selectedvalue=="boxes" || selectedvalue=="dropdownmenu" ){
                           CaluMath.PM.UpdateIndividualOption(defaultobject, "required", CaluMath.PM.DefaultEntriesObject.graphrequired(CaluMath.PM.PlotlistObject[optionsmenu[selectedIndex].value].cansupportbuttonslist, "Have Boxes Belong To A Particular Graph"));
                        };
                     }
                     else{ //alerttest("functionplot IS null");
                        CaluMath.PM.UpdateIndividualOption(defaultobject, "required", ["graph", "menu", [["none","none"]], "none", [["Graph", "help/individual_help.html#requiredgraph"], "Have Object Belong To A Particular Graph", "same"]]);
                     };
                  }
                  else{
                     CaluMath.PM.UpdateIndividualOption(defaultobject, "required", ["graph", "menu", [["none","none"]], "none", [["Graph", "help/individual_help.html#requiredgraph"], "Have Object Belong To A Particular Graph", "same"]]);
                  };
               };
               if(defaultobject.required["graph"] != null && optionsmenu[selectedIndex].value==tempobject.cm_getsetting("newplot")){
                   CaluMath.PM.MakeDefaultOption(defaultobject.required["graph"].menu, tempobject.cm_getsetting("graph"), "value"); 
               };

            };   
            //Comment": We actually invoke the onchange function to make sure the currently displayed menus are correct.
            defaultobject.required["newplot"].menu.onchange();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            if(temprequired.name != null && temprequired.name!= "default"){
               tempstring=tempstring+'name='+temprequired.name; 
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);        

            finishbuttonElement.standardcleanup();
            if(selectedvalue=="boxes" || selectedvalue=="dropdownmenu"  ){
               tempexpandbutton.parentNode.removeChild(tempexpandbutton);
            };   
       
         };
      } //Comment: End of various cases for  buttons.
      else if(selectedvalue=="changedirectionbutton" ||  selectedvalue=="startbutton" || selectedvalue=="stopbutton" || selectedvalue=="resetbutton" || selectedvalue=="stepbutton" || selectedvalue=="increasespeedbutton" ||  selectedvalue=="decreasespeedbutton"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, "Start Button"); 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.animationplotlist==null || CaluMath.PM.PlotlistObject.animationplotlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any animations. Please do so before trying to create buttons for an animation.");
            return cancelbuttonElement.onclick();
         };


         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
           
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="allanimationbutton"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, "Start Button"); 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

           var templistofbuttons=["startbutton","stopbutton", "stepbutton", "resetbutton", "changedirectionbutton", "increasespeedbutton","decreasespeedbutton"];

            for(var i=0; i< templistofbuttons.length; i++){
               var newtempobject=CaluMath.PM.PageMakerObject(templistofbuttons[i]);

               if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
                  CaluMath.PM.PageMakerObjectArray.push(newtempobject);  
               };
               newtempobject.cm_requiredarray=CaluMath.PM.CopyArray(tempobject.cm_requiredarray);
               newtempobject.cm_optionsarray=CaluMath.PM.CopyArray(tempobject.cm_optionsarray);
               newtempobject.cm_setrequired("buttontype", templistofbuttons[i]); 
               newtempobject.cm_setoption("value", "default"); 
               CaluMath.PM.AddToListsbuttons(newtempobject);
            };
            
           
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="animationoutput"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.animationplotlist==null || CaluMath.PM.PlotlistObject.animationplotlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any animations. Please do so before trying to create an Animation Output Text Box.");
            return cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
//            CaluMath.PM.WriteTextAndScriptChildren(tempobject, "script");
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="compositeanimation"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.animationplotlist==null || CaluMath.PM.PlotlistObject.animationplotlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any animations. You must create animations on multiple sets of axes before creating a Composite Animation.");
            return cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="addtoboxordropdown"){ 

         if(CaluMath.PM.PlotlistObject.boxeslist==null || CaluMath.PM.PlotlistObject.boxeslist.length ==0){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any Boxes or Drop Down Menus. Please do so before trying to add to a Box or Drop Down Menu.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtoboxordropdown", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel and delete, is exactly what the standardonclick function is. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtoboxordropdown", selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

               var autoplace=CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject);
               if(autoplace =="no"){
                  CaluMath.PM.PageMakerObjectArray.push(tempobject);  
               };

            finishbuttonElement.standardcleanup();
         };           
      }
      else if(selectedvalue=="functiontable"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            var oldinsertoption=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_insertoption");
            var oldinserttarget=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_inserttarget");
            var oldcaswindow=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow");
         };

/*
          CaluMath.PM.PageMakerfunctiontableDefault.caswindowonchangefunction = function(){
             var selectedcaswindow=CaluMath.PM.PageMakerfunctiontableDefault.required["cm_caswindow"].menu[CaluMath.PM.PageMakerfunctiontableDefault.required["cm_caswindow"].menu.selectedIndex].value;
             CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerfunctiontableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].namedobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
             if(CM_TopWindow.CM_EditMode){
                if(selectedcaswindow==oldcaswindow){
                   CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakerfunctiontableDefault.required["cm_inserttarget"].menu, oldinserttarget, "value"); 
                };
             };
             CaluMath.PM.PageMakerfunctiontableDefault.required["cm_caswindow"].menu.onchange= CaluMath.PM.PageMakerfunctiontableDefault.caswindowonchangefunction ;
          };
          CaluMath.PM.PageMakerfunctiontableDefault.caswindowonchangefunction();
*/

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var numberofrows= temprequired.rows; 
            var numberofcolumns= temprequired.columns; 

               var autoplace=CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject);
               if(autoplace =="no"){
                  CaluMath.PM.PageMakerObjectArray.push(tempobject);  
               };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="table"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            var oldinsertoption=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_insertoption");
            var oldinserttarget=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_inserttarget");
            var oldcaswindow=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow");
         };

         if(CM_TopWindow.CaluMath.PM.InsertionArray.length>0){
            if(CM_TopWindow.CaluMath.PM.InsertionArray.lastobject().type != "newwindow"){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["dynamic", "menu", [["yes","yes"]], "yes", [["Dynamic Table","help/individual_help.html#requireddynamic"], "Appears In Response To User Input","same"]]);
            };
         };


          CaluMath.PM.PageMakertableDefault.caswindowonchangefunction = function(){
             var selecteddynamic= CaluMath.PM.PageMakertableDefault.required["dynamic"].menu[CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.selectedIndex].value;
             var selectedcaswindow=CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu[CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.selectedIndex].value;
             if(selecteddynamic=="yes"){
                CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].namedobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
             }
             else{
                CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].staticobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
             };
             if(CM_TopWindow.CM_EditMode){
                if(selectedcaswindow==oldcaswindow){
                   CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_inserttarget"].menu, oldinserttarget, "value"); 
                };
             };
             CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.onchange= CaluMath.PM.PageMakertableDefault.caswindowonchangefunction ;
          };


            CaluMath.PM.PageMakertableDefault.dynamiconchangefunction=function(){
               if(CaluMath.PM.PageMakertableDefault.required["dynamic"].menu[CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.selectedIndex].value=="no"){
                  if(CM_TopWindow.CaluMath.PM.InsertionArray.length >0 && CM_TopWindow.CaluMath.PM.InsertionArray.lastobject().type == "newwindow"){
                     CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_caswindow", "menu", [[CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"),CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name")]], CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"), [["Window","help/individual_help.html#requiredcm_caswindow"], "Table Appears In This Window","same"]]);
                  }
                  else{
                     CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_caswindow", "menu", [["CM_MainWindow","CM_MainWindow"]], "CM_MainWindow", [["Window","help/individual_help.html#requiredcm_caswindow"], "Table Appears In This Window","same"]]);
                  };
                  var selectedcaswindow=CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu[CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.selectedIndex].value;
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].staticobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_insertoption", "menu", [["current point", "n/a"],["insert in", "cm_insertin"]], "current point", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Table Placement","same"]]);
                  CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.onchange= CaluMath.PM.PageMakertableDefault.caswindowonchangefunction ;
               }
               else{
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_caswindow", "menu", CaluMath.PM.PlotlistObject.newwindowlist, "CM_MainWindow", [["Window","help/individual_help.html#requiredcm_caswindow"], "Table Appears In This Window","same"]]);
                  var selectedcaswindow=CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu[CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.selectedIndex].value;
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].namedobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_insertoption", "menu", [["current point", "n/a"],["insert before", "cm_insertbefore"] ,["insert in", "cm_insertin"],["insert after","cm_insertafter"]], "current point", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Table Placement","same"]]);
                  CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu.onchange= CaluMath.PM.PageMakertableDefault.caswindowonchangefunction ;
               };
               CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange=CaluMath.PM.PageMakertableDefault.dynamiconchangefunction; 
               CaluMath.PM.PageMakertableDefault.caswindowonchangefunction();
            };

            CaluMath.PM.PageMakertableDefault.dynamiconchangefunctionedit=function(){
               var selectedcaswindow=CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow");
               if(CaluMath.PM.GetPageMakerObjectSetting(tempobject, "dynamic")=="no"){
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_insertoption", "menu", [["current point", "n/a"],["insertin", "cm_insertin"]], "n/a", [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Table Placement","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].staticobjectlist), "n/a", [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["dynamic", "menu", [["no","no"]], "no", [["Dynamic Table","help/individual_help.html#requireddynamic"], "Appears In Response To User Input","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_caswindow", "menu",CaluMath.PM.PlotlistObject.newwindowlist, oldcaswindow, [["Window","help/individual_help.html#requiredcm_caswindow"], "Table Appears In This Window","same"]]);
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_inserttarget"].menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget"), "value");
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_insertoption"].menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption"), "value");
               }
               else{
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_insertoption", "menu", [["current point", "n/a"],["cm_insertbefore", "cm_insertbefore"] ,["insertin", "cm_insertin"],["cm_insertafter","cm_insertafter"]], CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption"), [["Insert Options","help/individual_help.html#requiredcm_insertoption"], "Table Placement","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[selectedcaswindow].namedobjectlist), CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget"), [["Insert Target","help/individual_help.html#requiredcm_inserttarget"], "Relation of Table To Other Objects","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["dynamic", "menu", [["yes","yes"]], "yes", [["Dynamic Table","help/individual_help.html#requireddynamic"], "Appears In Response To User Input","same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakertableDefault, "required", ["cm_caswindow", "menu", CaluMath.PM.PlotlistObject.newwindowlist, "CM_MainWindow", [["Window","help/individual_help.html#requiredcm_caswindow"], "Table Appears In This Window","same"]]);
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_inserttarget"].menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget"), "value");
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_insertoption"].menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption"), "value");
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakertableDefault.required["cm_caswindow"].menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow"), "value");
               };
               CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange=CaluMath.PM.PageMakertableDefault.dynamiconchangefunctionedit; 
               CaluMath.PM.PageMakertableDefault.caswindowonchangefunction();
            };


         if(CaluMath.PM.GetPageMakerObjectSetting(tempobject, "dynamic").length ==0){
            CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange=CaluMath.PM.PageMakertableDefault.dynamiconchangefunction; 
            CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange();
         }
         else{
//            var selectedcaswindow=CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow");   777777777777777777
            CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange=CaluMath.PM.PageMakertableDefault.dynamiconchangefunctionedit; 
            CaluMath.PM.PageMakertableDefault.required["rows"].menu.onfocus=CaluMath.PM.PageMakertableDefault.required["rows"].menu.blur;
            CaluMath.PM.PageMakertableDefault.required["columns"].menu.onfocus=CaluMath.PM.PageMakertableDefault.required["columns"].menu.blur;
            CaluMath.PM.PageMakertableDefault.required["dynamic"].menu.onchange();
         };

          CaluMath.PM.PageMakertableDefault.caswindowonchangefunction();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var numberofrows= temprequired.rows; 
            var numberofcolumns= temprequired.columns; 

            if(CaluMath.PM.GetPageMakerObjectSetting(tempobject,"dynamic") =="no"){
               if(!CM_TopWindow.CM_EditMode){
                  CaluMath.PM.InsertStaticObject(tempobject);
//                  tempobject.name="htmlelement"+CM_TopWindow.HTMLElementIndex++;
//                  CaluMath.PM.PageMakerObjectParent[tempobject.name]=tempobject;
               }
               else{
                  CaluMath.PM.InsertStaticObject(tempobject, oldinsertoption, oldinserttarget, oldcaswindow);
               };
            }
            else{
               //Comment: So in dynamic mode 
               var autoplace=CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject);
               if(autoplace =="no"){
                  CaluMath.PM.PageMakerObjectArray.push(tempobject);  
               };
            };

            if(!CM_TopWindow.CM_EditMode){

               for(var i=0; i< numberofrows; i++){
                  var temprow=CaluMath.PM.PageMakerObject("tablerow");
                  tempobject.childarray[i]=temprow;
                  for(var j=0; j< numberofcolumns; j++){
                     var tempcol=CaluMath.PM.PageMakerObject("tablecell");
                     temprow.childarray[j]= tempcol;
                  };
               };
            };



            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="tablecell"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("tablecell", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "tablecell", selectedlabel, "Table Cell"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.style.display=="none";

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="tablerow"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("tablerow", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "tablerow", selectedlabel, "Table Row"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.style.display=="none";

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="inserttablerow"){

         if(CaluMath.PM.PlotlistObject.tablelist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any tables yet.You cannot insert a row until you create a table.");
         };


         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerinserttablerowDefault.required["tablechoice"].menu.onchange=function(){
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerinserttablerowDefault.required["tablechoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerinserttablerowDefault, "required", ["numberofrows", "menu", [CaluMath.PM.GetPageMakerObjectSetting(temptable, "rows")], CaluMath.PM.GetPageMakerObjectSetting(temptable, "rows"), "Number of Rows"]);
         };
         CaluMath.PM.PageMakerinserttablerowDefault.required["tablechoice"].menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){

            if(CaluMath.PM.PageMakerinserttablerowDefault.required["rows"].menu.selectedIndex >=   CaluMath.PM.PageMakerinserttablerowDefault.required["numberofrows"].menu[CaluMath.PM.PageMakerinserttablerowDefault.required["numberofrows"].menu.selectedIndex].value){
               return alert("You have chosen a row that is larger than the number of rows in the table. Remember the rows are numbered from 0 to "+(CaluMath.PM.PageMakerinserttablerowDefault.required["numberofrows"].menu[CaluMath.PM.PageMakerinserttablerowDefault.required["numberofrows"].menu.selectedIndex].value-1));
            };

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var numberofrows= temprequired.rows; 
            var insertoption= temprequired.insertoption; 
            var rows= temprequired.rows; 
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerinserttablerowDefault.required["tablechoice"].menu.selectedIndex][2];
            var numberofcolumns= CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns");
            var newrows= 1+1*CaluMath.PM.GetPageMakerObjectSetting(temptable,"rows");
            temptable.cm_setrequired("rows", ""+newrows);

            var tablename = CaluMath.PM.GetPageMakerObjectSetting(temptable,"name");
            var tempstring='';
            CaluMath.PM.DeleteFromListstable(temptable);
   
            var temprow=CaluMath.PM.PageMakerObject("tablerow");
            for(var j=0; j< numberofcolumns; j++){
               var tempcol=CaluMath.PM.PageMakerObject("tablecell");
               temprow.childarray[j]= tempcol;
            };

            if(insertoption=="insertbefore"){
               temptable.childarray.splice(rows,0,temprow); 
               CaluMath.PM.AdjustTableRowsAfterInsertion(temptable, rows);
            }
            else{
               temptable.childarray.splice(1*rows+1,0,temprow); 
               CaluMath.PM.AdjustTableRowsAfterInsertion(temptable, 1*rows+1);
            };

            CaluMath.PM.AddToListstable(temptable);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deletetablerow"){

         if(CaluMath.PM.PlotlistObject.tablelist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any tables yet.You cannot delete a row until you create a table.");
         };


         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerdeletetablerowDefault.required["tablechoice"].menu.onchange=function(){
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablerowDefault.required["tablechoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdeletetablerowDefault, "required", ["numberofrows", "menu", [CaluMath.PM.GetPageMakerObjectSetting(temptable, "rows")], CaluMath.PM.GetPageMakerObjectSetting(temptable, "rows"), "Number of Rows"]);
         };
         CaluMath.PM.PageMakerdeletetablerowDefault.required["tablechoice"].menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
//            if(CaluMath.PM.PageMakerdeletetablerowDefault.required["rows"].menu.selectedIndex >=CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablerowDefault.required["tablechoice"].menu.selectedIndex][2],"rows")){
            if(CaluMath.PM.PageMakerdeletetablerowDefault.required["rows"].menu.selectedIndex >=   CaluMath.PM.PageMakerdeletetablerowDefault.required["numberofrows"].menu[CaluMath.PM.PageMakerdeletetablerowDefault.required["numberofrows"].menu.selectedIndex].value){
               return alert("You have chosen a row that is larger than the number of rows in the table. Remember the rows are numbered from 0 to "+(CaluMath.PM.PageMakerdeletetablerowDefault.required["numberofrows"].menu[CaluMath.PM.PageMakerdeletetablerowDefault.required["numberofrows"].menu.selectedIndex].value-1));
            };

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var rows= temprequired.rows; 
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablerowDefault.required["tablechoice"].menu.selectedIndex][2];
            //Comment: We put the delete here before we start changing the number of rows. The new rows would mess up the DeleteFromLists
            var numberofrows= CaluMath.PM.GetPageMakerObjectSetting(temptable,"rows");
            var numberofcolumns= CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns");
            if(numberofrows==1){
               alert("There is only one row left in the table. Instead of deleting this one row, you must delete the entire table by editing it");
               cancelbuttonElement.onclick();
               return ;
            };
            CaluMath.PM.DeleteFromListstable(temptable);
            var newrows= 1*CaluMath.PM.GetPageMakerObjectSetting(temptable,"rows")-1;
            temptable.cm_setrequired("rows", ""+newrows);
            var tablename = CaluMath.PM.GetPageMakerObjectSetting(temptable,"name");
   
            var temprow= temptable.childarray[rows];
//            CaluMath.PM.DeleteFromLists(temptable.childarray[rows]);
            temptable.childarray.splice(rows,1);
            CaluMath.PM.AdjustTableRowsAfterDeletion(temptable, rows); 

            CaluMath.PM.AddToListstable(temptable);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="inserttablecolumn"){

         if(CaluMath.PM.PlotlistObject.tablelist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any tables yet.You cannot insert a row until you create a table.");
         };


         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerinserttablecolumnDefault.required["tablechoice"].menu.onchange=function(){
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerinserttablecolumnDefault.required["tablechoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerinserttablecolumnDefault, "required", ["numberofcolumns", "menu", [CaluMath.PM.GetPageMakerObjectSetting(temptable, "columns")], CaluMath.PM.GetPageMakerObjectSetting(temptable, "columns"), "Number of Columns"]);
         };
         CaluMath.PM.PageMakerinserttablecolumnDefault.required["tablechoice"].menu.onchange();
      
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){

            if(CaluMath.PM.PageMakerinserttablecolumnDefault.required["columns"].menu.selectedIndex >=   CaluMath.PM.PageMakerinserttablecolumnDefault.required["numberofcolumns"].menu[CaluMath.PM.PageMakerinserttablecolumnDefault.required["numberofcolumns"].menu.selectedIndex].value){
               return alert("You have chosen a column that is larger than the number of columns in the table. Remember the columns are numbered from 0 to "+(CaluMath.PM.PageMakerinserttablecolumnDefault.required["numberofcolumns"].menu[CaluMath.PM.PageMakerinserttablecolumnDefault.required["numberofcolumns"].menu.selectedIndex].value-1));
            };
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var cm_insertoption= temprequired.insertoption; 
            var columns= temprequired.columns; 
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerinserttablecolumnDefault.required["tablechoice"].menu.selectedIndex][2];
            var numberofrows= CaluMath.PM.GetPageMakerObjectSetting(temptable,"rows");
            var numberofcolumns= CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns");
            var newcolumns= 1+1*CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns");
            temptable.cm_setrequired("columns", ""+newcolumns);

            var tablename = CaluMath.PM.GetPageMakerObjectSetting(temptable,"name");
            tempstring= '';
            
            CaluMath.PM.DeleteFromListstable(temptable);

               if(cm_insertoption=="insertbefore"){
                  newcolumnindex=1*columns; 
               }
               else{
                  newcolumnindex=1+1*columns; 
               };
               for(var j=0; j< numberofrows; j++){
                  var temprow = temptable.childarray[j];
                  var tempcell =CaluMath.PM.PageMakerObject("tablecell");
                  temprow.childarray.splice(newcolumnindex, 0, tempcell);
               };
 

            CaluMath.PM.AdjustTableColumnsAfterInsertion(temptable, newcolumnindex);
            CaluMath.PM.AddToListstable(temptable);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deletetablecolumn"){

         if(CaluMath.PM.PlotlistObject.tablelist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any tables yet.You cannot delete a column until you create a table.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerdeletetablecolumnDefault.required["tablechoice"].menu.onchange=function(){
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablecolumnDefault.required["tablechoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdeletetablecolumnDefault, "required", ["numberofcolumns", "menu", [CaluMath.PM.GetPageMakerObjectSetting(temptable, "columns")], CaluMath.PM.GetPageMakerObjectSetting(temptable, "columns"), "Number of Columns"]);
         };
         CaluMath.PM.PageMakerdeletetablecolumnDefault.required["tablechoice"].menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
          
//            if(CaluMath.PM.PageMakerdeletetablecolumnDefault.required["columns"].menu.selectedIndex >=CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablecolumnDefault.required["tablechoice"].menu.selectedIndex][2],"columns")){
            if(CaluMath.PM.PageMakerdeletetablecolumnDefault.required["columns"].menu.selectedIndex >=   CaluMath.PM.PageMakerdeletetablecolumnDefault.required["numberofcolumns"].menu[CaluMath.PM.PageMakerdeletetablecolumnDefault.required["numberofcolumns"].menu.selectedIndex].value){
               return alert("You have chosen a column that is larger than the number of columns in the table. Remember the columns are numbered from 0 to "+(CaluMath.PM.PageMakerdeletetablecolumnDefault.required["numberofcolumns"].menu[CaluMath.PM.PageMakerdeletetablecolumnDefault.required["numberofcolumns"].menu.selectedIndex].value-1));
            };

            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
//            var tempstring=CaluMath.PM.CreateSettingsAndOptionString(selectedvalue,tempobject);
            var tempstring=CaluMath.PM.CreateSettingsArrays("selectedvalue",tempobject);
            if(tempstring == null){
               return;
            };

            var columns= temprequired.columns; 
            var temptable=CaluMath.PM.PlotlistObject.tablelist[CaluMath.PM.PageMakerdeletetablecolumnDefault.required["tablechoice"].menu.selectedIndex][2];
            var numberofrows= CaluMath.PM.GetPageMakerObjectSetting(temptable,"rows");
            var numberofcolumns= CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns");
            if(numberofcolumns==1){
               alert("There is only one  column in the table. Instead of deleting this one column, you must delete the entire table by editing it");
               cancelbuttonElement.onclick();
               return ;
            };
            CaluMath.PM.DeleteFromListstable(temptable);
            var newcolumns= 1*CaluMath.PM.GetPageMakerObjectSetting(temptable,"columns")-1;
            temptable.cm_setrequired("columns", ""+newcolumns);

//            CaluMath.PM.SetPageMakerObjectSetting(temptable,"columns", ""+newcolumns);

            var tablename = CaluMath.PM.GetPageMakerObjectSetting(temptable,"name");

            for(var i=0; i< numberofrows; i++){
               temptable.childarray[i].childarray.splice(columns,1);

            };

 
            CaluMath.PM.AdjustTableColumnsAfterDeletion(temptable, columns); 
            CaluMath.PM.AddToListstable(temptable);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="tablefromdata"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="discretefunctionconstructiontable"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="list"){

         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            var oldinsertoption=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_insertoption");
            var oldinserttarget=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_inserttarget");
            var oldcaswindow=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow");
         };

         CaluMath.PM.PageMakerlistDefault.options.listtype.menu.onchange=function(){
            if(CaluMath.PM.PageMakerlistDefault.options.listtype.menu.selectedIndex==0){
               //Comment:This means is it an ordered list
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerlistDefault, "options", ["type", "menu", [["default","n/a"], ["1,2,3", "decimal"], ["a,b,c", "lower-alpha"], ["i,ii,iii", "lower-roman"], ["A,B,C", "upper-alpha"], ["I,II,III", "upper-roman"]], "n/a", "List Marker"]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerlistDefault, "options", ["position", "menu", [["default","n/a"], ["wrap", "inside"], ["no wrap", "outside"]], "n/a", "List Position"]);
               if(CM_TopWindow.CM_EditMode){
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakerlistDefault.options.type.menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "type"), "value");
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakerlistDefault.options.position.menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "position"), "value");
               };
            }
            else if(CaluMath.PM.PageMakerlistDefault.options.listtype.menu.selectedIndex==1){
               //Comment:This means is it an unordered list
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerlistDefault, "options", ["type", "menu", [["default","n/a"], ["circle", "circle"], ["disc", "disc"], ["square", "square"]], "n/a", "List Marker"]);
               if(CM_TopWindow.CM_EditMode){
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakerlistDefault.options.type.menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "type"), "value");
                  CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakerlistDefault.options.position.menu, CaluMath.PM.GetPageMakerObjectSetting(tempobject, "position"), "value");
               };
            }
            else{ 
               //Comment:This means is it a definition list
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerlistDefault, "options", ["type", "menu", [["n/a","n/a"]], "n/a", "List Marker"]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerlistDefault, "options", ["position", "menu", [["n/a","n/a"]], "n/a", "List Position"]);
            };

         };

         CaluMath.PM.PageMakerlistDefault.options.listtype.menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var numberofitems= temprequired.items; 
            var tempname= temprequired.name; 

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };

            if(!CM_TopWindow.CM_EditMode){
               if(tempobject.cm_getsetting("listtype") != "dl"){
                  if(tempobject.cm_getsetting("maketext")=="no"){
                     for(var i=0; i< numberofitems; i++){
                        var tempitem=CaluMath.PM.PageMakerObject("listitem");
                        tempobject.childarray[i]=tempitem;
                     };
                  }
                  else{
                     for(var i=0; i< numberofitems; i++){
                        var tempitem=CaluMath.PM.PageMakerObject("listitem");
                        tempobject.childarray[i]=tempitem;
                        temptext= CaluMath.PM.PageMakerObject("htmltext")
                        CaluMath.PM.PageMakerObjectParent[tempname+"I"+(i+1)+"Text"]= temptext;
                        temptext.cm_setrequired("name", tempname+"I"+(i+1)+"Text")
                        temptext.cm_setrequired("tag", "span")
                        temptext.cm_setrequired("cm_caswindow", tempobject.cm_getsetting("cm_caswindow"));
                        temptext.cm_setrequired("cm_insertoption", "cm_insertin");
                        temptext.cm_setrequired("cm_inserttarget", tempname+"I"+(i+1));
                        tempchildtext= CaluMath.PM.PageMakerObject("text");
                        tempchildtext.cm_setrequired("text", tempname+"I"+(i+1));
                        temptext.childarray[0]=tempchildtext;
                        CaluMath.PM.AddToListsp(temptext);
                        if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(temptext)=="no"){
                           CaluMath.PM.PageMakerObjectArray.push(temptext);  
                        };
                     };
                  };
               }
               else{
                  if(tempobject.cm_getsetting("maketext")=="no"){
                     for(var i=0; i< numberofitems; i++){
                        var tempitem=CaluMath.PM.PageMakerObject("definitionlisttitle");
                        tempobject.childarray[2*i]=tempitem;
                        var tempitem=CaluMath.PM.PageMakerObject("definitionlistdata");
                        tempobject.childarray[2*i+1]=tempitem;
                     };
                  }
                  else{
                     for(var i=0; i< numberofitems; i++){
                        var tempitem=CaluMath.PM.PageMakerObject("definitionlisttitle");
                        tempobject.childarray[2*i]=tempitem;
                        var tempitem=CaluMath.PM.PageMakerObject("definitionlistdata");
                        tempobject.childarray[2*i+1]=tempitem;
                        temptext= CaluMath.PM.PageMakerObject("htmltext");
                        CaluMath.PM.PageMakerObjectParent[tempname+"T"+(i+1)+"Text"]= temptext;
                        temptext.cm_setrequired("name", tempname+"T"+(i+1)+"Text");
                        temptext.cm_setrequired("tag", "span");
                        temptext.cm_setrequired("cm_caswindow", tempobject.cm_getsetting("cm_caswindow"));
                        temptext.cm_setrequired("cm_insertoption", "cm_insertin");
                        temptext.cm_setrequired("cm_inserttarget", tempname+"T"+(i+1));
                        tempchildtext= CaluMath.PM.PageMakerObject("text");
                        tempchildtext.cm_setrequired("text", tempname+"T"+(i+1));
                        temptext.childarray[0]=tempchildtext;
                        CaluMath.PM.AddToListsp(temptext);
                        if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(temptext)=="no"){
                           CaluMath.PM.PageMakerObjectArray.push(temptext);  
                        };
                        temptext1= CaluMath.PM.PageMakerObject("htmltext")
                        CaluMath.PM.PageMakerObjectParent[tempname+"D"+(i+1)+"Text"]= temptext1;
                        temptext1.cm_setrequired("name", tempname+"D"+(i+1)+"Text")
                        temptext1.cm_setrequired("tag", "span")
                        temptext1.cm_setrequired("cm_caswindow", tempobject.cm_getsetting("cm_caswindow"));
                        temptext1.cm_setrequired("cm_insertoption", "cm_insertin");
                        temptext1.cm_setrequired("cm_inserttarget", tempname+"D"+(i+1));
                        tempchildtext1= CaluMath.PM.PageMakerObject("text");
                        tempchildtext1.cm_setrequired("text", tempname+"D"+(i+1))
                        temptext1.childarray[0]=tempchildtext1;
                        CaluMath.PM.AddToListsp(temptext1);
                        if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(temptext1)=="no"){
                           CaluMath.PM.PageMakerObjectArray.push(temptext1);  
                        };
                     };
                  };
               };
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="insertlistitem"){

         if(CaluMath.PM.PlotlistObject.listlist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any lists yet.You cannot insert an item until you create a list.");
         };


         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerinsertlistitemDefault.required["listchoice"].menu.onchange=function(){
            var templist=CaluMath.PM.PlotlistObject.listlist[CaluMath.PM.PageMakerinsertlistitemDefault.required["listchoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerinsertlistitemDefault, "required", ["numberofitems", "menu", [CaluMath.PM.GetPageMakerObjectSetting(templist, "items")], CaluMath.PM.GetPageMakerObjectSetting(templist, "items"), "Number of Rows"]);
         };
         CaluMath.PM.PageMakerinsertlistitemDefault.required["listchoice"].menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){

            if(CaluMath.PM.PageMakerinsertlistitemDefault.required["items"].menu.selectedIndex >   CaluMath.PM.PageMakerinsertlistitemDefault.required["numberofitems"].menu[CaluMath.PM.PageMakerinsertlistitemDefault.required["numberofitems"].menu.selectedIndex].value){
               return alert("You have chosen an item that is larger than the number of items in the list. Remember the items are numbered from 1 to "+(CaluMath.PM.PageMakerinsertlistitemDefault.required["numberofitems"].menu[CaluMath.PM.PageMakerinsertlistitemDefault.required["numberofitems"].menu.selectedIndex].value));
            };

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var numberofitems= temprequired.items; 
            var insertoption= temprequired.insertoption; 
            var items= temprequired.items; 
            var templist=CaluMath.PM.PlotlistObject.listlist[CaluMath.PM.PageMakerinsertlistitemDefault.required["listchoice"].menu.selectedIndex][2];
            var newitems= 1+1*CaluMath.PM.GetPageMakerObjectSetting(templist,"items");
            templist.cm_setrequired("items", ""+newitems);

            var listname = CaluMath.PM.GetPageMakerObjectSetting(templist,"name");
            var tempstring='';
            CaluMath.PM.DeleteFromListslist(templist);
   
            if(insertoption=="insertbefore"){
               if(templist.cm_getsetting("listtype") != "dl"){
                  var tempitem=CaluMath.PM.PageMakerObject("listitem");
                  templist.childarray.splice(items-1,0,tempitem); 
                  CaluMath.PM.AdjustListItemsAfterInsertion(templist, items);
               }
               else{
                  var tempitem=CaluMath.PM.PageMakerObject("definitionlisttitle");
                  templist.childarray.splice(2*(items-1),0,tempitem); 
                  var tempitem=CaluMath.PM.PageMakerObject("definitionlistdata");
                  templist.childarray.splice(2*(items-1)+1,0,tempitem); 
                  CaluMath.PM.AdjustListItemsAfterInsertion(templist, items);
               };
            }
            else{
               if(templist.cm_getsetting("listtype") != "dl"){
                  var tempitem=CaluMath.PM.PageMakerObject("listitem");
                  templist.childarray.splice(1*items,0,tempitem); 
                  CaluMath.PM.AdjustListItemsAfterInsertion(templist, 1*items+1);
               }
               else{
                  var tempitem=CaluMath.PM.PageMakerObject("definitionlisttitle");
                  templist.childarray.splice(2*items,0,tempitem); 
                  var tempitem=CaluMath.PM.PageMakerObject("definitionlistdata");
                  templist.childarray.splice(2*items+1,0,tempitem); 
                  CaluMath.PM.AdjustListItemsAfterInsertion(templist, items);
               };
            };

            CaluMath.PM.AddToListslist(templist);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="deletelistitem"){

         if(CaluMath.PM.PlotlistObject.listlist.length==0){
            CaluMath.PM.DisplayPageControls(); 
            return alert("You have not created any lists yet.You cannot delete an item until you create a list.");
         };


         tempobject=CaluMath.PM.ObjectStandardBeginning(selectedvalue, arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         CaluMath.PM.PageMakerdeletelistitemDefault.required["listchoice"].menu.onchange=function(){
            var templist=CaluMath.PM.PlotlistObject.listlist[CaluMath.PM.PageMakerdeletelistitemDefault.required["listchoice"].menu.selectedIndex][2];
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdeletelistitemDefault, "required", ["numberofitems", "menu", [CaluMath.PM.GetPageMakerObjectSetting(templist, "items")], CaluMath.PM.GetPageMakerObjectSetting(templist, "items"), "Number of Rows"]);
         };
         CaluMath.PM.PageMakerdeletelistitemDefault.required["listchoice"].menu.onchange();

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, selectedvalue, selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            if(CaluMath.PM.PageMakerdeletelistitemDefault.required["items"].menu.selectedIndex >   CaluMath.PM.PageMakerdeletelistitemDefault.required["numberofitems"].menu[CaluMath.PM.PageMakerdeletelistitemDefault.required["numberofitems"].menu.selectedIndex].value){
               return alert("You have chosen an item that is larger than the number of items in the list. Remember the items are numbered from 1 to "+(CaluMath.PM.PageMakerdeletelistitemDefault.required["numberofitems"].menu[CaluMath.PM.PageMakerdeletelistitemDefault.required["numberofitems"].menu.selectedIndex].value));
            };

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            var items= temprequired.items; 
            var templist=CaluMath.PM.PlotlistObject.listlist[CaluMath.PM.PageMakerdeletelistitemDefault.required["listchoice"].menu.selectedIndex][2];
            //Comment: We put the delete here before we start changing the number of items. The new items would mess up the DeleteFromLists
            var numberofitems= CaluMath.PM.GetPageMakerObjectSetting(templist,"items");
            if(numberofitems==1){
               alert("There is only one item left in the list. Instead of deleting this one item, you must delete the entire list by editing it");
               cancelbuttonElement.onclick();
               return ;
            };
            CaluMath.PM.DeleteFromListslist(templist);
            var newitems= 1*CaluMath.PM.GetPageMakerObjectSetting(templist,"items")-1;
            templist.cm_setrequired("items", ""+newitems);
            var listname = CaluMath.PM.GetPageMakerObjectSetting(templist,"name");
   
            if(templist.cm_getsetting("listtype") != "dl"){
               templist.childarray.splice(items-1,1);
            }
            else{
               templist.childarray.splice(2*(items-1),2);
            }
            CaluMath.PM.AdjustListItemsAfterDeletion(templist, items); 

            CaluMath.PM.AddToListslist(templist);
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="listitem"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("listitem", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "listitem", selectedlabel, "List Item"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.style.display=="none";

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays(selectedvalue,tempobject);
            if(tempstring == null){
               return;
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="iframe"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("iframe", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            var oldinsertoption= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption");
            var oldinserttarget= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget");
            var oldcaswindow= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow");
         };

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "iframe", selectedlabel, "Iframe"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         if(!CM_TopWindow.CM_EditMode && CaluMath.PM.InsertionArray.length >0){
            if(CaluMath.PM.InsertionArray.lastobject().type =="newwindow"){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [[CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"),CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name")]], CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name"), [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.InsertionArray.lastobject(),"name")].staticobjectlist), "n/a", "Insert Target"]);
            }
            else{
               alert("You cannot add an iframe while doing things such as  button actions, a routines, or conditionals. The only exception is that you can add an iframe to a new window by using the New Window or Add To New Window operations. We are now cancelling your iframe. ");
            };
         }
         else if(!CM_TopWindow.CM_EditMode){
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [["CM_MainWindow","CM_MainWindow"]],"CM_MainWindow", [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject["CM_MainWindow"].staticobjectlist), "n/a", "Insert Target"]);
         }
         else{
            if(tempobject.parent != null && tempobject.parent.type =="newwindow" && tempobject.parent.cm_getsetting("name") != CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow")){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [[tempobject.parent.cm_getsetting("name") , tempobject.parent.cm_getsetting("name") ]],  tempobject.parent.cm_getsetting("name") , [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[tempobject.parent.cm_getsetting("name")].staticobjectlist), "n/a", "Insert Target"]);
            }
            else if(tempobject.parent != null && tempobject.parent.type =="iframecontainer" && tempobject.parent.cm_getsetting("cm_caswindow") != CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow")){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [[tempobject.parent.cm_getsetting("cm_caswindow") , tempobject.parent.cm_getsetting("cm_caswindow") ]],  tempobject.parent.cm_getsetting("cm_caswindow") , [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[tempobject.parent.cm_getsetting("cm_caswindow")].staticobjectlist), "n/a", "Insert Target"]);
            }
            else if(tempobject.parent != null && tempobject.parent==CaluMath.PM.PageMakerObjectArray && CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow") != "CM_MainWindow"){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [[tempobject.parent.cm_getsetting("name") , tempobject.parent.cm_getsetting("name") ]],  tempobject.parent.cm_getsetting("name") , [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[tempobject.parent.cm_getsetting("name")].staticobjectlist), "n/a", "Insert Target"]);
            }
            else{ 
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_caswindow", "menu", [[CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow"), CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow")]],  CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow"), [["Window","help/individual_help.html#requiredcm_caswindow"], "Iframe Appears In This Window","same"]]);
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakeriframeDefault, "required", ["cm_inserttarget", "menu", [["n/a", "n/a"]].concat(CaluMath.PM.PlotlistObject[CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_caswindow")].staticobjectlist), CaluMath.PM.GetPageMakerObjectSetting(tempobject,"cm_inserttarget"), "Insert Target"]);
            }
         }


         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("iframe",tempobject);
            if(tempstring == null){
               return;
            };

            if(!CM_TopWindow.CM_EditMode){
               CaluMath.PM.InsertStaticObject(tempobject);
            }
            else{
               CaluMath.PM.InsertStaticObject(tempobject,  oldinsertoption, oldinserttarget, oldcaswindow);
            };
               
            CaluMath.PM.SetWriteTag(tempobject, "script");
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="iframecontainer"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("iframecontainer", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         if(CM_TopWindow.CM_EditMode){
            var oldinsertoption= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_insertoption");
            var oldinserttarget= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_inserttarget");
            var oldcaswindow= CaluMath.PM.GetPageMakerObjectSetting(tempobject, "cm_caswindow");
         };

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "iframecontainer", selectedlabel, "Iframe Container"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("iframecontainer",tempobject);
            if(tempstring == null){
               return;
            };


//            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject) !="yes"){  
               CaluMath.PM.InsertStaticObject(tempobject, oldinsertoption, oldinserttarget, oldcaswindow);
//               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

//            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="linebreak"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("linebreak", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "linebreak", selectedlabel, "Inserted Line Break"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("linebreak",tempobject);
            if(tempstring == null){
               return;
            };


            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="newwindow"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("newwindow", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "newwindow", selectedlabel, "Button Action"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };
         deletebuttonElement.onclick=function(){
//            var childindex= CaluMath.PM.ArrayIndex(CaluMath.PM.PageMakerObjectArray, tempobject); 
//            CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,childindex).concat(CaluMath.PM.PageMakerObjectArray.slice(childindex+1));
            CaluMath.PM.AssignParents();
            var childindex= CaluMath.PM.ArrayIndex(tempobject.parent.childarray, tempobject); 
            tempobject.parent.childarray.splice(childindex,1); 
            deletebuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };

         if(CM_TopWindow.CM_EditMode == true){
            //Comment: DO NOT REMOVE THE COMMENTED LINE BELOW. CaluMath.PM.EditIndividualEntries has some bugs and so was removed. We should reconsider whether it should be used in the future. 
            var tempcreatedbuttons= CaluMath.PM.EditIndividualEntries(tempobject, finishbuttonElement, cancelbuttonElement, deletebuttonElement);
            var downalevelbutton= tempcreatedbuttons[0];
            var recreatebutton= tempcreatedbuttons[1];
         };

         //Comment: The finish button onclick must be individually done for each type of math object. They have the same overall outline, however the strings written and objects made must be tailored to the type of object. Note the use of the standardcleanup function at the end that does standard removal of buttons etc.  
         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("newwindow",tempobject);
            if(tempstring == null){
               return;
            };
          
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject, "scriptnewwindow");


            if(CM_TopWindow.CM_EditMode != true){
               finishbuttonElement.standardcleanup();

               // PAGECONTROLCONTAINER.style.display="none";
               // PAGEASSISTCONTAINER.style.display="block";
               CaluMath.PM.HidePageControls("visible"); 
                  CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempobject, "NoQuote"));
//                  cm_alert("Now do the item you want to add to your New Window.");
                  cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
                  CaluMath.PM.HidePageControls("visible");
            }
            else{
               cm_alert("The changes to the "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+" have been made."); 
               finishbuttonElement.standardcleanup();
               if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
                  tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
                  delete tempobject.downalevelbutton;
               };
            }; 
         };

      }
      else if(selectedvalue=="addtonewwindow"){ 

         if(CaluMath.PM.PlotlistObject.newwindowlist==null || CaluMath.PM.PlotlistObject.newwindowlist.length ==1){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any New Windows. Please do so before trying to add to a New Window.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtonewwindow", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel and delete, is exactly what the standardonclick function is. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtonewwindow", selectedlabel, selectedlabel); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            CaluMath.PM.CreateSettingsArrays("addtonewwindow",tempobject);
            var selectedindex= CaluMath.PM.PageMakeraddtonewwindowDefault.required.newwindow.menu.options.selectedIndex;
            finishbuttonElement.standardcleanup();
            var tempnewwindow=CaluMath.PM.PlotlistObject.newwindowlist.slice(1)[selectedindex][2];
            CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempnewwindow, "NoQuote"));
            cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            // PAGECONTROLCONTAINER.style.display="none";
            // PAGEASSISTCONTAINER.style.display="block";
            CaluMath.PM.HidePageControls("visible"); 

         };           
      }
      else if(selectedvalue=="buttonaction"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("buttonaction", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This stops them from choosing a clickbutton action for a non click button.
         CaluMath.PM.PageMakerbuttonactionDefault.required.type.menu.onchange= function(){
            if(CaluMath.PM.PlotlistObject.buttonlist[CaluMath.PM.PageMakerbuttonactionDefault.required.button.menu.options.selectedIndex][2].type=="button"){
               CaluMath.PM.PageMakerbuttonactionDefault.required.type.menu.selectedIndex=0;
            };
         };
         //Comment: This guarantees before anything has been changed, an option of "When graph is clicked" will not appear with a non-clickbutton.
         CaluMath.PM.PageMakerbuttonactionDefault.required.type.menu.onchange();
         //Comment: This guarantees that a person cannot change the button and leave a value of "When graph is clicked" when they changed it to a non clickbutton.
         CaluMath.PM.PageMakerbuttonactionDefault.required.button.menu.onchange=CaluMath.PM.PageMakerbuttonactionDefault.required.type.menu.onchange;

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "buttonaction", selectedlabel, "Button Action"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };
         deletebuttonElement.onclick=function(){
//            var childindex= CaluMath.PM.ArrayIndex(CaluMath.PM.PageMakerObjectArray, tempobject); 
            CaluMath.PM.AssignParents();
            var childindex= CaluMath.PM.ArrayIndex(tempobject.parent.childarray, tempobject); 
            tempobject.parent.childarray.splice(childindex,1); 
//            CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.slice(0,childindex).concat(CaluMath.PM.PageMakerObjectArray.slice(childindex+1));
            deletebuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };

         if(CM_TopWindow.CM_EditMode == true){
            //Comment: DO NOT REMOVE THE COMMENTED LINE BELOW. CaluMath.PM.EditIndividualEntries has some bugs and so was removed. We should reconsider whether it should be used in the future. 
            var tempcreatedbuttons= CaluMath.PM.EditIndividualEntries(tempobject, finishbuttonElement, cancelbuttonElement, deletebuttonElement);
            var downalevelbutton= tempcreatedbuttons[0];
            var recreatebutton= tempcreatedbuttons[1];
         };

         //Comment: The finish button onclick must be individually done for each type of math object. They have the same overall outline, however the strings written and objects made must be tailored to the type of object. Note the use of the standardcleanup function at the end that does standard removal of buttons etc.  
         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("buttonaction",tempobject);
            if(tempstring == null){
               return;
            };
 
            var type= temprequired.type;
            var button=temprequired.button;

            checkifbuttonactionexistsalreadyloop:
            for(var i=0; i< CaluMath.PM.PlotlistObject.buttonactionlist.length; i++){
               if(CaluMath.PM.PlotlistObject.buttonactionlist[i][2].cm_getsetting("button")==button && CaluMath.PM.PlotlistObject.buttonactionlist[i][2].cm_getsetting("type")==type){
                  cancelbuttonElement.onclick();
                  CaluMath.PM.EveryObjectArray=CaluMath.PM.EveryObjectArray.cm_removeelements(tempobject,"yes");
                  return alert("You already have created a button action for this button. Please use \"add to buttonaction\" to add new items to this buttonaction.");
               };   
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject); 


            if(CM_TopWindow.CM_EditMode != true){

               finishbuttonElement.standardcleanup();

               // PAGECONTROLCONTAINER.style.display="none";
               // PAGEASSISTCONTAINER.style.display="block";
               CaluMath.PM.HidePageControls("visible"); 
                  CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempobject, "NoQuote"));
                  cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            }
            else{
               cm_alert("The changes to the "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+" have been made."); 
               finishbuttonElement.standardcleanup();
               if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
                  tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
                  delete tempobject.downalevelbutton;
               };
            }; 
         };

      }
      else if(selectedvalue=="addtobuttonaction"){ 

         if(CaluMath.PM.PlotlistObject.buttonactionlist==null || CaluMath.PM.PlotlistObject.buttonactionlist.length ==0){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any named button actions. Please do so before trying to add to a named button action");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtobuttonaction", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel and delete, is exactly what the standardonclick function is. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtobuttonaction", selectedlabel, "Button Action"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            if(CaluMath.PM.InsertionArray.length != 0){
               cm_alert("You are in the middle of a buttonaction or conditional or other such action. You cannot add to a buttonaction under these conditions. I am kicking you out of add to a buttonaction so you can finish what you were doing.");
               return  finishbuttonElement.standardcleanup();
            };
            CaluMath.PM.CreateSettingsArrays("addtobuttonaction",tempobject);
            var selectedindex= CaluMath.PM.PageMakeraddtobuttonactionDefault.required.buttonaction.menu.options.selectedIndex;
            finishbuttonElement.standardcleanup();
            var tempbuttonaction=CaluMath.PM.PlotlistObject.buttonactionlist[selectedindex][2];
            CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempbuttonaction, "NoQuote"));
            cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            // PAGECONTROLCONTAINER.style.display="none";
            // PAGEASSISTCONTAINER.style.display="block";
            CaluMath.PM.HidePageControls("visible"); 

         };           
      }
      else if(selectedvalue=="buttonactionnext"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("buttonactionnext", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "buttonactionnext", selectedlabel, "Button Action"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            //Comment: If the next is the only child, then we want the next to appear alone. If not, we want to end the previous string, put a comma, and then put a next. 
            if(CaluMath.PM.InsertionArray.length ==0 || CaluMath.PM.InsertionArray.lastobject().type !="buttonaction"){
               cm_alert("You cannot insert a buttonactionnext into anything other than a buttonaction. Since you are not doing that, you will be exited from the buttonactionnext sequence.");
               finishbuttonElement.standardcleanup();
            };
///////////REPLACED lastscriptchildarray WITH lastobjectchildarray
            var scriptchildren = CaluMath.PM.InsertionArray.lastobjectchildarray();
//            var scriptchildren = CaluMath.PM.InsertionArray.lastscriptchildarray();
//            if(scriptchildren != null){
               tempobject.writestring='}, \'next\' , function(){ ';
               scriptchildren.push(tempobject);
//             };
             finishbuttonElement.standardcleanup();
         };

      }
      else if(selectedvalue=="forloop"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("forloop", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "forloop", selectedlabel, "For Loop"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var childindex= CaluMath.PM.ArrayIndex(tempobject.parent.childarray, tempobject); 
            tempobject.parent.childarray.splice(childindex,1); 
            deletebuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };

         if(CM_TopWindow.CM_EditMode == true){
            //Comment: DO NOT REMOVE THE COMMENTED LINE BELOW. CaluMath.PM.EditIndividualEntries has some bugs and so was removed. We should reconsider whether it should be used in the future. 
            var tempcreatedbuttons= CaluMath.PM.EditIndividualEntries(tempobject, finishbuttonElement, cancelbuttonElement, deletebuttonElement);
            var downalevelbutton= tempcreatedbuttons[0];
            var recreatebutton= tempcreatedbuttons[1];
         };

         //Comment: The finish button onclick must be individually done for each type of math object. They have the same overall outline, however the strings written and objects made must be tailored to the type of object. Note the use of the standardcleanup function at the end that does standard removal of buttons etc.  
         finishbuttonElement.onclick=function(){

            var tempstring=CaluMath.PM.CreateSettingsArrays("forloop",tempobject);
            if(tempstring == null){
               return;
            };
 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject); 


            if(CM_TopWindow.CM_EditMode != true){

               finishbuttonElement.standardcleanup();

               // PAGECONTROLCONTAINER.style.display="none";
               // PAGEASSISTCONTAINER.style.display="block";
               CaluMath.PM.HidePageControls("visible"); 

                  CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempobject, "NoQuote"));
                  cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            }
            else{
               cm_alert("The changes to the "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+" have been made."); 
               finishbuttonElement.standardcleanup();
               if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
                  tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
                  delete tempobject.downalevelbutton;
               };
            }; 
         };

      }
      else if(selectedvalue=="addtoforloop"){ 

         if(CaluMath.PM.PlotlistObject.forlooplist==null || CaluMath.PM.PlotlistObject.forlooplist.length ==0){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any named button actions. Please do so before trying to add to a named button action");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtoforloop", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel and delete, is exactly what the standardonclick function is. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtoforloop", selectedlabel, "For Loop"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            if(CaluMath.PM.InsertionArray.length != 0){
               cm_alert("You are in the middle of a Button Action or Conditional or other such action. You cannot add to a For Loop under these conditions. I am kicking you out of Add to a For Loop so you can finish what you were doing.");
               return  finishbuttonElement.standardcleanup();
            };
            CaluMath.PM.CreateSettingsArrays("addtoforloop",tempobject);
            var selectedindex= CaluMath.PM.PageMakeraddtoforloopDefault.required.forloop.menu.options.selectedIndex;
            finishbuttonElement.standardcleanup();
            var tempforloop=CaluMath.PM.PlotlistObject.forlooplist[selectedindex][2];
            CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempforloop, "NoQuote"));
            cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            // PAGECONTROLCONTAINER.style.display="none";
            // PAGEASSISTCONTAINER.style.display="block";
            CaluMath.PM.HidePageControls("visible"); 

         };           
      }
      else if(selectedvalue=="conditional"){ 
         tempobject=CaluMath.PM.ObjectStandardBeginning("conditional", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "conditional", selectedlabel, "Conditional"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };

         if(CM_TopWindow.CM_EditMode == true){
            //Comment: DO NOT REMOVE THE COMMENTED LINE BELOW. CaluMath.PM.EditIndividualEntries has some bugs and so was removed. We should reconsider whether it should be used in the future. 
            var tempcreatedbuttons= CaluMath.PM.EditIndividualEntries(tempobject, finishbuttonElement, cancelbuttonElement, deletebuttonElement);
            var downalevelbutton= tempcreatedbuttons[0];
            var recreatebutton= tempcreatedbuttons[1];

            var oldtempinsertconditionaltarget=tempobject.cm_getsetting("insertconditionaltarget");
            var oldinsertconditionaloption=tempobject.cm_getsetting("insertconditionaloption");
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("conditional",tempobject);
            if(tempstring == null){
               return;
            }
           
            var nameinput= temprequired.name;
            var button=temprequired.button;
            var tempbranchtype=temprequired.branchtype;
            if(!CM_TopWindow.CM_EditMode){
               if(tempobject.cm_getsetting("insertconditionaloption") != "n/a" && tempobject.cm_getsetting("insertconditionaltarget") != "n/a"){
                  CaluMath.PM.AssignParents();
                  var tempinsertconditionaltarget=tempobject.cm_getsetting("insertconditionaltarget");
                  var insertconditionaloption=tempobject.cm_getsetting("insertconditionaloption");
                  var tempinsertconditionaltargetindex= CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.conditionallist,tempinsertconditionaltarget,0);
                  var tempinsertconditionaltargetobject=CaluMath.PM.PlotlistObject.conditionallist[tempinsertconditionaltargetindex][2]; 
                  tempinsertconditionaltargetobjectchildarray=tempinsertconditionaltargetobject.parent.childarray;
                  var tempindex= CaluMath.PM.ArrayIndex(tempinsertconditionaltargetobjectchildarray, tempinsertconditionaltargetobject);  
                  if(insertconditionaloption=="cm_insertafter"){
                     tempinsertconditionaltargetobjectchildarray.splice(tempindex+1,0,tempobject);  
                  }
                  else{
                      tempinsertconditionaltargetobjectchildarray.splice(tempindex,0,tempobject);    
                  }
               }
               else{
                  //Comment: This part has to do with where to put the object. It has nothing to do with adding a conditional to the CaluMath.PM.InsertionArray.
                 if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
                    CaluMath.PM.PageMakerObjectArray.push(tempobject); 
                 };
//                  if(CM_TopWindow.CaluMath.PM.InsertionArray.length != 0){
//                     CM_TopWindow.CaluMath.PM.InsertionArray.lastobjectchildarray().push(tempobject);
//                  }
//                  else{
//                     CaluMath.PM.PageMakerObjectArray=CaluMath.PM.PageMakerObjectArray.concat(tempobject);
//                  };
               };
            }
            else{
                  CaluMath.PM.AssignParents();
                  var tempinsertconditionaltarget=tempobject.cm_getsetting("insertconditionaltarget");
                  var insertconditionaloption=tempobject.cm_getsetting("insertconditionaloption");
                  if(oldtempinsertconditionaltarget != tempinsertconditionaltarget || oldinsertconditionaloption != insertconditionaloption){
                     var tempoldindex= CaluMath.PM.ArrayIndex(tempobject.parent.childarray,tempobject);

                     tempobject.parent.childarray.splice(tempoldindex,1);
                     if(tempobject.cm_getsetting("insertconditionaloption") != "n/a"){ 
                        var tempinsertconditionaltargetindex= CaluMath.PM.ArrayIndex(CaluMath.PM.PlotlistObject.conditionallist,tempinsertconditionaltarget,0);
                        var tempinsertconditionaltargetobject=CaluMath.PM.PlotlistObject.conditionallist[tempinsertconditionaltargetindex][2]; 
                        tempinsertconditionaltargetobjectchildarray=tempinsertconditionaltargetobject.parent.childarray;
                        var tempindex= CaluMath.PM.ArrayIndex(tempinsertconditionaltargetobjectchildarray, tempinsertconditionaltargetobject);  
                        if(insertconditionaloption=="cm_insertafter"){
                           tempinsertconditionaltargetobjectchildarray.splice(tempindex+1,0,tempobject);                          }
                        else{
                            tempinsertconditionaltargetobjectchildarray.splice(tempindex,0,tempobject);                            };
                     }
                     else{
                        tempobject.parent.childarray.push(tempobject); 
                     };
                  };
            }; 

            CaluMath.PM.SetWriteTag(tempobject); 
            //Comment: We make the local variable topwindoweditmode since standardcleanup will make CM_TopWindow.CM_EditMode false. 
            var topwindoweditmode=CM_TopWindow.CM_EditMode;
            finishbuttonElement.standardcleanup();


               if(!topwindoweditmode){
                  CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempobject, "NoQuote"));
               };


               var tempbranchtype=tempobject.cm_getsetting("branchtype"); 
               if(tempbranchtype == "else"){
                  if(topwindoweditmode != true){
                     cm_alert("Now add the item you want to your Conditional");
                     CaluMath.PM.HidePageControls("visible");
                  };
               }
               else if(tempbranchtype == "if"){
                  if(topwindoweditmode != true){
                     cm_alert("Now do the comparison for the "+tempbranchtype);
                     var tempobjecttocreatecomparison= new Object();
                     tempobjecttocreatecomparison.label="Comparison";
                     tempobjecttocreatecomparison.value="comparison";
                     CaluMath.PM.MATHBUTTONFUNCTION(tempobjecttocreatecomparison,"no");
                  };
               }
               else if(tempbranchtype == "if only"){
                  if(topwindoweditmode != true){
                     cm_alert("Now do the comparison for the "+tempbranchtype);
                     var tempobjecttocreatecomparison= new Object();
                     tempobjecttocreatecomparison.label="Comparison";
                     tempobjecttocreatecomparison.value="comparison";
                     CaluMath.PM.MATHBUTTONFUNCTION(tempobjecttocreatecomparison,"no");
                  };
               }
               else{
                  if(topwindoweditmode != true){
                     cm_alert("Now do the comparison for the "+tempbranchtype);
                     var tempobjecttocreatecomparison= new Object();
                     tempobjecttocreatecomparison.label="Comparison";
                     tempobjecttocreatecomparison.value="comparison";
                     CaluMath.PM.MATHBUTTONFUNCTION(tempobjecttocreatecomparison,"no");
                  };
               };


            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
            if(topwindoweditmode== true){
               cm_alert("The changes to the "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+" have been made."); 
            };
         };

      }
      else if(selectedvalue=="addtoconditional"){ 

         if(CaluMath.PM.PlotlistObject.conditionallist==null || CaluMath.PM.PlotlistObject.conditionallist.length ==0){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any conditionals. Please do so before trying to add to a conditional.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtoconditional", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtoconditional", selectedlabel, "Button Action"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            CaluMath.PM.CreateSettingsArrays("addtoconditional",tempobject);
            var selectedindex= CaluMath.PM.PageMakeraddtoconditionalDefault.required.conditional.menu.options.selectedIndex;
            finishbuttonElement.standardcleanup();
            CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(CaluMath.PM.PlotlistObject.conditionallist[selectedindex][2], "NoQuote"));
            cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            // PAGECONTROLCONTAINER.style.display="none";
            // PAGEASSISTCONTAINER.style.display="block";
            CaluMath.PM.HidePageControls("visible"); 

         };           
      }

//////////////////////////////////////////////////////////////////

      else if(selectedvalue=="routine"){ 
         tempobject=CaluMath.PM.ObjectStandardBeginning("routine", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "routine", selectedlabel, "Routine"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
         };

         if(CM_TopWindow.CM_EditMode == true){
            //Comment: DO NOT REMOVE THE COMMENTED LINE BELOW. CaluMath.PM.EditIndividualEntries has some bugs and so was removed. We should reconsider whether it should be used in the future. 
            var tempcreatedbuttons= CaluMath.PM.EditIndividualEntries(tempobject, finishbuttonElement, cancelbuttonElement, deletebuttonElement);
            var downalevelbutton= tempcreatedbuttons[0];
            var recreatebutton= tempcreatedbuttons[1];
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("routine",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            //Comment: We make the local variable topwindoweditmode since standardcleanup will make CM_TopWindow.CM_EditMode false. 
            var topwindoweditmode=CM_TopWindow.CM_EditMode;
            finishbuttonElement.standardcleanup();
            if(!topwindoweditmode){
                  CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(tempobject, "NoQuote"));
                  cm_alert("Now add the item you want to your Routine");
                  CaluMath.PM.HidePageControls("visible");
            };
            if(tempobject.downalevelbutton != null && tempobject.downalevelbutton.parentNode != null){
               tempobject.downalevelbutton.parentNode.removeChild(tempobject.downalevelbutton);
               delete tempobject.downalevelbutton;
            };
            if(topwindoweditmode== true){
               cm_alert("The changes to the "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+" have been made."); 
            };
         };

      }
      else if(selectedvalue=="addtoroutine"){ 

         if(CaluMath.PM.PlotlistObject.routinelist==null || CaluMath.PM.PlotlistObject.routinelist.length ==0){
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

            return cm_alert("You have not created any routines. Please do so before trying to add to a routine.");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("addtoroutine", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "addtoroutine", selectedlabel, "Add To Routine"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            CaluMath.PM.CreateSettingsArrays("addtoroutine",tempobject);
            var selectedindex= CaluMath.PM.PageMakeraddtoroutineDefault.required.routine.menu.options.selectedIndex;
            finishbuttonElement.standardcleanup();
            CaluMath.PM.InsertionArray.push(new CaluMath.PM.InsertionObject(CaluMath.PM.PlotlistObject.routinelist[selectedindex][2], "NoQuote"));
            cm_alert("Now construct the item you want to add to your "+CaluMath.PM.PageMakerObjectLabelName(tempobject)+".");
            // PAGECONTROLCONTAINER.style.display="none";
            // PAGEASSISTCONTAINER.style.display="block";
            CaluMath.PM.HidePageControls("visible"); 

         };           
      }
      else if(selectedvalue=="executeroutine"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("executeroutine", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "executeroutine", selectedlabel, "Execute A Routine"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.executeroutinelist==null || CaluMath.PM.PlotlistObject.executeroutinelist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any Routines or Button Actions. Please do so before trying to Execute A Routine.");
            return cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("executeroutine",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="animationroutine"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("animationroutine", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


//         var stopanimationroutine=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "animationplot", "animationplotlist", "Animation", "no"); 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "dragroutine", selectedlabel, "Execute A Routine"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.animationplotlist==null || CaluMath.PM.PlotlistObject.animationplotlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any animations. Please do so before trying to associate a routine to an animation.");
            return cancelbuttonElement.onclick();
         };

//         if(stopanimationroutine=="yes"){
//           alert("You have not created an animation. Please do this before trying to associate a routine to an animation.");
//            cancelbuttonElement.onclick();
//         };

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("animationroutine",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="dragroutine"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("dragroutine", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

//         var stopdragroutine=CaluMath.PM.MakeChangeNewPlotMenuRoutine(tempobject, "required", "graph", "slidingscaleslist", "If So, Choose Sliding Scale", "no"); 

         CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakerdragroutineDefault, "required", ["newplot", "menu", CaluMath.PM.PlotlistObject.slidingscalelist.concat(CaluMath.PM.PlotlistObject.newplotlist), 0, "Axes or Sliding Scale"]);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "dragroutine", selectedlabel, "Execute A Routine"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };


//         if(stopdragroutine=="yes"){
//           alert("You have not created anything that can be dragged yet. Please do this first.");
//            cancelbuttonElement.onclick();
//         };

if(CaluMath.PM.PlotlistObject.slidingscalelist.concat(CaluMath.PM.PlotlistObject.newplotlist).length==0){
   alert("You have not constructed any axes or sliding scales. You must do this before you associate a routine to a set of axes or a sliding scale.");
   return cancelbuttonElement.onclick();
};

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("dragroutine",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
///////////////////////////////////////////////////////////////////////////////////////////
      else if(selectedvalue=="hideandunhide"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("hideandunhide", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "hideandunhide", selectedlabel, "Hide and Unhide"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

//         var temparray=CaluMath.PM.PlotlistObject.namedobjectlist;
         var temparray=new Array();
         for(var j=0; j<CaluMath.PM.PlotlistObject.newwindowlist.length; j++){
            temparray=temparray.concat(CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newwindowlist[j][0]].namedobjectlist);
         };


         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("hideandunhide",tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };

            //Comment: We need to keep track of the window the hide or unhide target is in. Therefore we add it to the required array.
            var tempselectedindex=CaluMath.PM.PageMakerhideandunhideDefault.required.hidetarget.menu.options.selectedIndex;
            var hideandunhidetarget=temparray[tempselectedindex][2];
            tempobject.cm_setrequired("cm_caswindow",CaluMath.PM.GetPageMakerObjectSetting(hideandunhidetarget,"cm_caswindow"));
            tempobject.cm_setrequired("dynamic",CaluMath.PM.GetPageMakerObjectSetting(hideandunhidetarget,"dynamic"));
            tempobject.cm_setrequired("hidetargettype",hideandunhidetarget.type);

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="removehtml"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("removehtml", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "removehtml", selectedlabel, "Remove HTML"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

//         var temparray=CaluMath.PM.PlotlistObject.namedobjectlist;
         var temparray=new Array();
         for(var j=0; j<CaluMath.PM.PlotlistObject.newwindowlist.length; j++){
            temparray=temparray.concat(CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newwindowlist[j][0]].namedobjectlist);
         };


         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("removehtml",tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };

            //Comment: We need to keep track of the window the hide or unhide target is in. Therefore we add it to the required array.
            var tempselectedindex=CaluMath.PM.PageMakerremovehtmlDefault.required.hidetarget.menu.options.selectedIndex;
            var removehtmltarget=temparray[tempselectedindex][2];
            tempobject.cm_setrequired("cm_caswindow",CaluMath.PM.GetPageMakerObjectSetting(removehtmltarget,"cm_caswindow"));
            tempobject.cm_setrequired("hidetargettype",removehtmltarget.type);

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="gettextboxvalue"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("gettextboxvalue", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "gettextboxvalue", selectedlabel, "Get TextBox Value"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.textboxlist==null || CaluMath.PM.PlotlistObject.textboxlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any Text Boxes. Please do so before trying use a Get Text Box Value.");
            return cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;

            var tempstring=CaluMath.PM.CreateSettingsArrays("gettextboxvalue",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();
         };

      }
      else if(selectedvalue=="puttextboxvalue"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("puttextboxvalue", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "puttextboxvalue", selectedlabel, "Place Value In Textbox"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
            CaluMath.PM.AssignParents();
            var tempparent = tempobject.parent;
            var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
            tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
            deletebuttonElement.standardonclick();
         };

         if(CaluMath.PM.PlotlistObject.textboxlist==null || CaluMath.PM.PlotlistObject.textboxlist.length ==0){
            CaluMath.PM.DisplayPageControls(); 
            cm_alert("You have not created any Text Boxes. Please do so before trying use a Place Value In Text Box.");
            return cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;

            var tempstring=CaluMath.PM.CreateSettingsArrays("puttextboxvalue",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };
            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="getboxindex"){ 


         tempobject=CaluMath.PM.ObjectStandardBeginning("getboxindex", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "getboxindex", selectedlabel, "Get Radio Button Index"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;

            var tempstring=CaluMath.PM.CreateSettingsArrays("getboxindex",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);  
            };

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };

      }
      else if(selectedvalue=="search"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("search", arguments[0]);

         if(CM_TopWindow.CM_EditMode){
            var plotformenu=CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot");
            var functionformenu=CaluMath.PM.GetPageMakerObjectSetting(tempobject, "graph");
            CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["newplot", "menu", CaluMath.PM.PlotlistObject.newplotlist,CaluMath.PM.PlotlistObject.newplotlist[0][0],  [["Plot", "help/individual_help.html#requirednewplot"], "Axes for graph", "same"]]);
            if(CaluMath.PM.PlotlistObject[plotformenu].cansupportsearcheslist.length >0){
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[plotformenu].cansupportsearcheslist,CaluMath.PM.PlotlistObject[plotformenu].cansupportsearcheslist[0][0],  [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
            }
            else{
               CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", [[" ", " "]],"", [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
            };
            CaluMath.PM.PopulateTableWithCurrentValues("search",arguments[0]);
         }
         else{
            var cansupportsearches=false;
            cansupportsearchesloop:
            for(var j=0; j<CaluMath.PM.PlotlistObject.newplotlist.length; j++){
               if(CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newplotlist[j][0]].cansupportsearcheslist.length != 0){
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["newplot", "menu", CaluMath.PM.PlotlistObject.newplotlist,CaluMath.PM.PlotlistObject.newplotlist[j][0],  [["Plot", "help/individual_help.html#requirednewplot"], "Axes for graph", "same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newplotlist[j][0]].cansupportsearcheslist, CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newplotlist[j][0]].cansupportsearcheslist[0][0],  [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
                  cansupportsearches=true;
                  var goodsearchindex=j;
                  var goodoptionindex=CaluMath.PM.PageMakersearchDefault.required.newplot.menu.selectedIndex;
                  break cansupportsearchesloop;
               };
            };


            //Comment: We then assign an onchange function that changes the list of functions to those associated with the chosen plot. 
            CaluMath.PM.PageMakersearchDefault.required["newplot"].menu.onchange=function(){ 
               var tempchosenplotnew= CaluMath.PM.PageMakersearchDefault.required.newplot.menu[CaluMath.PM.PageMakersearchDefault.required.newplot.menu.selectedIndex].value;
               if(CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist.length >0){
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist , CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist[0][0], [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
               }
               else{
// I temporarily deleted this but this needs to be addressed                CaluMath.PM.PageMakersearchDefault.required.newplot.menu.options[goodoptionindex].selected=true
//                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newplotlist[goodsearchindex][0]].cansupportsearcheslist, CaluMath.PM.PlotlistObject[CaluMath.PM.PlotlistObject.newplotlist[goodsearchindex][0]].cansupportsearcheslist[0][0],  [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", [[" ", " "]],"", [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
               };
            };
         };
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         
         if(CM_EditMode){
            CaluMath.PM.PageMakersearchDefault.required["newplot"].menu.onchange=function(){
               var tempchosenplotnew= CaluMath.PM.PageMakersearchDefault.required.newplot.menu[CaluMath.PM.PageMakersearchDefault.required.newplot.menu.selectedIndex].value;
               if(CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist.length >0 && tempchosenplotnew != tempobject.cm_getsetting("newplot") ){
                  CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist , CaluMath.PM.PlotlistObject[tempchosenplotnew].cansupportsearcheslist[0][0], [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
               }
               else{
                   CaluMath.PM.MakeDefaultOption(CaluMath.PM.PageMakersearchDefault.required["newplot"].menu, tempobject.cm_getsetting("newplot"), "value"); 
                  if(CaluMath.PM.PlotlistObject[tempobject.cm_getsetting("newplot")].cansupportsearcheslist.length >0){
                     CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", CaluMath.PM.PlotlistObject[tempobject.cm_getsetting("newplot")].cansupportsearcheslist,tempobject.cm_getsetting("graph"),  [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
                  }
                  else{
                     CaluMath.PM.UpdateIndividualOption(CaluMath.PM.PageMakersearchDefault, "required", ["graph", "menu", [[" ", " "]],"", [["Graph", "help/individual_help.html#requiredgraph"], "Search This Graph", "same"]]);
                  };
               };
            };
          };
CaluMath.PM.PageMakersearchDefault.required["newplot"].menu.onchange();

         //Comment: We warn them that changing the name of a plot or the function is not a good idea, since tangents are children of the functionplot they are drawn on. 


         //Comment: This produces the standard cancel, delete and finish buttons for math objects. Noted that the onclick function for cancel, is exactly what the standardonclick function is. For the delete button, we need to add some specialized things that only deal with the delete button for the "Define A Function" case. 
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "search", selectedlabel, "Graph of Tangent"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakersearchDefault.required.newplot.menu.onfocus=null;
//            CaluMath.PM.PageMakersearchDefault.required.graph.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
//              CaluMath.PM.PageMakersearchDefault.required.newplot.menu.onfocus=null;
//              CaluMath.PM.PageMakersearchDefault.required.graph.menu.onfocus=null;
         };

         //Comment: Near the top of the search section, we defined canaddsearchs to be false, if there are no objects in any plot that can have a search drawn on them. In this case we want to exit the search screen. However, we need to clean up. So the check is put here, after the cancelbutton is defined, so we can call its event handler. 
         if(cansupportsearches ==false){
//            cm_alert("You have not drawn a graph that supporst a Search. You cannot do any searchs without doing this first.");
//            cancelbuttonElement.onclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("search", tempobject);
            if(tempstring == null){
               return;
            };

            //Comment: This places the object correctly as either an element of CaluMath.PM.PageMakerObjectArray or a child of another element. 
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
       
         };
      }
      else if(selectedvalue=="putboxindex"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("putboxindex", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "putboxindex", selectedlabel, "Put Radio Button Index"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
//         deletebuttonElement.onclick=deletebuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;

            var tempstring=CaluMath.PM.CreateSettingsArrays("putboxindex",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject); 
            finishbuttonElement.standardcleanup();

         };

      }
      else if(selectedvalue=="importpage"){ 

         if(CM_EditMode){
            return alert("You cannot import a web page in Edit Mode");
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("importpage", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         try{
            CaluMath.PM.PageMakerimportpageDefault.required.address.input.setAttribute("type","file");
         }
         catch(e){ CaluMath.Html.NullFunction();
         };

         if(CM_TopWindow.CM_EditMode){
            var oldaddress=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"address");
         };  

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "importpage", selectedlabel, "Import Page"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("importpage",tempobject);
            if(tempstring == null){
               return;
            };

            if(temprequired.address.length==0){
               temprequired.address=oldaddress; 
               CaluMath.PM.SetPageMakerObjectSetting(tempobject,"address", temprequired.address);
            }
            else if(temprequired.exactaddress=="no"){
               var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
               var address=temprequired.address.replace(/\\/g,"/").replace(/^[\/\"\/]/,'');
               var addressuptoslash=address;
               while(pathname.charAt(0)==address.charAt(0)){
                  if(pathname.charAt(0)=="/"){
                     addressuptoslash=address.slice(1);
                  };
                  pathname=pathname.slice(1); 
                  address=address.slice(1);
               };
               if(pathname.match(/\//)){
                  var numberofforwardslashes= pathname.split("/").length;
                  var tempdots="";
                  for(var i=1; i<numberofforwardslashes; i++){
                     tempdots=tempdots+"../";
                  };
                  tempdots= tempdots+addressuptoslash;

                  temprequired.address=tempdots;  //  'file:///'+temprequired.address.replace(/\\/g,"/");
                  CaluMath.PM.SetPageMakerObjectSetting(tempobject,"address", temprequired.address);
               }
               else{
                  tempdots= ''+addressuptoslash;
                  temprequired.address=tempdots;
               };
            };

//            tempwindow= window.open(temprequired.address, CM_TopWindow.CaluMath.PM.OpenWindowIndex++, "height="+Math.round(3*window.screen.availHeight/4)+", width="+Math.round(3*window.screen.availWidth/4)+", menubar=yes, scrollbars=yes, resizable=yes");
            tempwindow= window.open(temprequired.address, '', "height="+Math.round(3*window.screen.availHeight/4)+", width="+Math.round(3*window.screen.availWidth/4)+", menubar=yes, scrollbars=yes, resizable=yes");

            
//            window[temprequired.name]=tempwindow;
            window["CaluMath"]["PM"]["ImportWindow"]=tempwindow;
            
//            tempwindow.cm_importstring= 'CM_ParsePageMakerPageImport(window["'+temprequired.name+'"], "'+temprequired.name+'")';
            tempwindow.cm_importstring= 'CaluMath.PM.ParsePageMakerPageImport(window["CaluMath"]["PM"]["ImportWindow"], "'+temprequired.name+'")';

            tempwindow.cm_importfunction= function(){
               if(tempwindow.cm_windowloaded == "yes"){
                  tempwindow.focus();
                  if(tempwindow.confirm("Is this the page you wanted to import? Click OK if you want to import it and Cancel if you do not.")){
                     try{
                        CM_TopWindow.ImportMode="yes";
                        eval(tempwindow.cm_importstring);
                        CM_TopWindow.ImportMode=null;
                        tempwindow.close();
                     }
                     catch(e){
                        alert("There is a problem with the page you are trying to import. Because of this, it cannot be imported. I am closing the window now.");
                        CM_TopWindow.ImportMode=null;
                        tempwindow.close();
                     };
//                     document.getElementById("createpage").onclick();
                     finishbuttonElement.standardcleanup();
                  }
                  else{
                     tempwindow.close();
                     return ;
                  };
               }
               else{
                  setTimeout(tempwindow.cm_importfunction, 100);
               };
            };
            tempwindow.cm_importfunction();
         };
      }
      else if(selectedvalue=="changebuttontype"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("changebuttontype", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "changebuttontype", selectedlabel, "Change Button Type"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            //Comment: CaluMath.PM.CreateSettingsAndOptionString examines the user input in the input boxes and drop down menus and sees whether the entries are valid or not. If they are, they create the settings property of the associated object and return the options string to be put in the actual CaluMath.PM.Math code. If the entries are not correct, it returns undefined. So we check whether the return is undefined. If it is, we return undefined for the finishbuttonElement button, to stop processing of the input and allow them to change their input.
//            var tempstring=CaluMath.PM.CreateSettingsAndOptionString("changebuttontype",tempobject);
            var tempstring=CaluMath.PM.CreateSettingsArrays("changebuttontype",tempobject);
            if(tempstring == null){
               return;
            };

            var buttonindex=CaluMath.PM.PageMakerchangebuttontypeDefault.required.button.menu.selectedIndex;
            var buttonobject=CaluMath.PM.PlotlistObject.buttonlist[buttonindex][2];

            var buttontypeindex=CaluMath.PM.PageMakerchangebuttontypeDefault.required.buttontype.menu.selectedIndex;
            var buttontype=CaluMath.PM.PageMakerchangebuttontypeDefault.required.buttontype.menu[buttontypeindex].value;

            buttonobject.type=buttontype;
            finishbuttonElement.standardcleanup();
            CM_TopWindow.CM_EditMode=true;
//alerttest(buttonobject);
            CaluMath.PM.MATHBUTTONFUNCTION(buttonobject);

         };

      }
      else if(selectedvalue=="putfocus"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("putfocus", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "putfocus", selectedlabel, "Put Focus On A Box Or Button"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
           CaluMath.PM.AssignParents();
           var tempparent = tempobject.parent;
           var childindex= CaluMath.PM.ArrayIndex(tempparent.childarray, tempobject); 
           tempparent.childarray=tempparent.childarray.slice(0,childindex).concat(tempparent.childarray.slice(childindex+1));
           deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("putfocus",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject); 
            };

            CaluMath.PM.SetWriteTag(tempobject);  
            var tempselectedindex=CaluMath.PM.PageMakerputfocusDefault.required.target.menu.options.selectedIndex;
            var tempcaswindow= CaluMath.PM.GetPageMakerObjectSetting(CaluMath.PM.PlotlistObject.focuslist[tempselectedindex][2],"cm_caswindow");
            tempobject.cm_setrequired("cm_caswindow",tempcaswindow); 
//          var temptarget= CaluMath.PM.PageMakerputfocusDefault.required.target.menu.options[tempselectedindex].label;
            finishbuttonElement.standardcleanup();
         };

      }
      else if(selectedvalue=="textstylesheet"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("textstylesheet", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "textstylesheet", selectedlabel, "Set Defaults"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         //Comment: If they delete a stylesheet, we want to make sure to update the CaluMath.PM.CSSSyleSheetString.
         deletebuttonElement.onclick=function(){
            deletebuttonElement.standardonclick();
            CM_TopWindow.CaluMath.PM.CSSStyleSheetString='';
            var stylelist=CaluMath.PM.PlotlistObject.textstylesheetlist;
            var stylelistlength=stylelist.length;
         };   

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("textstylesheet",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               var tempindex=CaluMath.PM.StyleInsertionPoint();
               CaluMath.PM.PageMakerObjectArray.splice(tempindex,0,tempobject);
            };
            CaluMath.PM.SetWriteTag(tempobject);  


            finishbuttonElement.standardcleanup();
         };

      }
      else if(selectedvalue=="arrow"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("arrow", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 
//         if(CM_TopWindow.CM_EditMode){
//            CaluMath.PM.PageMakerarrowDefault.required.newplot.menu.onfocus=function(){
//               cm_alert("You cannot change the axis that the point is drawn on while in Edit Mode. If you want, delete the point, and then draw it on the axes that you want.");
//               CaluMath.PM.PageMakerarrowDefault.required.newplot.menu.blur();
//               CaluMath.PM.PageMakerarrowDefault.required.newplot.menu.onfocus=CaluMath.PM.PageMakerarrowDefault.required.newplot.menu.blur;
//            };
//         };


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "arrow", selectedlabel, "Arrow"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerarrowDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
//              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
//              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("arrow",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="bracket"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("bracket", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);



         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "bracket", selectedlabel, "Bracket"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerbracketDefault.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("bracket",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            CaluMath.PM.SetWriteTag(tempobject);  
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="pointbrackets3"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("pointbrackets3", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         //Comment: We warn them that changing the name of a plot is not a good idea, since graphs are defined in terms of the plot name. 


         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "pointbrackets3", selectedlabel, "Point Brackets"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerpointbrackets3Default.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("pointbrackets3",tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="pointbrackets2"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("pointbrackets2", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "pointbrackets2", selectedlabel, "Point Brackets II"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerpointbrackets2Default.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("pointbrackets2",tempobject);
            if(tempstring == null){
               return;
            };
            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="pointbrackets1"){

         if(CaluMath.PM.AlertNoNewPlotConstructedYet(selectedvalue)=="stop"){
            return ;
         };

         tempobject=CaluMath.PM.ObjectStandardBeginning("pointbrackets1", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);



         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "pointbrackets1", selectedlabel, "Point Brackets I"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
//            CaluMath.PM.PageMakerpointbrackets1Default.required.newplot.menu.onfocus=null;
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("pointbrackets1",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no" || CaluMath.PM.NewPlotChangeRoutine(tempobject, temprequired)){ 
               CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray=CaluMath.PM.PlotlistObject.newplotlist[CaluMath.PM.PlotlistObject.newplotlist.cm_obtainindex(temprequired.newplot,0)][2].childarray.concat(tempobject);
            };

            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="endinsertionarray"){

         cm_alert('You should only invoke this if you accidentally said you wanted to continue a Button Action, Conditional, New Window, Routine, or similary action, but realize that you really want to end it. If this is what you want click on the "End Button Action, Conditional, New Window or Routine". Otherwise, click on the "Continue With Button Action, Conditional, NewWindow or Routine" to continue with your Button Action or Conditional or Routine.'); 

         var finishbutton=document.createElement("input");
         finishbutton.setAttribute("type","button");
         finishbutton.setAttribute("value","End Button Action, Conditional, New Window, or Routine");
         CaluMath.PM.BUTTONCONTAINER.appendChild(finishbutton);

         var cancelbutton=document.createElement("input");
         cancelbutton.setAttribute("type","button");
         cancelbutton.setAttribute("value","Continue With Button Action, Conditional, New Window, or Routine");
         CaluMath.PM.BUTTONCONTAINER.appendChild(cancelbutton);

         cancelbutton.onclick=function(){
            cancelbutton.parentNode.removeChild(cancelbutton);
            cancelbutton.parentNode.removeChild(cancelbutton);
            // PAGECONTROLCONTAINER.style.display="block";
            // PAGEASSISTCONTAINER.style.display="none";
            CaluMath.PM.DisplayPageControls(); 

         };            

         finishbutton.onclick=function(){
            CaluMath.PM.InsertionObjectAlerts(CM_TopWindow.CaluMath.PM.InsertionArray[CM_TopWindow.CaluMath.PM.InsertionArray.length-1]);
            finishbutton.parentNode.removeChild(finishbutton);
            cancelbutton.parentNode.removeChild(cancelbutton);
         };            
      }
      else if(selectedvalue=="focusobject"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("focusobject", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "focusobject", selectedlabel, "FocusObject"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=cancelbuttonElement.standardonclick;
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();
         };

         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("focusobject",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               CaluMath.PM.PageMakerObjectArray.push(tempobject);
            };
            CaluMath.PM.SetWriteTag(tempobject);
            finishbuttonElement.standardcleanup();
         };
      }
/*
      else if(selectedvalue=="webpagename"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("webpagename", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "webpagename", selectedlabel, "Name Web Page"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=deletebuttonElement.standardonclick;

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("webpagename",tempobject);
            if(tempstring == null){
               return;
            };

            CaluMath.PM.PageName=temprequired.name;
            finishbuttonElement.standardcleanup();
         };
      }
*/
      else if(selectedvalue=="webpagename"){

         tempobject=CaluMath.PM.ObjectStandardBeginning("webpagename", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);


         window.location.hash="#endofdocument"; 

         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "webpagename", selectedlabel, "Web Page Name"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              deletebuttonElement.standardonclick();

         };
    
         finishbuttonElement.onclick=function(){
            CaluMath.PM.PlotNameIndex++;
            var tempstring=CaluMath.PM.CreateSettingsArrays("webpagename",tempobject);
            if(tempstring == null){
               return;
            };

            if(CaluMath.PM.AutomaticallyPlaceObjectAsChild(tempobject)=="no"){  
               var tempindex=CaluMath.PM.HeadHtmlInsertionPoint();
               CaluMath.PM.PageMakerObjectArray.splice(tempindex,0,tempobject);
            };
           
            finishbuttonElement.standardcleanup();
         };
      }
      else if(selectedvalue=="coordinates"){ 

         tempobject=CaluMath.PM.ObjectStandardBeginning("coordinates", arguments[0]);
         var temprequired=CaluMath.Html.MakeTempObject(tempobject);
         var buttonarray= CaluMath.PM.MakeCancelDeleteAndFinishButtons(tempobject, "coordinates", selectedlabel, "Math Text"); 
         var finishbuttonElement=buttonarray[0];
         var cancelbuttonElement= buttonarray[1];
         var deletebuttonElement= buttonarray[2];
         cancelbuttonElement.onclick=function(){
            newspecialobjectbuttonElement.parentNode.removeChild(newspecialobjectbuttonElement);
            coordinatesspecialsymbolsSELECT.parentNode.removeChild(coordinatesspecialsymbolsSELECT);
            breakElement.parentNode.removeChild(breakElement);
            cancelbuttonElement.standardonclick();
         };
         deletebuttonElement.onclick=function(){
              CaluMath.PM.AssignParents();
              var tempobjectparent=tempobject.parent; 
              var childindex= CaluMath.PM.AssignChildIndex(tempobject); 
              tempobjectparent.childarray=tempobjectparent.childarray.slice(0,childindex).concat(tempobjectparent.childarray.slice(childindex+1));
              newspecialobjectbuttonElement.parentNode.removeChild(newspecialobjectbuttonElement);
              coordinatesspecialsymbolsSELECT.parentNode.removeChild(coordinatesspecialsymbolsSELECT);
              breakElement.parentNode.removeChild(breakElement);
              deletebuttonElement.standardonclick();
         };

                  var specialsymbolsunicodeLISTlength=CaluMath.PM.specialsymbolsunicodeLIST.length;
//                  for(var i=0; i<specialsymbolsunicodeLISTlength; i++){
//                     if(specialsymbolsunicodeLIST[i] != null){ 
//                        var tempregexpression= new RegExp(specialsymbolsunicodeLIST[i][1].replace(/Unicode\(/g, "Unicode\\(").replace(/\)/g, "\\)"),"g");
//                        var tempregexpression1= new RegExp(specialsymbolsunicodeLIST[i][1]);
//                        CaluMath.PM.PageMakercoordinatesDefault.required.value.input.value=CaluMath.PM.PageMakercoordinatesDefault.required.value.input.value.replace(tempregexpression, specialsymbolsunicodeLIST[i][0]);
//                     };
//                  };

               var newspecialobjectbuttonElement=document.createElement("input");
               newspecialobjectbuttonElement.setAttribute("type","button");
               newspecialobjectbuttonElement.setAttribute("value","Insert Special Character");
               document.getElementById("displayleft").appendChild(newspecialobjectbuttonElement);

               var coordinatesspecialsymbolsSELECT=CaluMath.PM.specialsymbolsSELECT.cloneNode(true);
               document.getElementById("displayleft").appendChild(coordinatesspecialsymbolsSELECT);
               newspecialobjectbuttonElement.onclick=function(){
//                  var character = coordinatesspecialsymbolsSELECT.options[coordinatesspecialsymbolsSELECT.selectedIndex].label.replace(/^\s*/g,""); 
                  var character = coordinatesspecialsymbolsSELECT.options[coordinatesspecialsymbolsSELECT.selectedIndex].value.replace(/^\s*/g,""); 
                  CaluMath.PM.PageMakercoordinatesDefault.required.value.input.value= CaluMath.PM.PageMakercoordinatesDefault.required.value.input.value+character;
               };
               var breakElement= document.createElement("br");
               document.getElementById("displayleft").appendChild(breakElement);

         //Comment: This deals with a positioning bug with Mozilla. 
         finishbuttonElement.style.display="none";
         finishbuttonElement.style.display="inline";

         finishbuttonElement.onclick=function(){
            var tempstring=CaluMath.PM.CreateSettingsArrays("coordinates",tempobject);
            if(tempstring == null){
               return alerttest("Hi");
            };
               newspecialobjectbuttonElement.parentNode.removeChild(newspecialobjectbuttonElement);
               coordinatesspecialsymbolsSELECT.parentNode.removeChild(coordinatesspecialsymbolsSELECT);
               breakElement.parentNode.removeChild(breakElement);
               finishbuttonElement.standardcleanup();
         };
      }
};

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////END OF INDIVIDUAL ENTIRIES////////////////////////////////////////////////
//////////////////////////////////////////////////////END OF INDIVIDUAL ENTIRIES////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



CaluMath.PM.ReCreateObject=function(){ 
 window.CM_EditMode=true;
 var args0=arguments[0];
 if(args0 != null){ 
   if(args0.type=="htmltext" || args0.type=="h1" || args0.type=="h2" || args0.type=="p" || args0.type=="div" || args0.type=="span"){
      CaluMath.PM.WriteAndEdit(args0);
   }
   else{
      CaluMath.PM.MATHBUTTONFUNCTION(args0);
   };
 }
 else{
    CaluMath.PM.WriteAndEdit();
 };
};


CaluMath.PM.MakeSpaces=function(){
   if(arguments[0] < 0){
      return ;
   }
   else if(arguments[0] ==0){
      return '';
   }
   else if(arguments[0] ==1){
      return ' ';
   }
   else{ 
      return ' '+CaluMath.PM.MakeSpaces(arguments[0]-1);
   };
};




CaluMath.PM.TempWindowWriteRemainingImportPageMode= function(){
   if(window["CM_TempWindow"].CM_ClientAddpointsLoaded=="yes"){
      var importarray=CaluMath.PM.TempWindowWriteRemainingImportPageMode.cm_importarray;
//alert(["importarray", importarray]);
      var tempnewstring='<\/script>\n<input type="button" id="cutbutton" value="Cut" /><input type="button" id="copybutton" value="Copy" /><input type="button" id="pastebeforebutton" value="Paste Before" /><input type="button" id="pasteafterbutton" value="Paste After" /><input type="button" id="deletebutton" value="Delete" /><input type="button" id="undocutbutton" value="Undo Cut" /> <input type="button" id="undopastebutton" value="Undo Paste" /> <input type="button" id="closewindowbutton" value="Close" /> '+CM_ScriptTag+'> document.getElementById("cutbutton").onclick=function(){ return window.opener.CaluMath.PM.CutFunction();}; document.getElementById("copybutton").onclick=function(){ return window.opener.CaluMath.PM.CopyFunction();}; document.getElementById("deletebutton").onclick=function(){ return window.opener.CaluMath.PM.DeleteFunction();};  document.getElementById("pastebeforebutton").onclick=function(){ return window.opener.CaluMath.PM.PasteBeforeFunction();};  document.getElementById("pasteafterbutton").onclick=function(){ return window.opener.CaluMath.PM.PasteAfterFunction();};  document.getElementById("undocutbutton").onclick=function(){ window.opener.CaluMath.PM.UndoCutFunction();}; document.getElementById("undopastebutton").onclick=function(){ window.opener.CaluMath.PM.UndoPasteFunction();}; document.getElementById("closewindowbutton").onclick=function(){  window.close();};   <\/script> <br><br><div id="instructionscontainer"  style="text-align:center;" ><input type="button" id="instructionsbutton" value="Click To See Instructions"/><input type="button" id="hideinstructionsbutton" value="Click To Hide Instructions" style="display:none" /><\/div><\script type="text/javascript">document.getElementById("instructionsbutton").onclick=function(){ document.getElementById("instructionslist").style.display="block"; document.getElementById("hideinstructionsbutton").style.display="inline"; document.getElementById("instructionsbutton").style.display="none";};  document.getElementById("hideinstructionsbutton").onclick=function(){ document.getElementById("instructionslist").style.display="none"; document.getElementById("instructionsbutton").style.display="inline"; document.getElementById("hideinstructionsbutton").style.display="none";};<\/script> \n<div id="instructionslist" style="display:none;">\n    <h3>To delete a section of the document:</h3>  \n     <ol>\n         <li>Put your cursor on the first item you want to delete and hold the left mouse button down. Drag the cursor down over the document and lift the button over the final item you want to delete. The beginning and ending items must be "at the same level" of the document, in other words, they must be top level items of the document or they must be children of the same document element. It is not important that you completely highlight the first and last items you want to delete; you only must highlight a part of them.</li>\n         <li>Go to the top of the page and click the Cut Button</li>\n         <li> You will see the items disappear.</li>\n         <li>Click the Delete Button to remove the items permanently from the document</li>\n         <li>The Cut And Paste window automatically reloads so you can cut and paste again.</li>\n     </ol>\n    <h3>To cut and paste a section of the document:</h3>     <ol>\n         <li>Put your cursor on the first item you want to delete and hold the left mouse button down. Drag the cursor down over the document and lift the button over the final item you want to cut. The beginning and ending items must be "at the same level" of the document, in other words, they must be top level items of the document or they must be children of the same document element. It is not important that you completely highlight the first and last items you want to cut; you only must highlight a part of them. </li>\n         <li>Go to the top of the page and click the Cut Button</li>\n         <li> You will see the items disappear.</li>\n         <li>Go down to the item you want to place the cut items before or after and click on it.</li>\n         <li>Click the Paste Before button to insert the cut items before the item you clicked. Click the Paste After button to insert the cut items after the item you clicked.</li>\n         <li>The Cut And Paste window automatically reloads so you can cut and paste again.</li>\n     </ol>\n     <h3>To copy a section of the document:</h3>  \n     <ol>\n         <li>Put your cursor on the first item you want to copy and hold the left mouse button down. Drag the cursor down over the document and lift the button over the final item you want to copy. The beginning and ending items must be "at the same level" of the document, in other words, they must be top level items of the document or they must be children of the same document element. It is not important that you completely highlight the first and last items you want to copy; you only must highlight a part of them. </li>\n         <li>Go to the top of the page and click the Copy Button</li>\n         <li> It is very bad to have two different objects that have the same name that are created in a web page. (The only exception to this is if they are created using a condition if, else-if, then statement. In this case only one of several possible objects with the same name is created). Therefore, if you copy an item, you should adjust the name in some manner. Using the boxes at the top, you have the several options. Suppose you are copying a function named <i>Mygoodfunction</i>.\n         <ol style="list-style-type:lower-alpha">\n             <li> You can add a prefix to the name of the object you are copying. For example, if you type <i>NEW</i> in the Add Prefix To Names box, then the copied function will have the name <i>NEWMygoodfunction</i>. \n             <li> You can add a suffix to the name of the object you are copying. For example, if you type <i>NEW</i> in the Add Suffix To Names box, then the copied function will have the name <i>MygoodfunctionNEW</i>. \n             <li> You can replace letters in the name of <i>Mygoodfunction</i> in one of two ways: either you can replace all occurrences of a pattern of letters by some other pattern of letters, or you can replace the first occurrence of a pattern of letters by some other pattern of letters. For example, if you type <i>o</i> in the box Replace This In Names and <i>YYY</i> in the With This box and choose <i>first occurrence</i> in the Replace menu, the result is <i>MygYYYodfunction</i>. If you type the same information, but choose <i>all occurrences</i>, then the result is <i>MygYYYYYYdfunctiYYYn</i>. If you type <i>oo</i> instead <i>o</i> in the Replace This In Names box, the result is <i>MygYYYdfunction</i>.</li>\n             <li> You can add  a prefix and a suffix and replace combinations of letters in an objects name all at the same time.</li>\n             <li> If you copy several items, adding prefixes, suffixes, or replacing letters is done to all of the items copied.</li>\n         </ol>\n         <li>Go down to the item you want to place the copied items before or after and click on it.</li>\n         <li>Click the Paste Before button to insert the cut items before the item you clicked. Click the Paste After button to insert the cut items after the item you clicked.</li>\n         <li style="color:red"><b><i>Be sure that you paste objects in a place that makes sense. For example, do not paste the graph of a function to a place that is before where the axes are created!</i></b></li>\n         <li>The Cut And Paste window automatically reloads so you can cut and paste again.</li>\n     </ol>\n     <h3>What is the Clipboard?</h3><p>The Clipboard is a place where you can store items without them appearing in the document. Anything placed inside the Clipboard (which is the area at the bottom of the cut and paste window) is not part of your document, however items can be moved freely between the Clipboard and the document. If you Cut and item that you may or may not need in the future, you can place it in the Clipboard. This will allow you to move it back into your document in the future if you find that you need it. There is no way to edit objects in the Clipboard unless you move them so they are again part of your document. When you Save a page, the Clipboard gets saved with it. However it is a good idea to not include junk in the Clipboard, since this makes the size of the web page (in kilobytes) larger, meaning that it may take longer to load.</p>\n     <h3>The other buttons at the top of the Cut And Paste window:</h3>  \n     <ol>\n        <li>If you cut a set of items, clicking the Undo Cut button returns the item to the page so you can begin again.</li>\n        <li>If you do not like the way some items were pasted, you can click the Undo Paste button. This will return your page to the condition it was before you pasted your last items. <i>Note: you can even return to the page you are creating and add more items and make more changes. If you then return to the Cut And Paste window and click the Undo Paste button, it will return your page to the state it was before the last paste. All of your subsequent changes will be lost. (Of course, you can also return to previous versions using the Previous Version button at the top of the <span class="logo1">C</span><span class="logo2">ALU</span><span class="logo3">M</span><span class="logo4">ATH</span> Page Maker page).</i></li>\n        <li>The Close button closes the Cut And Paste window</li>\n     </ol>\n<\/div>\n<br><table border="2px" style="background-color:#F0F0F0" ><tr><td style="text-align:center">Add Prefix To Names</td><td style="text-align:center">Replace This In Names</td><td style="text-align:center">With This</td><td style="text-align:center">Replace</td><td style="text-align:center">Add Suffix To Names</td></tr><tr><td><input id="prefixbox" type="text" size="20" /></td><td><input id="replacebox" type="text" size="20" /></td><td><input id="replacewithbox" type="text" size="20" /></td><td><select id="replacetypemenu"><option  value="first" >first occurrence<\/option><option value="all" >all occurrences<\/option><\/select></td><td><input id="suffixbox" type="text" size="20" /></td></tr></table><br><ol >'  
      var NewString = [tempnewstring +' '+CaluMath.PM.WriteNewWindowStringEditMode(CaluMath.PM.PageMakerObjectArray.concat(CaluMath.PM.ClipBoard)), '<li><span style="font-size:28px; color:red">The Imported Page is Below and Your Current Page is Above. Cut and Paste Something From the Imported Page Into the Current Page.<\/span><\/li>' + CaluMath.PM.WriteNewWindowStringEditMode(importarray)];
      NewString=NewString.join(' ');
      window["CM_TempWindow"].document.write(' '+NewString+'<\/ol><br><br>\n'+CM_ScriptTag+'> CaluMath.PM.HTMLElementIndex='+CaluMath.PM.HTMLElementIndex+'\; CaluMath.PM.PlotNameIndex='+CaluMath.PM.PlotNameIndex+'\;  CaluMath.PM.MathTextIndex='+CaluMath.PM.MathTextIndex+'\; CaluMath.PM.TextIndex='+CaluMath.PM.TextIndex+'\; CaluMath.PM.ContainerIndex='+CaluMath.PM.ContainerIndex+'\; CaluMath.PM.ParagraphIndex='+CaluMath.PM.ParagraphIndex+'\; CaluMath.PM.TitleIndex='+CaluMath.PM.TitleIndex+'\; CaluMath.PM.SectionIndex='+CaluMath.PM.SectionIndex+'\;  window.cm_onload=function(){ window.opener.CaluMath.PM.MakeClickableCutAndPasteI(window);}; <\/script> \n'+CaluMath.PM.NewWindowStringClosing);
      window["CM_TempWindow"].document.close();
   }
   else{
      setTimeout('CaluMath.PM.TempWindowWriteRemainingImportPageMode();', 10);
   };
};


   

//Comment: The function CaluMath.PM.AssignParents is used extensively in this file. //

CaluMath.PM.AssignParents=function(){
  var args0=arguments[0];
  if(args0==null){
     var childarray=CaluMath.PM.PageMakerObjectArray;
     CaluMath.PM.PageMakerObjectArray.childarray=CaluMath.PM.PageMakerObjectArray;
     var childarraylength=childarray.length;
     for(var i=0; i<childarraylength; i++){
        childarray[i].parent=CaluMath.PM.PageMakerObjectArray;
        CaluMath.PM.AssignParents(childarray[i]);
     };

     if(window.CaluMath.PM.ClipBoard != null){
        var tempCM_ClipBoardchildarray= CaluMath.PM.ClipBoard.childarray;
        var tempCM_ClipBoardchildarraylength= tempCM_ClipBoardchildarray.length;
     };

     for(var ii=0; ii<tempCM_ClipBoardchildarraylength; ii++){
        tempCM_ClipBoardchildarray[ii].parent=CaluMath.PM.ClipBoard;
        CaluMath.PM.AssignParents(tempCM_ClipBoardchildarray[ii]);
     };
  }
  else{
     var tempobject=args0;
      var childarray=tempobject.childarray;
     var childarraylength=childarray.length;
     for(var j=0; j<childarraylength; j++){
        childarray[j].parent=tempobject;
        CaluMath.PM.AssignParents(childarray[j]);
     };
  };  
};



CaluMath.PM.AssignChildIndex=function(){
   CaluMath.PM.AssignParents();
  var args0=arguments[0];
  var parent=args0.parent;
  if(parent==null){
     childarray=CaluMath.PM.PageMakerObjectArray;
  }
  else{
     var childarray=parent.childarray
  };
  var childarraylength=childarray.length;
  smallloop:
  for(var j=0; j<childarraylength; j++){
     if(childarray[j]==args0){
        return j; 
        break smallloop;
     };
  };
};

CaluMath.PM.ArrayIndex=function(){
  //Comment: If arguments[2] is not null, then it is assumed that each element of the array consists of an array. If the searchedentry index of the array entry matches entry, the the index is returned. 
   var temparray=arguments[0];
   var temparraylength=temparray.length;
   var entry = arguments[1];
   var searchedentry=arguments[2];
   if(searchedentry == null){
      smallloop:
      for(var i=0; i<temparraylength; i++){
         if(temparray[i]==entry){
            var tempreturn =i;
            break smallloop;
         };
      };
      return tempreturn;
   }
   else{
      smallloop:
      for(var i=0; i<temparraylength; i++){
         if(temparray[i][searchedentry]==entry){
            var tempreturn =i;
            break smallloop;
         };
      };
      return tempreturn;
   };
};


//Comment: Certain objects must be placed among the first items in the page, even if they are not defined first. Therefore, they should be placed at the beginning of the CaluMath.PM.PageMakerObjectArray. One example is definedfunctions. By placing them at the beginning, they can be used anyplace in the page. This function finds the "last place" of the beginning section to place things like definedfunctions, variables, and definedconstants.//
CaluMath.PM.FindScriptInsertionPoint=function(){
  var newarray=CaluMath.PM.PageMakerObjectArray;
  var newarraylength=newarray.length;
  var tempreturn=newarraylength;
  smallloop:
  for(var i=0; i<newarraylength; i++){
     if(newarray[i] != null && newarray[i].type !="headhtml" && newarray[i].type !="webpagename" && newarray[i].type !="textstylesheet" &&  newarray[i].type !="definedfunction" && newarray[i].type !="variablename" && newarray[i].type !="definedconstant" && newarray[i].type !="splitfunction" && newarray[i].type !="comment"){
        tempreturn =i;
        break smallloop;
     };
  };
  return tempreturn;
};

//Comment: This finds the place in the CaluMath.PM.PageMakerArray where headhtml should be placed.//
CaluMath.PM.HeadHtmlInsertionPoint=function(){
  var newarray=CaluMath.PM.PageMakerObjectArray;
  var newarraylength=newarray.length;
  var tempreturn=newarraylength;
  smallloop:
  for(var i=0; i<newarraylength; i++){
     if(newarray[i] != null &&  newarray[i].type !="headhtml" && newarray[i].type !="webpagename"){
        tempreturn =i;
        break smallloop;
     };
  };
  return tempreturn;
};

//Comment; This finds the place in the CaluMath.PM.PageMakerObjectArray where style CSS style defaults should be placed. 
CaluMath.PM.StyleInsertionPoint=function(){
  var newarray=CaluMath.PM.PageMakerObjectArray;
  var newarraylength=newarray.length;
  var tempreturn=newarraylength;
  smallloop:
  for(var i=0; i<newarraylength; i++){
     if(newarray[i] != null && newarray[i].type !="headhtml" && newarray[i].type !="webpagename"  && newarray[i].type !="textstylesheet"){
        tempreturn =i;
        break smallloop;
     };
  };
  return tempreturn;
};



CaluMath.PM.GetPageMakerGraphFullName= function(){
   var tempobject=arguments[0];
   if(tempobject==null || tempobject.type == null){
      return ;
   };
   var tempreturn = "";
   if(tempobject.type=="newplot"){
     tempreturn = CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="functionplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "definedfunction");
   }
   else if(tempobject.type=="discretefunctionplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "discretefunction");
   }
   else if(tempobject.type=="arcplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="labelvertex"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="labelallvertices"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="animationplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="pointplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="rectangleplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="labelplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="textplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="tangent"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="highlight"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="linearplot"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="bracket"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="pointbrackets3"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="pointbrackets2"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="pointbrackets1"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   else if(tempobject.type=="arrow"){
     tempreturn =  CaluMath.PM.GetPageMakerObjectSetting(tempobject, "newplot")+'.'+ CaluMath.PM.GetPageMakerObjectSetting(tempobject, "name");
   }
   return tempreturn;
};

CaluMath.PM.DetermineAncestor= function(){
   var tempobject=arguments[0];
   var type=arguments[1];
   var wantedtype= arguments[2];

   var tempreturn = false;   
   var parentobject= tempobject;
   parentloop:
   while(parentobject.parent != null){
      parentobject=parentobject.parent;
      if(parentobject[type]==wantedtype){
         var tempreturn = true;
         break parentloop;
      };
   };
   return tempreturn;
};
   


CaluMath.PM.DeleteFromLists = function(){
   var tempobject=arguments[0];
   var tempdeletefunction = CM_TopWindow["CaluMath"]["PM"]["DeleteFromLists"+tempobject.type];


   var childarray=tempobject.childarray;
   var childarraylength=childarray.length;
   for(var i =0; i< childarraylength; i++){ //alerttest([childarray[i].type,childarray[i]]);
      CaluMath.PM.DeleteFromLists(childarray[i]);
   };

   if( tempdeletefunction != null){
      tempdeletefunction(tempobject);
   };

};



CaluMath.PM.AddToLists = function(){
   var tempobject=arguments[0];
   var tempdeletefunction = CM_TopWindow["CaluMath"]["PM"]["AddToLists"+tempobject.type];
//alert([tempobject, tempdeletefunction]);
   if( tempdeletefunction != null){
      tempdeletefunction(tempobject);
   };

   var childarray=tempobject.childarray;
   var childarraylength=childarray.length;
   for(var i =0; i< childarraylength; i++){ 
      CaluMath.PM.AddToLists(childarray[i]);
   };


};


CaluMath.PM.ParsePageMakerPageImport=function(){ 
   var tempwindow=arguments[0];
   var tempwindowname=arguments[1];

   var tempwindowpagemakerstring= tempwindow.CaluMath.PM.PageMakerObjectArrayString;
   if(tempwindowpagemakerstring==null){
      //Comment: This should be replaced once we redo the Demo Pages not using this technique anymore.
      var scripttags = tempwindow.document.getElementsByTagName("script");
      var scripttagslength=scripttags.length; 
      if((scripttags[scripttagslength-1].text).slice(3).match(/CM_PageMakerStringDelimiter/)){
         var newarray= (scripttags[scripttagslength-1].text).slice(3).split(/CM_PageMakerStringDelimiter/);
      }
      else{
         var newarray= (scripttags[scripttagslength-1].text).slice(3).split(/ZZZZZZZ/);
      };
   }
   else{
      tempwindowpagemakerstring=tempwindowpagemakerstring.slice(0);
      if(tempwindowpagemakerstring.match(/CM_PageMakerStringDelimiter/)){
         var newarray= tempwindowpagemakerstring.split(/CM_PageMakerStringDelimiter/);
      }
      else{
         var newarray= tempwindowpagemakerstring.split(/ZZZZZZZ/);
      };
   };

   var newarraylength= newarray.length; 

   var tempCM_PageMakerObjectArray= new Array();
   for(var i=0; i<newarraylength-1; i++){ 
      tempCM_PageMakerObjectArray[i]= eval(newarray[i]); 
   };
   CM_TopWindow.CaluMath.PM.CSSTextStyleString='\n.cm_math{white-space:nowrap}\n.cm_mathformula{white-space:nowrap}';
 
/*
 //Comment: This ensures that functions created in the newly loaded window will be defined in the main window.
   for(var i=0; i<CaluMath.PM.PageMakerObjectArray.length; i++){
      var tempobject= CaluMath.PM.PageMakerObjectArray[i];
      if(1==1 && tempobject.type =="definedfunction"){ //alerttest("evaluating the function");
         if(!tempobject.cm_getsetting("definition").match(/\'/) && !tempobject.cm_getsetting("definition").match(/\"/)){ 
            window[tempobject.cm_getsetting("name")]=CaluMath.PM.PlaceholderFunction;
         }
         else{
            window[tempobject.cm_getsetting("name")]=CaluMath.PM.PlaceholderStringFunction;
         };
      };
      if(tempobject.type =="splitfunction"){ //alerttest("evaluating the function");
         if(!tempobject.cm_getsetting("definition").match(/\'/) && !tempobject.cm_getsetting("definition").match(/\"/)){ 
            window[tempobject.cm_getsetting("name")]=CaluMath.PM.PlaceholderFunction;
         }
         else{
            window[tempobject.cm_getsetting("name")]=CaluMath.PM.PlaceholderStringFunction;
         };
      };
      if(tempobject.type =="variablename"){ //alerttest("Making the new variable definition");
         eval(tempobject.cm_writehtml());
      };
      if(tempobject.type =="nameclickedpoint"){ //alerttest("Making the new variable definition");
         var name=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name");
         window[name]=[0,0];
      };
      if(tempobject.type =="namedraggedvalue"){ //alerttest("Making the new variable definition");
         var name=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name");
         window[name]=[0,0];
      };
      if(tempobject.type =="definedconstant"){
         var name=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name");
         var constantdefinition=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"definition"); 
         window[name]=constantdefinition.cm_evalmath();
      };
      if(tempobject.type =="newplot"){
         var tempname=CaluMath.PM.GetPageMakerObjectSetting(tempobject,"name")
      };
   };
*/
   tempCM_PageMakerObjectArray.childarray=tempCM_PageMakerObjectArray;
   CaluMath.PM.AssignParents(tempCM_PageMakerObjectArray);
   CaluMath.PM.AssignCasWindowToTextChildren(tempCM_PageMakerObjectArray);
   CaluMath.PM.OpenTempWindowInEditMode("importpage", tempCM_PageMakerObjectArray );
   setTimeout('CaluMath.PM.MakeClickableCutAndPasteI(CM_TempWindow, "importpage");', 1000);
};


CaluMath.PM.DeletionCheck= function(){
   var tempobject= arguments[0];
   var tempbigdeletefunction = CM_TopWindow["CaluMath"]["PM"]["DeleteFromLists"+tempobject.type];
   tempbigdeletefunction(tempobject);
   CaluMath.PM.AssignParents();


   if(tempobject.type=="functionplot"){
      var tempdefinedfunction= tempobject.cm_getsetting("definedfunction");
      var tempnewplot= tempobject.cm_getsetting("newplot");
      var tempCM_EveryObjectArray=CaluMath.PM.EveryObjectArray;
      var tempCM_EveryObjectArraylength=tempCM_EveryObjectArray.length;
      for(var i = 0; i< tempCM_EveryObjectArraylength; i++){
         var childobject= tempCM_EveryObjectArray[i];
         if(childobject.type=="highlight"  || childobject.type=="textplot"){
            if(childobject.cm_getsetting("newplot")== tempnewplot && childobject.cm_getsetting("definedfunction")== tempdefinedfunction){
               tempdeletefunction = eval("CaluMath.PM.DeleteFromLists"+childobject.type);
               tempdeletefunction(childobject);
               var tempindex= CaluMath.PM.AssignChildIndex(childobject);
               childobject.parent.childarray.splice(tempindex,1);
            };
         }
         else if( childobject.type=="tangent"){
            if(childobject.cm_getsetting("newplot")== tempnewplot && childobject.cm_getsetting("graph")== tempdefinedfunction){
               tempdeletefunction = eval("CaluMath.PM.DeleteFromLists"+childobject.type);
               tempdeletefunction(childobject);
               var tempindex= CaluMath.PM.AssignChildIndex(childobject);
               childobject.parent.childarray.splice(tempindex,1);
            };
         }
      };
   }
   else if(tempobject.type=="tangent"){
      var tempname= tempobject.cm_getsetting("name");
      var tempnewplot= tempobject.cm_getsetting("newplot");
      var tempCM_EveryObjectArray=CaluMath.PM.EveryObjectArray;
      var tempCM_EveryObjectArraylength=tempCM_EveryObjectArray.length;
      for(var i = 0; i< tempCM_EveryObjectArraylength; i++){
         var childobject= tempCM_EveryObjectArray[i];
         if( childobject.type=="highlight"){
            if(childobject.cm_getsetting("newplot")== tempnewplot && childobject.cm_getsetting("definedfunction")== tempname){
               tempdeletefunction = eval("CaluMath.PM.DeleteFromLists"+childobject.type);
               tempdeletefunction(childobject);
               var tempindex= CaluMath.PM.AssignChildIndex(childobject);
               childobject.parent.childarray.splice(tempindex,1);
            };
         }
      };
   }

};
     


CaluMath.PM.FindPageMakerObject=function(){
   var tempobject=CaluMath.PM.PageMakerObjectArray;
   for(var i=0; i<arguments.length; i++){
      tempobject=tempobject.childarray[arguments[i]-1];
   };
   return tempobject;
};   

CaluMath.PM.Find= CaluMath.PM.FindPageMakerObject;

 

    

//Comment: This creates a "tooltip" window that is really not a window at all, but a box whose z index forces it in the front. Keep this code, although it is not being used.//
CaluMath.PM.MakeFakeWindow=function(){
   var tempdocument=arguments[0];
   var divElement=tempdocument.createElement("div");
   divElement.style.width=Math.round((window.screen.width)/3)+"px";
   divElement.style.position="absolute";
   divElement.style.left=Math.round((window.screen.width- Math.round((window.screen.width)/3))/2 )+"px";
   divElement.style.top=Math.round((window.screen.height)/3)+"px";
   divElement.style.zIndex=10000;
   divElement.style.borderStyle="solid";
   divElement.style.borderWidth="2px";
   var barElement=tempdocument.createElement("p");
   barElement.style.width=Math.round((window.screen.width)/3)+"px";
   barElement.style.height="30px";
   barElement.style.backgroundColor="blue";
   barElement.style.textAlign="right";
   var widthElement=tempdocument.createTextNode("Here is something");
   var xElement=tempdocument.createTextNode("X");
   var xspanElement=tempdocument.createElement("span");
   var pElement=tempdocument.createElement("p");
   pElement.style.zIndex=10000;
   divElement.style.backgroundColor="lavender";
   var textElement=tempdocument.createTextNode("Hello everyone. How are your?");
   pElement.appendChild(textElement);
   barElement.appendChild(widthElement);
   barElement.appendChild(xspanElement);
   xspanElement.appendChild(xElement);
   divElement.appendChild(barElement);
   divElement.appendChild(pElement);
   tempdocument.body.appendChild(divElement);
   xspanElement.onclick=function(){ 
      divElement.parentNode.removeChild(divElement);
   };
   barElement.onmousedown=function(){ //alerttest(this); //alerttest(this.parentNode.parentNode.tagName);
      var relativex=arguments[0].clientX-parseInt(this.parentNode.style.left);
      var relativey=arguments[0].clientY-parseInt(this.parentNode.style.top);
      this.onmousemove=function(){ //alerttest(this.parentNode.tagName)
         this.parentNode.style.left=Math.max(100,(arguments[0].clientX-relativex))+"px";
         this.parentNode.style.top=Math.min(Math.round(window.screen.height*3/5),(arguments[0].clientY-relativey))+"px";
      };
   };
   barElement.onmouseup=function(){
      this.onmousemove=null;
   };
   barElement.onmouseout=function(){
      this.onmousemove=null;
   };
   return divElement;
};

   





/*
function Rectangle(w,h){
   this.width=w; 
   this.height=h;
};
Rectangle.prototype.area=function(){
   return this.width*this.height;
};

Rectangle.prototype.toString=function(){
   return "Rectangle("+this.width+","+this.height+")";
};

function PRectangle(x,y,w,h){
   Rectangle.call(this,w,h);
   this.x=x; 
   this.y=y;
};

PRectangle.prototype= new Rectangle(50,11); 

//A= new Rectangle(3,4);
//B= new PRectangle(7,8,1,2);


function PRectangle(x,y,w,h){
alert(["Is this window?", this==window]);

   alert(Array.call(this,w,h));
alert(this[0]);
alert(this[1]);
alert(this.length);
alert(this.length);
   this.x=x; 
   this.y=y;
};

PRectangle.prototype= new Array(50,11, 12, 23); 

   delete PRectangle.prototype.length;
   delete PRectangle.prototype.length;

A= new Array(3,4);
B= new PRectangle(7,8,1,2);

PRectangle(6,5,4,3);

*/

/*
AAAAA= function JJohn(){
function sub(a,b){
   return a-b;
}

alert(JJohn);
alert(window.JJohn);
};

AAAAA();



function JSohn(){
function sub(a,b){
   return a-b;
}

alert(JSohn);
alert(window.JSohn);
};

JSohn();



BBB= function(){
function sub(a,b){
   return a-b;
}

alert(BBB);
alert(window.BBB);
};

BBB();


function JSohn(){
function sub(a,b){
   return a-b;
}
alert(sub);
alert(window.sub);
alert(JSohn);
alert(window.JSohn);
};

JSohn();


JunkFunction= function(){
};

JunkFunction.prototype=[1,2,3];

JunkFunction.prototype.help=function(){ alert("Hello");};


CaluMath.PM.MakeArray=function(){
   arguments[0].constructor=JunkFunction;
//   arguments[0].prototype=JunkFunction.prototype;
   return arguments[0];
};

AA=CaluMath.PM.MakeArray([4,5,6]);
*/

/*

CM_PageMakerObject = CaluMath.PM.PageMakerObject;

CaluMathPM = new Object();

CM_PageMakerObject = CaluMath.PM.PageMakerObject;

CaluMathPM.CM_PageMakerObject = CaluMath.PM.PageMakerObject;



beginTime=new Date()
beginTime=beginTime.getTime();

for(var i=0; i<100000; i++){
   CM_PageMakerObject;
};

endTime=new Date()
endTime=endTime.getTime();

beginTime1=new Date()
beginTime1=beginTime1.getTime();

for(var i=0; i<100000; i++){
   CaluMathPM.PageMakerObject;
};

endTime1=new Date()
endTime1=endTime1.getTime();


alert([endTime-beginTime,endTime1-beginTime1]);


(function(){
QQ=CaluMath.Html.DisplayObjectNames(window);
QQ1 = new Array();

for(var i=0; i< QQ.length; i++){
   if(QQ[i].match(/^CM_/) == null && window[QQ[i]] != null){
      QQ1.push(QQ[i]);
   };
};
})();




beginTime=new Date()
beginTime=beginTime.getTime();
TempString=["animationplot"];
for(var i=0; i<10; i++){
   TempString= TempString.concat(TempString);
}
TempString.join("");
endTime=new Date()
endTime=endTime.getTime();
alert([endTime-beginTime, TempString.length, TempString.join("")]);


beginTime1=new Date()
beginTime1=beginTime1.getTime();
TempString=["animationplot"];
for(var i=0; i<100; i++){
   TempString=TempString.concat(TempString);
};

endTime1=new Date()
endTime1=endTime1.getTime();

alert([endTime-beginTime, endTime1-beginTime1]);

var tempCaluMathPMPageMakerObjectLabelName=CaluMath.PM.PageMakerObjectLabelName;
beginnewTime=new Date()
beginnewTime=beginnewTime.getTime();

for(var i=0; i<1000; i++){
   tempCaluMathPMPageMakerObjectLabelName("animationroutine");
};

endnewTime=new Date()
endnewTime=endnewTime.getTime();

beginnewTime1=new Date()
beginnewTime1=beginnewTime1.getTime();

var tempCaluMathPMPageMakerObjectLabelName1=CaluMath.PM.PageMakerObjectLabelName1;

for(var i=0; i<1000; i++){
   tempCaluMathPMPageMakerObjectLabelName1("animationroutine");
};

endnewTime1=new Date()
endnewTime1=endnewTime1.getTime();


alert([endTime-beginTime,endTime1-beginTime1,endnewTime-beginnewTime,endnewTime1-beginnewTime1]);

*/


