var no = 0;
var yes = 1;
var maybe = 2;

function item(name, perc)
{
        this.name = name;
        this.perc = perc;
}

chuck = new item(10);

chuck[0] = new item('Chuck Bartowski', 0);
chuck[1] = new item('Sarah Walker', 0);
chuck[2] = new item('Morgan Grimes', 0);
chuck[3] = new item('Ellie Bartowski', 0);
chuck[4] = new item('Major John Casey', 0);
chuck[5] = new item('Lester Patel', 0);
chuck[6] = new item('Jeff Barnes', 0);
chuck[7] = new item('Devon "Captain Awesome" Woodcomb', 0);
chuck[8] = new item('Anna Wu', 0);
chuck[9] = new item('Big Mike', 0);


function change(who, n, perc, yesno)
{
	if (yesno == yes)
	{
		chuck[who].perc = chuck[who].perc + Math.round(n*perc);	
	}
	else if (yesno == no)
	{
		chuck[who].perc = chuck[who].perc + Math.round(4*perc) - Math.round(n*perc);
	}
	else // if yesno == maybe
	{
		// full no is 0 and full yes is 4
		// so if n is near middle then...
		if (n == 1)
			chuck[who].perc = chuck[who].perc + 2 * perc;
		if (n == 2)
			chuck[who].perc = chuck[who].perc + 4 * perc;
		if (n == 3)
			chuck[who].perc = chuck[who].perc + 2 * perc;
	}
} // end function change()


function update()
{
	// the formula is PercPerQuestion * Questions = Total
	// then PercPerQuestion / 4 is (Answer)
	
	var chuckb = 0;
	var chuck100 = 2.5		//  10 * 9 = 90 (2.5)
	var chuck50 = 1.25;	//  5 * 2 =  (1.25)
	var sarah = 1;
	var sarah100 = 4.125;	// 16.5 * 6 = 99 (4.125)
	var morgan = 2;
	var morgan100 = 5; 	// 20 * 5 = 100 (5)
	var ellie = 3;
	var ellie100 = 5; 	// 20 * 5 = 100 (5)
	var casey = 4;
	var casey100 = 5; 	// 20 * 5 = 100 (5)
	var lester = 5;
	var lester100 = 5; 	// 20 * 5 = 100 (5)
	var jeff = 6;
	var jeff100 = 5; 	// 20 * 5 = 100 (5)
	var awesome = 7;
	var awesome100 = 5; 	// 20 * 5 = 100 (5)
	var anna = 8;
	var anna100 = 5; 	// 20 * 5 = 100 (5)
	var bigmike = 9;
	var bigmike100 = 5; 	// 20 * 5 = 100 (5)
	
	 
	for (var n = 0; n < 10; n++)
		chuck[n].perc = 0;
			
	// Have you attended a University?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck1[n].checked)
		{
			change(chuckb, n, chuck100, yes);
			change(ellie, n, ellie100, yes);
			change(awesome, n, awesome100, yes);	
		}
	}
	
	// Do you love huge deli sandwhiches?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck2[n].checked)
		{
			change(chuckb, n, chuck100, yes);	
		}
	}
		
	// Are you good at puzzles and problem solving?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck3[n].checked)
		{
			change(chuckb, n, chuck100, yes);	
		}
	}
	
	// Would you consider yourself a nerd?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck4[n].checked)
		{
			change(chuckb, n, chuck100, yes);	
			change(morgan, n, morgan100, yes);
			change(jeff, n, jeff100, yes);
			change(lester, n, lester100, yes);
			change(casey, n, casey100, no);
			change(anna, n, anna100, yes);
		}
	}
	
	// Do you love computer and/or video games?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck5[n].checked)
		{
			change(chuckb, n, chuck100, yes);
			change(morgan, n, morgan100, yes);	
			change(jeff, n, jeff100, yes);
		}
	}
	
	// Do you prefer brunettes over blonds
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck6[n].checked)
		{
			change(chuckb, n, chuck50, no);	
			change(ellie, n, ellie100, no);
			change(awesome, n, awesome100, yes);
			change(sarah, n, sarah100, yes);
		}
	}
	
	// Would you say that your looks are bigger asset then your brains?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck7[n].checked)
		{
			change(chuckb, n, chuck100, no);
			change(awesome, n, awesome100, yes);
			change(sarah, n, sarah100, yes);
			change(anna, n, anna100, yes);	
		}
	}
	
	// Do you have a lot of friends?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck8[n].checked)
		{
			change(chuckb, n, chuck100, yes);	
			change(jeff, n, jeff100, no);
			change(lester, n, lester100, no);
			change(bigmike, n, bigmike100, no);
		}
	}
	
	// Do you have a cooler alter ego?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck9[n].checked)
		{
			change(chuckb, n, chuck100, yes);	
		}
	}
	
	// Do you work in a department store?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck10[n].checked)
		{
			change(chuckb, n, chuck50, yes);
			change(morgan, n, morgan100, yes);
			change(jeff, n, jeff100, yes);	
			change(lester, n, lester100, yes);
			change(anna, n, anna100, yes);
			change(bigmike, n, bigmike100, yes);
		}
	}
	
	// Are you in love with someone but you don't have the guts to tell them?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.chuck11[n].checked)
		{
			change(chuckb, n, chuck100, yes);
			change(sarah, n, sarah100, yes);	
		}
	}
	
	// Do your siblings think you worry about them too much?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.ellie1[n].checked)
		{
			change(ellie, n, ellie100, yes);	
		}
	}
	
	// Do you have long hair?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.ellie2[n].checked)
		{
			change(ellie, n, ellie100, yes);
			change(sarah, n, sarah100, yes);
			change(anna, n, anna100, yes);	
		}
	}
	
	// Do you work in the medical field?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.ellie3[n].checked)
		{
			change(ellie, n, ellie100, yes);
			change(awesome, n, awesome100, yes);	
		}
	}
	
	// Do you use the word "Awesome" frequently?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.awesome1[n].checked)
		{
			change(awesome, n, awesome100, yes);	
		}
	}
	
	// Do you have a best friend that you look up to very much?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.morgan1[n].checked)
		{
			change(morgan, n, morgan100, yes);	
		}
	}
	
	// Are you tall?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.morgan2[n].checked)
		{
			change(morgan, n, morgan100, no);
			change(casey, n, casey100, yes);
			change(anna, n, anna100, no);	
		}
	}
	
	// Would you eat or drink anything for a price?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.jeff1[n].checked)
		{
			change(jeff, n, jeff100, yes);	
		}
	}
	
	// Do you try to be intimidating to raise your self-esteem?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.lester1[n].checked)
		{
			change(lester, n, lester100, yes);
			change(bigmike, n, bigmike100, yes);	
		}
	}
	
	// Are you strong?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.lester2[n].checked)
		{
			change(lester, n, lester100, no);
			change(casey, n, casey100, yes);	
		}
	}
	
	// Are you trained in self-defense or combat?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.sarah1[n].checked)
		{
			change(sarah, n, sarah100, yes);
			change(casey, n, casey100, yes);	
		}
	}
	
	// Are you good at lying?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.sarah2[n].checked)
		{
			change(sarah, n, sarah100, yes);
			change(casey, n, casey100, yes);	
		}
	}
	
	// Do you love fishing?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.bigmike1[n].checked)
		{
			change(bigmike, n, bigmike100, yes);	
		}
	}
	
	// Are you bossy?
	for (n = 0; n < 5; n++)
	{
		if (document.fm.bigmike2[n].checked)
		{
			change(bigmike, n, bigmike100, yes);	
		}
	}
	
	if (chuck[chuckb].perc == 99) chuck[chuckb].perc = 100;
	if (chuck[sarah].perc == 102) chuck[sarah].perc = 100;	


	
	// The stuff below this line is for testing
	// to display the scores while answering:
	
	/*document.fm.chuckb.value = chuck[0].perc;
	document.fm.sarah.value = chuck[1].perc;
	document.fm.morgan.value = chuck[2].perc;
	document.fm.ellie.value = chuck[3].perc;
	document.fm.casey.value = chuck[4].perc;
	document.fm.lester.value = chuck[5].perc;
	document.fm.jeff.value = chuck[6].perc;
	document.fm.awesome.value = chuck[7].perc;
	document.fm.anna.value = chuck[8].perc;
	document.fm.bigmike.value = chuck[9].perc;
	*/
	
	
}  // end function update



function copyForm()
{
	parent.location = 'result.htm?a='+chuck[0].perc+
		'&b='+chuck[1].perc+
		'&c='+chuck[2].perc+
		'&d='+chuck[3].perc+
		'&e='+chuck[4].perc+
		'&f='+chuck[5].perc+
		'&g='+chuck[6].perc+
		'&h='+chuck[7].perc+
		'&i='+chuck[8].perc+
		'&j='+chuck[9].perc;
		
} // end copyForm()

document.write('<STYLE type="text/css"> TD { border-bottom:1px gray solid} </STYLE>');




// The stuff below is for testing



/*document.write('<TABLE><TR ALIGN="right"><TD>');
document.write('<BR>Chuck <INPUT TYPE=TEXT NAME="chuckb" VALUE="0" SIZE="5">');
document.write('<BR>Ellie <INPUT TYPE=TEXT NAME="ellie" VALUE="0" SIZE="5">');
document.write('<BR>Awesome <INPUT TYPE=TEXT NAME="awesome" VALUE="0" SIZE="5">');
document.write('<TD>');
document.write('<BR>Morgan <INPUT TYPE=TEXT NAME="morgan" VALUE="0" SIZE="5">');
document.write('<BR>Jeff <INPUT TYPE=TEXT NAME="jeff" VALUE="0" SIZE="5">');
document.write('<BR>Lester <INPUT TYPE=TEXT NAME="lester" VALUE="0" SIZE="5">');
document.write('<TD>');
document.write('<BR>Sarah <INPUT TYPE=TEXT NAME="sarah" VALUE="0" SIZE="5">');
document.write('<BR>Casey <INPUT TYPE=TEXT NAME="casey" VALUE="0" SIZE="5">');
document.write('<BR>Anna <INPUT TYPE=TEXT NAME="anna" VALUE="0" SIZE="5">');
document.write('<TD>');
document.write('<BR>Bigmike <INPUT TYPE=TEXT NAME="bigmike" VALUE="0" SIZE="5">');
document.write('</TR></TABLE>');
document.write('</FORM>');
*/


waitMessage();  // make "wait for quiz" message disappear
