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.

430 lines
12 KiB

  1. //------------------------------------------------------------------------
  2. //
  3. // inc_global.js: Resuable JavaScript functions
  4. // used accross all the pages
  5. //
  6. // Copyright (c) Microsoft Corporation. All rights reserved.
  7. //
  8. // Date Description
  9. // 25/07/2000 Created date
  10. //------------------------------------------------------------------------
  11. //------------------------------------------------------------------------
  12. // Function to clear the error messages (if any on screen) whenever required
  13. //------------------------------------------------------------------------
  14. function ClearErr()
  15. {
  16. // checking for the browser type
  17. if (IsIE())
  18. {
  19. var oDiv = document.all("divErrMsg");
  20. if ( oDiv ) oDiv.innerHTML = "";
  21. // removing the event handling
  22. document.frmTask.onkeypress = null ;
  23. }
  24. }
  25. //------------------------------------------------------------------------
  26. // Function: To check if given input is INTEGER or not
  27. // input: Text value, text length
  28. // returns: True if the field is integer else false
  29. //------------------------------------------------------------------------
  30. function isInteger(strText)
  31. {
  32. var blnResult = true;
  33. var strChar;
  34. // checking for null string
  35. if (strText.length==0)
  36. {
  37. blnResult=false;
  38. }
  39. for(var i=0;i < strText.length;i++)
  40. {
  41. strChar=strText.substring(i,i+1);
  42. if(strChar < "0" || strChar > "9")
  43. {
  44. blnResult = false;
  45. }
  46. }
  47. return blnResult;
  48. }
  49. //------------------------------------------------------------------------
  50. // Function: getRadioButtonValue
  51. // Description: Get's the selected radioButton value
  52. // input: Object -Radio Object
  53. // returns: String -value of the selected radio Button
  54. //------------------------------------------------------------------------
  55. function getRadioButtonValue(objRadio)
  56. {
  57. var strValue;
  58. for(var i =0; i < objRadio.length; i++)
  59. {
  60. //checking for If selected
  61. if(objRadio[i].checked)
  62. {
  63. strValue = objRadio[i].value ;
  64. break;
  65. }
  66. }
  67. return strValue;
  68. }
  69. //------------------------------------------------------------------------
  70. // Function: To count the number of occurences of given character in the text
  71. // input: strText-sourceString
  72. // : charToCount-character to be checked
  73. // returns: The count of no of character
  74. //------------------------------------------------------------------------
  75. function countChars(strText,charToCount)
  76. {
  77. var intStartingPosition = 0;
  78. var intFoundPosition =0;
  79. var intCount = 0;
  80. // checking for the null character
  81. if (charToCount=="")
  82. {
  83. return intCount;
  84. }
  85. while((intFoundPosition=strText.indexOf(charToCount,intStartingPosition)) >= 0)
  86. {
  87. intCount++;
  88. intStartingPosition = intFoundPosition + 1;
  89. }
  90. return intCount ;
  91. }
  92. //------------------------------------------------------------------------
  93. // Function: Check to see if all characters in string are spaces
  94. // input: strText-sourceString
  95. // returns:
  96. // 0 - not all spaces
  97. // 1 - all spaces
  98. //------------------------------------------------------------------------
  99. function IsAllSpaces(strText)
  100. {
  101. var bIsAllSpaces;
  102. if (countChars(strText," ") == strText.length)
  103. {
  104. bIsAllSpaces = 1;
  105. }
  106. else
  107. {
  108. bIsAllSpaces = 0;
  109. }
  110. return bIsAllSpaces ;
  111. }
  112. //------------------------------------------------------------------------
  113. // Function name: selectFocus
  114. // Description: select and focus on the Textbox object
  115. // input: The object on which focus must be set
  116. //------------------------------------------------------------------------
  117. function selectFocus(objControl)
  118. {
  119. objControl.focus();
  120. objControl.select();
  121. }
  122. //------------------------------------------------------------------------
  123. // Function : removeListBoxItems
  124. // Description: To remove the selected options from the given list
  125. // the selected items in the list object is removed from
  126. // the list on click of Remove button and sets focus on IP
  127. // address text object or the Remove button object depending
  128. // on conditions
  129. // Input: objList -Listbox
  130. // : btnRemove -Button object for disable/enable
  131. // Returns:
  132. // Support functions used :
  133. // ClearErr
  134. //------------------------------------------------------------------------
  135. function removeListBoxItems(objList,btnRemove)
  136. {
  137. // Clear any previous error messages
  138. ClearErr();
  139. var i=0;
  140. // number of elements in the list object
  141. var intListLength = objList.length ;
  142. var intDeletedItemPosition
  143. while(i < intListLength)
  144. {
  145. if ( objList.options[i].selected )
  146. {
  147. intDeletedItemPosition = i
  148. objList.options[i]=null;
  149. intListLength=objList.length;
  150. }
  151. else
  152. i++;
  153. }
  154. if (intDeletedItemPosition >=objList.length)
  155. intDeletedItemPosition = intDeletedItemPosition -1
  156. if(objList.length == 0)
  157. {
  158. btnRemove.disabled = true;
  159. //
  160. btnRemove.value = btnRemove.value;
  161. }
  162. else
  163. {
  164. objList.options[intDeletedItemPosition].selected = true;
  165. // focus on the Remove button
  166. btnRemove.focus();
  167. }
  168. }
  169. //------------------------------------------------------------------------
  170. // Function: addToListBox
  171. // Description: moves the passed textbox value to ListBox
  172. // input: objList-List Object
  173. // : ButtonObject- Remove button
  174. // : strText-Text of the option item
  175. // : strValue-value of the option item
  176. // output: btnRemove-Button
  177. //------------------------------------------------------------------------
  178. function addToListBox(objList,btnRemove,strText,strValue)
  179. {
  180. var blnResult=true;
  181. // checking for the text value null
  182. // If the value passed is null make it as text
  183. if (strValue=="")
  184. {
  185. strValue=strText;
  186. }
  187. if (strText!="" )
  188. {
  189. // check for duplicates not required as duplicates accepted
  190. if (!chkDuplicate(objList,strText))
  191. {
  192. // create a new option in the list box
  193. objList.options[objList.length] = new Option(strText,strValue);
  194. objList.options[objList.length-1].selected = true;
  195. // enable the Remove button
  196. if(btnRemove.disabled)
  197. btnRemove.disabled = false ;
  198. }
  199. else
  200. {
  201. blnResult= false;
  202. }
  203. }
  204. else
  205. {
  206. blnResult= false;
  207. }
  208. return blnResult;
  209. }
  210. //------------------------------------------------------------------------
  211. // Function: chkDuplicate
  212. // Description: checks for the duplicate text in the list box
  213. // input: Object -Radio Object
  214. // : strchkName -value of the Name to be checked
  215. //returns: blnDuplicate-Returns true/false on success/failure
  216. //------------------------------------------------------------------------
  217. function chkDuplicate(objList,strchkName)
  218. {
  219. var i;
  220. var blnDuplicate=false;
  221. for(var i=0;i < objList.length;i++)
  222. {
  223. if (objList.options[i].text == strchkName)
  224. blnDuplicate = true;
  225. }
  226. return blnDuplicate;
  227. }
  228. //------------------------------------------------------------------------
  229. // Function: isValidIP
  230. // Description: to validate the IP address
  231. // input: IP address text object
  232. // returns:0 if it is valid
  233. // 1 Empty
  234. // 2 Invalid Format, number of dots is not 3
  235. // 3 non-integers present in the value
  236. // 4 start ip > 223
  237. // 5 Should not start with 127
  238. // 6 out of bound
  239. // 7 All zeros
  240. // 8 Should not be 0
  241. // support functions:
  242. // IsAllSpaces
  243. // countChars
  244. // isInteger
  245. //------------------------------------------------------------------------
  246. function isValidIP(objIP)
  247. {
  248. var strIPtext = objIP.value;
  249. if ((strIPtext.length == 0) || IsAllSpaces(strIPtext))
  250. {
  251. // IP Empty
  252. return 1;
  253. }
  254. if ( countChars(strIPtext,".") != 3)
  255. {
  256. // Invalid Format, number of dots is not 3
  257. return 2;
  258. }
  259. var arrIP = strIPtext.split(".");
  260. for(var i = 0; i < 4; i++)
  261. {
  262. if ( (arrIP[i].length < 1 ) || (arrIP[i].length > 3 ) )
  263. {
  264. // Invalid Format, continuous dots or more than 3 digits given between dots
  265. return 2;
  266. }
  267. if ( !isInteger(arrIP[i]) )
  268. {
  269. // non-integers present in the value
  270. return 3;
  271. }
  272. arrIP[i] = parseInt(arrIP[i]);
  273. if(i == 0)
  274. {
  275. // start IP value
  276. if(arrIP[i] == 0)
  277. {
  278. // start IP value must not be 0
  279. return 8;
  280. }
  281. if(arrIP[i] > 223)
  282. {
  283. // start IP must not be > 223
  284. return 4;
  285. }
  286. if(arrIP[i] == 127)
  287. {
  288. // start IP must not be 127 - Loopback ip
  289. return 5;
  290. }
  291. }
  292. else
  293. {
  294. // the 2nd, 3rd and 4th IP values between the dots
  295. // these must not be more than 255
  296. if (arrIP[i] > 255)
  297. {
  298. // IP out of bound
  299. return 6;
  300. }
  301. }
  302. }
  303. objIP.value = arrIP.join(".");
  304. if(objIP.value == "0.0.0.0")
  305. {
  306. // IP all zeros
  307. return 7;
  308. }
  309. return 0;
  310. } // end of isValidIP
  311. //------------------------------------------------------------------------
  312. // Function :checkkeyforIPAddress
  313. // Description :function to allow only dots and numbers
  314. // input :Object -TextBox Object
  315. // returns :none
  316. //------------------------------------------------------------------------
  317. function checkKeyforIPAddress(obj)
  318. {
  319. // Clear any previous error messages
  320. ClearErr();
  321. if (!(window.event.keyCode >=48 && window.event.keyCode <=57 || window.event.keyCode == 46))
  322. {
  323. window.event.keyCode = 0;
  324. obj.focus();
  325. }
  326. }
  327. //------------------------------------------------------------------------
  328. // Function :checkkeyforNumbers
  329. // Description :function to allow only numbers
  330. // input :Object -TextBox Object
  331. // returns :none
  332. //------------------------------------------------------------------------
  333. function checkKeyforNumbers(obj)
  334. {
  335. // Clear any previous error messages
  336. ClearErr();
  337. if (!(window.event.keyCode >=48 && window.event.keyCode <=57))
  338. {
  339. window.event.keyCode = 0;
  340. obj.focus();
  341. }
  342. }
  343. //------------------------------------------------------------------------
  344. // Function :disableAddButton
  345. // Description :Function to make the add button disable
  346. // input :Object -TextBox Object
  347. // :Object-Addbutton
  348. // returns :none
  349. //------------------------------------------------------------------------
  350. // Function to make the add button disable
  351. function disableAddButton(objText,objButton)
  352. {
  353. if(Trim(objText.value)=="")
  354. {
  355. objButton.disabled=true;
  356. objButton.value = objButton.value;
  357. }
  358. else
  359. objButton.disabled=false;
  360. }
  361. //------------------------------------------------------------------------
  362. // Function :isvalidchar
  363. // Description :Function to check whether the input is valid or not
  364. // input :Invalid char list
  365. // The input string
  366. // returns :true if it doesnt contain the invalid chars; else false
  367. //------------------------------------------------------------------------
  368. // Checks For Invalid Key Entry
  369. function isvalidchar(strInvalidChars,strInput)
  370. {
  371. var rc = true;
  372. try
  373. {
  374. var exp = new RegExp(strInvalidChars);
  375. var result = exp.test(strInput);
  376. if ( result == true )
  377. {
  378. rc = false;
  379. }
  380. else
  381. {
  382. rc = true;
  383. }
  384. }
  385. catch(oException)
  386. {
  387. if ( SA_IsDebugEnabled() )
  388. {
  389. alert("Unexpected exception encountered in function: isvalidchar\n\n"
  390. + "Number: " + oException.number + "\n"
  391. + "Description: " + oException.description);
  392. }
  393. }
  394. return rc;
  395. }