//****************************************************************************************************
//
// mplus_sp_survey.js
//
// Date: 10/06/2010
//
// To integrate ForeSee version 6.1.0 without changing the existing way on
// various pages, this js file has been rewitten as follow:
//
// 1. Use location.href to determine the environment (i.e. dev, qa, or production)
// 2. Then, use document.write() to include the new ForeSee trigger javascript.
//
// For the new ForeSee version (6.1.0), both English and Spanish are using the same trigger javascript. 
// The trigger javascript (i.e. foresee-trigger.js) can detect the language by checking the URL path 
// (e.g. ./spanish/....) and then brings up the proper language contents. 
//
//****************************************************************************************************

var myhref = location.href;
var mySplitResult = myhref.split("/");
var myurl = '';
var stopat = mySplitResult.length - 1;
var foundit = false;

if (mySplitResult.length > 4) {
    for(i = 0; i < 3; i++){
	//alert('mySplitResult['+i+']:'+mySplitResult[i]);
        switch(mySplitResult[i])
        {
        case 'wwwdev.nlm.nih.gov':
             stopat = 6;
             foundit = true;
             break;
        case 'wwwqa.nlm.nih.gov':
             stopat = 4;
             foundit = true;
             break;
        case 'www.nlm.nih.gov':
             stopat = 3;
             foundit = true;
             break;
        }
    }
}

/*
   Special Note: 7/14/2011 Ta-Sun Hu
  
   In order to disable the foresee survey, we just need to uncomment out the following
   statement (i.e. foundit = false).  This will skip the document.write command and no
   foresee-trigger.js will be included during the page load.

*/

// foundit = false;

if (foundit) {
  for (i = 0; i <=stopat; i++) {
        if (myurl == '') { myurl =  mySplitResult[i];}
        else { myurl = myurl + '/' + mySplitResult[i];}
  }
  myurl = myurl + '/foresee/foresee-trigger.js';
  //document.write('<script type="text/javascript" src="' + myurl + '"></script>');
  var script = document.createElement("script");
  script.type="text/javascript";
  if (script.readyState) {
    script.onreadystatechange = function() {
      if ("loaded"==script.readyState || "complete"==script.readyState) {
        script.onreadystatechange = null;
      }
    };
  }
  else {
    script.onload = function() {
      ;
    }
  }
  script.src=myurl;
  document.getElementsByTagName("head")[0].appendChild(script);
}

