/*
//file: geometryManager.js

  NUFOSMATIC
  National UFO Sighting Mapping, Analysis, and Tracking Integration Cybersite
  Copyright (C) 2004-2009 NUFOSMATIC

  geometryManager.js - managing geometry for applets

  $Date: 2012/01/21 21:30:18 $
  $Revision: 1.43 $

*/
/*
  requires: releaseManager.js
  var releaseInfoHtml
*/

var w_source = 0 ;
var w_width = window.innerWidth ;
var w_height = window.innerHeight ;
var w_aspect_ratio = w_width/w_height ;
var a_aspect_ratio = 1.6 ; // CONUS map is 1.5, give space for header/footer
var a_width = 750 ;
var a_height = 500 ;
var a_modifier = .9 ;
var deployHost0 = "http://www.nufosmatic.com/" ;
var deployHost1 = "http://members.cox.net/" ;
var developRecordPath = "" ;
var deployRecordPath = "http://www.nufosmatic.com/nufosmatic/" ;
var recordScript = "../cgi-bin/nufosmatic/record.php" ;
var url = window.location.href ;
var url_length = url.length ;
var referrer = document.referrer ;
var verbose = 0 ;

/*
  if we can't get the window inner width
  estimate it from pixel width we assigned
  to header and footer frames

  we're trying to get to 800x600 here
  .8 works better for IExplorer
  .9 works better for Netscape
*/
if(typeof(w_width)=="undefined")
  {
    w_source = 1 ;
    a_modifier = .8 ; // IExplorer
    w_width = (window.screen.width-100-20) ;
    w_height = (window.screen.height-100-20) ;
    w_aspect_ratio = w_width/w_height ;
  }

/*
  compute common applet geometry
*/
if(w_aspect_ratio>a_aspect_ratio)
  {
    a_height = Math.floor(w_height*a_modifier) ;
    a_width = Math.floor(a_height*a_aspect_ratio) ;
  }
else
  {
    a_width = Math.floor(w_width*a_modifier) ;
    a_height = Math.floor(a_width/a_aspect_ratio) ;
  }	

function referrerPathVerify()
  {
    var currentURL = window.location.href ;
    /*
      alert("w_source=" + w_source
      + " document.URL=" + document.URL
      + " currentURL=" + currentURL 
      + " url=" + url 
      + " url_length=" + url_length 
      + " referrer=" + referrer) ;
    */
    var referrerURL = window.document.referrer ;
    /*
      alert("referrerURL=" + referrerURL) ;
    */
    // blank referrer is ok (openned from browser)
    if((referrerURL==null) || (referrerURL==""))
      return ;

    // referrer is in the same path as this html
    // NOTE: netscape 4.x looks to populate referrer after replace()
    // so we gotta handle that
    var indexNufosmatic = currentURL.lastIndexOf("html/") ;
    var basePath = currentURL.substring(0, indexNufosmatic) ;

    // match referrer at base of current path	
    if(referrerURL.indexOf(basePath)==0)
      return ;

    // force page display to flow through index.html
    indexNufosmatic = currentURL.lastIndexOf("html/") ;
    basePath = currentURL.substring(0, indexNufosmatic) ;    	

    if(verbose) alert("Replace link with URL=" + basePath + "index.html") ;
    window.location.replace(basePath + "index.html") ;
  }

function reframeWindow()
  {
    if(parent==window)
      {
        window.location.replace("frame.html") ;
      } 
  }

function recordAccess(parameter)
  {
    // document.write('<img src="')
    document.write('<script language="JavaScript" src="') ;
    
    // if this is deployHost, use deployRecordPath
    if((url.indexOf(deployHost0)==0)
       || (url.indexOf(deployHost1)==0))
      {
	// alert("deployed: " + deployRecordPath) ;
	document.write(deployRecordPath) ;
      }
    else // non-deployed developmental site
      {
	// alert("non-deployed: " + developRecordPath) ;
	document.write(developRecordPath) ;
      }

    // alert("recordScript: " + recordScript) ;
    document.write(recordScript) ;

    // alert("parameter: " + parameter) ;
    if(parameter!=null)
      {
        document.write('?' + parameter) ;
      }

    // document.write('" height=0 width=0 border=0 alt="">') ;
    document.write('"></script>') ;
  }	

function copyrightTag()
{
  document.write('<center>') ;
  document.write('<hr WIDTH="100%">') ;
  document.write('Copyright (C) 2004-2012 NUFOSMATIC All Rights Reserved') ;
  document.write('<br>National Unidentified Flying Object Sighting Mapping, Analysis, and Tracking Integration Cybersite') ;
  document.write('<br><img SRC="../graphics/nufosmaticLogoNationalMap.jpg" height=200 width=300>') ;
  document.write(releaseInfoHtml) ;
  document.write('</center>') ;
  document.write('<br>For inquiries regarding this site: <a href="mailto:nufosmatic@nufosmatic.com">click here</a>') ;
}

/*
  end of geometryManager.js
*/

