/*
Title:	linkTo.ja
Author: Dower Chin
Date:	09/17/2008
Description:
	This js library was made to handle calls to the LinkTo application for the new single site
	identity project for the new portal landing pages. 
	The js determines what environment to send the user to based upon the URL of the calling
	page.

	-06/18/2009 - Rich Waltein: Modified top case statement to handle all of the unit test environments correctly.

	-07/02/2009 - Rich Waltein: Modified exstensively for the Security Platform project. Only two methods needed now.
	
	-10/22/2009 - Gus Weloth: Modified for missing SelectCare ports and missing goToEService function. A lot of stuff that  
	              is in the PROD version has never made it back to the UNIT & ITS versions.

	-05/26/2010 - Nate Preston - updated links to providers search for PRISM Phase 1

*/

urlBase = "";
preferredcareBase = "";
providerSearchBase = "";
staticContentBase = "";
eServiceportalBase = "";
curBase = location.host;
portalServerBase = "";
selectCareBase = "";
isProd = false;

// DEV
if (curBase == "localhost:88"
 || curBase == "localhost:90"
 || curBase == "localhost:100"
 || curBase == "localhost"
 || curBase == "localhost:8988")
{
	urlBase = "http://localhost:9080/";
	preferredcareBase = "http://localhost:8988/";
	staticContentBase = "http://" + location.host + "/";
	portalServerBase = "http://localhost/";
	selectCareBase = "http://al5was03:9086/";
    	providerSearchBase = "http://localhost/Mlogic/mvp/";
}

// UNIT
else if (curBase == "wwwunit.mvpselectcare.com" || 
	 curBase == "wwwunitdev.mvpselectcare.com" || 
	 curBase == "al5cfsch01:88" || 
	 curBase == "mdunit:88" || 
	 curBase == "mdunit" || 
	 curBase == "wwwtest.preferredcare.org" || 
	 curBase == "mdunit:89" || 
	 curBase == "mdunit:101")
{	
	urlBase = "https://sm5ts01/";
	preferredcareBase = "http://wwwtest.preferredcare.org/";
	providerSearchBase = "http://al5cfsch01/";
	staticContentBase = "http://" + location.host + "/";
	eServiceportalBase = "https://sm5ts01/member/tzg/eservice/";
}

// ITS
else if (curBase == "al4cfsch01:89"
	 || curBase == "wwwits.mvpselectcare.com" || curBase == "wwwits2.mvpselectcare.com" || curBase == "wwwits3.mvpselectcare.com" 
	 || curBase == "al4cfsch01:89" || curBase == "mdits"
	 || curBase == "al6cfsch01:89" || curBase == "mdits2"
	 || curBase == "al7cfsch01:89" || curBase == "mdits3")
{
	if (curBase == "al4cfsch01:89" || 
	    curBase == "mdits" || 
	    curBase == "wwwits.mvpselectcare.com") 
	{ 
		urlBase = "https://sm4ts01/";
		providerSearchBase = "http://al4cfsch01/";
		eServiceportalBase = "https://sm4ts01/member/tzg/eservice/";
	} 
	else if (curBase == "al6cfsch01:89" || 
		 curBase == "mdits2" || 
		 curBase == "wwwits2.mvpselectcare.com") {
		urlBase = "https://sm4ts04/";
		providerSearchBase = "http://al6cfsch01/";
		eServiceportalBase = "https://sm4ts04/member/tzg/eservice/";
	}
	else if (curBase == "al7cfsch01:89" || 
		 curBase == "mdits3" || 
		 curBase == "wwwits3.mvpselectcare.com") {
		urlBase = "https://sm4ts07/";
		providerSearchBase = "http://al7cfsch01/";
		eServiceportalBase = "https://sm4ts07/member/tzg/eservice/";
	}
	preferredcareBase = "http://wwwtest.preferredcare.org/";
	staticContentBase = "http://" + location.host + ":88/";
}

// ACC
else if (curBase == "mdacc" 
	  || curBase == "mdacc:88"
	  || curBase == "mdacc:89"
	  || curBase == "wwwacc.mvphealthcare.com"
	  || curBase == "cfusionx" 
	  || curBase == "wwwstage.preferredcare.org:4444")
{
	urlBase = "https://swt.mvphealthcare.com/";
	preferredcareBase = "https://wwwstage.preferredcare.org:4444/";
	providerSearchBase = "http://al3cfsch01/";
	staticContentBase = "http://mdacc:88/";
	eServiceportalBase = "https://swt.mvphealthcare.com/member/tzg/eservice/";
}

// External ACC
// DZC - 08-11-2009 : added in for external ACC confirmation of level 3 content
else if (curBase == "76.12.47.147")
{
	urlBase = "https://swt.mvphealthcare.com/";
	preferredcareBase = "https://wwwstage.preferredcare.org/";
	providerSearchBase = "http://al3cfsch01/";
	staticContentBase = "http://76.12.47.147/";
}

// PROD
else
{
	urlBase = "https://swp.mvphealthcare.com/";
	preferredcareBase = "https://www.preferredcare.org/";
	staticContentBase = document.location.protocol + "//www.mvphealthcare.com/";
	providerSearchBase = "http://cfusion.mvphealthcare.com/";
	eServiceportalBase = "https://swp.mvphealthcare.com/member/tzg/eservice/";
	isProd = true;
	selectCareBase = "https://swp.mvphealthcare.com/";
}

/*** 
Function: 	linkTo
Author: 	Dower Chin
Date:		09/17/2008
Description:
	function that performs the call to the LinkTo application for Tivoli legacy
	applications. The call can be made normally, but this function was needed
	because we wanted to the call to dynamically determine which server environment 
	to go to.
*/
function linkTo(params)
{
		this.location = urlBase + "legacysso/LinkTo/LinkTo?" + params;
}

/***
Function: 	loadFrame
Author: 	Dower Chin
Date:		09/17/2008
Description:
	This function simple takes tha name of an iframe to load a web page to.
	The function was needed, mainly for dynamically loading the login frame
	from whichever environment was running the app.

	Update: 10/13/2009 - DZC
		Modified the function call to replace the login iFrame
		with a call to a CFM file which does a pre-check of the 
		destination to determine if it's available before 
		actually sending the user there.

		NOTE, I had to make an exception for all environments other than PROD.
		It appears that CF5 doesn't support the CFHTTP method of HEAD...
		Feb 4  removed isProd section as it is causing  problems and manual intervention 
		is required in the event of an outage
*/
function loadFrame(frame, target)
{

		frames[frame].location.replace(urlBase + target);

}

/*** 
Function: 	goToRegistration
Author: 	Dower Chin
Date:		07/07/2009
Description:
	function that is used to send users to the appropriate registration page for
	Kodak and WWLW.
*/
function goToRegistration(params)
{
	this.location = urlBase + "registration/register/?type=" + params;
}

/***
Function: 	linkToIKA
Author: 	Dower Chin
Date:		09/17/2008
Description:
	Similar function to the others, but used for linking to the various IKA environments.
*/
function linkToIKA()
{
	this.location= urlBase + "init/welcome/redirect.jsp";
}

/***
Function: 	goToProviderSearch
Author: 	Dower Chin
Date:		4/14/2009
Description:
	Function to send user to the appropriate Provider Search based upon environment the client web page is running from.
	The target of this function is for the header "Provider Search" link.
*/
function goToProviderSearch(target)
{		  
	if (target.indexOf('rx') == 0)
	{									 
		top.location = providerSearchBase + target;
	}
	else	   
    	{
    		// Provider search on Prism should open in new window
		goToProviderSearchWindow(target.toLowerCase());
    	}
}


/***
Function: 	goToProviderFunction
Author: 	Dower Chin
Date:		11/5/2008
Description:
	Similar function to the others, but used for linking to the various Provider functions
	in the various environments.
*/
function goToProviderFunction(mvpTarget, pcTarget)
{
	this.location = urlBase + mvpTarget;
}

/***
Function:   goToEService(target)
Author: 	Brian Bedard
Date:		05/07/2009
Description:
	This function is called when a user clicks on a level 4 link (in grey box) in member selectcare. It will send you to the proper link in eservice
*/
function goToEService(target)
{
	if (isProd)
	{
		this.location = "https://www.mvpselectcare.com/loginFrame.cfm?dest=" + eServiceportalBase + target;
	}
	else
	{
		this.location = eServiceportalBase + target;
	}
}


/* OLD FUNCTION FOR PC linkTo.js, Adding just in case we need it again */
function setBasePath(base, target)
{
	this.location = base + target;
}

function loadLogInImage()
// Rich Waltein
// 12/01/2009
// This function is called by the member pages to display a Logged In message if the use has been authenticated by 
// webseal. If not, an error will occur and it will display a Logged off message by calling loadLogOffImage().
// This is used by getHomePage() to determine whether the use should be brought to their HDHP landing page or the static
// content index.html page.
{

	var html = 	urlBase + "legacysso/hdhp/images/login_message.gif?random=" + Math.random();  //random() is to prevent caching.
	document.write("<img id='login_image' src='" + html + "' onerror='loadLogOffImage();' />");

}

function loadLogOffImage() 
// Rich Waltein
// 12/01/2009
// This function is called if the user is not logged in will display a logged out message.
{

	document.getElementById('login_image').src="../images/logout_message.gif"; 

}

function getHomePage()
// Rich Waltein
// 12/01/2009
// This function decides whether user should go to their HDHP landing page if they are logged in or the static content
// index.html page if they are not.
{
	
	var image = document.getElementById('login_image').src;

	if (image.indexOf("logout") > -1)
	{
		this.location = "../member/index.html";
	}
	else
	{
		this.location = urlBase + "legacysso/hdhp/home.do";
	}
}

// Dower Chin
// 3/1/2010
// Function is used to open a mvphealthcare.com location in a new window.
// This function was lost somehow, and is being readded to fix the Careers link in
// the site header.
function goToMVPLocationInWindow(target)
{
	window.open(staticContentBase + target);
}

/***
Function:  goToProviderSearchWindow
Author:  Dower Chin
Date:  5/12/2009
UPDATE: 3/1/2010 - Somehow this function went missing... Readded.
Description:
 Same function as above, but only opens the page in a new window.
*/
function goToProviderSearchWindow(target)
{				
	dcsMultiTrack('DCS.dcssip','www.mvphealthcare.com','DCS.dcsuri','/providersearch.html'); 
	window.open(providerSearchBase + target.toLowerCase());
}

