/*******************************************************************************
____________________________ 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
lastForm = " ";
isFocused = false;

//------------------------------------------------------------------------------
// VARIABLES END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// 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 new window for webinar bio
function videoHelpWin(url) {
 if(url != null || url != "")
 {
	var showToolBar = 0;
	if(gBrowser.ie && gBrowser.majorVersion > 6) showToolBar=1;
  videoHelpWin1 = window.open(url,'videoHelp_win','directories=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=yes,width=575,height=325,toolbar='+showToolBar);
  if(videoHelpWin1 != null) videoHelpWin1.focus( );
 }
}

//------------------------------------------------------------------------------
// NEW BROWSER WINDOW FUNCTIONS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// SEARCH FUNCTIONS BEGIN
//------------------------------------------------------------------------------

function setEmptySearch(obj) {
 if(obj.value == "Search") obj.value = "";
}

//------------------------------------------------------------------------------
// SEARCH 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
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG BEGIN
//------------------------------------------------------------------------------

pdfDialog = new Spawn_Object("pdfMessageDiv");
leavingDialog = new Spawn_Object("leavingSiteDiv");
whatsThisDialog = new Spawn_Object("whatsThisDiv");
segmentDialog = new Spawn_Object("segmentDialogDiv");

 if(theURL.indexOf("doctor_results.aspx")>0 || theURL.indexOf("search_results.aspx")>0 || theURL.indexOf("search_bystate.aspx")>0)
 {
  mapTipsDialog = new Spawn_Object("mapTipsDiv");
 }

//FUNCTION-- init dailogs
function initDialogs() {
 var grayMask = initMask("mask01", "/images/grayAlpha.png"); //initialize mask

 pdfDialog.m_initDialogProperties(grayMask, "pdf"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 leavingDialog.m_initDialogProperties(grayMask, "siteExit"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 whatsThisDialog.m_initDialogProperties(grayMask, "info2"); //init common dialog properties [mask=mask object or null | dialogType=integer]
 segmentDialog.m_initDialogProperties(grayMask, "info2"); //init common dialog properties [mask=mask object or null | dialogType=integer]

 activeDialog = null;
 activeStackDialog = null;
 window.onresize = adjustDialog;


 if((document.getElementsByTagName("body")[0].className == "page-patient-home" || document.getElementsByTagName("body")[0].className == "page-hcp-home") && !getCookie("nasfdd"))
 {
  doNowApprovedFilm();
 }
else if(theURL.indexOf("doctor_results.aspx")>0 || theURL.indexOf("search_results.aspx")>0 || theURL.indexOf("search_bystate.aspx")>0)
 {
  mapTipsDialog.m_initDialogProperties(grayMask, "info2"); //init common dialog properties [mask object or null]
  
 }
 else  if(document.getElementsByTagName("body")[0].className == "page-careCoachForm")
 {
  isiDialog = new Spawn_Object("isiDialogDiv");
  isiDialog.m_initDialogProperties(grayMask, "info2"); //init common dialog properties [mask object or null]
 }
}

//------------------------------------------------------------------------------
// DIALOG END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//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-- fixes png transparency in unsupported browsers
function setPng2(argId, argClearEl, argClearBg, argImagePath, argSizingMethod) {
 if(document.all)
 {
  var targetEl = document.getElementById(argId);
  if(argClearEl) targetEl.innerHTML = "";
  if(argClearBg) targetEl.style.backgroundImage = "none";
  targetEl.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+argImagePath+"', sizingMethod='"+argSizingMethod+"')";
 }
}

//------------------------------------------------------------------------------

function setLastForm(argForm) {
 lastForm = argForm;
}

//------------------------------------------------------------------------------

//FUNCTION-- sets isFocused value
function setFocus(argFocus) {
 isFocused = argFocus;
}

//------------------------------------------------------------------------------

//FUNCTION-- sets register paths 
function setRegister(argURL) {
 if(theURL.indexOf("hcp/")>0) window.location = argURL; //if hcp section go to hcp/register
 else segmentDialog.m_setResource(argURL); //if not hcp then invoke segment dialog
}

//------------------------------------------------------------------------------

//FUNCTION-- searches for specified URL parameter and returns its value
function getURLParameter(argParentDoc, argURLParam) {
 var theURL = "";
 var theURLParam = argURLParam + "=";
 var URLParameters = "";
 var parameterStartPos = "";
 var parameterEndPos = "";
	
 if(argParentDoc) {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
}

//------------------------------------------------------------------------------
// FUNCTIONS END
//------------------------------------------------------------------------------