function vh_talkStarted(){
spStop = 1;
msgX.firstChild.innerHTML = "Stop";
}

function vh_talkEnded(){
spStop = 0;
msgX.firstChild.innerHTML = "About Me";
}

function sayHello(){

//var strLink = <%="'" & lnkPage & "'" %>;
var reVisit = getCookie("c_post");
var txtDayTime;

if (initPost == 1){

var now = new Date();
now.setTime(now.getTime() + 30 * 24 * 60 * 60 * 1000);
d = new Date();
mins = d.getMinutes();
hours = d.getHours();

	if(hours < 12){
	  txtDayTime = "Good Morning, ";
	}
	else if (hours < 17){
	  txtDayTime = "Good Afternoon, ";
	}
	else{
	  hours = hours - 12;
	  txtDayTime = "Good Evening, ";
	}

	if(reVisit=="Y"){
      sayText(txtDayTime + ", Welcome Back to Natural Dynamics",1,1,3);
	}
	else{
	  setCookie("c_post","Y",365);  
      sayText(txtDayTime + ", Welcome to Natural Dynamics",1,1,3);
	}
}

}

function sayMore(){

if (spStop == 1){
  stopSpeech();
}
else{
var msgMore;

msgMore  = "<S>My name is Aimee. An acronym for Artificial Intelligence Me.</S>";
msgMore += "<S>I am a receptionist robot, designed to help you with some of the unique features on our web site.</S>";
msgMore += "<S>I am new here, and I still have a lot to learn. It takes quite a bit of programming to learn the many ways people ask questions.</S>";
msgMore += "<S>Right now, just follow any of our links to access our unique features.</S>";
msgMore += "<S>Soon I will be able to perform many more tasks, like helping you to make an appointment.</S>";
msgMore += "<S>If you would like to see what I can do, type help, below. Or, type anything else to chat with me.</S>";

writeAItext("Type 'HELP' to see some of my more advanced features.");		
sayText(msgMore,1,1,3);

}
}

function msgSent(){
 sayText("Thank You, your message has been sent",1,1,3);
}

function loadAITextFrame(){

	var ifrm = document.getElementById('iframeMSG');
	ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
	
	ifrm.document.open();
	ifrm.document.write("<html><head><link rel='stylesheet' href='css/aitext.css' type='text/css' /></head><body></body></html>");
	ifrm.document.close();
	
	return true;
}

function writeAItext(strAI){

	var ifrm = document.getElementById('iframeMSG');
	ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
	
	var body = strAI;
	  	
	ifrm.document.open();
	ifrm.document.write("<html><head><link rel='stylesheet' href='css/aitext.css' type='text/css' />");
	ifrm.document.write("<script type='text/javascript'>");
	ifrm.document.write("window.onload=function(){");
	ifrm.document.write("if(document.getElementById('btnCMD') != null){document.getElementById('btnCMD').click();}}");
	ifrm.document.write("</script></head><body>");
	ifrm.document.write(body);
	ifrm.document.write("</body></html>");
	ifrm.document.close();
	
	return true;
}

function vh_aiResponse(args) {
aiString = args;

writeAItext(aiString);
}

function sayAI(){

var TTS = document.getElementById("textToSay");

var cText = TTS.value;
var isCMD = cText.toString();

	isCMD = isCMD.substr(0,6);
	isCMD = isCMD.toUpperCase();

if(isCMD=="CALCUL"){
	doMath(cText);
	return false;
}

if(isCMD=="SEARCH"){
	doWiki(cText);
	return false;
}

else{

  sayAIResponse(TTS.value,1,1,3);
  TTS.value='';
  return false;
}

}

function noEkey(e){
     var key;

     if(window.event){
          key = window.event.keyCode;     //IE
     }
     else{
          key = e.which;     //firefox
	 }
     if(key == 13){
     
		sayAI();
		return false;
      }  
     else{
          return true;
	 }
}

function doMath(strCalc){

var eq = 0;
var strMath = strCalc;
strMath = strMath.substring(9,strMath.length); 

with (Math) {
  eq = eval((strMath));
     }

var strEQ = (strMath + " = " + eq);
var strEQsay = ("Equals " + eq);

sayText(strEQsay,1,1,3);
writeAItext(strEQ);
}

function doWiki(strWiki){

var posFrame = document.getElementById("iframe1");

var varWiki = strWiki;
varWiki = varWiki.substring(6,varWiki.length);

loadIframe('iframeAI', 'iframe1', 'iframe_ai.asp', varWiki);
posFrame.focus();

}

function doWikiAI(){

var posFrame = document.getElementById("iframe1");
var varWiki = aiString;
var posStr = varWiki.indexOf(":");

varWiki = varWiki.substring((posStr)+1,(varWiki.length)-4);

loadIframe('iframeAI', 'iframe1', 'iframe_ai.asp', varWiki);
posFrame.focus();

}

function doSearch(aiString){

var posFrame = document.getElementById("iframe1");
var varAI = aiString;

loadIframe('iframeAI', 'iframe1', 'iframe_ai.asp', varAI);
posFrame.focus();

}

function doDefine(){

var varWiki = aiString;
var posStr = varWiki.indexOf(":");

varWiki = varWiki.substring((posStr)+1,(varWiki.length)-4);

loadIframe('iframeAI', 'iframe1', 'iframe_ai_b.asp', varWiki);
setTimeout("setPosition();",1500);

}

function setPosition(){
  var posFrame = document.getElementById("iframe1");
  posFrame.focus();
}

function doCMD(intCmd){

  if(intCmd==10){
    loadIframe("iframeND", "iframe0", "ai_help.htm");
  }
  
  if(intCmd==11){
    loadIframe("iframeND", "iframe0", "help_math.htm");
  }

  if(intCmd==12){
    doDefine();
  }
  
  if(intCmd==13){
    doWikiAI();
  }
  
    if(intCmd==9){
    setCookie("c_sleep", "Y", 365);
  }
  
    if(intCmd==6){
    setCookie("c_sleep", "N", 365);
  }
  
  
}

