// JavaScript Document

// 2010.01.13 KJD: Set up globals
var sitePages = new Object({
		'zipCode'	: "/about/zipCode.jsp",
		'shopping'	: "/individual/medical/index.jsp"
		//'shopping'  : "/products/medical/index.jsp"
	});

function getCookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}	

function callSearch()
{
	var query = document.getElementById("textfield").value;
	planCode=getCookie ("PLANCODE");
	var collection="dotCom_all";
	switch (planCode){	
		case "ID":
			collection="dotCom_id";
			break;
		case "UT":
			collection="dotCom_ut";
			break;
		case "OR":
			collection="dotCom_or";
			break;
		case "WARBS":
			collection="dotCom_wa";
			break;
		case "BOEING":
			collection="dotCom_wa";
			break;
		default :
			collection="dotCom_all";
			break;
		}
	document.location="http://www.regence.com/about/search.jsp?query=" + query + "&collection=" +collection;
}

/* revised 11/18/2008 */
function getParameter( parameterName ) {
  var queryString = window.location.search.substring(1).toLowerCase();
  var parameters = new Array();
  parameters = queryString.split('&')
  for(var i = 0; i < parameters.length; i++) {
   	var key = parameters[i].split('=')
	if (key[0] == parameterName.toLowerCase())
      return key[1];
  }
  return "null";
}
function goToArea(plan,site)
{
	window.location.replace('http://www.' + plan + '.regence.com/' + site + '/');
}

function gotoQCSI(plan)
{
	//window.open("https://www.shop." + plan + ".regence.com/action/plansQuoteSubmit");
	window.location.replace("https://www.regence.com/PXPSecurityServices/login!input.action");
}
function shopNow()
{
	// 2010.01.13 KJD: Re-written
	planCode=$.cookie("PLANCODE");
	if ( planCode != null ) {
		gotoMedical(planCode);
	} else {
		document.location.href	= sitePages[ 'zipCode' ] + "?type=medical";
	}
	//document.location.href	= ? sitePages[ 'shopping' ] : sitePages[ 'zipCode' ] + "?type=medical";
	document.location.href	= sitePages[ 'shopping' ];
}

function loginToSite(site)
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		switch (site){	
		case "member":
			window.open("http://www.myregence.com"); 
			break;
		default :
			document.location = sitePages['zipCode'] + "?type=" + site;
			break;
		}
	}
	else  
	{
		var plan = planCode.toLowerCase();
		if (plan == "warbs") {plan = "wa"} 
		switch (site){	
		case "member":
			window.open("http://www.myregence.com"); 
			break;
		case "agent":
			if (plan == "wa"){window.open("http://www.wa.regence.com/broker/");}
				else {window.open("http://www." + plan + ".regence.com/agent/");}
			break;
		case "QCSI":
			gotoQCSI(plan);
			break;
		default :
			window.open("http://www." + plan + ".regence.com/" + site + "/");
			break;
		}
	}
}
function login2(site)
{
	loginToSite(site);
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location="/index.jsp";
	}
	else
	{
		document.location="/" + planCode + "/index.jsp";
	}
}


// functions to driect to the appropriate state plan category pages
function gotoMedical(planCode)
{
	// 2010.01.13 KJD: Updated
	window.location.replace( sitePages[ 'shopping' ] );
	//window.location.replace("/"+planCode+sitePages['shopping']);
}

function gotoShortTerm(planCode)
{
	if (planCode == "WARBS")
	{
		document.getElementById("validateResult").innerHTML = "<b>We're sorry, our short terms plans aren't available in the zip code you entered.</b>"
	}
	else
	{
		// 2010.01.13 KJD: Update with global var
		window.location.replace( sitePages[ 'shopping' ] + "#plan2");
	}
}

function gotoDental(planCode)
{
	switch (planCode){
		case "WARBS":
			// 2010.01.13 KJD: Updated
			window.location.replace( sitePages[ 'shopping' ] + "#plan2");
			break;
		case "OR":
		case "UT":
		case "ID":
			// 2010.01.13 KJD: Updated
			window.location.replace( sitePages[ 'shopping' ] + "#plan3");
			break;
		default :
			document.getElementById("validateResult").innerHTML = "<b>We're sorry, our dental plans aren't available in the zip code you entered.</b>"
			break;
		}
}

function gotoMedicare(planCode)
{
	window.location.replace("/" + planCode + "/products/medicare/index.jsp");
}

// functions to direct to the appropriate state medicare seminars pages
function gotoSeminars(planCode)
{
	switch (planCode){
		case "WARBS":
			window.open("/docs/WA/medicare2008/medAdvantageSeminar.pdf");
			document.location="/" + planCode + "/index.jsp";
			break;
		case "OR":
			window.open("/docs/OR/medicare2008/medAdvantageMeetings.pdf");
			document.location="/" + planCode + "/index.jsp";
			break;
		case "ID":
			document.location="/ID/products/medicare/seminars.jsp";
			break;
		case "UT":
			window.open("/docs/UT/medicare2008/seminarSchedule.pdf");
			document.location="/" + planCode + "/index.jsp";
			break;
		}
	
}
function gotoMemberResources()
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location= sitePages[ 'zipCode' ] + "?type=members";
	}
	else
	{
		document.location="/" + planCode + "/member/index.jsp";
	}
}


function gotoRegenceAdvantages()
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location= sitePages[ 'zipCode' ] + "?type=advantages";
	}
	else
	{
		window.open( '/' + planCode + '/member/advantages.jsp', 'advantages', 'width=750,height=650,scrollbars'); 
	}
}

function goHome()
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location="../index.jsp";
	}
	else
	{
		document.location="../" + planCode + "/index.jsp";
	}	
}

function openCareers()
{
	 window.open("https://erecruit.regence.com/careers/servlet/com.lawson.ijob.QuickCandidate?vendor=100", "XC", "status=1,scrollbars=1,menubar=1,toolbar=0,width=780,height=470,left=0,top=0,resizable=1,bordersize=thin,center=1,minimize=0");	
   	
}

/* HSA PRODUCT AND CALCULATOR SPECIFIC FUNCTIONS */
function gotoHSACalcIndividual()
{
	
	planCode = getCookie("PLANCODE")
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaCalcIndividual";
	}
	else
	{
		document.location = "/hsa/calculator.html?p="+planCode
	}
}

function gotoHSACalcEmployee()
{
	planCode = getCookie("PLANCODE")
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaCalcEmployee";
	}
	else
	{
		document.location = "/hsa/employee-calculator.html?p="+planCode
	}
}

function gotoHSACalcEmployer()
{
	planCode = getCookie("PLANCODE")
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaCalcEmployer";
	}
	else
	{
		document.location = "/hsa/employer-calculator.html?p="+planCode
	}
}

function gotoHSAProductPageIndividual(audience) // optional 'audience' represents Agent viewing individual
{ 

	planCode = getCookie("PLANCODE")
	audience = (audience != null) ? audience.toLowerCase() : getCookie("Audience").toLowerCase()
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaProductPageIndividual&a="+audience
	}
	else 
	{
		if (audience == "individual")
		{
			// 2010.01.13 KJD: Updated
			document.location = sitePages[ 'shopping' ];
			/*
			switch(planCode) {
				case "ID" :
					document.location = "/"+planCode+"/products/medical/regence-hsa-healthplan-1500-deductible-individual.jsp"
					break;
				case "OR" :
					document.location = "/"+planCode+"/products/medical/regence-hsa-healthplan-1500-individual-deductible.jsp"
					break;
				case "UT" :
					document.location = "/"+planCode+"/products/medical/regence-hsa-healthplan-1500-deductible.jsp"
					break;
				case "WARBS" :
					document.location = "/"+planCode+"/products/medical/regence-hsa-healthplan-2500-deductible.jsp"
					break;
				default :
					break;
			};
			*/
		} 
		else 
		{

			planCode = (planCode == "WARBS") ? "wa" : planCode.toLowerCase()
			document.location= "http://www." + planCode + ".regence.com/"+audience+"/products/group/medical/hsa.html"
			
		};
	};
};

function gotoHSAProductPageGroup(audience) // optional 'audience' represents Agent viewing employer
{

	planCode = getCookie("PLANCODE")
	audience = (audience != null) ? audience.toLowerCase() : getCookie("Audience").toLowerCase()
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaProductPageGroup&a="+audience
	}
	else 
	{
		
		if (planCode == "ID" && audience == "employer")
		{
			document.location = "http://www.id.regence.com/employer/products/group/medical/hsa/index.html"
		}
		else
		{
			planCode = (planCode == "WARBS") ? "wa" : planCode.toLowerCase()
			document.location= "http://www." + planCode + ".regence.com/"+audience+"/products/group/medical/hsa.html"
		};
		
	};
};

function gotoHSAAgentToolkit()
{
	planCode = getCookie("PLANCODE")
	
	if (null == planCode)
	{
		document.location=sitePages[ 'zipCode' ] + "?type=hsaAgentToolkit"
	}
	else
	{
		planCode = (planCode == "WARBS") ? "wa" : planCode.toLowerCase()
		document.location="http://www."+ planCode + ".regence.com/agent/agentCenter/hsa2AC.html"
	};
};

/* END HSA FUNCTIONS */
