home *** CD-ROM | disk | FTP | other *** search
/ PC World 2003 July & August / PCWorld_2003-07-08_cd.bin / Software / Vyzkuste / kerio / knm2-en-win.exe / Disk1 / data1.cab / WWW / script.js < prev    next >
Encoding:
JavaScript  |  2003-05-15  |  11.6 KB  |  407 lines

  1. /* javascript functions go here */
  2.  
  3. function getCookieVal(offset)
  4. {
  5.     var endstr = document.cookie.indexOf(";", offset);
  6.     if (endstr==-1) endstr = document.cookie.length;
  7.     return unescape(document.cookie.substring(offset,endstr));
  8. }
  9.  
  10. function GetCookie(name)
  11. {
  12.     var arg = name+ "=";
  13.     var alen = arg.length;
  14.     var clen = document.cookie.length;
  15.     var i = 0;
  16.     while (i < clen)
  17.     {
  18.              var j = i + alen;
  19.         if (document.cookie.substring(i,j) == arg)
  20.             return (getCookieVal(j));
  21.         i = document.cookie.indexOf(" ",i);
  22.         if (i==-1) break;
  23.         i = i + 1;
  24.     }
  25.     return 0;
  26. }
  27.  
  28. function SetCookie(name, value)
  29. {
  30.      var argv = SetCookie.arguments;
  31.     var argc = SetCookie.arguments.length;
  32.     var expires = (argc > 2) ? argv[2] : null; 
  33.     var path = (argc > 3) ? argv[3] : null; 
  34.     var domain = (argc > 4) ? argv[4] : null; 
  35.     var secure = (argc > 5) ? argv[5] : false; 
  36.  
  37. //    domain = "";
  38. //    path = null;
  39.     
  40.     cookie = name + "=" + escape(value) 
  41.         + ((expires == null) ? "" : ("; EXPIRES=" + expires.toGMTString()))
  42.         + ((path == null) ? "" : ("; PATH="+path))
  43.         + ((domain == null) ? "" : ("; DOMAIN="+domain))
  44.         + ((secure == true) ? "; SECURE" : "");
  45.         document.cookie = cookie;
  46. }
  47.  
  48. function radio_value(radio)
  49. {
  50.      for (i=0; i<radio.length; i++)
  51.         if (radio[i].checked) return radio[i].value;
  52.     return -1;
  53. }
  54.  
  55. function set_radio_value(radio,value)
  56. {
  57.      for (i=0; i<radio.length; i++)
  58.         if (radio[i].value == value ) radio[i].checked = true;
  59.     return -1;
  60. }
  61.  
  62. function select_value(options)
  63. {
  64.      for (i=0; i<options.length; i++)
  65.         if (options[i].selected) return options[i].value;
  66.     return -1;
  67. }
  68.  
  69. function set_select_value(options,value)
  70. {
  71.      for (i=0; i<options.length; i++)
  72.         if (options[i].value == value) return options[i].selected = true;
  73.     return -1;
  74. }
  75.  
  76. function get_parameter(cookie, parname)
  77. {
  78.     var arg = parname+ "=";
  79.     var i = 0;
  80.  
  81.     while (i!=-1)
  82.     {
  83.         i = cookie.indexOf(arg,i);
  84.         if (i==-1) return 0;
  85.  
  86.  
  87.         if (i==0 || cookie.substring(i-1,i)=="&")
  88.         {
  89.                     var end = cookie.indexOf("&",i);
  90.             if (end==-1) end=cookie.length();
  91.             return cookie.substring(i+arg.length,end);
  92.         }
  93.     }
  94. }
  95.  
  96. function report_restore_params(username)
  97. {
  98.     var cookie = GetCookie("PARAMS-report-"+username);
  99.     if (cookie!=0)
  100.     {
  101.         document.myform.columnscount.value = get_parameter(cookie,"columnscount");
  102.         document.myform.columnswidth.value = get_parameter(cookie,"columnswidth");
  103. //        document.myform.day.value = get_parameter(cookie,"day");
  104. //        document.myform.year.value = get_parameter(cookie,"year");
  105. //        document.myform.hour.value = get_parameter(cookie,"hour");
  106. //        document.myform.minute.value = get_parameter(cookie,"minute");
  107.         document.myform.includecurrent.checked = get_parameter(cookie,"includecurrent")=="true";
  108.         document.myform.percentage.checked = get_parameter(cookie,"percentage")=="true";
  109.  
  110.         set_radio_value(document.myform.direction,get_parameter(cookie,"direction"));
  111.         set_radio_value(document.myform.sort,get_parameter(cookie,"sort"));
  112.         set_radio_value(document.myform.format,get_parameter(cookie,"format"));
  113.  
  114.         set_select_value(document.myform.service,get_parameter(cookie,"service"));
  115. //        set_select_value(document.myform.month,get_parameter(cookie,"month"));
  116.         set_select_value(document.myform.interval,get_parameter(cookie,"interval"));
  117.     }
  118. }
  119.  
  120. function report_save_params(username)
  121. {
  122.     var expDays = 30;
  123.      var exp = new Date();
  124.     exp.setTime(exp.getTime()+expDays*24*3600*1000);
  125.  
  126.     var params = "";
  127.  
  128.     params = params + "format=" + radio_value(document.myform.format) + "&";
  129.     params = params + "columnscount=" + document.myform.columnscount.value + "&";
  130.     params = params + "columnswidth=" + document.myform.columnswidth.value + "&";
  131.     params = params + "interval=" +select_value(document.myform.interval) + "&";
  132. //    params = params + "month=" + select_value(document.myform.month) + "&";
  133. //    params = params + "day=" + document.myform.day.value + "&";
  134. //    params = params + "year=" + document.myform.year.value + "&";
  135. //    params = params + "hour=" + document.myform.hour.value + "&";
  136. //    params = params + "minute=" + document.myform.minute.value + "&";
  137.     params = params + "includecurrent=" + document.myform.includecurrent.checked + "&";
  138.     params = params + "service=" + select_value(document.myform.service) + "&";
  139.     params = params + "direction=" + radio_value(document.myform.direction) + "&";
  140.     params = params + "sort=" + radio_value(document.myform.sort) + "&";
  141.     params = params + "percentage=" + document.myform.percentage.checked + "&";
  142.  
  143.     SetCookie("PARAMS-report-"+username,params,exp,"/report/");
  144. }
  145.         
  146. function report_checkclock(form)     
  147. {
  148.     if (form.interval.selectedIndex>=2) 
  149.         {
  150.             form.hour.value="--"  
  151.             form.minute.value="--"  
  152.     }
  153.     else
  154.     if (form.hour.value=="--") 
  155.     {
  156.         form.hour.value = ""
  157.         form.minute.value = ""
  158.     }
  159. }
  160.  
  161. function report_suggeststart(form)
  162. {
  163.     tm = new Date()
  164.     var off = eval(form.columnscount.value) * eval(form.columnswidth.value)
  165.     if (form.includecurrent.checked) off--
  166.     if (form.interval.selectedIndex==0) // minutes 
  167.     {
  168.           tm.setTime(tm.getTime()-off * 60000)
  169.     } else 
  170.     if (form.interval.selectedIndex==1) // hours
  171.     {
  172.           tm.setTime(tm.getTime()-off * 3600000)
  173.     } else 
  174.     {
  175.         tm.setHours(0)
  176.         tm.setMinutes(0)
  177.         if (form.interval.selectedIndex==2) // days
  178.         {
  179.               tm.setTime(tm.getTime()-off * 3600 * 24 * 1000)
  180.         } else 
  181.         if (form.interval.selectedIndex==3) // weeks
  182.         {
  183.           tm.setDate(tm.getDate() - tm.getDay() - 7 * off);
  184.         } else 
  185.         if (form.interval.selectedIndex==4) // months
  186.         {
  187.           tm.setDate(1);
  188.           tm.setMonth(tm.getMonth() - off )
  189. //          defaultStatus = off / 12
  190.         } else 
  191.         if (form.interval.selectedIndex==5) // years
  192.         {
  193.                    tm.setMonth(0)
  194.           tm.setDate(1);
  195.               tm.setYear(tm.getYear()-off)
  196.         } else 
  197.         {}
  198.         }
  199.     form.month.selectedIndex = tm.getMonth()
  200.     form.year.value = tm.getYear()<200?tm.getYear()+1900:tm.getYear()
  201.     form.day.value = tm.getDate()
  202.  
  203.     form.hour.value = tm.getHours()
  204.     form.minute.value = tm.getMinutes()
  205.  
  206.     report_checkclock(form)
  207. }
  208.  
  209. function report_slowinit(username)
  210. {
  211.     var s = "";
  212. //    if (document.myform.columnscount.value=="") 
  213.     {
  214.         document.myform.columnscount.value="3"
  215.         document.myform.interval.selectedIndex=2
  216.     }
  217.     report_restore_params(username);
  218.     report_suggeststart(document.myform)
  219. }
  220.  
  221. function report_init(user)
  222. {
  223.     report_slowinit(user);
  224.         cmd = "report_slowinit(\""+user+"\")";
  225. //    setTimeout(cmd,1000)
  226. //    setTimeout(cmd,2000)
  227. }
  228.  
  229.  
  230.  
  231.  
  232. // ***************************************************************************
  233. function chart_myrefresh()
  234. {
  235.     if (document.myform.refresh.checked)
  236.     {
  237.         document.myform.submit();
  238.     }
  239.     else
  240.     {
  241.         setTimeout(chart_myrefresh,document.myform.refreshinterval.value*1000);
  242.     }
  243. }
  244.  
  245.  
  246. function chart_restore_params(username)
  247. {
  248.     return;
  249.     // parameters are restored by daemon
  250.     var cookie = GetCookie("PARAMS-chart-"+username);
  251.     if (cookie!=0)
  252.     {
  253.         set_select_value(document.myform.IP1,get_parameter(cookie,"IP1"));
  254.         set_select_value(document.myform.IP2,get_parameter(cookie,"IP2"));
  255.         set_select_value(document.myform.IP3,get_parameter(cookie,"IP3"));
  256.         set_select_value(document.myform.service,get_parameter(cookie,"service"));
  257.         set_select_value(document.myform.resolution,get_parameter(cookie,"resolution"));
  258.         document.myform.refresh.checked = get_parameter(cookie,"refresh")=="true";
  259.     }
  260. }
  261.  
  262. function chart_save_params(username)
  263. {
  264.     var expDays = 30;
  265.      var exp = new Date();
  266.     exp.setTime(exp.getTime()+expDays*24*3600*1000);
  267.  
  268.     var params = "";
  269.  
  270.     params = params + "IP1=" + select_value(document.myform.IP1) + "&";
  271.     params = params + "IP2=" + select_value(document.myform.IP2) + "&";
  272.     params = params + "IP3=" + select_value(document.myform.IP3) + "&";
  273.     params = params + "resolution=" + select_value(document.myform.resolution) + "&";
  274.     params = params + "service=" + select_value(document.myform.service) + "&";
  275.     params = params + "refresh=" + document.myform.refresh.checked + "&";
  276.  
  277.     SetCookie("PARAMS-chart-"+username,params,exp,"/chart/");
  278. }
  279.         
  280. function chart_slowinit(username)
  281. {
  282.     chart_restore_params(username);
  283. }
  284.  
  285. function chart_init(user)
  286. {
  287.     chart_slowinit(user);
  288.     setTimeout(chart_myrefresh,document.myform.refreshinterval.value*1000);
  289. }
  290.  
  291. // ***************************************************************************
  292. function barchart_restore_params(username)
  293. {
  294.     return;
  295.     // parameters are restored by daemon
  296.     var cookie = GetCookie("PARAMS-bandwith-"+username);
  297.     if (cookie!=0)
  298.     {
  299.         set_select_value(document.myform.service,get_parameter(cookie,"service"));
  300.         set_select_value(document.myform.resolution,get_parameter(cookie,"resolution"));
  301.         set_select_value(document.myform.selvalue,get_parameter(cookie,"selvalue"));
  302.         document.myform.refresh.checked = get_parameter(cookie,"refresh")=="true";
  303.         window.status = cookie;
  304.     }
  305. }
  306.  
  307. function barchart_save_params(username)
  308. {
  309.     var expDays = 30;
  310.      var exp = new Date();
  311.     exp.setTime(exp.getTime()+expDays*24*3600*1000);
  312.  
  313.     var params = "";
  314.  
  315.     params = params + "resolution=" + select_value(document.myform.resolution) + "&";
  316.     params = params + "service=" + select_value(document.myform.service) + "&";
  317.     params = params + "selvalue=" + select_value(document.myform.selvalue) + "&";
  318.     params = params + "refresh=" + document.myform.refresh.checked + "&";
  319.  
  320.     SetCookie("PARAMS-bandwith-"+username,params,exp,"/bandwith/");
  321. }
  322.         
  323. function barchart_slowinit(username)
  324. {
  325.     barchart_restore_params(username);
  326. }
  327.  
  328. function barchart_myrefresh()
  329. {
  330.     if (document.myform.refresh.checked)
  331.     {
  332.         document.myform.submit();
  333.     }
  334.     else
  335.     {
  336.         setTimeout(barchart_myrefresh,document.myform.refreshinterval.value*1000);
  337.     }
  338. }
  339.  
  340. function barchart_init(user)
  341. {
  342.     barchart_slowinit(user);
  343. //    setTimeout(barchart_myrefresh,5000);
  344. //      window.status = document.myform.refreshinterval.value*1000;
  345.     setTimeout(barchart_myrefresh,document.myform.refreshinterval.value*1000);
  346. }
  347.  
  348. // ***************************************************************************
  349.  
  350. function log_restore_params(username)
  351. {
  352.     var cookie = GetCookie("PARAMS-log-"+username);
  353.     if (cookie!=0)
  354.     {
  355.         set_radio_value(document.myform.log,get_parameter(cookie,"log"));
  356.         document.myform.age.value = get_parameter(cookie,"age");
  357.         document.myform.filter.value = get_parameter(cookie,"filter");
  358.         document.myform.maxlines.value = get_parameter(cookie,"maxlines");
  359.         document.myform.resolve.checked = get_parameter(cookie,"resolve")=="true";
  360.     }
  361. }
  362.  
  363. function log_save_params(username)
  364. {
  365.     var expDays = 30;
  366.      var exp = new Date();
  367.     exp.setTime(exp.getTime()+expDays*24*3600*1000);
  368.  
  369.     var params = "";
  370.  
  371.     params = params + "log=" + radio_value(document.myform.log) + "&";
  372.     params = params + "age=" + (document.myform.age.value) + "&";
  373.     params = params + "filter=" + (document.myform.filter.value) + "&";
  374.     params = params + "maxlines=" + (document.myform.maxlines.value) + "&";
  375.     params = params + "resolve=" + document.myform.resolve.checked + "&";
  376.  
  377.     SetCookie("PARAMS-log-"+username,params,exp,"/log/");
  378. }
  379.         
  380. function log_slowinit(username)
  381. {
  382.     log_restore_params(username);
  383. }
  384.  
  385. function log_init(user)
  386. {
  387.     log_slowinit(user);
  388.  
  389. //      cmd = "report_slowinit(\""+user+"\")";
  390. //    setTimeout(cmd,1000)
  391. //    setTimeout(cmd,2000)
  392. }
  393.  
  394. function ctest_init(user)
  395. {
  396.     var expDays = 3;
  397.      var exp = new Date();
  398.     exp.setTime(exp.getTime()+expDays*24*3600*1000);
  399.  
  400.     window.status = "Init OK, user: "+user;
  401.     SetCookie("TestCookie-"+user,"value3",exp,"/ctest/");
  402. //    SetCookie("TestCookie-"+user,"value",exp,location.pathname,"localhost:81");
  403.     document.all.clist.outerHTML = document.cookie;
  404.     document.all.url.outerHTML = document.URL;
  405. }
  406.  
  407.