// _indexLP.js - JavaScript copyright, Howard Charles Best, 2005 through 2012.
// The following JavaScript code tested using Firefox and Internet Explorer.
// Please feel free to copy / use / modify it in any way that you see fit for your own application(s)/web pages(s) as long as "Howard Charles Best (http://LLBest.com/)" is given credit in a comment, the same as or similar to this one, at the beginning of the copied / modified code.
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('|');
J='left,center,justify,right'.split(',');
                // Text justification options array
function CalculateIt()
 {
 var T1=GEBI('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()
 {
 ClearCalculator();
 if((undoPushDownStack.length||redoPushDownStack.length)&&confirm('All undos & redos will be deleted. Are you sure that you want to do this?'))
  {
  undoPushDownStack=[];
  redoPushDownStack=[];
  }
 }
function ClearCalculator()
 {
 if(GEBI('CalculatorProblem').value)
  {
  GEBI('hiddenSpan').innerHTML=GEBI('CalculatorProblem').value='';
  var T1=redoPushDownStack.pop();
  if((typeof(T1)!='undefined')&&T1)
   undoPushDownStack.push(T1);
  }
 }
function DisplayCalcAnswer(theText,theProblem)
 {
 GEBI('CalculatorProblem').value=theProblem;
 GEBI('hiddenSpan').innerHTML='<table class=TS2 style="margin-bottom:0.3em"><td class=TD3>'+theText+'</td></table>';
 storeCalculatorUndo();
 }
function displayCalcExample(theProblem)
 {
 if(GEBI('CalculatorProblem').value!=theProblem)
  GEBI('hiddenSpan').innerHTML='';
 GEBI('CalculatorProblem').value=theProblem;
 storeCalculatorUndo();
 }
function MakeLink()
 {
 var T1=GEBI('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);
  GEBI('CalculatorProblem').value=T1;
  }
 if(redoPushDownStack.length)
  {
  redoPushDownStack=redoPushDownStack.split(',');
  var T1=redoPushDownStack.pop();
  redoPushDownStack.push(T1);
  GEBI('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=GEBI('CalculatorProblem').value,T2=T1;
 while(T1==T2)
  {
  T2=redoPushDownStack.pop();
  if((typeof(T2)!='undefined')&&T2)
   {
   GEBI('CalculatorProblem').value=T2;
   undoPushDownStack.push(T2);
   }
  }
 //alert('1. undoPushDownStack = '+undoPushDownStack);
 //alert('1. redoPushDownStack = '+redoPushDownStack);
 }
function SearchBySubject(theTopic,theWebsite)
 {
 location.href=SearchBySubjectURL1[selectorIndex]+(theTopic.split('_(')[0].replace(/_/g,"+"))+SearchBySubjectURL2[selectorIndex]+theWebsite;
 }
function SearchStringURLPrep(SearchString)
 {
 return(SearchString.replace(/[ \xA0]/g,'+').replace(/"/g,'%22').replace(/[\xA1-\uffff]/g,function(T1){var T2=T1.charCodeAt();var T3=T2>>6;var T4=T3>>6;var T5=T1>'\u0fff';return(((T5?'%'+(224+T4).toString(16):'')+'%'+(T3-((T4-(T5?2:3))<<6)).toString(16)+'%'+(T2-((T3-2)<<6)).toString(16)).toUpperCase())}));
 }
function SearchUsingFreeFind(theID)
 {
 location.href='http://search.freefind.com/find.html?id='+theID+'&pageid=r&mode=ALL&n=0&_charset_=utf-8&bcd=%C3%B7&query='+SearchStringURLPrep(GEBI('SearchString').value);
 }
function SearchUsingGoogleEtc(theSE)
 {
 selectorIndex2=GEBI('theSelector2').value;
 var T1=siteList1[selectorIndex2]
 location.href=SearchUsingGoogleEtcURL1[theSE]+SearchStringURLPrep(GEBI('SearchString').value)+((T1=='The Web')?'':SearchUsingGoogleEtcURL2[theSE]+T1);
 }
function storeCalculatorUndo()
 {
 var T1=undoPushDownStack.pop();
 if((typeof(T1)!='undefined')&&T1)
  undoPushDownStack.push(T1);
 else
  T1='';
 var T2=GEBI('CalculatorProblem').value;
 if(T2&&(T1!=T2))
  undoPushDownStack.push(T2);
 //alert('2. undoPushDownStack = '+undoPushDownStack);
 //alert('2. redoPushDownStack = '+redoPushDownStack);
 }
function UndoCalculator()
 {
 GEBI('hiddenSpan').innerHTML='';
 var T1=undoPushDownStack.pop();
 if((typeof(T1)!='undefined')&&T1)
  redoPushDownStack.push(T1);
 T1=undoPushDownStack.pop();
 if((typeof(T1)!='undefined')&&T1)
  {
  GEBI('CalculatorProblem').value=T1;
  undoPushDownStack.push(T1);
  }
 //alert('3. undoPushDownStack = '+undoPushDownStack);
 //alert('3. redoPushDownStack = '+redoPushDownStack);
 }

