﻿// JScript File
prepLinks();

// Adds onClick events to all anchor tags that point to external links.
function prepLinks(){
var output;
  var anchorTags = document.getElementsByTagName('a');
  var anchor;
  for(var index = 0; index < anchorTags.length; index++){
    anchor = anchorTags[index];
    var location = anchor.href + '';
    if (location.length > 0){
		if (location.indexOf('enfaville.com') == -1 && location.indexOf('bms.com') == -1 && location.indexOf('enfamil.com') == -1 && location.indexOf('meadjohnson') == -1  && location.indexOf('mead-johnson') == -1  && location.indexOf('meadjohnson.com') == -1 && location.indexOf('lipil') == -1 && location.indexOf('GrantRequest.com') == -1 && location.indexOf('grantrequest.com') == -1 && location.indexOf('mjn.com') == -1 && location.indexOf('talkpoint.com') == -1)
			attachEvent('click', anchor, doExternalLinkPopup );
    }
  }
}

// Prompts whether or not user wants to exit page
function doExternalLinkPopup(e, i){
    e = (e) ? e : window.event;
    
    var answer = confirm('This link will take you out of the Mead Johnson Nutritionals website and to the website of an entity that is not related to Mead Johnson & Company.  Mead Johnson & Company does not have any control over nor responsibility for such other entity or the content of the website.  Providing a link to the other site does not necessarily imply endorsement of some content on the site. ');
    if (!answer && e.preventDefault)
      e.preventDefault();  // Works for DOM
    return answer; // Works for IE
}

// Attaches an event in either the DOM or IE Model, whichever is appropriate
function attachEvent(eventType, element, method){
   if (document.addEventListener) // DOM Model
    element.addEventListener(eventType, method, true);
  else if (document.attachEvent)  // IE Model
    element.attachEvent('on' + eventType, method);
 
}

function leaveSite(site,destination) {
        var msg = 'This link will take you out of the Mead Johnson Nutritionals website and to the website of an entity that is not related to Mead Johnson & Company.  Mead Johnson & Company does not have any control over nor responsibility for such other entity or the content of the website.  Providing a link to the other site does not necessarily imply endorsement of some content on the site.';
                
        if (confirm(msg) == 1) 
        {
	        if(destination == "internal")
			{
				window.open(site, 'related','toolbar=yes,width=800,height=500,directories=no,status=no,scrollbars=yes,resizable=yes,menubar=yes,location=yes');
			}
			else
			{
				window.location.href=site;
			}
        }
}