/*=============================================================================================
--       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
====================================*/
$(document).ready(function(){

var query = window.location.search.substring(1);

var params = query.split('=');

if(params[0] == "ISIBox" && params[1] == "true")
{
$('body').css("overflow-y","hidden");
$('#leftToutFlash').css("display","none");
$('#modalWindow').jqm({modal: true});
$('#modalWindow').jqmAddClose($('.closeBtn'));
$('#modalWindow').jqmShow();
}
});
//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];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


//Lawrence Jackson's function for flash windows
function openNewWindow(URLtoOpen, windowName, windowFeatures) 
{
	newWindow=window.open(URLtoOpen, windowName, windowFeatures);
}

//Flash Test
var MM_contentVersion = 6;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
		var words = navigator.plugins["Shockwave Flash"].description.split(" ");
	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;
		var MM_PluginVersion = words[i]; 
	    }
	var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
	document.write('on error resume next \n');
	document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
	document.write('</SCR' + 'IPT\> \n');
}

//END FLash


// Toggles images
// parm: targetImageName : String - the name of the image to replace
// parm: newImgSource : String - the name and path of the image to replate the target image with
//
// return: void
function toggleImage(targetImageName, newImgSource) {
	
	//alert("Target name is " + targetImageName + "\n and path to image is: " + newImgSource);
	
		if (targetImageName == null || newImgSource == null || targetImageName == "" || 
			newImgSource == "") {
			alert("Error : toggleImage : targetImageName parm or newImgSource parm is null or empty.");
		}
	document.images[targetImageName].src = newImgSource;
}


/*===================================
-- End image rollover functions
====================================*/

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');
}
function fnCheckBWCookie( flashPlayer, flashFile ) {
	var chkCookieValue = (getCookie("bandwidth"));
	//alert(chkCookieValue);
	if( chkCookieValue != "" && chkCookieValue != "undefined" && null != chkCookieValue)
	{
		fnOpenPlayer( chkCookieValue, flashPlayer, flashFile );
	}
	else
	{
		// No cookie set so open up bandwidth speed picker.
		var strEndURL = '/flash/choosespeed/choosehighlow.html?media=' + flashPlayer + '&vURL=' + flashFile;
		window.open( strEndURL, 'bwPick', 'width=430, height=220, toolbar=no, location=no, menu=no, resize=no');
	}
	
}
function setCookie (name, value) {
	var exp = new Date();
	exp.setTime(exp.getTime() + (30 * 24 * 60 * 60 * 1000));
	
	var strCookie = name + "=" + escape(value) + "; expires=" + exp.toGMTString() + "; path=/";
	document.cookie = strCookie;
}
 
function getCookie(name) {
 var search = name + "=";
 var retstr = "";
 var offset = 0;
 var end = 0;
 if (document.cookie.length > 0) {
  offset = document.cookie.indexOf(search);
  if (offset != -1) {
   offset += search.length;
   end = document.cookie.indexOf(";", offset);
   if (end == -1)
    end = document.cookie.length;
   retstr = unescape(document.cookie.substring(offset, end));
  }
 }
 return(retstr)
}



function fnChooseSpeed( bw, playType, playFile ) {
	setCookie("bandwidth", bw );
	fnOpenPlayer( bw, playType, playFile );
	self.window.close();
	
}





function fnOpenPlayer( bwSpeed, playerType, filePath )
{
	var strPlayerHTML;
	var strFile;
	var strFinalURL;
	var strAttributes;
	//alert('DL speed: ' + bwSpeed + ' and playertype: ' + playerType + ' and filepath is: ' + filePath);
	if( playerType == '0')
	{
		strPlayerHTML = '/flash/movieplayer/pat_moa.html?vURL=' + filePath;
		strAttributes = 'width=440, height=410, location=no, history=no, toolbar=no, status=yes, scrollbars=no';
	}
	else if( playerType == '1') {
		strPlayerHTML = '/flash/movieplayer/hcp_moa.html?vURL=' + filePath;
		strAttributes = 'width=560, height=410, location=no, history=no, toolbar=no, status=yes, scrollbars=no';
	}
	else if( playerType == '2') {
		strPlayerHTML = '/flash/movieplayer/expertplayer.html?vURL=' + filePath;
		strAttributes = 'width=470, height=520, location=no, history=no, toolbar=no, status=yes, scrollbars=yes';
	}
	strFinalURL = strPlayerHTML;
	//alert('Final URL is: ' + strPlayerHTML);
	//alert('window attributes are: ' + strAttributes);
	window.open(strPlayerHTML, 'mediaWindow', strAttributes);

}

function fnViewExpertBio( moviefile )
{
	movieURL = '/flash/movieplayer/expertplayer.html?disp=1&vURL=' + moviefile;
	window.open( movieURL, 'movieBIO', 'width=470, height=520, location=no, history=no, toolbar=no, status=yes, scrollbars=yes');
}

/*===================================
-- 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/text_small.gif',1);
	MM_swapImage('mediumTextButton','','/images/text_medium.gif',1);
	MM_swapImage('largeTextButton','','/images/text_large.gif',1);	
	//then set the correct font
	if(whichStyle=="smallFont"){
		setActiveStyleSheet('regularFont'); 
		MM_swapImage('smallTextButton','','/images/text_small_selected.gif',1);
	}else if(whichStyle=="mediumFont"){
		setActiveStyleSheet('largerFont');
		MM_swapImage('mediumTextButton','','/images/text_medium_selected.gif',1);
	}else if(whichStyle=="largeFont"){
		setActiveStyleSheet('largestFont');
		MM_swapImage('largeTextButton','','/images/text_large_selected.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(\'smallFont\');"><img src="/images/text_small_selected.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/text_medium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/text_large.gif" alt="Large text" name="largeTextButton" /></a>');
	}else if(title=='largerFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/text_small.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/text_medium_selected.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/text_large.gif" alt="Large text" name="largeTextButton" /></a>');
	}else if(title=='largestFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/text_small.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/text_medium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/text_large_selected.gif" alt="Large text" name="largeTextButton" /></a>');
	}else{
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/text_small_selected.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/text_medium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/text_large.gif" alt="Large text" name="largeTextButton" /></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;
      //alert("Disabled: " + a.getAttribute("title"));
      
      if(a.getAttribute("title") == title) 
      {
		a.disabled = false;
		//alert("Enabled: " + a.getAttribute("title"));
	  }
    }
  }
}
//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;
}
//Create a Session cookie
function writeSessionCookie (cookieName, cookieValue) {
	
		document.cookie = escape(cookieName) + "=" + escape(cookieValue) + "; path=/";
		return true;	
}
//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);
	checkPrint();
	checkISI();  	
}

// Call window.print if print=1 is in querystring
function checkPrint()
{
  var str = document.URL;
  point = str.lastIndexOf("?");
  var suffix = (str.substring(point+1,str.length));
  if (suffix == "type=print") {
	window.print();
  }

}

// Show ISI if ISI = 1
function checkISI()
{
	//alert('checking for ISI parameter');
	if(qsParm["ISI"] != null)
	{
		if(qsParm["ISI"] != '')
		{
			document.getElementById("ISI").style.display = "block";
		}
	}

}

//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);
	}
}
function printSurveyPage() {
	var append = document.URL;
	if(append!=''){
		var finalURL = append + "?type=printSurvey";
	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\">");
  }  
  if (suffix == "type=printSurvey")
  {
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/pfriendly.css\">");
  }
  if (suffix == "type=isi")
  {
	document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"/css/displayisi.css\">");
  }
}
//Personal Survey version of pageType
function checkSurveyPrint()
{	
	var str = document.URL;
    point = str.lastIndexOf("?");
    var suffix = (str.substring(point+1,str.length));
	if(str.indexOf("/patient/byetta_right_112_5.jsp") > 0)
	{
		if (suffix == "type=print")
		{	
			for(x = 1; x < 7; x++)
			{
				divNum = "q" + x;
				radA = divNum + "a";
				radD = divNum + "d";				

				if(readCookie(divNum) == radA || readCookie(divNum) == radD)
				{
					document.getElementById(readCookie(divNum)).checked = true;
				}

			}
		
		}
		// Clear the cookies so they aren't carried forward to the print page regardless if overwritten or not
		else
		{
			writeSessionCookie("q1", null);
			writeSessionCookie("q2", null);
			writeSessionCookie("q3", null);
			writeSessionCookie("q4", null);
			writeSessionCookie("q5", null);
			writeSessionCookie("q6", null);
		}
	}
}
//Save answers to the Personal Survey
function saveAnswer(question, answerid)
{
	writeSessionCookie(question, answerid);
}
/*===================================
-- End Printer-Friendly Functions
====================================*/

function fnGetDL( objElement ) {
	//var strDLDoc = new String('');
	//alert( 'You selected ' + objElement );
	var strDLDoc = document.getElementById(objElement);
	//alert('Opening ' + strDLDoc.value);
	dcsMultiTrack('DCS.dcsuri', strDLDoc.value, 'WT.ti', 'Resources Download');
	window.open( strDLDoc.value, 'dL');
	return false;
}



/*======================================
-- Toggle divs
-- arg[0] - must be either 0 or 1 and turns the id's following on or off.
========================================*/
function toggleDiv()
{
    var funcArgs = toggleDiv.arguments;
    
    if( funcArgs.length > 0 )
    {
        for( var i=0; i < funcArgs.length; i++ )
        {
            if( i > 0 )
            {
                if(funcArgs[0] == 0) {
                    document.getElementById(funcArgs[i]).style.display = 'none';              
                } else {
                    document.getElementById(funcArgs[i]).style.display = 'block';
                }
            }
        }
    }
}

function activate(btnCall)
{
	if( btnCall == 'learn')
	{
		MM_swapImage('top1','','/images/consumer/img00-nav-learn-on.gif',1);
	}
	if( btnCall == 'getting')
	{
		MM_swapImage('top2','','/images/consumer/img00-nav-get-started-on.gif',1);
	}
	t = setTimeout('MM_swapImgRestore()', 2000);
}


//Javascript code to read the querystring.
var qsParm = new Array();
qsParm["mc_id"] = null;
qsParm["ISI"]=null;
readQS();


function readQS()
{
	var query = window.location.search.substring(1);
	var parms = query.split('&');

	for(var i=0; i<parms.length; i++){
		var pos = parms[i].indexOf('=');
		if(pos > 0){
			var key = parms[i].substring(0, pos);
			var val = parms[i].substring(pos + 1);
			qsParm[key] = val;
   			}
	}
}




/*========================================
-- check for Campaign Tracking
==========================================*/
//alert('qsParm is: ' + qsParm["mc_id"]);
if(qsParm["mc_id"] != null)
{
	if(qsParm["mc_id"] != '')
	{
		document.write('<META NAME="WT.mc_id" CONTENT="' + qsParm["mc_id"] + '">');
	}
}



/*========================================
-- Code for Glossary Pop Over
==========================================*/

/* Check tooltip code for compatibility with Firefox */

/*----------------------------------- */
var cX = 0; 
var cY = 0;
function UpdateCursorPosition(e)
{ 
	cX = e.pageX; 
	cY = e.pageY;
}
function UpdateCursorPositionDocAll(e)
{ 
	cX = event.clientX; 
	cY = event.clientY;
}


if(document.all) 
{ 
	document.onmousemove = UpdateCursorPositionDocAll; 
}
else { 
	document.onmousemove = UpdateCursorPosition;
} 

window.onscroll = refreshCoordinates;

function mouseX(evt) {
	if (evt.pageX) return evt.pageX;
	else if (evt.clientX)
		return evt.clientX + (document.documentElement.scrollLeft ?
	document.documentElement.scrollLeft :
	document.body.scrollLeft);
	else return null;	
}

function mouseY(evt) {
	if (evt.pageY) return evt.pageY;
	else if (evt.clientY)
		return evt.clientY + (document.documentElement.scrollTop ?
	document.documentElement.scrollTop :
	document.body.scrollTop);
	else return null;
}


function refreshCoordinates()
{
	if(document.all) 
	{ 
		document.onmousemove = UpdateCursorPositionDocAll; 
	}
	else { 
		document.onmousemove = UpdateCursorPosition;
	} 
}

function AssignPosition(def) {
	//alert('Callign AssignPos');
	refreshCoordinates();

	//alert(cY);

	def.style.left = (cX - 260) + "px";
	def.style.top = (cY + 20) + "px";
	
	var browserName = navigator.appName;
	//alert(browserName);
	if( browserName != "Netscape" )
	{
		//alert('for IE only');
		def.style.left = (cX - 260) + "px";
		def.style.top = (cY + document.documentElement.scrollTop + 20 ) + "px"; //- 100
		//alert(document.documentElement.scrollTop);
	}
}




function HideContent(d) {
	//alert('hiding ID:' + d);
	if(d.length < 1) 
	{ 
		return; 
	}
	var dd = document.getElementById(d);
	dd.style.display = "none";
}

function ShowContent(d) {
	//alert(d.length);
	if(d.length < 1) 
	{ 
		return; 
	}
	//alert('Element to show is: ' + d);	

	var dd = document.getElementById(d);
	dd.style.display = "block";
	AssignPosition(dd);

}

function ReverseContentDisplay(d) {
	if(d.length < 1) { 
		return; 
	}

	var dd = document.getElementById(d);
	AssignPosition(dd);

	if(dd.style.display == "none") 
	{ 
		dd.style.visibility = "visible"; 
	}
	else { 
		dd.style.visibility = "hidden"; 
	}
}

//////////////////////////////////////////
//////////////////////////////////////////

function DisplayBio(onName, offName) {
	var divOn = document.getElementById(onName);
	var divOff = document.getElementById(offName);
	divOn.style.display = "block";
	divOff.style.display = "none";
	
}