// _kybdCommands.js - JavaScript copyright, Howard Best, 2005, 2006, 2007, 2008, 2009.
// The following JavaScript code was tested using IE6, IE7, Firefox 2 and Firefox 3.
// Please feel free to copy / use / modify it in any way that you see fit for your own application(s) as long as "Howard Best (llbest.com)" is given credit in a comment, similar to this one, at the beginning of the copied / modified code.

var _uacct;

itsMSIE=navigator.userAgent.indexOf('MSIE')>0;

document.write('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script><div id=message1 style="position:absolute;background:transparent;width:'+(itsMSIE?'100':'98')+'%;text-align:center;font-size:85%;font-weight:bold;left:0"></div>');

// BASIC PARAMETERS:
FW = 'normal, bold'.split(', ');
                // Available font weights
J  = 'justify,center,left,right'.split(',');
                // Text justification options array
if(typeof(JavaScriptForKeyG)=='undefined')
 JavaScriptForKeyG="if(thisFileName){loadIt('.');} // _kybdCommands.js";
                // Code to execute when the "G" key is pressed
if(typeof(JavaScriptForKeyS)=='undefined')
 JavaScriptForKeyS="loadIt(thisFileName); // _kybdCommands.js";
                // Code to execute when the "S" key is pressed

cookieVar='No cookies read or written so far.';

CS=fontWeightIndex=fontIndex=JI=lastJI=TP=lastFontIndex=lastFontWeightIndex=BG2=BG3=HFSA=VCM=0;
RO=theKeyCode=lastKeyCode=temp1=temp9=fontAbbreviation=diagVar=PLFN='';
blockKeyboardCommands=theAudioIsLoaded=threeBG=helpMode=DM=theAudioIsLoaded=ND=false;
initialVOL=VOL=50;
lastCookie='fhfsm98';
maxAlertsDM=10;
origColor=[];
lastColor=[];
numberOfColors=256*256*256;
colorVariableTags=new Array('BGI','BG','BG2','BG3','CN','CB','LC','ALC','VLC','HLC','CH','CG','SG','DIM');
colorTitles=new Array('Background image number','Background color','Background color #2','Background color #3','Text color','Bold text color','Link text color','Active link text color','Visited link text color','Hover link text color','Header text color','Header glow color','Header glow strength','"Extra" text dimming percent');

thisFileName=location.href.replace(/[\?#].*$/,'').replace(/^.*[\/\\]/,function(temp1){thisPathName=temp1;return('')}).replace(/%[0-9A-F]{2}/g,function(temp1){return String.fromCharCode(parseInt(temp1.substring(1),16))});
thisFileName=(thisFileName=='undefined')?'':thisFileName;

thisURL2=thisPathName+thisFileName;

theCookieName=document.title.replace(/ .*$/,'');

(cookieAndURLparser(cookieRead(theCookieName))).replace(/^;?DM=([^;]*)/,function(temp1){DM=temp1.slice(3)});
location.search.replace(/[\?&]DM=([^&]*)/,function(temp1){DM=temp1.slice(4)});
try{eval('DM='+DM)}catch(e){}

function alertDM(theMessage)
 {
 if(maxAlertsDM)
  {
  alert(theMessage);
  maxAlertsDM--;
  }
 else
  changeDM(false);
 }

function changeStyles()
 {
 styleRulesCount2=theStyles.cssRules?theStyles.cssRules.length /* Firefox */ :theStyles.rules.length /* IE */ ;
 var T1='color:#';
 var T2='';
 for(var i=0;i<6;i+=2)
  T2+=('0'+(parseInt((parseInt(CN.substring(i,i+2),16)+parseInt(BG.substring(i,i+2),16)*7)/8+0.5)).toString(16)).slice(-2).toUpperCase();
 var T3=T1+CN;
 var T4=';background:#';
 var T5=T4+BG;
 var T6=T4+T2;
 var T7=T3+T5;
 var T8=T3+T6;
 var T9=';border-color:#'+CB;
 var T10=T7+T9;
 var T11=T8+T9;
 var T12=T4+BG+';background-image:url('+imageFolder+G[Math.abs(BGI)]+')';
 var T13=T1+CB+';';
 var T14=T13+T9+T4+T2;
 var T15=T3+';background:transparent';
 var T16=T3+';text-align:'+J[JI];
 fontWeight=FW[fontWeightIndex];
 fontName=F[fontIndex];
 fontAbbreviation=FT[fontIndex];
 var T17=fontName+','+AF;
 GEBI('textDiv').style.fontFamily=T17;
 try{GEBI('textP').style.fontFamily=T17}catch(er){}
 GEBI('textDiv').style.fontWeight=fontWeight;
 try{GEBI('textP').style.fontWeight=fontWeight}catch(er){}
 T17=';font-family:'+T17+';font-weight:'+fontWeight;
 T18=T13+T17;
 T19=T16+T17;
 document.body.style.background='#'+T2;
 try{GCD.body.style.background='#'+BG;GCD.body.style.color='#'+CN}catch(e){};
 if(theStyles.deleteRule)
  { // Firefox:
  try{GEBI('TXTBOX2').style.background='#'+BG}catch(e){};
  try{GEBI('TXTBOX3').style.background='#'+BG}catch(e){};
  for(i=styleRulesCount2-1;i>=styleRulesCount;i--)
   theStyles.deleteRule(i);
  theStyles.insertRule('a:active{'+T1+ALC+'}',theStyles.cssRules.length);
  theStyles.insertRule('a:hover{'+T1+HLC+'}',theStyles.cssRules.length);
  theStyles.insertRule('a:link{'+T1+LC+'}',theStyles.cssRules.length);
  theStyles.insertRule('a:visited{'+T1+VLC+'}',theStyles.cssRules.length);
  theStyles.insertRule('div{'+T12+'}',theStyles.cssRules.length);
  theStyles.insertRule('h1{'+T18+'}',theStyles.cssRules.length);
  theStyles.insertRule('h2{'+T18+'}',theStyles.cssRules.length);
  theStyles.insertRule('h3{'+T18+'}',theStyles.cssRules.length);
  theStyles.insertRule('h4{'+T18+'}',theStyles.cssRules.length);
  theStyles.insertRule('hr{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('iframe{'+T9+'}',theStyles.cssRules.length);
  theStyles.insertRule('img{'+T9+'}',theStyles.cssRules.length);
  theStyles.insertRule('input{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('input.INP1{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('input.INP2{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('input.INP3{'+T15+'}',theStyles.cssRules.length);
  theStyles.insertRule('input.INP5{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('ol{'+T16+'}',theStyles.cssRules.length);
  theStyles.insertRule('p{'+T16+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.ColorBox{'+T14+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.TBOX{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.Bold{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.chapnum{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.Textnum{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('p.VerseNumberHeading{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('select{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('span{'+T13+'}',theStyles.cssRules.length);
  theStyles.insertRule('span.CN{'+T3+'}',theStyles.cssRules.length);
  theStyles.insertRule('span.G{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('table.BBOX{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('table.TS4{'+T10+'}',theStyles.cssRules.length);
  theStyles.insertRule('table.TS5{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('td{'+T19+'}',theStyles.cssRules.length);
  theStyles.insertRule('td.change{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('.TA2{'+T10+'}',theStyles.cssRules.length);
  theStyles.insertRule('.TA3{'+T7+'}',theStyles.cssRules.length);
  theStyles.insertRule('.TA4{'+T11+'}',theStyles.cssRules.length);
  theStyles.insertRule('tt{'+T3+'}',theStyles.cssRules.length);
  }
 else
  if(theStyles.removeRule)
   { // IE:
   try{GCD.body.style.scrollbarBaseColor='#'+T2}catch(e){};
   for(i=styleRulesCount2-1;i>=styleRulesCount;i--)
    removeArule(i);
   addArule('a:active',T1+ALC);
   addArule('a:hover',T1+HLC);
   addArule('a:link',T1+LC);
   addArule('a:visited',T1+VLC);
   addArule('body','scrollbar-base-color:'+T2);
   addArule('div',T12);
   addArule('h1',T18);
   addArule('h2',T18);
   addArule('h3',T18);
   addArule('h4',T18);
   addArule('hr',T13);
   addArule('iframe',T9);
   addArule('img',T9);
   addArule('input',T7);
   addArule('input.INP1',T7);
   addArule('input.INP2',T7);
   addArule('input.INP3',T15);
   addArule('input.INP5',T7);
   addArule('ol',T16);
   addArule('p',T16);
   addArule('p.ColorBox',T14);
   addArule('p.TBOX',T11);
   addArule('p.Bold',T13);
   addArule('p.chapnum',T13);
   addArule('p.Textnum',T13);
   addArule('p.VerseNumberHeading',T13);
   addArule('select',T7);
   addArule('span',T13);
   addArule('span.CN',T3);
   addArule('span.G',T11);
   addArule('table.BBOX',T11);
   addArule('table.TS4',T10);
   addArule('table.TS5',T11);
   addArule('td',T19);
   addArule('td.change',T11);
   addArule('.TA2',T10);
   addArule('.TA3',T7);
   addArule('.TA4',T11);
   addArule('tt',T3);
   }
 cookieParamsWrite('changeStyles()');
 window.status=' | Current font: '+fontName+', '+AF+' ('+fontWeight+') | Current color scheme number: '+CS+' |';
 }

function changeDM(trueOrFalse)
 {
 if(DM!=trueOrFalse)
  {
  DM=trueOrFalse;
  if(DM)
   {
   alert('Diagnostic mode started. Press "Alt+D" to stop.\n\n'+diagVar+'\n\nAutomatically stopped after 10 alerts in order to prevent infinite loop.');
   maxAlertsDM=10;
   }
  else
   alert('Diagnostic mode stopped. Press "Alt+D" to restart.');
  cookieParamsWrite('changeDM()');
  }
 }

function chooseRandomColor(min,max)
 {
 return(('00000'+(min+Math.floor(Math.random()*(max-min))).toString(16)).slice(-6).toUpperCase());
 }

function colorDimmer(theForegroundColor,theBackgroundColor,theDimmingPercent)
 {
 var T1='';
 for(var i=0;i<theForegroundColor.length;i+=2)
  T1+=decimalToHex((parseInt(theForegroundColor.substr(i,2),16)*(100-theDimmingPercent)+parseInt(theBackgroundColor.substr(i,2),16)*theDimmingPercent)/100);
 return(T1);
 }

function colorNameToCode(theColor)
 {
 var T1=document.bgColor,T2=theColor;
 T2=T2.replace(/^[0-9a-fA-F]{1,6}$/,function(T1){return((T1+'00000').replace(/^(......).*$/,'$1'))});
 try
  {
  if(itsMSIE)
   {
   document.body.style.backgroundColor=T2;
   T2=document.bgColor.slice(1);
   document.body.style.backgroundColor=T1;
   }
  else
   {
   document.bgColor=T2;
   T2=document.bgColor.slice(1);
   document.bgColor=T1;
   }
  }
 catch(e)
  {
  T2='000000';
  }
 return(T2.toUpperCase());
 }

function colorNegative(theColor)
 {
 if(theColor.length==6)
  {
  var T1=theColor.split('');
  for(var i=0;i<T1.length;i++)
   T1[i]=(15-parseInt(T1[i],16)).toString(16).toUpperCase();
  return(T1.join(''));
  }
 else
  {
  alert('"'+theColor+'" is not a valid color code.');
  return(theColor);
  }
 }

function colorParser(theIncrement)
 {
 CS|=0;
 CS=(CS+theIncrement+C.length)%C.length;
 BG2=BG3=0;
 try{eval(C[CS].replace(/=/g,'="').replace(/&/g,'";')+'"')}catch(e){alert(e)};
 BGI|=0;
 DIM|=0;
 SG|=0;
 if(!BG2)
  BG2=BG;
 if(!BG3)
  BG3=BG;
 threeBG=(BG!=BG2)||(BG!=BG3);
 for(i=0;i<colorVariableTags.length;i++)
  eval('origColor['+i+']='+colorVariableTags[i]);
 }

function colorShift(theColor)
 {
 var T1=[theColor.slice(2,4),theColor.slice(-2),theColor.slice(0,2)];
 return(T1.join(''));
 }

function cookieAndURLparser(theString)
 {
 return(theString?(theString.replace(/^\??/,';').replace(/[&;]/g,'";').replace(/;i=/g,';PLFN=').replace(/;p=/g,';PN=').replace(/;r=/g,';RO=').replace(/;h=/g,';HFSA=').replace(/;j=/g,';JI=').replace(/;cs=/g,';CS=').replace(/;v=/g,';VOL=').replace(/;vm=/g,';VCM=').replace(/;vs=/g,';VRS=').replace(/;[Ff]=/g,';temp1=').replace(/;t=/g,';TP=').slice(2).replace(/=/g,'="').replace(/\+/g,' ')+'";'):'');
 }

function cookieParamsWrite(calledBy)
 {
 if(VCM==0)
  {
  theCookie=encodeURL('dhr6344qq','cookieParamsWrite() / '+calledBy).slice(1).replace(/&/g,';')
  if(theCookie!=lastCookie)
   {
   cookieWrite(theCookieName,theCookie,8);
   lastCookie=theCookie;
   }
  }
 }

function cookieRead(cookieName)
 {
 var T1=document.cookie,T2=cookieName+'=',T3='',T4,T5='';
 if(T1)
  {
  T3=T1.indexOf(T2);
  if(T3+1)
   { 
   T3+=T2.length;
   T4=T1.indexOf(";",T3);
   if(!(T4+1))
    T4=T1.length;
   T5=unescape(T1.substring(T3,T4));
   cookieVar='Cookie "'+cookieName+'" containing "'+T5+'" read.\n';
   if(DM)
    alertDM(cookieVar);
   }
  }
 return(T5);
 }

function cookieWrite(cookieName,cookieContents,numberOfDaysToKeep)
 {
 var T1=new Date();
 T1.setTime(T1.getTime()+86400000*((cookieContents)?numberOfDaysToKeep:0));
 document.cookie=cookieName+'='+escape(cookieContents)+"; expires="+T1.toUTCString()+';path=/';
 cookieVar='Cookie "'+cookieName+'" '+(cookieContents?' containing "'+cookieContents+'" written':'deleted')+'.\n';
 if(DM)
  alertDM(cookieVar);
 }

function decimalToHex(decNum)
 {
 var T1=(decNum|0).toString(16).toUpperCase();
 return(((T1.length<2)?'0':'')+T1);
 }

function encodeURL(theFileName,calledBy)
 {
 if(DM)
  alertDM('_kybdCommands.js - encodeUR\x4C() / '+calledBy)
 var T1=encodeURLcommon(theFileName),T2;
 for(var i=0;i<origColor.length;i++)
  {
  T2=colorVariableTags[i];
  if(((T2=='BG2')&&(BG2==BG))||((T2=='BG3')&&(BG3==BG)))
   continue;
  eval('T1+=(origColor['+i+']=='+T2+')?"":"&'+T2+'='+eval(T2)+'"');
  }
 return(T1);
 }

function encodeURLcommon(theFileName)
 {
 var T1='',T2=(theFileName!=thisFileName)?0:Math.round((document.body.scrollTop/GEBI('textDiv').clientHeight*10000));
 //T1+=PLFN?'&PLFN='+PLFN:'';
 T1+=T2?'&TP='+T2:'';
 T2=fontAbbreviation+fontWeightIndex;
 T1+=(T2==FT[0]+0)?'':'&F='+T2;
 T1+=CS?'&CS='+CS:'';
 T1+=DM?'&DM='+DM:'';
 T1+=(VOL!=initialVOL)?'&VOL='+VOL:'';
 T1+=JI?'&JI='+JI:'';
 SW=helpMode?SW|32:SW&223;
 T1+=(SW!=defaultSW)?'&SW='+SW:'';
 T1+=HFSA?'&HFSA='+HFSA:'';
 T1+=ND?'&ND='+ND:'';
 return(T1);
 }

function enoughContrast(color1,color2)
 {
 var T1=0;
 for(var i=0;i<color1.length;i+=2)
  T1+=Math.abs(parseInt(color1.substr(i,2),16)-parseInt(color2.substr(i,2),16));
 // T1 ranges from 0 to 765
 return(T1>=255)
 }

function GEBI(theID)
 {
 return(document.getElementById(theID));
 }

function itsDark(theColor)
 {
 if(theColor.toLowerCase()=="transparent")
  return(255+255+255);
 else
  {
  var T1=0;
  for(var j=0;j<theColor.length;j+=2)
   T1+=parseInt(theColor.substr(j,2),16);
  // T1 ranges from 0 to 765
  return(T1<384);
  }
 }

function keyPressed(theEvent)
 {
 var T1=String.fromCharCode((itsMSIE)?theEvent.keyCode:theEvent.which);

 if(theEvent.altKey&&(T1=='D'))
  changeDM(!DM);

 if(blockKeyboardCommands||theEvent.shiftKey||theEvent.ctrlKey||theEvent.altKey)
  return;

 theKeyCode=T1;

 if(theKeyCode=='U')
  {
  theKeyCode=lastKeyCode;
  itsAnUndo=true;
  }
 else
  {
  itsAnUndo=false;
  storeUndoData();
  }

 switch(theKeyCode)
  {

  case'\xDC': // (\)
   PressedBackslash();
   break;

  case'-': // (Insert)
   alert('Screen resolution: '+screen.width+'x'+screen.height+'\nAvailable: '+document.body.clientWidth+'x'+document.body.clientHeight+'\nThis file name: '+thisFileName+'\nCurrent font: '+fontName+', '+AF+'\nURL: '+location+((typeof( undoDiac)=='string')?'\n\n(To '+(ND?'add':'remove')+' the diacritics, press the "D" key.)':''));
;
   break;

  case' ': // (Space bar)
   try{spaceBarPressed()}catch(e){};
   break;

  case'0':
   Pressed0();
   changeStyles();
   break;

  case'7':
   Pressed7('changeStyles()');
   break;

  case'8':
   Pressed8();
   window.status='|';
   changeStyles();
   break;

  case'C':
   PressedC();
   changeStyles();
   break;

  case'D':
   toggleDiac();
   break;
    
  case'G':
   eval(JavaScriptForKeyG);
   break;

  case'H':
   alert(
'AVAILABLE KEYBOARD COMMANDS:\n\n\\ - Cycle through the 4 types '+
'of text justification.\n\n0 - Cycle through the '+(G.length-1)+' b'+
'ackground images.\n\n7 - Enter colors manually.\n\n8 - Cycle '+
'through the '+C.length+' preset color schemes.\n\nC - Switch to randomly generate'+
'd color scheme.\n\n'+
((typeof( undoDiac)=='string')?'D - '+(ND?'Restore':'Remove')+' diacritics.\n\n':'')+
((thisFileName||PLFN)?'G - Go to index / home page.\n\n':'')+
'H - This help window.\n\nK - Switch to complimentary colors.'+
'\n\nN - Cycle through the '+F.length+' preset fonts.\n\nS - Store (bookmark) th'+
'e vertical scroll position at the end of the URL in the "Addr'+
'ess Bar" above. If you are going to want to return to this sa'+
'me web page / scroll position on...\n  1. ...this computer, t'+
'hen save the newly created URL as a "Favorite" / "Bookmark".'+
'\n  2. ...a DIFFERENT computer, then copy / paste the URL into'+
' an email message and send it to yourself.\n\nU - Undo.\n\nV '+
'- Restore defaults and delete cookie.\n');
   break;

  case'K':
   PressedK();
   changeStyles();
   break;

  case'N':
   PressedN();
   changeStyles();
   break;

  case'S':
   eval(JavaScriptForKeyS);
   break;

  case'V':
   PressedV();
   break;

  case'W':
   {
   PressedW();
   break;
   }

  default:
   return;

  }

 lastKeyCode=theKeyCode;
 }

function loadIt(theFileName)
 {
 var T1=encodeURL(theFileName,'loadIt()');
 location=(theFileName+(T1?'?'+T1.slice(1):'')).replace(/(#.*?)(\?.*$)/,'$2$1');
 }

function loadItPLFN(theFileName)
 {
 var T1=encodeURL(theFileName,'loadItPLFN()');
 T1+=(PLFN&&(PLFN!=IPL[0]))?'&PLFN='+PLFN:'';
 //T1+=(PLFN&&(PLFN!=IPL[0])&&thisFileName)?'&PLFN='+PLFN:''; (Prior to 4/15/2010)
 location=(theFileName+(T1?'?'+T1.slice(1):'')).replace(/(#.*?)(\?.*$)/,'$2$1');
 }

function pageLoaded()
 {
 var T1,T2,T3,T4,T5,T6;
 // iPhone, iPad, BlackBerry Storm 
 try{if(navigator.userAgent.match(/(iPhone|iPad|BlackBerry9530)/i)){GEBI('touchScreenSpan1').innerHTML=GEBI('touchScreenSpan2').innerHTML='<textarea class=TA4 style="text-align:center;font-family:Tahoma;font-size:16pt;width:410;line-height:1.2em;border:solid;border-width:1;margin:0;margin-bottom:5;overflow:hidden;" rows="2" readonly="readonly">Tap here to bring up the touch screen keyboard. (Then tap \u201cH\u201d for help.)</textarea>'}}catch(e){};
 try{_uacct=GA;}catch(e){};
 try{urchinTracker()}catch(e){}  // Call Google Analytics function
 diagVar='JavaScriptForKeyG = '+JavaScriptForKeyG+'\nJavaScriptForKeyS = '+JavaScriptForKeyS;
 itsATS=(typeof(PLA)!='undefined')&&(PLA=='pageLoadedTL');
 if(typeof(PLA2)=='undefined')
  PLA2='';
 if(typeof(PLFN)=='undefined')
  PLFN='';
 if(typeof(SW)=='undefined')
  SW=12;
 defaultSW=SW;
 colorParser(0);
 T1=BG;
 T2=BG2;
 T3=BG3;
 BG=BG2=BG3=0;
 j=0;
 lastCookie=cookieRead(theCookieName);
 T4=cookieAndURLparser(lastCookie);
 T5=cookieAndURLparser(location.search);
 temp1=T6='';
 try{eval(T4)}catch(e){}
 try{eval(T5)}catch(e){}
 if(CS)
  {
  CS=Math.min(CS|0,C.length-1);
  colorParser(0);
  T1=BG;
  try{eval(T4)}catch(e){}
  try{eval(T5)}catch(e){}
  }
 if(temp1)
  {
  T6=(temp1.slice(-1))|0;
  fontWeight=(temp1&&T2&&(!isNaN(T6)))?T6:0;
  fontWeightIndex=Math.min(FW.length-1,Math.max(0,fontWeight));
  fontAbbreviation=temp1.slice(0,-1);
  for(i=0;i<F.length;i++)
   {
   if(fontAbbreviation==FT[i])
    {
    fontIndex=i;
    fontName=F[fontIndex];
    break;
    }
   }
  }
 else
  fontAbbreviation=FT[0];
 BG=BG?BG:T1
 BG2=BG2?BG2:(T2?T2:BG);
 BG3=BG3?BG3:(T3?T3:BG);
 threeBG=(BG!=BG2)||(BG!=BG3);
 BGI|=0;
 if(BGI<0)
  VCM=false;
 DIM|=0;
 HFSA|=0;
 SG|=0;
 VOL|=0;
 SW=SW&127;
 helpMode=((SW&32)==32);
 if(j)
  JI|=0;
 if(JI>=J.length)
  JI=0;
 try{eval('DM='+DM)}catch(e){}
 if(DM)
  {
  DM=false;
  changeDM(true);
  }
 if(!itsATS)
  {
  theStyles=document.styleSheets[0];
  styleRulesCount=theStyles.cssRules?theStyles.cssRules.length /* Firefox */ :theStyles.rules.length /* IE */ ;
  if(theStyles.addRule)
   { // IE:
   addArule=theStyles.addRule;
   removeArule=theStyles.removeRule;
   }
  try{GEBI('pressH1').innerHTML=GEBI('pressH2').innerHTML='Press <span>H</span> for help. |'}catch(er){}
  changeStyles();
  if(TP&&(location.href.indexOf('#')<0))
   window.scrollTo(0,TP*GEBI('textDiv').clientHeight/10000);
  }
 try{eval(PLA+'()')}catch(e){} // PLA = Name of additional function to execute after the page has loaded
 if(ND)
  ND=true;
 else
  {
  ND=true;
  toggleDiac();
  }
 cookieParamsWrite('pageLoaded()');
 }

function Pressed0()
 {
 if(itsAnUndo&&!undo0)
  {
  BGI=(BGI-1+G.length)%G.length;
  undo0=true;
  }
 else
  {
  BGI=(BGI+1)%G.length;
  undo0=false;
  }
 }

function Pressed7(CC)
 {
 if(itsAnUndo)
  undoStyles();
 else
  {
  var T1,T2,T3;
  for(var i=0;i<colorVariableTags.length;i++)
   {
   T1=colorVariableTags[i];
   if(!itsATS&&(T1=='CH'))
    break;
   T2=T1=='BG';
   threeBG=itsATS?(T2?(confirm('Three color background?')?true:false):threeBG):false;
   if(itsATS&&!threeBG&&T2)
    {
    BG2=BG3=BG;
    eval(CC);
    }
   if((T1=='BG2')||(T1=='BG3'))
    {
    if(!itsATS||!threeBG)
     continue;
    if(T1=='BG2')
     BG2=colorShift(BG);
    else
     BG3=colorShift(BG2);
    }  
   T3=prompt(colorTitles[i]+((itsATS&&(T1=='BGI'))?', negative for scrolling background':'')+((itsATS&&(T1=='BG')&&threeBG)?' #1':'')+':',(eval(T1)));
   if(T3==null)
    break;
   eval(T1+(((T1=='BGI')||(T1=='SG')||(T1=='DIM'))?'=(T3|0);if(isNaN('+T1+')){'+T1+'=0}':'=colorNameToCode(T3)'));
   if(T2&&!threeBG)
    BG2=BG3=BG;
   if(T1=='BGI')
    {   
    if((BGI<0)&&itsATS&&VCM)
     {
     alert(first1+'"Tab" key.');
     return;
     }
    T1=Math.abs(BGI);
    T2=Math.min(T1,G.length-1);
    if(T1)
     BGI=itsATS?T2*BGI/T1:T2;
    }
   eval(CC);
   }
  }
 }

function Pressed8()
 {
 if(itsAnUndo&&!undo8)
  {
  colorParser(-1);
  undo8=true;
  }
 else
  {
  colorParser(1);
  undo8=false;
  }
 }

function PressedBackslash()
 {
 if(itsAnUndo)
  undoStyles();
 else
  JI=(JI+1)%J.length;
 changeStyles();
 }

function PressedC()
 {
 if(itsAnUndo)
  undoStyles();
 else
  {
  var T2;
  CS=0;
  colorParser(0);
  BGI=0;
  var T4=Math.random()>0.5;
  var T5=Math.random()>0.5;
  for(var T3=1;;T3++)
   {
   BG=chooseRandomColor(0,numberOfColors);
   CB=chooseRandomColor(0,numberOfColors);
   if(T4)
    {
    CN=colorDimmer(CB,T5?BG:itsDark(BG)?'FFFFFF':'000000',50);
    T2='bold font'+(T5?'/background':'');
    }
   else
    {
    CN=itsDark(BG)?'FFFFFF':'000000';
    T2='background';
    }
   if(enoughContrast(BG,CB)&&enoughContrast(BG,CN)&&enoughContrast(CB,CN))
    break;
   }
  BG2=threeBG?colorShift(BG):BG;
  BG3=threeBG?colorShift(BG2):BG;
  setLinkColors();
  }
 }

function PressedK()
 {
 for(var i=1;i<colorVariableTags.length-2;i++)
  eval(colorVariableTags[i]+'=colorNegative('+colorVariableTags[i]+')');
 BGI=(BGI==1)?2:(BGI==2)?1:0;
 }

function PressedN()
 {
 if(itsAnUndo)
  undoStyles();
 else
  {
  fontWeightIndex++;
  fontWeightIndex=(fontWeightIndex+FW.length)%FW.length;
  if(!fontWeightIndex)
   {
   fontIndex++;
   fontIndex=(fontIndex+F.length)%F.length;
   }
  }
 }

function PressedV()
 {
 var T1;
 if(itsAnUndo)
  {
  undoStyles();
  T1=lastVOL-VOL;
  HFSA=lastHFSA;
  SW=lastSW;
  if(lastND!=ND)
   {
   lastND=ND;
   toggleDiac();
   }
 helpMode=lastHelpMode;
  }
 else
  {
  CS=fontWeightIndex=fontIndex=JI=HFSA=0;
  colorParser(0);
  T1=initialVOL-VOL;
  SW=defaultSW;
  if(ND)
   toggleDiac();
  helpMode=false;
  }
 if(T1)
  {
  if(theAudioIsLoaded)
   changeVolumeLevel1(T1);
  else
   VOL+=T1;
  }
 if(itsATS)
  displayTitle();
 else
  changeStyles();
 }

function PressedW()
 {
 alert('Latest cookie info: '+cookieVar);
 }

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(document.theForm.SearchString.value);
 }

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 setLinkColors()
 {
 LC=CB;
 VLC=CN;
 HLC=(enoughContrast(HLC,BG))?'FF0000':'0000FF';
 ALC=colorDimmer(colorNegative(LC),itsDark(LC)?'FFFFFF':'000000',40);
 }

function storeUndoData()
 {
 lastCS=CS;
 for(var i=0;i<colorVariableTags.length;i++)
  eval('lastColor['+i+']='+colorVariableTags[i]);
 lastVOL=VOL;
 lastHFSA=HFSA;
 lastJI=JI;
 lastSW=SW;
 lastND=ND;
 lastHelpMode=helpMode;
 lastFontIndex=fontIndex;
 lastFontWeightIndex=fontWeightIndex;
 lastWindowStatus=window.status;
 }
 
function test(t)
 {
 alert(t+' '+typeof(t));
 }

function toggleDiac()
 {
 if(typeof( undoDiac)=='string')
  {
  ND=!ND;
  cookieParamsWrite('toggleDiac()');
  GEBI('message1').style.top=document.body.scrollTop+screen.availHeight/2-140;
  if(undoDiac.length>30000)
   GEBI('message1').innerHTML= '<span style="background:blue;color:yellow;padding:5">'+(ND?'Removing':'Adding')+' Sanskrit diacritics</span>';
  setTimeout('toggleDiac2()',50);
  }
 else
  ND=false;
 }

function toggleDiac2()
 {
 var T1=GEBI('theText').innerHTML;
 GEBI('theText').innerHTML=undoDiac;
 undoDiac=T1;
 GEBI('message1').innerHTML= '';
 }

function undoStyles()
 {
 var T1,T2;
 T1=window.status;
 window.status=lastWindowStatus;
 lastWindowStatus=T1;
 T1=CS;
 CS=lastCS;
 lastCS=T1;
 colorParser(0);
 for(var i=0;i<colorVariableTags.length;i++)
  {
  T1=colorVariableTags[i];
  eval('T2='+T1);
  eval(T1+'=lastColor['+i+']');
  eval('lastColor['+i+']=T2');
  }
 T1=fontWeightIndex;
 fontWeightIndex=lastFontWeightIndex;
 lastFontWeightIndex=T1;
 T1=fontIndex;
 fontIndex=lastFontIndex;
 lastFontIndex=T1;
 T1=JI;
 JI=lastJI;
 lastJI=T1;
 }

function unformatTheTime(theTime)
 {
 var T1=theTime.split(':');
 return((T1[0]|0)*60+(T1[1]|0));
 }

