/* --------------------------------- */
/* sampler-FontComparison.js         */
/* --------------------------------- */
/* Created:      2001-11-12          */
/* Issued:       2001-11-20          */
/* Modified:     2007-08-11          */
/* Copyright (c) 2001-2007 by        */
/* Philip Shaw, all rights reserved. */
/* --------------------------------- */

// Default domain
/////////////////////////////////////
var defaultDomain = 'www.codestyle.org';

// The sampler URL string.
/////////////////////////////////////
var sampleURL = '';

// Handle for the popup window.
/////////////////////////////////////
var fontWindow;

// The window features.
/////////////////////////////////////
var features = 'width=575,' +
               'height=235,' +
               'resizable=yes,' +
               'scrollbars=yes,' +
               'location=no' +
               'status=yes';

// The sampler host.
/////////////////////////////////////
var hostDomain = '';

if ((window.location) &&
    (window.location.host) &&
    (window.location.host != null) &&
    (window.location.host != '')){

  hostDomain = window.location.host;
}
else{

  hostDomain = defaultDomain;
}

// Pop-up window status
/////////////////////////////////////
var popable = false;

if (window.open) {

  popable = true;
}


// Create a new sampler window.
/////////////////////////////////////
function compareFonts(fontclass,fontname) {

  sampleURL = 'http://' + hostDomain;
  sampleURL += '/servlets/FontSampler?';
  sampleURL += 'class=' + fontclass;
  sampleURL += '&font=' + fontname;

  if (popable) {

    sampleURL += '&compare=popup';

    fontWindow = window.open(sampleURL,
                            'SampleWindow',
                             features);
    if (window.focus) {

      // Give focus to the popup window
      fontWindow.focus();
    }
  }
  else{
    /*
      Should not reach this clause,
      popable status is checked in
      the onclick handler. Fallback
      error recovery only.
    */
    sampleURL += '&compare=normal';

    if ((window.location) &&
        (window.location.href)) {

      // Recommended method
      window.location.href = sampleURL;
    }
    else {

      if (window.location){

        // Deprecated method
        window.location = sampleURL;
      }
      else{
        /*
          Inescapable error:
          nothing happens.
        */
      }
    }
  }
}

// Check all checkbox input types.
/////////////////////////////////////
function checkAllBoxes() {

  for (i = 0; i < document.forms[0].elements.length; i++) {

    if (document.forms[0].elements[i].type == 'checkbox') {

      document.forms[0].elements[i].checked = true;
    }
  }
}

// Javascript enhancements and accessibility information.
/////////////////////////////////////
var userInfo = '<p>\n';

var url = window.location.href;

if ((url != null) &&
    ((url.indexOf("sampler-Windows.shtml") > -1) ||
     (url.indexOf("sampler-Mac.shtml") > -1) ||
     (url.indexOf("sampler-Unix.shtml") > -1))) {

    if (popable) {

      userInfo += '<em>The lens icon comparisons will open in a pop-up window.<\/em> ';
    }
    userInfo += 'For convenience, you can <a href="#" onclick="checkAllBoxes(); return false;">check all boxes</a> to start with.\n';
}
userInfo += '<\/p>\n';

if (document.write) {

    document.write(userInfo);
}
