//============================================================================
//
// Javascript functions used by www.skimtta.com
//    ensure_in_frameset - called upon load of every page to handle orphan pgs
//    LogData object and methods - executed at end of each page to log hits
//
// Version $Id: global.js 175 2006-09-30 23:10:33Z Snowman $
//
//============================================================================

// ---------------------------------------------------------------------------
// DOM Access 
//----------------------------------------------------------------------------

//------ Key variables relating to DOM support and browser info 
var js=1;  var is_dhtml=0;  var is_dom_id=0;  var is_dom_all=0;  
var is_dom_layers=0;
if (document.getElementById) {is_dom_id=1;  is_dhtml=1;} 
else { if (document.all) {is_dom_all=1;  is_dhtml=1;}   
  else { browserVersion = parseInt(navigator.appVersion);
  if ((navigator.appName.indexOf('Netscape') != -1) &&
      (browserVersion == 4)) {is_dom_layers=1;  is_dhtml=1;} } } 


//------ Return object reference based on browser's DOM model (set above)
function findDOM(objectID,withStyle) 
{ if (withStyle == 1) 
  { if (is_dom_id) 
    { return (document.getElementById(objectID).style); } // W3 DOM 
    else 
    { if (is_dom_all) 
      { return (document.all[objectID].style);  } // IE 4/5 "all" DOM 
      else { if (is_dom_layers) 
        { return (document.layers[objectID]); } // NN 4 "layers" DOM
  } } } 
  else 
  { if (is_dom_id) 
    { return (document.getElementById(objectID)); }
    else 
    { if (is_dom_all) 
      { return (document.all[objectID]); }
      else 
      { if (is_dom_layers) 
        { return (document.layers[objectID]); }
  } } } 
}
   
//------ Output object info, note different object top location access methods
function whoAmI(objectID) {
  //var domStyle = findDOM(objectID,1);
  var dom = findDOM(objectID,0);
  if (dom.top) 
    { alert("object.top = "+dom.top); }  // NN 4
  else if (dom.pixelTop) 
    { alert("object.pixelTop = "+dom.pixelTop); }  // IE 4/5
  else if (dom.offsetTop) 
    { alert("object.offsetTop = "+dom.offsetTop); } // IE6, NN6, O6
  else { alert("Could not get top"); }
  alert("Object ID = "+dom.id);
}


// ---------------------------------------------------------------------------
// Browser Detection (sets brwsr_* variables)
// (from http://www.xs4all.nl/~ppk/js/index.html?/~ppk/js/browsers.html)
//
// This has been verified with:
//   IE6, Opera7,
//
// :TODO: Verify this with other current browsers.
//----------------------------------------------------------------------------
var brwsr_name, brwsr_os, brwsr_vers, thestring;
var detect = navigator.userAgent.toLowerCase();

if (checkIt('konqueror'))
{
  brwsr_name = "Konqueror";
  brwsr_os = "Linux";
}
else if (checkIt('safari')) brwsr_name = "Safari"
else if (checkIt('omniweb')) brwsr_name = "OmniWeb"
else if (checkIt('opera')) brwsr_name = "Opera"
else if (checkIt('webtv')) brwsr_name = "WebTV";
else if (checkIt('icab')) brwsr_name = "iCab"
else if (checkIt('msie')) brwsr_name = "IE"
else if (!checkIt('compatible'))
{
  brwsr_name = "Navigator"
  brwsr_vers = detect.charAt(8);
}
else brwsr_name = "Unknown";

if (!brwsr_vers) brwsr_vers = detect.charAt(place + thestring.length);

if (!brwsr_os)
{
  if (checkIt('linux')) brwsr_os = "Linux";
  else if (checkIt('x11')) brwsr_os = "Unix";
  else if (checkIt('mac')) brwsr_os = "Mac"
  else if (checkIt('win')) brwsr_os = "Windows"
  else brwsr_os = "Unknown";
}

function checkIt(string)
{
  place = detect.indexOf(string) + 1;
  thestring = string;  // this is used globally after function exit!
  return place;
}

//T alert("Browser = " + brwsr_name + " with version = " + brwsr_vers + "\n" + "OS = " + brwsr_os);


// ---------------------------------------------------------------------------
// Frameset Checker - ensure_in_frameset()
//
// Our content pages should always be displayed in our frameset; with our
// logo on top and our links on the left.  And we don't want our frameset to
// be framed by another site. 
//
// To the extent allowed by security restrictions and browser support, this 
// function detects these two conditions; and then directs index.htm to reload
// the browser window with our frameset and the appropriate content page.  
//
// All content pages should invoke this function via: 
//   <body onload="ensure_in_frameset()" ...>.
//----------------------------------------------------------------------------
function ensure_in_frameset() 
{
  // skip redirecting under the following conditions:
  // --- when requested by the referrer (as in no-frames case)...
  if (document.URL.search("skipRedirect=1") >= 0)  { return; }  
  // --- if the URL starts with "file:" (this can cause infinite loop) 
  if (document.URL.search("^file:") != -1) { return; }  
  // --- if we are in NN4 & are printing (no windows or window size of 0)
  if (document.layers && (self.innerHeight === 0 && self.innerWidth === 0)) 
    { return; }  //... then skip redirect
    
  // Determine if this page is an orphan, or is in our frameset but our
  // frameset is framed by another site.  We would also like to detect if this
  // page is framed by another site by itself; but this can not be determined
  // without out accessing the top frame's internal variables; which is not
  // allowed by most modern browsers (IE v4-v6 does allow this, but shouldn't).
  if ((top == self) || (top != self.parent)) 
  {          
    // Build URL to tell index.htm to load main framset + this page 
    var pageUrl = document.URL;  
    var siteUrl = pageUrl.replace(/(^.*\/).*$/, "$1"); 
    // 
    //RB, 4/2/06:  added below 1 line to support .htm files in subdirs
    //  Extract 'http://' and hostname.  This is where index.htm lives.
    siteUrl = siteUrl.replace(/^(http:\/\/)([^:\/]+\/)(.*)?$/i, "$1$2");
    //T alert("siteUrl = " + siteUrl );
    // 
    var redirectUrl = siteUrl + 'index.htm' + '?' + pageUrl; 


    // Redirect to index.htm via 'replace' or 'assign'
    if ((document.images) 
        && !((brwsr_name == "Navigator") && (brwsr_vers) == 6)
        ) 
    {
      // if supported, use 'replace' so this page isn't stored in history
      // :TODO: this reportedly fails in Netscape 6 -- need to verify above
      // detection of NN6 works. 
      //alert( 'In ensure_in_frames(), about to redirect via' + 
      // ' "replace (should not affect history)" to:\n' + '  ' + redirectUrl);
      top.location.replace(redirectUrl); 
    }
    else 
    {
      // else relocate to our page and leave current page in history.  This
      // causes problems when the BACK button is hit, but is required in
      // old browsers and possibly to avoid Netscape 6 problems.
      //alert( 'In ensure_in_frames(), about to redirect via' + 
      // ' "assign (will affect history)" to:\n' + '  ' + redirectUrl);
      top.location = redirectUrl; 
    }
  }
}


//----------------------------------------------------------------------------
// log and redirect - setup for and invoke server-side redirect & logger
//
//    This on-click event handler is explicitely called out for 
//    external links.  It allows us to log exits and click-thoughs before
//    actually following the link.  This javascript event handler works in
//    conjunction with the '/redirect.htm' PHP page which invokes the
//    hit_logger.php file.
//
//    The <a...> tag only calls this handler.  It does not actually 
//    implement the link redirect (that is done at the end of this func).
//
//    This mechanism reportedly works on all javascript enabled browsers.
//    For info, see http://www.faqts.com/knowledge_base/view.phtml/aid/18282
//----------------------------------------------------------------------------
//Optionally?, you can save the link URL to a global var 
//var redirect_url = "";  // :TODO: should this be done in all cases?? 
//
function log_and_redirect(link_object) {
  // Get the URL of the link object
  redirect_url = link_object.href; 
  //T alert(redirect_url + "   clicked from:   " + escape(document.URL)); 
  
  // Build GET var for page to redirect to 
  // ('?' is added below)
  var redirect_url_param = 'redirect_url=' + escape(redirect_url);
  // Build GET var for page we came from (via global set in page hdr)
  var current_url_param = '&current_url=' + escape(document.URL);

  // Build additional client data GET vars for server hit log 
  var log_data = new LogData();         // Collect client data
      // NOTE:  page & referrer aren't correct in this case and are ignored
  var url_params = log_data.getUrl();   // Convert to GET vars 

  // Server-side page which will log hit and do the redirect
  var server_log_and_redirect_page = "/redirect.htm";

  // Build complete URL to server-side log and redirect page
  var server_redirect_url  =  
    server_log_and_redirect_page + '?' + redirect_url_param + 
      current_url_param + url_params;
  //T alert("server_redirect_url = " + server_redirect_url);
  
  // Request the server page - it will reply with a Redirect header
  // This impliments the actual 'Link' (the <a> tag just gets us here)
  top.location = server_redirect_url; 

  return false // prevent the anchor from changing the document (redirecting)
}


//----------------------------------------------------------------------------
// LogData object - gathers and formats client data for hit logging:
//
// MAINTENANCE NOTE:  The GET variables in rtnLogDataAsUrl() must be kept in
// synch with the SQL statements in hit_logger.php and the database structure
// of the 'hits' table and 'm_client' table.
//
// Use javascript to collect data inaccessible on the server side, such as
// client date/time, browser info, OS, screen info.  
//
// OVERALL DATA LOGGING STRATEGY (* = most critical data to log)
//   -- see www.thecounter.com for example of logging stats
//
//  Server-side - via PHP 'hit_logger.php' script on server
//      Page info 
//       ** requested page and status (only if NA from client)
//       ** referrer page  (if NA from client, indicate NA via Server)
//      Date/Time
//       ** server date/time 
//      ISP and Client
//       ** client IP 
//          ISP server host name?
//          ISP name? 
//        ? ISP domain extension?: .com, .de, etc.
//          ISP location (country...)?
//          (list of IP's/servers for search engines robots)
//
//  Client-side - via this script
//      Page info (grabbed because referrer may be self on server)
//       ** requested page and status
//       ** referrer page
//      Date/Time (grabbed mostly to get client's time zone ~= location)
//        * client time zone
//          client date/time (time_t ms; long and short date-time, gmt)
//      Platform:
//        - Basic OS: Linux, Unix, Mac, Windows; see brwsr_os
//          Hardware?: X86, ?
//          OS Platform?:  W32, PPC
//          OS:  Win 98, Win 2000, Win ME, Win NT, Win95, Win 3.1, WinXP,
//               Mac, Unknown, Linux, Unix, X11, SunOS, WebTv, OS/2, Amiga
//        - Monitor:  screen size (width x height), color depth
//      Browser info:
//       ** User Agent string:  see below for examples
//       ** Version string
//        * language: 
//        * javascript support
//        * critical flags: dhtml, dom_w3, dom_all, dom_layers
//        - Browser Name: see brwsr_name
//        - Browser Major Version Number:  see brwsr_version
//        - browser window size (width x height)
//          cookie support: ?
//
//  Examples of Browser user agent strings:
//      Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
//      Mozilla/4.0 (compatible; MSIE 4.01; Windows 98)
//      Mozilla/4.5 [en] (Win95; U) = Netscape 4.5
//      Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.20  [en]
//      Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.05  [en]"
//      Mozilla/3.0 (compatible; Opera/3.0; Windows 95/NT4)
//      Mozilla/4.5 (Macintosh; U; PPC) 
//      NCSA Mosaic/2.6b1 (X11;UNIX_SV 4.2MP R4000)  libwww/2.12 modified
//      Lynx/2.7 libwww-FM/2.14
//      Mozilla/4.5 [en] (Win95; U)
//      
// Constructor: grabs client data and stores in object
// Properties: 
//      All properties are private to this document, except that the 
//      server-script that receives the URL must know the variable names 
//      and contents.  For this purpose, see the getUrl() code below.
// Methods:
//      getUrl():    puts log data in a URL parameter string 
//      print():     prints log data to user window
//----------------------------------------------------------------------------
function LogData()
{
    //--- Construct object properties ----------------------------------------

    // Indicate this log data generated by Javascript
    this.type = '1';

    //--- Set critical info 
    this.page = escape(document.URL);             // requested page URL
    this.referrer = escape(document.referrer);    // referrer page
    this.agent = escape(navigator.userAgent);     // browser string
    this.app_vers = escape(navigator.appVersion); // browser version 

    //--- Set important info that is easily accessed
    // :TODO!: This may need adjusting to work with new Netscape's?
    this.lang = navigator.appName=="Netscape" ?    // user language
        navigator.language : navigator.userLanguage;
    var date = new Date();
    this.timezone = date.getTimezoneOffset(); // user's time zone
    this.js = js;                 // javascript support var set above 
    this.dhtml = is_dhtml;        // DHTML support var set above 
    this.dom_w3 = is_dom_id;      // W3 DOM support var set above
    this.dom_all = is_dom_all;    // IE DOM support var set above
    this.dom_layers = is_dom_layers;  // Netscape v4 DOM support var set above

    //--- Get less important info or difficult to access info
    this.brwsr_name = brwsr_name;
    this.brwsr_vers = brwsr_vers;
    this.brwsr_os = brwsr_os;
    if (typeof(screen)=="object")
    {
        this.scn_w = screen.width;       // screen size
        this.scn_h = screen.height;             
        this.scn_cd = screen.colorDepth;    // screen color depth
        this.java = navigator.javaEnabled()?1:0; // Java enabled?
    }
    this.window = WindowStats();  // get browser window ~width, ~height 
    this.title = escape(document.title);          // requested page title

    //--- Get optional info (not currently logged in Server DB)
    this.local_time_t = date.getTime();   // # milliseconds since 1/1/1970
    this.local_date = escape(date.getFullYear() +  '-' + (date.getMonth()+1) + '-' + 
        date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + 
        ':' + date.getSeconds());
    this.local_date_long = escape(date);
    this.gmt_date = escape(date.toGMTString());
    // Add cookie test?
    
    // Define object member functions and connect to private functions
    this.getUrl = rtnLogDataAsUrl;
    this.print = printLogData;
}

// private Log Data method to prepare URL string
//
// MAINTENANCE NOTE:  The GET variables below must be kept in synch with the 
// SQL statements in hit_logger.php and the database structure of the 'hits' 
// table and 'm_client' table.  ***They must also be added to 'Ensure all
// optional vars are initialized' section of hit_logger.php or to default 
// Javascript at the head of EVERY CONTENT PAGE!***
//
function rtnLogDataAsUrl()
{ 
    var logUrl = 
        '&type=' + this.type +
        '&page=' + this.page +
        '&referrer=' + this.referrer +
        '&agent=' + this.agent +
        '&app_vers=' + this.app_vers +

        '&lang=' + this.lang +
        '&timezone=' + this.timezone +
        '&js=' + this.js + 
        '&dhtml=' + this.dhtml + 
        '&dom_w3=' + this.dom_w3 + 
        '&dom_all=' + this.dom_all + 
        '&dom_layers=' + this.dom_layers + 
        
        // Below are optional var's
        '&brwsr_name=' + this.brwsr_name + 
        '&brwsr_vers=' + this.brwsr_vers + 
        '&brwsr_os=' + this.brwsr_os + 
        '&scn_w=' + this.scn_w + 
        '&scn_h=' + this.scn_h + 
        '&scn_cd=' + this.scn_cd + 
        '&java=' + this.java + 
        '&win_w=' + this.window.width + 
        '&win_h=' + this.window.height + 
        '&title=' + this.title +

        // Below are optional var's that are not currently logged by Server
        '&t_ltt=' + this.local_time_t +
        '&t_ldl=' + this.local_date_long +
        '&t_ld=' + this.local_date +
        '&t_gmt=' + this.gmt_date; 
    return logUrl;
}

// private Log Data method to print (write) to user window 
function printLogData()
{ 
    var logStr = 
        'log = ' + this.type + '<br />' +
        'page = ' + this.page + '<br />' +
        'referrer = ' + this.referrer + '<br />' +
        'agent = ' + this.agent + '<br />' +
        'app_vers=' + this.app_vers + '<br />' +

        'lang=' + this.lang + '<br />' +
        'timezone=' + this.timezone + '<br />' +
        'js=' + this.js +  '<br />' +
        'dhtml=' + this.dhtml +  '<br />' +
        'dom_w3=' + this.dom_w3 +  '<br />' +
        'dom_all=' + this.dom_all +  '<br />' +
        'dom_layers=' + this.dom_layers +  '<br />' +

        'brwsr_name=' + this.brwsr_name +  '<br />' +
        'brwsr_vers=' + this.brwsr_vers +  '<br />' +
        'brwsr_os=' + this.brwsr_os + '<br />' + 
        'scn_w=' + this.scn_w +  '<br />' +
        'scn_h=' + this.scn_h +  '<br />' +
        'scn_cd=' + this.scn_cd +  '<br />' +
        'java=' + this.java +  '<br />' +
        'win_w=' + this.window.width +  '<br />' +
        'win_h=' + this.window.height +  '<br />' +
        'title=' + this.title + '<br />' +

        't_ltt = ' + this.local_time_t + '<br />' +
        't_ldl = ' + this.local_date_long + '<br />' +
        't_ld = ' + this.local_date + '<br />' +
        't_gmt = ' + this.gmt_date + '<br />';
    document.write(logStr);
}


//----------------------------------------------------------------------------
// WindowStats object
//
// Constructor:  determines ~window size, stores in object which is returned 
//
// :TODO: Verify browser detection is working correcly.  Add detection for
//        other modern browsers.
//
// :NOTE: With a IE browser and a frames-based document, the win_width
//        and win_height are that of the frame, not the overall window.
//
//----------------------------------------------------------------------------
function WindowStats()
{

    //--------- Get and save width and height of current browser window/frame
    if ( (brwsr_name == "Navigator") && (brwsr_vers >= 4)
         || (brwsr_name == "Opera") && (brwsr_vers >= 5) )
    {
        this.width = window.outerWidth;     // verified on op6
        this.height = window.outerHeight;   // verified on op6
    }
    else if ((brwsr_name == "IE") && (brwsr_vers >= 4))
    {
        // the following were verified in IE 5.0
        this.width = document.documentElement.offsetWidth; 
        this.height = document.documentElement.offsetHeight; 

        // The following 2 are recommended but kill my IE 5.0 Javascript!
        //width = document.body.offsetWidth;    // kills IE 5.0 JS
        //height = document.body.offsetHeight;  // kills IE 5.0 JS

        //width = document.body.clientWidth;    // kills IE 5.0 JS
        //height = document.body.clientHeight;  // kills IE 5.0 JS

        //width = window.innerWidth;        // undefined in IE 5.0
        //height = window.innerHeight;      // undefined in IE 5.5
        //width = document.clientWidth;     // undefined in IE 5.0
        //height = document.clientHeight;   // undefined in IE 5.0
        //width = document.offsetWidth;     // undefined in IE 5.0
        //height = document.offsetHeight;   // undefined in IE 5.0

    }
    else
    {
        // not supported by browser
        this.width = 0;
        this.height =0; 
    }
    return this;
}


//----------------------------------------------------------------------------
// Print Window 
//----------------------------------------------------------------------------
function printWindow()
  {
    if (window.print)
    {
      window.print()
    }
}


//----------------------------------------------------------------------------
// Popup Handler
//----------------------------------------------------------------------------
function popup(url)
{
  var windowObject;
  var name = "popup";
  var width = 300;
  var height = 450;

  if (arguments.length == 3)
  {
    height = arguments[1];
    width = arguments[2];
  }
  else if (arguments.length == 4)
  {
    height = arguments[1];
    width = arguments[2];
    name = arguments[3];
  }
 if (width < 300)
  {
    width = 300;
  }
  else if (width > 600)
  {
    width = 600;
  }
  if (height > 600)
  {
    height = 600;
  }
  windowObject = window.open(url, name, "height=" + height + ",innerHeight=" + height + ",width=" + width + ",innerWidth=" + width + ",screenX=0,screenY=0,scrollbars=yes,resizable=yes");
  windowObject.focus();
}





