/*=============================================================================================
--       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/pagetools/btntextsizesmall.gif',1);
	MM_swapImage('mediumTextButton','','/images/pagetools/btntextsizemedium.gif',1);
	MM_swapImage('largeTextButton','','/images/pagetools/btntextsizelarge.gif',1);
	//then set the correct font
	if(whichStyle=="smallFont"){
		setActiveStyleSheet('regularFont'); 
		MM_swapImage('smallTextButton','','/images/pagetools/btntextsizesmalloveron.gif',1);
	}else if(whichStyle=="mediumFont"){
		setActiveStyleSheet('largerFont');
		MM_swapImage('mediumTextButton','','/images/pagetools/btntextsizemediumoveron.gif',1);
	}else if(whichStyle=="largeFont"){
		setActiveStyleSheet('largestFont');
		MM_swapImage('largeTextButton','','/images/pagetools/btntextsizelargeoveron.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/pagetools/btntextsizesmalloveron.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/pagetools/btntextsizemedium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/pagetools/btntextsizelarge.gif" alt="Large text" name="largeTextButton" /></a>');
	}else if(title=='largerFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/pagetools/btntextsizesmall.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/pagetools/btntextsizemediumoveron.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/pagetools/btntextsizelarge.gif" alt="Large text" name="largeTextButton" /></a>');
	}else if(title=='largestFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/pagetools/btntextsizesmall.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/pagetools/btntextsizemedium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/pagetools/btntextsizelargeoveron.gif" alt="Large text" name="largeTextButton" /></a>');
	}else{
		return('<a href="#" onClick="javascript:styleSizer(\'smallFont\');"><img src="/images/pagetools/btntextsizesmalloveron.gif" alt="Small text" name="smallTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'mediumFont\');"><img src="/images/pagetools/btntextsizemedium.gif" alt="Medium text" name="mediumTextButton" /></a><a href="#" onClick="javascript:styleSizer(\'largeFont\');"><img src="/images/pagetools/btntextsizelarge.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;
      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/cascading_print.css\">");
  }
}
/*===================================
-- End Printer-Friendly 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
====================================*/


/*-----------------------------------------------------------------------------
 *  Function:  emailFriend
 *
 *  THIS IS FOR TESTING PURPOSES ONLY. Opens a new browser window for
 *  email-a-friend application.
 *  	
 *---------------------------------------------------------------------------*/

    function emailafriend() {
        setTimeout("go_now()",0);
    }
    function go_now() {
        var currentSite = window.location.href;
        var url = "";
        if (currentSite.indexOf("-d6.xh1.lilly.com") >= 0) {
          url = "https://emailafriend-d6.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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

