$(function(){
	$(".planinfo2, .planinfo3, .planinfo4").hide();
	$(".planbar1").addClass("active");
	// There are better ways to do the below, but IE8 doesnt think so
	$(".planbar1").click(function(){
		if($(".planinfo1").css("display")=="none"){
			$(".planinfo1").show();
		}
		else {
			$(".planinfo1").hide();
		};
		$(this).toggleClass("active");
	});
	$(".planbar2").click(function(){
		if($(".planinfo2").css("display")=="none"){
			$(".planinfo2").show();
		}
		else {
			$(".planinfo2").hide();
		};
		$(this).toggleClass("active");
	});
	$(".planbar3").click(function(){
		if($(".planinfo3").css("display")=="none"){
			$(".planinfo3").show();
		}
		else {
			$(".planinfo3").hide();
		};
		$(this).toggleClass("active");
	});
	$(".planbar4").click(function(){
		if($(".planinfo4").css("display")=="none"){
			$(".planinfo4").show();
		}
		else {
			$(".planinfo4").hide();
		};
		$(this).toggleClass("active");
	});
	$(".bluebox:first").css("margin-right","12px");
	
	
	
	
	$(".plan_option").click(function(){
		$("td.selected").removeClass("selected");
		$(".selectedheader").removeClass("selectedheader");
		if ($("input.plan_option[value^='copay']").is(":checked")){
			$("td.copay").addClass("selected");
			$("td.copay3").addClass("selected");
			$("td.coheader.zero").addClass("selectedheader");
			set_plan_name(2);
		}
		if ($("input.plan_option[value^='coinsurance1']").is(":checked")){
			$("td.coinsurance.one").addClass("selected");
			$("td.coinsurance3.one").addClass("selected");
			$("td.coheader.one").addClass("selectedheader");
			set_plan_name(4);
		}
		if ($("input.plan_option[value^='coinsurance2']").is(":checked")){
			$("td.coinsurance.two").addClass("selected");
			$("td.coinsurance3.two").addClass("selected");
			$("td.coheader.two").addClass("selectedheader");
			set_plan_name(5);
		}
		if ($("input.plan_option[value^='discount']").is(":checked")){
			$("td.discount").addClass("selected");
			$("td.discount3").addClass("selected");
			$("td.discount_type").addClass("selected");
			set_plan_name(1);
		}
		
		
		
		var planid=$("input.plan_option:checked").val().split("_")[1];
		$("#theplan").val(planid);
	});
	$(".qtip[title]").qtip({
		content: { text: false, prerender: true },
		style: { 
		  width: 220,
		  padding: 5,
		  background: '#d1f5ff',
		  color: '#1e1e1e',
		  textAlign: 'left',
		  fontSize: '12px',
		  border: {
			 width: 7,
			 radius: 7,
			 color: '#d1f5ff'
		  },
		  tip: {
			  corner: 'bottomMiddle',
			  color: '#d1f5ff'
		  }
	   },
	    position: {
		  	corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			}
		}
	   });
	$(".qtip2[title]").qtip({
		content: { text: false },
		style: { 
		  width: 220,
		  padding: 5,
		  background: '#d1f5ff',
		  color: '#1e1e1e',
		  textAlign: 'left',
		  fontSize: '12px',
		  border: {
			 width: 7,
			 radius: 7,
			 color: '#d1f5ff'
		  },
		  tip: {
			  corner: 'bottomMiddle',
			  color: '#d1f5ff'
		  }
	   },
	    position: {
		  	corner: {
				target: 'topMiddle',
				tooltip: 'bottomMiddle'
			},
			adjust: {
				x: 50,
				y: -1
			}
		},
		show: {
			solo: true,
			delay: 500
		}
	   });
});

function set_plan_name(plantypeid) {
	$("#youhaveselected").html(_plannames[plantypeid]);	
}

function set_plan_network(obj,rate_index) {	
	obj.id="current_radio_button";
	var tr=$("#current_radio_button").parents("tr")[0];
	
	// get rate
	var lbl=$("#current_radio_button").parents("label")[0];	
	lbl.id="current_label_1";
	var rate=$("#current_label_1").text();
	
	tr.cells[0].id="current_td_1";	
	var coverage=$("#current_td_1").text().replace(":","");
	
	var cindex=$("#current_radio_button").parents("td")[0].cellIndex;	
	tr.cells[cindex].id="current_td_2";
	var radioindex=0;
	$("#current_td_2 input").each(function(i){
		if(obj==this) {
			radioindex=i;
		}
	});	
	
	$(".network_header").parent("tr")[0].cells[cindex].id="current_td_3";	
	
	if($("#current_td_2 input").length==1) {
		var network=$("#current_td_3").text();
	} else {		
		if(radioindex>0) {
			radioindex++;
		}
		$("#current_td_3 .option_title_container div")[radioindex].id="current_td_4";		
		var network=$("#current_td_4").text();
	}	
	
	$("#current_td_1").attr("id","");
	$("#current_td_2").attr("id","");
	$("#current_td_3").attr("id","");
	$("#current_td_4").attr("id","");
	
	$("#current_label_1").attr("id","");
	$("#current_radio_button").attr("id","");
	
	$("#youhaveselected_network").html(network+" Network ");
	$("#youhaveselected_coverage").html(coverage+" ");
	$("#youhaveselected_rate").html(rate+" ");	
	
	$("#youhaveselected_none").hide();
	$("#youhaveselectedcontainer").show();

// set a variable to auto select the rate index on the next screen	
	$("#rate_index").val(rate_index);
}

function validate_product_checked() {
	if($("#theplan").val()=="") {
		alert("You must select a plan first.");
		return false;
	} else {
		return true;
	}
}

function validate_zipcode_entered() {
	var inp=document.getElementById("zip_code");
	if(inp==null) {
		// NOT CA OR NV
		return true;
	} else {
		if(inp.value=="") {
			alert("You must enter your zipcode first.");
			return false;
		} else {
			return true;
		}
	}
}

function wizard_assoc(assoc_id_in_url) {
	var obj=document.getElementById("wizard_assoc_checkbox");
	if(obj==null) {
		$("#assoc_div").hide();				
	} else {
		if(obj.checked) {
			$("#assoc_div").show();
		} else {
			if(assoc_id_in_url==0) {
				$("#assoc_div").hide();
			} else {
				document.getElementById("wizard_assoc_checkbox").checked=false;
				document.getElementById("assoc_id").options[0].selected=true;
				$("#filter_form").submit();
			}			
		}
	}
}

function set_full_printed_brochure_link() {
	$.ajax({
		type:"GET",
		url:"/wizard_printed_brochure.php",
		success: function(r){
			eval(r);
		}
	})
}

