OSDN Git Service

modified comments
[opengatem/opengatem.git] / html / macchk.js
1 //<!--
2 // Module to open/close the network
3 // used in macchk.html in lang(ja/en) directory
4 var seconds;
5 var status;
6 var macaddr;
7 var httpObj;
8 var cginame;
9 var timeout;
10
11 // create object of XMLHttpRequest
12 function createXMLHttpRequest() {
13   try { return new ActiveXObject("Msxml2.XMLHTTP");    } catch(e) {}
14   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {}
15   try { return new XMLHttpRequest();                   } catch(e) {}
16   return null;
17 }
18
19 // send AJAX request for status(=open/close)
20 // timer is started at open-request and stopped at close-request.
21 function ajaxRequest(status){
22   if((httpObj=createXMLHttpRequest())!=null){
23     try{  
24       httpObj.open('post', cginame ,false);
25       httpObj.setRequestHeader('content-type',
26         'application/x-www-form-urlencoded,charset=utf-8');
27       httpObj.send('status='+status+'&macaddr='+macaddr);
28       if(status=='open') startTimer();
29       else stopTimer();
30     }catch(e){ }
31   }
32 }
33
34 // send 'open' AJAX request
35 function openNet(){
36   document.checkform.open.disabled=true;
37   document.checkform.close.disabled=false;
38   getMacAddr();
39   document.regform.macaddr.value=macaddr;
40   ajaxRequest('open');
41 }
42
43 // send 'close' AJAX request
44 function closeNet(){
45   document.checkform.open.disabled=false;
46   document.checkform.close.disabled=true;
47   ajaxRequest('close');
48 }
49
50 // start timer
51 function startTimer(){
52   seconds=timeout;
53   setTimeout('onTimeout()', 1000);
54 }
55
56 // stop timer
57 function stopTimer(){
58   seconds=0;
59 }
60
61 // decrement counter and show the value on page
62 // if the counter reachs zero, close-request is sent automatically
63 function onTimeout(){
64   document.checkform.timer.value=seconds;
65   seconds--;
66   if(seconds<0) closeNet();
67   else setTimeout('onTimeout()', 1000);
68 }
69
70 // get the checked mac address in the list 
71 function getMacAddr(){
72   if(document.checkform.macaddr==undefined) macaddr='';
73   else if(document.checkform.macaddr.length==undefined)
74     macaddr=document.checkform.macaddr.value;
75   else{
76     for(var i=0; i<document.checkform.macaddr.length; i++){
77       if(document.checkform.macaddr[i].checked){
78         macaddr=document.checkform.macaddr[i].value;
79       }
80     }
81   }
82 }
83
84 // set parameters at starting of page(<body onload=..>)
85 function setParameters(cginameArg, timeoutArg){
86   cginame=cginameArg;
87   timeout=timeoutArg;
88 }
89 //-->