/* DORA - External Application JavaScript */

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : variables [ global ] */
// set basic variables to be used in functions below and in javascript w/in page
var hostStageAlias = '';

if ((window.location.hostname).indexOf('dev') != -1) hostStageAlias = '.dev.';
else if ((window.location.hostname).indexOf('stage') != -1) hostStageAlias = '.stage.';
else if ((window.location.hostname).indexOf('test') != -1) hostStageAlias = '.test.';
else if ((window.location.hostname).indexOf('uat') != -1) hostStageAlias = '.uat.';

var personCookieValue = getCookie("ORA_Person");
var userCookieValue = getCookie("ORA_User");
var contextCookieValue = getCookie("ORA_Context");
var loggedIn, preAuthenticated = false;
var CMEGlobalContext = "fkQAnXaGh978EU16Bomi+DRZEnXg9CYlnSiP+61E+lo=";

// evaluate global variables and reassign values if applicapable
if (personCookieValue && userCookieValue && contextCookieValue) {
	loggedIn = true;
	personCookieValue = decodeURIComponent(personCookieValue);
	userCookieValue = decodeBase64(decodeURIComponent(userCookieValue)); userCookieArray = userCookieValue.split("||");
	contextCookieValue = decodeURIComponent(contextCookieValue);
}
if (loggedIn && thisPageContext == contextCookieValue) { preAuthenticated = true; }

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : functions [ bounce ] */
function bounceUserToDORA() {
	var loggedInString = (loggedIn) ? "true" : "false";
// 	var bounceDORAURL = "http://my" + hostStageAlias + "discovery.com/?context=" + encodeURIComponent(CMEGlobalContext) + "&loggedin=" + loggedInString + "&network=CME&oncomplete=" + escape(window.location.href) + "&type=login";
	var bounceDORAURL = "http://ora" + hostStageAlias + "discovery.com/registration/continuing-medical-education/login.html?site=DORA&a=login&c=CME&oc=" + escape(window.location.href);
	window.location.href = bounceDORAURL;
}

if (loggedIn && !preAuthenticated) { bounceUserToDORA(); }
else if (!loggedIn) { bounceUserToDORA(); }

/* END DORA - External Application JavaScript */
