function ajax( filename, location )
  {
    var pageRequest = false;
    if ( window.XMLHttpRequest ) 
      { pageRequest = new XMLHttpRequest( ); }
    else if ( window.ActiveXObject ) 
      { pageRequest = new ActiveXObject('Microsoft.XMLHTTP'); }
    else return false;

    pageRequest.onreadystatechange = function( )
      { element( location ).innerHTML = pageRequest.responseText; } 

    pageRequest.open('GET',filename,true);
    pageRequest.send(null);
  }


function element( idvalue )
 {  return document.getElementById( idvalue ); }






function menufocus( object, toggles )
 {
   if ( toggles == 'on' )
    {
      object.style.borderColor = '#ff9966';
      object.style.color = '#ff6633';
      object.style.fontStyle = 'italic';
      object.style.fontVariant = 'small-caps';
    }
   else
    {
      object.style.borderColor = '#3366ff';
      object.style.color = '#6699ff';
      object.style.fontStyle = 'normal';
      object.style.fontVariant = 'normal';
    }
 } // end function navibutton



function navifocus( object, toggles )
 {
   if ( toggles == 'on' )
    {
      
      object.style.borderColor = '#ff9966';
      object.style.borderStyle = 'double';
      object.style.borderWidth = '1px 5px';
      object.style.color = '#ff6633';
      object.style.fontStyle = 'italic';
      object.style.fontVariant = 'small-caps';
      object.style.fontWeight = 'bold';
    }
   else
    {
      object.style.borderColor = '#3366ff';
      object.style.borderStyle = 'solid';
      object.style.borderWidth = '2px 1px';
      object.style.color = '#6699ff';
      object.style.fontStyle = 'normal';
      object.style.fontVariant = 'normal';
      object.style.fontWeight = 'normal';
    }
 } // end function menubutton


function replaceComic( newValue, theType )
 {
   switch ( theType )
    {
      case 'first':      currentComic = 1;             break;
      case 'previous':   currentComic--;               break;
      case 'random':     currentComic = newValue;      break;
      case 'next':       currentComic++;               break;
      case 'last':       currentComic = maximumComic;  break;
      case 'goto':       currentComic = newValue;      break;
      case 'other':                                    break;
      default:           alert('failed switch');
    }

   if ( theType != 'other' )
    {
      if ( newValue < 1 )      { newValue = 1; }
      if ( currentComic < 1 )  { currentComic = 1; }
      if ( newValue > maximumComic )     { newValue = maximumComic; }
      if ( currentComic > maximumComic)  { currentComic = maximumComic; }
      newImageFilename = '' + newValue;
      while ( newImageFilename.length < 4 )
       {
         newImageFilename = '0' + newImageFilename;
       } // end while
      newComicNumber = newImageFilename;
      newImageFilename = newImageFilename + '.php';

      element('episode').innerHTML = ':: ' + currentComic + '';
      ajax( newImageFilename, 'comic' );
      element('comicnumber').innerHTML = newComicNumber;
      return;
    }
   else if ( theType == 'other' )
    {
      newImageFilename = newValue + '.php';
      element('episode').innerHTML = ':: ' + newValue + '';
      ajax( newImageFilename, 'comic' );
      element('comicnumber').innerHTML = 'current';
      return;
    }
   return;

 }


function replaceText( newTextFile )
 {
    ajax( newTextFile, 'text' );
 }