	var slotMax = parseFloat("80");
	var plotElement = new Array(slotMax);
		
	var rollsMin = parseFloat("1");
	var rollsMax = parseFloat("5");
	

	var tableStart = '<table border="0" width="100%" valign="top" style="width:148mm; border-collapse:collapse;">';
	var tableEnd = '</table>';
	var rowSpan = '<tr><td class=\'cell\' colspan=\'2\'><b>@MSG</b></td></tr>';
	var rowContentSpan = '<tr><td class=\'content\' colspan=\'2\'>@MSG</td></tr>';
	var rowNoteSpan = '<tr><td class=\'note\' colspan=\'2\'>@MSG</td></tr>';
	var rowInformativeSpan = '<tr><td class=\'informative\' colspan=\'2\'>@MSG</td></tr>';
	
	function makePlotLine()
	{
		clearAreas();
		flushSlots();
		var rolls = getRolls();
		makeRandomPlotline(rolls);
	}
	function getRolls()
	{
		var rolls = parseFloat("0");
		//parse input
		//rolls = document.PlotElements.elements["roll"].value.replace(/\$|\,/g,'');
		rolls = document.forms[0].roll.value.replace(/\$|\,/g,'');
		rolls =  parseFloat((isNaN(rolls) || (rolls=="")) ? "0": rolls);
		rolls = (rolls < rollsMin) ? rollsMin : rolls;
		rolls = (rolls > rollsMax) ? rollsMax : rolls;
		document.forms[0].roll.value = rolls;
		//document.PlotElements.elements["roll"].value = rolls;
		return parseFloat(rolls);
	}
	function clearAreas()
	{
		document.getElementById("resultsArea").innerHTML = '';
	}
	function flushSlots()
	{
		for (var i = 0; i < slotMax; i++)
		{
			plotElement[i] = false;
		}
	}
	function roll1dx(x)
	{
		var total = Math.ceil(Math.random() * x);
		return total;
	}
	function  makeRandomPlotline(rolls)
	{
		var plotLine;
		plotLine = rowSpan.replace('@MSG','Cyberpunk Plot Line');
		for (var i = 0; i < rolls; i++)
		{	
			var slot = roll1dx(slotMax);
			while(plotElement[slot] == true)
			{
				slot = roll1dx(slotMax);
			}
			plotElement[slot] = true;
			
			//fetch back a random plot line
			plotLine += getPlotElementSlot(slot);
		}
		//output
		document.getElementById("resultsArea").innerHTML = plotLine;
		
	}
	function getPlotElementSlot(slot)
	{

		var title = "";
		var desc = "";
		switch(slot)
		{
			case 1:
				title = 'The Hit';
				desc = 'The PCs are contracted to take out a specific target or group.';
				break;
			case 2:
				title = 'In The Crosshairs';
				desc = 'Someone has taken out a Hit on one or more of the PCs.';
				break;						
			case 3:
				title = 'On The Run';
				desc = 'A powerful threat is after the PCs and they must flee.';
				break;
			case 4:
				title = 'Bodyguard';
				desc = 'The PCs are hired to protect someone or something.';
				break;
			case 5:
				title = 'Decoys';
				desc = 'Whether they know it or not, the PCs task is to attract attention away from something else.';
				break;				
			case 6:
				title = 'Monster Hunt';
				desc = 'The PCs have to trackdown, find, and capture/eliminate a self-willed weapon or other unusual threat.';
				break;				
			case 7:
				title = 'McGuffin Hunt';
				desc = 'One or more parties are trying to get their hands on a object of great supposed value, the PCs get involved in the search.';
				break;				
			case 8:
				title = 'Hot Potato';
				desc = 'One or more parties are trying to get their hands on a object of great supposed value, the PCs have it and are in over their heads.';
				break;
			case 9:
				title = 'Bidding War';
				desc = 'Multiple parties are trying to get their hands on a object of great supposed value, the PCs have it and must hang on to it long enough to realize a profit from it.';
				break;	
			case 10:
				title = 'Scapegoats';
				desc = 'The PCs have been framed for something they did not do...';
				break;
			case 11:
				title = 'Dirty Jobs';
				desc = 'The PCs have been hired to frame someone else for something, or frag over another group of Runners.';
				break;
			case 12:
				title = 'The Snatch & Grab';
				desc = 'An object or person is on the move from one highly secure locale to another; the goal is to acquire it while it has theoretically less security';
				break;						
			case 13:
				title = 'The Ambush';
				desc = 'The PCs have been hired to interdict something on the move and cause as much damage to it as possible.';
				break;
			case 14:
				title = 'The Raid';
				desc = 'The PCs have been hired to do a direct assault on a location';
				break;
			case 15:
				title = 'The Collateral Damage War';
				desc = 'The PCs have been hired to just cause as much random damage to a target as possible over time';
				break;				
			case 16:
				title = 'The Extraction';
				desc = 'The PCs have been hired to do a direct assault on a location and bring something or someone specific back out.';
				break;				
			case 17:
				title = 'The Breakout';
				desc = 'The PCs are hired to break something out from the inside; usually by going undercover for some period of time';
				break;				
			case 18:
				title = 'The Heist';
				desc = 'The PCs have been hired to steal something by stealth or trickery.';
				break;
			case 19:
				title = 'The Crash';
				desc = 'The PCs have been hired to bring down someones infotech.';
				break;	
			case 20:
				title = 'The Indirect Sabotage';
				desc = 'The PCs have been hired to sabotage something seemingly minor that indirectly hoses something bigger / more important';
				break;	
			case 21:
				title = 'Missing Persons';
				desc = 'The PCs have been hired to find someone that has gone missing.';
				break;		
			case 22:
				title = 'Nonexistance';
				desc = 'One or more of the PCs have their identity swiped, expunged, or otherwise interferred with; but why and by whom?';
				break;	
			case 23:
				title = 'You 2.0';
				desc = 'One or more of the PCs has flashbacks to memories that do not fit with their supposed background, and / or suffer other circumstances that indicate what they think they know about themselves is not 100% accurate or complete.';
				break;	
			case 24:
				title = 'Monkey in the Middle';
				desc = 'Two or more parties are having an extended altercation, and the PCs somehow get caught in the crossfire.';
				break;	
			case 25:
				title = 'Infiltration';
				desc = 'The PCs are hired to get into a place via subtlety or guile for some purpose.';
				break;					
			case 26:
				title = 'The Sacrificial Lamb';
				desc = 'The PCs have been hired to Raid or Infiltrate a facility. What they do not know is that they have been hired by the owners of the facility and the real purpose is to test the security or to make an example out of them...or both.';
				break;	
			case 27:
				title = 'The Pick';
				desc = 'The PCs have been hired to provide a "scrape off" for some other job done on the move. The operators on that job move thru the PCs emplaced position, leading any pursuers into an Ambush and giving themselves more time to get away.';
				break;	
			case 28:
				title = 'Stranded';
				desc = 'The PCs get stuck some place they would rather not be and have to figure a way out of it.';
				break;	
			case 29:
				title = 'Information Wants To Be Free';
				desc = 'There is a highly volatile secret or data that if publically known would have major ramifications. The PCs somehow become involved in the struggle to release it, or to stop it from being released.';
				break;	
			case 30:
				title = 'The Warzone';
				desc = 'The PCs become involved in a full on prolonged armed conflict between two or more sides.';
				break;	
			case 31:
				title = 'Ticket To The Good Life';
				desc = 'The PCs are given an opportunity that if capitalized upon will elevate their status and or living conditions substantially...but succeeding is the trick. And what if they do succeed, but the opportunity was not legit?';
				break;	
			case 32:
				title = 'There Is No Spoon';
				desc = 'A job the PCs are hired to do turns out to be bogus in some way. The hiring party isnt legit, the target isnt real, there is no pay off at the end, or some other chicanery is afoot.';
				break;
			case 33:
				title = 'The Reprisal';
				desc = 'The PCs have pissed off someone or someones sufficiently to invite reprisal(s).';
				break;		
			case 34:
				title = 'Getting Out Of The Game';
				desc = 'One or more PCs want to retire, but their skill set or history is such that at least one other party is determined that they will do at least one more job -- and they are willing to go to great lengths to force the issue.';
				break;	
			case 35:
				title = 'We Are Not The Runners You Are Looking For';
				desc = 'The PCs have been mistaken for some other group of Runners; for better or worse.';
				break;	
			case 36:
				title = 'The SynthiGrass Is Greener';
				desc = 'The PCs are enticed, invited, chased, or other wise motivated to take a job in another city. The price is right, but can they handle the powers-that-be and harsh foreign reality of the new city?';
				break;	
			case 37:
				title = 'Have Space Suit Will Travel';
				desc = 'The PCs are hired to do a job outside of the atmosphere -- whether that be an orbiting space station, or another planet. The contract price is astronomical, but so are the extra dangers.';
				break;	
			case 38:
				title = 'Lets All Be Friends';
				desc = 'The PCs have been offered a contract for a major job, but its so big multiple teams are on it. One of the other groups are either an old rival, or a new rival waiting to happen.';
				break;					
			case 39:
				title = 'Undercut';
				desc = 'Another Runner team looking to make a name for themselves snake one of the PCs contracts. Perhaps concurrent to the PCs actually executing it, throwing a massive wrench into the works, or perhaps before the PCs get around to it making them look bad.';
				break;					
			case 40:
				title = 'Young Guns';
				desc = 'The PCs have developed a certain reputation for themselves. A newer team looking to make a name for themselves move in and go after the PCs directly.';
				break;	
			case 41:
				title = 'Insert Dagger Into Back';
				desc = 'A job goes bad inexplicably. As the web unravels it is revealed that a trusted source or associate of the PCs betrayed them.';
				break;	
			case 42:
				title = 'Unexpected Assistance';
				desc = 'The PCs are unexpectedly helped and from an unexpected direction; perhaps by a total stranger, perhaps by an enemy. Why, and what is their ulterior motive?';
				break;	
			case 43:
				title = 'Sink Or Swim';
				desc = 'The current job offered to the PCs sounds reasonable, but once they get into it they realize that there is much hidden under the surface and they are soon in over their heads. Do they abort and lose face, push forward and maybe all die, or rise to the occasion and manage to pull it off?';
				break;
			case 44:
				title = 'We Underbid';
				desc = 'The job the PCs just agreed to do was accepted for too low of a pay off. Not only is the Risk vs Reward off center, but other Runner teams that had turned it down waiting for the asking price to come up are pissed that the PCs undercut them...and are prepared to demonstrate their unhappiness.';
				break;					
			case 45:
				title = 'No Value Added';
				desc = 'The PCs did something and got paid for it in the past, but new information that has come to light in the interim makes it look like they didnt really do the job (perhaps they really did not!), or else did it half-baked. The hiring party is not pleased...';
				break;							
			case 46:
				title = 'Time To Pay The Piper';
				desc = 'The PCs owe someone something from past events, or at least someone feels like they do. They come to collect...';
				break;									
			case 47:
				title = 'The Career Maker';
				desc = 'There is a standing contract for a job so hot no one will touch it. If the PCs take it and pull it off, their reps will become plated in solid anodized gold...';
				break;											
			case 48:
				title = 'The Femme Fatale';
				desc = 'One (or more) of the PCs become involved with a woman of remarkable attributes. But is she what she seems, and why is a dame like that interested in a rough edged Runner anyway?';
				break;											
			case 49:
				title = 'Pro Bono';
				desc = 'For whatever reason, someone expects the PCs to undertake a tough mission, job, or favor for FREE. What is their leverage and do the PCs do it?';
				break;											
			case 50:
				title = 'Esprit de Corpse';
				desc = 'One or more PCs have drawn the attention and ire of a particular megacorps, which allocates resources specifically to make their life very difficult and / or short';
				break;	
			case 51:
				title = 'The Loose Cannon';
				desc = 'Another Runner or Runner team is in town and shaking up the status quo. They dont play be the unspoken rules, and fallout from their actions is starting to have an effect on the PCs. Do they do anything about it?';
				break;	
			case 52:
				title = 'Deal Breaker';
				desc = 'The PCs are in the middle of a job, when they uncover info or are informed of details that make them question whether or not to abort the contract...And what is the fallout for them if they do either?';
				break;					
			case 53:
				title = 'Read The Small Print';
				desc = 'The PCs accept a complex arrangement, perhaps an exclusivity contract, perhaps enter into a corporate sponsorship or retainer agreement, or some other extended contract. However as time elapses all sorts of unforeseen complications arise from it to make the situation untennable. What do the PCs do?';
				break;	
			case 54:
				title = 'Its Just Business';
				desc = 'A trusted Runner associate; perhaps a teammate, supplier, fixer, or ally; sells the team out while in the middle of a Run. However, the PCs survive the encounter. What do they do now?';
				break;	
			case 55:
				title = 'Dry Spell';
				desc = 'No one has any Runs available for the PCs for a bit, and they are left to survive off of whatever money they have saved. Some will likely have to seek some fundage from a sideline, like arena fights, robbery, selling off some excess gear, and other unglamorous angles.';
				break;					
			case 56:
				title = 'Rogue Agent';
				desc = 'One of the PCs have been sidelining, moonlighting, lone wolfing, or otherwise working on their own outside of the Runner team. However, something or things from their independent activities backlash to affect the group.';
				break;					
			case 57:
				title = 'An Offer You Cannot Refuse';
				desc = 'A representative of a powerful person, organization, megacorps, or other power base approaches one or more of the PCs and entices or coerces them to sell out one or more of the other PCs. Do they do it, and how do they go about it?';
				break;					
			case 58:
				title = 'Company Man In Our Midst';
				desc = 'Information comes to light that suggests one of the PCs secretly has a corporate relationship or agenda that has not been disclosed to the group. Is it even true? Does paranoia reign supreme, or is the suspect member given the benefit of the doubt, or is an investigation carried out on the sly?';
				break;					
			case 59:
				title = 'Malfunction';
				desc = 'One of the PCs that has cyber suffers some key system malfunctions that they do not currently have the resources to fix when the Runner team is under tight deadlines or mounting pressure to execute one or more jobs. If they complete the job and get their finances fluid again they can cover their maintenance. Do their teammates help them get back into working order, spot them the cost, give them a bye on the mission and still pay them a share, or do they cut them to the winds? If left out in the cold, does the cyborg consider selling out the Runner team to their target to get the funds they need?';
				break;	
			case 60:
				title = 'The ACBs Of Me';
				desc = 'One or more of the PCs gets an opportunity to field test a new line of combat drugs or enhancers. The stuff is free, and seems to work great at first, but over time the members on the stuff get increasingly unstable. Once they are hooked on the stuff, the providing company starts requiring the users to do jobs for them in return for more supply. What transpires...?';
				break;	
			case 61:
				title = 'Killing You Wholesale';
				desc = 'A Runner or team with a rep as cleaners (i.e. specializing in extremely wet work with high body counts and low visibility) is rumored to be in town, but no one seems to know what kind of job they are working. Then one of the PCs thinks they are being surveilled or shadowed by the cleaners. Are the PCs the mark? What is going on, and how long do they have before the hammer falls?';
				break;				
			case 62:
				title = 'Is It Live Or Is It Memorex';
				desc = 'One of the PCs encounters a persona online that seems to defy the commonly held limits of the technology. Whats the deal? Are they just another hacker with a cool trick and an air of mystery, or are they something else?';
				break;	
			case 63:
				title = 'Blast From The Past';
				desc = 'While usually newer is better, some old skool tech, a hush hush black lab project from a couple decades back, or other oldy but goody payload enters play, and the PCs have to deal with the fully matured baggage that goes with it. And perhaps there are some parties that would prefer the past stays in the past...at any cost.';
				break;	
			case 64:
				title = 'Arent You Supposed To Be Dead?';
				desc = 'A person that the PCs are pretty damn sure they killed very dead resurfaces, perhaps in a position of authority or power. What gives, and do they have a hate on for the PCs?';
				break;	
			case 65:
				title = 'I Love It When Im Wrong';
				desc = 'One of the PCs has been doom croaking about something. Their worst conjectures on the subject prove to be essentially correct, to the teams detriment. Sometimes it just does not pay to be right.';
				break;
			case 66:
				title = 'There Can Be Only One';
				desc = 'One of the PCs is well known for their skills in a certain area. Another pro with a similar skill set who thinks the PCs rep is overblown sets out to debunk it and prove themselves better. Does the PC take up the guantlet, ignore it, or take steps to remove their rival?';
				break;	
			case 67:
				title = 'Waiting For The Shoe To Drop';
				desc = 'The PCs do a job that just goes too well. Its cake from start to finish, the pay is fat, every one involved seems happy, and even the target doesnt seem too irritated. This isnt how the world works; what the hell is going on? Will the PCs pay for the seeming boon later? Make them worry about it and second guess their success.';
				break;					
			case 68:
				title = 'Thats All You Wanted?';
				desc = 'One of those mythical perfect Runs presents itself. The PCs skill set is a perfect match, the client is fluffy and waiting to be sheared, the contract is very generous, the Run is almost effortless, but somehow when word of it hits the streets it sounds like the PCs really did something special and their rep spikes. It dont happen often, so savor the flavor.';
				break;
			case 69:
				title = 'The Big Meet';
				desc = 'A potential hirer doesnt want to go through a Fixer (or at least not solely), and wants to meet the Runners at least semi-directly to guage them themselves. Do the PCs transition smoothly to a social atmosphere, or do they frag it up? And is the meet legit, or is it sleight of hand for something else?';
				break;					
			case 70:
				title = 'I Thought Youd Be Taller In Person';
				desc = 'One or more of the PCs reps exceeds their actual exerpience and / or abilities. They draw a sweetheart contract specifically for them based on their rep, but the hirer doesnt know the rep is inflated. What happens?';
				break;
			case 71:
				title = 'Jiminy Cricket Time';
				desc = 'The PCs realize midway through a Run that if they finish the job, they will be enabling a disaster, catastrophe, or hardship that could affect a huge number of people. Do they have a fit of morality, and waive off or reverse course, or do they earn their paycheck and go home regardless of the longer term fallout?';
				break;					
			case 72:
				title = 'Cry Me A River';
				desc = 'The PCs are approached with information that pulls at the old heart strings or otherwise generates sympathy. Is the info in the hard luck story legitimate, still relevant, or otherwsie of interest and do the PCs act on it in some way, or do they shed a crocodile tear and move on?';
				break;		
			case 73:
				title = 'Back In Black';
				desc = 'An old enemy, or a person that used to have a lot of power but has been gone, incarcerated, in suspended animation, whatever has returned and his rocking the boat in a major way. The PCs get involved one way or another.';
				break;					
			case 74:
				title = 'The Rescue';
				desc = 'The representative of another team or a Fixer contacts the PCs with an extremely urgent, now or never contract to bail out or reenforce another Runner team on job in progress that is going bad. If they accept the contract there is zero prep time and PCs have to scramble immediately. Do they take the job?';
				break;	
			case 75:
				title = 'My Precious';
				desc = 'The PCs have attained something on a Run that they are supposed to fork over to the hiring party, but once they get their hands on it they decide they want it for themselves...';
				break;					
			case 76:
				title = 'You Shouldnt Have Snoozed Through The Exposition';
				desc = 'A person offering a job actually gives the PCs legit info and fully discloses whats going on instead of keeping them in the dark or lying to them, but in excessive detail. Most of the team blows it off, cuts the source off in mid-explanation, or otherwise fails to pay attention to it. As the job transpires things that they should have seen coming if they had paid attention catch them off guard. Hindsight is 20/20...';
				break;					
			case 77:
				title = 'Bug Problem';
				desc = 'The PCs home base, apartments, or private residences have been bugged for an unknown period of time, and one of the PCs accidentally finds one of the surveillance devices. Who bugged them, how long ago, and what has been talked about that could be of danger to the PCs if disclosed to the wrong people? Paranoia ensues...';
				break;	
			case 78:
				title = 'Witch Hunt';
				desc = 'A corporate exec has gone rogue, and their former corp has put an extremely high price on their head. Its open season time, and all sorts of people are going after the prize. Do the PCs join in? Perhaps the mark has approached them directly and hired them to act as bodyguards? And what is the mark up to anyway?';
				break;	
			case 79:
				title = 'Sec Force Shuffle';
				desc = 'The PCs have two or more Corporate Sec Forces on their asses, but they are from rival megacorps that have a history of violence with each other. Can the PCs figure out a way to turn them against each other to take some of the heat off themselves?';
				break;	
			case 80:
				title = 'Theres No Such Thing As A Free Lunch';
				desc = 'The PCs are offered a job that is just too good to be true...literally. They are naturally suspicious, but also of course greedy. Do they take the job, do some sleuthing, give it a pass and later find out it was legit, or what?';
				break;	


		}

	
		return getPackageRow(title,desc,1)
		
	}
	function getPackageRow(name,plotElement,emphasis)
	{

		var cellName = '<td class=\'cell\' valign=\'top\' width=\'25%\'><@e>@NAME</@e></td>';
		cellName = (emphasis == 1 || emphasis == 4) ? cellName.replace(/@e/g,'b') : cellName;
		cellName = (emphasis == 2) ? cellName.replace(/@e/g,'i') : cellName;
		cellName = (emphasis == 3) ? cellName.replace(/@e/g,'u') : cellName;
		cellName = (emphasis == 4) ? cellName.replace('<b>','<b><i>') : cellName;
		cellName = (emphasis == 4) ? cellName.replace('</b>','</b></i>') : cellName;
		cellName = cellName.replace(/<@e>/g,'');
		cellName = cellName.replace(/<\/@e>/g,'');

		var cellSlot = '<td class=\'cell\' valign=\'top\' width=\'75%\'>@plotElement</td>';;
		return '<tr>' + cellName.replace('@NAME',name) + cellSlot.replace('@plotElement',plotElement) + '</tr>';
			
	}
	
	
	
	
