/////////////////////////////////////////////////////////////////////////////////////// 
var _bpDev = new BpDev();


///////////////////////////////////////////////////////////////////////////////////////
function BpDev() {
	this._debug = true;
	this.isDebug = __isDebug;

	function __isDebug() {
		return this._debug;
	}


}


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];}}
}

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;
}

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;
}

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);
}

// Toggels 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) {
	
	if (_bpDev.isDebug()) {
		if (targetImageName == null || newImgSource == null || targetImageName == "" || 
			newImgSource == "") {
			alert("Error : toggleImage : targetImageName parm or newImgSource parm is null or empty.");
		}
	}
	document.images[targetImageName].src = newImgSource;
}


function thirdParty(theURL) { 
	var myURL = "/interstitials/3rd_party.jsp?redirect="+encodeUrl(theURL);
	window.open(myURL,'myWin','scrollbars=yes, width=450,height=400');
}

function allianceLink(theURL) { 
	var myURL = "/interstitials/alliance_link.jsp?redirect="+encodeUrl(theURL);
	window.open(myURL,'myWin','scrollbars=yes, width=450,height=400');
}

function thirdPartySpa(theURL) { 
	var myURL = "/interstitials/3rd_party_spa.jsp?redirect="+encodeUrl(theURL);
	window.open(myURL,'myWin','scrollbars=yes, width=450,height=400');
}

function encodeUrl(url) {
	return escape(url);
}

function withinLilly(theURL){
	var myURL = "/interstitials/within_lilly.jsp?redirect="+theURL;
	window.open(myURL,'myWin','scrollbars=yes, width=400,height=350');
}

function withinLillyTFI(theURL){
	var myURL = "/interstitials/within_lilly_tfi.jsp?redirect="+theURL;
	window.open(myURL,'myWin','scrollbars=yes, width=400,height=350');
}

function withinLillySpa(theURL){
	var myURL = "/interstitials/within_lilly_spa.jsp?redirect="+theURL;
	window.open(myURL,'myWin','scrollbars=yes, width=400,height=350');
}

function disclaimerHCP(theURL){
	var myURL = "/interstitials/lillydiabetes_hcp.jsp?redirect="+theURL;
	window.open(myURL,'myWin','scrollbars=yes, width=450,height=360');
}

// Swap Image Script

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;
}
function MM_nbGroup(event, grpName) { //v6.0
var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

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];}}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


// Email a Friend Script

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');
}

//Autotmatic updating copyright year in footer files.
function copyear() {
	dt = new Date();
	var str = dt.getFullYear()
	document.write(str)
	}

//below is the hash table for inline linking

var myHashTable = new Object();

/////////////////// S P A N I S H   S E C T I O N  /////////////////// 

//section 1 - About Diabetes
myHashTable['/spa/about_diabetes/about_diabetes.jsp'] = '1.0';
myHashTable['/spa/about_diabetes/diabetes_basics.jsp'] = '1.1';
myHashTable['/spa/about_diabetes/types_of_diabetes.jsp'] = '1.1.1';
myHashTable['/spa/about_diabetes/symptoms_of_diabetes.jsp'] = '1.1.2';
myHashTable['/spa/about_diabetes/how_treated.jsp'] = '1.1.3';
myHashTable['/spa/about_diabetes/goals_targets.jsp'] = '1.1.4';
myHashTable['/spa/about_diabetes/support.jsp'] = '1.1.5';
myHashTable['/spa/about_diabetes/blood_sugar_testing.jsp'] = '1.2';
myHashTable['/spa/about_diabetes/food_nutrition.jsp'] = '1.3';
myHashTable['/spa/about_diabetes/different_foods.jsp'] = '1.3.1';
myHashTable['/spa/about_diabetes/how_much.jsp'] = '1.3.2';
myHashTable['/spa/about_diabetes/exercise.jsp'] = '1.4';
myHashTable['/spa/about_diabetes/highs_lows.jsp'] = '1.5';
myHashTable['/spa/about_diabetes/staying_healthy.jsp'] = '1.6';
myHashTable['/spa/about_diabetes/care_guidelines.jsp'] = '1.6.1';
myHashTable['/spa/about_diabetes/talking_with_team.jsp'] = '1.6.2';
myHashTable['/spa/about_diabetes/taking_care.jsp'] = '1.6.3';
//section 2 - About Insulin
myHashTable['/spa/about_insulin/about_insulin.jsp'] = '2.0';
myHashTable['/spa/about_insulin/what_is_insulin.jsp'] = '2.1';
myHashTable['/spa/about_insulin/what_type.jsp'] = '2.2';
myHashTable['/spa/about_insulin/what_will_i_use.jsp'] = '2.3';
myHashTable['/spa/about_insulin/deciding_to_take.jsp'] = '2.4';
//common pages
myHashTable['/spa/common_pages/site_map.jsp'] = '';
myHashTable['/spa/common_pages/resources.jsp'] = '';
myHashTable['/spa/common_pages/ask_lilly.jsp'] = '';
myHashTable['/spa/common_pages/safety_information.jsp'] = '';



//function name: getNavId
//function: called from getID, takes in page name, returns pageNavId	
//function name: getNavId
//function: called from getID, takes in page name, returns pageNavId	
function getNavId (whatPage) {
	var myNavId = myHashTable[whatPage];
	return myNavId;
}
//function name: getID
//function: is called from the links in order to call getNavId function and determine the links navigation ID
function getID(pageName) {
	//only capture up to the .jsp", and do not capture characters after
	//getDot returns the number where the dot hits
	var getDot = pageName.indexOf('.');
	//add 4 to get dot to get the first char after the dot
	getDot+=4;
	var newString = pageName.substring(0,getDot);
	var appendString = pageName.substring(getDot);
	var appendMe = getNavId(newString);
	if(appendMe!=''){
		var finalURL = newString + "?reqNavId=" + appendMe + appendString;
	}else{
		var finalURL = pageName + appendString;
	}
	window.location.href = finalURL;
}


