// Javascript specific to the wrapper elements in general

/////////////////////////////////////////////////////////////////////////
// Netscape 4 resize bugfix from Macromedia Dreamweaver
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
   if (init==true) with (navigator) {if 
((appName=="Netscape") && (parseInt(appVersion)==4)) {
     document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; 
onresize=MM_reloadPage; }}
   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
location.reload();
}
MM_reloadPage(true);
// End resize bugfix
/////////////////////////////////////////////////////////////////////////
function onTrack(track)
{
  // if we are in this branch, do not flip
  if(window.navChoice&&(window.navChoice==track)) return;

  imgSrc = '';
  // 1. in the CMS...
  if(track=='science') imgSrc = 'img-header/tn_science_o.gif';
  if(track=='donate') imgSrc = 'img-header/tn_donate_o.gif';
  if(track=='info') imgSrc = 'img-header/tn_info_o.gif';
  if(track=='about') imgSrc = 'img-header/tn_about_o.gif';
  if(track=='research') imgSrc = 'img-header/tn_research_o.gif';
  if(track=='help') imgSrc = 'img-header/tn_help_o.gif';

  if(track=='sciencehomepage') imgSrc = 'img-header/tn_sciencehomepage_o.gif';
  if(track=='donatehomepage') imgSrc = 'img-header/tn_donatehomepage_o.gif';
  if(track=='infohomepage') imgSrc = 'img-header/tn_infohomepage_o.gif';
  if(track=='abouthomepage') imgSrc = 'img-header/tn_abouthomepage_o.gif';
  if(track=='researchhomepage') imgSrc = 'img-header/tn_researchhomepage_o.gif';
  if(track=='helphomepage') imgSrc = 'img-header/tn_helphomepage_o.gif';

  // 2. outside the CMS...
  if((window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1) &&
     (window.location.hostname.indexOf('cms.fhcrc.org')==-1)){
    imgSrc = '/wrapper/img-header/tn_' + track + '_o.gif';
  }
  imgName = 'headerNav_' + track;
  if(imgSrc){
   switchImage(imgSrc, imgName);
  }
}
function offTrack(track)
{
  // if we are in this branch, do not flip
  if(window.navChoice&&(window.navChoice==track)) return;

  imgSrc = '';
  // 1. in the CMS...
  if(track=='science') imgSrc = 'img-header/tn_science.gif';
  if(track=='donate') imgSrc = 'img-header/tn_donate.gif';
  if(track=='info') imgSrc = 'img-header/tn_info.gif';
  if(track=='about') imgSrc = 'img-header/tn_about.gif';
  if(track=='research') imgSrc = 'img-header/tn_research.gif';
  if(track=='help') imgSrc = 'img-header/tn_help.gif';

  if(track=='sciencehomepage') imgSrc = 'img-header/tn_sciencehomepage.gif';
  if(track=='donatehomepage') imgSrc = 'img-header/tn_donatehomepage.gif';
  if(track=='infohomepage') imgSrc = 'img-header/tn_infohomepage.gif';
  if(track=='abouthomepage') imgSrc = 'img-header/tn_abouthomepage.gif';
  if(track=='researchhomepage') imgSrc = 'img-header/tn_researchhomepage.gif';
  if(track=='helphomepage') imgSrc = 'img-header/tn_helphomepage.gif';

  // 2. outside the CMS...
  if((window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1) &&
     (window.location.hostname.indexOf('cms.fhcrc.org')==-1) ){
    imgSrc = '/wrapper/img-header/tn_' + track + '.gif';
  }  
  imgName = 'headerNav_' + track;
  if(imgSrc){
    switchImage(imgSrc, imgName);
  }
}

function activeTrack(track)
{
  var imgSrc = '';
  // 1. in the CMS...
  if(track=='science') imgSrc = 'img-header/tn_science_a.gif';
  if(track=='donate') imgSrc = '/Public/wrapper/img-header/tn_donate_a.gif';
  if(track=='info') imgSrc = 'img-header/tn_info_a.gif';
  if(track=='about') imgSrc = 'img-header/tn_about_a.gif';
  if(track=='research') imgSrc = 'img-header/tn_research_a.gif';
  if(track=='help') imgSrc = 'img-header/tn_help_a.gif';
  // 2. outside the CMS...
  if(window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1&&
     window.location.hostname.indexOf('cms.fhcrc.org')==-1){
    imgSrc = '/wrapper/img-header/tn_' + track + '_a.gif';
  }
  var imgName = 'headerNav_' + track;
  if(imgSrc){
   switchImage(imgSrc, imgName);
  }
}
function activeTrackStripe(track)
{
  var imgSrc = '';
  // 1. in the CMS...
  if(track=='science') imgSrc = 'img-header/green_line.gif';
  if(track=='donate') imgSrc = 'img-header/blue_line.gif';
  if(track=='info') imgSrc = 'img-header/purple_line.gif';
  if(track=='about') imgSrc = 'img-header/brown_line.gif';
  if(track=='research') imgSrc = 'img-header/yellow_line.gif';
  if(track=='help') imgSrc = 'img-header/blue_line.gif';
  // 2. outside the CMS...
  if(window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1&&
     window.location.hostname.indexOf('cms.fhcrc.org')==-1){
    var color= track=='science'?'green':(track=='donate'?'blue':(track=='info'?'purple':(track=='about'?'brown':(track=='research'?'yellow':(track=='help'?'blue':'')))));
    if(color) imgSrc = '/wrapper/img-header/' + color + '_line.gif';
  }

  if(imgSrc&&document['headerNavStripeImage']){
    document['headerNavStripeImage'].src=imgSrc;
    document['headerNavStripeImage'].height=5;
    document['headerNavStripeImage'].width=830;
  }
}

// function to determine which branch of the site we are in, for roll-over effects
// this is called once, after page has loaded.
window.navChoice='';
function detectSection()
{
  var arBranchURL=Array('donating','research','about','patient','science');
  var arNavChoice=Array('help','research','about','info','science');
  var i; var texp;
  var thisurl=document.location.pathname;
  for( i=0;i<arBranchURL.length;i++ ){
    texp = new RegExp("^/"+arBranchURL[i]+"|CenterWeb.+/Public/"+arBranchURL[i]); // matches both in CMS and outside
    if(texp.test(thisurl)){
      window.navChoice=arNavChoice[i];
      activeTrack(navChoice);
      activeTrackStripe(navChoice);
      return;
    }
  }
}
addEvent(window,"load",detectSection);

function onUtility(utility)
{
  imgSrc = '';
  // 1. inside the CMS
  if(utility=='directory') imgSrc = 'img-header/un_directory_o.gif';
  if(utility=='jobs') imgSrc = 'img-header/un_jobs_o.gif';
  if(utility=='contact_us') imgSrc = 'img-header/un_contact_us_o.gif';
  if(utility=='intranet') imgSrc = 'img-header/un_intranet_o.gif';
  if(utility=='check_email') imgSrc = 'img-header/un_check_email_o.gif';
  if(utility=='centernet') imgSrc = 'img-header/un_centernet_o.gif';
  if(utility=='extranet') imgSrc = 'img-header/un_extranet_o.gif';
  if(utility=='espanol') imgSrc = 'img-header/un_espanol_o.gif';

  // 2. outside the CMS...
  if((window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1)&&
     (window.location.hostname.indexOf('cms.fhcrc.org')==-1)){
    imgSrc = '/wrapper/img-header/un_' + utility + '_o.gif';
  }
  imgName = 'headerUtility_' + utility;
  switchImage(imgSrc, imgName);
}
function offUtility(utility)
{
  imgSrc = '/wrapper/img-header/un_' + utility + '.gif';
  // 1. inside the CMS
  if(utility=='directory') imgSrc = 'img-header/un_directory.gif';
  if(utility=='jobs') imgSrc = 'img-header/un_jobs.gif';
  if(utility=='contact_us') imgSrc = 'img-header/un_contact_us.gif';
  if(utility=='intranet') imgSrc = 'img-header/un_intranet.gif';
  if(utility=='check_email') imgSrc = 'img-header/un_check_email.gif';
  if(utility=='centernet') imgSrc = 'img-header/un_centernet.gif';
  if(utility=='extranet') imgSrc = 'img-header/un_extranet.gif';
  if(utility=='espanol') imgSrc = 'img-header/un_espanol.gif';

  // 2. outside the CMS...
  if((window.location.hostname.indexOf('cms-dev.fhcrc.org')==-1) &&
     (window.location.hostname.indexOf('cms.fhcrc.org')==-1)){
    imgSrc = '/wrapper/img-header/un_' + utility + '.gif';
  }
  imgName = 'headerUtility_' + utility;
  switchImage(imgSrc, imgName);
}


// this omits the topmost image of the right column upon request
function omitSidebarTopImage(){
  if(document.getElementById('sidebarTopImage')){
    document.getElementById('sidebarTopImage').style.display='none';
  }
}