//====================================================================
// header.js - 'Global' JavaScript that almost every file includes.
//
// This file contains JavaScript code to support ProductCenter Web Client
//
// If you see this page in your browser, it is due to a missing entry
// in your web server's mime_types file that reads:
//                      application/x-javascript   js
//
// COPYRIGHT:	(c) Copyright, 2003 Softech, Inc.
//====================================================================

// Platform & browser defines
var unknown = -1;
var unix = 0;
var windows = 1;
var sun = 2;
var hpux = 3;
var sgi = 4;
var linux = 5;

var netscape = 0;
var msie = 1;
var netscape6 = 2;

var platform = unknown;
var browser = unknown;
var DOM = (document.getElementById)?true:false;   // ns6 etc.

// Window dimensions
var winWidth = 0;
var winHeight = 0;

// Init variables and load style sheet.
findPlatform();
findBrowser();
loadStyleSheet();

//=======================================================
// Determine the platform - if UNIX, it will have X11 in the appVersion,
// if Windows, it will have 'Win' in the string
//=======================================================
function findPlatform()
{
  // convert all characters to lowercase to simplify testing 
  var agt=navigator.userAgent.toLowerCase(); 

  var index = navigator.appVersion.indexOf( '(' );
  var platformStr = navigator.appVersion.substring(index+1, index+4);
  if (platformStr == "X11")
    platform = unix;
  else if (navigator.appVersion.indexOf('Win') != -1)
    platform = windows;

  // Determine UNIX flavor
  if (agt.indexOf("sunos") != -1)
    platform = sun;
  else if (agt.indexOf("hp-ux") != -1)
    platform = hpux;
  else if (agt.indexOf("irix") != -1)
    platform = sgi;
  else if (agt.indexOf("inux") != -1)
    platform = linux;
}

//=======================================================
// Determine the browser
//=======================================================
function findBrowser()
{
  if (navigator.appName == "Netscape") {
	if (DOM == true)
		browser = netscape6;
	else 
		browser = netscape;

  }
  else if (navigator.appName == "Microsoft Internet Explorer")
    browser = msie;
}

//=======================================================
// Load the correct style sheet for the platform and browser
//=======================================================
function loadStyleSheet()
{
  if (isUNIX())
    document.write('<LINK REL="stylesheet" HREF="/pcenterweb/stylesheets/unixstyle.css">');
  else if (browser == msie)
    document.write('<LINK REL="stylesheet" HREF="/pcenterweb/stylesheets/winIEstyle.css">');
  else
    document.write('<LINK REL="stylesheet" HREF="/pcenterweb/stylesheets/winNNstyle.css">');
}

function isMSIE()
{
  return (browser == msie);
}

function isNetscape()
{
  return (browser == netscape);
}

function isNetscape6()
{
  return (browser == netscape6);
}


function isDOM()
{
 return DOM;
}


function isUNIX()
{
  if ((platform == unix) || (platform == hpux) || (platform == sun)
    || (platform == sgi) || (platform == linux))
    return true;
  return false;
}

function isHPUX()
{
  return (platform == hpux);
}

function isSun()
{
  return (platform == sun);
}

function isSGI()
{
  return (platform == sgi);
}

function isLinux()
{
  return (platform == linux);
}

function isWindows()
{
  return (platform == windows);
}

//=========================================================
// Return the size of the input field for date attributes
//=========================================================
function getDateSize()
{
  var dateSize = 12;
  if (isHPUX())
    dateSize = 8;
  else if (isSGI())
    dateSize = 12;
  else if (isSun())
    dateSize = 13;
  else if (isWindows())
  {
    if (isNetscape())
      dateSize = 7;
    else if (isNetscape6())
      dateSize = 12;
    else if (isMSIE())
      dateSize = 8;
  }

  return dateSize;
}
 
//=========================================================
// Calculate window dimensions - browser-specific
//=========================================================
function calcWinDimensions()
{
  if (browser == netscape)
  {
    winWidth = window.innerWidth-16;
    winHeight = window.innerHeight+4;
  }
  else if (browser == msie)
  {
    winWidth = document.body.offsetWidth-20;
    winHeight = document.body.offsetHeight
  }
  else if (browser == netscape6)
  {
    winWidth = window.innerWidth-16;
    winHeight = window.innerHeight+4;
  }
}

