/*******************************************************************************
FILE NAME    :global.js
DEPENDENCIES :browser.js
********************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Functions used throughout website.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//-- global variables and functionality begin ----------------------------------
pageLoaded = false; //set page loaded flag
homePage = false;
if(top.location.href != self.location.href) top.location.href = self.location.href; //prevent unauthorized framing
theURL = window.document.location.href;
//-- global variables and functionality end ------------------------------------

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- preload images
function preloadImage(virtualName, filePath, fileName) {
 eval(virtualName +' = new Image()'); //create a new image object
 eval(virtualName +'.src = "' + filePath + fileName + '"');
}

//FUNCTION-- dynamically swaps one image (also used for rollovers in layers for Netscape 4)
function swapImageSingle(imageName, imageState, imageLayer) {
 if(gBrowser.ns4 && imageLayer!=null) eval('document.' + imageLayer + '.document.images["'+ imageName +'"].src =' + imageName + imageState + ".src"); //path to nested layer for Netscape 4
 else document.images[imageName].src = eval(imageName + imageState + ".src");
}

//FUNCTION-- sets rollover highlight
function setRollover(imageId, imageFilePath, imageFileName) {
 preloadImage(imageId+"_off", imageFilePath, imageFileName);
 preloadImage(imageId+"_on", imageFilePath, imageFileName);
 swapImageSingle(imageId, '_on', null);
}

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- creates a new 3/4 browser window for links to other websites throughout site
function newWin(url) {
 if(url != null || url != "")
 {
  newWin1 = window.open(url,"act_win",'directories=yes,location=yes,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=yes');
  newWin1.focus( );
 }
}

//FUNCTION-- creates a new browser window for Important Safety Information
function isiWin(url) {
 if(url != null || url != "")
 {
  isiWin1 = window.open(url,"act_isi",'directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no,width=650,height=430');
  isiWin1.focus( );
 }
}

//FUNCTION-- creates a new 3/4 browser window for Legal Notice and Privacy Policy
function legalWin(url) {
 if(url != null || url != "")
 {
  legalWin1 = window.open(url,"act_legal",'directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no');
  legalWin1.focus( );
 }
}

if(gBrowser.isWin && gBrowser.ie) {pdfReaderInitialized = false;} //used for newPDFWin function

//FUNCTION-- creates a popup window for pdfs
function newPDFWin(url) {
 if(url != null || url != "")
 {
  if(!gBrowser.isMac) //if its not a Mac
  {
   popupWinName = "act_PDF";
	 popupWinFeatures = "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no,width=700,height=350";

	 if(gBrowser.ie)
	 {
		try
		{
		 if(!newPDFWin1.name) {} //check property existance
		} 
    catch (e)
		{
		 pdfReaderInitialized = false; //reset flag
		}  

	  if(pdfReaderInitialized)
	  {
		 newPDFWin1 = window.open("",popupWinName,popupWinFeatures);
		 newPDFWin1.close();
		 newPDFWin1 = window.open(url,popupWinName,popupWinFeatures);
	  }
	  else 
		{
		 newPDFWin1 = window.open(url,popupWinName,popupWinFeatures);
		 pdfReaderInitialized = true;
		}
	 }
	 else
	 {
	  newPDFWin1 = window.open(url,popupWinName,popupWinFeatures);
	  newPDFWin1.focus();
	 }
  }
  else window.location.href = url; //mac fix for OS X
 }
}

//FUNCTION-- creates a new browser window for Anemia Tutorial
function anemiatutorialWin(url) {
 if(url != null || url != "")
 {
  anemiatutorial1 = window.open(url,"anemiatutorial",'directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no');
  anemiatutorial1.focus( );
 }
}

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// LEAVING THIS SITE EXTERNAL URL FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- escapes string
function escapeURL(url) {
 return escape(url);
}

//FUNCTION-- unescapes string
function unescapeURL(url) {
 return unescape(url);
}

//FUNCTION-- builds string
function buildURL(page, url, params) {
 window.top.location.href = page+escape(url)+params;
}

//------------------------------------------------------------------------------
// LEAVING THIS SITE EXTERNAL URL FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG AND MASKING BEGIN
//------------------------------------------------------------------------------

//used for dialog functionality
maskInitialized = false;
leavingSiteInitialized = true;
pdfInitialized = false;
bridgeMessageInitialized = false;
windowResizeSet = false;
currentDialog = null; //used for dynamic dialog tracking
dialogEnabled = false;
dailogType = 0;
externalURL = "";
pdfURL = "";
linkTarget = 0;
yWidth = 700;

//FUNCTION-- moves dialog off screen
function moveOffScreen() {
 currentDialog.m_moveTo(0, -1000);
}

//FUNCTION-- sets dialog
function setDialog() {
 if(dialogEnabled) 
 {
  if(dailogType == 1)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   pdfMessage.m_updateHeight();
   pdfMessage.m_positionObj(yWidth);
  }
  else if(dailogType == 2)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   leavingSite.m_updateHeight();
   leavingSite.m_positionObj(yWidth);
  }
  else if(dailogType == 3)
  {
   mask01.objCss.height = 50;
   mask01.objCss.width = 50;
   mask01.m_setMask();
   bridgeMessage.m_updateHeight();
   bridgeMessage.m_positionObj(yWidth);
  }
  else {alert("Error: dailogType undefined");}
 }
}

//FUNCTION-- clears dialog and Mask
function clearDialogMask() {
 dialogEnabled = false;
 moveOffScreen();
 if(dailogType == 1) {mask01.m_setDisplay(2);}
 else if(dailogType == 2) {mask01.m_setDisplay(2);}
 else if(dailogType == 3) {mask01.m_setDisplay(2);}
 else {alert("Error: dailogType undefined");}
}

//FUNCTION-- clears dialog only and retains mask (used when swapping mutliple dialogs when mask is visible)
function clearDialog() {
 dialogEnabled = false;
 moveOffScreen();
}

//------------------------------------------------------------------------------
// DIALOG AND MASKING END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// PDF MESSAGE BEGIN
//------------------------------------------------------------------------------

function setPDFMessage(formObj) {
 if(formObj.checked) setCookie("act", 1, 183);
 else deleteCookie("act");
}

function isPDFMessage() {
 if(getCookie("act")) return true;
 else return false;
}

//------------------------------------------------------------------------------
// PDF MESSAGE END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// CSS FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- swap class
function swapClass(theId, theClass) {
 var objId = document.getElementById(theId);
 objId.className = theClass;
}

//------------------------------------------------------------------------------
// CSS FUNCTIONS END
//------------------------------------------------------------------------------

//FUNCTION-- enables linking to home page based on homePage flag
function goHome(url) {
 if(!homePage) window.location.href = url; 
}

//FUNCTION-- determines if the browser used supports the print method
function canPrint() {
 if(!(gBrowser.isMac && (gBrowser.ie && gBrowser.majorVersion <=5 || gBrowser.ns && gBrowser.majorVersion <=4 || gBrowser.safari && gBrowser.majorVersion == 85))) return true; //supports print method
 else return false; //does not support print method
}

//FUNCTION-- returns value of URL parameter
function getURLParameter(parentDoc, URLParam) {
 var theURL = "";
 var theURLParam = URLParam + "=";
 var URLParameters = "";
 var parameterStartPos = "";
 var parameterEndPos = "";
	
 if(parentDoc) {theURL = window.top.document.location.href;} //get top frameset URL
 else {theURL = window.document.location.href;} //get document URL

 if(theURL.indexOf("?")>0) {URLParameters = theURL.substring(theURL.indexOf("?")+1, theURL.length);} //strip parameters from URL
 else {return null;} //? not found in URL

 if(URLParameters.indexOf(theURLParam)>=0)
 {
  parameterStartPos = (URLParameters.indexOf(theURLParam)+theURLParam.length);
  if(URLParameters.indexOf("&", parameterStartPos)>0) 
 {
  parameterEndPos = URLParameters.indexOf("&", parameterStartPos);
  return URLParameters.substring(parameterStartPos, parameterEndPos);
 }
  else {return URLParameters.substring(parameterStartPos, URLParameters.length);}
 }
 else return null; //parameter not found
}
//---END