var element_id;

var choice1=$.jqURL.get('talk');
var choice2=$.jqURL.get('text');
var choice3=$.jqURL.get('data');;


//alert("this is choice 1 " + choice1);
//alert("this is choice 2 " + choice2);
//alert("this is choice 3 " + choice3);

var the_choices = "";


//var answer_copy = [




var paygo_plans =
	[
		[null,"pt_20","pt_30","pt_50","pt_basic","pt_bar"],
		[null,"pm_5","pm_10","pm_20","pm_basic"],
		[null,"pd_5","pd_10","pd_20","pd_basic"]
	];

var monthly_plans =
	[
		[null,"mt_24","mt_34","mt_49","mt_59","mt_79"],
		[null,"mm_5","mm_10","mm_basic"],
		[null,"md_5","md_10","md_basic","md_none"]
	];



var set_2a3a = [
		[   [null],
			[null,"none","none","1-2-3","1-5","4"],  ///talk
			[null,"none","none","3","3","3"], ///messaging
			[null,"none","none","2-3","2-3","2-3"] ///data
		],
		[   [null],
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"2","2","none","none","none"], ///messaging
			[null,"1-2","1-2","none","none","none"] ///data
		]
	];


var set_2a3b =
	[
		[  ////Paygo
			null,
			[null,"none","none","1-2-3","1-5","4"],  ///talk
			[null,"none","none","3","3","3"], ///messaging
			[null,"none","none","1-2","1-2","1-2"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"2","2","none","none","none"], ///messaging
			[null,"1","1","none","none","none"] ///data
		]
	];

var set_2a3c =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"3","none","3","3","3"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"2","2","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];

var set_2a3d =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"3","none","3","3","3"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"2","2","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];

var set_2b3a =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"2","none","2","2","2"], ///messaging
			[null,"2-3","none","2-3","2-3","2-3"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"1","1","none","none","none"], ///messaging
			[null,"1-2","1-2","none","none","none"] ///data
		]
	];

var set_2b3b =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"2","none","2","2","2"], ///messaging
			[null,"1-2","none","1-2","1-2","1-2"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"1","1","none","none","none"], ///messaging
			[null,"1","1","none","none","none"] ///data
		]
	];


var set_2b3c =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"2","none","2","2","2"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"1","1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];

var set_2b3d =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"2","none","2","2","2"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"1","1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];



var set_2c3a =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"2-3","none","2-3","2-3","2-3"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"1-2","1-2","none","none","none"] ///data
		]
	];



var set_2d3a =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"2-3","none","2-3","2-3","2-3"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"1-2","1-2","none","none","none"] ///data
		]
	];



var set_2c3b =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"1-2","none","1-2","1-2","1-2"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"1","1","none","none","none"] ///data
		]
	];


var set_2d3b =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"1-2","none","1-2","1-2","1-2"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"1","1","none","none","none"] ///data
		]
	];

var set_2d3c =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];


var set_2c3d =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];


var set_2c3c =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];

var set_2d3d =
	[
		[  ////Paygo
			null,
			[null,"3","none","1-2-3","1-5","4"],  ///talk
			[null,"4-1","none","4-1","4-1","4-1"], ///messaging
			[null,"4","none","4","4","4"] ///data
		],
		[   ////Monthly
			null,
			[null,"5","1-2-3-4","none","none","none"],  ///talk
			[null,"3-1","3-1","none","none","none"], ///messaging
			[null,"3","3","none","none","none"] ///data
		]
	];


var selection_group;
var selection_group_val;

var answer_query_string = "";



function select_answer(){

	//$("#the_questions").fadeTo(1000, 0.33,function(){$("div.plan_area").fadeIn(1000)});


	selection_group = $("#" + element_id).attr("name");




	selection_group_val = $("input[name= 'group1']:checked").val();

	var answer_copy = new Array();
	
	
	answer_query_string = "?talk=" + choice1 + "&text=" + choice2 + "&data=" + choice3;

	//alert(choice2);

	var answers_for_1 = new Array (null, "1a","1b","1c","1d","1e");

	answer_copy.push(jQuery.trim($("#question-" + answers_for_1[choice1] + "_container").text()));

	answer_copy.push(jQuery.trim($("#question-" + choice2 + "_container").text()));

	answer_copy.push(jQuery.trim($("#question-" + choice3 + "_container").text()));

	//alert(answer_copy);

	$("#answer_copy0").html("<span style='font-weight:bold;'>Talk:</span><br/>" + answer_copy[0]);
	$("#answer_copy1").html("<span style='font-weight:bold;'>Text & Messaging:</span><br/>" +answer_copy[1]);
	$("#answer_copy2").html("<span style='font-weight:bold;'>Mobile Web:</span><br/>" +answer_copy[2]);
	
	//$("#print_this").attr("href","plan-evalueator.html" + answer_query_string).attr("target","_blank");



	 // Loop over each question. -- this is code if you want to get the index number of the radio button that is selected
 	 /*  $("input[name= 'group1']").each(

    	 function( intIndex ){

   			if(   $("input[name= '" + selection_group + "']:checked")   ==    $("input[name= '" + selection_group + "']:eq('" + intIndex + "')")  ){

   				alert( $("input[name= '" + selection_group + "']:eq('" + intIndex + "')").is("checked") );

   				alert( "Hottie index: " + intIndex );

   			}

   		 }

   );*/


	var set_array = eval("set_" + choice2 + choice3);

	//alert("set_" + choice2 + choice3 );


	var paygo_talk_raw = set_array[0][1][choice1];

	var paygo_messaging_raw = set_array[0][2][choice1];

	var paygo_data_raw = set_array[0][3][choice1];


	var monthly_talk_raw = set_array[1][1][choice1];

	var monthly_messaging_raw = set_array[1][2][choice1];

	var monthly_data_raw = set_array[1][3][choice1];


	//alert("Monthly raw " + monthly_talk_raw + " | " + monthly_messaging_raw + " | " + monthly_data_raw);

	//alert("Paygo raw " + paygo_talk_raw + " | " + paygo_messaging_raw + " | " + paygo_data_raw);




	var paygo_talk_highlight = new Array();

	var paygo_messaging_highlight = new Array();

	var paygo_data_highlight = new Array();

	var monthly_talk_highlight = new Array();

	var monthly_messaging_highlight = new Array();

	var monthly_data_highlight = new Array();

	var highlight_styles = new Array("best","good","ok","kindof");

	var rows_to_highlight = new Array(monthly_talk_highlight,monthly_messaging_highlight,monthly_data_highlight,paygo_talk_highlight,paygo_messaging_highlight,paygo_data_highlight); ///array of everything to turn on


	var none_count_paygo = 0;

	var none_count_monthly = 0;

	////determine monthly answers
	///talk
	if(monthly_talk_raw != "none"){

		var monthly_talk_array = monthly_talk_raw.split("-"); ////5



		for(mt=0;mt< monthly_talk_array.length;++mt){

			///rows to turn on

		//alert(monthly_talk_array[0][5]);

		monthly_talk_highlight.push(monthly_plans[0][monthly_talk_array[mt]]);



		}
	}
	else{
		///what to do when the answer is none
		none_count_monthly++;
	}

	///messaging
	if(monthly_messaging_raw != "none"){

		var monthly_messaging_array = monthly_messaging_raw.split("-");

		for(mm=0;mm<monthly_messaging_array.length;++mm){

			///rows to turn on
			monthly_messaging_highlight.push(monthly_plans[1][monthly_messaging_array[mm]]);
		}
	}
	else{
		///what to do when the answer is none
	}

	///data
	if(monthly_data_raw != "none"){

		var monthly_data_array = monthly_data_raw.split("-");

		for(md=0;md<monthly_data_array.length;++md){

			///rows to turn on
			monthly_data_highlight.push(monthly_plans[2][monthly_data_array[md]]);
		}
	}
	else{
		///what to do when the answer is none
	}



	////determine paygo answers
	///talk
	if(paygo_talk_raw != "none"){

		var paygo_talk_array = paygo_talk_raw.split("-");

		for(pt=0;pt<paygo_talk_array.length;++pt){

			///rows to turn on
			paygo_talk_highlight.push(paygo_plans[0][paygo_talk_array[pt]]);
		}
	}
	else{
		///what to do when the answer is none

		none_count_paygo++;
	}

	///messaging
	if(paygo_messaging_raw != "none"){

		var paygo_messaging_array = paygo_messaging_raw.split("-");

		for(pm=0;pm<paygo_messaging_array.length;++pm){

			///rows to turn on
			paygo_messaging_highlight.push(paygo_plans[1][paygo_messaging_array[pm]]);
		}
	}
	else{
		///what to do when the answer is none
	}

	///data
	if(paygo_data_raw != "none"){

		var paygo_data_array = paygo_data_raw.split("-");

		for(pd=0;pd<paygo_data_array.length;++pd){

			///rows to turn on
			paygo_data_highlight.push(paygo_plans[2][paygo_data_array[pd]]);
		}
	}
	else{
		///what to do when the answer is none
	}

	$("tr.row_ready").addClass("row_off");
	$("tr.row_best").addClass("row_off");

	$("tr.row_ready").removeClass("row_ready");
	$("tr.row_best").removeClass("row_best");

	//alert(none_count_paygo);

/*	if(none_count_paygo == 1){
		$("#paygo_plan_header").css({"background":"url(paygo-plans-bad.gif) no-repeat 0 0"});
	}
	else{
	$("#paygo_plan_header").css({"background":"url(paygo-plans-good.gif) no-repeat 0 0 "});
	}

	if(none_count_monthly == 1){
		$("#monthly_plan_header").css({"background":"url(monthly-plan-bad.gif) no-repeat 0 0 "});
	}
	else{
		$("#monthly_plan_header").css({"background":"url(monthly-plan-good.gif) no-repeat 0 0"});
	}*/




	//alert(rows_to_highlight);

	var highlight_index = 0;
	
	

	for(hh=0;hh<rows_to_highlight.length;++hh){

		highlight_index = rows_to_highlight[hh].length-1;//0;

		//alert("this is the highlight index " + highlight_index);


			for(pp=0;pp<rows_to_highlight[hh].length;++pp){

				//alert(pp);

				//alert("rows to highlight " + rows_to_highlight[hh]);

				if(rows_to_highlight[hh][pp] != "" && rows_to_highlight[hh][pp] != null && rows_to_highlight[hh][pp] != undefined){

				//alert(rows_to_highlight[hh][pp]);
				//	alert(pp);
			//	alert(highlight_styles[highlight_index]);
			
				the_choices += (rows_to_highlight[hh][pp]) + ",";
			
			

					$("#" + rows_to_highlight[hh][pp]).removeClass("row_off");
					$("#" + rows_to_highlight[hh][pp]).addClass("row_" + highlight_styles[highlight_index]);
				}
				highlight_index=highlight_index-1;
			}


		pp=0;
		
		
	}

	paygo_talk_highlight.length = 0;
	paygo_messaging_highlight.length = 0;
	paygo_data_highlight.length = 0;

	monthly_talk_highlight.length = 0;
	monthly_messaging_highlight.length = 0;
	monthly_data_highlight.length = 0;



	//alert(none_count_monthly);
	//alert(none_count_paygo);

	if(none_count_monthly <= none_count_paygo){

		$("#monthly_plans").css({"top" : "235px"});

		//$("#the_or").css(

		//alert($("#monthly_plans").height());
		$("#paygo_plans").css({"top" : "570px"});
	}

	else{
		$("#paygo_plans").css({"top" : "230px"});

		$("#monthly_plans").css({"top" : "570px"});

	}



	//$("#the_questions").fadeTo("normal", 0.33,function(){$("div.plan_area").fadeIn("normal")});

	//$("#the_questions").css({"height" : "900px"});


	//alert(the_choices);
}

function reset_charts(){

	$('div.plan_area').fadeOut("normal");
	$('#the_questions').fadeTo("normal",100,function(){

			$("#the_questions").css({"height" : "500px"});

			$("tr.row_best").addClass("row_ready");
			$("tr.row_good").addClass("row_ready");
			$("tr.row_ok").addClass("row_ready");
			$("tr.row_kindof").addClass("row_ready");

			$("tr.row_good").removeClass("row_good");
			$("tr.row_best").removeClass("row_best");
			$("tr.row_ok").removeClass("row_ok");
			$("tr.row_kindof").removeClass("row_kindof");
			}

	);
	
	answer_query_string = "";


	}
	
function print_results(){

window.open("/plan-evalueator-print" + answer_query_string);

}



