I have a javascript chat bot where a person types in a text box and the bot responds in a text box. A small working demo is below.

I can capture the last thing a person types in by using this here:


Code:
if (last_response==input) 
{document.result.result.value = ""+input+" <====again! Is there an echo in here or something?"; 
return true;}

last_response=input;
What I want to do now is capture the second to last input such as:

A person types:

person: I just bought me a new bike.
bot: Good, I love buying new things.
person: What did I just say?
bot: You said "I just bought me a new bike."

Now with last_input it would capture the line "What did I just say?"

I now want it to capture the line "I just bought me a new bike."

Does anyone know the best way to do that?

Thanks!

Code:
<HTML> 
<HEAD>
<TITLE>ChatterBot Page</TITLE>


<script language="JavaScript">

var message = new Array(); 

var last_response="";

var randomnum; 
var flagrandom;


function Parse() { 
var input = new String(document.chat.input.value); 

document.chat.input.value=""; 
input=input.toLowerCase(); 

word=input.split(" ");
num_of_words=word.length;

input=input.replace(/[!|?|,|.]/g,""); 
word=input.split(" ");




if (input.search(/\bu\b/)!=-1) input=input.replace(/\bu\b/,"you");
if (input.search(/\br\b/)!=-1) input=input.replace(/\br\b/,"are");
if (input.search(/\bk\b/)!=-1) input=input.replace(/\bk\b/,"ok");
if (input.search(/\by\b/)!=-1) input=input.replace(/\by\b/,"why");


if (last_response==input) 
{document.result.result.value = ""+input+" <====again! Is there an echo in here or something?"; 
return true;}

last_response=input;

if (input.search("ok")!= -1)     
{document.result.result.value = "Okay, that's interesting."; 
return true;}


if (!flagrandom) {
randomnum = [Math.floor(Math.random()*3)]
flagrandom=true;}
message[0] = "Sorry, you stumped me on that one.";  
message[1] = "Sorry, a search of my data base comes up empty."; 
message[2] = "Not sure";
document.result.result.value = message[randomnum]; 
randomnum++
if (randomnum>2){randomnum=0}
return true;}


</script> 




</head> 



<BODY BACKGROUND="FFFFFF" TEXT="#0000cc" LINK="#FFCOOO" ALINK="#FFCC99"
VLINK="#FFC000" marginwidth="0" leftmargin="0" topmargin="0" rightmargin="0">
<Center>
<font size="+3">
ChatterBot
</font>
<br>
<img src="botpix.jpg" border="0" WIDTH="200" HEIGHT="200">
<br>
<form name="result">
<textarea rows=5 cols=40 input type="text" name="result">
</textarea><br>
</form>
</center>
<form name="chat" onSubmit="Parse();return false">
&nbsp;<b>Type here:</b> 
<input type="text" name="input" size="100">
</form>



</body> 
</html>