home *** CD-ROM | disk | FTP | other *** search
- /* javascript functions go here */
-
- function getCookieVal(offset)
- {
- var endstr = document.cookie.indexOf(";", offset);
- if (endstr==-1) endstr = document.cookie.length;
- return unescape(document.cookie.substring(offset,endstr));
- }
-
- function GetCookie(name)
- {
- var arg = name+ "=";
- var alen = arg.length;
- var clen = document.cookie.length;
- var i = 0;
- while (i < clen)
- {
- var j = i + alen;
- if (document.cookie.substring(i,j) == arg)
- return (getCookieVal(j));
- i = document.cookie.indexOf(" ",i);
- if (i==-1) break;
- i = i + 1;
- }
- return 0;
- }
-
- function SetCookie(name, value)
- {
- var argv = SetCookie.arguments;
- var argc = SetCookie.arguments.length;
- var expires = (argc > 2) ? argv[2] : null;
- var path = (argc > 3) ? argv[3] : null;
- var domain = (argc > 4) ? argv[4] : null;
- var secure = (argc > 5) ? argv[5] : false;
-
- // domain = "";
- // path = null;
-
- cookie = name + "=" + escape(value)
- + ((expires == null) ? "" : ("; EXPIRES=" + expires.toGMTString()))
- + ((path == null) ? "" : ("; PATH="+path))
- + ((domain == null) ? "" : ("; DOMAIN="+domain))
- + ((secure == true) ? "; SECURE" : "");
- document.cookie = cookie;
- }
-
- function radio_value(radio)
- {
- for (i=0; i<radio.length; i++)
- if (radio[i].checked) return radio[i].value;
- return -1;
- }
-
- function set_radio_value(radio,value)
- {
- for (i=0; i<radio.length; i++)
- if (radio[i].value == value ) radio[i].checked = true;
- return -1;
- }
-
- function select_value(options)
- {
- for (i=0; i<options.length; i++)
- if (options[i].selected) return options[i].value;
- return -1;
- }
-
- function set_select_value(options,value)
- {
- for (i=0; i<options.length; i++)
- if (options[i].value == value) return options[i].selected = true;
- return -1;
- }
-
- function get_parameter(cookie, parname)
- {
- var arg = parname+ "=";
- var i = 0;
-
- while (i!=-1)
- {
- i = cookie.indexOf(arg,i);
- if (i==-1) return 0;
-
-
- if (i==0 || cookie.substring(i-1,i)=="&")
- {
- var end = cookie.indexOf("&",i);
- if (end==-1) end=cookie.length();
- return cookie.substring(i+arg.length,end);
- }
- }
- }
-
- function report_restore_params(username)
- {
- var cookie = GetCookie("PARAMS-report-"+username);
- if (cookie!=0)
- {
- document.myform.columnscount.value = get_parameter(cookie,"columnscount");
- document.myform.columnswidth.value = get_parameter(cookie,"columnswidth");
- // document.myform.day.value = get_parameter(cookie,"day");
- // document.myform.year.value = get_parameter(cookie,"year");
- // document.myform.hour.value = get_parameter(cookie,"hour");
- // document.myform.minute.value = get_parameter(cookie,"minute");
- document.myform.includecurrent.checked = get_parameter(cookie,"includecurrent")=="true";
- document.myform.percentage.checked = get_parameter(cookie,"percentage")=="true";
-
- set_radio_value(document.myform.direction,get_parameter(cookie,"direction"));
- set_radio_value(document.myform.sort,get_parameter(cookie,"sort"));
- set_radio_value(document.myform.format,get_parameter(cookie,"format"));
-
- set_select_value(document.myform.service,get_parameter(cookie,"service"));
- // set_select_value(document.myform.month,get_parameter(cookie,"month"));
- set_select_value(document.myform.interval,get_parameter(cookie,"interval"));
- }
- }
-
- function report_save_params(username)
- {
- var expDays = 30;
- var exp = new Date();
- exp.setTime(exp.getTime()+expDays*24*3600*1000);
-
- var params = "";
-
- params = params + "format=" + radio_value(document.myform.format) + "&";
- params = params + "columnscount=" + document.myform.columnscount.value + "&";
- params = params + "columnswidth=" + document.myform.columnswidth.value + "&";
- params = params + "interval=" +select_value(document.myform.interval) + "&";
- // params = params + "month=" + select_value(document.myform.month) + "&";
- // params = params + "day=" + document.myform.day.value + "&";
- // params = params + "year=" + document.myform.year.value + "&";
- // params = params + "hour=" + document.myform.hour.value + "&";
- // params = params + "minute=" + document.myform.minute.value + "&";
- params = params + "includecurrent=" + document.myform.includecurrent.checked + "&";
- params = params + "service=" + select_value(document.myform.service) + "&";
- params = params + "direction=" + radio_value(document.myform.direction) + "&";
- params = params + "sort=" + radio_value(document.myform.sort) + "&";
- params = params + "percentage=" + document.myform.percentage.checked + "&";
-
- SetCookie("PARAMS-report-"+username,params,exp,"/report/");
- }
-
- function report_checkclock(form)
- {
- if (form.interval.selectedIndex>=2)
- {
- form.hour.value="--"
- form.minute.value="--"
- }
- else
- if (form.hour.value=="--")
- {
- form.hour.value = ""
- form.minute.value = ""
- }
- }
-
- function report_suggeststart(form)
- {
- tm = new Date()
- var off = eval(form.columnscount.value) * eval(form.columnswidth.value)
- if (form.includecurrent.checked) off--
- if (form.interval.selectedIndex==0) // minutes
- {
- tm.setTime(tm.getTime()-off * 60000)
- } else
- if (form.interval.selectedIndex==1) // hours
- {
- tm.setTime(tm.getTime()-off * 3600000)
- } else
- {
- tm.setHours(0)
- tm.setMinutes(0)
- if (form.interval.selectedIndex==2) // days
- {
- tm.setTime(tm.getTime()-off * 3600 * 24 * 1000)
- } else
- if (form.interval.selectedIndex==3) // weeks
- {
- tm.setDate(tm.getDate() - tm.getDay() - 7 * off);
- } else
- if (form.interval.selectedIndex==4) // months
- {
- tm.setDate(1);
- tm.setMonth(tm.getMonth() - off )
- // defaultStatus = off / 12
- } else
- if (form.interval.selectedIndex==5) // years
- {
- tm.setMonth(0)
- tm.setDate(1);
- tm.setYear(tm.getYear()-off)
- } else
- {}
- }
- form.month.selectedIndex = tm.getMonth()
- form.year.value = tm.getYear()<200?tm.getYear()+1900:tm.getYear()
- form.day.value = tm.getDate()
-
- form.hour.value = tm.getHours()
- form.minute.value = tm.getMinutes()
-
- report_checkclock(form)
- }
-
- function report_slowinit(username)
- {
- var s = "";
- // if (document.myform.columnscount.value=="")
- {
- document.myform.columnscount.value="3"
- document.myform.interval.selectedIndex=2
- }
- report_restore_params(username);
- report_suggeststart(document.myform)
- }
-
- function report_init(user)
- {
- report_slowinit(user);
- cmd = "report_slowinit(\""+user+"\")";
- // setTimeout(cmd,1000)
- // setTimeout(cmd,2000)
- }
-
-
-
-
- // ***************************************************************************
- function chart_myrefresh()
- {
- if (document.myform.refresh.checked)
- {
- document.myform.submit();
- }
- else
- {
- setTimeout(chart_myrefresh,document.myform.refreshinterval.value*1000);
- }
- }
-
-
- function chart_restore_params(username)
- {
- return;
- // parameters are restored by daemon
- var cookie = GetCookie("PARAMS-chart-"+username);
- if (cookie!=0)
- {
- set_select_value(document.myform.IP1,get_parameter(cookie,"IP1"));
- set_select_value(document.myform.IP2,get_parameter(cookie,"IP2"));
- set_select_value(document.myform.IP3,get_parameter(cookie,"IP3"));
- set_select_value(document.myform.service,get_parameter(cookie,"service"));
- set_select_value(document.myform.resolution,get_parameter(cookie,"resolution"));
- document.myform.refresh.checked = get_parameter(cookie,"refresh")=="true";
- }
- }
-
- function chart_save_params(username)
- {
- var expDays = 30;
- var exp = new Date();
- exp.setTime(exp.getTime()+expDays*24*3600*1000);
-
- var params = "";
-
- params = params + "IP1=" + select_value(document.myform.IP1) + "&";
- params = params + "IP2=" + select_value(document.myform.IP2) + "&";
- params = params + "IP3=" + select_value(document.myform.IP3) + "&";
- params = params + "resolution=" + select_value(document.myform.resolution) + "&";
- params = params + "service=" + select_value(document.myform.service) + "&";
- params = params + "refresh=" + document.myform.refresh.checked + "&";
-
- SetCookie("PARAMS-chart-"+username,params,exp,"/chart/");
- }
-
- function chart_slowinit(username)
- {
- chart_restore_params(username);
- }
-
- function chart_init(user)
- {
- chart_slowinit(user);
- setTimeout(chart_myrefresh,document.myform.refreshinterval.value*1000);
- }
-
- // ***************************************************************************
- function barchart_restore_params(username)
- {
- return;
- // parameters are restored by daemon
- var cookie = GetCookie("PARAMS-bandwith-"+username);
- if (cookie!=0)
- {
- set_select_value(document.myform.service,get_parameter(cookie,"service"));
- set_select_value(document.myform.resolution,get_parameter(cookie,"resolution"));
- set_select_value(document.myform.selvalue,get_parameter(cookie,"selvalue"));
- document.myform.refresh.checked = get_parameter(cookie,"refresh")=="true";
- window.status = cookie;
- }
- }
-
- function barchart_save_params(username)
- {
- var expDays = 30;
- var exp = new Date();
- exp.setTime(exp.getTime()+expDays*24*3600*1000);
-
- var params = "";
-
- params = params + "resolution=" + select_value(document.myform.resolution) + "&";
- params = params + "service=" + select_value(document.myform.service) + "&";
- params = params + "selvalue=" + select_value(document.myform.selvalue) + "&";
- params = params + "refresh=" + document.myform.refresh.checked + "&";
-
- SetCookie("PARAMS-bandwith-"+username,params,exp,"/bandwith/");
- }
-
- function barchart_slowinit(username)
- {
- barchart_restore_params(username);
- }
-
- function barchart_myrefresh()
- {
- if (document.myform.refresh.checked)
- {
- document.myform.submit();
- }
- else
- {
- setTimeout(barchart_myrefresh,document.myform.refreshinterval.value*1000);
- }
- }
-
- function barchart_init(user)
- {
- barchart_slowinit(user);
- // setTimeout(barchart_myrefresh,5000);
- // window.status = document.myform.refreshinterval.value*1000;
- setTimeout(barchart_myrefresh,document.myform.refreshinterval.value*1000);
- }
-
- // ***************************************************************************
-
- function log_restore_params(username)
- {
- var cookie = GetCookie("PARAMS-log-"+username);
- if (cookie!=0)
- {
- set_radio_value(document.myform.log,get_parameter(cookie,"log"));
- document.myform.age.value = get_parameter(cookie,"age");
- document.myform.filter.value = get_parameter(cookie,"filter");
- document.myform.maxlines.value = get_parameter(cookie,"maxlines");
- document.myform.resolve.checked = get_parameter(cookie,"resolve")=="true";
- }
- }
-
- function log_save_params(username)
- {
- var expDays = 30;
- var exp = new Date();
- exp.setTime(exp.getTime()+expDays*24*3600*1000);
-
- var params = "";
-
- params = params + "log=" + radio_value(document.myform.log) + "&";
- params = params + "age=" + (document.myform.age.value) + "&";
- params = params + "filter=" + (document.myform.filter.value) + "&";
- params = params + "maxlines=" + (document.myform.maxlines.value) + "&";
- params = params + "resolve=" + document.myform.resolve.checked + "&";
-
- SetCookie("PARAMS-log-"+username,params,exp,"/log/");
- }
-
- function log_slowinit(username)
- {
- log_restore_params(username);
- }
-
- function log_init(user)
- {
- log_slowinit(user);
-
- // cmd = "report_slowinit(\""+user+"\")";
- // setTimeout(cmd,1000)
- // setTimeout(cmd,2000)
- }
-
- function ctest_init(user)
- {
- var expDays = 3;
- var exp = new Date();
- exp.setTime(exp.getTime()+expDays*24*3600*1000);
-
- window.status = "Init OK, user: "+user;
- SetCookie("TestCookie-"+user,"value3",exp,"/ctest/");
- // SetCookie("TestCookie-"+user,"value",exp,location.pathname,"localhost:81");
- document.all.clist.outerHTML = document.cookie;
- document.all.url.outerHTML = document.URL;
- }
-
-