
/*
	System configuration parameters
*/
var SERVLET_STRING = '/!redirect/';

var ABBOTT_FAMILY_SITES = new Array("abbott", "phx.corporate-ir.net", "jobs.brassring.com", "chad004v5358", "rxabbott.com", "diabeteshealthconnection.com", "diabeteshealthconnection.com", "therasense.com", "welcomeaddition.com", "glucerna-precision.com","glucerna","glucerna.com","prosure.com","spinalconcepts.com","abbottvirology.com","ensure.com","prevacid.com","humira.com","lupron.com","licensing.abbott.com","norvir.com","fibroids.info","endofacts.com","zemplar.com","tricorx.com","synthroid.com","urovysion.com","tricortablets.com","survanta.com","pediasure.com","tanzaniacare.org","stepforwardforchildren.org","i-stat.com","juven.com","candowithra.com","medisense.com","omnicefforkids.com","isomiladvance.com","isomiladvancecontest.com","zemplar.com","diabetesfreedom.com","diabetesnow.co.uk","medisense.ch","cybergrants.com","ra.com","depakote.com","tanzaniacare.org","stepforwardforchildren.org","norvir.com","kaletra.com","abbottdiabetescare.com","ensurehealthymom.com","lupron.com","welcomeaddition.com","abbottdiabetescare.com","toosoon.com","omnicef.com","meridia.net","spinalconcepts.com","biaxin.com","depakote.com","glucerna.com","biaxinxl.com", "omnicefcapsules.com", "diabetescontrolforlife.com", "labsarevital.com", "similac","continuousmonitor.com","e-mediaroom.com","eas.com","zoneperfect.com","rpdsurveys.com","xiencev.com","xiencemediakit.com", "crohnsonline.com","niaspan.com");

var debug=false;
						
/* 
	End of the system configuration parameters
*/
						

/* Only update the link if we're supposed tof
	1. It starts with http
	2. The URL doesn't point to an Abbott Family site.
*/
function isUpdateCandidate(url) {
	url = url.toLowerCase();
	if (url.substring(0, 4) == 'http') {
		for (i=0; i<ABBOTT_FAMILY_SITES.length; ++i) {
			if (url.indexOf(ABBOTT_FAMILY_SITES[i]) > -1) {
				return false;
			}
		}
		
		return true;
	} 
	
	return false;
}

var targetUrl;
function showConfirmation(url) {
	targetUrl = url;
	window.open('/static/application/html/confirmExternalLink.html','confirm','width=420,height=280,resizable=yes').focus();
}

function showProductSiteConfirmation(url) {
	targetUrl = url;
	window.open('/static/application/html/confirmProductSiteLink.html','confirm','width=420,height=280,resizable=yes').focus();
}

function processLink(tag)
{
	var url = tag.getAttribute('href');

	if (!url || url=="" || url.length==0) return;

	if (isUpdateCandidate(url)) {
		/* 
			First, add an onClick event to the link
		*/
		tag.setAttribute('href', "javascript:showConfirmation('" + url + "');");
		tag.onmouseover = function() {status=url; return true;};
		tag.onmouseout = function() {status=defaultStatus; return true;};
	} 
}



/* 
	1. Iterate through every link AND form action on the page.
	2. If their HREF or ACTION does not contain "_pageLabel", add "_pageLabel=$CURRENT_PAGE"
*/
function updateLinks() {

 if (debug) alert("Starting updateLinks function");

  // Find any link tags and grab their content
  tgs = document.getElementsByTagName('a');
  if (!tgs) return;
  for (var i=0;i<tgs.length;i++) {
	processLink( tgs[i] );
  }	
// Finally, if this is on development, update all of the image tags
if (location.href.toLowerCase().indexOf('dev.abbott.com') != -1) {
  tgs = document.getElementsByTagName('img');
  for (var i=0;i<tgs.length;i++) {
        if (tgs[i].src.indexOf('acs')==-1 ) {
                tgs[i].src = ('http://wip-d.abbott.com'+tgs[i].src.substring(21, tgs[i].src.length) );
        }
  }
}

  
  if (debug) alert("Finished updateLinks function");
}



