// JavaScript Document
//
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="/about/search.jsp?query=" + query + "&collection=" +collection;
}

function getParameter( parameterName ) {
  var queryString = window.location.search.substring(1).toLowerCase();
  //alert(queryString);
  //if (queryString.length==0) {return "null";}
  var parameters = new Array();
  parameters = queryString.split('&');
  for(var i = 0; i < parameters.length; i++) {
    //alert(parameters[i]);
    //alert(parameters[i].indexOf(parameterName));
    if (parameters[i].indexOf(parameterName.toLowerCase())>=0) {
      //alert(parameters[i]);
      var parameterValue = new Array();
      parameterValue = parameters[i].split('=');
      return parameterValue[1];
    }
  }
  return "null";
}

function goToArea(plan,site)
{
	window.open("http://www." + plan + ".regence.com/" + site + "/");
	planCode=getCookie ("PLANCODE");
	document.location="/" + planCode + "/index.jsp";
}

function gotoQCSI(plan)
{
	window.open("https://www.shop." + plan + ".regence.com/action/plansQuoteSubmit");
}
function shopNow()
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location="/about/zipCode.jsp?type=medical";
	}
	else
	{
		document.location="/" + planCode + "/products/medical/index.jsp";
	}
}

function loginToSite(site)
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		switch (site){	
		case "member":
			window.open("http://www.myregence.com"); 
			break;
		default :
			document.location="/about/zipCode.jsp?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)
{
	document.location="/" + planCode + "/products/medical/index.jsp";
}

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
	{
		document.location="/" + planCode + "/products/medical/index.jsp#plan2";
	}
}

function gotoDental(planCode)
{
	switch (planCode){
		case "WARBS":
			document.location="/" + planCode + "/products/medical/index.jsp#plan2";
			break;
		case "OR":
			document.location="/" + planCode + "/products/medical/index.jsp#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)
{
	document.location="/" + 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="/about/zipCode.jsp?type=members";
	}
	else
	{
		document.location="/" + planCode + "/member/index.jsp";
	}
}


function gotoRegenceAdvantages()
{
	planCode=getCookie ("PLANCODE");
	if (null == planCode)
	{
		document.location="/about/zipCode.jsp?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");	
   	
}