// 2010.01.12 KJD: Added
$( document ).ready( function(){

	var planCode	= $.cookie("PLANCODE");
	var zipCode		= $( '#postCode' ).val();
	
	var thisTitle	= (planCode)?"Tell us what location you'd like to change to.":"Tell us where you are so we can better assist you.";
	$( '#frmZip H2' ).html( thisTitle );
	
	$( "#frmZip" ).validate({
		submitHandler:function( form )
		{
			$.post( '/planCodeService.do', $( "#frmZip" ).serialize(),
				function(data)
				{
					var thisResult = $( data ).find( 'plancode' ).attr('value');
					
					if( !thisResult )
					{
						$('#frmZip fieldset').hide(); 
						
						$('#frmZip h2').html( "Sorry, our system is temporarily down while we make updates and improvements." );
						
						$('#frmZip div').html( "<p>Please use one of the following links to find your service area:</p>"
												+ '<p><a href="/about/service-areas.jsp">Interactive map</a></p>'
												+ '<p><a href="/ID/">Idaho (including Asotin & Garfield Co., WA)</a> | <a href="/OR/">Oregon (including Clark Co., WA)</a> | <a href="/UT/">Utah</a> | <a href="/WARBS/">Washington (select counties)</a></p>' );
						return false;
					}
					else
					{
						var planCode = thisResult.toUpperCase();

						if( planCode == "ERROR" )
						{
							// 2010.01.13 KJD: if error
							$("#validateResult").html("We're sorry; Regence does not offer health plans in your area.");
							return false;
						}
						
						switch (planCode){
							
							case "ID":
								plan = "id";
								break;
							case "OR":
								plan = "or";
								break;
							case "UT":
								plan = "ut";
								break;
							case "WARBS":
								plan = "wa";
								break;
						
						}

						if ( ( planCode == "WAANH" ) || ( planCode == "ASURIS" ) )
						{
							$("#validateResult").html("The zip code you entered is served by our affiliate, <a href='/about/leavingDisclaimerAsuris.jsp' target='_new'>Asuris Northwest Health</a>.  Visit them now for more information.");
							return false;
						}

						$.cookie("PLANCODE", planCode);
						$.cookie("ZIPCODE", $( '#postCode' ).val());

						var type		= $.getUrlVar( 'type' );
						var audience	= $.getUrlVar( 'a' );

						if( type		){type 		= type.toLowerCase();}
						if( audience	){audience 	= audience.toLowerCase();}
						
						//var plan = planCode.toLowerCase();
						
						//$.cookie("PLANCODE", planCode);
						
						switch (type){
							case "medical":
								gotoMedical(planCode);
								break;
							case "short":
								gotoShortTerm(planCode);
								break;
							case "dental":
								gotoDental(planCode);
								break;
							case "medicare":
								gotoMedicare(planCode);
								break;
							case "seminars":
								gotoSeminars(planCode);
								break;
							case "employer":
								goToArea(plan,type);
								break;
							case "agent":
								if (plan == "wa")
								{ goToArea(plan,"broker"); }
								else { goToArea(plan,"agent");}
								break;
							case "provider":
								goToArea(plan,type);
								break;
							case "qcsi":
								gotoQCSI(plan);
								break;
							case "members":
								gotoMemberResources();
								break;
							case "advantages":
								gotoRegenceAdvantages();
								break;
							case "hsacalcindividual":
								gotoHSACalcIndividual();
								break;
							case "hsacalcemployee":
								gotoHSACalcEmployee();
								break;
							case "hsacalcemployer":
								gotoHSACalcEmployer()
								break;
							case "hsaproductpageindividual":
								gotoHSAProductPageIndividual(audience) // optional 'audience' represents Agent viewing individual
								break;
							case "hsaproductpagegroup":
								gotoHSAProductPageGroup(audience) // optional 'audience' represents Agent viewing employer	
								break;
							case "hsaagenttoolkit":
								gotoHSAAgentToolkit()
								break;
							case "cobra":
								window.location.replace("/cobra/index.jsp");
								break;
							default:
								window.location.replace("/" + planCode + "/index.jsp");	
								break;
						}
					}
				}, "xml"
				);
		}
	});
		
});
	
	