
/*
	System configuration parameters
*/
var SERVLET_STRING = '/!redirect/';

var ABBOTT_FAMILY_SITES = new Array("alphatrakmeter", "phx.corporate-ir.net", "jobs.brassring.com", "chad004v5358", "rxabbott.com", "diabeteshealthconnection.com", "therasense.com", "welcomeaddition.com", "glucerna-precision.com", "prosure.com", "spinalconcepts.com", "abbottvirology.com", "ensure.com", "prevacid.com", "humira.com", "lupron.com", "licensing.abbott.com", "norvir.com", "fibroids.info", "endofacts.com", "tap.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", "ensurehealthymom.com", "lupron.com", "welcomeaddition.com", "toosoon.com", "omnicef.com", "meridia.net", "spinalconcepts.com", "biaxin.com", "depakote.com", "glucerna.com", "biaxinxl.com", "omnicefcapsules.com", "abbottvascular", "abbottnutrition.ca", "freestylelite.com", "xiencev.com", "continuousmonitor.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('/en_CA/application/html/confirmExternalLink.htm','confirm','width=420,height=280,resizable=yes').focus();
}

function showProductSiteConfirmation(url) {
	targetUrl = url;
	window.open('/en_US/application/html/confirmProductSiteLink.htm','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");
}



