Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1989 lines
62 KiB

  1. // Agent Constants
  2. var kdwAgentUserShowed = 2;
  3. var kdwAgentBalloonAutoPace = 8;
  4. var kdwAgentRequestInProgress = 4;
  5. var kdwAgentLeftButton = 1;
  6. var kdwAgentRequestFailed = 1;
  7. // Local Constants
  8. var kpszAgentFilename = window.external.API.get_SystemDirectory() + "\\oobe\\images\\qmark.acs";
  9. var kdwAgentWelcomeIntroFinished = 9999;
  10. var kdwAgentIdleLevel1Finished = 9995;
  11. var kdwAgentIdleStart = 9994;
  12. var kdwAgentNoop = 9993;
  13. var kdwAgentKeepLookingTimeout = 5000;
  14. var kdwAgentMoveSpeed = 400;
  15. var kdwAgentPageIdleTimeout1 = 10000;
  16. var kdwAgentPageIdleTimeout2 = 20000;
  17. var kpszISPSpecialCommand1 = "ISPCommand1";
  18. var kpszISPSpecialCommand2 = "ISPCommand2";
  19. var kpszISPSpecialCommand3 = "ISPCommand3";
  20. // The offsets are used to position the character
  21. // closer to elements than we would be able to get by
  22. // simply using the character's width (which is the size
  23. // of it's frame). These constants will potentially differ
  24. // if multiple characters are used (in localization scenarios).
  25. // Simply set them to the number of pixels from the edge
  26. // of the frame the character's arm is in it's Gesture animations.
  27. var kiAgentLeftArmOffsetX = 67;
  28. var kiAgentRightArmOffsetX = 6;
  29. var kiAgentRightBodyOffsetX = 30;
  30. var kiAgentLeftArmOffsetY = 58;
  31. var kiAgentRightArmOffsetY = 58;
  32. // Member Variables
  33. var g_AgentDisabled; // if true, then Agent is disabled (all external agent calls immediately return)
  34. var g_AgentCharacter = null;
  35. var g_strAgentCurrentPage = "";
  36. var g_strAgentLastPage = "";
  37. var g_bAgentFirstTime = false;
  38. var g_bAgentPreWelcome = false;
  39. var g_bAgentCongratulateOnFinish = true;
  40. var g_bAgentWelcomeIntroFinished = false;
  41. var g_bAgentRegister3ShortEmail = false;
  42. var g_bAgentRegister3LongEmail = false;
  43. var g_bAgentRegister3Privacy = false;
  44. var g_bAgentRegister3VisitState = false;
  45. var g_bAgentRegister3VisitProvince = false;
  46. var g_bAgentRegister3VisitCountry = false;
  47. var g_bAgentProductKeyCongratulate = false;
  48. var g_bAgentDoneHide = true;
  49. var g_bAgentFirstTimeClick = true;
  50. var g_bAgentIgnoreSelectClick = false;
  51. var g_bAgentIgnoreEvents = false;
  52. var g_bAgentInternalIgnoreEvents = false;
  53. var g_bAgentMenuUp = false;
  54. var g_strAgentLastFocusID = "";
  55. var g_AgentRequestHideImage = null;
  56. var g_AgentRequestShowAssistSpan = null;
  57. var g_AgentRequestShowPopup = null;
  58. var g_AgentRequestIdling = null;
  59. var g_AgentRequestLooking = null;
  60. var g_AgentRequestIgnoreResetIdle = null;
  61. var g_AgentKeepLookingTimer = null;
  62. var g_AgentLookBlinkTimer = null;
  63. var g_bAgentPlayLookReturn = false;
  64. var g_strAgentLookAnimation = "";
  65. var g_AgentLookElement = null;
  66. var g_AgentPageIdleTimer = null;
  67. var g_iAgentPageIdleLevel = 0;
  68. var g_bAgentShowSpecialISPCommands = false;
  69. /////////////////////////////////////////////////////////////////////////////
  70. // INTERNAL AGENT FUNCTIONS //
  71. /////////////////////////////////////////////////////////////////////////////
  72. /////////////////////////////////////////////////////////////////////////////
  73. // The below functions are agent functions that are called only from //
  74. // INSIDE agtcore.js and agtscrpt.js. All external functions (called //
  75. // from outside) must be placed at the bottom of this file in the EXTERNAL//
  76. // section and must have the check against g_AgentDisabled just as those //
  77. // functions do. //
  78. /////////////////////////////////////////////////////////////////////////////
  79. // --------------- Agent Event Handlers ---------------- //
  80. function Agent_ShowAssistantSpan()
  81. {
  82. document.all("spnAssist").style.visibility = "visible";
  83. document.all("AssistImg").style.visibility = "visible";
  84. document.all("agentStr1").style.visibility = "visible";
  85. document.all("agentStr2").style.visibility = "visible";
  86. document.all("agentStr3").style.visibility = "visible";
  87. }
  88. function Agent_HideAssistantSpan()
  89. {
  90. document.all("spnAssist").style.visibility = "hidden";
  91. document.all("AssistImg").style.visibility = "hidden";
  92. document.all("agentStr1").style.visibility = "hidden";
  93. document.all("agentStr2").style.visibility = "hidden";
  94. document.all("agentStr3").style.visibility = "hidden";
  95. }
  96. function Agent_ResetFocus() {
  97. // Reset the focus back to the main frame
  98. g.focus();
  99. // Try to set the focus back to the last control that
  100. // had it. We need to do this since setting the focus
  101. // back to the document doesn't necessarily set it back
  102. // to the control that last had it. Bug in IE?
  103. if (g_strAgentLastFocusID != "") {
  104. try {
  105. Agent_InternalSetFocus(g.document.all(g_strAgentLastFocusID));
  106. }
  107. catch (e) {
  108. }
  109. }
  110. // HACK HACK HACK!!! Once we set the focus back to the browser
  111. // OOBE is going to go on top of the character because it is
  112. // a topmost window. Activate(2) makes the character HWND_TOPMOST
  113. // again.
  114. g_AgentCharacter.Activate(2);
  115. }
  116. function Agent_IsGivingIdleInstructions() {
  117. if (g_AgentRequestIdling)
  118. return true;
  119. else
  120. return false;
  121. }
  122. var g_CallMusicOnce = false;
  123. function Agent_OnHide(characterID) {
  124. // NOTE NOTE NOTE!!! Reset the g_bAgentMenuUp flag. We don't
  125. // get a Command event from Agent in the case that the user
  126. // selected Hide.
  127. g_bAgentMenuUp = false;
  128. // Stop timers
  129. Agent_StopPageIdleTimer();
  130. // Make the icon visible
  131. Agent_ShowAssistantSpan();
  132. // Start playing background music if Agent is finished with intro message.
  133. if (!g_CallMusicOnce)
  134. {
  135. g_CallMusicOnce = true;
  136. window.parent.PlayBackgroundMusic();
  137. }
  138. // Have to reset the focus here. Normally this is
  139. // handled in Agent_OnCommand but setting the AssistImg
  140. // visible causes that frame to get the focus.
  141. Agent_ResetFocus();
  142. }
  143. // --------------- OEM API ---------------- //
  144. function Agent_SetCharacterFilename(strFilename) {
  145. kpszAgentFilename = strFilename;
  146. }
  147. function Agent_Play(strAnimation, bWantRequest) {
  148. // Paranoia. Make sure an OEM page didn't make a
  149. // mistake.
  150. if (null == g_AgentCharacter)
  151. return null;
  152. // Make sure the character isn't looking
  153. Agent_StopLooking();
  154. // The caller has to specify whether they want a request
  155. // object returned from this function or not. Unfortunately,
  156. // if you return a request object from this function and the
  157. // caller doesn't assign it to anything, JScript keeps a
  158. // reference on the object (presumably until the garbage collector
  159. // cleans it up). If the request object has a reference at the
  160. // time of the RequestComplete event, Agent will fire the event.
  161. //
  162. // We don't want this behavior. First of all, we don't want all
  163. // of these extraneous request objects hanging around. Secondly,
  164. // we want to be able to fall thru in our OnRequestComplete handler
  165. // if we get the event and the request object is not one of ours.
  166. // If it's not, we can make the assumption that it's from an OEM
  167. // page that is using Agent.
  168. if (Agent_Play.arguments.length != 2)
  169. bWantRequest = false;
  170. if (bWantRequest) {
  171. return g_AgentCharacter.Play(strAnimation);
  172. }
  173. else {
  174. g_AgentCharacter.Play(strAnimation);
  175. return null;
  176. }
  177. }
  178. function Agent_MoveTo(x, y, speed, bWantRequest) {
  179. // speed = 0; // uncomment this line to change Merlin's flying to teleportation
  180. // Paranoia. Make sure an OEM page didn't make a
  181. // mistake.
  182. if (null == g_AgentCharacter)
  183. return null;
  184. Agent_StopLooking();
  185. if (Agent_MoveTo.arguments.length != 4)
  186. bWantRequest = false;
  187. if (bWantRequest) {
  188. return g_AgentCharacter.MoveTo(x, y, speed);
  189. }
  190. else {
  191. g_AgentCharacter.MoveTo(x, y, speed);
  192. return null;
  193. }
  194. }
  195. function Agent_Speak(text, bWantRequest) {
  196. // Paranoia. Make sure an OEM page didn't make a
  197. // mistake.
  198. if (null == g_AgentCharacter)
  199. return null;
  200. Agent_StopLooking();
  201. if (Agent_Speak.arguments.length != 2)
  202. bWantRequest = false;
  203. // Bug fix 134701: Check to see if we have
  204. // Chinese or Japanese and add spaces to the
  205. // string to keep word balloon up for a reasonable
  206. // period of time if there is no TTS engine
  207. if (IsFarEastLocale() && !IsKoreanLocale()) {
  208. // Add a minimum number of spaces
  209. text = text + "\u200b \u200b \u200b \u200b \u200b "
  210. // Now calculate the length of the string
  211. // and use that to determine how many more spaces
  212. // we should add
  213. var i;
  214. var endloop = text.length/2;
  215. if (endloop > 50)
  216. endloop = 50;
  217. for (i=0; i < endloop; i++)
  218. text = text + "\u200b ";
  219. }
  220. if (bWantRequest) {
  221. return g_AgentCharacter.Speak(text);
  222. }
  223. else {
  224. g_AgentCharacter.Speak(text);
  225. return null;
  226. }
  227. }
  228. function Agent_Think(text, bWantRequest) {
  229. // Paranoia. Make sure an OEM page didn't make a
  230. // mistake.
  231. if (null == g_AgentCharacter)
  232. return null;
  233. Agent_StopLooking();
  234. if (Agent_Think.arguments.length != 2)
  235. bWantRequest = false;
  236. if (bWantRequest) {
  237. return g_AgentCharacter.Think(text);
  238. }
  239. else {
  240. g_AgentCharacter.Think(text);
  241. return null;
  242. }
  243. }
  244. function Agent_Stop(request) {
  245. if (null == g_AgentCharacter)
  246. return;
  247. if (Agent_IsLooking()) {
  248. if (g_AgentLookBlinkTimer) {
  249. window.clearTimeout(g_AgentLookBlinkTimer);
  250. g_AgentLookBlinkTimer = null;
  251. }
  252. if (g_AgentKeepLookingTimer) {
  253. window.clearTimeout(g_AgentKeepLookingTimer);
  254. g_AgentKeepLookingTimer = null;
  255. }
  256. g_AgentRequestLooking = null;
  257. }
  258. if (Agent_Stop.arguments.length == 1)
  259. g_AgentCharacter.Stop(request);
  260. else
  261. g_AgentCharacter.Stop();
  262. }
  263. function Agent_StopAll(types) {
  264. if (null == g_AgentCharacter)
  265. return;
  266. if (Agent_IsLooking()) {
  267. if (g_AgentLookBlinkTimer) {
  268. window.clearTimeout(g_AgentLookBlinkTimer);
  269. g_AgentLookBlinkTimer = null;
  270. }
  271. if (g_AgentKeepLookingTimer) {
  272. window.clearTimeout(g_AgentKeepLookingTimer);
  273. g_AgentKeepLookingTimer = null;
  274. }
  275. g_AgentRequestLooking = null;
  276. }
  277. if (Agent_StopAll.arguments.length == 1)
  278. g_AgentCharacter.StopAll(types);
  279. else
  280. g_AgentCharacter.StopAll();
  281. }
  282. function Agent_MoveToElement(elem, side, speed, bWantRequest) {
  283. // Hmmm
  284. if (null == elem)
  285. return null;
  286. // Find the absolute (screen) position of the specified
  287. // element.
  288. var curElem = elem;
  289. var x = elem.document.parentWindow.screenLeft;
  290. var y = elem.document.parentWindow.screenTop;
  291. while (curElem.tagName.toUpperCase() != "BODY") {
  292. x += curElem.offsetLeft + curElem.clientLeft;
  293. y += curElem.offsetTop + curElem.clientTop;
  294. curElem = curElem.offsetParent;
  295. };
  296. // Offset the position taking into consideration the
  297. // offset of the character's arms from the edge of the
  298. // character frame.
  299. switch (side) {
  300. case "Left":
  301. x = x - g_AgentCharacter.Width + kiAgentLeftArmOffsetX;
  302. y -= kiAgentLeftArmOffsetY;
  303. break;
  304. case "Right":
  305. x = x + elem.offsetWidth - kiAgentRightArmOffsetX;
  306. y -= kiAgentRightArmOffsetY;
  307. break;
  308. case "Top":
  309. y -= g_AgentCharacter.Height;
  310. break;
  311. case "Bottom":
  312. y += elem.offsetHeight;
  313. break;
  314. case "Center":
  315. x += ((elem.offsetWidth - g_AgentCharacter.Width) / 2);
  316. y += ((elem.offsetHeight - g_AgentCharacter.Height) / 2);
  317. break;
  318. case "LeftCenter":
  319. x = x - g_AgentCharacter.Width + kiAgentLeftArmOffsetX;
  320. y += ((elem.offsetHeight - g_AgentCharacter.Height) / 2);
  321. break;
  322. case "RightCenter":
  323. x = x + elem.offsetWidth - kiAgentRightArmOffsetX;
  324. y += ((elem.offsetHeight - g_AgentCharacter.Height) / 2);
  325. break;
  326. case "TopCenterWidth":
  327. x += ((elem.offsetWidth - g_AgentCharacter.Width) / 2);
  328. y -= g_AgentCharacter.Height;
  329. break;
  330. case "TopLeft":
  331. x = x - g_AgentCharacter.Width + kiAgentLeftArmOffsetX;
  332. y -= g_AgentCharacter.Height;
  333. break;
  334. case "TopRight":
  335. x = x + elem.offsetWidth - g_AgentCharacter.Width + kiAgentRightBodyOffsetX;
  336. y -= g_AgentCharacter.Height;
  337. break;
  338. case "BottomRight":
  339. x = x + elem.offsetWidth - kiAgentRightArmOffsetX;
  340. y += elem.offsetHeight;
  341. break;
  342. case "BottomCenterWidthExactTop":
  343. x += ((elem.offsetWidth - g_AgentCharacter.Width) / 2);
  344. break;
  345. case "BottomCenterWidthExactBottom":
  346. x += ((elem.offsetWidth - g_AgentCharacter.Width) / 2);
  347. y = y + elem.offsetHeight - g_AgentCharacter.Height;
  348. break;
  349. case "BottomCenterWidth":
  350. x += ((elem.offsetWidth - g_AgentCharacter.Width) / 2);
  351. y += elem.offsetHeight;
  352. break;
  353. case "Exact":
  354. break;
  355. }
  356. var cArgs = Agent_MoveToElement.arguments.length;
  357. if (cArgs < 4) {
  358. bWantRequest = false;
  359. if (cArgs < 3)
  360. speed = kdwAgentMoveSpeed;
  361. }
  362. return Agent_MoveTo(x, y, speed, bWantRequest);
  363. }
  364. function Agent_GestureAtElement(elem, side, bWantRequest) {
  365. // Move to the element
  366. Agent_MoveToElement(elem, side, kdwAgentMoveSpeed);
  367. // And play an appropriate animation
  368. switch (side) {
  369. case "Left":
  370. case "LeftCenter":
  371. return Agent_Play("PointLeft", bWantRequest);
  372. case "Right":
  373. case "RightCenter":
  374. case "BottomRight":
  375. return Agent_Play("PointRight", bWantRequest);
  376. case "Top":
  377. case "TopCenterWidth":
  378. case "TopLeft":
  379. case "TopRight":
  380. return Agent_Play("PointDown", bWantRequest);
  381. case "Bottom":
  382. case "BottomCenterWidthExactTop":
  383. case "BottomCenterWidthExactBottom":
  384. case "BottomCenterWidth":
  385. return Agent_Play("PointUp", bWantRequest);
  386. }
  387. return null;
  388. }
  389. function Agent_AddCommand(strName, strCommand) {
  390. if (!Agent_Init())
  391. return;
  392. g_AgentCharacter.Commands.Add(strName, strCommand);
  393. }
  394. // --------------- Common Functions ---------------- //
  395. function QueueStartPageIdleTimer() {
  396. if (g_AgentRequestIgnoreResetIdle)
  397. g_AgentCharacter.Stop(g_AgentRequestIgnoreResetIdle);
  398. // NOTE NOTE NOTE!!! Don't use Agent_Think here!!! That will kill
  399. // any calls to StartLookingAtElement!!!
  400. //
  401. // NOTE NOTE NOTE!!! Don't use Speak here. Calling speak may make
  402. // the character return to the RestPose if it doesn't have mouths
  403. // for the current animation (e.g. any of the Looking animations).
  404. // Using Think does the trick. We get the bookmark but it won't
  405. // try to look for mouths.
  406. g_AgentRequestIgnoreResetIdle = g_AgentCharacter.Think("\\mrk=" + kdwAgentIdleStart + "\\");
  407. }
  408. function Agent_IsLooking() {
  409. if (g_AgentRequestLooking)
  410. return true;
  411. else
  412. return false;
  413. }
  414. function Agent_GetLookAnimation(x) {
  415. if (g_AgentCharacter.Left > x)
  416. return "LookRight";
  417. else
  418. return "LookLeft";
  419. }
  420. function Agent_StartLookingAtElement(elem, animation) {
  421. // Find the absolute (screen) position of the specified
  422. // element.
  423. var curElem = elem;
  424. var x = elem.document.parentWindow.screenLeft;
  425. var y = elem.document.parentWindow.screenTop;
  426. while (curElem.tagName.toUpperCase() != "BODY") {
  427. x += curElem.offsetLeft + curElem.clientLeft;
  428. y += curElem.offsetTop + curElem.clientTop;
  429. curElem = curElem.offsetParent;
  430. };
  431. // Play the appropriate Look animation
  432. if (animation != "")
  433. g_strAgentLookAnimation = animation;
  434. else
  435. g_strAgentLookAnimation = Agent_GetLookAnimation(x);
  436. // If we're not currently looking, stop all animations
  437. // and play the appropriate look animation.
  438. if (!Agent_IsLooking() || (g_AgentLookElement != elem)) {
  439. // Stop Plays and Speaks but not Moves
  440. g_AgentCharacter.StopAll("play, speak");
  441. g_AgentRequestLooking = g_AgentCharacter.Play(g_strAgentLookAnimation);
  442. }
  443. // This starts the KeepLooking timer
  444. Agent_KeepLooking();
  445. g_AgentLookElement = elem;
  446. }
  447. function Agent_KeepLooking() {
  448. // Restart the KeepLooking timer
  449. if (g_AgentKeepLookingTimer)
  450. window.clearTimeout(g_AgentKeepLookingTimer);
  451. g_AgentKeepLookingTimer = window.setTimeout("Agent_StopLooking()", kdwAgentKeepLookingTimeout);
  452. }
  453. function Agent_StopLooking() {
  454. var animation;
  455. // If we're not currently looking, we're done
  456. if (!Agent_IsLooking())
  457. return;
  458. if (g_bAgentMenuUp) {
  459. Agent_KeepLooking();
  460. return;
  461. }
  462. // Reset the look timers
  463. if (g_AgentKeepLookingTimer) {
  464. window.clearTimeout(g_AgentKeepLookingTimer);
  465. g_AgentKeepLookingTimer = null;
  466. }
  467. if (g_AgentLookBlinkTimer) {
  468. window.clearTimeout(g_AgentLookBlinkTimer);
  469. g_AgentLookBlinkTimer = null;
  470. }
  471. // Play the return animation if we can
  472. if (g_bAgentPlayLookReturn)
  473. animation = g_strAgentLookAnimation + "Return";
  474. else
  475. animation = "RestPose";
  476. if (!g_bAgentPlayLookReturn)
  477. g_AgentCharacter.StopAll();
  478. g_AgentRequestLooking = null;
  479. g_AgentLookElement = null;
  480. g_strAgentLookAnimation = "";
  481. g_bAgentPlayLookReturn = false;
  482. g_AgentCharacter.Play(animation);
  483. // This is necessary because the <Look>Blink animations
  484. // are not required. So some system characters may not
  485. // support them. If they don't, we play <Look> and turn
  486. // idle off.
  487. g_AgentCharacter.IdleOn = true;
  488. }
  489. function Agent_OnLookBlinkTimer() {
  490. // One shot timer
  491. if (g_AgentLookBlinkTimer) {
  492. window.clearTimeout(g_AgentLookBlinkTimer);
  493. g_AgentLookBlinkTimer = null;
  494. }
  495. // Are we still looking?
  496. if (null == g_AgentRequestLooking)
  497. return;
  498. // Look and blink
  499. g_AgentRequestLooking = g_AgentCharacter.Play(g_strAgentLookAnimation + "Blink");
  500. if (g_AgentRequestLooking.Status == kdwAgentRequestFailed)
  501. g_AgentCharacter.IdleOn = false;
  502. else
  503. g_bAgentPlayLookReturn = false;
  504. }
  505. function Agent_IsNextTabItem(elem1, elem2) {
  506. // Determine if elem2 is the next item in the tab order.
  507. // This function is useful so that we don't have to
  508. // make sure that a tabIndex was specified for each
  509. // element.
  510. // If they both have a tab index, use that
  511. if ((elem1.tabIndex > 0) && (elem2.tabIndex > 0))
  512. return (elem1.tabIndex == (elem2.tabIndex-1));
  513. // This is a bit more complicated. We can use the sourceIndex
  514. // but the 2 elements might not be consecutive due to labels, etc.
  515. // First do the simple check
  516. if (elem1.sourceIndex > elem2.sourceIndex)
  517. return false;
  518. var curIndex = elem1.sourceIndex + 1;
  519. var curElem;
  520. while (curIndex < elem2.sourceIndex) {
  521. curElem = g.document.all(curIndex);
  522. ++curIndex;
  523. switch (curElem.tagName) {
  524. case "INPUT":
  525. case "SELECT":
  526. break;
  527. default:
  528. continue;
  529. }
  530. // If it's not visible, we ignore it
  531. if ((curElem.style.visibility == "hidden") ||
  532. (curElem.style.display == "none"))
  533. continue;
  534. // There's another element before the specified
  535. // one.
  536. return false;
  537. }
  538. return true;
  539. }
  540. function Agent_MoveToPreWelcomePos() {
  541. var elem = g.document.all("AgentPos");
  542. // Hmmm
  543. if (null == elem)
  544. return;
  545. // Find the absolute (screen) position of the specified
  546. // element.
  547. var curElem = elem;
  548. var x = elem.document.parentWindow.screenLeft;
  549. var y = elem.document.parentWindow.screenTop;
  550. while (curElem.tagName.toUpperCase() != "BODY") {
  551. x += curElem.offsetLeft + curElem.clientLeft;
  552. y += curElem.offsetTop + curElem.clientTop;
  553. curElem = curElem.offsetParent;
  554. };
  555. // Position the character left justified to the element
  556. // and on top of it.
  557. y = y - g_AgentCharacter.Height - 20;
  558. Agent_MoveTo(x, y, 0);
  559. }
  560. function Agent_IsVisible() {
  561. if (null == g_AgentCharacter)
  562. return false;
  563. else
  564. return g_AgentCharacter.Visible;
  565. }
  566. function Agent_Show()
  567. {
  568. // Initialize Agent
  569. if (!Agent_Init())
  570. return false;
  571. // Position the character at the appropriate position
  572. // if it's not visible.
  573. if (!g_AgentCharacter.Visible)
  574. {
  575. Agent_HideAssistantSpan();
  576. if (!g_bAgentPreWelcome)
  577. Agent_MoveToPreWelcomePos();
  578. else
  579. Agent_MoveToElement(document.all("AssistImg"), "BottomCenterWidthExactBottom", 0);
  580. if (!g_bAgentPreWelcome)
  581. {
  582. g_AgentCharacter.Show();
  583. g_AgentCharacter.Play("Welcome");
  584. return true;
  585. }
  586. else
  587. {
  588. g_AgentCharacter.Show();
  589. g_AgentCharacter.Play("WakeUp");
  590. return true;
  591. }
  592. if ("Finish" == g_strAgentCurrentPage)
  593. return true;
  594. }
  595. return true;
  596. }
  597. function Agent_OnPageIdle() {
  598. g_AgentPageIdleTimer = null;
  599. if (g_bAgentMenuUp) {
  600. Agent_ResetPageIdleTimer();
  601. return;
  602. }
  603. if (g_strAgentCurrentPage == "")
  604. return;
  605. if (g_iAgentPageIdleLevel == 0) {
  606. try {
  607. eval("Agent_On" + g_strAgentCurrentPage + "Idle()");
  608. }
  609. catch(e) {
  610. }
  611. // Queue a bookmark to start the second level idle
  612. Agent_Think("\\mrk=" + kdwAgentIdleLevel1Finished + "\\");
  613. }
  614. else {
  615. // Level 2 idle is not currently page specific
  616. try {
  617. Agent_OnPageIdleLevel2();
  618. }
  619. catch (e) {
  620. }
  621. }
  622. // Queue a noop Think statement so that we know we're giving
  623. // the idle instructions.
  624. g_AgentRequestIdling = Agent_Think("\\mrk=" + kdwAgentNoop + "\\", true);
  625. }
  626. function Agent_StopPageIdleTimer() {
  627. if (g_AgentPageIdleTimer) {
  628. window.clearTimeout(g_AgentPageIdleTimer);
  629. g_AgentPageIdleTimer = null;
  630. }
  631. g_iAgentPageIdleLevel = 0;
  632. }
  633. function Agent_StartPageIdleTimer() {
  634. if (g_AgentPageIdleTimer)
  635. return;
  636. if (g_iAgentPageIdleLevel == 0)
  637. g_AgentPageIdleTimer = window.setTimeout("Agent_OnPageIdle()", kdwAgentPageIdleTimeout1);
  638. else
  639. g_AgentPageIdleTimer = window.setTimeout("Agent_OnPageIdle()", kdwAgentPageIdleTimeout2);
  640. }
  641. function Agent_ResetPageIdleTimer() {
  642. if (g_AgentRequestIgnoreResetIdle)
  643. return;
  644. if (Agent_IsGivingIdleInstructions())
  645. Agent_StopAll();
  646. if (g_AgentPageIdleTimer)
  647. window.clearTimeout(g_AgentPageIdleTimer);
  648. g_iAgentPageIdleLevel = 0;
  649. g_AgentPageIdleTimer = window.setTimeout("Agent_OnPageIdle()", kdwAgentPageIdleTimeout1);
  650. }
  651. function Agent_StopIgnoreEvents() {
  652. g_bAgentIgnoreEvents = false;
  653. }
  654. function Agent_StopInternalIgnoreEvents() {
  655. g_bAgentInternalIgnoreEvents = false;
  656. }
  657. function Agent_InternalIgnoreEvents(bIgnore) {
  658. if (bIgnore)
  659. g_bAgentInternalIgnoreEvents = bIgnore;
  660. else
  661. window.setTimeout("Agent_StopInternalIgnoreEvents();", 500);
  662. }
  663. function Agent_InternalSetFocus(elem) {
  664. var bPrevIgnore = g_bAgentInternalIgnoreEvents;
  665. Agent_InternalIgnoreEvents(true);
  666. elem.focus();
  667. g_AgentCharacter.Activate(2);
  668. if (bPrevIgnore == false)
  669. Agent_InternalIgnoreEvents(false);
  670. }
  671. function Agent_DoPage() {
  672. // Is this the Finish page?
  673. if ("Finish" == g_strAgentCurrentPage) {
  674. // If we have a character and the character is visible,
  675. // we won't automatically hide it when we're done with
  676. // the page intro.
  677. //
  678. // Also, if the user clicked out of the PreWelcome, we
  679. // don't want to automatically show the character on this
  680. // page.
  681. //
  682. // BUG FIX #101123
  683. if (g_AgentCharacter) {
  684. if (g_AgentCharacter.Visible)
  685. g_bAgentDoneHide = false;
  686. else if (!g_bAgentCongratulateOnFinish)
  687. return;
  688. }
  689. }
  690. // Ensure that Agent is initialized. NOTE NOTE NOTE!!!
  691. // We delay load Agent so that the user doesn't take
  692. // the working set hit if they haven't asked for the
  693. // character.
  694. if (!Agent_Show())
  695. return;
  696. // Stop the idle timer
  697. Agent_StopPageIdleTimer();
  698. // Add the commands appropriate for this checkpoint
  699. Agent_AddCommonCommands();
  700. // Move the character back to his starting position
  701. // BUG FIX for bug #126103
  702. if ((g_strAgentCurrentPage != "Welcome") || g_bAgentPreWelcome)
  703. Agent_MoveToElement(document.all("AssistImg"), "BottomCenterWidthExactBottom", 0);
  704. // Start the page
  705. var bTryOem = false;
  706. if (g_strAgentCurrentPage == "") {
  707. bTryOem = true;
  708. }
  709. else {
  710. // First add page specific commands, then do the intro
  711. try {
  712. eval("Agent_" + g_strAgentCurrentPage + "AddCommands();");
  713. }
  714. catch(e) {
  715. bTryOem = true;
  716. }
  717. if (!bTryOem) {
  718. try {
  719. eval("Agent_" + g_strAgentCurrentPage + "Intro();");
  720. }
  721. catch(e) {
  722. }
  723. }
  724. }
  725. if (bTryOem) {
  726. // It's not a page we know anything about. See if there is
  727. // an OEM page hooked in.
  728. try {
  729. g.Agent_UserRequestAssistant();
  730. }
  731. catch(e) {
  732. }
  733. return;
  734. }
  735. // Queue a bookmark to start idle
  736. QueueStartPageIdleTimer();
  737. }
  738. /////////////////////////////////////////////////////////////////////////////
  739. // EXTERNAL AGENT FUNCTIONS //
  740. /////////////////////////////////////////////////////////////////////////////
  741. /////////////////////////////////////////////////////////////////////////////
  742. // The below functions are the only agent functions that are called from //
  743. // outside of agtcore.js and agtscrpt.js. All external functions must be //
  744. // placed here and must have the check against g_AgentDisabled just as //
  745. // these functions do. //
  746. /////////////////////////////////////////////////////////////////////////////
  747. // --------------- Agent Event Handlers ---------------- //
  748. function Agent_OnRequestComplete(request) {
  749. if (g_AgentDisabled)
  750. return;
  751. if (request == g_AgentRequestLooking) {
  752. // If the request was Interrupted, then reset the object
  753. // to null. NOTE: It's important to do it this way rather
  754. // than setting the request object to null when it is
  755. // stopped (in Agent_InternalStop) so that we can avoid
  756. // going thru the fall thru code at the bottom of this
  757. // if statement.
  758. if (request.Status == 3) {
  759. g_AgentRequestLooking = null;
  760. return;
  761. }
  762. g_bAgentPlayLookReturn = (request.Status == 0);
  763. g_AgentLookBlinkTimer = window.setTimeout("Agent_OnLookBlinkTimer()", 1000);
  764. return;
  765. }
  766. else if (request == g_AgentRequestIdling) {
  767. g_AgentRequestIdling = null;
  768. }
  769. else if (request == g_AgentRequestIgnoreResetIdle) {
  770. g_AgentRequestIgnoreResetIdle = null;
  771. }
  772. else if (request == g_AgentRequestShowPopup) {
  773. g_bAgentMenuUp = true;
  774. // Allow customization of the menu before showing it
  775. if (g_strAgentCurrentPage != "") {
  776. try {
  777. eval("Agent_On" + g_strAgentCurrentPage + "PreDisplayMenu()");
  778. }
  779. catch(e) {
  780. }
  781. }
  782. g_AgentCharacter.ShowPopupMenu(g_AgentCharacter.Left + g_AgentCharacter.Width - kiAgentLeftArmOffsetX, g_AgentCharacter.Top);
  783. g_strAgentLookAnimation = "LookLeft";
  784. Agent_OnF1();
  785. g_AgentRequestLooking = g_AgentCharacter.Play(g_strAgentLookAnimation);
  786. Agent_KeepLooking();
  787. }
  788. else if (request == g_AgentRequestShowAssistSpan) {
  789. // Show the span
  790. document.all("spnAssist").style.visibility = "visible";
  791. // We only want to show the image if the character makes
  792. // it far enough in the script to point at the image.
  793. // Otherwise, it got interrupted and we don't want the
  794. // image there.
  795. if (request.Status == 0)
  796. Agent_ShowAssistantSpan();
  797. }
  798. else if (request == g_AgentRequestHideImage) {
  799. // We need a request object to catch the possibility that
  800. // the character was interrupted during the pre-welcome.
  801. // In that case, we don't want the AssistImg to be visible.
  802. if (request.Status != 0)
  803. Agent_HideAssistantSpan();
  804. g_AgentRequestHideImage = null;
  805. }
  806. else {
  807. // This is probably not one of our requests. NOTE: this is
  808. // NOT perfect due to JScript's lazy garbage collection. It's
  809. // possible that we've reset one of our objects to null, or
  810. // assigned them to another request. If JScript doesn't release
  811. // it's reference immediately, the request object will still
  812. // exist, Agent will fire the RequestComplete event, and our
  813. // internal variable will be null so we won't have caught it
  814. // above. Not a big deal though. The OEM should have a similar
  815. // if or switch statement in their RequestComplete handler.
  816. try {
  817. eval("g.Agent_RequestComplete(request);");
  818. }
  819. catch (e) {
  820. }
  821. }
  822. }
  823. function Agent_OnBookmark(id) {
  824. if (g_AgentDisabled)
  825. return;
  826. switch (id) {
  827. case kdwAgentWelcomeIntroFinished:
  828. g_bAgentWelcomeIntroFinished = true;
  829. break;
  830. case kdwAgentIdleStart:
  831. Agent_StartPageIdleTimer();
  832. break;
  833. case kdwAgentIdleLevel1Finished:
  834. g_iAgentPageIdleLevel++;
  835. Agent_StartPageIdleTimer();
  836. break;
  837. default:
  838. // Default: assume that it is an OEM command. Try to
  839. // fire the event to the OEM page.
  840. try {
  841. eval("g.Agent_Bookmark(id);");
  842. }
  843. catch (e) {
  844. }
  845. break;
  846. }
  847. }
  848. function Agent_OnCommand(userInput) {
  849. if (g_AgentDisabled)
  850. return;
  851. g_bAgentMenuUp = false;
  852. // This is necessary to stop the Look animation that
  853. // might be playing.
  854. Agent_StopAll();
  855. Agent_Play("Acknowledge");
  856. // Reset the focus back to the page
  857. Agent_ResetFocus();
  858. // Stop Idle
  859. Agent_StopPageIdleTimer();
  860. switch (userInput.Name) {
  861. // Common Commands
  862. case "":
  863. case "CloseMenu":
  864. // NOTE NOTE NOTE!!! The empty string ("") means that
  865. // the user dismissed the menu.
  866. break;
  867. case kpszISPSpecialCommand1:
  868. Agent_DoSpecialISPCommand1();
  869. break;
  870. case kpszISPSpecialCommand2:
  871. Agent_DoSpecialISPCommand2();
  872. break;
  873. case kpszISPSpecialCommand3:
  874. Agent_DoSpecialISPCommand3();
  875. break;
  876. default:
  877. // All pages use the scheme that requires that the name
  878. // of the command be equal to the name of the command
  879. // handler.
  880. try {
  881. // Try to evaluate the Command handler function.
  882. // NOTE NOTE NOTE!!! The name of the command should
  883. // be the same as the name of the handler function.
  884. // Also note that parentheses MUST be appended for
  885. // eval to work correctly.
  886. eval(userInput.Name + "();");
  887. break;
  888. }
  889. catch(e) {
  890. // If we don't have an internal command handler by this
  891. // name, assume that the command event is a result of a
  892. // command added by an OEM page. So try to fire it to them.
  893. try {
  894. eval("g.Agent_Command(userInput.Name);");
  895. return;
  896. }
  897. catch (e) {
  898. }
  899. }
  900. }
  901. // Queue a bookmark that will reset the idle timer when
  902. // the above is finished.
  903. QueueStartPageIdleTimer();
  904. }
  905. function Agent_OnDragComplete(characterID, button, shift, x, y) {
  906. if (g_AgentDisabled)
  907. return;
  908. // Just reset the focus to the page and reset the
  909. // idle timer.
  910. Agent_ResetFocus();
  911. Agent_ResetPageIdleTimer();
  912. }
  913. function Agent_OnClick(characterID, button, shift, x, y) {
  914. if (g_AgentDisabled)
  915. return;
  916. // Stop the character
  917. Agent_StopAll();
  918. // Stop the idle timer
  919. Agent_StopPageIdleTimer();
  920. // Allow customization of the menu before showing it
  921. if (g_strAgentCurrentPage != "") {
  922. try {
  923. eval("Agent_On" + g_strAgentCurrentPage + "PreDisplayMenu()");
  924. }
  925. catch(e) {
  926. }
  927. }
  928. // There's no taskbar during OOBE so we don't have to worry
  929. // that the user clicked on the taskbar icon. If this is the
  930. // first time the character's been clicked, play Surprised.
  931. // Otherwise, just look down at the menu.
  932. if (g_bAgentFirstTimeClick) {
  933. g_bAgentFirstTimeClick = false;
  934. Agent_Play("Surprised");
  935. }
  936. Agent_Play("LookDown");
  937. Agent_Play("LookDownBlink");
  938. Agent_Play("LookDownReturn");
  939. Agent_Play("Blink");
  940. g_bAgentMenuUp = true;
  941. // NOTE NOTE NOTE!!! Set the look animation. If idle starts
  942. // we want to keep looking in this direction.
  943. g_strAgentLookAnimation = "LookDown";
  944. if (button == kdwAgentLeftButton)
  945. g_AgentCharacter.ShowPopupMenu(x, y);
  946. // Queue a bookmark to start idle
  947. QueueStartPageIdleTimer();
  948. }
  949. function Agent_OnIdleStart(characterID) {
  950. if (g_AgentDisabled)
  951. return;
  952. if (g_bAgentMenuUp) {
  953. g_AgentRequestLooking = g_AgentCharacter.Play(g_strAgentLookAnimation);
  954. Agent_KeepLooking();
  955. return;
  956. }
  957. }
  958. function Agent_OnIdleComplete(characterID) {
  959. if (g_AgentDisabled)
  960. return;
  961. }
  962. // --------------- Common Functions ---------------- //
  963. function Agent_Init() {
  964. if (g_AgentDisabled)
  965. return false;
  966. if (g_AgentCharacter)
  967. return true;
  968. // Delay loading Agent until absolutely necessary.
  969. // This prevents AgentServer from running on systems
  970. // where the Assistant is not requested.
  971. document.body.insertAdjacentHTML("BeforeEnd", "<OBJECT classid=clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F width=0 height=0 id=Agent></OBJECT>");
  972. try {
  973. Agent.RaiseRequestErrors = false;
  974. Agent.Characters.Load("Character", kpszAgentFilename);
  975. g_AgentCharacter = Agent.Characters.Character("Character");
  976. // Set the character's balloon style to show text all at once
  977. // g_AgentCharacter.Balloon.Style = g_AgentCharacter.Balloon.Style & (~kdwAgentBalloonAutoPace);
  978. g_AgentCharacter.Balloon.Style = 0x2200007;
  979. // Load a character which causes a data provider to get loaded
  980. // into AgentServer that fixes the "not getting a Command
  981. // event when the menu is dismissed without selecting anything"
  982. // bug. It also handles WM_ACTIVATEAPP so that if the OOBE
  983. // main window gets activation, it resets the character's
  984. // z-order to HWND_TOPMOST.
  985. //
  986. // NOTE NOTE NOTE!!! You MUST load this character AFTER
  987. // the real character.
  988. Agent.Characters.Load("AgentCmdFix", "AgentCmd.dat");
  989. }
  990. catch(e) {
  991. return false;
  992. }
  993. try {
  994. // Set the language ID to match the OOBE language
  995. g_AgentCharacter.LanguageID = window.external.get_AppLANGID();
  996. }
  997. catch(e) {
  998. }
  999. return true;
  1000. }
  1001. function Agent_Hide()
  1002. {
  1003. if (g_AgentDisabled)
  1004. return;
  1005. if (null == g_AgentCharacter)
  1006. return;
  1007. g_AgentCharacter.Hide();
  1008. }
  1009. function Agent_OnUserRequestAssistant()
  1010. {
  1011. if (g_AgentDisabled)
  1012. return;
  1013. if ((null == g_AgentCharacter) || (!g_AgentCharacter.Visible))
  1014. {
  1015. // If this is the last page, we need to reset 2 variables. The
  1016. // g_bAgentCongratulateOnFinish variable controls whether Agent_DoPage
  1017. // does anything on the "Finish" page. g_bAgentDoneHide determines whether
  1018. // the character hides after the "Finish" intro. In this case, the
  1019. // user asked for assistance so we don't want to automatically hide.
  1020. if ("Finish" == g_strAgentCurrentPage)
  1021. {
  1022. g_bAgentCongratulateOnFinish = true;
  1023. g_bAgentDoneHide = false;
  1024. }
  1025. Agent_DoPage();
  1026. Agent_Play("Shimmer");
  1027. //tandyt - BUGFIX #117115. Show the menu when we show the character.
  1028. if (window.parent.document.dir == "rtl")
  1029. {
  1030. Agent_MoveTo(screen.width - g_AgentCharacter.Width + kiAgentLeftArmOffsetX - 650, g_AgentCharacter.Top, 4);
  1031. }
  1032. else
  1033. {
  1034. Agent_MoveTo(screen.width - g_AgentCharacter.Width + kiAgentLeftArmOffsetX - 300, g_AgentCharacter.Top, 4);
  1035. }
  1036. g_AgentRequestShowPopup = Agent_Play("PointLeft", true);
  1037. }
  1038. else
  1039. {
  1040. Agent_StopAll();
  1041. Agent_Play("Acknowledge");
  1042. if (window.parent.document.dir == "rtl")
  1043. {
  1044. if ((g_AgentCharacter.Left + g_AgentCharacter.Width - kiAgentLeftArmOffsetX + 650) > screen.width)
  1045. {
  1046. Agent_MoveTo(screen.width - g_AgentCharacter.Width + kiAgentLeftArmOffsetX - 650, g_AgentCharacter.Top, 4);
  1047. }
  1048. }
  1049. else
  1050. {
  1051. if ((g_AgentCharacter.Left + g_AgentCharacter.Width - kiAgentLeftArmOffsetX + 300) > screen.width)
  1052. {
  1053. Agent_MoveTo(screen.width - g_AgentCharacter.Width + kiAgentLeftArmOffsetX - 300, g_AgentCharacter.Top, 4);
  1054. }
  1055. }
  1056. g_AgentRequestShowPopup = Agent_Play("PointLeft", true);
  1057. }
  1058. }
  1059. function Agent_OnFocus(elem) {
  1060. if (g_AgentDisabled)
  1061. return;
  1062. // Save the id of the control that is getting the
  1063. // focus.
  1064. g_strAgentLastFocusID = elem.id;
  1065. // If we don't have Agent, we're done
  1066. if (null == g_AgentCharacter)
  1067. return;
  1068. if (g_bAgentIgnoreEvents || g_bAgentInternalIgnoreEvents)
  1069. return;
  1070. // Stop the idle timer
  1071. Agent_StopPageIdleTimer();
  1072. // If the character is hidden, we're done
  1073. if (!g_AgentCharacter.Visible)
  1074. return;
  1075. if (g_strAgentCurrentPage == "")
  1076. return;
  1077. // Try to call the page specific focus handler
  1078. try {
  1079. eval("Agent_On" + g_strAgentCurrentPage + "GotFocus(elem);");
  1080. }
  1081. catch(e) {
  1082. }
  1083. // Queue a bookmark to start idle
  1084. QueueStartPageIdleTimer();
  1085. }
  1086. function Agent_OnKeyDown(elem) {
  1087. if (g_AgentDisabled)
  1088. return;
  1089. if (g_bAgentIgnoreEvents)
  1090. return;
  1091. // Check for the F1 key
  1092. if (g.event.keyCode == 112) {
  1093. Agent_OnUserRequestAssistant();
  1094. return;
  1095. }
  1096. // Hmmmm
  1097. if (elem.id == "")
  1098. return;
  1099. // If we don't have Agent, we're done
  1100. if (null == g_AgentCharacter)
  1101. return;
  1102. // Stop the timers on any keydown event
  1103. Agent_StopPageIdleTimer();
  1104. // If the character is currently hidden, we don't
  1105. // do anything.
  1106. if (!g_AgentCharacter.Visible)
  1107. return;
  1108. // BUG FIX #116394. If this is an unknown page, we're done.
  1109. // Otherwise, we'll get stuck in an endless recursive call
  1110. // to AgentOnKeyDown.
  1111. if (g_strAgentCurrentPage == "")
  1112. return;
  1113. try {
  1114. eval("Agent_On" + g_strAgentCurrentPage + "KeyDown(elem, g.event.keyCode);");
  1115. }
  1116. catch(e) {
  1117. }
  1118. // Queue a bookmark to start idle
  1119. QueueStartPageIdleTimer();
  1120. }
  1121. function Agent_OnElementClick(elem) {
  1122. if (g_AgentDisabled)
  1123. return;
  1124. if (g_bAgentIgnoreEvents)
  1125. return;
  1126. // Hmmmm
  1127. if (elem.id == "")
  1128. return;
  1129. // If we don't have Agent, we're done
  1130. if (null == g_AgentCharacter)
  1131. return;
  1132. // Stop the timers on any click event
  1133. Agent_StopPageIdleTimer();
  1134. // If the character is currently hidden, we don't
  1135. // do anything.
  1136. if (!g_AgentCharacter.Visible)
  1137. return;
  1138. if (g_strAgentCurrentPage == "")
  1139. return;
  1140. try {
  1141. eval("Agent_On" + g_strAgentCurrentPage + "ElementClick(elem);");
  1142. }
  1143. catch(e) {
  1144. }
  1145. // Queue a bookmark to start idle
  1146. QueueStartPageIdleTimer();
  1147. }
  1148. function Agent_OnSelectClick(elem) {
  1149. if (g_AgentDisabled)
  1150. return;
  1151. if (null == g_AgentCharacter)
  1152. return;
  1153. if (g_bAgentIgnoreEvents)
  1154. return;
  1155. // Stop the idle timer
  1156. Agent_StopPageIdleTimer();
  1157. // We want to ignore the Select click when we also get
  1158. // a Select change event.
  1159. if (g_bAgentIgnoreSelectClick) {
  1160. g_bAgentIgnoreSelectClick = false;
  1161. return;
  1162. }
  1163. Agent_StopAll();
  1164. // Bug fix 126010 - removed check for selCountry to set dir as TopRight and LookDown
  1165. if (g.document.dir == "rtl") {
  1166. Agent_MoveToElement(elem, "Left", 0);
  1167. Agent_StartLookingAtElement(elem, "LookLeft");
  1168. }
  1169. else {
  1170. Agent_MoveToElement(elem, "Right", 0);
  1171. Agent_StartLookingAtElement(elem, "LookRight");
  1172. }
  1173. switch (elem.id) {
  1174. case "selUSState":
  1175. g_bAgentRegister3VisitState = true;
  1176. break;
  1177. case "selCAProvince":
  1178. g_bAgentRegister3VisitProvince = true;
  1179. break;
  1180. case "selCountry":
  1181. g_bAgentRegister3VisitCountry = true;
  1182. break;
  1183. }
  1184. // Queue a bookmark to start idle
  1185. QueueStartPageIdleTimer();
  1186. }
  1187. function Agent_IgnoreEvents(bIgnore) {
  1188. if (g_AgentDisabled)
  1189. return;
  1190. if (bIgnore)
  1191. g_bAgentIgnoreEvents = true;
  1192. else
  1193. window.setTimeout("Agent_StopIgnoreEvents();", 500);
  1194. }
  1195. function Agent_OnSelectChange(elem) {
  1196. if (g_AgentDisabled)
  1197. return;
  1198. if (null == g_AgentCharacter)
  1199. return;
  1200. if (g_bAgentIgnoreEvents)
  1201. return;
  1202. // Stop the idle timer
  1203. Agent_StopPageIdleTimer();
  1204. // Stop looking
  1205. if (Agent_IsLooking())
  1206. Agent_StopLooking();
  1207. else
  1208. Agent_StopAll();
  1209. // Acknowledge the selection change
  1210. Agent_Play("Acknowledge");
  1211. // Ignore the next Select click event that will come
  1212. // after this event.
  1213. g_bAgentIgnoreSelectClick = true;
  1214. // Queue a bookmark to start idle
  1215. QueueStartPageIdleTimer();
  1216. }
  1217. function Agent_Activate(strPage) {
  1218. if (g_AgentDisabled)
  1219. return;
  1220. // Hmmm, we're active and someone is calling Activate.
  1221. // This means that Deactivate didn't get called.
  1222. if (g_strAgentCurrentPage != "")
  1223. Agent_Deactivate();
  1224. // Save the current page
  1225. g_strAgentCurrentPage = strPage;
  1226. if (g_strAgentCurrentPage == "ISP")
  1227. g_bAgentShowSpecialISPCommands = false;
  1228. // If this is the Welcome page and we haven't played the
  1229. // pre-welcome yet, do it here. NOTE: the timer use is explained
  1230. // further below.
  1231. if ("Welcome" == g_strAgentCurrentPage) {
  1232. if (!g_bAgentPreWelcome) {
  1233. Agent_DoPage();
  1234. return;
  1235. }
  1236. }
  1237. // BUG FIX #101199. If this checkpoint is greater than the
  1238. // Welcome page, and we haven't played the pre-welcome intro,
  1239. // than OOBE is being restarted. In that case, we need to
  1240. // make sure that the character icon is visible and that we
  1241. // don't do anything.
  1242. if ((g_CurrentCKPT > CKPT_WELCOME) && !g_bAgentPreWelcome) {
  1243. g_bAgentPreWelcome = true;
  1244. Agent_ShowAssistantSpan();
  1245. return;
  1246. }
  1247. // If we don't have Agent, we're done
  1248. if (null == g_AgentCharacter)
  1249. return;
  1250. // If the character is currently hidden, we're done. NOTE:
  1251. // the exception being CKPT_DONE. If this is the last page
  1252. // we're going to show the character automatically so that
  1253. // it can say goodbye.
  1254. if (!g_AgentCharacter.Visible)
  1255. return;
  1256. // HACK HACK HACK!!! Timing issues galore here. Just
  1257. // make sure we ignore events until the page tells
  1258. // us it's ready, i.e. it's done setting focus to
  1259. // controls, etc.
  1260. if ("Register3" == g_strAgentCurrentPage)
  1261. Agent_IgnoreEvents(true);
  1262. // If the last current page is empty (i.e. an unknown page), we need
  1263. // to stop the character here. NOTE: if it's a known page, we would
  1264. // have stopped it in Agent_Deactivate.
  1265. if ("" == g_strAgentLastPage) {
  1266. if (Agent_IsLooking())
  1267. Agent_StopLooking();
  1268. else
  1269. Agent_StopAll();
  1270. }
  1271. // Do the page introduction
  1272. Agent_DoPage();
  1273. }
  1274. function Agent_Deactivate()
  1275. {
  1276. if (g_AgentDisabled)
  1277. {
  1278. return;
  1279. }
  1280. g_strAgentLastPage = g_strAgentCurrentPage;
  1281. g_strAgentCurrentPage = "";
  1282. // Special case handling for ISP Common Commands
  1283. // Reset the last focus id
  1284. g_strAgentLastFocusID = "";
  1285. // Stop the idle timer
  1286. Agent_StopPageIdleTimer();
  1287. // If we don't have Agent, we're done
  1288. if (null == g_AgentCharacter)
  1289. {
  1290. return;
  1291. }
  1292. // Reset the commands
  1293. Agent_AddCommonCommands();
  1294. // If the character is currently hidden, we're done
  1295. if (!g_AgentCharacter.Visible)
  1296. {
  1297. return;
  1298. }
  1299. if (g_AgentRequestHideImage)
  1300. {
  1301. Agent_StopAll();
  1302. g_AgentCharacter.Hide();
  1303. g_bAgentCongratulateOnFinish = false;
  1304. return;
  1305. }
  1306. // BUG FIX #100694. Use Agent_Stop here instead of Agent_StopAll.
  1307. // We don't want to interrupt a Hide command that may have been
  1308. // issued by the user via the menu. The difference between StopAll
  1309. // and Stop with no parameters is that Stop will NOT stop a Hide
  1310. // request.
  1311. Agent_Stop();
  1312. // BUG FIX # 232615,291844
  1313. // Added the Hide control, so the agent will get deactivated if
  1314. // none of the prior tests have deactivated it or dropped us out.
  1315. Agent_Play("RestPose");
  1316. g_AgentCharacter.Hide();
  1317. }
  1318. function Agent_TurnOnISPSpecialCommands() {
  1319. if (g_AgentDisabled)
  1320. return;
  1321. g_bAgentShowSpecialISPCommands = true;
  1322. if (null == g_AgentCharacter)
  1323. return;
  1324. Agent_AddCommonCommands();
  1325. }
  1326. function Agent_TurnOffISPSpecialCommands() {
  1327. if (g_AgentDisabled)
  1328. return;
  1329. g_bAgentShowSpecialISPCommands = false;
  1330. if (null == g_AgentCharacter)
  1331. return;
  1332. try {
  1333. g_AgentCharacter.Commands.Remove(kpszISPSpecialCommand1);
  1334. g_AgentCharacter.Commands.Remove(kpszISPSpecialCommand2);
  1335. g_AgentCharacter.Commands.Remove(kpszISPSpecialCommand3);
  1336. }
  1337. catch (e) {
  1338. }
  1339. }
  1340. function Agent_OnFinish() {
  1341. if (g_AgentDisabled)
  1342. return;
  1343. // If we don't have Agent, we're done
  1344. if (null == g_AgentCharacter)
  1345. return;
  1346. Agent_StopAll();
  1347. g_AgentCharacter.Hide(true);
  1348. }
  1349. function Agent_OnNavigate() {
  1350. }
  1351. // --------------- Product Key Page(prodkey.htm) Scripts ----------------//
  1352. function Agent_OnProductKeyKeyboardHelper(elem, keyCode) {
  1353. if (g_AgentDisabled)
  1354. return;
  1355. // Pretty much the same as Agent_OnKeyDown. But, we can't
  1356. // rely on g.event.keyCode, etc.
  1357. if (g_bAgentIgnoreEvents)
  1358. return;
  1359. // Hmmmm
  1360. if (elem.id == "")
  1361. return;
  1362. // If we don't have Agent, we're done
  1363. if (null == g_AgentCharacter)
  1364. return;
  1365. // We're not idle
  1366. Agent_StopPageIdleTimer();
  1367. // If the character is currently hidden, we don't
  1368. // do anything.
  1369. if (!g_AgentCharacter.Visible)
  1370. return;
  1371. Agent_OnProductKeyKeyDown(elem, keyCode);
  1372. // Queue a bookmark to start idle
  1373. QueueStartPageIdleTimer();
  1374. }
  1375. //------------- general mouse tutorial functions ---------------//
  1376. function Agent_MouseOver(elem) {
  1377. if (g_AgentDisabled)
  1378. return;
  1379. // If we don't have Agent, we're done
  1380. if (null == g_AgentCharacter)
  1381. return;
  1382. if (g_bAgentIgnoreEvents || g_bAgentInternalIgnoreEvents)
  1383. return;
  1384. // If the character is hidden, we're done
  1385. if (!g_AgentCharacter.Visible)
  1386. return;
  1387. if (g_strAgentCurrentPage == "")
  1388. return;
  1389. Agent_StopAll();
  1390. Agent_MoveToElement(elem, "TopCenterWidth", 0);
  1391. Agent_StartLookingAtElement(elem, "Look" + "Down");
  1392. }