//	Dark Heresy Character Generator 2.0
//  Code copyright 2008 thisisnotatrueending.com, all rights reserved
//  Content copyright Games Workshop and Fantasy Flight Games LLC

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////


//Dice roller
function rd(sides)
{
	return(Math.floor(Math.random()*sides)+1);
}

//Fills the HTML of a given td, tr or other field on the page
function chtd(td,txt)
{
	document.getElementById(td).innerHTML = txt;
}

//Rolls a random world and hits chooseworld to populate the lists
function randomworld(derp)
{
	var roll = rd(100);
	chtd('hwroll',"(" + roll + ")");
	if (roll>=1 && roll<=15) { derp.selectedIndex = 1; } // Feral World
	if (roll>=16 && roll<=35) { derp.selectedIndex = 3; } // Hive World
	if (roll>=36 && roll<=55) { derp.selectedIndex = 6; } // Imperial World
	if (roll>=56 && roll<=65) { derp.selectedIndex = 9; } // Void Born
	if (roll>=66 && roll<=75) { derp.selectedIndex = 11; } // Forge World
	if (roll>=76 && roll<=85) { derp.selectedIndex = 12; } // Schola Progenium
	if (roll>=86 && roll<=95) { derp.selectedIndex = 13; } // Noble Born
	if (roll>=96) { derp.selectedIndex = 14; } // Mind Cleansed
	chooseworld(derp,roll);
}

//Fills out the individual selects with the appropriate possible choices based on homeworld
function chooseworld(derp,roll)
{
	//Reveals the div, forcing the player to choose a starting homeworld first
	if (derp.value==-1)
	{ document.getElementById('maindiv').style.visibility='hidden'; }
	else
	{ document.getElementById('maindiv').style.visibility='visible'; }

	//Hides divs that may need to be re-selected if the world is changed
	document.getElementById('careerdiv').style.visibility='hidden';
	//document.getElementById('statsdiv').style.visibility='hidden';
	
	//Fills each dropdown based on chosen world, where necessary
	document.dhgen.gender.selectedIndex = 0;
	document.dhgen.impdiv.selectedIndex = 0;
	chtd('buildtd',fillbuild(derp.value));
	chtd('skintd',fillskin(derp.value));
	chtd('hairtd',fillhair(derp.value));
	chtd('eyestd',filleyes(derp.value));
	chtd('quirktd',fillquirk(derp.value));
	chtd('careertd',fillcareer(derp.value));
	chtd('hwtraitstd',filltraits(derp.value));
	chtd('hwskillstd',fillworldskills(derp.value));
	chtd('hwtalentstd',fillworldtalents(derp.value));
	chtd('hwspectd',fillhwspec(derp.value));
	chtd('hwspectitletd',fillhwspectitle(derp.value));
	chtd('agetd',fillage(derp.value));
	chtd('mementotd',fillmemento(derp.value));

	//If randomworld wasn't used, marks the item as chosen
	if (roll===0) { markchosen('hwroll'); }

	//Fills out the statblock
	genstats(derp.value);
	checkpackages(-1,-1);
}

//Simply sets the label to (Chosen)
function markchosen(derp)
{
	chtd(derp,'(Chosen)'); 
}


//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

//Form validation stuff
function validate(theform)
{
	if (theform.cortotal.value>0 && this.form.career.value=='Sororitas') { alert('You cannot have a Sororitas with Corruption points!'); return 0; }
	if (theform.charname.value=='') { alert('You must choose a name!'); return 0; }
	if (theform.hw.value<0) { alert('You must select a homeworld!'); return 0; }
	if (theform.career.value=='Select Career') { alert('You must choose a career!'); return 0; }
	if (theform.impdiv.value=='Select Imperial Divination') { alert('You must choose a divination!'); return 0; }
	if (theform.build.value=='Select Build') { alert('You must choose a description for your body type!'); return 0; }
	if (theform.skin.value=='Select Skin') { alert('You must choose a description for your skin!'); return 0; }
	if (theform.hair.value=='Select Hair') { alert('You must choose a description for your hair!'); return 0; }
	if (theform.eyes.value=='Select Eyes') { alert('You must choose a description for your eyes!'); return 0; }
	if (theform.gender.value=='Select Gender') { alert('You must choose a gender!'); return 0; }
	if (isNaN(theform.age.value)||parseInt(theform.age.value)<10||theform.age.value=='') { alert('You must choose a real age!'); return 0; }
	if (theform.hwspec.value.search('Select')!=-1) { alert('You must choose your special homeworld info (e.g. Superstition)!'); return 0; }
	return 1;

}

//Fills out the statblock on world selection
function genstats(hw)
{

	document.getElementById('statsdiv').style.visibility = 'visible';

	//Clears all the fields
	clearstats();

	//Rolls the base values for each stat
	rollstats(hw,0,0);

	//Individual world base stats
	if (hw==0||hw==9)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',25);
		ss('tbase',25);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',15);
		ss('felbase',15);
		ss('woundbase',9);
		if (hw==9)		//Dusk insanity and corruption, +3 per/will
		{
			ss('insroll1',rd(5));
			ss('corroll1',rd(5));
			ss('perwtra',3);
			ss('wpwtra',3);
			ss('fatewtra',-1);
		}
	}
	if (hw==1||hw==10||hw==13)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',15);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',20);
		ss('felbase',25);
		ss('woundbase',8);
		if (hw==13) { ss('tbase',25); ss('felbase',15); ss('insroll1',rd(10)); }
		if (hw==10)	{ ss('bswtra',5); }
	}
	if (hw==2||hw==11||hw==12)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',20);
		ss('felbase',20);
		ss('woundbase',8);
		if (hw==11) { ss('twtra',-3); ss('fatewtra',1); }
		if (hw==12) { ss('perwtra',5); ss('wpwtra',-3); ss('felwtra',-3); }
		if (hw==2) { ss('wpwtra',3); } //Superior Origins traits
	}
	if (hw==3||hw==8)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',15);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',25);
		ss('felbase',20);
		ss('woundbase',6);
		if (hw==8) { ss('swtra',5); }
	}
	if (hw==4)
	{
		ss('wsbase',15);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',25);
		ss('perbase',20);
		ss('wpbase',20);
		ss('felbase',20);
		ss('woundbase',7);
	}
	if (hw==5)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',25);
		ss('felbase',15);
		ss('woundbase',8);
		ss('insroll1',rd(5)+2); //Insanity
	}
	if (hw==6)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',15);
		ss('felbase',25);
		ss('woundbase',8);
	}
	if (hw==7)
	{
		ss('wsbase',20);
		ss('bsbase',20);
		ss('sbase',20);
		ss('tbase',20);
		ss('agbase',20);
		ss('intbase',20);
		ss('perbase',20);
		ss('wpbase',20);
		ss('felbase',20);
		ss('woundbase',8);
	}

	fateroll(hw);

	//Updates the statblock
	updatestats();
}

//Rolls 2d10 for each stat
function rollstats(hw, career, pack)
{
	ss('wsroll1',rd(10));
	ss('wsroll2',rd(10));

	ss('bsroll1',rd(10));
	ss('bsroll2',rd(10));
	
	ss('sroll1',rd(10));
	ss('sroll2',rd(10));

	ss('troll1',rd(10));
	ss('troll2',rd(10));

	ss('agroll1',rd(10));
	ss('agroll2',rd(10));

	ss('introll1',rd(10));
	ss('introll2',rd(10));

	ss('perroll1',rd(10));
	ss('perroll2',rd(10));

	ss('wproll1',rd(10));
	ss('wproll2',rd(10));

	ss('felroll1',rd(10));
	ss('felroll2',rd(10));

	ss('woundroll1',rd(5));

	fateroll(hw.value);

	//World Insanity and Corruption
	if (hw.value==5) { ss('insroll1',rd(5)+2); }
	if (hw.value==9) { ss('insroll1',rd(5)); ss('corroll1',rd(5)); }
	if (hw.value==13) { ss('insroll1',rd(10)); }

	//Package Insanity and Corruption
	if (pack.value=="The Empty Men of Sinophia Magna") { ss('insptra',rd(5)); }
	if (pack.value=="The Red Vaults of Luggnum") { ss('insptra',rd(5)); }
	if (pack.value=="The Astral Knives") { ss('corptra',rd(5)); }
	if (pack.value=="The Moritat") { ss('insptra',rd(5)); }
	if (pack.value=="Redemptionist Firebrand") { ss('insptra',rd(5)); }
	if (pack.value=="The Mara Landing Massacre") { ss('insptra',rd(10)); ss('corptra',rd(5)); }
	if (pack.value=="Tranch War Veteran") { ss('insptra',rd(5)); }
	if (pack.value=="A Shadow Over Thy Soul") { ss('insptra',rd(5)); ss('corptra',rd(5)); }
	if (pack.value== "Living Nightmare") { ss('insptra',rd(10)); }
	if (pack.value=="The Beast Slaver") { ss('corptra',rd(5)); }
	if (pack.value=="The Divine Light of Sollex") { ss('insptra',rd(5)); }
	if (pack.value=="Malygrisian Tech Heresy") { ss('insptra',rd(5)); ss('corptra',rd(5)); }

	//Starting funds
	if (career.value=="Adept") { ss('throneroll1',rd(10)); ss('thronebase',100); }
	if (career.value=="Arbitrator") { ss('throneroll1',rd(10)+rd(10)); ss('thronebase',50); }
	if (career.value=="Assassin") { ss('throneroll1',rd(10)+rd(10)+rd(10)); ss('thronebase',120); }
	if (career.value=="Cleric") { ss('throneroll1',rd(10)+rd(10)+rd(10)+rd(10)+rd(10)); ss('thronebase',300); }
	if (career.value=="Guardsman") { ss('throneroll1',rd(10)); ss('thronebase',70); }
	if (career.value=="Imperial Psyker")
		{ ss('throneroll1',rd(5)); ss('thronebase',50);
			var sans = document.forms['dhgen'].elements['sansfx'].value;
			if (sans=="Reconstructed Skull") { ss('thronespec', rd(10)+rd(10)+rd(10)+rd(10)+rd(10)); }
			if (sans=="Hunted") { ss('insspec', rd(10)); }
			if (sans=="Unlovely Memories"||sans=="The Horror, the Horror") { ss('insspec', rd(5)); }
		}
	if (career.value=="Scum") { ss('throneroll1',rd(5)); ss('thronebase',10); }
	if (career.value=="Tech-Priest") { ss('throneroll1',rd(10)); ss('thronebase',150); ss('gchoice1',rd(10)); } //Also spare parts
	if (career.value=="Sororitas") { ss('throneroll1',rd(10)+rd(10)); ss('thronebase',70); }

	updatestats();

	if (hw.value==6){ var thrones = gs('thronetotal'); ss('thronetotal',thrones*2); }

}

function fateroll(hw)
{
	var fateroll = rd(10);

	if (hw==0||hw==9)
	{
		if (fateroll>=1 && fateroll<=4) { ss('fateroll1',1); }
		if (fateroll>=5 && fateroll<=8) { ss('fateroll1',2); }
		if (fateroll>=9 && fateroll<=10) { ss('fateroll1',2); }
	}

	if (hw==1||hw==10||hw==13)
	{
		if (fateroll>=1 && fateroll<=4) { ss('fateroll1',1); }
		if (fateroll>=5 && fateroll<=8) { ss('fateroll1',2); }
		if (fateroll>=9 && fateroll<=10) { ss('fateroll1',3); }
	}

	if (hw==2||hw==11||hw==12)
	{
		if (fateroll>=1 && fateroll<=4) { ss('fateroll1',2); }
		if (fateroll>=5 && fateroll<=8) { ss('fateroll1',2); }
		if (fateroll>=9 && fateroll<=10) { ss('fateroll1',3); }
	}

	if (hw==3||hw==8)
	{
		if (fateroll>=1 && fateroll<=4) { ss('fateroll1',2); }
		if (fateroll>=5 && fateroll<=8) { ss('fateroll1',3); }
		if (fateroll>=9 && fateroll<=10) { ss('fateroll1',3); }
	}

	if (hw==4)
	{
		if (fateroll>=1 && fateroll<=5) { ss('fateroll1',1); }
		if (fateroll>=6 && fateroll<=9) { ss('fateroll1',2); }
		if (fateroll==10) { ss('fateroll1',3); }
	}

	if (hw==5)
	{
		if (fateroll>=1 && fateroll<=3) { ss('fateroll1',2); }
		if (fateroll>=4 && fateroll<=9) { ss('fateroll1',3); }
		if (fateroll==10) { ss('fateroll1',4); }
	}

	if (hw==6)
	{
		if (fateroll>=1 && fateroll<=3) { ss('fateroll1',1); }
		if (fateroll>=4 && fateroll<=9) { ss('fateroll1',2); }
		if (fateroll==10) { ss('fateroll1',3); }
	}

	if (hw==7)
	{
		if (fateroll>=1 && fateroll<=2) { ss('fateroll1',1); }
		if (fateroll>=3 && fateroll<=7) { ss('fateroll1',2); }
		if (fateroll>=8 && fateroll<=10) { ss('fateroll1',3); }
	}
}

//Fills a given field with a given value
function ss(box, roll)
{
	document.forms['dhgen'].elements[box].value = roll;
}

//Retrieves the value of a given field
function gs(box)
{
	return(parseInt(document.forms['dhgen'].elements[box].value));
}

//Adds up all the fields and displays the totals
function updatestats()
{
	ss('wstotal',gs('wsroll1')+gs('wsroll2')+gs('wsbase')+gs('wswtra')+gs('wsptra')+gs('wsspec')+gs('wsdiv'));
	ss('bstotal',gs('bsroll1')+gs('bsroll2')+gs('bsbase')+gs('bswtra')+gs('bsptra')+gs('bsspec')+gs('bsdiv'));
	ss('stotal',gs('sroll1')+gs('sroll2')+gs('sbase')+gs('swtra')+gs('sptra')+gs('sspec')+gs('sdiv'));
	ss('ttotal',gs('troll1')+gs('troll2')+gs('tbase')+gs('twtra')+gs('tptra')+gs('tspec')+gs('tdiv'));
	ss('agtotal',gs('agroll1')+gs('agroll2')+gs('agbase')+gs('agwtra')+gs('agptra')+gs('agspec')+gs('agdiv'));
	ss('inttotal',gs('introll1')+gs('introll2')+gs('intbase')+gs('intwtra')+gs('intptra')+gs('intspec')+gs('intdiv'));
	ss('pertotal',gs('perroll1')+gs('perroll2')+gs('perbase')+gs('perwtra')+gs('perptra')+gs('perspec')+gs('perdiv'));
	ss('wptotal',gs('wproll1')+gs('wproll2')+gs('wpbase')+gs('wpwtra')+gs('wpptra')+gs('wpspec')+gs('wpdiv'));
	ss('feltotal',gs('felroll1')+gs('felroll2')+gs('felbase')+gs('felwtra')+gs('felptra')+gs('felspec')+gs('feldiv'));
	ss('woundtotal',gs('woundroll1')+gs('woundbase')+gs('woundwtra')+gs('woundptra')+gs('woundspec')+gs('wounddiv'));
	ss('fatetotal',gs('fateroll1')+gs('fatebase')+gs('fatewtra')+gs('fateptra')+gs('fatespec')+gs('fatediv'));
	ss('instotal',gs('insroll1')+gs('insbase')+gs('inswtra')+gs('insptra')+gs('insspec')+gs('insdiv'));
	ss('cortotal',gs('corroll1')+gs('corbase')+gs('corwtra')+gs('corptra')+gs('corspec')+gs('cordiv'));
	ss('thronetotal',gs('throneroll1')+gs('thronebase')+gs('thronewtra')+gs('throneptra')+gs('thronespec')+gs('thronediv'));

	if (document.forms['dhgen'].elements['hw'].value == "13") { var bob = gs('thronetotal'); ss('thronetotal',(gs*2)); }
	if (document.forms['dhgen'].elements['startpack'].value == "Mendicantine Missionary") { ss('thronetotal',parseInt(gs('thronetotal')/2)); } //Vow of Poverty = 1/2 starting Thrones
}

function clearstats()
{
	ss('wsbase',0);
	ss('wswtra',0);
	ss('wsptra',0);
	ss('wsspec',0);
	ss('wsdiv',0);

	ss('bsbase',0);
	ss('bswtra',0);
	ss('bsptra',0);
	ss('bsspec',0);
	ss('bsdiv',0);

	ss('sbase',0);
	ss('swtra',0);
	ss('sptra',0);
	ss('sspec',0);
	ss('sdiv',0);

	ss('tbase',0);
	ss('twtra',0);
	ss('tptra',0);
	ss('tspec',0);
	ss('tdiv',0);

	ss('agbase',0);
	ss('agwtra',0);
	ss('agptra',0);
	ss('agspec',0);
	ss('agdiv',0);

	ss('intbase',0);
	ss('intwtra',0);
	ss('intptra',0);
	ss('intspec',0);
	ss('intdiv',0);

	ss('perbase',0);
	ss('perwtra',0);
	ss('perptra',0);
	ss('perspec',0);
	ss('perdiv',0);

	ss('wpbase',0);
	ss('wpwtra',0);
	ss('wpptra',0);
	ss('wpspec',0);
	ss('wpdiv',0);

	ss('felbase',0);
	ss('felwtra',0);
	ss('felptra',0);
	ss('felspec',0);
	ss('feldiv',0);

	ss('woundbase',0);
	ss('woundwtra',0);
	ss('woundptra',0);
	ss('woundspec',0);
	ss('wounddiv',0);

	ss('fatebase',0);
	ss('fatewtra',0);
	ss('fateptra',0);
	ss('fatespec',0);
	ss('fatediv',0);

	ss('insroll1',0);
	ss('insbase',0);
	ss('inswtra',0);
	ss('insptra',0);
	ss('insspec',0);
	ss('insdiv',0);

	ss('corroll1',0);
	ss('corbase',0);
	ss('corwtra',0);
	ss('corptra',0);
	ss('corspec',0);
	ss('cordiv',0);

	ss('throneroll1',0);
	ss('thronebase',0);
	ss('thronewtra',0);
	ss('throneptra',0);
	ss('thronespec',0);
	ss('thronediv',0);
}

function clearspec()
{
	ss('wsspec',0);
	ss('bsspec',0);
	ss('sspec',0);
	ss('tspec',0);
	ss('agspec',0);
	ss('intspec',0);
	ss('perspec',0);
	ss('wpspec',0);
	ss('felspec',0);
	ss('woundspec',0);
	ss('fatespec',0);
	ss('insspec',0);
	ss('corspec',0);
	ss('thronespec',0);
}

function cleardiv()
{
	ss('wsdiv',0);
	ss('bsdiv',0);
	ss('sdiv',0);
	ss('tdiv',0);
	ss('agdiv',0);
	ss('intdiv',0);
	ss('perdiv',0);
	ss('wpdiv',0);
	ss('feldiv',0);
	ss('wounddiv',0);
	ss('fatediv',0);
	ss('insdiv',0);
	ss('cordiv',0);
	ss('thronediv',0);
}


//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

//Fills out the skills and talents for the given career
function choosecareer(derp,hw,roll)
{
	clearspec();

	if (derp.selectedIndex==0)
	{ document.getElementById('careerdiv').style.visibility='hidden'; }
	else
	{ document.getElementById('careerdiv').style.visibility='visible'; }

	chtd('skillstd',fillclassskills(derp.value));
	chtd('talentstd',filltalents(derp.value));
	chtd('geartd',fillgear(derp.value));
	chtd('carmementotd',fillcarmemento(derp.value));

	if (derp.value=='Tech-Priest') { ss('gchoice1',rd(10)); }
	//Special tables
	if (derp.value=='Imperial Psyker') { chtd('specialtd1','Sanctioning Side Effects:'); chtd('specialtd2',fillspecial(derp.value)); chtd('agespan','4d10'); chtd('ageroll',''); ss('age',0); document.forms['dhgen'].elements['ageopt'].selectedIndex = 0; }
	else { chtd('specialtd1',''); chtd('specialtd2',''); chtd('agespan','1d10'); chtd('ageroll',''); ss('age',0); document.forms['dhgen'].elements['ageopt'].selectedIndex = 0; }

	if (derp.value=='Adept' && hw.value==4) { ss('intwtra',3); ss('agwtra',0); ss('bswtra',0); ss('perwtra',0); ss('wpwtra',0); }
	if (derp.value=='Assassin' && hw.value==4) { ss('intwtra',0); ss('agwtra',3); ss('bswtra',0); ss('perwtra',0); ss('wpwtra',0); }
	if (derp.value=='Guardsman' && hw.value==4) { ss('intwtra',0); ss('agwtra',0); ss('bswtra',3); ss('perwtra',0); ss('wpwtra',0); }
	if (derp.value=='Scum' && hw.value==4) { ss('intwtra',0); ss('agwtra',0); ss('bswtra',0); ss('perwtra',3); ss('wpwtra',0); }
	if (derp.value=='Tech-Priest' && hw.value==4) { ss('intwtra',0); ss('agwtra',0); ss('bswtra',0); ss('perwtra',0); ss('wpwtra',3); }

	updatestats();

	if (hw.value==6){ var thrones = gs('thronetotal'); ss('thronetotal',thrones*2); }

	if (roll===0) { markchosen('careerroll'); }

	gendercheck(derp);
	checkpackages(hw,derp);
}

//Randomize function, matches the roll values given in the books
function randomcareer(derp,hw)
{
	var roll = rd(100);
	chtd('careerroll',"(" + roll + ")");
	if (hw.value==0||hw.value==9) //Feral World
	{
		if (roll>=1 && roll<=30) { derp.selectedIndex = 1; }
		if (roll>=31 && roll<=80) { derp.selectedIndex = 2; }
		if (roll>=81 && roll<=90) { derp.selectedIndex = 3; }
		if (roll>=91) { derp.selectedIndex = 4; }
	}
	if (hw.value==1||hw.value==10||hw.value==13) //Hive World
	{
		if (roll>=1 && roll<=17) { derp.selectedIndex = 1; }
		if (roll>=18 && roll<=20) { derp.selectedIndex = 2; }
		if (roll>=21 && roll<=25) { derp.selectedIndex = 3; }
		if (roll>=26 && roll<=35) { derp.selectedIndex = 4; }
		if (roll>=36 && roll<=40) { derp.selectedIndex = 5; }
		if (roll>=41 && roll<=89) { derp.selectedIndex = 6; }
		if (roll>=90) { derp.selectedIndex = 7; }
	}
	if (hw.value==2||hw.value==11||hw.value==12) //Imperial World
	{
		if (roll>=1 && roll<=12) { derp.selectedIndex = 1; }
		if (roll>=13 && roll<=25) { derp.selectedIndex = 2; }
		if (roll>=26 && roll<=38) { derp.selectedIndex = 3; }
		if (roll>=39 && roll<=52) { derp.selectedIndex = 4; }
		if (roll>=53 && roll<=65) { derp.selectedIndex = 5; }
		if (roll>=66 && roll<=79) { derp.selectedIndex = 6; }
		if (roll>=80 && roll<=90) { derp.selectedIndex = 7; }
		if (roll>=91) { derp.selectedIndex = 8; }
	}
	if (hw.value==3||hw.value==8) //Void Born
	{
		if (roll>=1 && roll<=10) { derp.selectedIndex = 1; }
		if (roll>=11 && roll<=20) { derp.selectedIndex = 2; }
		if (roll>=21 && roll<=25) { derp.selectedIndex = 3; }
		if (roll>=26 && roll<=35) { derp.selectedIndex = 4; }
		if (roll>=36 && roll<=75) { derp.selectedIndex = 5; }
		if (roll>=76 && roll<=85) { derp.selectedIndex = 6; }
		if (roll>=86) { derp.selectedIndex = 7; }
	}
	if (hw.value==4) //Forge World
	{
		if (roll>=1 && roll<=25) { derp.selectedIndex = 1; }
		if (roll>=26 && roll<=35) { derp.selectedIndex = 2; }
		if (roll>=36 && roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61 && roll<=70) { derp.selectedIndex = 4; }
		if (roll>=71) { derp.selectedIndex = 5; }
	}
	if (hw.value==5) //Mind Cleansed
	{
		if (roll>=1 && roll<=15) { derp.selectedIndex = 1; }
		if (roll>=16 && roll<=50) { derp.selectedIndex = 2; }
		if (roll>=51 && roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61 && roll<=80) { derp.selectedIndex = 4; }
		if (roll>=81 && roll<=90) { derp.selectedIndex = 5; }
		if (roll>=91) { derp.selectedIndex = 6; }
	}
	if (hw.value==6) //Noble Born
	{
		if (roll>=1 && roll<=18) { derp.selectedIndex = 1; }
		if (roll>=19 && roll<=30) { derp.selectedIndex = 2; }
		if (roll>=31 && roll<=40) { derp.selectedIndex = 3; }
		if (roll>=41 && roll<=56) { derp.selectedIndex = 4; }
		if (roll>=57 && roll<=75) { derp.selectedIndex = 5; }
		if (roll>=76 && roll<=85) { derp.selectedIndex = 6; }
		if (roll>=86) { derp.selectedIndex = 7; }
	}
	if (hw.value==7) //Schola Progenium
	{
		if (roll>=1 && roll<=20) { derp.selectedIndex = 1; }
		if (roll>=21 && roll<=40) { derp.selectedIndex = 2; }
		if (roll>=41 && roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61 && roll<=80) { derp.selectedIndex = 4; }
		if (roll>=81) { derp.selectedIndex = 5; }
	}
	choosecareer(derp, hw, roll);
}

//Applies stat changes from sanctioning side effects
function choosesansfx(derp, roll)
{
	if (roll===0) { markchosen('sansfxroll'); }
}

//Randomizes sanctioning side effects
function randomsansfx(derp)
{
	var roll = rd(100);
	chtd('sansfxroll',"(" + roll + ")");
	if (roll>=1 && roll<=8)	{ derp.selectedIndex = 1; }
	if (roll>=9 && roll<=14)	{ derp.selectedIndex = 2; }
	if (roll>=15 && roll<=25)	{ derp.selectedIndex = 3; }
	if (roll>=26 && roll<=35)	{ derp.selectedIndex = 4; }
	if (roll>=36 && roll<=42)	{ derp.selectedIndex = 5; }
	if (roll>=43 && roll<=49)	{ derp.selectedIndex = 6; }
	if (roll>=50 && roll<=57)	{ derp.selectedIndex = 7; }
	if (roll>=58 && roll<=63)	{ derp.selectedIndex = 8; }
	if (roll>=64 && roll<=70)	{ derp.selectedIndex = 9; }
	if (roll>=71 && roll<=75)	{ derp.selectedIndex = 10; }
	if (roll>=76 && roll<=88)	{ derp.selectedIndex = 11; }
	if (roll>=89 && roll<=94)	{ derp.selectedIndex = 12; }
	if (roll>=95)	{ derp.selectedIndex = 13; }
	choosesansfx(derp, roll);
}


//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////


//Fills the career selection list based on homeworld
function fillcareer(hw)
{
	if (hw==0) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Assassin">Assassin</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option></select>'); }
	if (hw==9) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Assassin">Assassin</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option></select>'); }
	if (hw==1||hw==10||hw==13) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Arbitrator">Arbitrator</option><option value="Assassin">Assassin</option><option value="Cleric">Cleric</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option><option value="Tech-Priest">Tech-Priest</option></select>'); }
	if (hw==2||hw==11||hw==12) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Adept">Adept</option><option value="Arbitrator">Arbitrator</option><option value="Assassin">Assassin</option><option value="Cleric">Cleric</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option><option value="Tech-Priest">Tech-Priest</option></select>'); }
	if (hw==3||hw==8) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Adept">Adept</option><option value="Arbitrator">Arbitrator</option><option value="Assassin">Assassin</option><option value="Cleric">Cleric</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option><option value="Tech-Priest">Tech-Priest</option></select>'); }
	if (hw==4) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Adept">Adept</option><option value="Assassin">Assassin</option><option value="Guardsman">Guardsman</option><option value="Scum">Scum</option><option value="Tech-Priest">Tech-Priest</option></select>'); }
	if (hw==5) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Arbitrator">Arbitrator</option><option value="Assassin">Assassin</option><option value="Cleric">Cleric</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Tech-Priest">Tech-Priest</option></select>'); }
	if (hw==6) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Adept">Adept</option><option value="Arbitrator">Arbitrator</option><option value="Assassin">Assassin</option><option value="Cleric">Cleric</option><option value="Guardsman">Guardsman</option><option value="Imperial Psyker">Imperial Psyker</option><option value="Scum">Scum</option></select>'); }
	if (hw==7) { return('<select name="career" onchange="choosecareer(this.form.career,hw,0); gendercheck(this.form.career);"><option>Select Career</option><option value="Adept">Adept</option><option value="Arbitrator">Arbitrator</option><option value="Cleric">Cleric</option><option value="Guardsman">Guardsman</option><option value="Sororitas">Sororitas</option></select>'); }
}

//Fills out the traits granted from starting homeworld
function filltraits(hw)
{
	if (hw==0) { return('Iron Stomach, Primitive, Rite of Passage, Wilderness Savvy'); }
	if (hw==1) { return('Accustomed to Crowds, Caves of Steel, Hivebound, Wary'); }
	if (hw==2) { return('Blessed Ignorance, Hagiography, Litugical Familiarity, Superior Origins'); }
	if (hw==3) { return('Charmed, Ill-Omened, Shipwise, Void Accustomed'); }
	if (hw==4) { return('Fit for Purpose, Stranger to the Cult, Credo Omnissiah'); }
	if (hw==5) { return('Engram Implantation, Failsafe Control, Imperial Conditioning, Through a Mirror Darkly'); }
	if (hw==6) { return('Etiquette, Supremely Connected, Vendetta, Wealth'); }
	if (hw==7) { return('Schola Education, Skill at Arms, Sheltered Upbringing, Tempered Will'); }
	if (hw==8) { return('Shipwise, Void Accustomed, Naval Lineage Skills, Close-Quarter Fighter, Officer on Deck'); }
	if (hw==9) { return('Primitive, Wilderness Savvy, Dusk Native Skills, Bad Blood, Dark Tales, Little Left to Fear'); }
	if (hw==10) { return('Caves of Steel, Hivebound, Wary, Gunmetal Hiver Skills, Packing Iron, Way of the Gun'); }
	if (hw==11) { return('Blessed Ignorance, Hagiography, Litugical Familiarity, Barren World, Beloved of the God-Emperor'); }
	if (hw==12) { return('Blighted Origins, Decayed Society, Litugical Familiarity'); }
	if (hw==13) { return('Accustomed to Crowds, Caves of Steel, Hivebound, Volg Hiver Skills, Born Survivor, Grim'); }
}

//Fills out the skills granted from chosen homeworld
function fillworldskills(hw)
{
	if (hw==0) { return('Speak Language (Tribal Dialect) (Int); Navigation (Surface) (Int) (Wild. Sav.), Survival (Int) (Wild. Sav.), and Tracking (Int) (Wild. Sav.) as Basic Skills'); }
	if (hw==1) { return('Speak Language (Hive Dialect) (Int); Tech-Use (Int) (Caves of Steel) as Basic Skill'); }
	if (hw==2) { return('Common Lore (Imperial Creed) (Int) (Hagi.), Common Lore (Imperium) (Int) (Hagi.), Common Lore (War) (Int) (Hagi.), Literacy (Int) (Lit. Fam.), Speak Language (High Gothic) (Int) (Lit. Fam.) as Basic Skills'); }
	if (hw==3) { return('Speak Language (Ship Dialect) (Int); Navigation (Stellar) (Int) (Shipwise), Pilot (Starcraft) (Ag) (Shipwise) as Basic Skills'); }
	if (hw==4) { return('Common Lore (Tech) (Int) and Common Lore (Machine Cult) (Int) as Basic Skills'); }
	if (hw==5) { return('Deceive (Fel) (Engram), Intimidate (S) (Engram); Common Lore (Tech) (Int) (Engram), Survival (Int) (Engram) as Basic Skills.'); }
	if (hw==6) { return('Literacy (Int), Speak Language (High Gothic) (Int), Speak Language (Low Gothic) (Int)'); }
	if (hw==7) { return('Literacy (Int), Speak Language (High Gothic) (Int), Speak Language (Low Gothic) (Int); Common Lore (Administratum) (Int) (Sch. Ed.), Common Lore (Ecclesarchy) (Int) (Sch. Ed.), Common Lore (Imperial Creed) (Int) (Sch. Ed.), Common Lore (Imperium) (Int) (Sch. Ed.), Common Lore (War) (Int) (Sch. Ed.), Scholastic Lore (Philosophy) (Int) (Sch. Ed.) as Basic Skills'); }
	if (hw==8) { return('Speak Language (Ship Dialect) (Int), Speak Language (Battlefleet War Cant) (Int) (Nav. Lin. Sk.); Navigation (Stellar) (Int) (Shipwise), Pilot (Starcraft) (Ag) (Shipwise), Common Lore (Tech) (Int) (Nav. Lin. Sk.) Basic Skills'); }
	if (hw==9) { return('Speak Language (Tribal Dialect) (Int), Speak Language (Dusk Cant) (Int) (Dusk Nat. Sk.), Common Lore (Dusk Folklore) (Int) (Dark Tales); Navigation (Surface) (Int) (Wild. Sav.), Survival (Int) (Wild. Sav.), and Tracking (Int) (Wild. Sav.), Forbidden Lore (Daemonology) (Int) (Dark Tales), Scholastic Lore (Occult) (Int) (Dark Tales) as Basic Skills'); }
	if (hw==10) { return('Speak Language (Hive Dialect) (Int), Speak Language (Metallican Hive Dialect) (Int) (Gunm. Hiver Sk.); Tech-Use (Int) as Basic Skill (Caves of Steel)'); }
	if (hw==11) { return('Common Lore (Imperial Creed) (Int) (Hagi.), Common Lore (Imperium) (Int) (Hagi.), Common Lore (War) (Int) (Hagi.), Literacy (Int) (Lit. Fam.), Speak Language (High Gothic) (Int) (Lit. Fam.) as Basic Skills'); }
	if (hw==12) { return('Deceive (Fel) (Dec. Soc.); Common Lore (Underworld) (Int) (Dec. Soc.), Forbidden Lore (Cults) (Int) (Dec. Soc.), Forbidden Lore (Heresy) (Int) (Dec. Soc.) as Basic Skills'); }
	if (hw==13) { return('Speak Language (Hive Dialect) (Int), Intimidate (S) (Volg Hiv. Sk.), Speak Language (Volg Hiver Dialect) (Int) (Volg Hiv. Sk.); Tech-Use (Int) as Basic Skill (Caves of Steel)'); }
}

//Fills out starting talents from chosen homeworld, if any
function fillworldtalents(hw)
{
	if (hw==0) { return('None'); }
	if (hw==1) { return('None'); }
	if (hw==2) { return('None'); }
	if (hw==3) { return('None'); }
	if (hw==4) { return('Technical Knock (Credo Omnissiah)'); }
	if (hw==5) { return('Jaded (Engram), Pistol Weapon Training (Las) (Engram), Pistol Weapon Training (SP) (Engram)'); }
	if (hw==6) { return('Peer (Nobility) (Supremely Connected), <select name="wtchoice1"><option value="Peer (Academics)">Peer (Academics)</option><option value="Peer (Adeptus Mechanicus)">Peer (Adeptus Mechanicus)</option><option value="Peer (Administratum)">Peer (Administratum)</option><option value="Peer (Astropaths)">Peer (Astropaths)</option><option value="Peer (Ecclesiarchy)">Peer (Ecclesiarchy)</option><option value="Peer (Government)">Peer (Government)</option><option value="Peer (Mercantile)">Peer (Mercantile)</option><option value="Peer (Military)">Peer (Military)</option><option value="Peer (Underworld)">Peer (Underworld)</option></select> (Supremely Connected)'); }
	if (hw==7) { return('Melee Weapons Training (Primitive) (Skill at Arms), <select name="wtchoice1"><option value="Basic Weapons Training (Las)">Basic Weapons Training (Las)</option><option value="Basic Weapons Training (SP)">Basic Weapons Training (SP)</option></select> (Skill at Arms), <select name="wtchoice2"><option value="Pistol Training (Las)">Pistol Training (Las)</option><option value="Pistol Training (SP)">Pistol Training (SP)</option></select> (Skill at Arms)'); }
	if (hw==8) { return('Basic Weapons Training (SP) (Close-Quarter Fighter)'); }
	if (hw==9) { return('None'); }
	if (hw==10) { return('Pistol Training (SP) (Way of the Gun)'); }
	if (hw==11) { return('Resistance (Cold) (Barren World)');} 
	if (hw==12) { return('Paranoia (Blighted Origins)'); }
	if (hw==13) { return('Jaded (Born Survivor), Light Sleeper (Born Survivor), Melee Weapons Training (Primitive) (Born Survivor)'); }
}

function fillhwspec(hw) 
{
	if (hw==0||hw==9) {	return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Superstition</option><option value="Dirt Ward">Dirt Ward</option><option value="Unlucky Colour">Unlucky Colour</option><option value="Hunter&apos;s Oath">Hunter&apos;s Oath</option><option value="Thirsty Blade">Thirsty Blade</option><option value="Spirit Shackle">Spirit Shackle</option><option value="Warrior Death">Warrior Death</option><option value="Power Of Names">Power Of Names</option><option value="Lonely Dead">Lonely Dead</option><option value="Living Record">Living Record</option><option value="Nemesis">Nemesis</option></select>'); } //Feral - Superstitions
	if (hw==1||hw==10||hw==13) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Hive Class</option><option value="Dross Hound">Dross Hound</option><option value="Ganger Scum">Ganger Scum</option><option value="Factory Dregs">Factory Dregs</option><option value="Middle Hive">Middle Hive</option><option value="Specialist">Specialist</option><option value="Hive Noble">Hive Noble</option></select>'); } //Hiver Class
	if (hw==2||hw==11||hw==12) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Planet Of Birth</option><option value="Agri-world">Agri-world</option><option value="Backwater">Backwater</option><option value="Feudal World ">Feudal World</option><option value="War Zone">War Zone</option><option value="Dead Planet">Dead Planet</option><option value="Shrine World">Shrine World</option><option value="Paradise Planet">Paradise Planet</option></select>'); }
	if (hw==3||hw==8) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Ship Tradition</option><option value="Space Hulk">Space Hulk</option><option value="Orbital">Orbital</option><option value="Chartist Vessel">Chartist Vessel</option><option value="War Ship">War Ship</option><option value="Rogue Trader">Rogue Trader</option></select>'); }
	if (hw==4) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Point of Origin</option><option value="Greater Forge World">Greater Forge World</option><option value="Minor Forge World">Minor Forge World</option><option value="Orbital">Orbital</option><option value="Demesne">Demesne</option><option value="Research Outpost">Research Outpost</option><option value="Explorator Fleet">Explorator Fleet</option></select>'); }
	if (hw==5) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Shards of Memory</option><option value="The Shattered Mirror">The Shattered Mirror</option><option value="The Cold Grave">The Cold Grave</option><option value="The Night of the Daemon">The Night of the Daemon</option><option value="The Sole Survivor">The Sole Survivor</option><option value="The Dark Altar">The Dark Altar</option><option value="The Throne of Blood">The Throne of Blood</option><option value="The Nightmare Forest">The Nightmare Forest</option><option value="The Malfian Candidate">The Malfian Candidate</option><option value="The Repairer of Reputations">The Repairer of Reputations</option></select>'); }
	if (hw==6) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Lineage Of Renown</option><option value="Merchant Magnates">Merchant Magnates</option><option value="Family Militant">Family Militant</option><option value="Commanders of Mankind">Commanders of Mankind</option><option value="Provender of the Imperium">Provender of the Imperium</option><option value="House of the Iron Spires">House of the Iron Spires</option><option value="The Blood of Greatness">The Blood of Greatness</option><option value="Rogue&apos;s Fortune">Rogue&apos;s Fortune</option><option value="Shadowed Blood">Shadowed Blood</option></select>'); }
	if (hw==7) { return('<select name="hwspec" onchange="markchosen(\'hwspecroll\');"><option>Select Family&apos;s Fate</option><option value="Warrior Martyr">Warrior Martyr</option><option value="Slaughtered by Rebels">Slaughtered by Rebels</option><option value="Distant Outpost">Distant Outpost</option><option value="Lost to the Void">Lost to the Void</option><option value="Without a Trace">Without a Trace</option><option value="Never to Return">Never to Return</option><option value="Not Spoken Of">Not Spoken Of</option></select>'); }
}

function fillhwspectitle(hw)
{
	if (hw==0||hw==9) {	return('Superstition: '); }
	if (hw==1||hw==10||hw==13) { return('Hive Class: '); }
	if (hw==2||hw==11||hw==12) { return('Planet of Birth: '); }
	if (hw==3||hw==8) { return('Ship Tradition: '); }
	if (hw==4) { return('Point of Origin: '); }
	if (hw==5) { return('Shards of Memory: '); }
	if (hw==6) { return('Lineage of Renown: '); }
	if (hw==7) { return('Family&apos;s Fate: '); }
}

function randomhwspec(hw,derp)
{
	var roll = rd(100);
	chtd('hwspecroll',"(" + roll + ")");
	if (hw.value==0||hw.value==9)
	{
		if (roll>=1&&roll<=10) { derp.selectedIndex = 1; }
		if (roll>=11&&roll<=20) { derp.selectedIndex = 2; }
		if (roll>=21&&roll<=30) { derp.selectedIndex = 3; }
		if (roll>=31&&roll<=40) { derp.selectedIndex = 4; }
		if (roll>=41&&roll<=50) { derp.selectedIndex = 5; }
		if (roll>=51&&roll<=60) { derp.selectedIndex = 6; }
		if (roll>=61&&roll<=70) { derp.selectedIndex = 7; }
		if (roll>=71&&roll<=80) { derp.selectedIndex = 8; }
		if (roll>=81&&roll<=90) { derp.selectedIndex = 9; }
		if (roll>=91&&roll<=100) { derp.selectedIndex = 10; }
	}
	if (hw.value==1||hw.value==10||hw.value==13)
	{
		if (roll>=1&&roll<=20) { derp.selectedIndex = 1; }
		if (roll>=21&&roll<=40) { derp.selectedIndex = 2; }
		if (roll>=41&&roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61&&roll<=80) { derp.selectedIndex = 4; }
		if (roll>=81&&roll<=90) { derp.selectedIndex = 5; }
		if (roll>=91&&roll<=100) { derp.selectedIndex = 6; }
	}
	if (hw.value==2||hw.value==11||hw.value==12)
	{
		if (roll>=1&&roll<=20) { derp.selectedIndex = 1; }
		if (roll>=21&&roll<=40) { derp.selectedIndex = 2; }
		if (roll>=41&&roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61&&roll<=70) { derp.selectedIndex = 4; }
		if (roll>=71&&roll<=80) { derp.selectedIndex = 5; }
		if (roll>=81&&roll<=90) { derp.selectedIndex = 5; }
		if (roll>=91&&roll<=100) { derp.selectedIndex = 6; }
	}

	if (hw.value==3||hw.value==8)
	{
		if (roll>=1&&roll<=20) { derp.selectedIndex = 1; }
		if (roll>=21&&roll<=40) { derp.selectedIndex = 2; }
		if (roll>=41&&roll<=60) { derp.selectedIndex = 3; }
		if (roll>=61&&roll<=80) { derp.selectedIndex = 4; }
		if (roll>=81&&roll<=100) { derp.selectedIndex = 5; }
	}

	if (hw.value==4)
	{
		if (roll>=1&&roll<=30) { derp.selectedIndex = 1; }
		if (roll>=31&&roll<=47) { derp.selectedIndex = 2; }
		if (roll>=48&&roll<=61) { derp.selectedIndex = 3; }
		if (roll>=62&&roll<=74) { derp.selectedIndex = 4; }
		if (roll>=75&&roll<=89) { derp.selectedIndex = 5; }
		if (roll>=90&&roll<=100) { derp.selectedIndex = 6; }
	}
	if (hw.value==5)
	{
		if (roll>=1&&roll<=22) { derp.selectedIndex = 1; }
		if (roll>=23&&roll<=34) { derp.selectedIndex = 2; }
		if (roll>=35&&roll<=40) { derp.selectedIndex = 3; }
		if (roll>=41&&roll<=52) { derp.selectedIndex = 4; }
		if (roll>=53&&roll<=61) { derp.selectedIndex = 5; }
		if (roll>=62&&roll<=71) { derp.selectedIndex = 6; }
		if (roll>=72&&roll<=80) { derp.selectedIndex = 7; }
		if (roll>=81&&roll<=95) { derp.selectedIndex = 8; }
		if (roll>=96&&roll<=100) { derp.selectedIndex = 9; }
	}
	if (hw.value==6)
	{
		if (roll>=1&&roll<=15) { derp.selectedIndex = 1; }
		if (roll>=16&&roll<=30) { derp.selectedIndex = 2; }
		if (roll>=31&&roll<=45) { derp.selectedIndex = 3; }
		if (roll>=46&&roll<=60) { derp.selectedIndex = 4; }
		if (roll>=61&&roll<=75) { derp.selectedIndex = 5; }
		if (roll>=76&&roll<=85) { derp.selectedIndex = 6; }
		if (roll>=86&&roll<=95) { derp.selectedIndex = 7; }
		if (roll>=96&&roll<=100) { derp.selectedIndex = 8; }
	}
	if (hw.value==7)
	{
		if (roll>=1&&roll<=25) { derp.selectedIndex = 1; }
		if (roll>=26&&roll<=45) { derp.selectedIndex = 2; }
		if (roll>=46&&roll<=65) { derp.selectedIndex = 3; }
		if (roll>=66&&roll<=75) { derp.selectedIndex = 4; }
		if (roll>=76&&roll<=85) { derp.selectedIndex = 5; }
		if (roll>=86&&roll<=95) { derp.selectedIndex = 6; }
		if (roll>=96&&roll<=100) { derp.selectedIndex = 7; }
	}
}

//Fills out the skill list for the chosen class, enter starting thrones
function fillclassskills(derp)
{
	if (derp=="Adept") { ss('throneroll1',rd(10)); ss('thronebase',100); return('Speak Language (Low Gothic) (Int), Literacy (Int), Common Lore (Imperium) (Int), <select name="schoice1"><option value="Trade (Copyist) (Int)">Trade (Copyist) (Int)</option><option value="Trade (Valet) (Fel)">Trade (Valet) (Fel)</option></select>,<select name="schoice2"><option value="Scholastic Lore (Legend) (Int)">Scholastic Lore (Legend) (Int)</option><option value="Common Lore (Tech) (Int)">Common Lore (Tech) (Int)</option></select>'); }
	if (derp=="Arbitrator") { ss('throneroll1',rd(10)+rd(10)); ss('thronebase',50); return('Speak Language (Low Gothic) (Int), Literacy (Int), Common Lore (Adeptus Arbites) (Int), Common Lore (Imperium) (Int), Inquiry (Fel)'); }
	if (derp=="Assassin") { ss('throneroll1',rd(10)+rd(10)+rd(10)); ss('thronebase',120); return('Speak Language (Low Gothic) (Int), Awareness (Per), Dodge (Ag)'); }
	if (derp=="Cleric") { ss('throneroll1',rd(10)+rd(10)+rd(10)+rd(10)+rd(10)); ss('thronebase',300); return('Speak Language (Low Gothic) (Int), Common Lore (Imperial Creed) (Int), Literacy (Int), <select name="schoice1"><option value="Performer (Singer) (Fel)">Performer (Singer) (Fel)</option><option value="Trade (Copyist) (Int)">Trade (Copyist) (Int)</option></select>, <select name="schoice2"><option value="Trade (Cook) (Int)">Trade (Cook) (Int)</option><option value="Trade (Valet) (Fel)">Trade (Valet) (Fel)</option></select>'); }
	if (derp=="Guardsman") { ss('throneroll1',rd(10)); ss('thronebase',70); return('Speak Language (Low Gothic) (Int), <select name="schoice1"><option value="Drive (Ground Vehicle) (Ag)">Drive (Ground Vehicle) (Ag)</option><option value="Swim (S)">Swim (S)</option>'); }
	if (derp=="Imperial Psyker") { ss('throneroll1',rd(5)); ss('thronebase',50); return('Speak Language (Low Gothic) (Int), Psyniscience (Per), Invocation (WP), Literacy (Int), <select name="schoice1"><option value="Trade (Merchant) (Fel)"> Trade (Merchant) (Fel)</option><option value="Trade (Soothsayer) (Fel)">Trade (Soothsayer) (Fel)</option></select>'); }
	if (derp=="Scum") { ss('throneroll1',rd(5)); ss('thronebase',10); return('Speak Language (Low Gothic) (Int), Blather (Fel), Deceive (Fel), Awareness (Per), Common Lore (Imperium) (Int), <select name="schoice1"><option value="Charm (Fel)">Charm (Fel)</option><option value="Dodge (Ag)">Dodge (Ag)</option></value>'); }
	if (derp=="Tech-Priest") { ss('throneroll1',rd(10)); ss('thronebase',150); return('Speak Language (Low Gothic) (Int), Tech-Use (Int), Literacy (Int), Secret Tongue (Tech) (Int), <select name="schoice1"><option value="Trade (Scrimshawer) (Ag)">Trade (Scrimshawer) (Ag)</option><option value="Trade (Copyist) (Int)">Trade (Copyist) (Int)</option></select>'); }
	if (derp=="Sororitas") { ss('throneroll1',rd(10)+rd(10)); ss('thronebase',70); return('Common Lore (Imperial Creed) (Int), Literacy (Int), Performer (Singer) (Fel), Speak Language (Low Gothic) (Int), Trade (Copyist) (Int)'); }
}

//Fills out the talent list for the chosen class
function filltalents(derp)
{
	if (derp=="Adept") { return('<select name="tchoice1"><option value="Melee Weapons Training (Primitive)">Melee Weapons Training (Primitive)</option><option value="Pistol Training (SP)">Pistol Training (SP)</option></select>, <select name="tchoice2"><option value="Light Sleeper">Light Sleeper</option><option value="Resistance (Cold)">Resistance (Cold)</option></select>, <select name="tchoice3"><option value="Sprint">Sprint</option><option value="Unremarkable">Unremarkable</option></select>'); }
	if (derp=="Arbitrator") { return('Basic Weapons Training (SP), Melee Weapons Training (Primitive), <select name="tchoice1"><option value="Quick Draw">Quick Draw</option><option value="Rapid Reload">Rapid Reload</option></select>'); }
	if (derp=="Assassin") { return('Melee Weapons Training (Primitive), Basic Weapons Training (SP), Pistol Training (SP), <select name="tchoice1"><option value="Ambidextrous">Ambidextrous</option><option value="Unremarkable">Unremarkable</option></select>, <select name="tchoice2"><option value="Thrown Weapons Training">Thrown Weapons Training</option><option value="Pistol Training (Las)">Pistol Training (Las)</option></select>'); }
	if (derp=="Cleric") { return('Melee Weapons Training (Primitive), Pistol Training (SP), <select name="tchoice1"><option value="Basic Weapons Training (Primitive)">Basic Weapons Training (Primitive)</option><option value="Thrown Weapons Training (Primitive)">Thrown Weapons Training (Primitive)</option></select>'); }
	if (derp=="Guardsman") { return('Melee Weapons Training (Primitive), Basic Weapons Training (Las), <select name="tchoice1"><option value="Pistol Training (Primitive)">Pistol Training (Primitive)</option><option value="Pistol Training (Las)">Pistol Training (Las)</option></select>, <select name="tchoice2"><option value="Basic Weapons Training (Primitive)">Basic Weapons Training (Primitive)</option><option value="Basic Weapons Training (SP)">Basic Weapons Training (SP)</option></select>'); }
	if (derp=="Imperial Psyker") { return('Melee Weapons Training (Primitive), Psy Rating 1, <select name="tchoice1"><option value="Pistol Weapons Training (SP)">Pistol Weapons Training (SP)</option><option value="Pistol Weapons Training (Las)">Pistol Weapons Training (Las)</option></select>'); }
	if (derp=="Scum") { return('Melee Weapons Training (Primitive), Pistol Training (SP), Basic Weapons Training (SP), <select name="tchoice1"><option value="Ambidextrous">Ambidextrous</option><option value="Unremarkable">Unremarkable</option></select>'); }
	if (derp=="Tech-Priest") { return('Melee Weapons Training (Primitive), Basic Weapons Training (Las), Pistol Training (Las), Electro Graft Use'); }
	if (derp=="Sororitas") { return('Basic Weapons Training (Primitive), Melee Weapons Training (Primitive), Pistol Training (Las), Pure Faith'); }
}

//Fills out the starting equipment for the chosen class
function fillgear(derp)
{
	if (derp=="Adept") { return('Administratum robes (Common Quality Clothing), backpack, <select name="gchoice1"><option value="stub revolver and 6 bullets">stub revolver and 6 bullets</option><option value="staff">staff</option></select>, <select name="gchoice2"><option value="auto-quill">auto-quill</option><option value="writing kit">writing kit</option></select>, <select name="gchoice3"><option value="chrono">chrono</option><option value="hour glass">hour glass</option></select>, <select name="gchoice4"><option value="data-slate">data-slate</option><option value="illuminated tome">illuminated tome</option></select>'); }
	if (derp=="Arbitrator") { return('shotgun and 12 shells, club, brass knuckles, knife, uniform (Good Quality Clothing), 3 doses of stimm, injector, Arbitrator ID, chrono, <select name="gchoice1"><option value="pack of lho-sticks">pack of lho-sticks</option><option value="flask of amasec">flask of amasec</option></select>, <select name="gchoice2"><option value="chain coat">chain coat</option><option value="flak vest">flak vest</option><option value="mesh vest">mesh vest</option></select>'); }
	if (derp=="Assassin") { return('sword, knife, 3 doses of stimm, charge (corpse hair), black bodyglove (Common Quality Clothing), <select name="gchoice1"><option value="shotgun and 12 shells">shotgun and 12 shells</option><option value="hunting rifle and 16 rounds">hunting rifle and 16 rounds</option><option value="autogun and 1 clip">autogun and 1 clip</option></select>, <select name="gchoice2"><option value="compact las pistol and 1 charge pack">compact las pistol and 1 charge pack</option><option value="10 throwing knives">10 throwing knives</option></select>'); }
	if (derp=="Cleric") { return('aquila necklace, Ecclesiarchy robes (Good Quality Clothing), 4 candles, charm (skull), backpack, <select name="gchoice1"><option value="hammer">hammer</option><option value="sword">sword</option></select>, <select name="gchoice2"><option value="stub revolver and 6 bullets">stub revolver and 6 bullets</option><option value="autopistol and 1 clip">autopistol and 1 clip</option></select>, <select name="gchoice3"><option value="crossbow and 10 bolts">crossbow and 10 bolts</option><option value="5 throwing knives">5 throwing knives</option></select>, <select name="gchoice4"><option value="chain coat">chain coat</option><option value="flak vest">flak vest</option></select>'); }
	if (derp=="Guardsman") { return('lasgun and 1 charge pack, knife, guard flak armour, 1 week corpse starch rations, <select name="gchoice1"><option value="sword">sword</option><option value="axe">axe</option><option value="hammer">hammer</option></select>, <select name="gchoice2"><option value="flintlock pistol and 12 shots">flintlock pistol and 12 shots</option><option value="las pistol and 1 charge pack">las pistol and 1 charge pack</option></select>, <select name="gchoice3"><option value="bow and 10 arrows">bow and 10 arrows</option><option value="musket and 12 shots">musket and 12 shots</option><option value="shotgun and 12 shells">shotgun and 12 shells</option></select>, <select name="gchoice4"><option value="uniform (Common Quality Clothing)">uniform (Common Quality Clothing)</option><option value="stealth gear (Common Quality Clothing)">stealth gear (Common Quality Clothing)</option><option value="street clothes (Common Quality Clothing)">street clothes (Common Quality Clothing)</option></select>, <select name="gchoice5"><option value="mercenary license">mercenary license</option><option value="explosive collar (still attached)">explosive collar (still attached)</option><option value="Imperial Infantryman&apos;s Uplifting Primer">Imperial Infantryman&apos;s Uplifting Primer</option></select>'); }
	if (derp=="Imperial Psyker") { return('staff, knife (psykana mercy blade), quilted vest, tatty robe (Poor Quality Clothing), Psy-Focus, sanctioning brand, <select name="gchoice1"><option value="axe">axe</option><option value="sword">sword</option></select>, <select name="gchoice2"><option value="book of Imperial saints">book of Imperial saints</option><option value="deck of cards">deck of cards</option><option value="dice">dice</option></select>, <select name="gchoice3"><option value="combat stub revolver and 3 bullets">combat stub revolver and 3 bullets</option><option value="compact las pistol and 1 charge pack">compact las pistol and 1 charge pack</option></select>'); }
	if (derp=="Scum") { return('autopistol and 1 clip, knife, <select name="gchoice1"><option value="autogun and 1 clip">autogun and 1 clip</option><option value="shotgun and 12 shells">shotgun and 12 shells</option></select>, <select name="gchoice2"><option value="brass knuckles">brass knuckles</option><option value="club">club</option></select>, <select name="gchoice3"><option value="quilted vest">quilted vest</option><option value="beast furs">beast furs</option></select>, <select name="gchoice4"><option value="street ware (Poor Quality Clothing)">street ware (Poor Quality Clothing)</option><option value="rags (Poor Quality Clothing)">rags (Poor Quality Clothing)</option><option value="dirty coveralls (Poor Quality Clothing)">dirty coveralls (Poor Quality Clothing)</option></select>'); }
	if (derp=="Tech-Priest") { return('metal staff, las pistol and 1 charge pack, las carbine and 1 charge pack, knife, flak vest, glow lamp, data-slate, Mechanicus robes and vestments (Good Quality Clothing), <input type="text" name="gchoice1" readonly="readonly" size="2" /> spare parts (power cells, wires, chronometers etc), vial of Sacred Machine Oil, Mechanicus implants'); }
	if (derp=="Sororitas") { return('las pistol and charge pack, aquila necklace, chaplet Ecclesiasticus, vestments (Good Quality Clothing), 4 candles, writing kit, copy of the Rules of the Sororitas, Ring of Suffrage, <select name="gchoice1"><option value="club">club</option><option value="flail">flail</option><option value="staff">staff</option></select>, <select name="gchoice2"><option value="carapace chest plate and mesh cowl">carapace chest plate and mesh cowl</option><option value="feudal plate">feudal plate</option></select>'); }
}

//Fills out the unique class-specific selections, e.g. sanctioning side effects
function fillspecial(derp)
{
	if (derp=='Imperial Psyker') { return('<select name="sansfx" onchange="sanc(this.form.sansfx);"><option>Select Side Effect</option><option value="Reconstructed Skull">Reconstructed Skull</option><option value="Hunted">Hunted</option><option value="Unlovely Memories">Unlovely Memories</option><option value="The Horror, the Horror">The Horror, the Horror</option><option value="Pain through Nerve Induction">Pain through Nerve Induction</option><option value="Dental Probes">Dental Probes</option><option value="Optical Rupture">Optical Rupture</option><option value="Screaming Devotions">Screaming Devotions</option><option value="Irradience">Irradience</option><option value="Tongue Bound">Tongue Bound</option><option value="Throne Wed">Throne Wed</option><option value="Witch Prickling">Witch Prickling</option><option value="Hypno-doctrination">Hypno-doctrination</option></select>&nbsp;<input type="button" value="Random" onclick="randomsansfx(this.form.sansfx); sanc(this.form.sansfx);" />&nbsp;&nbsp;<b id="sansfxroll"></b>'); }
}

function sanc(derp)
{
	clearspec();
	if (derp.value=="Reconstructed Skull") { ss('intspec',-3); ss('thronespec',rd(10)+rd(10)+rd(10)+rd(10)+rd(10)); chtd('special2tr','<td>Effects:</td><td>-3 Int, +5d10 Gelt</td>'); }
	if (derp.value=="Hunted") { ss('insspec',rd(10)); chtd('special2tr','<td>Effects:</td><td>+1d10 Insanity Points</td>'); }
	if (derp.value=="Unlovely Memories") { ss('insspec',rd(5)); chtd('special2tr','<td>Effects:</td><td>+1d5 Insanity Points</td>'); }
	if (derp.value=="The Horror, the Horror") { ss('insspec',rd(5)); chtd('special2tr','<td>Effects:</td><td>+1d5 Insanity Points</td>'); }
	if (derp.value=="Pain through Nerve Induction") { chtd('special2tr','<td>Effects:</td><td>None</td>'); }
	if (derp.value=="Dental Probes") { chtd('special2tr','<td>Effects:</td><td>Good Quality carved dentures</td>'); }
	if (derp.value=="Optical Rupture") { chtd('special2tr','<td>Effects:</td><td>Common Quality cybernetic senses</td>'); }
	if (derp.value=="Screaming Devotions") { chtd('special2tr','<td>Effects:</td><td>Vox inducer (no mechanical effect)</td>'); }
	if (derp.value=="Irradience") { chtd('special2tr','<td>Effects:</td><td>Hairless (no mechanical effect)</td>'); }
	if (derp.value=="Tongue Bound") { chtd('special2tr','<td>Effects:</td><td>Hard (-20) Willpower Test to speak Khorne, Tzeentch, Slaanesh, Nurgle</td>'); }
	if (derp.value=="Throne Wed") { chtd('special2tr','<td>Effects:</td><td>Chem Geld talent, chattallium ring</td>'); }
	if (derp.value=="Witch Prickling") { ss('tspec',3); chtd('special2tr','<td>Effects:</td><td>+3 Toughness</td>');}
	if (derp.value=="Hypno-doctrination") { ss('wpspec',3); chtd('special2tr','<td>Effects:</td><td>+3 Willpower</td>'); }
	updatestats();
}

function div(derp)
{
	cleardiv();
	if (derp.value=="Mutation without, corruption within.") { chtd('diveff','Gain one Minor Mutation.');	}
	if (derp.value=="Only the insane have strength enough to prosper. Only those who prosper may judge what is sane.") { ss('insdiv',2); chtd('diveff','+2 Insanity points'); }
	if (derp.value=="Sins hidden in the heart turn all to decay.") { ss('cordiv',3); chtd('diveff','+3 Corruption points'); }
	if (derp.value=="Innocence is an illusion.") { ss('insdiv',1); ss('cordiv',1); chtd('diveff','+1 Corruption point, +1 Insanity point'); }
	if (derp.value=="Dark dreams lie upon the heart.") { ss('cordiv',2); chtd('diveff','+2 Corruption points'); }
	if (derp.value=="The pain of a bullet is ecstasy compared to damnation.") { ss('tdiv',1); chtd('diveff','+1 Toughness'); }
	if (derp.value=="Kill the alien before it can speak its lies.") { ss('agdiv',2); chtd('diveff','+2 Agility'); }
	if (derp.value=="Truth is subjective.") { ss('intdiv',3); ss('cordiv',3); chtd('diveff','+3 Corruption points'); }
	if (derp.value=="Know the mutant; kill the mutant.") { ss('perdiv',2); chtd('diveff','+2 Perception'); }
	if (derp.value=="Even a man who has nothing can still offer his life.") { ss('sdiv',2); chtd('diveff','+2 Strength'); }
	if (derp.value=="If a job is worth doing it is worth dying for.") { chtd('diveff','Gain the Frenzy talent.'); } ///Frenzy talent
	if (derp.value=="Only in death does duty end.") { ss('wounddiv',1); chtd('diveff','+1 Wound'); }
	if (derp.value=="A mind without purpose will wander in dark places.") { ss('fatediv',1); chtd('diveff','+1 Fate point');}
	if (derp.value=="There are no civilians in the battle for survival.") { ss('tdiv',2); ss('wounddiv',1); chtd('diveff','+1 Wound, +2 Toughness'); }
	if (derp.value=="Violence solves everything.") { ss('wsdiv',3); chtd('diveff','+3 Weapon Skill'); }
	if (derp.value=="To war is human.") { ss('agdiv',3); chtd('diveff','+3 Agility'); }
	if (derp.value=="Die if you must, but not with your spirit broken.") { ss('wpdiv',3); chtd('diveff','+3 Willpower'); }
	if (derp.value=="The gun is mightier than the sword.") { ss('bsdiv',3); chtd('diveff','+3 Ballistic Skill'); }
	if (derp.value=="Be a boon to your brothers and bane to your enemies.") { ss('feldiv',3); chtd('diveff','+3 Fellowship'); }
	if (derp.value=="Men must die so that Man endures.") { ss('tdiv',3); chtd('diveff','+3 Toughness'); }
	if (derp.value=="In the darkness, follow the light of Terra.") { ss('wpdiv',3); chtd('diveff','+3 Willpower'); }
	if (derp.value=="The only true fear is of dying with your duty not done.") { ss('wounddiv',2); chtd('diveff','+2 Wounds'); }
	if (derp.value=="Thought begets Heresy; Heresy begets Retribution.") { ss('sdiv',3); chtd('diveff','+3 Strength'); }
	if (derp.value=="The wise man learns from the deaths of others.") { ss('intdiv',3); chtd('diveff','+3 Intelligence'); }
	if (derp.value=="A suspicious mind is a healthy mind.") { ss('perdiv',3); chtd('diveff','+3 Perception'); }
	if (derp.value=="Trust in your fear.") { ss('agdiv',2); ss('fatediv',1); chtd('diveff','+1 Fate point'); }
	if (derp.value=="There is no substitute for zeal.") { ss('tdiv',2); ss('wpdiv',2); chtd('diveff','+2 Toughness, +2 Willpower'); }
	if (derp.value=="Do not ask why you serve. Only ask how.") { ss('wsdiv',2); ss('bsdiv',2); chtd('diveff','+2 Weapon Skill, +2 Ballistic Skill'); }
	updatestats();
}

function randomdiv(derp)
{
	var roll = rd(100);
	chtd('divroll',"(" + roll + ")");
	if (roll==1) { derp.selectedIndex = 1; }
	if (roll>=2&&roll<=3) { derp.selectedIndex = 2; }
	if (roll>=4&&roll<=7) { derp.selectedIndex = 3; }
	if (roll==8) { derp.selectedIndex = 4; }
	if (roll>=9&&roll<=11) { derp.selectedIndex = 5; }
	if (roll>=12&&roll<=15) { derp.selectedIndex = 6; }
	if (roll>=16&&roll<=18) { derp.selectedIndex = 7; }
	if (roll>=19&&roll<=21) { derp.selectedIndex = 8; }
	if (roll>=22&&roll<=26) { derp.selectedIndex = 9; }
	if (roll>=27&&roll<=30) { derp.selectedIndex = 10; }
	if (roll>=31&&roll<=33) { derp.selectedIndex = 11; }
	if (roll>=34&&roll<=38) { derp.selectedIndex = 12; }
	if (roll>=39&&roll<=42) { derp.selectedIndex = 13; }
	if (roll>=43&&roll<=46) { derp.selectedIndex = 14; }
	if (roll>=47&&roll<=50) { derp.selectedIndex = 15; }
	if (roll>=51&&roll<=54) { derp.selectedIndex = 16; }
	if (roll>=55&&roll<=58) { derp.selectedIndex = 17; }
	if (roll>=59&&roll<=62) { derp.selectedIndex = 18; }
	if (roll>=63&&roll<=66) { derp.selectedIndex = 19; }
	if (roll>=67&&roll<=70) { derp.selectedIndex = 20; }
	if (roll>=71&&roll<=74) { derp.selectedIndex = 21; }
	if (roll>=75&&roll<=79) { derp.selectedIndex = 22; }
	if (roll>=80&&roll<=85) { derp.selectedIndex = 23; }
	if (roll>=86&&roll<=90) { derp.selectedIndex = 24; }
	if (roll>=91&&roll<=94) { derp.selectedIndex = 25; }
	if (roll>=95&&roll<=97) { derp.selectedIndex = 26; }
	if (roll>=98&&roll<=99) { derp.selectedIndex = 27; }
	if (roll == 100) { derp.selectedIndex = 28; }
	div(derp);
}

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

//Fill appearance
function gendercheck(career)
{
	if (career.value=='Sororitas') { chtd('gendertd','<select name="gender"><option value="2">Female</option></select>'); }
	else { chtd('gendertd','<select name="gender"><option>Select Gender</option><option value="1">Male</option><option value="2">Female</option></select>'); }
}

function fillbuild(hw)
{
	if (hw==0||hw==9) { return('<select name="build" onchange="markchosen(\'buildroll\');"><option>Select Build</option><option value="Rangy">Rangy</option><option value="Lean">Lean</option><option value="Muscular">Muscular</option><option value="Squat">Squat</option><option value="Strapping">Strapping</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="build" onchange="markchosen(\'buildroll\');"><option>Select Build</option><option value="Runt">Runt</option><option value="Scrawny">Scrawny</option><option value="Wiry">Wiry</option><option value="Lanky">Lanky</option><option value="Brawny">Brawny</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="build" onchange="markchosen(\'buildroll\');"><option>Select Build</option><option value="Slender">Slender</option><option value="Svelte">Svelte</option><option value="Fit">Fit</option><option value="Well-built">Well-built</option><option value="Stocky">Stocky</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="build" onchange="markchosen(\'buildroll\');"><option>Select Build</option><option value="Skeletal">Skeletal</option><option value="Stunted">Stunted</option><option value="Gaunt">Gaunt</option><option value="Gangling">Gangling</option><option value="Spindly">Spindly</option></select>'); }
	chtd('buildroll','');
}

function fillskin(hw)
{
	if (hw==0||hw==9) { return('<select name="skin" onchange="markchosen(\'skinroll\');"><option>Select Skin</option><option value="Dark">Dark</option><option value="Tan">Tan</option><option value="Fair">Fair</option><option value="Ruddy">Ruddy</option><option value="Bronze">Bronze</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="skin" onchange="markchosen(\'skinroll\');"><option>Select Skin</option><option value="Dark">Dark</option><option value="Tan">Tan</option><option value="Fair">Fair</option><option value="Ruddy">Ruddy</option><option value="Stained">Stained</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="skin" onchange="markchosen(\'skinroll\');"><option>Select Skin</option><option value="Dark">Dark</option><option value="Tan">Tan</option><option value="Fair">Fair</option><option value="Ruddy">Ruddy</option><option value="Dyed">Dyed</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="skin" onchange="markchosen(\'skinroll\');"><option>Select Skin</option><option value="Porcelain">Porcelain</option><option value="Fair">Fair</option><option value="Bluish">Bluish</option><option value="Greyish">Greyish</option><option value="Milky">Milky</option></select>'); }
	chtd('skinroll','');
}

function fillhair(hw)
{
	if (hw==0||hw==9) { return('<select name="hair" onchange="markchosen(\'hairroll\');"><option>Select Hair</option><option value="Red">Red</option><option value="Blond">Blond</option><option value="Brown">Brown</option><option value="Black">Black</option><option value="Grey">Grey</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="hair" onchange="markchosen(\'hairroll\');"><option>Select Hair</option><option value="Brown">Brown</option><option value="Mousy">Mousy</option><option value="Dyed">Dyed</option><option value="Grey">Grey</option><option value="Black">Black</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="hair" onchange="markchosen(\'hairroll\');"><option>Select Hair</option><option value="Dyed">Dyed</option><option value="Blond">Blond</option><option value="Brown">Brown</option><option value="Black">Black</option><option value="Grey">Grey</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="hair" onchange="markchosen(\'hairroll\');"><option>Select Hair</option><option value="Ginger">Ginger</option><option value="Blond">Blond</option><option value="Copper">Copper</option><option value="Black">Black</option><option value="Auburn">Auburn</option></select>'); }
	chtd('hairroll','');
}

function filleyes(hw)
{
	if (hw==0||hw==9) { return('<select name="eyes" onchange="markchosen(\'eyesroll\');"><option>Select Eyes</option><option value="Blue">Blue</option><option value="Grey">Grey</option><option value="Brown">Brown</option><option value="Green">Green</option><option value="Yellow">Yellow</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="eyes" onchange="markchosen(\'eyesroll\');"><option>Select Eyes</option><option value="Blue">Blue</option><option value="Grey">Grey</option><option value="Brown">Brown</option><option value="Green">Green</option><option value="Lenses">Lenses</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="eyes" onchange="markchosen(\'eyesroll\');"><option>Select Eyes</option><option value="Blue">Blue</option><option value="Grey">Grey</option><option value="Brown">Brown</option><option value="Green">Green</option><option value="Lenses">Lenses</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="eyes" onchange="markchosen(\'eyesroll\');"><option>Select Eyes</option><option value="Watery Blue">Watery Blue</option><option value="Grey">Grey</option><option value="Black">Black</option><option value="Green">Green</option><option value="Violet">Violet</option></select>'); }
	chtd('eyesroll','');
}

function fillage(hw)
{
	if (hw==0||hw==9) { return('<select name="ageopt" onchange="markchosen(\'ageroll\');"><option>Select Age</option><option value="Warrior">Warrior (15)</option><option value="Old One">Old One (25)</option></select> + <span id="agespan">1d10</span> = <input type="text" name="age" maxlength="2" size="2" />'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="ageopt" onchange="markchosen(\'ageroll\');"><option>Select Age</option><option value="Nipper">Nipper (15)</option><option value="Adult">Adult (25)</option><option value="Old Timer">Old Timer (35)</option></select> + <span id="agespan">1d10</span> = <input type="text" name="age" maxlength="2" size="2" />'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) {return('<select name="ageopt" onchange="markchosen(\'ageroll\');"><option>Select Age</option><option value="Stripling">Stripling (20)</option><option value="Mature">Mature (30)</option><option value="Veteran">Veteran (40)</select> + <span id="agespan">1d10</span> = <input type="text" name="age" maxlength="2" size="2" />'); }
	if (hw==3||hw==8||hw==5) {return('<select name="ageopt" onchange="markchosen(\'ageroll\');"><option>Select Age</option><option value="Youth">Youth (15)</option><option value="Mature">Mature (20)</option><option value="Methuselah">Methuselah (50)</option></select> + <span id="agespan">1d10</span> = <input type="text" name="age" maxlength="2" size="2" />'); }
	chtd('ageroll','');
}

function fillquirk(hw)
{
	if (hw==0||hw==9) { return('<select name="quirk" onchange="markchosen(\'quirkroll\');"><option value="None">None</option><option value="You have hairy knuckles.">Hairy Knuckles</option><option value="You have joined eyebrows.">Joined Eyebrows</option><option value="You wear warpaint.">Warpaint</option><option value="You have hands like spatchcocks">Hands Like Spatchcocks</option><option value="You have filed teeth.">Filed Teeth</option><option value="You have beetling brows.">Beetling Brows</option><option value="You have a musky smell.">Musky Smell</option><option value="You are excessively hairy.">Hairy</option><option value="You have ripped ears.">Ripped Ears</option><option value="You have very long fingernails.">Long Fingernails</option><option value="You have tribal tattooing.">Tribal Tattooing</option><option value="Your body has significant scarring.">Scarring</option><option value="You have an unusual piercing.">Piercing</option><option value="You have cat&apos;s eyes.">Cat&apos;s Eyes</option><option value="You have a small head.">Small Head</option><option value="You have an unusually thick jaw.">Thick Jaw</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="quirk" onchange="markchosen(\'quirkroll\');"><option value="None">None</option><option value="You are pallid.">Pallid</option><option value="You have grimy skin.">Grimy Skin</option><option value="You have outrageous hair.">Outrageous Hair</option><option value="You have rotten teeth.">Rotten Teeth</option><option value="You have an electoo.">Electoo</option><option value="You have an unusual piercing.">Piercing</option><option value="You have a set of piercings.">Set Of Piercings</option><option value="You have a chronic, hacking cough.">Hacking Cough</option><option value="You have tattoos.">Tattoos</option><option value="You have a bullet wound scar.">Bullet Wound Scar</option><option value="You have a nervous tick.">Nervous Tick</option><option value="You have a large mole.">Large Mole</option><option value="You have pollution scars.">Pollutions Scars</option><option value="You hav a hump.">Hump</option><option value="You have unusually small hands.">Small Hands</option><option value="You have a chemical smell.">Chemical Smell</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="quirk" onchange="markchosen(\'quirkroll\');"><option value="None">None</option><option value="You are missing a digit.">Missing Digit</option><option value="You have an aquiline nose.">Aquiline Nose</option><option value="You have warts.">Warts</option><option value="You have a duelling scar.">Duelling Scar</option><option value="You have a pierced nose.">Pierced Nose</option><option value="You have a nervous tick.">Nervous Tick</option><option value="You have an aquila tattoo.">Aquila Tattoo</option><option value="You have a faint smell about you.">Faint Smell</option><option value="You are covered in Pox marks.">Pox Marks</option><option value="You have a devotional scar.">Devotional Scar</option><option value="You have an electoo">Electoo</option><option value="You have quivering fingers.">Quivering Fingers</option><option value="You have pierced ears.">Pierced Ears</option><option value="You have a sinister boil.">Sinister Boil</option><option value="You wear make-up.">Make-up</option><option value="You walk with a slouched gait.">Slouched Gait</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="quirk" onchange="markchosen(\'quirkroll\');"><option value="None">None</option><option value="You are pallid.">Pallid</option><option value="You are bald.">Bald</option><option value="You have unusually long fingers.">Long Fingers</option><option value="You have tiny ears.">Tiny Ears</option><option value="You have spindly limbs.">Spindly Limbs</option><option value="You have yellow fingernails.">Yellow Fingernails</option><option value="You have stumpy teeth.">Stumpy Teeth</option><option value="You have widely-spaced eyes.">Widely Spaced Eyes</option><option value="You have a large head.">Large Head</option><option value="You have a curved spine.">Curved Spine</option><option value="You are completely hairless.">Hairless</option><option value="You have unusually elegant hands.">Elegant Hands</option><option value="You have long, flowing hair.">Flowing Hair</option><option value="You are an albino.">Albino</option><option value="You walk with a limping gait.">Limping Gait</option><option value="You have a stooped stance.">Stooped Stance</option></select>'); }
	chtd('quirkroll','');
}

function fillmemento(hw)
{
	if (hw==0||hw==9) { return('<select name="memento"><option>None</option><option value="length of braided hair">length of braided hair</option><option value="animal skull">animal skull</option><option value="bag of home world dirt">bag of home world dirt</option><option value="broken spear tip">broken spear tip</option><option value="leather pouch">leather pouch</option><option value="collection of">dried leaves collection of dried leaves</option><option value="carved idol">carved idol</option><option value="stone finger">ring stone finger ring</option><option value="dried umbilical cord (yours)">dried umbilical cord (yours)</option><option value="fire stick">fire stick</option><option value="fur/skin cloak">fur/skin cloak</option><option value="stone knife">stone knife</option><option value="hide boots">hide boots</option><option value="human skull">human skull</option><option value="leather bracers">leather bracers</option><option value="bag of ashes">bag of ashes</option><option value="necklace of teeth">necklace of teeth</option><option value="tallow candle">tallow candle</option><option value="ceremonial mask">ceremonial mask</option><option value="dried frog">dried frog</option></select>'); }
	if (hw==1||hw==10||hw==13||hw==4) { return('<select name="memento"><option>None</option><option value="heavy gloves">heavy gloves</option><option value="jacket in gang\hive colors">jacket in gang\hive colors</option><option value="deck of cards">deck of cards</option><option value="wooden dice">wooden dice</option><option value="spent bullet casing">spent bullet casing</option><option value="engraved knife">engraved knife</option><option value="hipflask">hipflask</option><option value="identity card">identity card</option><option value="tattoo kit">tattoo kit</option><option value="spent bullet casing">spent bullet casing</option><option value="leather cap">leather cap</option><option value="vial of glowing water">vial of glowing water</option><option value="smoking pipe">smoking pipe</option><option value="mass of melted bullets">mass of melted bullets</option><option value="crystalline carving">crystalline carving</option><option value="steel toecap boots">steel toecap boots</option><option value="small length of chain">small length of chain</option><option value="lucky cog">lucky cog</option><option value="tube of grease">tube of grease</option><option value="fancy vest">fancy vest</option></select>'); }
	if (hw==2||hw==11||hw==12||hw==6||hw==7) { return('<select name="memento"><option>None</option><option value="brocade coat">brocade coat</option><option value="metal lho-stick case">metal lho-stick case</option><option value="all-weather cape">all-weather cape</option><option value="ancestral sabre">ancestral sabre</option><option value="glassteel disc">glassteel disc</option><option value="necklace">necklace</option><option value="metal flute">metal flute</option><option value="book of inspiring words">book of inspiring words</option><option value="icon of the Emperor">icon of the Emperor</option><option value="bent metal coin">bent metal coin</option><option value="antique earring">antique earring</option><option value="tattered velvet cloak">tattered velvet cloak</option><option value="impressive hat">impressive hat</option><option value="incense sticks">incense sticks</option><option value="old hab door key">old hab door key</option><option value="shard of stained glass">shard of stained glass</option><option value="headband">headband</option><option value="skull charm">skull charm</option><option value="pilgrimage token">pilgrimage token</option><option value="vial of blessed water">vial of blessed water</option></select>'); }
	if (hw==3||hw==8||hw==5) { return('<select name="memento"><option>None</option><option value="bag of salt">bag of salt</option><option value="ceremonial sword">ceremonial sword</option><option value="corpse hair amulet">corpse hair amulet</option><option value="three quartz marbles">three quartz marbles</option><option value="bone dice">bone dice</option><option value="wooden beads">wooden beads</option><option value="dogtags">dogtags</option><option value="glow lantern">glow lantern</option><option value="aquilia pendent">aquilia pendent</option><option value="squeezebox">squeezebox</option><option value="lodestone">lodestone</option><option value="lucky rat&apos;s foot">lucky rat&apos;s foot</option><option value="mirror">mirror</option><option value="asteroid fragment">asteroid fragment</option><option value="deck plate section">deck plate section</option><option value="expired rad-counter">expired rad-counter</option><option value="glass lens">glass lens</option><option value="bag of seeds">bag of seeds</option><option value="polished coral icon">polished coral icon</option><option value="whittling knife">whittling knife</option></select>'); }
	chtd('mementoroll','');
}

function fillcarmemento(car)
{
	var durr;
	switch(car)	{
		case "Adept": durr = '<select name="carmemento"><option>None</option><option value="brass quill tip">brass quill tip</option><option value="ribbon bookmark">ribbon bookmark</option><option value="cracked lens">cracked lens</option><option value="singed parchment">singed parchment</option><option value="vial of powdered ink">vial of powdered ink</option><option value="rusty scalpel">rusty scalpel</option><option value="map fragment">map fragment</option><option value="finger bone">finger bone</option><option value="wire coil">wire coil</option><option value="lump of candle wax">lump of candle wax</option><option value="glass key">glass key</option><option value="charcoal stick">charcoal stick</option><option value="own severed fingernail">own severed fingernail</option><option value="copper key punch">copper key punch</option><option value="metal book clasp">metal book clasp</option><option value="fesnel hair paintbrush">fesnel hair paintbrush</option><option value="aquila paperweight">aquila paperweight</option><option value="stitching needle">stitching needle</option><option value="ancient magnifying lens">ancient magnifying lens</option><option value="blank velum folio">blank velum folio</option></select>'; break;
		case "Arbitrator": durr = '<select name="carmemento"><option>None</option><option value="Short Length of Chain">Short Length of Chain</option><option value="Expired Wanted Poster">Expired Wanted Poster</option><option value="Bag of Shot Pellets">Bag of Shot Pellets</option><option value="Dented Steel Toe Cap">Dented Steel Toe Cap</option><option value="Broken Spy-Eye Lens">Broken Spy-Eye Lens</option><option value="Leather Wrist-Band">Leather Wrist-Band</option><option value="Bent Key">Bent Key</option><option value="Lock of Hair">Lock of Hair</option><option value="Knife Handle">Knife Handle</option><option value="Metal Shot Glass">Metal Shot Glass</option><option value="Stick of Chalk">Stick of Chalk</option><option value="Cracked Data-Slate">Cracked Data-Slate</option><option value="Old Nameplate">Old Nameplate</option><option value="Scrap of Chain Mail">Scrap of Chain Mail</option><option value="Small Brush">Small Brush</option><option value="Braided Dog Hair">Braided Dog Hair</option><option value="Pommel Weight">Pommel Weight</option><option value="Section of Chest Plate">Section of Chest Plate</option><option value="Bag of Broken Teeth">Bag of Broken Teeth</option><option value="Amasec Bottle Top">Amasec Bottle Top</option></select>'; break;
		case "Assassin": durr = '<select name="carmemento"><option>None</option><option value="Skull Fragment">Skull Fragment</option><option value="Broken Gunsight">Broken Gunsight</option><option value="Cloth Sash">Cloth Sash</option><option value="Vial of Blood">Vial of Blood</option><option value="Xenos Bone">Xenos Bone</option><option value="Snapped Lock">Snapped Lock</option><option value="Throne Penny">Throne Penny</option><option value="Frayed Bow-String">Frayed Bow-String</option><option value="Carved Animal Tooth">Carved Animal Tooth</option><option value="Bloodstained Kerchief">Bloodstained Kerchief</option><option value="Veil">Veil</option><option value="Human Hair Gamsbart">Human Hair Gamsbart</option><option value="Small Stone Bowl">Small Stone Bowl</option><option value="Pistol Trigger">Pistol Trigger</option><option value="Cracked Grey Pearl">Cracked Grey Pearl</option><option value="Tin of Ashes">Tin of Ashes</option><option value="Duelling Foil Safety Cap">Duelling Foil Safety Cap</option><option value="Pinfeather">Pinfeather</option><option value="Bone Nose or Ear Ring">Bone Nose or Ear Ring</option><option value="Fragment of Tanned Skin">Fragment of Tanned Skin</option></select>'; break;
		case "Cleric": durr = '<select name="carmemento"><option>None</option><option value="Broken Sextant">Broken Sextant</option><option value="Lamp Wick">Lamp Wick</option><option value="Leaking Hourglass">Leaking Hourglass</option><option value="Rat Tail">Rat Tail</option><option value="Tin of Soft Wax">Tin of Soft Wax</option><option value="Dried Leach">Dried Leach</option><option value="Ball of Feathers">Ball of Feathers</option><option value="Large (5cm sq) Salt Crystal">Large (five-square-centimeter) Salt Crystal</option><option value="Bone Drill Bit">Bone Drill Bit</option><option value="Phial of Dust">Phial of Dust</option><option value="Fragment of Stone Tablet">Fragment of Stone Tablet</option><option value="Stained Wooden Tooth">Stained Wooden Tooth</option><option value="Regicide Piece">Regicide Piece</option><option value="Smudged Optic Lens">Smudged Optic Lens</option><option value="Tattered Bookmark">Tattered Bookmark</option><option value="Bag of Old Spices">Bag of Old Spices</option><option value="Brass Key Punch">Brass Key Punch</option><option value="Handkerchief with Burn Holes">Handkerchief with Burn Holes</option><option value="Sliver of Silver in Plasteel Disc">Sliver of Silver in Plasteel Disc</option><option value="Burned Feather Quill">Burned Feather Quill</option></select>'; break;
		case "Guardsman": durr = '<select name="carmemento"><option>None</option><option value="Burnt Las Power Pack">Burnt Las Power Pack</option><option value="Xenos Skin Fragment">Xenos Skin Fragment</option><option value="Braided Boot Lace">Braided Boot Lace</option><option value="Bent Grenade Pin">Bent Grenade Pin</option><option value="Bloodstained Rock">Bloodstained Rock</option><option value="Chip of Tank Tread">Chip of Tank Tread</option><option value="Shard of Ceramite Armor">Shard of Ceramite Armor</option><option value="Ration Pack Foil">Ration Pack Foil</option><option value="Small Iron Horseshoe">Small Iron Horseshoe</option><option value="Rock that Glows in Dark">Rock that Glows in Dark</option><option value="Cracked Baton">Cracked Baton</option><option value="Orc Toof Necklace">Orc Toof Necklace</option><option value="Chunk of Fused Sand">Chunk of Fused Sand</option><option value="Bloodstained Bandage">Bloodstained Bandage</option><option value="Smoked Glass Shard">Smoked Glass Shard</option><option value="Frayed Pennant">Frayed Pennant</option><option value="Old Helmet Strap">Old Helmet Strap</option><option value="Dented Belt Buckle">Dented Belt Buckle</option><option value="Form 4111-JUN-555">Form 4111-JUN-555</option><option value="First Commendation Medal">First Commendation Medal</option></select>'; break;
		case "Imperial Psyker": durr = '<select name="carmemento"><option>None</option><option value="Myrrhine Musk Stick">Myrrhine Musk Stick</option><option value="Bent Spoon">Bent Spoon</option><option value="Torn Tarot Card">Torn Tarot Card</option><option value="Deck Plating Fragment">Deck Plating Fragment</option><option value="Pressed Flower Petal">Pressed Flower Petal</option><option value="Wooden Egg">Wooden Egg</option><option value="Necklace of Beads">Necklace of Beads</option><option value="Metal Tube (5cm)">Metal Tube (5cm)</option><option value="Wide Black Ribbon (30cm)">Wide Black Ribbon (30cm)</option><option value="Cracked Looking Glass">Cracked Looking Glass</option><option value="Animal Horn Chip">Animal Horn Chip</option><option value="wath of Metallic Cloth">wath of Metallic Cloth</option><option value="Charred Mahogonite Chip">Charred Mahogonite Chip</option><option value="Bag of Toenail Clippings">Bag of Toenail Clippings</option><option value="Thin Glassteel Disc">Thin Glassteel Disc</option><option value="Crystal Ring">Crystal Ring</option><option value="Rusted Iron Nail">Rusted Iron Nail</option><option value="Fossil Xeno Bone">Fossil Xeno Bone</option><option value="Broken Chrono">Broken Chrono</option><option value="A Single Black Pearl">A Single Black Pearl</option></select>'; break;
		case "Scum": durr = '<select name="carmemento"><option>None</option><option value="Box of Matches (all used)">Box of Matches (all used)</option><option value="Bottle of Shrapnel">Bottle of Shrapnel</option><option value="Eye Patch">Eye Patch</option><option value="Silk Gorget">Silk Gorget</option><option value="Ankle Bracelet">Ankle Bracelet</option><option value="Shotgun Shell Casing">Shotgun Shell Casing</option><option value="Leather Hair Strap">Leather Hair Strap</option><option value="Cork Bottle Stopper">Cork Bottle Stopper</option><option value="Bent Coin">Bent Coin</option><option value="Leather Pouch">Leather Pouch</option><option value="Flagon Handle">Flagon Handle</option><option value="Cloth Armband">Cloth Armband</option><option value="Metal Artificial Nose">Metal Artificial Nose</option><option value="Cracked Autopistol Clip">Cracked Autopistol Clip</option><option value="Tube of Bright Red Lipstick">Tube of Bright Red Lipstick</option><option value="Mouth Harp">Mouth Harp</option><option value="Loaded Dice (2)">Loaded Dice (2)</option><option value="Badly Forged Gelt Coin">Badly Forged Gelt Coin</option><option value="Bag of Dust">Bag of Dust</option><option value="Plasteel Toothpick">Plasteel Toothpick</option></select>'; break;
		case "Tech-Priest": durr = '<select name="carmemento"><option>None</option><option value="Brass Cog Wheel">Brass Cog Wheel</option><option value="Sulphur Crystal">Sulphur Crystal</option><option value="Length of Coiled Wire">Length of Coiled Wire</option><option value="Plasteel Cube (1cm)">Plasteel Cube (1cm)</option><option value="Bag of Red Sand">Bag of Red Sand</option><option value="Tiny Hand-Gyroscope">Tiny Hand-Gyroscope</option><option value="Nugget of Copper Ore">Nugget of Copper Ore</option><option value="Bar Magnet in Glass Block">Bar Magnet in Glass Block</option><option value="Lump of your own Mummified Flesh">Lump of your own Mummified Flesh</option><option value="Cracked Crystal Wafer">Cracked Crystal Wafer</option><option value="Hematite Stone">Hematite Stone</option><option value="Phial of Iron Filings">Phial of Iron Filings</option><option value="Small Brass Ingot">Small Brass Ingot</option><option value="Oily Cleaning Rags">Oily Cleaning Rags</option><option value="Twisted Metal Wrench">Twisted Metal Wrench</option><option value="Phial of Gelatinous Liquid">Phial of Gelatinous Liquid</option><option value="Small Metal Pyramid">Small Metal Pyramid</option><option value="Fragment of Stained Glass">Fragment of Stained Glass</option><option value="own Finger Bone">Finger Bone (possibly your own)</option><option value="Metal Carbon Rod (3cm)">Metal Carbon Rod (3cm)</option></select>'; break;
		case "Sororitas": durr='<select name="carmemento"><option>None</option></select>'; break;
	}
	chtd('carmementoroll','');
	return(durr.toLowerCase());
}

function randomgender(derp)
{
	var roll = rd(2);
	if (document.dhgen.career.value!='Sororitas')
	{
		if (roll==1) { derp.selectedIndex = 1; }
		if (roll==2) { derp.selectedIndex = 2; }
	}
}

function randombuild(derp)
{
	var roll = rd(100);
	chtd('buildroll',"(" + roll + ")");
	if (roll>=1 && roll<=20) { derp.selectedIndex = 1; }
	if (roll>=21 && roll<=50) { derp.selectedIndex = 2; }
	if (roll>=51 && roll<=80) { derp.selectedIndex = 3; }
	if (roll>=81 && roll<=90) { derp.selectedIndex = 4; }
	if (roll>=91) { derp.selectedIndex = 5; }
}

function randomskin(derp)
{
	var roll = rd(100);
	chtd('skinroll',"(" + roll + ")");
	if (roll>=1 && roll<=20) { derp.selectedIndex = 1; }
	if (roll>=21 && roll<=50) { derp.selectedIndex = 2; }
	if (roll>=51 && roll<=80) { derp.selectedIndex = 3; }
	if (roll>=81 && roll<=90) { derp.selectedIndex = 4; }
	if (roll>=91) { derp.selectedIndex = 5; }
}

function randomhair(derp)
{
	var roll = rd(100);
	chtd('hairroll',"(" + roll + ")");
	if (roll>=1 && roll<=20) { derp.selectedIndex = 1; }
	if (roll>=21 && roll<=50) { derp.selectedIndex = 2; }
	if (roll>=51 && roll<=80) { derp.selectedIndex = 3; }
	if (roll>=81 && roll<=90) { derp.selectedIndex = 4; }
	if (roll>=91) { derp.selectedIndex = 5; }
}

function randomeyes(derp)
{
	var roll = rd(100);
	chtd('eyesroll',"(" + roll + ")");
	if (roll>=1 && roll<=20) { derp.selectedIndex = 1; }
	if (roll>=21 && roll<=50) { derp.selectedIndex = 2; }
	if (roll>=51 && roll<=80) { derp.selectedIndex = 3; }
	if (roll>=81 && roll<=90) { derp.selectedIndex = 4; }
	if (roll>=91) { derp.selectedIndex = 5; }
}

function randomquirk(derp)
{
	var roll = rd(100);
	chtd('quirkroll',"(" + roll + ")");
	if (roll>=1 && roll<=6) { derp.selectedIndex = 1; }
	if (roll>=7 && roll<=13) { derp.selectedIndex = 2; }
	if (roll>=14 && roll<=20) { derp.selectedIndex = 3; }
	if (roll>=21 && roll<=27) { derp.selectedIndex = 4; }
	if (roll>=28 && roll<=34) { derp.selectedIndex = 5; }
	if (roll>=35 && roll<=41) { derp.selectedIndex = 6; }
	if (roll>=42 && roll<=48) { derp.selectedIndex = 7; }
	if (roll>=49 && roll<=55) { derp.selectedIndex = 8; }
	if (roll>=56 && roll<=61) { derp.selectedIndex = 9; }
	if (roll>=62 && roll<=68) { derp.selectedIndex = 10; }
	if (roll>=69 && roll<=75) { derp.selectedIndex = 11; }
	if (roll>=76 && roll<=82) { derp.selectedIndex = 12; }
	if (roll>=83 && roll<=87) { derp.selectedIndex = 13; }
	if (roll==88) { derp.selectedIndex = 14; }
	if (roll>=89 && roll<=95) { derp.selectedIndex = 15; }
	if (roll>=96) { derp.selectedIndex = 16; }
}

function randommemento(derp)
{
	var roll = rd(100);
	chtd('mementoroll',"(" + roll + ")");
	if (roll>=1 && roll<=5) { derp.selectedIndex = 1; }
	if (roll>=6 && roll<=10) { derp.selectedIndex = 2; }
	if (roll>=11 && roll<=15) { derp.selectedIndex = 3; }
	if (roll>=16 && roll<=20) { derp.selectedIndex = 4; }
	if (roll>=21 && roll<=25) { derp.selectedIndex = 5; }
	if (roll>=26 && roll<=30) { derp.selectedIndex = 6; }
	if (roll>=31 && roll<=35) { derp.selectedIndex = 7; }
	if (roll>=36 && roll<=40) { derp.selectedIndex = 8; }
	if (roll>=41 && roll<=45) { derp.selectedIndex = 9; }
	if (roll>=46 && roll<=50) { derp.selectedIndex = 10; }
	if (roll>=51 && roll<=55) { derp.selectedIndex = 11; }
	if (roll>=56 && roll<=60) { derp.selectedIndex = 12; }
	if (roll>=61 && roll<=65) { derp.selectedIndex = 13; }
	if (roll>=66 && roll<=70) { derp.selectedIndex = 14; }
	if (roll>=71 && roll<=75) { derp.selectedIndex = 15; }
	if (roll>=76 && roll<=80) { derp.selectedIndex = 16; }
	if (roll>=81 && roll<=85) { derp.selectedIndex = 17; }
	if (roll>=86 && roll<=90) { derp.selectedIndex = 18; }
	if (roll>=91 && roll<=95) { derp.selectedIndex = 19; }
	if (roll>=96) { derp.selectedIndex = 20; }
}

function randomcarmemento(car, derp)
{
	if (car.value == "Sororitas")
	{ }
	else
	{
		var roll = rd(100);
		chtd('carmementoroll',"(" + roll + ")");
		if (roll>=1 && roll<=5) { derp.selectedIndex = 1; }
		if (roll>=6 && roll<=10) { derp.selectedIndex = 2; }
		if (roll>=11 && roll<=15) { derp.selectedIndex = 3; }
		if (roll>=16 && roll<=20) { derp.selectedIndex = 4; }
		if (roll>=21 && roll<=25) { derp.selectedIndex = 5; }
		if (roll>=26 && roll<=30) { derp.selectedIndex = 6; }
		if (roll>=31 && roll<=35) { derp.selectedIndex = 7; }
		if (roll>=36 && roll<=40) { derp.selectedIndex = 8; }
		if (roll>=41 && roll<=45) { derp.selectedIndex = 9; }
		if (roll>=46 && roll<=50) { derp.selectedIndex = 10; }
		if (roll>=51 && roll<=55) { derp.selectedIndex = 11; }
		if (roll>=56 && roll<=60) { derp.selectedIndex = 12; }
		if (roll>=61 && roll<=65) { derp.selectedIndex = 13; }
		if (roll>=66 && roll<=70) { derp.selectedIndex = 14; }
		if (roll>=71 && roll<=75) { derp.selectedIndex = 15; }
		if (roll>=76 && roll<=80) { derp.selectedIndex = 16; }
		if (roll>=81 && roll<=85) { derp.selectedIndex = 17; }
		if (roll>=86 && roll<=90) { derp.selectedIndex = 18; }
		if (roll>=91 && roll<=95) { derp.selectedIndex = 19; }
		if (roll>=96) { derp.selectedIndex = 20; }
	}
}

function randomage(hw,derp)
{
	var roll = rd(100);
	var ageroll = rd(10);
	var psyroll1 = rd(10);
	var psyroll2 = rd(10);
	var psyroll3 = rd(10);
	var psyroll = psyroll1 + psyroll2 + psyroll3;
	if (document.forms['dhgen'].elements['career'].value=="Imperial Psyker")
	{
		chtd('ageroll',"(" + roll + " = " + ageroll + " years, + " + psyroll1 + " + " + psyroll2 + " + " + psyroll3 + " years)");
		ageroll = ageroll + psyroll;
	}
	else
	{
		chtd('ageroll',"(" + roll + " = " + ageroll + " years)");
	}

	if (hw.value==0||hw.value==9)
	{
		if (roll<=70) { derp.selectedIndex = 1; ss('age',15+ageroll); }
		else { derp.selectedIndex = 2; ss('age',25+ageroll); }
	}
	if (hw.value==1||hw.value==10||hw.value==13||hw.value==4)
	{
		if (roll<=30) { derp.selectedIndex = 1; ss('age',15+ageroll); }
		if (roll>=31 && roll<=90){ derp.selectedIndex = 2; ss('age',25+ageroll); }
		if (roll>=91) { derp.selectedIndex = 3; ss('age',35+ageroll); }
	}
	if (hw.value==2||hw.value==11||hw.value==12||hw.value==6||hw.value==7)
	{
		if (roll<=50) { derp.selectedIndex = 1; ss('age',20+ageroll); }
		if (roll>=51 && roll<=80) { derp.selectedIndex = 2; ss('age',30+ageroll); }
		if (roll>=81) { derp.selectedIndex = 3; ss('age',40+ageroll); }
	}
	if (hw.value==3||hw.value==8||hw.value==5)
	{
		if (roll<=40) { derp.selectedIndex = 1; ss('age',15+ageroll); }
		if (roll>=41 && roll<=70) { derp.selectedIndex = 2; ss('age',20+ageroll); }
		if (roll>=71) { derp.selectedIndex = 3; ss('age',50+ageroll); }
	}
}

//Starting packages

function checkpackages(hw,career)
{
	var opts = '<select	name="startpack" onchange="choosepackage(this.form.startpack);"><option value="None">None</option>';
	if (career.value=="Adept") 
	{ 
		opts = opts + '<option value="Munitorium Quastor">Munitorium Quastor</option>';
		if (hw.value=="2"||hw.value=="11"||hw.value=="12"||hw.value=="6") { opts = opts + '<option value="Scholar of the Colleges Hetaireia Lexis">Scholar of the Colleges Hetaireia Lexis</option>'; }
		if (hw.value=="3"||hw.value=="8") { opts = opts + '<option value="Void Commercia">Void Commercia</option>'; }
	}
	if (career.value=="Arbitrator")
	{
		opts = opts + '<option value="The Calixian Pattern Killings">The Calixian Pattern Killings</option>';
		opts = opts + '<option value="The Empty Men of Sinophia Magna">The Empty Men of Sinophia Magna</option>';
		opts = opts + '<option value="The Red Vaults of Luggnum">The Red Vaults of Luggnum</option>';
	}
	if (career.value=="Assassin")
	{
		if (hw.value=="3"||hw.value=="8") { opts = opts + '<option value="The Astral Knives">The Astral Knives</option>'; }
		if (hw.value=="2"||hw.value=="11"||hw.value=="12"||hw.value=="0"||hw.value=="9"||hw.value=="1"||hw.value=="10"||hw.value=="13") { opts = opts + '<option value="The Moritat">The Moritat</option>'; }
		opts = opts + '<option value="The Sons of Dispater">The Sons of Dispater</option>';
	}
	if (career.value=="Cleric")
	{
		if (hw.value=="6"||hw.value=="2"||hw.value=="11"||hw.value=="12"||hw.value=="1"||hw.value=="10"||hw.value=="13") { opts = opts + '<option value="The Great Chantries of Tarsus">The Great Chantries of Tarsus</option>'; }
		opts = opts + '<option value="Mendicantine Missionary">Mendicantine Missionary</option>';
		opts = opts + '<option value="Redemptionist Firebrand">Redemptionist Firebrand</option>';
	}
	if (career.value=="Guardsman")
	{
		opts = opts + '<option value="The Mara Landing Massacre">The Mara Landing Massacre</option>';
		opts = opts + '<option value="Soldier of the Margin Crusade">Soldier of the Margin Crusade</option>';
		opts = opts + '<option value="Tranch War Veteran">Tranch War Veteran</option>';
	}
	if (career.value=="Imperial Psyker")
	{
		opts = opts + '<option value="A Shadow Over Thy Soul">A Shadow Over Thy Soul</option>';
		opts = opts + '<option value="The Guiding Light of the God-Emperor">The Guiding Light of the God-Emperor</option>';
		opts = opts + '<option value="Living Nightmare">Living Nightmare</option>';
	}
	if (career.value=="Scum")
	{
		if (hw.value=="0"||hw.value=="9"||hw.value=="1"||hw.value=="10"||hw.value=="13"||hw.value=="2"||hw.value=="11"||hw.value=="12") { opts = opts + '<option value="The Beast Slaver">The Beast Slaver</option>'; }
		if (hw.value=="3"||hw.value=="8") { opts = opts + '<option value="Cold Guild Courier">Cold Guild Courier</option>'; }
		if (hw.value=="1"||hw.value=="10"||hw.value=="13"||hw.value=="2"||hw.value=="11"||hw.value=="12") { opts = opts + '<option value="The Brotherhood of Thollos">The Brotherhood of Thollos</option>'; }
	}
	if (career.value=="Tech-Priest")
	{
		if (hw.value=="4"||hw.value=="3"||hw.value=="8") { opts = opts + '<option value="The Disciples of Thule">The Disciples of Thule</option>'; }
		if (hw.value=="4") { opts = opts + '<option value="The Divine Light of Sollex">The Divine Light of Sollex</option>'; }
		if (hw.value=="4"||hw.value=="3"||hw.value=="8") { opts = opts + '<option value="Malygrisian Tech Heresy">Malygrisian Tech Heresy</option>'; }
	}

	opts = opts + '</select>';
	chtd('startpacktd',opts);
	chtd('packeffectstd','None');
	clearpackage();

}

function clearpackage()
{
	ss('xp',400);
	ss('wsptra',0);
	ss('bsptra',0);
	ss('sptra',0);
	ss('tptra',0);
	ss('agptra',0);
	ss('intptra',0);
	ss('perptra',0);
	ss('wpptra',0);
	ss('felptra',0);
	ss('woundptra',0);
	ss('fateptra',0);
	ss('insptra',0);
	ss('corptra',0);
	ss('throneptra',0);
}

function choosepackage(derp)
{
	clearpackage();
	chtd('geartd',fillgear(document.forms['dhgen'].elements['career'].value)); //Resets values in case it was changed previously by a special package

	if (derp.value=="None")
	{
		ss('xp',400);
		chtd('packeffectstd','None');
	}

	if (derp.value=="Munitorium Quastor")
	{
		ss('xp',300); ss('wpptra',-5); ss('felptra',-5);
		chtd('packeffectstd','-5 Willpower, -5 Fellowship. Gain Command (Fel), Common Lore (Imperial Guard) (Int), Inquiry (Fel), Search (Int), and Security (Ag) as starting skills. Gain the Paranoia talent.');
	}

	if (derp.value=="Scholar of the Colleges Hetaireia Lexis")
	{
		ss('xp',300); ss('intptra',3); ss('wsptra',-5); ss('sptra',-5);
		chtd('packeffectstd','+3 Intelligence, -5 Weapon Skill, -5 Strength. Gain Ciphers (Secret Society - Hetaireia) (Int), <select name="packchoice1"><option value="Forbidden Lore (The Black Library) (Int)">Forbidden Lore (The Black Library) (Int)</option><option value="Forbidden Lore (Cults) (Int)">Forbidden Lore (Cults) (Int)</option><option value="Forbidden Lore (Daemonology) (Int)">Forbidden Lore (Daemonology) (Int)</option><option value="Forbidden Lore (Heresy) (Int)">Forbidden Lore (Heresy) (Int)</option><option value="Forbidden Lore (Inquisition) (Int)">Forbidden Lore (Inquisition) (Int)</option><option value="Forbidden Lore (Archeotech) (Int)">Forbidden Lore (Archeotech) (Int)</option><option value="Forbidden Lore (Mutants) (Int)">Forbidden Lore (Mutants) (Int)</option><option value="Forbidden Lore (Ordos Malleus) (Int)">Forbidden Lore (Ordos Malleus) (Int)</option><option value="Forbidden Lore (Ordos Hereticus) (Int)">Forbidden Lore (Ordos Hereticus) (Int)</option><option value="Forbidden Lore (Ordos Xenos) (Int)">Forbidden Lore (Ordos Xenos) (Int)</option><option value="Forbidden Lore (Adeptus Mechanicus) (Int)">Forbidden Lore (Adeptus Mechanicus) (Int)</option><option value="Forbidden Lore (Psykers) (Int)">Forbidden Lore (Psykers) (Int)</option><option value="Forbidden Lore (Warp) (Int)">Forbidden Lore (Warp) (Int)</option><option value="Forbidden Lore (Xenos) (Int)">Forbidden Lore (Xenos) (Int)</option></select> and <select name="packchoice2"><option value="Scholastic Lore (Archaic) (Int)">Scholastic Lore (Archaic) (Int)</option><option value="Scholastic Lore (Astromancy) (Int)">Scholastic Lore (Astromancy) (Int)</option><option value="Scholastic Lore (Beasts) (Int)">Scholastic Lore (Beasts) (Int)</option><option value="Scholastic Lore (Bureaucracy) (Int)">Scholastic Lore (Bureaucracy) (Int)</option><option value="Scholastic Lore (Chymistry) (Int)">Scholastic Lore (Chymistry) (Int)</option><option value="Scholastic Lore (Cryptology) (Int)">Scholastic Lore (Cryptology) (Int)</option><option value="Scholastic Lore (Heraldry) (Int)">Scholastic Lore (Heraldry) (Int)</option><option value="Scholastic Lore (Imperial Creed) (Int)">Scholastic Lore (Imperial Creed) (Int)</option><option value="Scholastic Lore (Judgement) (Int)">Scholastic Lore (Judgement) (Int)</option><option value="Scholastic Lore (Legend) (Int)">Scholastic Lore (Legend) (Int)</option><option value="Scholastic Lore (Numerology) (Int)">Scholastic Lore (Numerology) (Int)</option><option value="Scholastic Lore (Occult) (Int)">Scholastic Lore (Occult) (Int)</option><option value="Scholastic Lore (Philosophy) (Int)">Scholastic Lore (Philosophy) (Int)</option><option value="Scholastic Lore (Tactica Imperialis) (Int)">Scholastic Lore (Tactica Imperialis) (Int)</option></select> as starting skills. Gain the Peer (Academic) talent.');
	}

	if (derp.value=="Void Commercia")
	{
		ss('xp',200); ss('wsptra',-5); ss('tptra',-5);
		chtd('packeffectstd','-5 Weapon Skill, -5 Toughness. Gain Barter (Fel), Charm (Fel), Common Lore (Imperium) (Int), Common Lore (Mercantile) (Int), Evaluate (Int), Scrutiny (Per), and Secret Tongue (former master&apos;s organization) as starting skills.');
	}

	if (derp.value=="The Calixian Pattern Killings")
	{
		ss('xp',200);
		chtd('packeffectstd','<select name="packchoice1" onchange="ss(\'perptra\',0);ss(\'intptra\',0);if (this.form.packchoice1.value==\'fiveper\') { ss(\'perptra\',5); } if (this.form.packchoice1.value==\'fiveint\') { ss(\'intptra\',5); }"><option>Select one</option><option value="fiveint">+5 Intelligence</option><option value="fiveper">+5 Perception</option></select>. Gain the Talented (Inquiry) talent.');
	}

	if (derp.value=="The Empty Men of Sinophia Magna")
	{
		ss('xp',300); ss('insptra',rd(5));
		chtd('packeffectstd','+1d5 Insanity points. Gain Hatred (Tech Heretics) and Paranoia talents.');
	}

	if (derp.value=="The Red Vaults of Luggnum")
	{
		ss('xp',300); ss('wpptra',3); ss('insptra',rd(5));
		chtd('packeffectstd','+3 Willpower, +1d5 Insanity points. Gain the Jaded talent.');
	}

	if (derp.value=="The Astral Knives")
	{
		ss('xp',200); ss('corptra',rd(5));
		chtd('packeffectstd','+1d5 Corruption points. Gain Ciphers (Secret Society - Astral Knives) (Int) and Deceive (Fel) as starting skills. Treat Forbidden Lore (Warp) (Int) and Tech Use (Int) as basic skills.');
	}

	if (derp.value=="The Moritat")
	{
		ss('xp',100); ss('felptra',-5); ss('insptra',rd(5));
		chtd('packeffectstd','-5 Fellowship, +1d5 Insanity points. Gain Climb (S), Secret Tongue (Moritat) (Int), Shadowing (Ag), and Silent Move (Ag) as starting skills. Gain the Jaded talent. Gain the Bloody Edge trait. Your starting equipment is replaced with a special loadout.');
		chtd('geartd','mono-sword, six throwing knives, crossbow pistol and twenty bolts, grapnel and line, equipment harness, 3 doses of stimm, protective bodyglove (2 points Primitive armor for Body, Arms and Legs)');
	}

	if (derp.value=="The Sons of Dispater")
	{
		ss('xp',300);
		chtd('packeffectstd','Gain Common Lore (Underworld) (Int), Intimidate (S) and Security (Ag) as starting skills. Your sword is replaced by a stub automatic with a silencer and two clips of ammunition.');
		chtd('geartd','stub automatic with silencer and two clips of ammunition, knife, 3 doses of stimm, charge (corpse hair), black bodyglove (Common Quality Clothing), <select name="gchoice1"><option value="shotgun and 12 shells">shotgun and 12 shells</option><option value="hunting rifle and 16 rounds">hunting rifle and 16 rounds</option><option value="autogun and 1 clip">autogun and 1 clip</option></select>, <select name="gchoice2"><option value="compact las pistol and 1 charge pack">compact las pistol and 1 charge pack</option><option value="10 throwing knives">10 throwing knives</option></select>');
	}

	if (derp.value=="The Great Chantries of Tarsus")
	{
		ss('xp',200); ss('intptra',5); ss('felptra',5); ss('wsptra',-5); ss('bsptra',-5); ss('sptra',-5);
		chtd('packeffectstd','Gain Charm (Fel), Common Lore (Ecclesiarchy) (Int), Scrutiny (Per), and Speak Language (High Gothic) (Int) as starting skills. Gain the Peer (Ecclesiarchy) talent.');
	}

	if (derp.value=="Mendicantine Missionary")
	{
		ss('xp',300);
		chtd('packeffectstd','Gain Common Lore (Imperium) (Int), Navigation (Surface) (Int), Scholastic Lore (Legends) (Int), and Survival (Int) as starting skills. Your starting funds are reduced by half and your income level is lowered to Outcast.');
	}

	if (derp.value=="Redemptionist Firebrand")
	{
		ss('xp',200); ss('felptra',-5); ss('insptra',rd(5));
		chtd('packeffectstd','+1d5 Insanity points, -5 Fellowship. Gain Interrogation (WP) and Intimidate (S) as starting skills. Gain the Unshakable Faith and <select name="packchoicetal1"><option value="Basic Weapons Training (Flame)">Basic Weapons Training (Flame)</option><option value="Melee Weapons Training (Chain)">Melee Weapons Training (Chain)</option></select> talents.');
	}

	if (derp.value=="The Mara Landing Massacre")
	{
		ss('xp',100); ss('corptra',rd(5)); ss('fateptra',1); ss('insptra',rd(10));
		chtd('packeffectstd','+1 Fate point, +1d10 Insanity points, +1d5 Corruption points. You are Unhinged. Gain the Resistance (Psychic Powers) talent.');
	}

	if (derp.value=="Soldier of the Margin Crusade")
	{
		ss('xp',200); ss('tptra',-3);
		chtd('packeffectstd','-3 Toughness. Gain Awareness (Per) and Survival (Int) as starting skills. Gain the Unshakable Faith talent.');
	}

	if (derp.value=="Tranch War Veteran")
	{
		ss('xp',300); ss('insptra',rd(5));
		chtd('packeffectstd','+1d5 Insanity points. Gain Search (Int) as a starting skill. Gain the Hatred (Mutants) and Light Sleeper talents.');
	}

	if (derp.value=="A Shadow Over Thy Soul")
	{
		ss('xp',200); ss('insptra',rd(5)); ss('corptra',rd(5));
		chtd('packeffectstd','+1d5 Insanity points, +1d5 Corruption points. Gain Forbidden Lore (Daemonology) (Int) as a starting skill. Gain the Dark Soul talent.');
	}

	if (derp.value=="The Guiding Light of the God-Emperor")
	{
		ss('xp',300); ss('sptra',-5);
		chtd('packeffectstd','-5 Strength. Gain the Hatred (Witches) and Insanely Faithful talents.');
	}

	if (derp.value=="Living Nightmare")
	{
		ss('xp',100); ss('wpptra',5); ss('insptra',rd(5));
		chtd('packeffectstd','+5 Willpower, +1d5 Insanity points. Gain the Resistance (Psychic Powers) talent and Unreadable Mind trait.');
	}

	if (derp.value=="The Beast Slaver")
	{
		ss('xp',300); ss('corptra',rd(5));
		chtd('packeffectstd','+1d5 Corruption points. Gain <select name="packchoice1"><option value="Forbidden Lore (Mutants) (Int)">Forbidden Lore (Mutants) (Int)</option><option value="Scholastic Lore (Beasts) (Int)">Scholastics Lore (Beasts) (Int)</option></select> as a starting skill. Gain the Melee Weapons Training (Shock) and Peer (Underworld) talents.');
	}

	if (derp.value=="Cold Guild Courier")
	{
		ss('xp',300); ss('perptra',5); ss('tptra',-5);
		chtd('packeffectstd','+5 Perception, -5 Toughness. Gain the Concealed Cavity, Peer (Void Born) and Talented (Concealment) talents.');
	}

	if (derp.value=="The Brotherhood of Thollos")
	{
		ss('xp',200); ss('wsptra',3); ss('tptra',3); ss('felptra',-5);
		chtd('packeffectstd','+3 Weapon Skill, +3 Toughness, -5 Fellowship. Gain the Street Fighting and Peer (Underworld) talents.');
	}

	if (derp.value=="The Disciples of Thule")
	{
		ss('xp',300); ss('wsptra',-5); ss('perptra',-5);
		chtd('packeffectstd','-5 Weapon Skill, -5 Perception. Gain Common Lore (Machine Cult) (Int), Evaluate (Int), Forbidden Lore (Archaeotech) (Int), Logic (Int) and Scholastic Lore (Cryptology) (Int) as starting skills.');
	}

	if (derp.value=="The Divine Light of Sollex")
	{
		ss('xp',100); ss('felptra',-5); ss('insptra',rd(5));
		chtd('packeffectstd','-5 Fellowship, +1d5 Insanity points. Gain Ciphers (Secret Society - Sollex) (Int), Common Lore (Machine Cult) (Int), Demolition (Int) and Scholastic Lore (Tactica Imperialis) (Int) as starting skills. Gain the Hatred (Tech-heretics) and Unshakable Faith talents. Gain +10 to Tech-Use tests involving laser or holo devices.');
	}

	if (derp.value=="Malygrisian Tech Heresy")
	{
		ss('xp',200); ss('corptra',rd(5)); ss('insptra',rd(5));
		chtd('packeffectstd','+1d5 Corruption points, +1d5 Insanity points. You are Unhinged. Gain Ciphers (Malygris Codex) (Int), Forbidden Lore (Warp) (Int), Forbidden Lore (Xenos) (Int), Scholastic Lore (Legend) (Int), and Scholastic Lore (Numerology) (Int) as starting skills.');
	}

	updatestats();
}


function createfam(type, hw, family)
{
	type = parseInt(type.value);
	if (type==0)
	{
		family.value = 'None';
	}
	else
	{
		var momname = randomname(2);
		var dadname = randomname(1);
		var momcar = randomcareername(hw.value); while(momcar=="Sororitas") { momcar = randomcareername(hw.value); }
		var dadcar = randomcareername(hw.value); while(dadcar=="Sororitas") { dadcar = randomcareername(hw.value); }
		var momlive;
		var dadlive;
		if (type==1) { momlive = 1; dadlive = 1; } else { momlive = rd(4); dadlive = rd(4); }

		var sibs = rd(3);
		var sibonegen;
		var sibonename;
		var sibonecar;
		var sibonelive;
		var sibtwogen;
		var sibtwoname;
		var sibtwocar;
		var sibtwolive;

		if (sibs>1)
		{
			sibonegen = rd(2);
			sibonename = randomname(sibonegen);
			sibonecar = randomcareername(hw.value);
			if (sibonegen==1) { while (sibonecar=="Sororitas") { sibonecar = randomcareername(hw.value); } }
			if (type==1) { sibonelive = 1; } else { sibonelive = rd(4); }
		}
		if (sibs==3)
		{
			sibtwogen = rd(2);
			sibtwoname = randomname(sibtwogen);
			sibtwocar = randomcareername(hw.value);
			if (sibtwogen==1) { while (sibtwocar=="Sororitas") { sibtwocar = randomcareername(hw.value); } }
			if (type==1) { sibtwolive = 1; } else { sibtwolive = rd(4); }
		}

		var iswas;
		var walks;
		var heshe;
		var brosis;
		var deadmsg;

		if (momlive==4) { iswas = 'was'; walks = 'walked'; deadmsg = ' She is deceased.'; } 
		else { iswas = 'is'; walks = 'walks'; deadmsg = ''; }

		txt = 'Your mother\'s name ' + iswas + ' ' + momname + '. She ' + walks + ' the path of the ' + momcar + '.' + deadmsg;

		if (dadlive==4) { iswas = 'was'; walks = 'walked'; deadmsg = ' He is deceased.'; }
		else { iswas = 'is'; walks = 'walks'; deadmsg = ''; }
		
		txt = txt + ' Your father\'s name ' + iswas + ' ' + dadname + '. He ' + walks + ' the path of the ' + dadcar + '.' + deadmsg;

		if (sibs>1)
		{
			if (sibonegen==1) { heshe = 'He'; brosis = 'brother'; } else { heshe = 'She'; brosis = 'sister'; }
			if (sibonelive==4) { iswas = 'was'; walks = 'walked'; deadmsg = ' ' + heshe + ' is deceased.'; }
			else { iswas = 'is'; walks = 'walks'; deadmsg = ''; }

			txt = txt + ' Your ' + brosis + '\'s name ' + iswas + ' ' + sibonename + '. ' + heshe + ' ' + walks + ' the path of the ' + sibonecar + '.' + deadmsg;

			if (sibs==3)
			{
				if (sibtwogen==1) { heshe = 'He'; brosis = 'brother'; } else { heshe = 'She'; brosis = 'sister'; }
				if (sibtwolive==4) { iswas = 'was'; walks = 'walked'; deadmsg = ' ' + heshe + ' is deceased.'; }
				else { iswas = 'is'; walks = 'walks'; deadmsg = ''; }

				txt = txt + ' Your ' + brosis + '\'s name ' + iswas + ' ' + sibtwoname + '. ' + heshe + ' ' + walks + ' the path of the ' + sibtwocar + '.' + deadmsg;
			}
		}
		else
		{
			txt = txt + ' You are an only child.';
		}

		family.value = txt;

	}
}

function rname(gender, charname, type)
{
	var retname;
	if (type==0)
	{ 
		retname = randomname(gender.value);
		charname.value = retname;
	}
	else { return retname; }
}

function randomname(gender)
{
	var roll = rd(100);

	switch(roll) {
		case 1:
		case 2:
		case 3:
			if (gender==1) {
				pri = "Arl";
				low = "Barak";
				high = "Atellus";
				arc = "Alaric";
				inf = "Able";
			}
			else { 
				pri = "Arla";
				low = "Akadia";
				high = "Atella";
				arc = "Aenid";
				inf = "Alpha";
			}
			break;
		case 4:
		case 5:
		case 6:
			if (gender==1) {
				pri = "Bruul";
				low = "Cain";
				high = "Brutis";
				arc = "Attilas";
				inf = "Bones";
			}
			else { 
				pri = "Brulla";
				low = "Chaldia";
				high = "Brutilla";
				arc = "Albia";
				inf = "Blaze";
			}
			break;
		case 7:
		case 8:
		case 9:
			if (gender==1) {
				pri = "Dar";
				low = "Dariel";
				high = "Callidon";
				arc = "Barbosa";
				inf = "Crisis";
			}
			else { 
				pri = "Darl";
				low = "Cyrine";
				high = "Calldia";
				arc = "Borgia";
				inf = "Blue";
			}
			break;
		case 10:
		case 11:
		case 12:
		case 13:
			if (gender==1) {

				pri = "Frak";
				low = "Eli";
				high = "Castus";
				arc = "Cortez";
				inf = "Cutter";
			}
			else { 
				pri = "Fraka";
				low = "Diona";
				high = "Castella";
				arc = "Cimbria";
				inf = "Cat";
			}
			break;
		case 14:
		case 15:
		case 16:
			if (gender==1) {
				pri = "Fral";
				low = "Enoch";
				high = "Drustos";
				arc = "Constantine";
				inf = "Dekko";
			}
			else { 
				pri = "Fraal";
				low = "Deatrix";
				high = "Drustilla";
				arc = "Devi";
				inf = "Calamity";
			}
			break;
		case 17:
		case 18:
		case 19:
		case 20:
			if (gender==1) {
				pri = "Garm";
				low = "Frastus";
				high = "Flavion";
				arc = "Cromwell";
				inf = "Dakka";
			}
			else { 
				pri = "Garma";
				low = "Ethina";
				high = "Flavia";
				arc = "Ephese";
				inf = "Dame";
			}
			break;
		case 21:
		case 22:
		case 23:
			if (gender==1) {
				pri = "Grish";
				low = "Gaius";
				high = "Gallus";
				arc = "Dorn";
				inf = "Frag";
			}
			else { 
				pri = "Grisha";
				low = "Ephrael";
				high = "Gallia";
				arc = "Euphrati";
				inf = "Dice";
			}
			break;
		case 24:
		case 25:
		case 26:
		case 27:
			if (gender==1) {
				pri = "Grak";
				low = "Garvel";
				high = "Haxtes";
				arc = "Drake";
				inf = "Flair";
			}
			else { 
				pri = "Graki";
				low = "Fenria";
				high = "Haxta";
				arc = "Inez";
				inf = "Flair";
			}
			break;
		case 28:
		case 29:
		case 30:
			if (gender==1) {
				pri = "Hak";
				low = "Hastus";
				high = "Intios";
				arc = "Eisen";
				inf = "Finial";
			}
			else { 
				pri = "Haka";
				low = "Gaia";
				high = "Intias";
				arc = "Imperatrice";
				inf = "Gold";
			}
			break;
		case 31:
		case 32:
		case 33:
			if (gender==1) {
				pri = "Jarr";
				low = "Ignace";
				high = "Jastilus";
				arc = "Ferrus";
				inf = "Grim";
			}
			else { 
				pri = "Jarra";
				low = "Galatia";
				high = "Jestilla";
				arc = "Jemadar";
				inf = "Gunner";
			}
			break;
		case 34:
		case 35:
		case 36:
		case 37:
			if (gender==1) {
				pri = "Kar";
				low = "Ishmael";
				high = "Kaltos";
				arc = "Grendel";
				inf = "Gob";
			}
			else { 
				pri = "Karna";
				low = "Hazael";
				high = "Kalta";
				arc = "Jezail";
				inf = "Hack";
			}
			break;
		case 38:
		case 39:
		case 40:
			if (gender==1) {
				pri = "Kaarl";
				low = "Jericus";
				high = "Litilus";
				arc = "Guilliman";
				inf = "Gunner";
			}
			else { 
				pri = "Kaarli";
				low = "Isha";
				high = "Litila";
				arc = "Joss";
				inf = "Halo";
			}
			break;
		case 41:
		case 42:
		case 43:
		case 44:
			if (gender==1) {
				pri = "Krell";
				low = "Klightus";
				high = "Lupus";
				arc = "Havelock";
				inf = "Hack";
			}
			else { 
				pri = "Krella";
				low = "Ishta";
				high = "Lupa";
				arc = "Kadis";
				inf = "Lady";
			}
			break;
		case 45:
		case 46:
		case 47:
			if (gender==1) {
				pri = "Lek";
				low = "Lazerus";
				high = "Mallear";
				arc = "Iacton";
				inf = "Jakes";
			}
			else { 
				pri = "Lekka";
				low = "Jedia";
				high = "Mallia";
				arc = "Kali";
				inf = "Luck";
			}
			break;
		case 48:
		case 49:
		case 50:
			if (gender==1) {
				pri = "Mar";
				low = "Mordeci";
				high = "Metalus";
				arc = "Jaghatai";
				inf = "Krak";
			}
			else { 
				pri = "Marlla";
				low = "Judicca";
				high = "Meta";
				arc = "Lethe";
				inf = "Modesty";
			}
			break;
		case 51:
		case 52:
		case 53:
		case 54:
			if (gender==1) {
				pri = "Mir";
				low = "Mithras";
				high = "Nihilius";
				arc = "Khan";
				inf = "Lug";
			}
			else { 
				pri = "Mira";
				low = "Lyra";
				high = "Nihila";
				arc = "Mae";
				inf = "Moll";
			}
			break;
		case 55:
		case 56:
		case 57:
			if (gender==1) {
				pri = "Narl";
				low = "Nicodemus";
				high = "Novus";
				arc = "Leman";
				inf = "Mongrel";
			}
			else { 
				pri = "Narla";
				low = "Magdela";
				high = "Novia";
				arc = "Millicent";
				inf = "Pistol";
			}
			break;
		case 58:
		case 59:
		case 60:
			if (gender==1) {
				pri = "Orl";
				low = "Pontius";
				high = "Octus";
				arc = "Lionus";
				inf = "Plex";
			}
			else { 
				pri = "Orla";
				low = "Narcia";
				high = "Octia";
				arc = "Merica";
				inf = "Plex";
			}
			break;
		case 61:
		case 62:
		case 63:
			if (gender==1) {
				pri = "Phrenz";
				low = "Quint";
				high = "Praetus";
				arc = "Magnus";
				inf = "Rat";
			}
			else { 
				pri = "Phrix";
				low = "Ophilia";
				high = "Praetia";
				arc = "Midkiff";
				inf = "Pris";
			}
			break;
		case 64:
		case 65:
		case 66:
			if (gender==1) {
				pri = "Quarl";
				low = "Rabalias";
				high = "Quintos";
				arc = "Mercutio";
				inf = "Red";
			}
			else { 
				pri = "Quali";
				low = "Phebia";
				high = "Quintilla";
				arc = "Megehra";
				inf = "Rat";
			}
			break;
		case 67:
		case 68:
		case 69:
			if (gender==1) {
				pri = "Roth";
				low = "Reestheus";
				high = "Raltus";
				arc = "Nixios";
				inf = "Sawney";
			}
			else { 
				pri = "Rotha";
				low = "Qualia";
				high = "Raltia";
				arc = "Odessa";
				inf = "Red";
			}
			break;
		case 70:
		case 71:
		case 72:
			if (gender==1) {
				pri = "Ragaa";
				low = "Silvanus";
				high = "Ravion";
				arc = "Ramirez";
				inf = "Scab";
			}
			else { 
				pri = "Ragaana";
				low = "Rhia";
				high = "Ravia";
				arc = "Orlean";
				inf = "Ruby";
			}
			break;
		case 73:
		case 74:
		case 75:
			if (gender==1) {
				pri = "Stig";
				low = "Solomon";
				high = "Regis";
				arc = "Serghar";
				inf = "Scammer";
			}
			else { 
				pri = "Stigga";
				low = "Salomis";
				high = "Regia";
				arc = "Plath";
				inf = "Scarlet";
			}
			break;
		case 76:
		case 77:
		case 78:
		case 79:
			if (gender==1) {
				pri = "Strang";
				low = "Thaddius";
				high = "Severus";
				arc = "Sigismund";
				inf = "Skive";
			}
			else { 
				pri = "Stranga";
				low = "Solaria";
				high = "Scythia";
				arc = "Severine";
				inf = "Spike";
			}
			break;
		case 80:
		case 81:
		case 82:
			if (gender==1) {
				pri = "Thak";
				low = "Titus";
				high = "Silon";
				arc = "Tybalt";
				inf = "Shanks";
			}
			else { 
				pri = "Thakka";
				low = "Thyratia";
				high = "Sila";
				arc = "Thiopia";
				inf = "Steel";
			}
			break;
		case 83:
		case 84:
		case 85:
			if (gender==1) {
				pri = "Ulth";
				low = "Uriah";
				high = "Tauron";
				arc = "Vern";
				inf = "Shiv";
			}
			else { 
				pri = "Ultha";
				low = "Thebe";
				high = "Taura";
				arc = "Thrace";
				inf = "Starr";
			}
			break;
		case 86:
		case 87:
		case 88:
		case 89:
			if (gender==1) {
				pri = "Varn";
				low = "Varnias";
				high = "Trantor";
				arc = "Wolfe";
				inf = "Sham";
			}
			else { 
				pri = "Varna";
				low = "Uriel";
				high = "Trantia";
				arc = "Tzarine";
				inf = "Trauma";
			}
			break;
		case 90:
		case 91:
		case 92:
		case 93:
			if (gender==1) {
				pri = "Wrax";
				low = "Xerxes";
				high = "Venris";
				arc = "Wollsey";
				inf = "Stern";
			}
			else { 
				pri = "Wraxa";
				low = "Veyda";
				high = "Venria";
				arc = "Venus";
				inf = "Trick";
			}
			break;
		case 94:
		case 95:
		case 96:
			if (gender==1) {
				pri = "Yarn";
				low = "Zaddion";
				high = "Victus";
				arc = "Zane";
				inf = "Stubber";
			}
			else { 
				pri = "Yarni";
				low = "Xantippe";
				high = "Xanthia";
				arc = "Walperga";
				inf = "Trix";
			}
			break;
		case 97:
		case 98:
		case 99:
		case 100:
			if (gender==1) {
				pri = "Zek";
				low = "Zuriel";
				high = "Xanthis";
				arc = "Zarkov";
				inf = "Verbal";
			}
			else { 
				pri = "Zekka";
				low = "Ziapatra";
				high = "Zenthia";
				arc = "Zetkin";
				inf = "Zee";
			}
			break;
	}

	var type = rd(5)
	if (type==1) { return pri; }
	if (type==2) { return low; }
	if (type==3) { return high; }
	if (type==4) { return arc; }
	if (type==5) { return inf; }

}

function randomcareername(hw)
{
	var roll = rd(100);
	var car;

	hw = parseInt(hw);

	switch(hw) { 
		case 0:
		case 9:
			if (roll>=1 && roll<=30) { car = 'Assassin'; }
			if (roll>=31 && roll<=80) { car = 'Guardsman'; }
			if (roll>=81 && roll<=90) { car = 'Imperial Psyker'; }
			if (roll>=91) { car = 'Scum'; }
			break;
		case 1:
		case 10:
		case 13:
			if (roll>=1 && roll<=17) { car = 'Arbitrator'; }
			if (roll>=18 && roll<=20) { car = 'Assassin'; }
			if (roll>=21 && roll<=25) { car = 'Cleric'; }
			if (roll>=26 && roll<=35) { car = 'Guardsman'; }
			if (roll>=36 && roll<=40) { car = 'Imperial Psyker'; }
			if (roll>=41 && roll<=89) { car = 'Scum'; }
			if (roll>=90) { car = 'Tech-Priest'; }
			break;
		case 2:
		case 11:
		case 12:
			if (roll>=1 && roll<=12) { car = 'Adept'; }
			if (roll>=13 && roll<=25) { car = 'Arbitrator'; }
			if (roll>=26 && roll<=38) { car = 'Assassin'; }
			if (roll>=39 && roll<=52) { car = 'Cleric'; }
			if (roll>=53 && roll<=65) { car = 'Guardsman'; }
			if (roll>=66 && roll<=79) { car = 'Imperial Psyker'; }
			if (roll>=80 && roll<=90) { car = 'Scum'; }
			if (roll>=91) { car = 'Tech-Priest'; }
			break;
		case 3:
		case 8:
			if (roll>=1 && roll<=10) { car = 'Adept'; }
			if (roll>=11 && roll<=20) { car = 'Arbitrator'; }
			if (roll>=21 && roll<=25) { car = 'Assassin'; }
			if (roll>=26 && roll<=35) { car = 'Cleric'; }
			if (roll>=36 && roll<=75) { car = 'Imperial Psyker'; }
			if (roll>=76 && roll<=85) { car = 'Scum'; }
			if (roll>=86) { car = 'Tech-Priest'; }
			break;
		case 4:
			if (roll>=1 && roll<=25) { car = 'Adept'; }
			if (roll>=26 && roll<=35) { car = 'Assassin'; }
			if (roll>=36 && roll<=60) { car = 'Guardsman'; }
			if (roll>=61 && roll<=70) { car = 'Scum'; }
			if (roll>=71) { car = 'Tech-Priest'; }
			break;
		case 5:
			if (roll>=1 && roll<=15) { car = 'Arbitrator'; }
			if (roll>=16 && roll<=50) { car = 'Assassin'; }
			if (roll>=51 && roll<=60) { car = 'Cleric'; }
			if (roll>=61 && roll<=80) { car = 'Guardsman'; }
			if (roll>=81 && roll<=90) { car = 'Imperial Psyker'; }
			if (roll>=91) { car = 'Tech-Priest'; }
			break;
		case 6:
			if (roll>=1 && roll<=18) { car = 'Adept'; }
			if (roll>=19 && roll<=30) { car = 'Arbitrator'; }
			if (roll>=31 && roll<=40) { car = 'Assassin'; }
			if (roll>=41 && roll<=56) { car = 'Cleric'; }
			if (roll>=57 && roll<=75) { car = 'Guardsman'; }
			if (roll>=76 && roll<=85) { car = 'Imperial Psyker'; }
			if (roll>=86) { car = 'Scum'; }
			break;
		case 7:
			if (roll>=1 && roll<=20) { car = 'Adept'; }
			if (roll>=21 && roll<=40) { car = 'Arbitrator'; }
			if (roll>=41 && roll<=60) { car = 'Cleric'; }
			if (roll>=61 && roll<=81) { car = 'Guardsman'; }
			if (roll>=81) { car = 'Sororitas'; }
			break;
		default:
			alert('hurr');break;
	}
	return car;
}

/*
	<select name="mutation"><option>Select Mutation</option>
		<option value="Grotesque">Grotesque</option>
		<option value="Tough Hide">Tough Hide</option>
		<option value="Misshapen">Misshapen</option>
		<option value="Feels No Pain">Feels No Pain</option>
		<option vlaue="Brute">Brute</option>
		<option value="Nightsider">Nightsider</option>
		<option value="Big Eyes">Big Eyes</option>
		<option value="Malformed Hands">Malformed Hands</option>
		<option value="Tox Blood">Tox Blood</option>
		<option value="Wyrdling">Wyrdling</option>
	</select>

	
function startingrank(derp)
{
	if (derp=="Adept") { return('Archivist'); }
	if (derp=="Arbitrator") { return('Trooper'); }
	if (derp=="Assassin") { return('Sell-Steel'); }
	if (derp=="Cleric") { return('Novice'); }
	if (derp=="Guardsman") { return('Conscript'); }
	if (derp=="Imperial Psyker") { return('Sanctionite'); }
	if (derp=="Scum") { return('Dreg'); }
	if (derp=="Tech-Priest") { return('Technographer'); }
	if (derp=="Sororitas") { return('Novice'); }
}

*/