/*
 From now Globals should start with a Capitol letter, local vars with function
should always be lower case
11-11-01 I started with the picture scaling varbs newWidth now NewWidth, etc
Also added new method to DebugConsole
From now on turn debuging on in the javascript files
*/

// the system screen.width and screen.height
var sysWidth;
var sysHeight;

// the users cookie settings
var usrWidth;
var usrHeight;
var usrFrameRate;
var usersCookie;

var routinesIncluded = true;

// browser magic numbers
var WidthDecorationSize = 20;
var heightDecorationSize = 30;
var WindowFrameDecoration = 25;
var LocationDecoration = 25;
var StatusDecoration   = 25;
var htmlDecorationSize = 100;   // The caption area and blank space
var IeHeightOffset = 20;
var NnHeightOffset = 20;
var NnWidthOffset  = 10;
var TaskBarOffset  = 20;
var ScrollBarSize  = 30;

// globals used by slide shows and web presentation
var PicWidth, PicHeight,NewWidth, NewHeight;

var fontSize = new Array(10,12,14,16, 18);

function getUsrSettings() {

// grab the users screen width & height and use everywhere ALWAYS AFTER BODY!!
// test for cookie settings before using the System settings
  sysWidth = screen.width;
  sysHeight = screen.height;

  usersCookie = new Cookie(document, "DahNordlie", 1);
  if (! usersCookie.load() ) {
     usrWidth  = sysWidth;
     usrHeight = sysHeight;
     usrFrameRate = 15;
  }
  else {
     usrWidth     = 640; // usersCookie.usrWidth;
     usrHeight    = 480; // usersCookie.usrHeight;
     usrFrameRate =   15; //usersCookie.usrFrameRate;
  }
}


function popupMain(w)
{
// test to see if we are in the dahMain window if not pop it up 
// it is still not working correctly
if ( w.target !="dahMain") {
    var winId =
    window.open("index.htm", "dahMain", "width=800,height=560,scrollbars=yes,resizable=yes", true);
    winId.moveTo(0,0);
   }
}


// used for DHTML named window hyperlinks
function launch(page2Load, winName, winFeatures) {
  open(page2Load, winName, winFeatures);
}

function launchAt(page2Load, winName, winFeatures, locX, locY) {

  var winId = open(page2Load, winName, winFeatures);
  winId.moveTo(locX, locY);
}


/*
   It appears for some reason javascript will not support using the hex
   color string values for setting the background colors.  It does support
   the named colors.  I wonder why?  USE named colors to dynamicaly set
   the background colors
*/
function setBgColor(winDocument, aColor) {
  winDocument.bgColor = aColor;

}

function escapeScript(theDocument){
  theDocument.write("<");
    theDocument.write("/");
  theDocument.write("SCRIPT");
  theDocument.writeln(">");
}



/*
  always run this AFTER THE BODY TAG or else... and of course AFTER 
  instantiating its();, because we use that here.. think about updateing
  ua.js to use some of Apples stuff if Apple truly reports correct
  versions of IE 5 as 5 and not 4.. Their code is suspect
*/
function env () {

  this.documentWidth = 0;
  this.documentHeight = 0;
  this.supported = true;
  this.platform ="Unknown ";
  this.browser ="Unknown ";
  this.colorDepth=0;
  this.os = "Unknown ";
  this.client = "Unknown ";

  // Internet Explorer
  this.its = new its();

  if ( this.its.ie == true) {
    this.browser = "Internet Explorer "; 
      this.browser = this.browser + this.its.major + "." + this.its.minor 
	+ " browser";

    if (this.its.major > 3 ) { // we support IE 4 and above
 
       this.documentWidth  = document.body.clientWidth;
       this.documentHeight = document.body.clientHeight;
       this.colorDepth = screen.colorDepth;
    }
    else {
       this.supported = false;
    }

  } 
  else if (this.its.nn == true){
      this.browser = "Netscape Navigator ";
      this.browser = this.browser + this.its.major + "." + this.its.minor 
	+ " browser";

    if ( this.its.major > 3 ) {

      this.documentWidth = self.innerWidth;
      this.documentHeight = self.innerHeight;
      this.colorDepth = screen.colorDepth
    }
    else {
       this.supported = false;
    }
  } 
  else {
     this.browser = this.browser + this.its.major + "." + this.its.minor 
	+ " browser";

    if (_version > 1.1 ) {
      this.colorDepth = screen.colorDepth
    } else {
        this.supported = false;
    }
  }
  // do the operating system check
  if ( this.its.winxp ){
	this.platform = "Windows XP ";
	this.os ="winxp";
  }
  else if ( this.its.winnt ) {
	this.platform = "Windows NT ";
	this.os ="winnt";
  }
  else if ( this.its.win98 )  {
	this.platform = "Windows 98 ";
	this.os = "win98";
  }
  else if ( this.its.win95 )  {
	this.platform = "Windows 95 ";
	this.os = "win95";
  }
  else if ( this.its.win98 )  {
	this.platform = "Windows 98 ";
	this.os = "win98";
  }
  else if ( this.its.win16 )  {
	this.platform = "Windows 3.0";
	this.os = "win16";
  }
  else if ( this.its.win31 )  {
	this.platform = "Windows 3.1 ";
	this.os = "win31";
  }
  else if ( this.its.os2 )  {
	this.platform = "IBM OS/2 ";
	this.os = "os2";
  }
  else if ( this.its.sunos )  {
	this.platform = "Sun OS ";
	this.os = "sunos";
  }
  else if ( this.its.hpux )  {
	this.platform = "HP UX ";
	this.os = "hpux";
  }
  else if ( this.its.linux )  {
	this.platform = "linux ";
	this.os = "linux";
  }
  else if ( this.its.freebsd )  {
	this.platform = "Free BSD ";
	this.os = "freebsd";
  }
  else if ( this.its.bsd )  {
	this.platform = "BSD ";
	this.os = "bsd";
  }
  else if ( this.its.unix )  {
	this.platform = "X11 running on Unix ";
	this.os = "unix";
  }
  else if ( this.its.mac )  {
	this.platform = "Macintosh ";
	this.os = "mac";
  }
  else if ( this.its.mac68k )  {
	this.platform = "Macintosh 68000 ";
	this.os = "mac68k";
  }
  else if ( this.its.macppc )  {
	this.platform = "Macintosh Power PC ";
	this.os = "macppc";
  }

// Now for the browsers
 
  if ( this.its.nn ) {
	this.browser = "Netscape Navigator ";
	this.client = "nn";
  }
  else if ( this.its.opera ) {
	this.browser = "Opera ";
	this.client = "opera";
  }
  else if ( this.its.mozilla ) {
	this.browser = "Mozilla ";
	this.client = "mozilla";
  }
  else if ( this.its.webtv ) {
	this.browser = "Web TV ";
	this.client = "webtv";
  }
  else if ( this.its.ie ) {
	this.browser = "Internet Explorer ";
	this.client = "ie";
  }
  else if ( this.its.aol ) {
	this.browser = "America Online ";
	this.client = "aol";
  }
 
}


/*
   figure out whats a good font size to user based off of the usr settings
   800 x 600, 1024 x 768, 1280 x 1024, 1600, 1200
   we always use point sizes for fonts, not pixels
*/


function bestFontSize( width, height){

}



/*  
   My first JavaScript object created 11-10-01 A debug console that
   has writeln(), write().  You can your debug in the code and turn it off
   by setting DEBUG = false,  true turns it on.
   11-11-01 adding a colsole clear method.. 
   
   DAH bug: 11-11-01 I don't want to compile Javascript DBUG code into
   my Java programs, but I would like to call a javascript method
   that turns debuging on or turns it off. when DBUG is false my
   debug calls should not occur.  What I get is the functions are not
   defined....why is this?
   You can't call document methods until the BODY has been created.
   
*/
var DebugParent;  // the window Id of the parent who is using DebugConsole

function createDebug(debugWindId){

   DBUG = false;
   debug = new DebugConsole(debugWinId);
}

function DebugConsole(debugWinId) {
DebugParent = debugWinId;

  if ( DebugParent.DBUG ) {

    this.msg ="";
    this.debugWindow = 0;
    this.debugWindow = window.open("","debugWin",",scrollbars,width=400,height=400,resizable");

    this.debugWindow.document.writeln('<HTML><HEAD><TITLE>DAH Debug Console</TITLE><BODY TEXT="#000000">');
  }
  this.write   =  _DebugConsole_write;
  this.writeln =  _DebugConsole_writeln;
  this.clear   = _DebugConsole_clear;


}

function _DebugConsole_clear() {

  if (DebugParent.DBUG)  {

     this.debugWindow.document.close();
     this.debugWindow.document.open();
  }
}

function _DebugConsole_write(msg) {

  if (DebugParent.DBUG) 
  {
    this.msg = msg;
    this.debugWindow.document.write(this.msg);
  }
}


function _DebugConsole_writeln(msg) {

  if (DebugParent.DBUG) 
  {

     this.msg = msg;
    this.debugWindow.document.writeln(this.msg + '<br>');

  }
}
// load the proper style sheet
function writeHomeCSS(stylePath) {
var cssFullname;

if (navigator.family == 'ie4') {
    if (navigator.version >= 6) {

         cssFullname = stylePath + "/" + "homeIE.css";

document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         
    }
    else if (navigator.version >= 5.5) {
         cssFullname = stylePath + "/" + "homeIE.css";
document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         
    }
    else if (navigator.version >= 5) { // IE 5.x
         cssFullname = stylePath + "/" + "homeIE.css";

document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         
    }
    else {

         cssFullname = stylePath + "/" + "homeIE.css";
document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         
   }
}
else if (navigator.family == 'nn4') {

         cssFullname = stylePath + "/" + "homeNN.css";
document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         
}
else {

         cssFullname = stylePath + "/" + "home.css";
document.writeln("<link REL='stylesheet' HREF='" + cssFullname + "' TYPE='text/css'>");         

}


}


// The constructor function: creates a cookie object for the specified
// document, with a specified name and optional attributes.
// Arguments:
//   document: The Document object that the cookie is stored for. Required.
//   name:     A string that specifies a name for the cookie. Required.
//   hours:    An optional number that specifies the number of hours from now
//             that the cookie should expire.
//   path:     An optional string that specifies the cookie path attribute.
//   domain:   An optional string that specifies the cookie domain attribute.
//   secure:   An optional Boolean value that, if true, requests a secure cookie.
//
function Cookie(document, name, hours, path, domain, secure)
{
    // All the predefined properties of this object begin with '$'
    // to distinguish them from other properties which are the values to
    // be stored in the cookie.
    this.$document = document;
    this.$name = name;
    if (hours)
        this.$expiration = new Date((new Date()).getTime() + hours*3600000);
    else this.$expiration = null;
    if (path) this.$path = path; else this.$path = null;
    if (domain) this.$domain = domain; else this.$domain = null;
    if (secure) this.$secure = true; else this.$secure = false;
}

// This function is the store() method of the Cookie object.
function _Cookie_store()
{
    // First, loop through the properties of the Cookie object and
    // put together the value of the cookie. Since cookies use the
    // equals sign and semicolons as separators, we'll use colons
    // and ampersands for the individual state variables we store 
    // within a single cookie value. Note that we escape the value
    // of each state variable, in case it contains punctuation or other
    // illegal characters.
    var cookieval = "";
    for(var prop in this) {
        // Ignore properties with names that begin with '$' and also methods.
        if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function')) 
            continue;
        if (cookieval != "") cookieval += '&';
        cookieval += prop + ':' + escape(this[prop]);
    }

    // Now that we have the value of the cookie, put together the 
    // complete cookie string, which includes the name and the various
    // attributes specified when the Cookie object was created.
    var cookie = this.$name + '=' + cookieval;
    if (this.$expiration)
        cookie += '; expires=' + this.$expiration.toGMTString();
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    if (this.$secure) cookie += '; secure';

    // Now store the cookie by setting the magic Document.cookie property.
    this.$document.cookie = cookie;
}
// This function is the load() method of the Cookie object.
function _Cookie_load()
{
    // First, get a list of all cookies that pertain to this document.
    // We do this by reading the magic Document.cookie property.
    var allcookies = this.$document.cookie;
    if (allcookies == "") return false;

    // Now extract just the named cookie from that list.
    var start = allcookies.indexOf(this.$name + '=');
    if (start == -1) return false;   // Cookie not defined for this page.
    start += this.$name.length + 1;  // Skip name and equals sign.
    var end = allcookies.indexOf(';', start);
    if (end == -1) end = allcookies.length;
    var cookieval = allcookies.substring(start, end);

    // Now that we've extracted the value of the named cookie, we've
    // got to break that value down into individual state variable 
    // names and values. The name/value pairs are separated from each
    // other by ampersands, and the individual names and values are
    // separated from each other by colons. We use the split method
    // to parse everything.
    var a = cookieval.split('&');    // Break it into array of name/value pairs.
    for(var i=0; i < a.length; i++)  // Break each pair into an array.
        a[i] = a[i].split(':');

    // Now that we've parsed the cookie value, set all the names and values
    // of the state variables in this Cookie object. Note that we unescape()
    // the property value, because we called escape() when we stored it.
    for(var i = 0; i < a.length; i++) {
        this[a[i][0]] = unescape(a[i][1]);
    }

    // We're done, so return the success code.
    return true;
}

// This function is the remove() method of the Cookie object.
function _Cookie_remove()
{
    var cookie;
    cookie = this.$name + '=';
    if (this.$path) cookie += '; path=' + this.$path;
    if (this.$domain) cookie += '; domain=' + this.$domain;
    cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

    this.$document.cookie = cookie;
}

/*
 Create a dummy Cookie object, so we can use the prototype object 
	to make the functions above into methods.
*/
new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;




// Apples routine for telling browser implementation
function its() {
	var n = navigator;
	// string comparisons are much easier if we lowercase everything now.
	// to make indexOf() tests more compact/readable, we prepend a space 
	// to the userAgent string (to get around '-1' indexOf() comparison)
	var ua = ' ' + n.userAgent.toLowerCase();
	var pl = n.platform.toLowerCase(); // not supported in NS3.0
	var an = n.appName.toLowerCase();

	// browser version
	this.version = n.appVersion;
	
    this.nn = ua.indexOf('mozilla') > 0;

	// 'compatible' versions of mozilla aren't navigator
	if(ua.indexOf('compatible') > 0) {
		this.nn = false;
	}
        else {
	  this.mozilla = true;
        }

	this.opera = ua.indexOf('opera') > 0;
	this.webtv = ua.indexOf('webtv') > 0;
	this.ie = ua.indexOf('msie') > 0;
	this.aol = ua.indexOf('aol') > 0;
	
	this.major = parseInt( this.version );
	this.minor = parseFloat( this.version );
	
	// platform
	this.mac = ua.indexOf('mac') > 0;
	this.mac68k = (ua.indexOf('68k') > 0 || ua.indexOf('68000') > 0);
	this.macppc = (ua.indexOf('ppc') > 0 || ua.indexOf('powerpc') > 0);

	this.win = ua.indexOf('win') > 0;
	this.win16 = (ua.indexOf('16') > 0 && ua.indexOf('win') > 0);
	this.win31 = this.win16;
	this.win95 = (ua.indexOf('95') > 0 && ua.indexOf('win') > 0);
	this.win98 = (ua.indexOf('98') > 0 && ua.indexOf('win') > 0);
	this.winnt = (ua.indexOf('nt') > 0 && ua.indexOf('win') > 0);
	this.winxp = (ua.indexOf('xp') > 0 && ua.indexOf('win') > 0);

	this.os2 = ua.indexOf('os/2') > 0;

	this.sun = ua.indexOf('sunos') > 0;
	this.irix = ua.indexOf('irix') > 0;
	this.hpux = ua.indexOf('hpux') > 0;
	this.aix = ua.indexOf('aix') > 0;
	this.dec = (ua.indexOf('dec') > 0 || ua.indexOf('alpha') > 0 || ua.indexOf('osf1') > 0 || ua.indexOf('ultrix') > 0);
	this.sco = (ua.indexOf('sco') > 0 || ua.indexOf('unix_sv') > 0);
	this.vms = (ua.indexOf('vax') > 0 || ua.indexOf('openvms') > 0);
	this.linux = ua.indexOf('linux') > 0;
	this.sinix = ua.indexOf('sinix') > 0;
	this.reliant = ua.indexOf('reliantunix') > 0;
	this.freebsd = ua.indexOf('freebsd') > 0;
	this.openbsd = ua.indexOf('openbsd') > 0;
	this.netbsd = ua.indexOf('netbsd') > 0;
	this.bsd = ua.indexOf('bsd') > 0;
	this.unixware = ua.indexOf('unix_system_v') > 0;
	this.mpras = ua.indexOf('ncr') > 0;

	this.unix = ua.indexOf("x11") > 0;

	// workarounds
	// - IE5/Mac reports itself as version 4.0
	if(this.ie && this.mac) {
		if(ua.indexOf("msie 5")) {
			this.major = 5;
			var actual_index = ua.indexOf("msie 5");
			var actual_major = ua.substring(actual_index + 5, actual_index + 8);
			this.minor = parseFloat(actual_major);
		}
	}

	return this;
}


// from Netscape developer site
// ua.js - Detect Browser
// Requires JavaScript 1.1

// work around bug in xpcdom Mozilla 0.9.1
window.saveNavigator = window.navigator;

// Handy functions
function noop() {}
function noerror() { return true; }

function defaultOnError(msg, url, line)
{
  // customize this for your site
  if (top.location.href.indexOf('/evangelism/lib/js/errors/') == -1)
    top.location = '/evangelism/lib/js/errors/index.html?msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line);
}

// Display Error page... 
// XXX: more work to be done here
//
function reportError(message)
{
  // customize this for your site
  if (top.location.href.indexOf('/evangelism/lib/js/errors/') == -1)
    top.location = '/evangelism/lib/js/errors/index.html?msg=' + escape(message);
}

function pageRequires(cond, msg, redirectTo)
{
  if (!cond)
  {
    msg = 'This page requires ' + msg;
    top.location = redirectTo + '?msg=' + escape(msg);
  }
  // return cond so can use in <A> onclick handlers to exclude browsers
  // from pages they do not support.
  return cond;
}

function detectBrowser()
{
  var oldOnError = window.onerror;
  var element = null;
  
  window.onerror = defaultOnError;

  navigator.OS    = '';
  navigator.version  = 0;
  navigator.org    = '';
  navigator.family  = '';

  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';
  }

  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
      navigator.family = 'ie4'
  }
  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);
  }

  navigator.DOMCORE1  = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined');
  navigator.DOMCORE2  = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined' && typeof(document.createElementNS) != 'undefined');
  navigator.DOMHTML  = (navigator.DOMCORE1 && typeof(document.getElementById) != 'undefined');
  navigator.DOMCSS1  = ( (navigator.family == 'gecko') || (navigator.family == 'ie4') );

  navigator.DOMCSS2   = false;
  if (navigator.DOMCORE1)
  {
    element = document.createElement('p');
    navigator.DOMCSS2 = (typeof(element.style) == 'object');
  }

  navigator.DOMEVENTS  = (typeof(document.createEvent) != 'undefined');

  window.onerror = oldOnError;
}

detectBrowser();

/*
	scalingFactor() and scalingOffset() are used by the slide show
        and the web site single Picture javascript pages.. ex. DSCN????.htm
*/

// For scaling Pictures on the single large Pic pages

function scalingFactor(actualSize, preferedSize){
 var actualDummy = 4545.0897876;
 var preferedDummy = 3435.90
actualDummy = 1.0 * actualSize;
preferedDummy = 1.0 * preferedSize;

 var sf = (preferedDummy) / ( actualDummy);
    return sf;
}

// For scaling Pictures on the single large Pic pages

function sugestedSize(browserDim, titleNavSize) {
  var maxDim = browserDim - titleNavSize;
 return maxDim;
}

     /*
	Since we are now dealing with document sizes, there is the potential
        the users browser size could be portrait or landscape.  
        This has to be taken into account with both portrain and landscape
	pictures

     */

function scalePicture(extraHTML, documentWidth, documentHeight){

/* What if the picture is small , we shouldn't bother scaling in those
   cases, how do we detect that ?
*/


   var dummyWidth = 3434.234;
   var dummyHeight = 343.9786;
   var goodSize, difference, goodHeight, goodWidth;

   dummyWidth = 1.0 * PicWidth;
   dummyHeight = 1.0 * PicHeight;
   

   /* 
	we may be running inside the dahPopup or dahSlides windows.
	We know when we are running in dahslides because we created the
	slideControl window which creates the slide window.  We don't
        know if we are running everything from the dahPopup.., unless we
	ask the browser.
   */
   if (window.name == "dahPopup" ) {
	extraOffset += 200; // a test value
   }
/*   debug.clear();
   debug.writeln("<br>****** inside scalePicture *********");
   debug.writeln("documentWidth: " + documentWidth + " documentHeight: "
                 + documentHeight);
   debug.writeln("PicWidth: " + PicWidth + " PicHeight: " + PicHeight);
*/
   goodHeight = documentHeight - extraHTML;
   goodWidth  = documentWidth - WidthDecorationSize;
 
/*  debug.writeln("goodWidth: " + goodWidth + " goodHeight: " 
                       + goodHeight);
*/
   if (PicWidth >= PicHeight) { // constrain the width
//        debug.writeln("@ Picture is Landscape @");

     if (documentWidth >= documentHeight) {
        // case where picture is landscape and browser is landscape
//	debug.writeln("# Browser is is Landscape  #");


        if ( PicHeight >= goodHeight ) {
//          debug.writeln("Using Height to determine the scaling factor");



             // does the new height fit the document height?
            
               sf = scalingFactor(PicHeight, goodHeight);

             
             NewWidth  = Math.floor(sf * dummyWidth);
	     if (NewWidth > documentWidth ) { // change to width
//                debug.writeln("NewWidth  doesn't fit, recalc SF");
                 sf = scalingFactor(PicWidth, goodWidth);
	     }
             NewHeight = Math.floor(sf * dummyHeight);
             NewWidth  = Math.floor(sf * dummyWidth);
        }
        else {
	   //  no scaling needed  
//	debug.writeln("NO SCALING USED"); 
	     NewHeight = dummyHeight;
	     NewWidth  = dummyWidth;
        }
     }
     else {
        /* case where picture is landscape and browser is portrait */
//        debug.writeln("# Browser is is Portrait  #");
	/*
           the browser is portrait & picture is landscape.  browser width
           is now the constraining factor 
        */
         if (PicWidth >= goodWidth ) {
//          debug.writeln("Using Width to determine the scaling factor");
            sf = scalingFactor(PicWidth, goodWidth);

            NewHeight = Math.floor(sf * dummyHeight);
            NewWidth  = Math.floor(sf * dummyWidth);
         }
	 else {
	   //  no scaling needed  
//	debug.writeln("NO SCALING USED"); 
	     NewHeight = dummyHeight;
	     NewWidth  = dummyWidth;
         }
      }
   }
   else {  // case where the picture is Portrait
//       debug.writeln("@ Picture is Portrait @");

     if (documentWidth >= documentHeight) {
//	debug.writeln("# Browser is is Landscape  #");

        if (PicHeight >= goodHeight) {
//          debug.writeln("Using Height to determine the scaling factor");
           sf = scalingFactor(PicHeight, goodHeight);
            NewHeight = Math.floor(sf * dummyHeight);
            NewWidth  = Math.floor(sf * dummyWidth);
        }
        else {
	   //  no scaling needed  
//	debug.writeln("NO SCALING USED"); 
	     NewHeight = dummyHeight;
	     NewWidth  = dummyWidth;
        }
     }    	
     else { // Picture is portrait browser is portrait
//       debug.writeln("# Browser is is Portrait  #");

       if ( PicWidth >= goodWidth ) {
//          debug.writeln("Using Height to determine the scaling factor");
	   sf = scalingFactor(PicHeight, goodHeight)
            NewHeight = Math.floor(sf * dummyHeight);
            NewWidth  = Math.floor(sf * dummyWidth);
       }
       else {
//	debug.writeln("NO SCALING USED"); 
         NewWidth = PicWidth;  // don't scale its not needed
	 NewHeight = PicHeight;
       }
    }
           
  }
/*     debug.writeln("Exit NewWidth " + NewWidth + " NewHeight " 
	+ NewHeight + " SF " + sf);
*/
}

