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.

1177 lines
28 KiB

  1. // ==============================================================
  2. // Microsoft Server Appliance
  3. // Page-level JavaScript functions
  4. //
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. //
  7. // ==============================================================
  8. <!-- Copyright (c) Microsoft Corporation. All rights reserved.-->
  9. var blnOkayToLeavePage = true;
  10. function SetOkayToLeavePage()
  11. {
  12. blnOkayToLeavePage = true;
  13. }
  14. function ClearOkayToLeavePage()
  15. {
  16. blnOkayToLeavePage = false;
  17. }
  18. function SetPageChanged(valChanged)
  19. {
  20. if ( valChanged )
  21. {
  22. ClearOkayToLeavePage();
  23. }
  24. else
  25. {
  26. SetOkayToLeavePage();
  27. SA_StoreInitialState();
  28. }
  29. }
  30. function SA_IsOkToChangePage()
  31. {
  32. if ( SA_HasStateChanged() )
  33. return false;
  34. else
  35. return true;
  36. }
  37. //-------------------------------------------------------------------------
  38. //
  39. // Function : GetCurrentTabURL
  40. //
  41. // Synopsis : Get the URL of the currently active tab
  42. //
  43. // Arguments: None
  44. //
  45. // Returns : None
  46. //
  47. //-------------------------------------------------------------------------
  48. function GetCurrentTabURL()
  49. {
  50. var strReturnURL;
  51. var strStart;
  52. var strEnd;
  53. var intTab;
  54. strReturnURL = document.location.search;
  55. strStart = strReturnURL.indexOf("Tab=");
  56. if (strStart != -1)
  57. {
  58. strEnd = strReturnURL.indexOf("&", strStart+4);
  59. if (strEnd != -1)
  60. {
  61. intTab = strReturnURL.substring(strStart+4, strEnd);
  62. }
  63. else
  64. {
  65. intTab = strReturnURL.substring(strStart+4, strReturnURL.length);
  66. }
  67. }
  68. if (intTab==null)
  69. {
  70. intTab=0;
  71. }
  72. return GetTabURL(intTab);
  73. }
  74. //-------------------------------------------------------------------------
  75. //
  76. // Function : OpenNewPage
  77. //
  78. // Synopsis : Opens a new browser window for the specified URL
  79. //
  80. // Arguments: VirtualRoot(IN) - current virtual root
  81. // TaskURL(IN) - URL to open
  82. //
  83. // Returns : None
  84. //
  85. //-------------------------------------------------------------------------
  86. function OpenNewPage(VirtualRoot, TaskURL, WindowFeatures) {
  87. var strURL;
  88. strURL = VirtualRoot + TaskURL;
  89. if ( WindowFeatures != 'undefined' && WindowFeatures.length > 0 )
  90. {
  91. window.open(strURL, '_blank', WindowFeatures)
  92. }
  93. else
  94. {
  95. window.open(strURL, '_blank')
  96. }
  97. return true;
  98. }
  99. //-------------------------------------------------------------------------
  100. //
  101. // Function : OpenRawPageEx
  102. //
  103. // Synopsis : Opens a new browser window for the specified URL
  104. //
  105. // Arguments: TaskURL(IN) - URL to open
  106. // WindowFeatures - parameters for window features in window.open call
  107. //
  108. // Returns : None
  109. //
  110. //-------------------------------------------------------------------------
  111. function OpenRawPageEx(TaskURL, WindowFeatures) {
  112. if ( WindowFeatures != 'undefined' && WindowFeatures.length > 0 )
  113. {
  114. window.open(TaskURL, '_blank', WindowFeatures)
  115. }
  116. else
  117. {
  118. window.open(TaskURL, '_blank')
  119. }
  120. return true;
  121. }
  122. //-------------------------------------------------------------------------
  123. //
  124. // Function : OpenRawPage
  125. //
  126. // Synopsis : Opens a new browser window for the specified URL
  127. //
  128. // Arguments: VirtualRoot(IN) - current virtual root
  129. // TaskURL(IN) - URL to open
  130. //
  131. // Returns : None
  132. //
  133. //-------------------------------------------------------------------------
  134. function OpenRawPage(TaskURL) {
  135. return OpenRawPageEx(TaskURL, '');
  136. }
  137. //-------------------------------------------------------------------------
  138. //
  139. // Function : OpenNormalPage
  140. //
  141. // Synopsis : ,
  142. // and sets the current window to open it.
  143. //
  144. // Arguments: VirtualRoot(IN) - current virtual root
  145. // TaskURL(IN) - URL to open
  146. //
  147. // Returns : None
  148. //
  149. //-------------------------------------------------------------------------
  150. function OpenNormalPage(VirtualRoot, TaskURL) {
  151. var strURL;
  152. // This section will check to see if the user has made any changes to the page
  153. // which might be lost if we leave. Ask the user if this is the case.
  154. if (!SA_IsOkToChangePage() )
  155. {
  156. if (!confirm(GetUnsavedChangesMessage()) )
  157. {
  158. return false;
  159. }
  160. }
  161. strURL = VirtualRoot + TaskURL;
  162. strURL = SA_MungeURL(strURL, SAI_FLD_PAGEKEY, g_strSAIPageKey);
  163. top.location = strURL;
  164. }
  165. function SA_OnOpenNormalPage(sRoot, sURL, sReturnURL)
  166. {
  167. if ( sReturnURL.length <= 0 )
  168. {
  169. sReturnURL = top.location.href;
  170. }
  171. sReturnURL = SA_MungeURL(sReturnURL, "R", ""+Math.random());
  172. sURL = SA_MungeURL(sURL, "ReturnURL", sReturnURL);
  173. OpenNormalPage(sRoot, sURL)
  174. return true;
  175. }
  176. function SA_OnOpenPropertyPage(sRoot, sURL, sReturnURL, sTaskTitle)
  177. {
  178. if ( sReturnURL.length <= 0 )
  179. {
  180. sReturnURL = top.location.href;
  181. }
  182. sReturnURL = SA_MungeURL(sReturnURL, "R", ""+Math.random());
  183. OpenPage(sRoot, sURL, sReturnURL, sTaskTitle)
  184. return true;
  185. }
  186. //-------------------------------------------------------------------------
  187. //
  188. // Function : OpenPage
  189. //
  190. // Synopsis : Builds a URL, adding a ReturnURL and a random number(R),
  191. // and sets the current window to open it.
  192. //
  193. // Arguments: VirtualRoot(IN) - current virtual root
  194. // TaskURL(IN) - URL to open
  195. // ReturnURL(IN) - URL to mark as return URL for the TaskURL
  196. // strTitle(IN) - title of wizard
  197. //
  198. // Returns : None
  199. //
  200. //-------------------------------------------------------------------------
  201. function OpenPage(VirtualRoot, TaskURL, ReturnURL, strTitle) {
  202. var strURL;
  203. var strQueryString;
  204. var strCurrentURL;
  205. var i;
  206. var intReturnURLIndex;
  207. //alert("TaskURL: " + TaskURL);
  208. //alert("ReturnURL: " + ReturnURL);
  209. //alert("top.location: " + top.location);
  210. if (!SA_IsOkToChangePage() )
  211. {
  212. if (!confirm(GetUnsavedChangesMessage()) )
  213. {
  214. return false;
  215. }
  216. }
  217. //
  218. // Remove Random number param from ReturnURL
  219. //
  220. //alert("Before removing R param ReturnURL: " + ReturnURL);
  221. ReturnURL = SA_MungeURL(ReturnURL, "R", ""+Math.random());
  222. //alert("After ReturnURL: " + ReturnURL);
  223. //i = ReturnURL.indexOf('&R=');
  224. //if (i != -1)
  225. //{
  226. // ReturnURL = ReturnURL.substring(0, i);
  227. //}
  228. //else
  229. //{
  230. // i = ReturnURL.indexOf('?R=');
  231. // if (i != -1)
  232. // {
  233. // ReturnURL = ReturnURL.substring(0, i);
  234. // }
  235. //}
  236. //i = ReturnURL.indexOf('?')
  237. //if ( i != -1 )
  238. //{
  239. //ReturnURL = ReturnURL + "&R=" + Math.random();
  240. //}
  241. //else
  242. //{
  243. //ReturnURL = ReturnURL + "?R=" + Math.random();
  244. //}
  245. i = TaskURL.indexOf('&ReturnURL=')
  246. if (i != -1)
  247. {
  248. strURL = TaskURL.substring(0, i);
  249. }
  250. // JK 1-16-01
  251. // Strip TaskURL of the Random number parameter
  252. //strURL = SA_MungeURL(TaskURL, "R", "");
  253. i = TaskURL.indexOf('&R=');
  254. if (i != -1)
  255. {
  256. strURL = TaskURL.substring(0, i);
  257. }
  258. else
  259. {
  260. i = TaskURL.indexOf('?R=');
  261. if (i != -1)
  262. {
  263. strURL = TaskURL.substring(0, i);
  264. }
  265. else
  266. {
  267. strURL = TaskURL;
  268. }
  269. }
  270. strURL = '&URL=' + EscapeArg(strURL);
  271. if (TaskURL.indexOf('ReturnURL') == -1)
  272. {
  273. if ( (ReturnURL == null) || (ReturnURL == '') )
  274. {
  275. strQueryString = window.location.search;
  276. i = strQueryString.indexOf('&R=');
  277. if (i != -1)
  278. {
  279. strQueryString = strQueryString.substring(0, i);
  280. }
  281. else
  282. {
  283. i = strQueryString.indexOf('?R=');
  284. if (i != -1)
  285. {
  286. strQueryString = strQueryString.substring(0, i);
  287. }
  288. }
  289. intReturnURLIndex = strQueryString.indexOf('ReturnURL');
  290. if (intReturnURLIndex != -1)
  291. {
  292. strQueryString = strQueryString.substring(0, intReturnURLIndex);
  293. }
  294. strCurrentURL = window.location.pathname + strQueryString;
  295. }
  296. else
  297. {
  298. // JK 1-16-01
  299. // Do not remove returnURL parameter contained within returnURL
  300. //
  301. //i = ReturnURL.indexOf('&ReturnURL=');
  302. //if (i != -1)
  303. //{
  304. // ReturnURL = ReturnURL.substring(0,i);
  305. //}
  306. strCurrentURL = EscapeArg(ReturnURL);
  307. }
  308. strURL += "&ReturnURL=";
  309. if (strCurrentURL.indexOf('/', 1) != -1 && strCurrentURL.substr('..', 0, 2) == -1)
  310. {
  311. strURL += "..";
  312. }
  313. strURL += strCurrentURL;
  314. }
  315. strURL += "&R=" + Math.random();
  316. strURL += "&" + SAI_FLD_PAGEKEY + "=" + g_strSAIPageKey;
  317. strURL = 'Title=' + EscapeArg(strTitle) + strURL;
  318. strURL = VirtualRoot + 'sh_taskframes.asp?' + strURL;
  319. top.location = strURL;
  320. }
  321. //-------------------------------------------------------------------------
  322. //
  323. // Function : GetServerName
  324. //
  325. // Synopsis : Return server name as specified in browser address bar
  326. //
  327. // Arguments: None
  328. //
  329. // Returns : server name object
  330. //
  331. //-------------------------------------------------------------------------
  332. function GetServerName()
  333. {
  334. return window.location.host;
  335. }
  336. //-------------------------------------------------------------------------
  337. //
  338. // Function : IsIE
  339. //
  340. // Synopsis : Is browser IE
  341. //
  342. // Arguments: None
  343. //
  344. // Returns : true/false
  345. //
  346. //-------------------------------------------------------------------------
  347. function IsIE()
  348. {
  349. if (navigator.userAgent.indexOf('MSIE')>-1)
  350. return true;
  351. else
  352. return false;
  353. }
  354. //-------------------------------------------------------------------------
  355. //
  356. // Function : Trim
  357. //
  358. // Synopsis : remove all spaces from a string
  359. //
  360. // Arguments: str(IN) - string to modify
  361. //
  362. // Returns : modified string
  363. //
  364. //-------------------------------------------------------------------------
  365. function Trim(str)
  366. {
  367. var res="", i, ch;
  368. for (i=0; i < str.length; i++) {
  369. ch = str.charAt(i);
  370. if (ch != ' '){
  371. res = res + ch;
  372. }
  373. }
  374. return res;
  375. }
  376. //-------------------------------------------------------------------------
  377. //
  378. // Function : BlurLayer
  379. //
  380. // Synopsis : hide layer
  381. //
  382. // Arguments: None
  383. //
  384. // Returns : None
  385. //
  386. //-------------------------------------------------------------------------
  387. function BlurLayer()
  388. {
  389. document.menu.visibility = "hide";
  390. }
  391. //---------------------------------------------------------------
  392. // Confirm tab change support global variables
  393. //---------------------------------------------------------------
  394. var aCSAFormFields = null;
  395. //-------------------------------------------------------------------------
  396. //
  397. // Object: CSAFormField
  398. //
  399. // Synopsis: This object is used to track form field state changes
  400. //
  401. // Arguments: [in] nameIn name of form field
  402. // [in] valueIn initial value of form field
  403. // [in] statusIn initial status of form field
  404. //
  405. // Returns: Nothing
  406. //
  407. //-------------------------------------------------------------------------
  408. function CSAFormField(formNameIn, nameIn, valueIn, statusIn )
  409. {
  410. this.FormName = formNameIn;
  411. this.Name = nameIn;
  412. this.Value = valueIn;
  413. this.Status = statusIn;
  414. }
  415. //-------------------------------------------------------------------------
  416. //
  417. // Function: SA_StoreInitialState
  418. //
  419. // Synopsis: Store the initial state of all form fields on this page.
  420. //
  421. // Arguments: None
  422. //
  423. // Returns: Nothing
  424. //
  425. //-------------------------------------------------------------------------
  426. function SA_StoreInitialState()
  427. {
  428. var x;
  429. var y;
  430. var z;
  431. var formFieldCount;
  432. formFieldCount = 0;
  433. for( x = 0; x < document.forms.length; x++ )
  434. {
  435. formFieldCount += document.forms[x].elements.length;
  436. }
  437. aCSAFormFields = new Array(formFieldCount);
  438. z = 0;
  439. for( x = 0; x < document.forms.length; x++ )
  440. {
  441. for ( y = 0; y < document.forms[x].elements.length; y++)
  442. {
  443. aCSAFormFields[z] = new CSAFormField(
  444. document.forms[x].name,
  445. document.forms[x].elements[y].name,
  446. document.forms[x].elements[y].value,
  447. document.forms[x].elements[y].status );
  448. z++;
  449. }
  450. }
  451. }
  452. //-------------------------------------------------------------------------
  453. //
  454. // Function: SA_HasStateChanged
  455. //
  456. // Synopsis: Check to see if any of the form fields on this page have
  457. // changed from their initial state.
  458. //
  459. // Arguments: None
  460. //
  461. // Returns: True if changes were made, False if form is unchanged.
  462. //
  463. //-------------------------------------------------------------------------
  464. function SA_HasStateChanged()
  465. {
  466. var x;
  467. var y;
  468. var z;
  469. if ( aCSAFormFields == null ) return false;
  470. z = 0;
  471. for( x = 0; x < document.forms.length; x++ )
  472. {
  473. for ( y = 0; y < document.forms[x].elements.length; y++)
  474. {
  475. var ff = aCSAFormFields[z];
  476. if ( ff.Name != document.forms[x].elements[y].name )
  477. {
  478. SA_TraceOut("SA_HasStateChanged", "Field " + ff.Name + "\r\nUnexpected error, form field name changed.");
  479. return true;
  480. }
  481. if ( ff.Value != document.forms[x].elements[y].value )
  482. {
  483. //SA_TraceOut("SA_HasStateChanged", "Form:" + ff.FormName + "\r\nField:" + ff.Name + "\r\nStarting Value:" + ff.Value + " Ending Value:" + document.forms[x].elements[y].value);
  484. return true;
  485. }
  486. if ( ff.Status != document.forms[x].elements[y].status)
  487. {
  488. //SA_TraceOut("SA_HasStateChanged", "Form:" + ff.FormName + "\r\nField:" + ff.Name + "\r\nValue:" + ff.Value+ "\r\nStarting Status:" + ff.Status + " Ending Status:" + document.forms[x].elements[y].status);
  489. return true;
  490. }
  491. z++;
  492. }
  493. }
  494. return false;
  495. }
  496. //---------------------------------------------------------------
  497. // Client side script debugging
  498. //---------------------------------------------------------------
  499. var sa_bDebugEnabled = true;
  500. //-------------------------------------------------------------------------
  501. //
  502. // Function:
  503. //
  504. // Synopsis:
  505. //
  506. // Arguments:
  507. //
  508. // Returns:
  509. //
  510. //-------------------------------------------------------------------------
  511. function SA_IsDebugEnabled()
  512. {
  513. //return sa_bDebugEnabled;
  514. return GetIsDebugEnabled();
  515. }
  516. //-------------------------------------------------------------------------
  517. //
  518. // Function:
  519. //
  520. // Synopsis:
  521. //
  522. // Arguments:
  523. //
  524. // Returns:
  525. //
  526. //-------------------------------------------------------------------------
  527. function SA_TraceOut(fn, msg)
  528. {
  529. if ( SA_IsDebugEnabled() )
  530. {
  531. objForm = SA_FindForm("frmDebug");
  532. if ( null == objForm )
  533. {
  534. //alert("Function: " + fn + "\r\n\r\n" + msg );
  535. }
  536. else
  537. {
  538. if ( objForm.txtDebugOut.value.length > 1 )
  539. objForm.txtDebugOut.value += "\r\nFunction: " + fn + " " + msg;
  540. else
  541. objForm.txtDebugOut.value = "Function: " + fn + " " + msg;
  542. }
  543. }
  544. }
  545. function SA_FindForm(formName)
  546. {
  547. var x;
  548. if ( top.document.forms.length > 0 )
  549. {
  550. for( x = 0; x < top.document.forms.length; x++ )
  551. {
  552. //alert( "Found form: " + top.document.forms[x].name );
  553. if ( formName == top.document.forms[x].name )
  554. {
  555. return top.document.forms[x];
  556. }
  557. }
  558. }
  559. else
  560. {
  561. //alert( "Form count: " + parent.main.document.forms.length );
  562. for( x = 0; x < parent.main.document.forms.length; x++ )
  563. {
  564. //alert( "Found form: " + parent.main.document.forms[x].name );
  565. if ( formName == parent.main.document.forms[x].name )
  566. {
  567. return parent.main.document.forms[x];
  568. }
  569. }
  570. }
  571. return null;
  572. }
  573. //---------------------------------------------------------------------------------
  574. // Function:
  575. // SA_MungeURL(var sURL, var sParamName, var sParamValue )
  576. //
  577. // Synopsis:
  578. // Add, Update, or Delete parameters to a query string URL. If the parameter is not in
  579. // the URL it is added. If it exists, it's value is updated. If the parameter value is blank
  580. // then the parameter is removed from the URL.
  581. //
  582. // The URL must be non-blank on input. If a blank URL is passed an error message is
  583. // displayed and a empty string is returned.
  584. //
  585. // Arguments:
  586. // sURL - Non blank URL that is to be changed.
  587. // sParamName - Name of QueryString parameter
  588. // sParamValue - Value of the parameter
  589. //
  590. // Returns:
  591. // Updated query string URL, empty string if an error occurs.
  592. //
  593. //---------------------------------------------------------------------------------
  594. function SA_MungeURL(sURL, sParamName, sParamValue)
  595. {
  596. var i;
  597. var oException;
  598. //
  599. // Validate arguments
  600. //
  601. if ( sURL == null )
  602. {
  603. sURL = "";
  604. }
  605. if ( (typeof sURL) != "string" )
  606. {
  607. sURL = "" + sURL;
  608. }
  609. if ( sParamName == null )
  610. {
  611. SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is null");
  612. return "";
  613. }
  614. if ( (typeof sParamName) != "string" )
  615. {
  616. sParamName = "" + sParamName;
  617. }
  618. if ( sParamValue == null )
  619. {
  620. sParamValue = "";
  621. }
  622. if ( (typeof sParamValue) != "string" )
  623. {
  624. sParamValue = "" + sParamValue;
  625. }
  626. if ( sURL.length <= 0 )
  627. {
  628. SA_TraceOut("SA_MungeURL", "Invalid argument: sURL is empty");
  629. return "";
  630. }
  631. if ( sParamName.length <= 0 )
  632. {
  633. SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is empty");
  634. return "";
  635. }
  636. //
  637. // Munge the URL
  638. //
  639. try
  640. {
  641. i = sURL.indexOf("?"+sParamName+"=");
  642. if ( i < 0 )
  643. {
  644. i = sURL.indexOf("&"+sParamName+"=");
  645. }
  646. if ( i > 0 )
  647. {
  648. //SA_TraceOut("SA_MungeURL","Found parameter: " + sParamName );
  649. var sURL1 = sURL.substring(0, i);
  650. var sURL2 = sURL.substring(i+1);
  651. //SA_TraceOut("SA_MungeURL", "sURL1: " + sURL1);
  652. //SA_TraceOut("SA_MungeURL", "sURL2: " + sURL2);
  653. i = sURL2.indexOf("&");
  654. if ( i > 0 )
  655. {
  656. sURL2 = sURL2.substring(i);
  657. }
  658. else
  659. {
  660. sURL2 = "";
  661. }
  662. if (sParamValue.length > 0)
  663. {
  664. //SA_TraceOut("SA_MungeURL","Value: " + sParamValue);
  665. if (sURL1.indexOf("?") > 0 )
  666. {
  667. sURL = sURL1 + "&" + sParamName + "="
  668. + EscapeArg(sParamValue) + sURL2;
  669. }
  670. else
  671. {
  672. sURL = sURL1 + "?" + sParamName + "="
  673. + EscapeArg(sParamValue) + sURL2;
  674. }
  675. }
  676. else
  677. {
  678. if (sURL1.indexOf("?") > 0)
  679. {
  680. sURL = sURL1 + sURL2;
  681. }
  682. else
  683. {
  684. sURL = sURL1 + "?" + sURL2.substring(1);
  685. }
  686. }
  687. }
  688. else
  689. {
  690. if ( sParamValue.length > 0 )
  691. {
  692. if ( 0 > sURL.indexOf("?") )
  693. {
  694. sURL += '?' + sParamName + '=' + EscapeArg(sParamValue);
  695. }
  696. else
  697. {
  698. sURL += '&' + sParamName + '=' + EscapeArg(sParamValue);
  699. }
  700. }
  701. }
  702. }
  703. catch(oException)
  704. {
  705. SA_TraceOut("SA_MungeURL",
  706. "SA_MungeURL encountered exception: "
  707. + oException.number
  708. + " "
  709. + oException.description);
  710. }
  711. return sURL;
  712. }
  713. //---------------------------------------------------------------------------------
  714. // Function:
  715. // SA_MungeExtractURLParameter(var sURL, var sParamName)
  716. //
  717. // Synopsis:
  718. // Extract the value of a query string parameter. If the parameter does not exist an empty
  719. // string is returned.
  720. //
  721. // The URL must be non-blank on input. If a blank URL is passed an error message is
  722. // displayed and a empty string is returned.
  723. //
  724. // Arguments:
  725. // sURL - Non blank URL that is to be changed.
  726. // sParamName - Name of QueryString parameter
  727. //
  728. // Returns:
  729. // Value of query string parameter, empty string if an error occurs.
  730. //
  731. //---------------------------------------------------------------------------------
  732. function SA_MungeExtractURLParameter(sURL, sParamName)
  733. {
  734. var i;
  735. var oException;
  736. var sParamValue = "";
  737. //
  738. // Validate arguments
  739. //
  740. if ( sURL == null )
  741. {
  742. sURL = "";
  743. }
  744. if ( (typeof sURL) != "string" )
  745. {
  746. sURL = "" + sURL;
  747. }
  748. if ( sParamName == null )
  749. {
  750. SA_TraceOut("SA_MungeURL", "Invalid argument: sParamName is null");
  751. return "";
  752. }
  753. if ( (typeof sParamName) != "string" )
  754. {
  755. sParamName = "" + sParamName;
  756. }
  757. if ( sURL.length <= 0 )
  758. {
  759. SA_TraceOut("SA_MungeExtractURLParameter", "Invalid argument: sURL is empty");
  760. return "";
  761. }
  762. if ( sParamName.length <= 0 )
  763. {
  764. SA_TraceOut("SA_MungeExtractURLParameter", "Invalid argument: sParamName is empty");
  765. return "";
  766. }
  767. //
  768. // Scan for the Parameter
  769. //
  770. try
  771. {
  772. var sParamToken = "?"+sParamName+"=";
  773. i = sURL.indexOf(sParamToken);
  774. if ( i < 0 )
  775. {
  776. sParamToken = "&"+sParamName+"=";
  777. i = sURL.indexOf(sParamToken);
  778. }
  779. if ( i > 0 )
  780. {
  781. sParamValue = sURL.substring(i+sParamToken.length);
  782. i = sParamValue.indexOf("&");
  783. if ( i > 0 )
  784. {
  785. sParamValue = sParamValue.substring(0, i);
  786. }
  787. }
  788. }
  789. catch(oException)
  790. {
  791. SA_TraceOut("SA_MungeExtractURLParameter",
  792. "SA_MungeExtractURLParameter encountered exception: "
  793. + oException.number + " " + oException.description);
  794. }
  795. return sParamValue;
  796. }
  797. //---------------------------------------------------------------------------------
  798. // Function:
  799. // SA_EnableButton(var oButton, var bEnabled)
  800. //
  801. // Synopsis:
  802. // Change the enabled state for a button. oButton must be a DOM reference to a object
  803. // of type='button'.
  804. //
  805. // Arguments:
  806. // oButton - DOM Reference object ot a button
  807. // bEnabled - boolean flag indicating if the button should be enabled (true) or disabled(false)
  808. //
  809. // Returns:
  810. // true to indicate success, false to indicate errors.
  811. //
  812. //---------------------------------------------------------------------------------
  813. function SA_EnableButton(oButton, bEnable)
  814. {
  815. var oException;
  816. try
  817. {
  818. //
  819. // Validate arguments
  820. if ( oButton == null )
  821. {
  822. SA_TraceOut("SA_EnableButton", "oButton argument was null.");
  823. return false;
  824. }
  825. if ( oButton.type != "button" )
  826. {
  827. SA_TraceOut("SA_EnableButton", "oButton.type is invalid, requires oButton.type='button'. Type was: " +oButton.type);
  828. return false;
  829. }
  830. if ( bEnable != true && bEnable != false )
  831. {
  832. SA_TraceOut("SA_EnableButton", "bEnable argument was invalid, required to be either true or false");
  833. return false;
  834. }
  835. //
  836. // Set the button disabled state, the inverse of the bEnabled argument
  837. oButton.disabled = ( (bEnable) ? false : true );
  838. oButton.value = oButton.value;
  839. return true;
  840. }
  841. catch(oException)
  842. {
  843. SA_TraceOut("SA_EnableButton",
  844. "Encountered exception: "
  845. + oException.number + " " + oException.description);
  846. return false;
  847. }
  848. }
  849. ///////////////////////////////////////////////////////////////////////////////////////////////////
  850. // EscapeArg(
  851. //
  852. // @jfunc This function escapes (i.e., legalize) the specified argument.
  853. //
  854. // @rdesc Newly formatted argument
  855. //
  856. // @ex Usage: strShow = EscapeArg("Is <> : * \" this?");
  857. ///////////////////////////////////////////////////////////////////////////////////////////////////
  858. function EscapeArg(
  859. strArg
  860. )
  861. {
  862. return EncodeHttpURL(strArg, 1);
  863. // Validate input.
  864. if (null == strArg)
  865. return null;
  866. // Convert %xx to %u00xx
  867. var strEscArg = escape( strArg );
  868. strEscArg = strEscArg.replace(/(%)([0-9A-F])/gi, "%u00$2");
  869. strEscArg = strEscArg.replace(/\+/g, "%u002B"); // Else + becomes space.
  870. return strEscArg;
  871. }
  872. ///////////////////////////////////////////////////////////////////////////////////////////////////
  873. // UnicodeToUTF8
  874. //
  875. // @jfunc This function converts a string from Unicode to UTF-8 encoding.
  876. //
  877. // @rdesc Newly formatted string
  878. //
  879. // @ex Usage: strShow = UnicodeToUTF8("\u33C2\u7575\u8763");
  880. ///////////////////////////////////////////////////////////////////////////////////////////////////
  881. function UnicodeToUTF8(
  882. strInUni // @parm The string in Unicode encoding
  883. )
  884. {
  885. // Validate input.
  886. if (null == strInUni)
  887. return null;
  888. // The following line fixes a problem when the input is not a valid java script string object.
  889. // This can happen, for example, if the caller passes the output of QueryString() to this
  890. // function; InterDev pops up the following error message if this happen: the error code is
  891. // object doesn't support this property or method. This line of code makes sure we use a valid
  892. // java script string object.
  893. var strUni = ""+strInUni;
  894. // Map string.
  895. var strUTF8 = ""; // Destination (UTF8 encoded string)
  896. // Convert Unicode to UTF-8
  897. for(var i=0; i<strUni.length; i++)
  898. {
  899. var wchr = strUni.charCodeAt(i); // Unicode value.
  900. if (wchr < 0x80)
  901. {
  902. // A char in range 0-0x7f don't need any work. just copy the char.
  903. strUTF8 += strUni.charAt(i);
  904. }
  905. else if (wchr < 0x800)
  906. {
  907. // A char in range 0x80-0x7ff is converted to 2 bytes as follows:
  908. // 0000 0yyy xxxx xxxx -> 110y yyxx 10xx xxxx
  909. var chr1 = wchr & 0xff; // low byte.
  910. var chr2 = (wchr >> 8) & 0xff; // high byte.
  911. strUTF8 += String.fromCharCode(0xC0 | (chr2 << 2) | ((chr1 >> 6) & 0x3));
  912. strUTF8 += String.fromCharCode(0x80 | (chr1 & 0x3F));
  913. }
  914. else
  915. {
  916. // A char in range 0x800-0xffff is converted to 3 bytes as follows:
  917. // yyyy yyyy xxxx xxxx -> 1110 yyyy 10yy yyxx 10xx xxxx
  918. var chr1 = wchr & 0xff; // low byte.
  919. var chr2 = (wchr >> 8) & 0xff; // high byte.
  920. strUTF8 += String.fromCharCode(0xE0 | (chr2 >> 4));
  921. strUTF8 += String.fromCharCode(0x80 | ((chr2 << 2) & 0x3C) | ((chr1 >> 6) & 0x3));
  922. strUTF8 += String.fromCharCode(0x80 | (chr1 & 0x3F));
  923. }
  924. }
  925. return strUTF8;
  926. }
  927. ///////////////////////////////////////////////////////////////////////////////////////////////////
  928. // EscapeHttpURL
  929. //
  930. // @jfunc This function escapes the illigal http chars.
  931. //
  932. // @rdesc Newly formatted string
  933. //
  934. // @ex Usage: strShow = EscapeHttpURL("Is <> \" this a / folder \ name?");
  935. ///////////////////////////////////////////////////////////////////////////////////////////////////
  936. function EscapeHttpURL(
  937. strHttpURL, // @parm URL to escape
  938. nFlags // @parm Encoding flags.
  939. )
  940. {
  941. // Validate input.
  942. if (null == strHttpURL)
  943. return null;
  944. // Init default argument.
  945. if (null == nFlags)
  946. nFlags = 0;
  947. // The following line fixes a problem when the input is not a valid java script string object.
  948. // This can happen, for example, if the caller passes the output of QueryString() to this
  949. // function; InterDev pops up the following error message if this happen: the error code is
  950. // object doesn't support this property or method. This line of code makes sure we use a valid
  951. // java script string object.
  952. var strURL = ""+strHttpURL;
  953. // Unescape string.
  954. var strEsc = "";
  955. for(var i=0; i<strURL.length; i++)
  956. {
  957. var bEscape = false;
  958. var chr = strURL.charAt(i);
  959. var chrCode = strURL.charCodeAt(i);
  960. switch(chr)
  961. {
  962. case '"':
  963. case '#':
  964. case '&':
  965. case '\'':
  966. case '+':
  967. case '<':
  968. case '>':
  969. case '\\':
  970. bEscape = true;
  971. break;
  972. case '%':
  973. if (nFlags & 0x1)
  974. bEscape = true;
  975. break;
  976. default:
  977. if ((chrCode > 0x00 && chrCode <= 0x20) ||
  978. (chrCode > 0x7f && chrCode <= 0xff))
  979. bEscape = true;
  980. break;
  981. }
  982. // escape() doesn't escape the '+' sign.
  983. if ('+' == chr)
  984. strEsc += "%2B";
  985. else if (bEscape)
  986. strEsc += escape(chr);
  987. else
  988. strEsc += chr;
  989. }
  990. // All done.
  991. return strEsc;
  992. }
  993. ///////////////////////////////////////////////////////////////////////////////////////////////////
  994. // EncodeHttpURL(
  995. //
  996. // @jfunc This function legalizes an http url.
  997. //
  998. // @rdesc Newly formatted name
  999. //
  1000. // @ex Usage: strShow = EncodeHttpURL("Is [] {} $24 $22 it a folder$3F");
  1001. ///////////////////////////////////////////////////////////////////////////////////////////////////
  1002. function EncodeHttpURL(
  1003. strHttpURL, // @parm File folder name to be encode.
  1004. nFlags // @parm Encoding flags.
  1005. )
  1006. {
  1007. // Validate input.
  1008. if (null == strHttpURL)
  1009. return null;
  1010. // Init default argument.
  1011. if (null == nFlags)
  1012. nFlags = 0;
  1013. // The following line fixes a problem when the input is not a valid java script string object.
  1014. // This can happen, for example, if the caller passes the output of QueryString() to this
  1015. // function; InterDev pops up the following error message if this happen: the error code is
  1016. // object doesn't support this property or method. This line of code makes sure we use a valid
  1017. // java script string object.
  1018. var strURL = ""+strHttpURL;
  1019. // Convert to UTF-8
  1020. strURL = UnicodeToUTF8( strURL );
  1021. // Percent escape.
  1022. strURL = EscapeHttpURL( strURL, nFlags );
  1023. // All done.
  1024. return strURL;
  1025. }