function ShowImage(p_Class, p_Src, p_Width1, p_Height1, p_Width2, p_Height2)
{
   var Width  = p_Width1;
   var Height = p_Height1;
   var Src    = p_Src;

   if(document.body.clientWidth > 800)
   {
      Width  = p_Width2;
      Height = p_Height2;
      Src    = p_Src.replace(/(\.jpg)/g, "_2$1");
   }

   document.writeln('<img ' + Attrib('class' , p_Class) + Attrib('src'   , Src)     +
                              Attrib('width' , Width)   + Attrib('height', Height)  + '>');
}

function Attrib(p_Name, p_Value)
{
   return(" " + p_Name + '="' + p_Value + '"');
}


// Set a cookie that never expires.
function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + '; Expires=01 Jan 2020 00:00 GMT'; //; domain=www.wademan.com';
}

// Read a cookie by name
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if(sName == aCrumb[0])
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

// Cross-platform function to get the target that generated an event.  For details see www.quirksmode.org
function EventTarget(e)
{
  var EventTarget;
  if(!e)
    var e = window.event;

  if(e.target)
    EventTarget = e.target;

  else if(e.srcElement)
    EventTarget = e.srcElement;

  if(EventTarget.nodeType == 3)
    EventTarget = EventTarget.parentNode;

  return EventTarget;
}

// Simple little debugging trace statement
function iTrace()
{
   if(arguments.length == 1)
   {
      document.write('<p style="color:Red;">' + arguments[0] + '</p>')
      return;
   }
   else
   {
      document.writeln('<table border=1 cellpadding=0 cellspacing=0 width=100% style="color:Red;">');
      for(var ArgIx = 0; ArgIx < arguments.length; ArgIx++)
         document.writeln('<tr><td>' + arguments[ArgIx] + '</td></tr>');
      document.writeln('</table>');
   }
}

// Simple little debugging trace statement
function iStop()
{
   var Display = '';
   Display = arguments[0];
   for(var ArgIx = 1; ArgIx < arguments.length; ArgIx++)
      Display += '\n-----------------------\n' + arguments[ArgIx];

   alert(Display, 'iStop');
}

function iDumpProps(pObj, pObjName)
{
   var Result = "";
   for (var i in pObj)
      Result += pObjName + "." + i + " = " + pObj[i] + "\n";

   alert(Result);
}

// Calculate a relative filename based on a file that ends in a number.  If pOffset is a number, adds
// that number to the current filename and returns it.  Otherwise, returns the current filename.
function RelativeFile(pOffset)
{
   if(pOffset == null || parseInt(pOffset) == NaN)
      return(pOffset);

   var SplitLocation = /.*[\\/](.*?)(\d+)(\.ht.*)/i;
   var Components    = SplitLocation.exec(document.location);
   if(Components == null)
      return(pOffset);

   var NewOffset     = '0000000' + (parseInt(Components[2]) + pOffset);
   return(Components[1] + NewOffset.substring(NewOffset.length - Components[2].length, 9999) + Components[3]);
}


function SetLingo(pLingo)
{
   // Set flags for the supported languages, with null or invalid being converted to Bilingual
   var English, Spanish;
   switch(parseInt(pLingo))
   {
   case 1:
      English = true;
      Spanish = false;
      break;

   case 2:
      English = false;
      Spanish = true;
      break;

   default:
      pLingo  = 0;
      English = true;
      Spanish = true;
      break;
   }
   document.forms.frmLingo.selLingo.selectedIndex = pLingo;

   var LangTags = "P H1 H2 H3 H4 H5 SPAN DIV TABLE TR TD";
   LangTags = LangTags.split(" ");

   for(var TagIx = 0; TagIx < LangTags.length; TagIx++)
   {
      var aDivs = document.body.getElementsByTagName(LangTags[TagIx]);
      var LastElement = ThisElement = null;
      for(DivIx = 0; DivIx < aDivs.length; DivIx++)
      {
         LastElement   = ThisElement;
         ThisElement   = aDivs[DivIx];
         var ThisLingo = ThisElement.lang.toUpperCase();
         if(ThisLingo == "ES")
         {
            ThisElement.style.display = Spanish ? "" : "none";
//            if(ThisElement.style.color == null)
               ThisElement.style.color   = English ? "DarkBlue" : "Black";
         }

         else if(ThisLingo == "EN")
         {
            ThisElement.style.display = English ? "" : "none";
         }

         else if(ThisLingo == "EN,ES")
         {
            ThisElement.style.display = (English && Spanish) ? "" : "none";
         }
      }
   }

   SetCookie('Lingo', pLingo);
}

function LingoToolbar(pAlign)
{
   if(pAlign == null)
      pAlign = 'Right';

   document.writeln('<table align=' + pAlign + ' border=0 cellpadding=0 cellspacing=0>');
   document.writeln('  <form id=frmLingo name=frmLingo>');
   document.writeln('    <caption style="Font-family: Arial, Sans; Font-Size: 9pt; color: DarkMagenta;">Language / Idoma');
   document.writeln('    <select id=selLingo onchange="ChangeLingo()" size=1 name=selLingo style="Font-family: Arial, Sans; Font-Size: 9pt; color: DarkMagenta;">');
   document.writeln('    <option selected>Bilingual / Bilingüe&nbsp;&nbsp;&nbsp;</option>');
   document.writeln('    <option>English&nbsp;&nbsp;</option>');
   document.writeln('    <option>Español</option>');
   document.writeln('    </select><font size=2> </font></caption>');
   document.writeln('  </form>');
   document.writeln('</table><br>');
   document.writeln('');
   document.forms.frmLingo.selLingo.selectedIndex = GetCookie('Lingo');
//   addLoadEvent(PageFooter);
}

function ChangeLingo()
{
   SetLingo(document.forms.frmLingo.selLingo.selectedIndex);
}

function RestoreLingo()
{
   SetLingo(GetCookie('Lingo'));
}

// Add an event to be executed after page load.  Cross-browser.
// See http://simon.incutio.com/archive/2004/05/26/addLoadEvent
// Usage:
// addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
// addLoadEvent(function() {
//   /* more code to run on page load */
// } );
function addLoadEvent(pFunc)
{
   var OldOnLoad = window.onload;
   if (typeof window.onload != 'function')
   {
     window.onload = pFunc;
   }
   else
   {
      window.onload = function()
      {
         OldOnLoad();
         pFunc();
      }
   }
}

var M_NextTextEN, M_NextTextES, M_NextURL, M_PrevURL;

function PageHeader(pTitle, pBgColor, pPrevURL, pNextURL, pNextTextEN, pNextTextES)
{
   M_NextTextEN = pNextTextEN;
   M_NextTextES = pNextTextES;
   if(pTitle == null)
      pTitle = document.title;

   M_PrevURL = RelativeFile(pPrevURL);
   M_NextURL = RelativeFile(pNextURL);

   document.writeln('<table border=5 cellspacing=0 cellpadding=0 bgcolor=' + pBgColor + ' width=100% frame=Box>');
   document.writeln('  <tr>');
   document.writeln('    <td>');
   document.writeln('    <table width=100% style="border-collapse: collapse" bordercolor=#111111 cellpadding=0 cellspacing=0>');
   document.writeln('      <tr>');
   document.writeln('        <td class=LTitle>&nbsp; <a href="/index.html"><span lang=EN>Home</span><span lang=EN,ES>/</span><span lang=ES>Inicio</span></a></td>');
   document.writeln('        <td class=CTitle>' + pTitle + '</td>');
   document.writeln('        <td class=RTitle>');
   if(M_PrevURL != null)
      document.writeln('<a href="' + M_PrevURL + '"><span lang=EN,ES>Prev</span></a>&nbsp;&nbsp;&nbsp;&nbsp;');

   if(pNextTextEN != null)
      document.writeln('<a href="' + M_NextURL + '"><span lang=EN>Next</span><span lang=EN,ES>/</span><span lang=ES>Próximo</span></a>');

   document.writeln('        &nbsp;</td>');
   document.writeln('      </tr>');
   document.writeln('    </table>');
   document.writeln('    </td>');
   document.writeln('  </tr>');
   document.writeln('</table>');
   LingoToolbar();
}

function PageFooter(pNextURL, pNextTextES, pNextTextEN)
{
   if(pNextURL    == null) pNextURL    = M_NextURL;
   if(pNextTextES == null) pNextTextES = M_NextTextES;
   if(pNextTextEN == null) pNextTextEN = M_NextTextEN;

   document.writeln('<table border=0 cellpadding=0 cellspacing=0>');

   if(pNextTextES != null && pNextTextES != "")
      document.writeln('<tr Lang=ES>'
                     +    '<td align="right">Próximo&nbsp;</td>'
                     +    '<td>->&nbsp;<a href="' + pNextURL + '">' + pNextTextES + '</a></td>'
                     + '</tr>');

   document.writeln('<tr Lang=EN>'
                  +    '<td align=right style="margin-top:0;">Next&nbsp;</td>'
                  +    '<td>->&nbsp;<a href="' + pNextURL + '">' + pNextTextEN + '</a></td>'
                  + '</tr>');
   document.writeln('</table>');
   RestoreLingo();
}
