// ***************************************************************************
// ***                            Browser Detection                        ***
// ***************************************************************************
// Dected the browser name, version, organisation and other
// usefull parameters.
//
// The output result can be found in the "navigator" variable.
// Available values:
//  - OS          String, the OS name.
//  - version     Integer, the browser version (sub versions ignored).
//  - org         String, the broswer maker.
//  - family      String, the broswer family.
//  - DOMCORE1    Boolean, supports DOM level 1.
//  - DOMCORE2    Boolean, supports DOM level 2.
//  - DOMHTML     Boolean, supports HTML as DOM definition.
//  - DOMCSS1     Boolean, supports CSS level 1.
//  - DOMCSS2     Boolean, supports CSS level 2.
//  - DOMEVENTS   Boolean, supports DOM events.
function detectBrowser ()
{
   var element= null;
   navigator.OS= '';
   navigator.version= 0;
   navigator.org= '';
   navigator.family= '';

   // Plateform detection...
   var platform;
   if (typeof(window.navigator.platform) != 'undefined')
   {
      platform = window.navigator.platform.toLowerCase();
      if (platform.indexOf('win') != -1)
         navigator.OS = 'win';
      else if (platform.indexOf('mac') != -1)
         navigator.OS = 'mac';
      else if (platform.indexOf('unix') != -1 || platform.indexOf('linux') != -1 || platform.indexOf('sun') != -1)
         navigator.OS = 'nix';
   }

   // Browser family, organization and version...
   var i = 0;
   var ua = window.navigator.userAgent.toLowerCase();
   
   if (ua.indexOf('opera') != -1)
   {
      i = ua.indexOf('opera');
      navigator.family= 'opera';
      navigator.org= 'opera';
      navigator.version= parseFloat('0' + ua.substr(i + 6), 10);
   }
   else if ((i = ua.indexOf('msie')) != -1)
   {
      navigator.org= 'microsoft';
      navigator.version= parseFloat('0' + ua.substr(i + 5), 10);
      
      if (navigator.version < 4)
         navigator.family= 'ie3';
      else if (navigator.version < 5)
         navigator.family= 'ie4';
      else if (navigator.version < 6)
         navigator.family= 'ie5';
      else
         navigator.family= 'ie6'
   }
   else if (typeof(window.controllers) != 'undefined' && typeof(window.locationbar) != 'undefined')
   {
      i = ua.lastIndexOf('/')
      navigator.version= parseFloat('0' + ua.substr(i + 1), 10);
      navigator.family= 'gecko';

      if (ua.indexOf('netscape') != -1)
         navigator.org= 'netscape';
      else if (ua.indexOf('compuserve') != -1)
         navigator.org= 'compuserve';
      else
         navigator.org= 'mozilla';
   }
   else if ((ua.indexOf('mozilla') !=-1) && (ua.indexOf('spoofer')==-1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1)&& (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1))
   {
       var is_major= parseFloat(navigator.appVersion);
    
      if (is_major < 4)
         navigator.version= is_major;
      else
      {
         i= ua.lastIndexOf('/')
         navigator.version= parseFloat('0' + ua.substr(i + 1), 10);
      }
      navigator.org= 'netscape';
      navigator.family= 'nn' + parseInt(navigator.appVersion);
   }
   else if ((i = ua.indexOf('aol')) != -1 )
   {
      // aol
      navigator.family   = 'aol';
      navigator.org      = 'aol';
      navigator.version   = parseFloat('0' + ua.substr(i + 4), 10);
   }

   // DOM and CSS support...
   navigator.DOMCORE1= (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
   navigator.DOMHTML= (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
   navigator.DOMCORE2= (navigator.DOMHTML && typeof(document.createElementNS) != 'undefined');
   navigator.DOMCSS1= ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );

   navigator.DOMCSS2  = false;
   if (navigator.DOMCORE1)
   {
      element= document.createElement('p');
      if (typeof(element) != 'undefined')
        navigator.DOMCSS2 = (typeof(element.style) == 'object');
   }

   navigator.DOMEVENTS   = (typeof(document.createEvent) != 'undefined');
} // END detectBrowser ()


// ***************************************************************************
// ***                            Frame Handlers                           ***
// ***************************************************************************
// Pop the current frame content to the top of the browser.
function popFrame ()
{
   popTargetFrame (self);
} // END popFrame ()

// Pop the current frame content to the top of the browser.
function popTargetFrame (target)
{
  if(target != top)
    replaceURL(target.location.href.toString());
} // END popTargetFrame ()

// Replace the current location with the new URL.
function replaceURL (url)
{
  top.location.replace(url.toString());
}  // END replaceURL ()


// ***************************************************************************
// ***                             Goodies Functions                       ***
// ***************************************************************************
// Open a new remote window.
//
// Parameters:
// - newURL        The url of the new window content.
// - newName       The name of the window.
// - newFeatures   The window features.
// - orgName       The remote opener name.
function launch ( newURL, newName, newFeatures, orgName ) 
{
  var remote = originalOpenFunction(newURL, newName, newFeatures);
  if (remote.opener == null)
    remote.opener = window;
  remote.opener.name = orgName;
  return remote;
} // END launch ()

// Open a popup with a given page loaded.
//
// Parameter:
// - pageUrl    The page to view.
function showPage ( pageUrl )
{
  // Set the vars
  var newwin= "pcRemote";
  //var features= "height=550,width=750";
  var features= "alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=0,z-lock=0";
  var thiswin= "APage";

  // Launch it!
  launch (pageUrl, newwin, features, thiswin);
} // END showPage ()

function sendMel (name, server, attributes)
{
  // Make URL
  var mailURL= "mailto:" + name + "@" + server;
  if (attributes)
    mailURL+= "?" + attributes;

  // Send
  replaceURL(mailURL);
} // END sendMel ()


// ***************************************************************************
// ***                             Validator Service                       ***
// ***************************************************************************
// Request the W3C HTML validator to check the target.
//
// Parameter:
// - target     The page to test.
function HTMLValidator (target)
{
 showPage ("http://validator.w3.org/check?uri=" + target);
} // END HTMLValidator ()

// Request the W3C CSS validator to check the target.
//
// Parameter:
// - target     The page to test.
function CSSValidator (target)
{
 showPage ("http://jigsaw.w3.org/css-validator/validator?uri=" + target);
} // END CSSValidator ()

