/******************************************************************

  JavaScript stuff for managing the stylesheets on the fly and
  for maintaining e-mail addresses munged in the HTML source.

  The "WriteMailLink" function is © 2004-2006 G. Stewart,
  gstewart at spamcop dot net, and released under the terms of
  the GNU General Public License Version 2, the terms of which
  are viewable at http://www.gnu.org/licenses/gpl.html

  The "changeStylesheet", "useStylesheet" and "makeCookie"
  functions are based on code shamelessly pilfered fron the
  www.spamcop.net site with the permission of Jaeson Schultz
  of IronPort Systems, jaeson at ironport dot com.

******************************************************************/

  function WriteMailLink(user,domain,subject,display) {
    document.write('<a href="mai');
    document.write('lto:'+user+'&#64;');
    document.write(domain);
    if ( subject.length > 0 )  document.write("?subject="+subject);
    document.write('">');
    if ( display.length > 0 )
      document.write(display);
     else
      document.write(user+'&#64;'+domain);
    document.write('<'+'/a>');
  }

  function changeStylesheet(sheetName) {
    var newStyleNum;
    useStylesheet(sheetName);
    if ( sheetName == 'Microscopic' ) { newStyleNum = -2; }
    else if ( sheetName == 'Small' )  { newStyleNum = -1; }
    else if ( sheetName == 'Normal' ) { newStyleNum =  0; }
    else if ( sheetName == 'Large' )  { newStyleNum =  1; }
    else if ( sheetName == 'Giant' )  { newStyleNum =  2; }
    else newStyleNum = 0;
    makeCookie(newStyleNum);
  }

  function useStylesheet(sheetName) {
    var link=1;
    var count=0;
    var tagId, tagRel, useIt;
    while ( 1 ) {
      link = document.getElementsByTagName("link")[count];
      if ( !link ) { break; }
      tagId = link.getAttribute("title");
      tagRel = link.getAttribute("rel");
      useIt = ( ( tagRel.indexOf("stylesheet") != -1 ) && ( sheetName == tagId ) );
      link.disabled = !useIt;
      count++;
    }
  }

  function makeCookie(styleNum) {
    var cookieData;
    var expiry = new Date();
    expiry.setTime(expiry.getTime()+(365*24*60*60*1000));
    cookiedata = "textsize=" + styleNum + "; expires=" + expiry.toGMTString() + "; path=/; domain=howto-pages.org";
    document.cookie = cookiedata;
  }


