// JavaScript Document

//------ Dom ready function
$(document).ready(function(){
		
		// DLS: write from cookies if they exist
		if ( $.cookie('ZIP') ){
			$("#ZipCode").val($.cookie('ZIP'));
		}
		if ( $.cookie('age0')){
			$("#age0").val($.cookie('age0'));
		}
		if ( $.cookie('gender0')){
			var selectedGender = $.cookie('gender0');
			$("#gender0 option[value='"+selectedGender+"']").attr('selected', 'selected'); // Set the gender
		}

		$('#zip1').click(function () {
			$(this).hide();
			$("#zip2").show();
		});
		$('#advisor').click(function(){
			$(this).find('a').click();
		});
		
		$('.dialog').each(function(i){
			var title = $(this).attr('title');
			$(this).dialog({
				autoOpen:false,
				width:535,
				height:275,
				modal:true,
				title:title,
				buttons: { "Continue": function() { $("input#seturl"+i).click(); } },
				dialogClass:'d'+i}).addClass('advantagesDialog');
		});

		$('#advantages .column').click(function() {
			if( $(this).attr("id") == "medicare_link" ){
				shopMedicare();
			} else {
			i = $('#advantages .column').index(this);
			$('.d'+i).find('.dialog').dialog('open');
			}
		});


});

//------ End Dom ready function
// DLS check to see if cookie is set, then setup links
function setUrl (urlval, cookiename) {
	if (!$.cookie(cookiename)){
		parent.location = urlval;
	} else {
		var c = $.cookie(cookiename);
		parent.location = urlval+"&ZipCode="+c;
	}
}



// DLS set up medicare links by region 
function shopMedicare () {
	if (!$.cookie("PLANCODE")){
		parent.location = "http://www.regence.com/about/zipCode.jsp?type=medicare";
	} else {
		var c = $.cookie("PLANCODE");
		parent.location = "http://www.regence.com/"+c+"/products/medicare/index.jsp";
	}
}






