﻿// JScript File

function MakeJoke()

{
	var arrFirstLines=new Array(	'What\'s the difference between acne and a paedophile?',
									'What do you get if you put a dead baby in a blender?',
									'What do you call a dog with no legs?',
									'What\'s that foul smell?',
									'Why the long face?',
									'You can\'t bring him in here',
									'Are you Adolf Hitler?',
									'What\'s better than winning gold at the Paralympics?',
									'What\'s black and blue and doesn\'t like sex?',
									'What\'s got eight legs and a big black cunt?',
									'What\'s ten feet long and smells of piss?',
									'How do you crucify a spastic?');
									
	var arrSecondLines=new Array(	'How do you think I got this hunchback?',
									'I don\'t know, I never found her head',
									'A pizza doesn\'t scream when you put it in the oven',
									'Your dad\'s cock tastes funny',
									'A baby with a javelin through its neck',
									'An erection',
									'You\'re right. Let\'s bury her',
									'I may be blind but at least I\'m not black',
									'No, I\'m joking. She really is dead',
									'Throw your laundry in with him',
									'Can I push your stool up for you?',
									'There\'s twenty-eight of them',
									'You think that\'s bad, I\'ve got to walk home on my own',
									'Me in my lucky blue coat',
									'Hypothermia',
									'It started out as a wart on my arse',
									'You should see what\'s down my other trouser leg',
									'Shit in her cunt',
									'AIDS',
									'You can\'t beat a blowjob',
									'The Aristocrats',
									'A baby with a fork in its head',
									'Half a cat',
									'That\'s a big word for a five year old',
									'I\'m in bed with my sister',
									'It was stapled to the other koala',
									'A dialysis machine',
									'Bloody hell, a talking sausage!',
									'I promise not to cum in your mouth',
									'Oh no! Not the breathalyzer again!',
									'If you really, really, really, really, try you could eat a cricket ball',
									'A dead baby in a clown costume',
									'Doritos!',
									'Sexy children');
	var intSelectedLocation;
	var arrArticles=new Array();
	var sJoke=new String('');
	var arrActors=new Array(		'spastic',
									'epileptic',
									'Gary Glitter',
									'horse',
									'pakistani',
									'jew',
									'Hitler',
									'Michael Jackson',
									'nun',
									'monkey',
									'puff',
									'lesbian',
									'leper',
									'Saddam Hussein',
									'The Pope',
									'Jeremy Beadle',
									'Jade Goody',
									'Joseph Fritzl',
									'Osama bin Laden');
									
	var arrLocations=new Array(		'turkish knocking shop',
									'web development company',
									'mosque',
									'bar',
									'pub',
									'brothel',
									'synagogue',
									'igloo',
									'gay bar',
									'church',
									'doctor\'s surgery');
									
	var arrLocationActors=new Array('Princess Diana',
									'spastic',
									'Jesus',
									'barman',
									'prostitute',
									'truck driver',
									'alien',
									'parrot',
									'pirate',
									'eskimo',
									'priest',
									'Eva Braun',
									'God',
									'Daz Sampson',
									'Ian Huntley',
									'Maxine Carr',
									'Harold Shipman',
									'dead baby');
									
	var arrNumberOfThings=new Array('A','two','three','four');
	var arrOrdinalNunmbers=new Array('first','second','third','fourth');
	var arrSelectedActors=new Array();

	var intNumberOfActors=Math.floor(Math.random() * 3);
	var sUsedActors='';
	intSelectedLocation=RandomArrayIndex(arrLocations);
	
	for (var intCurrentActor=0;intCurrentActor<=intNumberOfActors;intCurrentActor++)
	{
		arrSelectedActors[intCurrentActor]=RandomArrayMember(arrActors);
		arrArticles[intCurrentActor]=IndefiniteArticle(arrSelectedActors[intCurrentActor]);
	}
	
	for (intCurrentActor=0;intCurrentActor<=intNumberOfActors;intCurrentActor++)
	{
		sJoke += arrArticles[intCurrentActor] + ' ' + arrSelectedActors[intCurrentActor];
		if (intCurrentActor < intNumberOfActors -1) sJoke+= ', ';
		if (intCurrentActor == intNumberOfActors -1 && intNumberOfActors != 0) sJoke+= ' and ';
		
	}
	
	sJoke+= (intNumberOfActors==0) ? ' goes' : ' go';
	sJoke+=' into a ' + arrLocations[intSelectedLocation] + '. ';
	var sLocationActor=RandomArrayMember(arrLocationActors);
	var sLocationActorArticle=DefiniteArticle(sLocationActor,true);
	sJoke+=sLocationActorArticle + ' ' + sLocationActor + ' says \'' + RandomArrayMember(arrFirstLines) + '\'';
	sJoke+=' and ';
	var sActorAnswering=RandomArrayMember(arrSelectedActors);
	sJoke+=DefiniteArticle(sActorAnswering,false) + ' ' + sActorAnswering + ' says \'';
	sJoke+=RandomArrayMember(arrSecondLines) + '\'';
	
	
	var sFirstChar=sJoke.substr(0,1).toUpperCase();
	sJoke=sFirstChar + sJoke.substring(1, sJoke.length);
	sJoke=sJoke.replace('  ',' ');
	
	document.getElementById('prgContent1').innerHTML=sJoke;
}

function StartsWithVowel(sSentence)
{
	var sVowels='aeiouAEIOU';
	var sNoSpaceString=new String(sSentence.replace(' ',''));
	
	return (sVowels.indexOf(sNoSpaceString.substr(0,1)) >=0)		//starts with vowel
}

function FirstCap(sLCaseString)
{
	return sLCaseString.substring(0,1).toUpperCase() + sLCaseString.substring(1,sLCaseString.length);
}

function DefiniteArticle(sNoun, blnUcase)
{
	var sNoSpaceString=new String(sNoun.replace(' ',''));
	var sFirstChar=sNoSpaceString.substr(0,1);
	if (sFirstChar.toUpperCase() == sFirstChar)		//proper noun
	{
		return '';
	}
	return (blnUcase) ? 'The' : 'the';
}

function IndefiniteArticle(sNoun)
{
	var sVowels=new String('aeiou');
	var sFirstLetter=new String(sNoun.substr(0,1));
	
	if (sFirstLetter.toUpperCase()==sFirstLetter) return '';	//proper noun
	
	if (StartsWithVowel(sFirstLetter))
	{
		return 'an';
	}
	else
	{
		return 'a';
	}
			
}

function RandomArrayMember(arrAnyArray, sUsedMembers)
{
	var intArrLength=arrAnyArray.length;
	var intRandomIndex=RandomArrayIndex(arrAnyArray);
	return arrAnyArray[intRandomIndex];
}

function RandomArrayIndex(arrAnyArray)
{
	var intArrLength=arrAnyArray.length;
	return Math.floor(Math.random() * intArrLength);
}
