/*=============================================================================================
--       SITE/SYSTEM : Brand Platform v2
--       DESCRIPTION : Global JavaScript File
--  REVISION HISTORY : Date      Version   Name             Description
--                     09/27/05  1.0.0.0   Joe Gallagher    Initial version
=============================================================================================*/
/*===================================
-- Begin image rollover functions
====================================*/
//Preload specified images on the page
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//Restore the specified image to its original state
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
//Find image objects with specified IDs
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
//Swap oringal image with specifed image
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*===================================
-- End image rollover functions
====================================*/

/*===================================
-- Begin text sizing functions
====================================*/
//Resets all the text-size images and sets the correct font
function styleSizer(whichStyle){	
	//reset all the images
	MM_swapImage('smallTextButton','','/images/global/textSmall.gif',1);
	MM_swapImage('mediumTextButton','','/images/global/textMedium.gif',1);
	MM_swapImage('largeTextButton','','/images/global/textLarge.gif',1);
	//then set the correct font
	if(whichStyle=="regularFont"){
		setActiveStyleSheet('regularFont'); 
		MM_swapImage('smallTextButton','','/images/global/textSmall-on.gif',1);
	}else if(whichStyle=="largerFont"){
		setActiveStyleSheet('largerFont');
		MM_swapImage('mediumTextButton','','/images/global/textMedium-on.gif',1);
	}else if(whichStyle=="largestFont"){
		setActiveStyleSheet('largestFont');
		MM_swapImage('largeTextButton','','/images/global/textLarge-on.gif',1);
	}
}

//writeImages writes out what image should be live on page load
function writeImages(){
	 var cookie = readCookie("style");
 	 var title = cookie ? cookie : getPreferredStyleSheet();
	//regularFont, largerFont, largestFont
	if(title==null || title=='regularFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\'); return false;"><img src="/images/global/textSmall-on.gif" alt="Small text" id="smallTextButton" name="smallTextButton" width="18" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\'); return false;"><img src="/images/global/textMedium.gif" alt="Medium text" id="mediumTextButton" name="mediumTextButton" width="16" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\'); return false;"><img src="/images/global/textLarge.gif" alt="Large text" id="largeTextButton" name="largeTextButton" width="22" height="26" style="padding-right: 1px;" /></a>');
	}else if(title=='largerFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\'); return false;"><img src="/images/global/textSmall.gif" alt="Small text" id="Img1" name="smallTextButton" width="18" height="26" style="padding-right: 1px;"  /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\'); return false;"><img src="/images/global/textMedium-on.gif" alt="Medium text" id="Img2" name="mediumTextButton" width="16" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\'); return false;"><img src="/images/global/textLarge.gif" alt="Large text" id="Img3" name="largeTextButton" width="22" height="26" style="padding-right: 1px;" /></a>');
	}else if(title=='largestFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\'); return false;"><img src="/images/global/textSmall.gif" alt="Small text" id="Img4" name="smallTextButton" width="18" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\'); return false;"><img src="/images/global/textMedium.gif" alt="Medium text" id="Img5" name="mediumTextButton" width="16" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\'); return false;"><img src="/images/global/textLarge-on.gif" alt="Large text" id="Img6" name="largeTextButton" width="22" height="26" style="padding-right: 1px;" /></a>');
	}else{
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\'); return false;"><img src="/images/global/textSmall-on.gif" alt="Small text" id="Img7" name="smallTextButton" width="18" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\'); return false;"><img src="/images/global/textMedium.gif" alt="Medium text" id="Img8" name="mediumTextButton" width="16" height="26" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\'); return false;"><img src="/images/global/textLarge.gif" alt="Large text" id="Img9" name="largeTextButton" width="22" height="26" style="padding-right: 1px;" /></a>');
}
}
// 1. Loop through every link element in the document.
// 2. Disable all preferred and alternate style sheets that we don’t want active.
// 3. Enable all preferred and alternate style sheets that we do want active.
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}
//Return the current style sheet
function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}
//Find out which style sheet is the preferred style sheet.
function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}
//Create a cookie to store the preferred style sheet.
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}
//Read the cookie to return the prefered style sheet.
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
//On page load get the value of previous style sheeet or use preferred styles sheet.
window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}
//Save the cookie in the onunload event
window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
/*===================================
-- End text sizing functions
====================================*/

/*===================================
-- Begin Printer-Friendly Functions
====================================*/
//Change the status bar when user mouses over the Printer Friendly Version button.
function printOver() {
  window.status="Open a printer friendly version in a new window"
}
//Restore the status bar when user mouses over the Printer Friendly Version button.
function printOut() {
  window.status="";
}
//Get the URL of current page and append ?type=print to it. Open the new page.
function printPage() {
	var append = document.URL;
	if(append!=''){
		var finalURL = append + "?type=print";
	window.open(finalURL);
	}
}
//Get the URL of the current page. If the URL ends in type=print, attach print-friendly styles.
function pageType() {
  var str = document.URL
  point = str.lastIndexOf("?");
  var suffix = (str.substring(point+1,str.length));
  if (suffix == "type=print") {
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/pfriendly.css\">");
  }
}
/*===================================
-- End Printer-Friendly Functions
====================================*/


/*===================================
-- Begin Email a Friend function
====================================*/

function emailafriend(){
	var currentSite = window.location.href;
        var url = "";
  if (currentSite.indexOf("-d.xh1.lilly.com") >= 0) {
          url = "https://emailafriend-d.xh1.lilly.com/index.jsp?url=" + currentSite;
        } else if (currentSite.indexOf("-d6.xh1.lilly.com") >= 0) {
          url = "https://emailafriend-d6.xh1.lilly.com/index.jsp?url=" + currentSite;
        } else if (currentSite.indexOf("-qa.xh1.lilly.com") >= 0) {
          url = "https://emailafriend-qa.xh1.lilly.com/index.jsp?url=" + currentSite;
        } else {
          url = "https://emailafriend.lilly.com/index.jsp?url=" + currentSite;
        }
        window.open(url, 'EmailAFriend', 'height=500, resizable=yes, scrollbars=yes, width=650');
}
/*===================================
-- End Email a Friend functions
====================================*/




/*==================================================================================================
-- Begin Drop-down menu function

-- IMPORTANT NOTICE:
-- The Drop-down menu function below is commented out by default. If you are specifying the dropdown
-- style set in the siteconfig DCR file, the comment block around the drop-down menu function should
-- be removed.

====================================================================================================*/

/* Begin Comment
// 1. Apply the 'sfhover' class to li elements in the 'nav' id'd ul element when they are 'moused over'
// 2. Remove the 'sfhover' class from li elements in the 'nav' id'd ul element when 'moused out'
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
End Comment*/
/*===================================
-- End Drop-down menu function
====================================*/

/*========================
-- Check for HCP status
========================*/

//Check to see if it's not coming from an HCP e-mail
if(document.location.search.indexOf("email") > 0) {
	createCookie('isHCP',1,1);
}
	
var urlContinue = window.location.href;
var hcpCookie = checkHCP();

if ((!hcpCookie) && (window.location.href.indexOf("index.html") < 0))
{
		//window.location.href="/index.html?page="+urlContinue
}

function checkHCP()
{
	var chkHCP = readCookie('isHCP');
	if (chkHCP == null || chkHCP == '')
		return false;
	else
		return true;
}

function setHCPCookie()
{
	createCookie('isHCP',1,1);
	var hcpDirect = document.location.search.substring(1).split("=");
	//alert (hcpDirect[1]);
	if (document.location.search)
		if (hcpDirect.indexOf("index.html") != -1)
			document.location.href = hcpDirect[1];
		else
			document.location.href = "index.jsp";
	else
		document.location.href = "index.jsp";
	
	return false;
}

function popEntry()
{
	if (hcpCookie) {
		return true;
	} else {
		var winArgs = popEntry.arguments;
		window.open(winArgs[0], 'popWindow', 'width='+winArgs[1]+',height='+winArgs[2]+',toolbar=no,menubar=no,location=no,scrollbars='+winArgs[3]+',status=no,resizable=no');
		return false;
	}
	
}
/*========================
-- End HCP Status Check
========================*/


/*====================
-- pop interstitial
====================*/
function popInterstitialHCP()
{
	var winArgs = popInterstitialHCP.arguments;
	window.open( '/include/interstitial.jsp?url=' + winArgs[0].replace(/&/g,"%26"), winArgs[1], 'width=400,height=290,toolbar=no,menubar=no,location=no,scrollbars=no,status=yes,resizable=no');
	return false;
}
function popInterstitialPat()
{
	var winArgs = popInterstitialPat.arguments;
	window.open( '/include/interstitial.jsp?url=' + winArgs[0].replace(/&/g,"%26"), winArgs[1], 'width=400,height=290,toolbar=no,menubar=no,location=no,scrollbars=no,status=yes,resizable=no');
	return false;
}
/*====================
-- end interstitial
====================*/

/*====================
-- Parse query string
====================*/
function parseQuery(query)
{
	var Params = {};
	
	if (!query) {return Params;} // return empty object

	query = query.substring(query.indexOf('?') + 1);
	var Pairs = query.split(/[;&]/);
	for ( var i = 0; i < Pairs.length; i++ )
	{
		//var KeyVal = Pairs[i].split('=');
		var KeyVal = new Array();
		KeyVal[0] = Pairs[i].substring(0, Pairs[i].indexOf('='));
		KeyVal[1] = Pairs[i].substring(Pairs[i].indexOf('=') + 1);
		if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
		var key = unescape( KeyVal[0] );
		var val = unescape( KeyVal[1] );
		val = val.replace(/\+/g, ' ');
		Params[key] = val;
	}
	return Params;
}
/*====================
-- end parse query string
====================*/



/*====================
-- Customer's Prefered footer Popup size
====================*/

var newwindow;
function preferedPop(url)
{
	newwindow=window.open(url,'name','height=500,width=600,resizable=yes,scrollbars=yes,menubar=yes');
	if (window.focus) {newwindow.focus()}
}
/*====================
-- Customer's Prefered footer Popup size
====================*/



/*==========================
Track page change with flash
===========================*/

function flashTrack()
{
	//dcsMultiTrack('DCS.dcsuri', '', 'WT.ti', 'Flash_PI');

	dcsMultiTrack('DCS.dcsuri', '/hcp/safetyInformationHCP.jsp', 'WT.ti', 'Flash_ImportantSafetyInfo');

	window.location = "/hcp/safetyInformationHCP.jsp";
}
