/* author: MH */
/* Creation date: 7/24/2005 */

  //  Solar Power Electric System   S I M U L A T O R   ***
  var solarAmps=0;
  var batteryAmps=0;
  var totalAmpHours;
  var batteryVolts=12.7;
  var sunIntensity=0;
  var numPanels=8;
  var panelAmps=7;
  var solarAmpsChange=0;
  var acAmps=0;
  var Timer1;
  var Timer1Interval=50;
  var Timer2;
  var Timer2Interval=1000;
  var Timer3;
  var Timer3Interval=500;
  var plusminus;
  var batteryInc;
  var batterySize=1000;
  var speedValue=60;
  var simSec=0;
  var simMin=0;
  var simHrs=0;
  var stopClock=1;
  var appLoad=0;
  var eachApp=0;
  var chargingMess;
  var simulatorOn=0;
  var Timer4=0;
  var batLevel;
  var colorOn="#00ffff";
  var colorOff="#000000";  
  
  //***************************
  function init()
  //***************************
  {
  	appOnOff=new Array(0,0,0,0,0,0,0);
	sunIntensity=2;solarAmps=16;batteryAmps=16;totalAmpHours=-100;
	upIntensity();     // set charge level to 1 sun intensity
	setApp(2);         // turn on house lighting 
	document.SimulatorForm.simSpeed.value=60;
	document.SimulatorForm.AmpHoursMeter.value=-100;
    document.SimulatorForm.Light1.src="images/charge_light_off.gif";   //turn off discharging light
    document.SimulatorForm.Light2.src="images/charge_light_off.gif";   //turn off Charging light
	document.all.b1.style.backgroundColor=colorOn;
	document.all.b2.style.backgroundColor=colorOn;
	document.all.b3.style.backgroundColor=colorOn;
	document.all.b4.style.backgroundColor=colorOn;
	document.all.b5.style.backgroundColor=colorOn;
	document.all.b6.style.backgroundColor=colorOn;
	document.all.b7.style.backgroundColor=colorOn;
	document.all.b8.style.backgroundColor=colorOn;
	document.all.b9.style.backgroundColor=colorOn;
	document.all.b10.style.backgroundColor=colorOn;
	document.all.b11.style.backgroundColor=colorOn;
	document.all.b12.style.backgroundColor=colorOn;
  }

  function setBatteryBar()
  { 
   batLevel=Math.round(((-1*(totalAmpHours/batterySize))/.03125)-16);
   batLevel=batLevel*-1;
   if (batLevel<0){batLevel=0;}
   //document.SimulatorForm.test1.value=batLevel;
   switch (batLevel)
    {
   	 case 0: document.all.b1.style.backgroundColor=colorOff;clearBatteryBar();break;
	 case 1: document.all.b1.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 2: document.all.b2.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 3: document.all.b3.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 4: document.all.b4.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 5: document.all.b5.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 6: document.all.b6.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 7: document.all.b7.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 8: document.all.b8.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 9: document.all.b9.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 10: document.all.b10.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 11: document.all.b11.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 12: document.all.b12.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 13: document.all.b13.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 14: document.all.b14.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 15: document.all.b15.style.backgroundColor=colorOn;clearBatteryBar();break;
	 case 16: document.all.b16.style.backgroundColor=colorOn;break;
	}
  }
    
  function clearBatteryBar()
  {
   switch (batLevel)
    {
   	 case 0: document.all.b1.style.backgroundColor=colorOff;
   	 case 1: document.all.b2.style.backgroundColor=colorOff;
   	 case 2: document.all.b3.style.backgroundColor=colorOff;
   	 case 3: document.all.b4.style.backgroundColor=colorOff;
   	 case 4: document.all.b5.style.backgroundColor=colorOff;
   	 case 5: document.all.b6.style.backgroundColor=colorOff;
   	 case 6: document.all.b7.style.backgroundColor=colorOff;
   	 case 7: document.all.b8.style.backgroundColor=colorOff;
   	 case 8: document.all.b9.style.backgroundColor=colorOff;
   	 case 9: document.all.b10.style.backgroundColor=colorOff;
   	 case 10: document.all.b11.style.backgroundColor=colorOff;
   	 case 11: document.all.b12.style.backgroundColor=colorOff;
   	 case 12: document.all.b13.style.backgroundColor=colorOff;
   	 case 13: document.all.b14.style.backgroundColor=colorOff;
   	 case 14: document.all.b15.style.backgroundColor=colorOff;
   	 case 15: document.all.b16.style.backgroundColor=colorOff;
	}
  }
  
  //***************************
  function minSunIntensity()
  //***************************
  {
   if (Timer3) {return;}   // disable min button if appliances auto shutting down
   else 
   if (!Timer4)
   {Timer4=setInterval("setMinSun()",100);}
  } 

  //***************************
  function maxSunIntensity()
  //***************************
  {
   if (Timer3) {return;}   // disable min button if appliances auto shutting down
   else
   if (!Timer4)
    {Timer4=setInterval("setMaxSun()",100);}
  } 
  
  //***************************
  function setMinSun()
  //***************************
  {
    if (sunIntensity==0)
	 {clearInterval(Timer4);Timer4=0;}
 	else  
	 {dnIntensity();}
  }
     
  //***************************
  function setMaxSun()
  //***************************
  {
   if (sunIntensity==7)
    {clearInterval(Timer4);Timer4=0;}
   else  
    {upIntensity();}
  }

  //***************************
  function resetClock()
  //***************************
  {
   simSec=0;simMin=0;simHrs=0;
   totalTime="Hrs: "+String(simHrs)+"  Min: "+String(simMin)+"  Sec: "+String(simSec);
   document.SimulatorForm.speedTime.value=totalTime;
  }

  //***************************  
  function StartStop()
  //***************************
  { 
   if (Timer3) {return;}   // disable Start/Stop button is appliances are auto shutting down
   if (simulatorOn)     // Stop the Simulator  STOP STOP  STOP STOP  STOP STOP  STOP STOP
    {
     clearInterval(Timer2); Timer2=0;                                     // Stop   monitorAmpHours() function
	 document.SimulatorForm.statusText.value="THE SIMULATOR IS STOPPED";
     document.SimulatorForm.electron1.src="images/electrons0.gif";
     document.SimulatorForm.electron2.src="images/electrons0.gif";
	 document.SimulatorForm.electron3.src="images/electrons0.gif";
	 document.SimulatorForm.rtAngle.src="images/electrons_rt_angle_off.gif";

	 document.SimulatorForm.onoff.src="images/off.gif";               //Turn OFF sim light
     document.SimulatorForm.Light1Text.value="Not Charging";          //set text message to 'Not Charging'
     document.SimulatorForm.Light1.src="images/charge_light_off.gif"; //turn of discharging light
     document.SimulatorForm.Light2.src="images/charge_light_off.gif"; //turn off charging light
     document.SimulatorForm.Light3.src="images/charge_light_off.gif"; // Set flashing DisCharged light OFF
     document.SimulatorForm.Light4.src="images/charge_light_off.gif"; // Set 'float charging' light to OFF
	 document.SimulatorForm.statusWarning1.src="images/yel_light.gif";
	 document.SimulatorForm.statusWarning2.src="images/yel_light.gif";
 	 document.SimulatorForm.statusText.value="THE SIMULATOR IS STOPPED  (Click Start/Stop button to restart)";
	 simulatorOn=0;
	}
	else   // Start the Simulator  START    START  START  START  START  START  START
	{
     Timer2=setInterval("monitorAmpHours()",Timer2Interval);          //Start   monitorAmpHours() function
 	 document.SimulatorForm.statusWarning1.src="images/yel_light_off.gif";
	 document.SimulatorForm.statusWarning2.src="images/yel_light_off.gif";
	 document.SimulatorForm.onoff.src="images/on.gif";                //Turn ON sim light
     simulatorOn=1;
	 if(sunIntensity)
	 {
	   document.SimulatorForm.electron1.src="images/electrons2.gif";
       document.SimulatorForm.electron2.src="images/electrons2.gif";
	 }  
 	 if (appLoad)
	 {
	   document.SimulatorForm.electron3.src="images/electrons2.gif";
	   document.SimulatorForm.rtAngle.src="images/electrons_rt_angle.gif";
     }
	}
  }
  
  //***************************
  function changeSpeed() // SIMULATOR SPEED
  //***************************
  {
   if (document.SimulatorForm.simSpeed.value==3600){speedValue=3600;}
   if (document.SimulatorForm.simSpeed.value==360){speedValue=360;}
   if (document.SimulatorForm.simSpeed.value==60){speedValue=60;}
   if (document.SimulatorForm.simSpeed.value==6){speedValue=6;}
   if (document.SimulatorForm.simSpeed.value==2){speedValue=2;}
  } // values are 3600, 360, 60, 6, and 2.  (2 is 1 seconds = 30 min sim time.)
  
  //***************************
  function adjustAmps()
  //***************************
  {
   document.SimulatorForm.acAmpsMeter.value=acAmps;
   document.SimulatorForm.BatteryAmpsMeter.value=batteryAmps;
  }

  //***************************
  function upIntensity()//***   upIntensity()  INCREASE SUN  BRIGHTNESS LEVEL  ***  
  //***************************
  {
   if (!Timer1)
    { sunIntensity=sunIntensity+1;
	  if (sunIntensity>7)  //Sun Intensity can't be greater than 7
	   {
		sunIntensity=7; return;
	   }
      plusminus=1;
	  Timer1=setInterval("changeSolarAmps()",Timer1Interval);
	  changeSunText();
      document.SimulatorForm.SunMeter.value=sunIntensity;
	  switch (sunIntensity)
	   {
	    case 1:
		 document.SimulatorForm.s1.src="images/sun_section.gif";
	     break;
	    case 2:
		 document.SimulatorForm.s2.src="images/sun_section.gif";
	     break;
	    case 3:
		 document.SimulatorForm.s3.src="images/sun_section.gif";
	     break;
	    case 4:
		 document.SimulatorForm.s4.src="images/sun_section.gif";
	     break;
	    case 5:
		 document.SimulatorForm.s5.src="images/sun_section.gif";
	     break;
	    case 6:
		 document.SimulatorForm.s6.src="images/sun_section.gif";
	     break;
	    case 7:
		 document.SimulatorForm.s7.src="images/sun_section.gif";
	     break;
	   } 
	}
  }
  
  //***************************
  function dnIntensity()//***   dnIntensity()  DECREASE SUN  BRIGHTNESS LEVEL  ***  
  //***************************
  {
  if (!Timer1)
    {
      sunIntensity=sunIntensity-1;
       if (sunIntensity<0)   //Sun Intensity can't be less than 0
		{
		 sunIntensity=0;
		 return;
		}
      document.SimulatorForm.SunMeter.value=sunIntensity;
	  plusminus=-1;
      Timer1=setInterval("changeSolarAmps()",Timer1Interval);
	  changeSunText();
  	  switch (sunIntensity+1)
	   {
	    case 1:
		 document.SimulatorForm.s1.src="images/sun_section_off.gif";
	     break;
	    case 2:
		 document.SimulatorForm.s2.src="images/sun_section_off.gif";
	     break;
	    case 3:
		 document.SimulatorForm.s3.src="images/sun_section_off.gif";
	     break;
	    case 4:
		 document.SimulatorForm.s4.src="images/sun_section_off.gif";
	     break;
	    case 5:
		 document.SimulatorForm.s5.src="images/sun_section_off.gif";
	     break;
	    case 6:
		 document.SimulatorForm.s6.src="images/sun_section_off.gif";
	     break;
	    case 7:
		 document.SimulatorForm.s7.src="images/sun_section_off.gif";
	     break;
	   } 
	}
  }
  
  //*************************** // step change in value. Solar charging changes 8 counts at Timer1 interval rate (100 to 500 msec)
  function changeSolarAmps()  // show increase or decrease at Timer1 rate
  //***************************
  {                           // goes up/down 8 amps each change in Sun Intensity
  solarAmpsChange=solarAmpsChange+1;
  if (solarAmpsChange==numPanels)
    {
	 clearInterval(Timer1);
	 solarAmps=solarAmps+(solarAmpsChange*plusminus);
	 batteryAmps=batteryAmps+(solarAmpsChange*plusminus);
	 solarAmpsChange=0;
	 Timer1=0;
	}
  document.SimulatorForm.SolarAmpsMeter.value=solarAmps+(solarAmpsChange*plusminus);     //show solarAmps change
  document.SimulatorForm.BatteryAmpsMeter.value=batteryAmps+(solarAmpsChange*plusminus); //show batteryAmps change
  }
  
  //************************************************************************************************************************
  function monitorAmpHours()       //                 MAIN CONTROL FUNCTION FOR SIMULATOR
  //************************************************************************************************************************
  {   var batteryChargeInc; var chargeMess,statusMess,runMess;
	totalAmpHours=totalAmpHours+(batteryAmps/speedValue);  // add/subtract % of battery amps to AmpHours for time...
	setBatteryBar();                                       // set Battery level
	if (!sunIntensity && !appLoad)                         // If no sun AND no appliances STOP CLOCK
	 {
	  stopClock=1;
	  document.SimulatorForm.speedTime.value="Simulator Clock is stopped";
	  runMess="stopped";
	 }
	if (sunIntensity || appLoad) {stopClock=0;runMess="running";}  //If sun OR appliances START CLOCK
	
	if (!stopClock)
	 {
	  updateTime();  
	 }
	 
	if (totalAmpHours>0)    //control MAXIMUM AmpHour level
	 {
	  totalAmpHours=0;      //totalAmpHours-(batteryAmps/speedValue);
	  if (sunIntensity>1)   //If float charging reduce sun intensity but not below 1
	   {
	    dnIntensity();
	   }
	  document.SimulatorForm.Light4.src="images/charged_light.gif";
      document.SimulatorForm.Light3.src="images/charge_light_off.gif";
      document.SimulatorForm.Light2Text.value="Full Charge";
	 }

    chargeMess="100"; //String( 100-(Math.round((totalAmpHours/batterySize)*-100)) );
	if (totalAmpHours<0) // Check AmpHours if below 0
	 {  // Show percentage of charge
      chargeMess=String( 100-(Math.round((totalAmpHours/batterySize)*-100)) );
	  document.SimulatorForm.Light2Text.value=chargeMess+" % Charged";
	 }
	
	if (totalAmpHours<-batterySize/2)     //  Ok, less than 0 but is it below 50% charge level?
	 {
	   document.SimulatorForm.Light4.src="images/charge_light_off.gif"; // Set charged light OFF
	   document.SimulatorForm.Light3.src="images/discharged_light.gif"; // Set flashing DisCharged light ON
	   document.SimulatorForm.Light2Text.value="Below 50% !";           // Set message: 'Below 50% !'
	   //    SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   
	   shutOffApp();//Shut off all Appliances          SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   SHUT OFF APPLIANCES   
	 }
	
	if (totalAmpHours<0 && totalAmpHours>-batterySize/2) //  If AmpHours ABOVE  50% charge level...
	 {
	  document.SimulatorForm.Light4.src="images/charge_light_off.gif";
	  document.SimulatorForm.Light3.src="images/charge_light_off.gif";
	 } 
	 
	setAllLights();  // set lights 1 and 2 
	
	// FACTOR 1 :Calculate changing Battery Voltage based on totalAmpHours
	if (totalAmpHours<0) 
	{
	  batteryInc=.011*(totalAmpHours/(batterySize*.01));    // (.11 volt each 10%)
 	  // if totalAmpHours is negative subtract .1 volts for each  10% of batterySize (battery bank capacity)
	}
	else  
	{
	  if (sunIntensity) //if charging
	   {
		batteryInc=.2*(totalAmpHours/(batterySize*.001));  // IS charging
	   }
	   else
	   {
		batteryInc=.01*(totalAmpHours/(batterySize*.001)); // NOT charging
	   }
	}
	// FACTOR 2 :  Rate of Charge (batteryAmps is + if charging)
    if (batteryAmps<0) // negative batteryAmps
	 {
	  batteryChargeInc=.005*batteryAmps;
	 }
	 else              // positive batteryAmps
	 {
	  batteryChargeInc=.03*batteryAmps;
	 }
	// ADJUST BATTERY VOLTAGE HERE
	batteryVolts=12.7+batteryInc+batteryChargeInc;
	if (batteryVolts>14.4) // don't allow batteryVolts to exceed bulk charge rate
	 {
	  batteryVolts=14.4;
	 }
	document.SimulatorForm.AmpHoursMeter.value=Math.round(totalAmpHours*100)/100;
	document.SimulatorForm.BatteryVoltsMeter.value=Math.round(batteryVolts*100)/100;
	statusMess="The Simulator is currently "+runMess+". The batteries are "+chargingMess+" and are "+chargeMess+" % charged.";
	document.SimulatorForm.statusText.value=statusMess;
  }  // END MAIN CONTROL FUNCTION FOR SIMULATOR       ************************       END MAIN CONTROL FUNCTION FOR SIMULATOR
  
  //***************************
  function changeSunText()
  //***************************
  {
    stopClock=0;    // run clock
    panelsOnOff();  // turn on/off electrons if sun intensity is on/off
	switch(sunIntensity)
    { 
     case 0:
       document.SimulatorForm.sunText.value="Very heavily overcast. No Sun at all.";
	   stopClock=1;   //stop Clock
	   document.SimulatorForm.speedTime.value="Simulator Clock is stopped";
	   break;
     case 1:
	   document.SimulatorForm.sunText.value="Overcast : Very low output power.";
       break;
     case 2:
	   document.SimulatorForm.sunText.value="Mostly Cloudy : Low output power.";
       break;
     case 3:
	   document.SimulatorForm.sunText.value="Partly Cloudy : Medium output power.";
       break;
     case 4:
	   document.SimulatorForm.sunText.value="A Few Clouds : Medium high output.";
       break;
     case 5:
	   document.SimulatorForm.sunText.value="Clear but hazy : High output power.";
       break;
     case 6:
	   document.SimulatorForm.sunText.value="Clear Skies : Near maximum output.";
       break;
     case 7:
	   document.SimulatorForm.sunText.value="Full Sun : Very Clear & Maximum power.";
       break;
    }
  }
  
  //***************************
  function setApp(which)
  //***************************
  {
   // start CLOCK if any appliances turned on
   switch(which)
    {
	 case 1: //Refrigerator
	   if(!appOnOff[1])
	    {
		 document.SimulatorForm.app1.src="images/on.gif";
		 appOnOff[1]=1; 
		 acAmps=acAmps+8;
		 batteryAmps=batteryAmps-8;
		}
	   else
	    {
		 document.SimulatorForm.app1.src="images/off.gif";
		 appOnOff[1]=0;
		 acAmps=acAmps-8;
		 batteryAmps=batteryAmps+8;
		}
       adjustAmps();
	   break;
     case 2: //32 Color TV
	   if(!appOnOff[2])
	    {
		 document.SimulatorForm.app2.src="images/on.gif";
		 appOnOff[2]=1;
		 acAmps=acAmps+15;
		 batteryAmps=batteryAmps-15;
		}
	   else
	    {
		 document.SimulatorForm.app2.src="images/off.gif";
		 appOnOff[2]=0;
		 acAmps=acAmps-15;
		 batteryAmps=batteryAmps+15;
		}
       adjustAmps();
	   break;
     case 3: //Desk Computer
	   if(!appOnOff[3])
	    {
		 document.SimulatorForm.app3.src="images/on.gif";
		 appOnOff[3]=1;
		 acAmps=acAmps+15;
		 batteryAmps=batteryAmps-15;
		}
	   else
	    {
		 document.SimulatorForm.app3.src="images/off.gif";
		 appOnOff[3]=0;
		 acAmps=acAmps-15;
		 batteryAmps=batteryAmps+15;
		}
       adjustAmps();
       break;
     case 4: //House Lighting
	   if(!appOnOff[4])
	    {
		 document.SimulatorForm.app4.src="images/on.gif";
		 appOnOff[4]=1;
		 acAmps=acAmps+10;
		 batteryAmps=batteryAmps-10;
		}
	   else
	    {
		 document.SimulatorForm.app4.src="images/off.gif";
		 appOnOff[4]=0;
		 acAmps=acAmps-10;
		 batteryAmps=batteryAmps+10;
		}
		adjustAmps();
       break;
     case 5: // MicroWave
	   if(!appOnOff[5])
	    {
		 document.SimulatorForm.app5.src="images/on.gif";
		 appOnOff[5]=1;
		 acAmps=acAmps+100;
		 batteryAmps=batteryAmps-100;
		}
	   else
	    {
		 document.SimulatorForm.app5.src="images/off.gif";
		 appOnOff[5]=0;
		 acAmps=acAmps-100;
		 batteryAmps=batteryAmps+100;
		}
	   adjustAmps();
       break;
     case 6: // 5000 BTU Air Conditioner
	   if(!appOnOff[6])
	    {
		 document.SimulatorForm.app6.src="images/on.gif";
		 appOnOff[6]=1;
		 acAmps=acAmps+75;
		 batteryAmps=batteryAmps-75;
	    }
	   else
	    {
		 document.SimulatorForm.app6.src="images/off.gif";
		 appOnOff[6]=0;
		 acAmps=acAmps-75;
		 batteryAmps=batteryAmps+75;
		}
	   adjustAmps();
       break;
    }
   // Check to see if ANY appliances are ON
   if (appOnOff[1]||appOnOff[2]||appOnOff[3]||appOnOff[4]||appOnOff[5]||appOnOff[6])
    {
	 appLoad=1;
	 //if (!Timer2){Timer2=setInterval("monitorAmpHours()",Timer2Interval);} // if Timer2 not on, turn it ON
	 if(simulatorOn)
	 {
	  document.SimulatorForm.electron3.src="images/electrons2.gif";
	  document.SimulatorForm.rtAngle.src="images/electrons_rt_angle.gif";
	 }
	}
   // if All appliances are OFF
   if (!appOnOff[1]&&!appOnOff[2]&&!appOnOff[3]&&!appOnOff[4]&&!appOnOff[5]&&!appOnOff[6])
    {
	 appLoad=0;
	 document.SimulatorForm.electron3.src="images/electrons0.gif";
	 document.SimulatorForm.rtAngle.src="images/electrons_rt_angle_off.gif";
	}
  }
  
  //***************************
  function panelsOnOff()
  //***************************
  {
  if (sunIntensity) //if charging
   { // Turn ON electrons
	if(simulatorOn)
	{
	  document.SimulatorForm.electron1.src="images/electrons2.gif";
	  document.SimulatorForm.electron2.src="images/electrons2.gif";
	}
   }
   else
   { // Turn OFF electrons
    document.SimulatorForm.electron1.src="images/electrons0.gif";
    document.SimulatorForm.electron2.src="images/electrons0.gif";
   }  
  }
  
  //***************************
  function setAllLights()
  //***************************
  {                           // Set Solar CHARGING lights ON and OFF
    if (batteryAmps>0)        //CHARGING CONDITION
	 {
      document.SimulatorForm.Light1.src="images/charge_light_off.gif";   //turn off discharging light
      document.SimulatorForm.Light1Text.value="Charging";                //set text message to 'Charging'
      document.SimulatorForm.Light2.src="images/charge_light_grn.gif";   //turn on Charging light
	  chargingMess="charging up";
	 }
    if (batteryAmps==0)       //NOT CHARGING CONDITION
	 {
	  document.SimulatorForm.Light1.src="images/charge_light_off.gif";   //turn of discharging light
	  document.SimulatorForm.Light1Text.value="Not Charging";            //set text message to 'Not Charging'
	  document.SimulatorForm.Light2.src="images/charge_light_off.gif";   //turn off charging light
	  chargingMess="not charging";
	 } 
    if (batteryAmps<0)        //DISCHARGING CONDITION
	 {
      document.SimulatorForm.Light1.src="images/charge_light_red.gif";   //turn on discharging light
      document.SimulatorForm.Light1Text.value="Discharging";             //set text message to 'Discharging'
      document.SimulatorForm.Light2.src="images/charge_light_off.gif";   //turn off charging light
	  chargingMess="discharging";
     }
  }
  
  //*************************** 
  function updateTime()
  //***************************
  { var totalTime;
	switch (speedValue)
    {
	  case 3600:
        simSec=simSec+1;
	    if (simSec>=60){simSec=0;simMin=simMin+1;}
	    if (simMin>=60){simMin=0;simHrs=simHrs+1;}
		break;
	  case 360:
        simSec=simSec+10;
        if (simSec>=60){simSec=0;simMin=simMin+1;}
        break;
	  case 60:
        simMin=simMin+1;
        if (simMin>=60){simMin=0;simHrs=simHrs+1;}
        break;
	  case 6:
        simMin=simMin+10;
        if (simMin>=60){simMin=0;simHrs=simHrs+1;}
        break;
	  case 2:
        simMin=simMin+30;
		//simHrs=simHrs+1;
        if (simMin>=60){simMin=0;simHrs=simHrs+1;}
        break;
    }
	totalTime="Hrs: "+String(simHrs)+"  Min: "+String(simMin)+"  Sec: "+String(simSec);
	document.SimulatorForm.speedTime.value=totalTime;
  } // values are 3600, 360, 60, 6, and 1.  (1 is 1 seconds = 1 hour sim time.)

  //***************************
  function shutOffApp()
  //***************************
  {
   clearInterval(Timer2);//temporarily disable timer2
   Timer3=setInterval("setAppsOff()",Timer3Interval);
  }
  
  //***************************
  function setAppsOff()
  //***************************
  {
   eachApp=eachApp+1;
   switch (eachApp)
   {
     case 1:
	  if (appOnOff[1]){setApp(1);break;}	 
     case 2:
      if (appOnOff[2]){setApp(2);break;}
     case 3:
      if (appOnOff[3]){setApp(3);break;}
     case 4:
      if (appOnOff[4]){setApp(4);break;}
     case 5:
      if (appOnOff[5]){setApp(5);break;}
     case 6:
      if (appOnOff[6]){setApp(6);break;}
	 case 7:
	  eachApp=0;
	  clearInterval(Timer3);Timer3=0;
	  Timer2=setInterval("monitorAmpHours()",Timer2Interval);  // reset timer2 (main timer)
   }
  }