/*=============================================================================================
--       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('textSizeSmall','','/images/pat/img00textsizeNormalOff.gif',1);
	MM_swapImage('textSizeMedium','','/images/pat/img00textsizeLargerOff.gif',1);
	MM_swapImage('textSizeLarge','','/images/pat/img00textsizeLargestOff.gif',1);
	

	//then set the correct font
	if(whichStyle=="smallFont"){
		//MM_swapImage('textSizeSmall','','/images/pat/img00textsizeNormalOn.gif',1);
		//MM_swapImage('textSizeMedium','','/images/pat/img00textsizeLargerOff.gif',1);
		//MM_swapImage('textSizeLarge','','/images/pat/img00textsizeLargestOff.gif',1);
		setActiveStyleSheet('regularFont');
		
	}else if(whichStyle=="mediumFont"){
		MM_swapImage('textSizeSmall','','/images/pat/img00textsizeNormalOff.gif',1);
		MM_swapImage('textSizeMedium','','/images/pat/img00textsizeLargerOn.gif',1);
		MM_swapImage('textSizeLarge','','/images/pat/img00textsizeLargestOff.gif',1);
		setActiveStyleSheet('largerFont');
		
	}else if(whichStyle=="largeFont"){
		MM_swapImage('textSizeSmall','','/images/pat/img00textsizeNormalOff.gif',1);
		MM_swapImage('textSizeLarge','','/images/pat/img00textsizeLargestOn.gif',1);
		MM_swapImage('textSizeMedium','','/images/pat/img00textsizeLargerOff.gif',1);
		setActiveStyleSheet('largestFont');
	}
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
	document.getElementById('textSizeBtns').innerHTML = writeImages();
}
//writeImages writes out what image should be live on page load
function writeImages(){
//alert('writing images');
	 var cookie = readCookie("style");
 	 var title = cookie ? cookie : getPreferredStyleSheet();
	//regularFont, largerFont, largestFont
	if(title==null || title=='regularFont'){
		return('<a href="javascript:;" onclick="styleSizer(\'smallFont\');"><img src="/images/pat/img00textsizeNormalOn.gif" width="26" height="26" alt="Normal Text" id="textSizeSmall" name="textSizeSmall"></a><a href="javascript:;" onclick="styleSizer(\'mediumFont\');"><img src="/images/pat/img00textsizeLargerOff.gif" width="23" height="26" alt="Larger Text" id="textSizeMedium" name="textSizeMedium"></a><a href="javascript:;" onclick="styleSizer(\'largeFont\');"><img src="/images/pat/img00textsizeLargestOff.gif" width="26" height="26" alt="Largest Text" id="textSizeLarge" name="textSizeLarge"></a>');
	}else if(title=='largerFont'){
		return('<a href="javascript:;" onclick="styleSizer(\'smallFont\');"><img src="/images/pat/img00textsizeNormalOff.gif" width="26" height="26" alt="Normal Text" id="textSizeSmall" name="textSizeSmall"></a><a href="javascript:;" onclick="styleSizer(\'mediumFont\');"><img src="/images/pat/img00textsizeLargerOn.gif" width="23" height="26" alt="Larger Text" id="textSizeMedium" name="textSizeMedium"></a><a href="javascript:;" onclick="styleSizer(\'largeFont\');"><img src="/images/pat/img00textsizeLargestOff.gif" width="26" height="26" alt="Largest Text" id="textSizeLarge" name="textSizeLarge"></a>');
	}else if(title=='largestFont'){
		return('<a href="javascript:;" onclick="styleSizer(\'smallFont\');"><img src="/images/pat/img00textsizeNormalOff.gif" width="26" height="26" alt="Normal Text" id="textSizeSmall" name="textSizeSmall"></a><a href="javascript:;" onclick="styleSizer(\'mediumFont\');"><img src="/images/pat/img00textsizeLargerOff.gif" width="23" height="26" alt="Larger Text" id="textSizeMedium" name="textSizeMedium"></a><a href="javascript:;" onclick="styleSizer(\'largeFont\');"><img src="/images/pat/img00textsizeLargestOn.gif" width="26" height="26" alt="Largest Text" id="textSizeLarge" name="textSizeLarge"></a>');
	}else{
		return('<a href="javascript:;" onclick="styleSizer(\'smallFont\');"><img src="/images/pat/img00textsizeNormalOff.gif" width="26" height="26" alt="Normal Text" id="textSizeSmall" name="textSizeSmall" onMouseOver="MM_swapImage(\'textSizeSmall\',\'\',\'/images/pat/img00textsizeNormalOn.gif\',1);" onMouseOut="MM_swapImgRestore();"></a><a href="javascript:;" onclick="styleSizer(\'mediumFont\');"><img src="/images/pat/img00textsizeLargerOff.gif" width="23" height="26" alt="Larger Text" id="textSizeMedium" name="textSizeMedium" onMouseOver="MM_swapImage(\'textSizeMedium\',\'\',\'/images/pat/img00textsizeLargerOn.gif\',1);" onMouseOut="MM_swapImgRestore();"></a><a href="javascript:;" onclick="styleSizer(\'largeFont\');"><img src="/images/pat/img00textsizeLargestOff.gif" width="26" height="26" alt="Largest Text" id="textSizeLarge" name="textSizeLarge" onMouseOver="MM_swapImage(\'textSizeLarge\',\'\',\'/images/pat/img00textsizeLargestOn.gif\',1);" onMouseOut="MM_swapImgRestore();"></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);
  checkShowPlayer();
}
//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
====================================*/
/*====================
-- 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
====================*/

/*===================================
-- Begin Email show HCP popWindow
====================================*/
function checkShowPlayer()
{
	var params = parseQuery(self.location.href);
	if (params['ShowPlayer'] == 'true')
	{
	tvAdNewWindow();
	}
}
/*===================================
-- End Email show HCP popWindow
====================================*/

/*===================================
-- 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
====================================*/

// -------------------------------
//Email a friend javascript code
// -------------------------------

function emailafriend() {

	//setTimeout("go_now()",0);
	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');

}


function go_now() 
{
	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 javascript
===============================*/



/*====================
-- pop interstitial
====================*/
function popInterstitialHCP()
{
	var winArgs = popInterstitialHCP.arguments;
	window.open( '/include/interstitial_hcp.jsp?url=' + winArgs[0].replace(/&/g,"%26"), winArgs[1], 'width=450,height=300,toolbar=no,menubar=no,location=no,scrollbars=no,status=yes,resizable=no');
	return false;
}
function popInterstitialPat()
{
	var winArgs = popInterstitialPat.arguments;
	window.open( '/include/interstitial_pat.jsp?url=' + winArgs[0].replace(/&/g,"%26"), winArgs[1], 'width=450,height=300,toolbar=no,menubar=no,location=no,scrollbars=no,status=yes,resizable=no');
	return false;
}
/*====================
-- end interstitial
====================*/

/*====================
-- pop standard
====================*/
function popWin()
{
	var winArgs = popWin.arguments;
	window.open(winArgs[0], 'popWindow', 'width='+winArgs[1]+',height='+winArgs[2]+',toolbar=yes,menubar=yes,location=yes,scrollbars='+winArgs[3]+',status=yes,resizable=yes');
	return false;
}
function popWinStatic()
{
	var winArgs = popWinStatic.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;
}
function tvAdNewWindow()
{
	window.open('/hcp/tv_ad_videoplayer.jsp','','width=400,height=360,toobar=no,menubar=no,location=no,scrollbars=no,status=yes,resizable=no');
	dcsMultiTrack('DCS.dcsuri', 'tv_ad_videoplayer.jsp', 'WT.ti', 'EVISTA Patient Advertising Campaign');
}
/*====================
-- end standard
====================*/


/*========================
-- 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
========================*/

//Enable and disable general layers (parameter required)
function enableLayer(layerName) {
	document.getElementById(layerName).style.display = "block";
}
function disableLayer(layerName) {
	document.getElementById(layerName).style.display = "none";
}

/*==================================================================================================
-- 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
====================================*/

function trackITP() {
    var sPath = window.location.pathname;
    //var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
    var pageName = sPath.substring(sPath.lastIndexOf('/') + 1);

    var strURL = '';
    var strTitle = '';
	//alert(pageName);

    switch (pageName) {
        case 'pat220_risk_assessment_guide.jsp':
            strURL = '/pat/tout/MyPersonalGuide_AmIAtRisk';
            strTitle = 'My Personal Guide - Am I At Risk - Tout';
            break;
        case 'pat300_about_evista.jsp':
        case 'pat310_benefits_of_evista.jsp':
        case 'pat320_how_is_evista_taken.jsp':
        case 'pat340_faq.jsp':
            strURL = '/pat/tout/MyPersonalGuide_AboutEVISTA';
            strTitle = 'My Personal Guide - About EVISTA - Tout';
            break;
        case 'pat400_take_charge.jsp':
        case 'pat430_quiz.jsp':
            strURL = '/pat/tout/MyPersonalGuide_TakeChargeOfYourHealth';
            strTitle = 'My Personal Guide - Take Charge of Your Health - Tout';
		break;
        case 'pat500_resources.jsp':
            strURL = '/pat/tout/MyPersonalGuide_Resources';
            strTitle = 'My Personal Guide - Resources - Tout';
		break;
        default:
            strURL = '/pat/tout/MyPersonalGuide_homePage';
            strTitle = 'My Personal Guide - Homepage - Tout';
		break;
    }

    dcsMultiTrack('DCS.dcsuri', strURL, 'WT.ti', strTitle);

	window.open('/swf/guide.jsp','PersonalizedGuide', 'height=800, width=840, scrollbars=1');

    return false;
}


/*===================================
-- Modal Function
====================================*/
$(document).ready(function(){

	$('#dtcModalWindow').jqm({
              modal: true
          });
	$('#hcpModalWindow').jqm({
              modal: true
          });
	

	var params = parseQuery(self.location.href);
	if (params["pcc1"] == "true")
	{

		if(self.location.href.indexOf("/pat/") != -1)
		{
			$("#dtcModalWindow").jqmShow();
			$(".jqmOverlay").before($("#dtcModalWindow"));
		}
		else
		{
			$("#hcpModalWindow").jqmShow();
			$(".jqmOverlay").before($("#hcpModalWindow"));
		}
	}
});



function spotlightTracking(CAT)
{
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	$("#spotlightIFrame").attr("src" , "http://fls.doubleclick.net/activityi;src=2079262;type=evist481;cat=" + CAT + ";ord=1?");
}

function spotlightTrackingTout(CAT)
{
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	if(location.href.indexOf("pat300_about_evista") >= 0)
	{
		$("#spotlightIFrame").attr("src" , "https://fls.doubleclick.net/activityi;src=2079262;type=stand177;cat=" + CAT + ";ord=" + a + "?");
	}
}

function spotlightTrackingToutEAF()
{
	var axel = Math.random()+"";
	var a = axel * 10000000000000;	
	trackEAF('evist481', 'email848');

	setTimeout("trackEAF('stand177','evist382')",5000);

}

function trackEAF(p1, p2)
{
	var axel = Math.random()+"";
	var a = axel * 10000000000000;
	$("#spotlightIFrame").attr("src" , "https://fls.doubleclick.net/activityi;src=2079262;type=" + p1 + ";cat=" + p2 + ";ord=1;num=' + a + '?");	
}