/*******************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Variables and functions used throughout website.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// VARIABLES BEGIN
//------------------------------------------------------------------------------

homePage = false; //sets home page flag
pageLoaded = false; //set page loaded flag
theURL = window.document.location.href; //set window location

//------------------------------------------------------------------------------
// VARIABLES END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// ROLLOVER FUNCTIONS BEGIN - depricated functions used for HCP MIT only
//------------------------------------------------------------------------------

//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 - depricated functions used for HCP MIT only
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// AUTO INVOKE FUNCTIONALITY BEGIN
//------------------------------------------------------------------------------

if(top.location.href != self.location.href) top.location.href = self.location.href; //prevent unauthorized framing

//------------------------------------------------------------------------------
// AUTO INVOKE FUNCTIONALITY END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// CSS FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- sets CSS class
function setCssClass(argID, argClass) {
 document.getElementById(argID).className = argClass;
}

//------------------------------------------------------------------------------
// CSS FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- creates a new 3/4 browser window for links to other websites throughout site
function openExternalWin(argURL) {
 externalWin = window.open(argURL, null, 'toolbar=1,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=600,height=500');
 if(externalWin != null) externalWin.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a popup window for pdfs
function newPDFWin(argURL) {
 if(!gBrowser.isMac) //if its not a Mac
 {
	popupWinFeatures = "directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,toolbar=no";
  window.open(argURL,"",popupWinFeatures);
 }
 else window.location.href = argURL; //mac fix for OS X
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a mini popup browser window for glossary
function glossaryWin(url)
{
 var showToolBar = 0;
 if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar=1;
 glossaryWin1= window.open(url,"enjuvia_glossary",'directories=no,location=no,menubar=1,resizable=yes,scrollbars=yes,status=no,titlebar=yes,width=690,height=275,toolbar='+showToolBar);
 if(glossaryWin1 != null) glossaryWin1.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a new window for coupon
function couponWin(url) {
 couponWin2 = open(url,'couponview','directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,width=600,height=450,toolbar=yes');
 if(couponWin2 != null) couponWin2.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a new window for hcp impact Tool
function impactToolWin(url) {
 var showToolBar = 0;
 if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar=1;
 impactToolWin2 = open(url,'mitHCP','directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=yes,width=780,height=615,toolbar='+showToolBar);
 if(impactToolWin2 != null) impactToolWin2.focus();
}

//------------------------------------------------------------------------------

//FUNCTION-- creates a new window for patients impact Tool
function mitPatientsWin(url) {
 mitPatients = open(url,'mitPatients','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width=712,height=582,left=10,top=10,screenX=10,screenY=10');
 if(mitPatients != null) mitPatients.focus();
}

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- sets a cookie - jsv 1.0
function setCookie(cookieName, cookieValue, expireDate) { 
 if(expireDate != null)
 {
  //set expiration date for cookie
	var expires = new Date( );                                   
	expires.setTime(expires.getTime( ) + (1000 * 60 * 60 * 24 * expireDate)); //days ahead
 }
 document.cookie = cookieName + "=" + escape(cookieValue) + "; path=/" + ((expireDate == null) ? ";" : "; expires=" + expires.toGMTString());
}

//FUNCTION-- retrieves a cookie - jsv 1.0
function getCookie(cookieName) {
 var cookieNameStr = cookieName + "=";               
 var dc = document.cookie;
	            
 if(dc.length > 0)
 {              
  var beginStr = dc.indexOf(cookieNameStr);       
  if(beginStr != -1) 
  {           
   beginStr += cookieNameStr.length;       
   var endStr = dc.indexOf(";", beginStr);
   if(endStr == -1) {endStr = dc.length;}
   return unescape(dc.substring(beginStr, endStr));
  } 
 }
 return null;
}

//FUNCTION-- deletes a cookie - jsv 1.0
function deleteCookie(cookieName) {
 document.cookie = cookieName + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}

//------------------------------------------------------------------------------
// COOKIE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns screen height
function getScreenHeight() {
 return parseInt(screen.height);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns screen width
function getScreenWidth() {
 return parseInt(screen.width);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns height of working area of system's screen, excluding windows taskbar
function getScreenAvailHeight() {
 return parseInt(screen.availHeight);
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of working area of system's screen, excluding windows taskbar
function getScreenAvailWidth() {
 return parseInt(screen.availWidth);
}

//------------------------------------------------------------------------------
// SCREEN FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of browser window
function getBrowserWindowHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientHeight;
	else return document.body.clientHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasHorizontalScrollbar()) return window.innerHeight-getScrollbarOffSet();
	else return window.innerHeight;
 }
 else return window.innerHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of browser window
function getBrowserWindowWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.clientWidth;
	else return document.body.clientWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	if(hasVerticalScrollbar()) return window.innerWidth-getScrollbarOffSet();
	else return window.innerWidth;
 }
 else if(gBrowser.safari && hasVerticalScrollbar()) //safari
 {
	return window.innerWidth - getScrollbarOffSet();
 }
 else return window.innerWidth;
}

//------------------------------------------------------------------------------
// BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns height of body
function getBodyHeight() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollHeight;
	else return document.body.scrollHeight;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasHorizontalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasVerticalScrollbar())	return (window.innerHeight+window.scrollMaxY)-scrollOffSet;
  else return window.innerHeight-scrollOffSet;
 }
 else return document.body.scrollHeight;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns width of body
function getBodyWidth() {
 if(document.all) //ie
 {
	if(checkMode()) return document.documentElement.scrollWidth;
	else return document.body.scrollWidth;
 }
 else if(isScrollMax()) //mozilla
 {
	var scrollOffSet = 0;
	if(hasVerticalScrollbar()) scrollOffSet = getScrollbarOffSet();
	
	if(hasHorizontalScrollbar())	return (window.innerWidth+window.scrollMaxX)-scrollOffSet;
  else return window.innerWidth-scrollOffSet;
 }
 else return document.body.scrollWidth;
}

//------------------------------------------------------------------------------
// BROWSER BODY/DOCUMENT FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- determines horizontal scrollbar existence
function hasHorizontalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxX > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- determines vertical scrollbar existence
function hasVerticalScrollbar() {
 if(!document.all && isScrollMax()) //mozilla
 {
  if(window.scrollMaxY > 0) return true; //has scrollbar
	else return false; //has no scrollbar
 }
 else if(gBrowser.safari) //safari
 {
	if(window.innerWidth == getBodyWidth()) return false;
	else return true;
 }
 else {alert("Function not supported by browser"); return;}
}

//------------------------------------------------------------------------------

//FUNCTION-- checks if scrollMaxY and scrollMaxX properties are supported
function isScrollMax() {
 if(window.scrollMaxY >= 0 && window.scrollMaxX >= 0) return true;
 else return false;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns vertical scroll position
function getVerticalScrollPosition() {
 if(window.pageYOffset) {return window.pageYOffset;}
 else if(document.documentElement && document.documentElement.scrollTop) {return document.documentElement.scrollTop;}
 else if(document.body) {return document.body.scrollTop;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns horizontal scroll position
function getHorizontalScrollPosition() {
 if(window.pageXOffset) {return window.pageXOffset;}
 else if(document.documentElement && document.documentElement.scrollLeft) {return document.documentElement.scrollLeft;}
 else if(document.body) {return document.body.scrollLeft;}
}

//------------------------------------------------------------------------------

//FUNCTION-- returns offset value equal to scrollbar width
function getScrollbarOffSet() {
 if(gBrowser.firefox)
 {
  if(gBrowser.isWin) return 17;
	else if(gBrowser.isMac) return 15;
 }
 else if(gBrowser.safari) {return 15;}
}

//------------------------------------------------------------------------------
// BROWSER SCROLLBAR FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- checks document mode for IE
function checkMode() {
 if(document.all) {return (document.compatMode && document.compatMode != "BackCompat");}
 else {alert("Mode not detected");}
}

//------------------------------------------------------------------------------

//FUNCTION-- sets document mode for IE (documentElement or body based on DOCTYPE used)
function setMode() {
 if(document.all)
 {
	if(checkMode()) {DOCUMENTMODE = document.documentElement;}
	else {DOCUMENTMODE = document.body;}
 }
 else {alert("Unable to set mode");}
}

//------------------------------------------------------------------------------
// BROWSER COMPATMODE FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- returns left coordinates for object centering
function getObjectPositionLeft(argScreenWidth, argObjWidth) {
 if(argObjWidth < argScreenWidth)
 {
  var halfScreenWidth = parseInt(argScreenWidth/2);
  var halfObjWidth = parseInt(argObjWidth/2); 
  return ((halfScreenWidth-halfObjWidth)+getHorizontalScrollPosition());
 }
 else return 0;
}

//------------------------------------------------------------------------------

//FUNCTION-- returns top coordinates for object centering
function getObjectPositionTop(argScreenHeight, argObjHeight) {
 if(argObjHeight < argScreenHeight)
 {	
  var halfScreenHeight = parseInt(argScreenHeight/2);
  var halfObjHeight = parseInt(argObjHeight/2); 
  return ((halfScreenHeight-halfObjHeight)+getVerticalScrollPosition());
 }
 else return getVerticalScrollPosition();
}	

//------------------------------------------------------------------------------

//FUNCTION-- validate top position
function isValidatePositionTop(argTopPosition, argObjectHeight, argBrowserWindowHeight) {
 if(argTopPosition <= 0 || (argTopPosition+argObjectHeight) > argBrowserWindowHeight) return false;
 else return true;
}

//------------------------------------------------------------------------------

//FUNCTION-- validate left position
function isValidatePositionLeft(argLeftPosition, argObjectWidth, argBrowserWindowWidth) {
 if(argLeftPosition <= 0 || (argLeftPosition+argObjectWidth) > argBrowserWindowWidth) return false;
 else return true;
}

//------------------------------------------------------------------------------
// OBJECT POSITIONING FUNCTIONS END
//------------------------------------------------------------------------------

//FUNCTION-- fixes png transparency in unsupported browsers
function setPng(argId, argImagePath) {
 if(gBrowser.ie && gBrowser.majorVersion < 7)
 {
  var targetEl = document.getElementById(argId);
  targetEl.innerHTML = "";
  targetEl.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+argImagePath+"', sizingMethod='scale')";
 }
}

//FUNCTION-- closes active dialog (used mostly for flash external javascript calls)
function closeDialog() {
 activeDialog.m_hideDialog(true);
}