
/*
	System configuration parameters
*/
var SERVLET_STRING = '/!redirect/';

var ABBOTT_FAMILY_SITES = new Array(
	"abbott.com",
	"abbott.hpd.info",
	"abbottdiabetescare.nl",
	"abbottdiagnostics.com",
	"abbottdiagnostics.nl",
	"abbottdrinkvoedingen.nl",
	"abbottlabs.nl",
	"abbottlogistics.nl",
	"abbottmedischevoeding.nl",
	"abbottmedischevoedingen.nl",
	"abbottnederland.nl",
	"abbottvoedingen.nl",
	"allesoverkankerenvoeding.com",
	"allesoverkankerenvoeding.nl",
	"allesovervoedingenkanker.com",
	"allesovervoedingenkanker.nl",
	"aluviran.nl",
	"anesthetica.nl",
	"artritispsoriatica.nl",
	"axsym.nl",
	"brufenbruis600.nl",
	"cd3700.nl",
	"cd4000.nl",
	"cd-sms.nl",
	"chirocaine.info",
	"chirocaine.nl",
	"cyclosporines.nl",
	"drinkvoedingen.nl",
	"edisco.nl",
	"erectiele-dysfunctie.info",
	"fero-gradumet.nl",
	"forene.nl",
	"gemstar.nl",
	"hospira.nl",
	"humira.nl",
	"humiracare.com",
	"humiracare.nl",
	"hytrin.nl",
	"procure.nl",
	"similac.nl",
	"inhalatie-anesthesie.nl",
	"kankerenvoeding.nl",
	"kanker-voeding.nl",
	"klacid.nl",
	"luchtweginfecties.info",
	"lucrin.nl",
	"medischevoedingen.nl",
	"medisense.nl",
	"memo-mail.nl",
	"norvir.nl",
	"obesitas.info",
	"pijnmanagement.info",
	"pijnmanagement.nl",
	"precedex.nl",
	"propofol.nl",
	"prosure.nl",
	"reductil.nl",
	"receptal.info",
	"regionaal-anesthesie.nl",
	"reumatoideartritis.nl",
	"rsvirus.nl",
	"sedatie.nl",
	"sevorane.nl",
	"simdax.nl",
	"similac.nl",
	"syna-care.nl",
	"synacare.nl",
	"synagis.nl",
	"voedingenkanker.com",
	"voedingenkanker.nl",
	"voedinginformatie.nl",
	"voedinginformatiecentrum.nl",
	"ziektevanbechterew.nl"
);

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('/fileadmin/templates/static/application/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");
}



