public.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. /*
  2. * 打开新窗口 f:链接地址 n:窗口的名称 w:窗口的宽度 h:窗口的高度 s:窗口是否有滚动条,1:有滚动条;0:没有滚动条
  3. */
  4. function openWin(f, n, w, h, s)
  5. {
  6. var iTop = (window.screen.availHeight - 30 - w) / 2;
  7. var iLeft = (window.screen.availWidth - 10 - w) / 2;
  8. var iWidth = 500;
  9. var iHeight = 300;
  10. var iTop = (window.screen.availHeight - 30 - iHeight) / 2;
  11. var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;
  12. //var win = window.open("request.aspx", "弹出窗口", "width=" + iWidth + ", height=" + iHeight + ",top=" + iTop + ",left=" + iLeft + ",toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no,alwaysRaised=yes,depended=yes");
  13. var result=window.open(f,n,"height="+h+",width="+w+",top=" + iTop +",left=" + iLeft + "," +s);
  14. //var result=window.showModalDialog(f,n,"dialogHeight:"+h+";dialogWidth:"+w+";"+s);
  15. if(result==true)
  16. {
  17. window.location.reload(true);
  18. }
  19. else
  20. {
  21. //window.location.reload(true);
  22. }
  23. }
  24. /*
  25. * 删除记录
  26. */
  27. function del(url, info)
  28. {
  29. if (confirm(info))
  30. {
  31. var result=window.showModalDialog(url,"window123","dialogHeight:234px;dialogWidth:271px;resizable:no;help:no;status:no;scroll:no");
  32. if(result==true)
  33. {
  34. window.location.reload(true);
  35. }
  36. else
  37. {
  38. }
  39. }
  40. else
  41. {
  42. }
  43. }
  44. /*
  45. * 校验checkbox
  46. */
  47. function checkAll(chkName, checkboxName, pageSize) {
  48. var src = event.srcElement;
  49. var chkN = eval("document.all." + chkName);
  50. if (src.checked) {
  51. chkN[0].checked = true;
  52. chkN[1].checked = true;
  53. for (var i = 0; i < pageSize; i++) {
  54. var chk = eval("document.all." + checkboxName + i);
  55. if (chk) {
  56. chk.checked = true;
  57. }
  58. }
  59. } else {
  60. chkN[0].checked = false;
  61. chkN[1].checked = false;
  62. for (var i = 0; i < pageSize; i++) {
  63. var chk = eval("document.all." + checkboxName + i);
  64. if (chk) {
  65. chk.checked = false;
  66. }
  67. }
  68. }
  69. }
  70. /*
  71. *
  72. */
  73. function makePages(maxPage, selectedPage, selectName) {
  74. var sel = eval("document.all." + selectName);
  75. sel.length = 0;
  76. for (var i = 1; i <= maxPage; i++) {
  77. sel.options[i] = new Option(i, i);
  78. if (sel.options[i] == selectedPage) {
  79. sel.options[i].selected = true;
  80. }
  81. }
  82. }
  83. /*
  84. * 替换字符串
  85. */
  86. function replaceStr(str) {
  87. var re = "/( )/gi";
  88. str = str.replace(re, "");
  89. re = "/\</gi";
  90. str = str.replace(re, "&lt;");
  91. return str;
  92. }
  93. /*
  94. * 去掉左边空格
  95. */
  96. function LTrim(str) {
  97. var whitespace = new String(" \t\n\r");
  98. var s = new String(str);
  99. if (whitespace.indexOf(s.charAt(0)) != -1) {
  100. var j = 0, i = s.length;
  101. while (j < i && whitespace.indexOf(s.charAt(j)) != -1) {
  102. j++;
  103. }
  104. s = s.substring(j, i);
  105. }
  106. return s;
  107. }
  108. /*
  109. * 去掉右边空格
  110. */
  111. function RTrim(str) {
  112. var whitespace = new String(" \t\n\r");
  113. var s = new String(str);
  114. if (whitespace.indexOf(s.charAt(s.length - 1)) != -1) {
  115. var i = s.length - 1;
  116. while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) {
  117. i--;
  118. }
  119. s = s.substring(0, i + 1);
  120. }
  121. return s;
  122. }
  123. /*
  124. * 去掉两边空格
  125. */
  126. function Trim(str) {
  127. return RTrim(LTrim(str));
  128. }
  129. /*
  130. *
  131. */
  132. function exeOperation(exePath) {
  133. var obj = new ActiveXObject("Microsoft.XMLHTTP");
  134. obj.open("post", exePath, false);
  135. obj.send();
  136. var res = obj.responseText;
  137. var rs = Trim(res);
  138. if (rs.indexOf('true', 0) != -1) {
  139. return true;
  140. } else {
  141. return false;
  142. }
  143. }
  144. /*
  145. *
  146. */
  147. function exeValidate(exePath) {
  148. var obj = new ActiveXObject("Microsoft.XMLHTTP");
  149. obj.open("post", exePath, false);
  150. obj.send();
  151. var res = obj.responseText;
  152. var rs = Trim(res);
  153. if (rs.indexOf('validate_login_user', 0) != -1) {
  154. return true;
  155. } else {
  156. return false;
  157. }
  158. }
  159. /*
  160. * 显示
  161. */
  162. function validate_date(exePath) {
  163. var obj = new ActiveXObject("Microsoft.XMLHTTP");
  164. obj.open("post", exePath, false);
  165. obj.send();
  166. var res = obj.responseText;
  167. var rs = Trim(res);
  168. var begin_str = "<!--begin-->";
  169. var beginIndex = rs.indexOf(begin_str) + begin_str.length;
  170. var endIndex = rs.indexOf("<!--end-->");
  171. rs = ((beginIndex >= 0) && (endIndex >= 0)) ? rs.substring(beginIndex,
  172. endIndex) : "";
  173. return Trim(rs);
  174. }
  175. /*
  176. * 校验是否数字
  177. */
  178. function checkNumber(name, TempS) {
  179. for (Count = 0; Count < TempS.length; Count++) {
  180. TempChar = TempS.substring(Count, Count + 1);
  181. RefString = "0123456789";
  182. if (RefString.indexOf(TempChar, 0) == -1) {
  183. alert("请输入数字");
  184. eval("document.all." + name).focus();
  185. return false;
  186. }
  187. }
  188. }
  189. /*
  190. * 是否有非法字符
  191. */
  192. function chksafe(a) {
  193. fibdn = new Array("'", "\\");
  194. i = fibdn.length;
  195. j = a.length;
  196. for (ii = 0; ii < i; ii++) {
  197. for (jj = 0; jj < j; jj++) {
  198. temp1 = a.charAt(jj);
  199. temp2 = fibdn[ii];
  200. if (temp1 == temp2) {
  201. return false;
  202. }
  203. }
  204. }
  205. return true;
  206. }
  207. /*
  208. *
  209. */
  210. function fucCheckNUM(NUM) {
  211. var i, j, strTemp;
  212. strTemp = "0123456789";
  213. if (NUM.length == 0)
  214. return false;
  215. for (i = 0; i < NUM.length; i++) {
  216. j = strTemp.indexOf(NUM.charAt(i));
  217. if (j == -1) {
  218. return false;
  219. }
  220. }
  221. return true;
  222. }
  223. /*
  224. *
  225. */
  226. function fucCheckLength(strTemp) {
  227. var i, sum;
  228. sum = 0;
  229. for (i = 0; i < strTemp.length; i++) {
  230. if ((strTemp.charCodeAt(i) >= 0) && (strTemp.charCodeAt(i) <= 255)) {
  231. sum = sum + 1;
  232. } else {
  233. sum = sum + 2;
  234. }
  235. }
  236. return sum;
  237. }
  238. /*
  239. *
  240. */
  241. function chkElements(name, errMsg, max_length, lengthMsg) {
  242. var el_name = eval("document.all." + name);
  243. var v = el_name.value;
  244. if (!chksafe(v)) {
  245. el_name.focus();
  246. alert(errMsg);
  247. return false;
  248. } else if (fucCheckLength(v) > max_length) {
  249. el_name.focus();
  250. alert(lengthMsg);
  251. return false;
  252. }
  253. return true;
  254. }
  255. /*
  256. * 校验空字符串
  257. */
  258. function checkNullStr(name, msg) {
  259. var el_name = eval("document.all." + name);
  260. if (Trim(el_name.value).length == 0) {
  261. alert(msg);
  262. el_name.focus();
  263. return false;
  264. }
  265. return true;
  266. }
  267. /*
  268. * 显示日期控jian
  269. */
  270. function GetDate(nText, para) {
  271. var v_url = para == "1" ? "./common/data.html" : "../../common/data.html";
  272. var reVal = window
  273. .showModalDialog(
  274. v_url,
  275. 'data',
  276. "status:no;center:yes;scroll:no;resizable:no;dialogWidth:255px;dialogHeight:260px");
  277. if (reVal != null) {
  278. var n = eval("document.all." + nText);
  279. n.value = reVal;
  280. }
  281. }
  282. /*
  283. * 按比例缩小图片
  284. */
  285. function DrawImage(ImgD, iwidth, iheight) {
  286. var flag = false;
  287. var image = new Image();
  288. image.src = ImgD.src;
  289. if (image.width > 0 && image.height > 0) {
  290. flag = true;
  291. if (image.width / image.height >= iwidth / iheight) {
  292. if (image.width > iwidth) {
  293. ImgD.width = iwidth;
  294. ImgD.height = (image.height * iwidth) / image.width;
  295. } else {
  296. ImgD.width = image.width;
  297. ImgD.height = image.height;
  298. }
  299. // ImgD.alt=image.width+"×"+image.height;
  300. } else {
  301. if (image.height > iheight) {
  302. ImgD.height = iheight;
  303. ImgD.width = (image.width * iheight) / image.height;
  304. } else {
  305. ImgD.width = image.width;
  306. ImgD.height = image.height;
  307. }
  308. // ImgD.alt=image.width+"×"+image.height;
  309. }
  310. }
  311. ImgD.style.visibility = "visible";
  312. }
  313. /*
  314. * 回车键转为Tab键
  315. */
  316. function enterTab() {
  317. if (event.keyCode == 13) {
  318. oElement = document.activeElement;
  319. if (oElement.tagName != "TEXTAREA" && oElement.type != "button")
  320. event.keyCode = 9;
  321. return;
  322. }
  323. }
  324. /*
  325. *
  326. */
  327. function objectEval(text) {
  328. text = text.replace(/\n/g, " ");
  329. text = text.replace(/\r/g, " ");
  330. if (text.match(/^\s*\{.*\}\s*$/)) {
  331. text = "[" + text + "]";
  332. }
  333. return eval(text)[0];
  334. }
  335. /*
  336. * 打开领导查询页面 action - 查询的Action method - 调用的方法 title - 标题message name -
  337. * 员工选择域的name
  338. */
  339. function openLeaderQuery(action, method, title, name) {
  340. openWin("../../common/selectStaff.jsp?action=" + action + "&method="
  341. + method + "&title=" + title + "&name=" + name,
  342. "public_leader_find_page", "400", "150");
  343. }
  344. /*
  345. * 第一行变色
  346. */
  347. function chgColor() {
  348. var v_table = document.all["PowerTable"];
  349. var v_row = v_table.rows[1];
  350. var len = v_row.cells.length;
  351. for (var i = 0; i < len; i++) {
  352. var v_cell = v_row.cells[i];
  353. v_cell.style.backgroundColor = "yellow";
  354. }
  355. }
  356. /*
  357. * 第一行变色
  358. */
  359. function chgColor2() {
  360. var v_table = document.all["PowerTable"];
  361. var rows_count = v_table.rows.length;
  362. var v_row, v_cell, temp_len, len;
  363. var rowspan = 0;
  364. // get rowspan
  365. if (v_table.rows.length > 1) {
  366. len = v_table.rows[1].cells.length;
  367. for (var r = 2; r < rows_count; r++) {
  368. v_row = v_table.rows[r];
  369. temp_len = v_row.cells.length;
  370. if (temp_len == len) {
  371. rowspan = r - 1;
  372. break;
  373. }
  374. }
  375. rowspan = (rowspan > 0) ? (rowspan + 1) : rows_count;
  376. for (var r = 1; r < rowspan; r++) {
  377. v_row = v_table.rows[r];
  378. for (var t = 0; t < v_row.cells.length; t++) {
  379. v_cell = v_row.cells[t];
  380. v_cell.style.backgroundColor = "yellow";
  381. }
  382. }
  383. }
  384. }
  385. /*
  386. * 添加页面载入后触发的shijian
  387. */
  388. function addLoadEvent(func) {
  389. var oldonload = window.onload;
  390. if (typeof(window.onload) != "function") {
  391. window.onload = func;
  392. } else {
  393. window.onload = function() {
  394. oldonload();
  395. func();
  396. }
  397. }
  398. }
  399. // adsName:名称,adsUrl:地址,sTime:时间(小时) add by wujie 2005.12.12
  400. function PopAds(adsName, adsUrl, sTime, number, w, h, s) {
  401. if (document.cookie.indexOf(adsName) == -1) {
  402. window.open(adsUrl, adsName);
  403. self.focus();
  404. var expireDate = new Date();
  405. var lefttime = 1000 * (3600 * sTime);
  406. expireDate.setTime(expireDate.getTime() + lefttime);
  407. document.cookie = adsName + "=yes" + "; expires="
  408. + expireDate.toGMTString() + ";";
  409. }
  410. openWin(adsUrl, number, w, h, s);
  411. }