// javascript for whitehead institute site

/////////////////////////////////////////////////////////////////////////////////////////
//
// counter
//

// ONESTAT.COM COUNTER

// Modification of this code is not allowed and will permanently disable your account!
// Account ID: 171691
// Site URL  : http://www.wi.mit.edu
// Copyright (C) 2002,2003 OneStat.com All Rights Reserved
function OneStat_Tag()
{
    var CONTENTSECTION= "";
    var CUSTOMDATA= "";
    var osp_URL= document.URL;
    var osp_Title= document.title;

    function A(S, K)
    {
        U+="&"+S+"="+escape(K);
    //    U2+="&"+S+"="+escape(K);
    }

    var t = new Date();

    var U="http"+(document.URL.indexOf('https:')==0?'s':'')+"://stat.onestat.com/asp/stat.asp?tagver=1&sid=171691";
    //var U2="http"+(document.URL.indexOf('https:')==0?'s':'')+"://www.wi.mit.edu/scripts/hitlog.php?tagver=1&sid=171691";

    A( "tz", t.getTimezoneOffset());
    A( "ch", t.getHours());
    A( "ti", typeof(osp_Title)== "string" ? osp_Title : document.title);
    A( "url", typeof(osp_URL)== "string" ? osp_URL : document.URL);
    A( "rf", parent==self ? window.document.referrer : top.document.referrer);
    A( "js", "Yes");
    A( "ul", navigator.appName=="Netscape" ? navigator.language : navigator.userLanguage);
    if(typeof(screen)=="object")
    {
    A( "sr", screen.width+"x"+screen.height);
    A( "cd", screen.colorDepth);
    A( "jo", navigator.javaEnabled()?"Yes":"No");
    }
    A( "section", typeof(CONTENTSECTION)== "string" ? CONTENTSECTION : "");
    A( "custom", typeof(CUSTOMDATA)== "string" ? CUSTOMDATA : "");
    if( U.length>2048 && navigator.userAgent.indexOf('MSIE')>=0)
        U= U.substring( 0, 2043)+"&tu=1";
    //if( U2.length>2048 && navigator.userAgent.indexOf('MSIE')>=0)
    //    U2= U2.substring( 0, 2043)+"&tu=1";

    document.write('<a href="http://www.onestat.com/asp/login.asp?sid=171691" target=_blank><img id="ONESTAT_TAG" border="0" src="'+U+'" alt="This Site Tracked by OneStat.com"></a>');
    //document.write('<img width="1" height="1" src="'+U2+'" alt=""></a>');
}


/////////////////////////////////////////////////////////////////////////////////////////
//
// toggle caption
//
var captionOn = false;

function ShowHideCaption() {
  var divi = MM_findObj("captiondiv");
  if (divi != null) {
    if (divi.style != null) {
      divi = divi.style;
    }
    if (captionOn) {
      divi.display = "none";
      captionOn = false;
    }
    else {
      divi.display = "block";
      captionOn = true;
    }
  }
}



/////////////////////////////////////////////////////////////////////////////////////////
//
// dynamic text resizing
//

//
// variables and initialization
//
var textSize = 1;
var pageType = "";

// call at start of page to read text size from cookie and get style sheet
function init_textsize() {
  load_cookie_info();
  if (textSize == 2) {
    document.writeln("<link rel='stylesheet' href='/styles/wimedium.css' type='text/css'>");
    if (pageType != "")
      document.writeln("<link rel='stylesheet' href='/styles/wimedium_"+pageType+".css' type='text/css'>");
  }
  else if (textSize == 3) {
    document.writeln("<link rel='stylesheet' href='/styles/wilarge.css' type='text/css'>");
    if (pageType != "")
      document.writeln("<link rel='stylesheet' href='/styles/wilarge_"+pageType+".css' type='text/css'>");
  }
}

//
// looks for text size in cookie
// if found, set textsize to 1, 2, or 3
//
function load_cookie_info() {
  var cookies = document.cookie.split(';');
  for (i = 0; i < cookies.length; i++) {
    if (cookies[i].indexOf('textSize') > -1) { // found the text size in cookie
      cookieparts = cookies[i].split('=')
      textSize = parseInt(cookieparts[1]);
      if (textSize < 1)
        textSize = 1;
      else if (textSize > 3)
        textSize = 3;
    }
  }
}
//
// save textsize to a cookie
//
function save_cookie_info() {
  var expire = new Date ();
  expire.setTime (expire.getTime() + (10*365*24*60*60*1000)); //expires in 10 years
  expire = expire.toGMTString();
  var str = 'textSize='+textSize+'; path=/; expires='+expire;
  document.cookie=str;
}

//
// called when small text size button clicked
//
function TextSmall() {
  text_resize_event(1);
}
//
// called when small text size button clicked
//
function TextMedium() {
  text_resize_event(2);
}
//
// called when small text size button clicked
//
function TextLarge() {
  text_resize_event(3);
}
//
// called by resize events
// sets the face sizes and saves info to cookie
//
function text_resize_event(size) {
  textSize = size;
  save_cookie_info();
  location.reload();
}


/////////////////////////////////////////////////////////////////////////////////////////
//
// PrinterFriendly
//

function PrinterFriendly() {
  url = "/scripts/pf1.php?p="+window.location.href;
  var newwindow = window.open(url, '', 'left=0,top=0,screenX=0,screenY=0,width=600,height=400,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes,status=no');
  if (newwindow) {
    if (window.focus)
      newwindow.focus();
    return false;
  }
  return true; // unsuccessful
}
function PrinterFriendly2() {
  url = "/scripts/pf2.php?p="+window.location.href;
  var newwindow = window.open(url, '', 'left=0,top=0,screenX=0,screenY=0,width=600,height=400,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes,status=no');
  if (newwindow) {
    if (window.focus)
      newwindow.focus();
    return false;
  }
  return true; // unsuccessful
}

/////////////////////////////////////////////////////////////////////////////////////////
//
// Email to a Friend
//

function EmailToFriend() {
  url = "/scripts/etf.php?p="+window.location.href;
  var newwindow = window.open(url, '', 'left=0,top=0,screenX=0,screenY=0,width=600,height=400,resizable=yes,scrollbars=yes,toolbar=no,menubar=yes,status=no');
  if (newwindow) {
    if (window.focus)
      newwindow.focus();
    return false;
  }
  return true; // unsuccessful
}

/////////////////////////////////////////////////////////////////////////////////////////
//
// Home Page visit counter
//  (used rather than random number to display photo and on topic)

var homeCount = 0;

function init_homecount() {
  var cookies = document.cookie.split(';');
  for (i = 0; i < cookies.length; i++) {
    if (cookies[i].indexOf('homeCount') > -1) { // found home page visit count in cookie
      cookieparts = cookies[i].split('=')
      homeCount = parseInt(cookieparts[1]);
      if (homeCount < 0)
        homeCount = 0;
    }
  }

  // increment and save back to cookie
  var newHomeCount = (homeCount+1) % 10000; // wrap at 10000
  var expire = new Date ();
  expire.setTime (expire.getTime() + (10*365*24*60*60*1000)); //expires in 10 years
  expire = expire.toGMTString();
  var str = 'homeCount='+newHomeCount+'; path=/; expires='+expire;
  document.cookie=str;

}


