/*=============================================================================================
--       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
=============================================================================================*/

$(document).ready(function() {

  $('UL.content LI > SPAN').addClass('ieLIfix');
  $('H4 + P').addClass('PafterH4');

});



$(function(){
	$('IMG[src="/images/000.jpg"]').click(function(){
		window.open(this.href);
		return false;
	});
});



/*===================================
-- 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 Email a Friend function
====================================*/

function eaf(){
	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 text sizing functions
====================================*/
//Resets all the text-size images and sets the correct font
function styleSizer(whichStyle){
	//reset all the images
	
	//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=="regularFont"){
		setActiveStyleSheet('regularFont'); 
		MM_swapImage('smallTextButton','','/images/text_small_selected.gif',1);
	}else if(whichStyle=="largerFont"){
		setActiveStyleSheet('largerFont');
		MM_swapImage('mediumTextButton','','/images/text_medium_selected.gif',1);
	}else if(whichStyle=="largestFont"){
		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(\'regularFont\');"><img src="/images/text_small_selected.gif" alt="Small text" id="smallTextButton" name="smallTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\');"><img src="/images/text_medium.gif" alt="Medium text" id="mediumTextButton" name="mediumTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\');"><img src="/images/text_large.gif" alt="Large text" id="largeTextButton" name="largeTextButton" width="21" height="25" style="padding-right: 1px;" /></a>');
	}else if(title=='largerFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\');"><img src="/images/text_small.gif" alt="Small text" id="Img1" name="smallTextButton" width="17" height="25" style="padding-right: 1px;"  /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\');"><img src="/images/text_medium_selected.gif" alt="Medium text" id="Img2" name="mediumTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\');"><img src="/images/text_large.gif" alt="Large text" id="Img3" name="largeTextButton" width="21" height="25" style="padding-right: 1px;" /></a>');
	}else if(title=='largestFont'){
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\');"><img src="/images/text_small.gif" alt="Small text" id="Img4" name="smallTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\');"><img src="/images/text_medium.gif" alt="Medium text" id="Img5" name="mediumTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\');"><img src="/images/text_large_selected.gif" alt="Large text" id="Img6" name="largeTextButton" width="21" height="25" style="padding-right: 1px;" /></a>');
	}else{
		return('<a href="#" onClick="javascript:styleSizer(\'regularFont\');"><img src="/images/text_small_selected.gif" alt="Small text" id="Img7" name="smallTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largerFont\');"><img src="/images/text_medium.gif" alt="Medium text" id="Img8" name="mediumTextButton" width="17" height="25" style="padding-right: 1px;" /></a><a href="#" onClick="javascript:styleSizer(\'largestFont\');"><img src="/images/text_large.gif" alt="Large text" id="Img9" name="largeTextButton" width="21" height="25" 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);
var curURL = window.location.href;
if (curURL.indexOf("/interstitial") <= 0)
document.onmousemove=followmouse;
	if(strPageName.indexOf('interstitial.jsp') > 0 )
{
	//alert('tracking interstitial.');
dcsMultiTrack('DCS.dcsuri', strPageName, 'WT.ti', 'exit_link_Interstitial');
}
else if(strPageName.indexOf('vidplayer.jsp') > 0)
{
	//alert('tracking ltoutVidPlayer.' + strPageName);
dcsMultiTrack('DCS.dcsuri', strPageName, 'WT.ti', 'leftTout_VidPlayer_Click');
}
else if(strPageName.indexOf('\/dictionary.jsp') > 0)
{
	//alert('tracking Dictionary. ' + strPageName);
dcsMultiTrack('DCS.dcsuri', strPageName, 'WT.ti', 'Diabetes_Dictionary_click');
}
}
//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;
	var strPrintURL = strPageName.replace("\/", "_");
	launchTrackWindowHTML('', '', '', 'PrintPage', 'PrintPage_' + strPageName);
	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 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
====================================*/

//Pop Tracking Window 0) Domain 1) Path 2) window name 3) Tracking name

var pgURL = new String(window.location.href);
var strPageName = new String("");

var testInt = pgURL.indexOf('lillydiabetesbp2-d6.xh1.lilly.com');

//alert("pgURL.indexOf value is: " + testInt);

if(pgURL.indexOf('lillydiabetesbp2-d6.xh1.lilly.com') > 0)
{
    strPageName = pgURL.replace('http://lillydiabetesbp2-d6.xh1.lilly.com', '');
}
else if(pgURL.indexOf("lillydiabetesbp2-qa.xh1.lilly.com") > 0)
{
    strPageName = pgURL.replace('http://lillydiabetesbp2-qa.xh1.lilly.com', '');
}
else
{
    strPageName = pgURL.replace('http://www.lillydiabetes.com', '');
}

function launchTrackWindow() 
{
	//alert("calling track window");
    var windowArgs = launchTrackWindow.arguments;
	//alert(windowArgs[1]);
    
    var finalURL = '';
        if( windowArgs[0].length > 0 ) {
            dcsMultiTrack('DCS.dcssip', windowArgs[0], 'DCS.dcsuri', windowArgs[1], 'WT.ti', windowArgs[3]);
            finalURL = 'http://' + windowArgs[0] + windowArgs[1];
	    window.open( finalURL, windowArgs[2]);
        }
        else if( windowArgs[1].length > 0 && windowArgs[1] != 'undefined' ) {
            dcsMultiTrack('DCS.dcsuri', windowArgs[1], 'WT.ti', windowArgs[3]);
            finalURL = windowArgs[1];
	    window.open( finalURL, windowArgs[2]);
        }
	else
	{
	   dcsMultiTrack('DCS.dcsuri', 'FlashTrack', 'WT.ti', windowArgs[3]);
	}
	//alert(windowArgs[3]);

}

//Pop Tracking Window 0) Domain 1) Path 2) window name 3) Tracking name


function launchTrackWindowHTML() 
{
	//alert("calling track window");
    var windowArgsHTML = launchTrackWindowHTML.arguments;
	//alert(windowArgsHTML[1]);

    var finalURL = '';
    if( windowArgsHTML[0].length > 0 ) {
        dcsMultiTrack('DCS.dcssip', windowArgsHTML[0], 'DCS.dcsuri', windowArgsHTML[1], 'WT.ti', windowArgsHTML[3]);
        finalURL = windowArgsHTML[0] + windowArgsHTML[1];
        //alert(windowArgsHTML[3]);
        if(windowArgsHTML.length > 4){
        	window.open( finalURL, windowArgsHTML[2], windowArgsHTML[4]);
	}
	else{
		window.open( finalURL, windowArgsHTML[2]);
	}
	    return false;
    }
    else if( windowArgsHTML[1].length > 0 && windowArgsHTML[1] != 'undefined' ) {
        dcsMultiTrack('DCS.dcsuri', windowArgsHTML[1], 'WT.ti', windowArgsHTML[3]);
        finalURL = windowArgsHTML[1];
        //alert(windowArgsHTML[3]);
	if(windowArgsHTML.length > 4){
        	window.open( finalURL, windowArgsHTML[2], windowArgsHTML[4]);
	}
	else{
		window.open( finalURL, windowArgsHTML[2]);
	}
	    return false;
    }
	else
	{
	   dcsMultiTrack('DCS.dcsuri', windowArgsHTML[4], 'WT.ti', windowArgsHTML[3]);
	   //alert('Tracking' + windowArgsHTML[3] + ' ' + windowArgsHTML[4] );
	   return false;
	}
	//alert('Tracking parameters not met, should not get here.');
}


function fnToggleRecipes(objItem)
{
	//alert(objItem);
	for( i=0; i< 13; i++)
    {
	//alert(i);
        if(objItem == i)
        {
           document.getElementById('arrow' + i).src = '/images/redArrowDown.gif';
           document.getElementById('recipe' + i).style.display = 'block';
        }
        else
        {
           document.getElementById('arrow' + i).src = '/images/grayArrow.gif';
           document.getElementById('recipe' + i).style.display = 'none';
        }
    }
    
    var recipeName = new String('');
    
    switch (objItem.toString())
    {
    case '1':
        recipeName = 'select_entree_chicken_spinach_salad';
        break;
    case '2':
        recipeName = 'select_entree_shrimp_garlic';
        break;
    case '3':
        recipeName = 'select_entree_sirloin_tips';
        break;
    case '4':
        recipeName = 'select_entree_glazed_pork_chops';
        break;                        
    case '5':
        recipeName = 'select_entree_enchilada_casserole';
        break;
    case '6':
        recipeName = 'select_entree_chicken_stir_fry';
        break;
    case '7':
        recipeName = 'select_entree_blacked_halibut';
        break;
    case '8':
        recipeName = 'select_dessert_cheesecake';
        break;
    case '9':
        recipeName = 'select_dessert_banana_bread';
        break;
    case '10':
        recipeName = 'select_dessert_cchip_cookies';
        break;
    case '11':
        recipeName = 'select_dessert_oatmeal_cookies';
        break;
    case '12':
        recipeName = 'select_dessert_mocha_smoothie';
        break;                
    }
	//alert('Recipename is: ' + recipeName);
    launchTrackWindowHTML('','','','Diabetes-Friendly-Recipes_clicked', recipeName );
}

function eaf() 
{
	var currentSite = window.location.href;
        var url = '';
        var url2 = '';
        url2 = strPageName.replace("/", "_");
        url2 = url2.replace(".jsp", "");
        launchTrackWindowHTML('', '', '', 'Email_A_Friend', 'EmailFriend_click' + url2);
  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 closeMe()
{
	//alert('being called');
	self.parent.Shadowbox.close();
}

function storeMyVote( objVote )
{
	//alert('Value voted is: ' + objVote);
    var voteURL = new String(window.location.href);
    var strVoteURL = new String('');

    if(voteURL.indexOf("lillydiabetesbp2-d6.xh1.lilly.com") > 0)
        strVoteURL = voteURL.replace("http://lillydiabetesbp2-d6.xh1.lilly.com", "");
    else if(voteURL.indexOf("lillydiabetesbp2-qa.xh1.lilly.com") > 0)
        strVoteURL = voteURL.replace("http://lillydiabetesbp2-qa.xh1.lilly.com", "");
    else
    {
        if(voteURL.indexOf("www.lillydiabetes.com") > 0)
            strVoteURL = voteURL.replace("http://www.lillydiabetes.com", "");
        else
            strVoteURL = voteURL.replace("http://lillydiabetes.com", "");
    }
    if(strVoteURL.indexOf("?") > 0)
    {
        var stripInt = strVoteURL.indexOf("?");
        strVoteURL = strVoteURL.substring(0, stripInt);    
    }
	//alert("Storing Session Cookie URL: " + strVoteURL + " with vote: " + objVote);

    createCookie(strVoteURL, objVote);
}

function getMyVote()
{
	//alert(window.location.search.substring(0));
	//alert('Value voted is: ' + objVote);
    var prevURL = new String(window.location.href);
    var strPvoteURL = new String('');

    if(prevURL.indexOf("lillydiabetesbp2-d6.xh1.lilly.com") > 0)
        strPvoteURL = prevURL.replace("http://lillydiabetesbp2-d6.xh1.lilly.com", "");
    else if(prevURL.indexOf("lillydiabetesbp2-qa.xh1.lilly.com") > 0)
        strPvoteURL = prevURL.replace("http://lillydiabetesbp2-qa.xh1.lilly.com", "");
    else
    {
        if(prevURL.indexOf("www.lillydiabetes.com") > 0)
            strPvoteURL = prevURL.replace("http://www.lillydiabetes.com", "");
        else
            strPvoteURL = prevURL.replace("http://lillydiabetes.com", "");
    }	
    if(strPvoteURL.indexOf("?") > 0)
    {
        var stripInt = strPvoteURL.indexOf("?");
        strPvoteURL = strPvoteURL.substring(0, stripInt);    
    }
	var intPVote = readCookie(strPvoteURL);
	//alert("Previous vote was: " + intPVote );
	if(intPVote != null)
		return intPVote;
	else
		return "";
}


//Image rollover
//image filenames must be in the format 'filename.ext' and 'filename-on.ext'

Rollover = function()
{
	//empty constructor
}

//Static function turns on the rollover image
Rollover.turnOn = function(element)
{
	//Get the image element
	var img = element;

	//Get the filename portion minus the extension
	var filename = img.src.substr(0, img.src.lastIndexOf('.'));

	//Get the extension portion
	var extension = img.src.substr(img.src.length - 4, 4);

	//insert '-on' between the filename and extension and set it as the new src
	img.src = filename + '-on' + extension;
}

//Static function turns off the rollover image
Rollover.turnOff = function(element)
{
	// //Get the image element
	var img = element;

	//Get the filename portion minus the extension, also removed the '-on'
	var filename = img.src.substr(0, img.src.lastIndexOf('.') - 3);

	//Get the extension portion
	var extension = img.src.substr(img.src.length - 4, 4);

	//Set the combined name as the new img src
	img.src = filename + extension;
}

//Download PDFs of Different Languages
function dlPDF( objTar )
{
	var tarObj = document.getElementById(objTar);
	//alert( tarObj.selectedIndex );
	if(tarObj.selectedIndex != 0)
	{
		if(tarObj.value != '')
		{
			//alert( tarObj.value );
			dcsMultiTrack('DCS.dcsuri', tarObj.value, 'WT.ti', 'Downloadable Materials');
			window.open( tarObj.value, 'pdfDL');
		}
		else
			alert('No PDF to download yet.');
	}

}

