undoPushDownStack=[];
redoPushDownStack=[];
selectorIndex=selectorIndex2=selectorIndex3=0;

SearchBySubjectURL1='http://search.yahoo.com/search?ei=UTF-8&va=|http://www.google.com/custom?q='.split('|');
SearchBySubjectURL2='&vp_vt=title&vs=|&as_occt=title&cof=S%3Ahttp%3A%2F%3BGL%3A1%3BVLC%3A%23C000C0%3BAH%3Acenter%3BBGC%3Againsboro%3BALC%3Ared%3BBIMG%3Ahttp%3A%2F%2Fllbest.com%2Fimages%2F_bg1.gif%3BGIMP%3A%230037DD%3BAWFID%3Ae06b945d936c1667%3B&sitesearch='.split('|');

SearchUsingGoogleEtcURL1='http://www.google.com/search?q=|http://search.yahoo.com/search?ei=UTF-8&va=|http://search.msn.com/results.aspx?FORM=MSNH&srch_type=0&q='.split('|');
SearchUsingGoogleEtcURL2='&sitesearch=|&vs=|&q1=site%3A'.split('|');

function CalculateIt()
 {
 var T1=document.theForm.CalculatorProblem.value;
 if(T1)
  {
  try
   {
   DisplayCalcAnswer((eval('with(Math){'+T1+'}')),T1);
   }
  catch(err)
   {
   alert('ERROR: '+err.message+'.\n\nPlease correct the problem and try again.');
   }
  }
 }

function ClearCalculatorAll()
 {
 if((undoPushDownStack.length||redoPushDownStack.length)&&confirm('All undos & redos will be deleted. Are you sure that you want to do this?'))
  {
  undoPushDownStack=[];
  redoPushDownStack=[];
  ClearCalculator();
  }
 }

function ClearCalculator()
 {
 if(document.theForm.CalculatorProblem.value)
  {
  GEBI('hiddenSpan').innerHTML=document.theForm.CalculatorProblem.value='';
  var T1=redoPushDownStack.pop();
  if((typeof(T1)!='undefined')&&T1)
   undoPushDownStack.push(T1);
  }
 }

function DisplayCalcAnswer(theText,theProblem)
 {
 document.theForm.CalculatorProblem.value=theProblem;
 GEBI('hiddenSpan').innerHTML='<table class=TS5 style="margin-bottom:0.3em"><td class=TD1>'+theText+'</td></table>';
 storeCalculatorUndo();
 }

function displayCalcExample(theProblem)
 {
 if(document.theForm.CalculatorProblem.value!=theProblem)
  GEBI('hiddenSpan').innerHTML='';
 document.theForm.CalculatorProblem.value=theProblem;
 storeCalculatorUndo();
 }

function MakeLink()
 {
 var T1=document.theForm.CalculatorProblem.value;
 if(T1)
  DisplayCalcAnswer('<a href=\"'+T1+'\">'+T1+'</a>',T1);
 }

function pageLoadedLP(theCookieName)
 {
 try{pageLoaded()}catch(e){}
 try{eval(cookieRead(theCookieName))}catch(e){}
 if(selectorIndex)
  GEBI('theSelector').value=selectorIndex;
 if(selectorIndex2)
  GEBI('theSelector2').value=selectorIndex2;
 if(selectorIndex3)
  GEBI('theSelector3').value=selectorIndex3;
 if(undoPushDownStack.length)
  {
  undoPushDownStack=undoPushDownStack.split(',');
  var T1=undoPushDownStack.pop();
  undoPushDownStack.push(T1);
  document.theForm.CalculatorProblem.value=T1;
  }
 if(redoPushDownStack.length)
  {
  redoPushDownStack=redoPushDownStack.split(',');
  var T1=redoPushDownStack.pop();
  redoPushDownStack.push(T1);
  document.theForm.CalculatorProblem.value=T1;
  }
 }

function pageUnloadedLP(theCookieName)
 {
 var T1='';
 if(selectorIndex|0)
  T1+='selectorIndex='+selectorIndex+';';
 if(selectorIndex2|0)
  T1+='selectorIndex2='+selectorIndex2+';';
 if(selectorIndex3|0)
  T1+='selectorIndex3='+selectorIndex3+';';
 if(undoPushDownStack.length)
  T1+='undoPushDownStack="'+undoPushDownStack+'";';
 if(redoPushDownStack.length)
  T1+='redoPushDownStack="'+redoPushDownStack+'";';
 try{cookieWrite(theCookieName,T1,8)}catch(e){};
 }

function RedoCalculator()
 {
 GEBI('hiddenSpan').innerHTML='';
 var T1=document.theForm.CalculatorProblem.value,T2=T1;
 while(T1==T2)
  {
  T2=redoPushDownStack.pop();
  if((typeof(T2)!='undefined')&&T2)
   {
   document.theForm.CalculatorProblem.value=T2;
   undoPushDownStack.push(T2);
   }
  }
 }

function SearchUsingGoogleEtc(theSE)
 {
 selectorIndex2=GEBI('theSelector2').value;
 var T1=siteList1[selectorIndex2]
 location.href=SearchUsingGoogleEtcURL1[theSE]+SearchStringURLPrep(document.theForm.SearchString.value)+((T1=='The Web')?'':SearchUsingGoogleEtcURL2[theSE]+T1);
 }

function SearchBySubject(theTopic,theWebsite)
 {
 location.href=SearchBySubjectURL1[selectorIndex]+(theTopic.split('_(')[0].replace(/_/g,"+"))+SearchBySubjectURL2[selectorIndex]+theWebsite;
 }

function storeCalculatorUndo()
 {
 var T1=undoPushDownStack.pop();
 if((typeof(T1)!='undefined')&&T1)
  undoPushDownStack.push(T1);
 else
  T1='';
 var T2=document.theForm.CalculatorProblem.value;
 if(T2&&(T1!=T2))
  undoPushDownStack.push(T2);
 }

function UndoCalculator()
 {
 GEBI('hiddenSpan').innerHTML='';
 var T1=document.theForm.CalculatorProblem.value,T2=T1;
 while(T1==T2)
  {
  T2=undoPushDownStack.pop();
  if((typeof(T2)!='undefined')&&T2)
   {
   document.theForm.CalculatorProblem.value=T2;
   redoPushDownStack.push(T2);
   }
  }
 }

