function madlibByTsD(TextNo) {

// This is the game function that starts the actual game 


var myReference = document.getElementById("QuestionForm");
myReference.innerHTML="";
var OriginalTextStr=document.Initial.Original.value;
var SpeachPartsStr=document.Initial.SpeachP.value;
var HidenTxt="T";
var HidenSpeech="S";

if (TextNo==1) { 
// This "if" statement can be reused for as many hiden text as we want and we just need to change the "TextNo" variable to invoke it. 
	OriginalTextStr=MadLibByTsD_texts(TextNo, HidenTxt);
	SpeachPartsStr=MadLibByTsD_texts(TextNo, HidenSpeech);
}
if (TextNo==2) { 
// This "if" statement can be reused for as many hiden text as we want and we just need to change the "TextNo" variable to invoke it. 
	OriginalTextStr=MadLibByTsD_texts(TextNo, HidenTxt);
	SpeachPartsStr=MadLibByTsD_texts(TextNo, HidenSpeech);
}




if (OriginalTextStr=="") {	/* This could be done more precisely since now it only checks for absolute blank text and the user can start the game with just one space or enter, but i don't have time right now */
	alert("You have to enter some Text");
	document.Initial.Original.focus();
	return false;
}

if (SpeachPartsStr=="") {	/* This could be done more precisely since now it only checks for absolute blank text and the user can start the game with just one space or enter, but i don't have time right now */
	alert("You have to enter some speech parts");
	document.Initial.SpeachP.focus();
	return false;
}

OriginalText=new Array();
SpeachParts =new Array();
ChangedWords=new Array();
DifferentWords = new Array();
DifferentSpeachParts = new Array();
OriginalTextLowCase = new Array();
ChangedWordsText = new Array();
document.TextForm.output.value="";

var htmlStr="";
var count=0;
var count1=0;
var case1=1;
var case2=2;
var case3=3;
var anciistop="9,10,11,13,32";
var asciiCode=0;
var asciiCode1=0;

if (OriginalTextStr.indexOf("**nl**tsd") != -1) {
	alert("You have in you Text the string: \n \"**nl**tsd\"\nThis is a special string and cannot be used\nPlease change this and continue");
	document.Initial.Original.focus();
	return false;
}


if (SpeachPartsStr.indexOf("**nl**tsd") != -1) {
	alert("You have in you Speech Parts the string: \n \"**nl**tsd\"\nThis is a special string and cannot be used\nPlease change this and continue");
	document.Initial.SpeachP.focus();
	return false;
}




OriginalTextStr=removeNL(OriginalTextStr);


var i=-1;

	for (count=0; count<OriginalTextStr.length; count++) {
		asciiCode=OriginalTextStr.charCodeAt(count);
		if (anciistop.indexOf(asciiCode) == -1) {
			i++;
			OriginalText[i]="";
		}
			while (anciistop.indexOf(asciiCode) == -1 && count<OriginalTextStr.length)  {
				
				OriginalText[i]+=OriginalTextStr.charAt(count);
				count+=1;
				asciiCode=OriginalTextStr.charCodeAt(count);
			}

		
	}



i=-1;

	for (count=0; count<SpeachPartsStr.length; count++) {
		asciiCode=SpeachPartsStr.charCodeAt(count);		
		if (anciistop.indexOf(asciiCode) == -1) {
			i++;
			SpeachParts[i]="";
		}
			while (anciistop.indexOf(asciiCode) == -1 && count<SpeachPartsStr.length)  {
				
				SpeachParts[i]+=SpeachPartsStr.charAt(count);
				count+=1;
				asciiCode=SpeachPartsStr.charCodeAt(count);
			}

		
	}


	for (count=0; count<OriginalText.length; count++) {
		if (OriginalText[count] == "**nl**tsd") {
			SpeachParts.splice(count,0,"**nl**tsd");
		}
	}



if (OriginalText.length!=SpeachParts.length) {
	alert("There is a mistake in your text\nYou entered "+OriginalText.length+" words, but "+SpeachParts.length+" Speach Parts");
	alert("Click *Check Text* if you want to check your text \nword by word!!");
	myReference.innerHTML = "";
	document.Initial.Original.focus();
	return false;
}

document.Initial.Original.value="";
document.Initial.SpeachP.value="";


DifferentWords = DiffOnly(OriginalText, SpeachParts, case2);
DifferentSpeachParts = DiffOnly(OriginalText, SpeachParts, case3);

alert("The text you play with has\n\n"+DifferentWords.length+" different Words");

var num = numberofnewwords(num);

	while (num>DiffOnly(OriginalText, SpeachParts, case1)) {
		alert("BUT!!!\n\n\nThere are "+DiffOnly(OriginalText, SpeachParts, case1)+" different words in the text and you entered "+num+".\n\nPlease enter a number less than "+DiffOnly(OriginalText, SpeachParts, case1)+"!");
		num = numberofnewwords(num);
	} 


ChangedWords=DifRandInt(num, ChangedWords, DifferentWords.length);
ChangedWords=SortIntArray(ChangedWords);


	for (count=0; count<OriginalText.length; count++) {
		OriginalTextLowCase[count]=OriginalText[count].toLowerCase();
	}

	for (count=0; count<SpeachParts.length; count++) {
		SpeachPartslowCase[count]=SpeachParts[count].toLowerCase();
	}

	for (count=0; count<ChangedWords.length; count++) {
		ChangedWordsText[count]=DifferentWords[ChangedWords[count]];
	}




htmlStr += "<table width='30%' border='0'>";
	for (count=0; count<num; count++) {
		htmlStr += "<tr><td align='left'>";
		htmlStr += count;
		htmlStr += ". Enter a: ";
		htmlStr += DifferentSpeachParts[ChangedWords[count]];
		htmlStr += "</td><td align='left'><input name='";
		htmlStr += DifferentSpeachParts[ChangedWords[count]];
		htmlStr += "' type='text' value='' size='15' maxlength='30'></td></tr>";
	
	} 

htmlStr += "</table>";
myReference.innerHTML+=htmlStr;

return true;
}