
/*

    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 file is used to detect where in the path the CaluMath folder is, so that the files in the library folder can be read. */

(function(){
   CM_HeadSection=document.getElementsByTagName("head")[0];
   if(window.decodeURI != null){
      var pathname = decodeURI(document.location.pathname).replace(/^[\/\"\/]/,'');
   }
   else{
      var pathname = document.location.pathname.replace(/^[\/\"\/]/,'');
   };
   var pathnamematch=pathname.match(/CaluMath/);
   if(pathnamematch != null){
      pathname=pathname.slice(pathnamematch.index+9);
      if(pathname.match(/\\/)){ 
         var numberofforwardslashes= pathname.split("\\").length;
         var tempdots="";
         for(var i=1; i<numberofforwardslashes; i++){
            tempdots=tempdots+"../";
         };
         CM_DotsToCaluMathFolder=tempdots;    
      }
      else if(pathname.match(/\//)){ 
         var numberofforwardslashes= pathname.split("/").length;
         var tempdots="";
         for(var i=1; i<numberofforwardslashes; i++){
            tempdots=tempdots+"../";
         };
         CM_DotsToCaluMathFolder=tempdots;   
      }
      else{
         CM_DotsToCaluMathFolder="";  
      };

      try{
         if(window.opener != null && window.opener.CaluMath != null && window.opener.CaluMath.PM.PageMakerObjectArray != null ){       
            var tempscript = document.createElement("script");  
            tempscript.src=CM_DotsToCaluMathFolder+"library/Initialize.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");  
            tempscript.src=CM_DotsToCaluMathFolder+"library/GeneralizedPlot.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
            tempscript.src=CM_DotsToCaluMathFolder+"library/Array.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/Function.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/Global.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script"); 
             tempscript.src=CM_DotsToCaluMathFolder+"library/Math.js"; 
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/Number.js"; 
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/String.js";
            CM_HeadSection.appendChild(tempscript); 
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/DefinedFunctionClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/UnicodePostscript.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/PlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/SinglePlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/FunctionPlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/PointPlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/TextPlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/RectanglePlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/NewWindowClass.js";
            CM_HeadSection.appendChild(tempscript); 
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/MiscellaneousClasses.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/ArcPlotClass.js"; 
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
               tempscript.src=CM_DotsToCaluMathFolder+"library/LinearPlotClass.js";
             CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
               tempscript.src=CM_DotsToCaluMathFolder+"library/AnimationPlotClass.js"; 
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/InputTextClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/SelectClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/AnimationOutputClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/ButtonClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/DiscretePlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/CompositePlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/HtmlBlockClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/TableClass.js"; 
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/DiscreteFunctionCollectionClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/CompositeAnimationPlotClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script"); 
             tempscript.src=CM_DotsToCaluMathFolder+"library/BoxesClass.js";
            CM_HeadSection.appendChild(tempscript);
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/SlidingScaleClass.js";
            CM_HeadSection.appendChild(tempscript); 
            var tempscript = document.createElement("script");
               tempscript.src=CM_DotsToCaluMathFolder+"library/UpdatableFunctionPlotClass.js";
            CM_HeadSection.appendChild(tempscript); 
            var tempscript = document.createElement("script");
              tempscript.src=CM_DotsToCaluMathFolder+"library/Finalize.js"
            CM_HeadSection.appendChild(tempscript); 
         }
         else{
            document.write('<script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Initialize.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/GeneralizedPlot.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Array.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Function.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Global.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Math.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Number.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/String.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DefinedFunctionClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/UnicodePostscript.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/PlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SinglePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/FunctionPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/PointPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/TextPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/RectanglePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/NewWindowClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/MiscellaneousClasses.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/ArcPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/LinearPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/AnimationPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/InputTextClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SelectClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/AnimationOutputClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/ButtonClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DiscretePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/CompositePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/HtmlBlockClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/TableClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DiscreteFunctionCollectionClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/CompositeAnimationPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/BoxesClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SlidingScaleClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/UpdatableFunctionPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Finalize.js"><\/script>');
         };
      }
      catch(e){
         document.write('<script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Initialize.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/GeneralizedPlot.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Array.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Function.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Global.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Math.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Number.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/String.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DefinedFunctionClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/UnicodePostscript.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/PlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SinglePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/FunctionPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/PointPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/TextPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/RectanglePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/NewWindowClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/MiscellaneousClasses.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/ArcPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/LinearPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/AnimationPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/InputTextClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SelectClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/AnimationOutputClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/ButtonClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DiscretePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/CompositePlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/HtmlBlockClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/TableClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/DiscreteFunctionCollectionClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/CompositeAnimationPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/BoxesClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/SlidingScaleClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/UpdatableFunctionPlotClass.js"><\/script><script type="text/javascript" src="'+CM_DotsToCaluMathFolder+'library/Finalize.js"><\/script>');
      };
   }
   else{
      alert("You do not have the CaluMath Page Maker in the CaluMath folder. It will not work properly in this case.");
   };

   if(window.CM_BeginLoadingTime != null){
      CM_CoreLoadingTime=1*CM_BeginLoadingTime+2000;

      CM_PopUpsBlockedAlertMessage=function(){

         try{
            if( window.CM_ClientAddpointsLoaded == null && ( window.CM_ProgressWindow == null || (window.CM_ProgressWindow != null && ! window.CM_ProgressWindow.closed && window.CM_ProgressWindow.document == null)) ){
               return alert("Try: It will take about "+ Math.round(14*(CM_CoreLoadingTime-CM_BeginLoadingTime)/1000)+" seconds to load this page. However any future math page you load will load immediately. You also are blocking Pop-Up Windows. This page will not work correctly unless you turn your Pop-Up Blocker Off.");
            };
         }
         catch(e){
            return alert("Catch: It will take about "+ Math.round(14*(CM_CoreLoadingTime-CM_BeginLoadingTime)/1000)+" seconds to load this page. However any future math page you load will load immediately. You also are blocking Pop-Up Windows. To prevent errors, please turn your Pop-Up Blocker Off.");
         };
      };
 
      if(window.CM_CoreLoadingTime != null && window.CM_BeginLoadingTime != null && CM_CoreLoadingTime-CM_BeginLoadingTime > 800 && window.opener == null){
         var templocation=window.location+"";
         var templocationmatch=templocation.match(/CaluMath/); 
         if(templocationmatch != null){
            templocation = templocation.slice(0,templocationmatch.index).replace(/\\/,"/");
            templocation=templocation+"CaluMath/library/progressbar.html";
            CM_ProgressWindow=window.open(templocation,null,"width=350px, height=350, toolbar=yes");

              CM_OpenProgressWindowFunction= function(){
                 if(window.CM_ClientAddpointsLoaded == null){
                    CM_ProgressWindow = window.open(templocation,null,"width=350px, height=350, toolbar=yes");
                 };
              };

            setTimeout('CM_OpenProgressWindowFunction()', 4000); 
            setTimeout('CM_PopUpsBlockedAlertMessage()',7000); 
         };
      };
   };




})()

