if (window.addEventListener) {
	window.addEventListener("load", legacyRedirector, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", legacyRedirector);
} else {
	var oldonload=window.onload;
	window.onload=function(){if(typeof(oldonload)=='function'){oldonload();}legacyRedirector()};
}

function createCookie2(name,value,days) {
	try {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else expires = "";
		
		var secure = location.protocol == 'https:' ? "; secure ": "";
		
		document.cookie = name+"="+value+expires+"; path=/"+secure;
	} catch(e) {
	}
}

function legacyRedirector() {
	var url = window.location.href;
	var regexp = new RegExp("(https?://)(contentstudio|serviceportal|infocenter|internetgateway)\.(.*?)/.*", "g");
	var exclude = new RegExp("(pearson|merckfod|packageTracking|pkgid)","gi");
	if (url.match(regexp) && !readCookie("WAMNET_LEGACY_ACCESS") && !url.match(exclude)) {
		if (document.getElementById('logout')) {
			//IG auto logins:
			alert("Please use the WAM!NET Portal at " + url.replace(regexp,'portal.$3') + " with your same authentication credentials or contact your administrator for a new auto login url.\n\nThe web site at " + url.replace(regexp,'$2.$3') + " will be retired on January 9, 2012.");
			createCookie2("WAMNET_LEGACY_ACCESS","1","1")
		} else {
			//phase 1:
			//alert("The web site at " + url.replace(regexp,'$2.$3') + " will be retired on January 9, 2012.\n\nPlease use the WAM!NET Portal at " + url.replace(regexp,'portal.$3') + " with your same authentication credentials.");
			//createCookie2("WAMNET_LEGACY_ACCESS","1","1")
			//phase 2 & 3:
			//alert("We are directing you to WAM!NET Portal.\n\nThe web site at " + url.replace(regexp,'$2.$3') + " will be retired on January 9, 2012.\n\nIf necessary you may return here to continue using this legacy interface by clicking the \"more\" link under the \"Retirement of Legacy Web Interfaces\" news item.");
			//createCookie2("WAMNET_LEGACY_ACCESS","1","7")
			//createCookie2("WAMNET_LEGACY_ACCESS","1","1")
			//window.location.href = url.replace(regexp,'//portal.$3/');
			//phase 3:
			alert("We are directing you to WAM!NET Portal.\n\nThe web site at " + url.replace(regexp,'$2.$3') + " was retired on January 9, 2012.");
			window.location.href = url.replace(regexp,'//portal.$3/');
		}
	}
}

