esco button moved inside php page
[brisk.git] / web / room.js
1 /* 
2    data = [ [ flags, name ],  ... ]
3    
4 */
5
6 function state_add(flags)
7 {
8     var content = "";
9     var st, name = "";
10     var tit = "";
11
12     if ((flags & 0xf00) != 0) {
13         st = flags & 0xf00;
14         switch (st) {
15         case 0x100:
16             name = "st_pau.png";
17             tit = "sono in pausa";
18             break;
19         case 0x200:
20             name = "st_out.png";
21             tit = "sono fuori";
22             break;
23         case 0x300:
24             name = "st_dog.png";
25             tit = "sono a spasso col cane";
26             break;
27         case 0x400:
28             name = "st_eat.png";
29             tit = "sto mangiando";
30             break;
31         case 0x500:
32             name = "st_wrk.png";
33             tit = "sono a lavoro";
34             break;
35         case 0x600:
36             name = "st_smk.png";
37             tit = "sto fumando una sigaretta (e facendomi venire il cancro)";
38             break;
39         case 0x700:
40             name = "st_eye.png";
41             tit = "sono presente!";
42             break;
43         default:
44             break;
45         }
46         if (name != "") {
47             content += '<img title="'+tit+'" class="unbo" src="img/'+name+'">';
48         }
49     }
50
51     return content;
52 }
53
54 function j_stand_cont(data)
55 {
56     var i;
57     var content;
58     var st, name = "";
59
60     content = '<table cols="'+(data.length < 4 ? data.length : 4)+'" class="table_standup">';
61     for (i = 0 ; i < data.length ; i++) {
62         if ((i % 4) == 0)
63             content += '<tr>';
64         content += '<td class="room_standup">';
65         if (data[i][0] & 0x01)
66             content += '<b>';
67
68         if (data[i][0] & 0x02)
69             content += '<i>';
70
71         content += data[i][1];
72         
73         if (data[i][0] & 0x02)
74             content += '</i>';
75
76         if (data[i][0] & 0x01)
77             content += '</b>';
78
79         content += state_add(data[i][0]);
80         content += '</td>';
81
82         if ((i % 4) == 3)
83             content += '</tr>';
84     }
85     content += '</tr>';
86
87     $("standup").innerHTML = content;
88
89     // $("esco").innerHTML =  '<input class="button" name="logout" value="Esco." onclick="esco_cb();" type="button">';
90 }
91
92 function esco_cb() {
93     window.onbeforeunload = null; 
94     window.onunload = null; 
95     // nonunload = true; 
96     act_logout();
97  };
98
99
100
101 function j_tab_cont(table_idx, data)
102 {
103     var i;
104     var content = '';
105
106     for (i = 0 ; i < data.length ; i++) {
107         if (data[i][0] & 0x01)
108             content += '<b>';
109
110         if (data[i][0] & 0x02)
111             content += '<i>';
112
113         content += data[i][1];
114         
115         if (data[i][0] & 0x02)
116             content += '</i>';
117
118         if (data[i][0] & 0x01)
119             content += '</b>';
120         content += state_add(data[i][0]);
121
122         content += '<br>';
123     }
124     $("table"+table_idx).innerHTML = content;
125 }
126
127 function j_tab_act_cont(idx, act)
128 {
129     if (act == 'sit') {
130         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xhenter'+idx+'"  value="Mi siedo." onclick="act_sitdown('+idx+');">';
131     }
132     else if (act == 'sitreser') {
133         // <img class="nobo" title="tavolo riservato agli utenti registrati" style="display: inline; margin-right: 80px;" src="img/okauth.png">
134         $("table_act"+idx).innerHTML = '<input type="button" style="background-repeat: no-repeat; background-position: center; background-image: url(\'img/okauth.png\');" class="button" name="xhenter'+idx+'"  value="Mi siedo." onclick="act_sitdown('+idx+');">';
135     }
136     else if (act == 'wake') {
137         $("table_act"+idx).innerHTML = '<input type="button" class="button" name="xwakeup"  value="Mi alzo." onclick="act_wakeup();">';
138     }
139     else if (act == 'reserved') {
140         $("table_act"+idx).innerHTML = '<img class="nobo" title="tavolo riservato agli utenti registrati" style="margin-right: 20px;" src="img/onlyauth.png">';
141     }
142     else {
143         $("table_act"+idx).innerHTML = '';
144     }
145 }
146
147 function j_login_manager(form)
148 {
149     var token;
150
151     if (form.elements['passid'].value == '')
152         return (true);
153
154     else {
155         // console.log("richiesta token");
156         /* richiede token */
157         token = server_request('mesg', 'getchallenge', 'cli_name', encodeURIComponent(form.elements['nameid'].value));
158         tokens = token.split('|');
159         
160         // console.log('XX token: '+token);
161         // console.log(tokens);
162         if (token == null)
163             return (false);
164
165         token = calcMD5(tokens[1]+calcMD5(form.elements['passid'].value));
166         
167         form.elements['passid_private'].value = token;
168         form.elements['passid'].value = ""; // FIXME da sost con la stessa len di A
169
170         return (true);
171     }
172     
173     return (false);
174 }
175
176 function formtext_hilite(obj)
177 {
178     obj.className = 'input_text';
179     addEvent(obj, "focus", function () { this.className = 'input_text_hi'; });
180     addEvent(obj, "blur",  function () { this.className = 'input_text'; });
181 }
182
183 function formsub_hilite(obj)
184 {
185     obj.className = 'input_sub';
186     addEvent(obj, "focus", function () { this.className = 'input_sub_hi'; });
187     addEvent(obj, "blur",  function () { this.className = 'input_sub'; });
188 }
189
190 function login_formtext_hilite()
191 {
192     formtext_hilite($("nameid"));
193     formtext_hilite($("passid"));
194     formsub_hilite($("sub"));
195 }
196
197 function login_init()
198 {
199     menu_init();
200     login_formtext_hilite();
201 }
202
203 function warrant_formtext_hilite()
204 {
205     formtext_hilite($("nameid"));
206     formtext_hilite($("emailid"));
207     formsub_hilite($("subid"));
208     formsub_hilite($("cloid"));
209 }
210
211
212 function j_check_email(email)
213 {
214     if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
215         return (true);
216     return (false);
217 }
218
219 function j_authbox(form)
220 {
221     var no; 
222
223     if (form.elements['realsub'].value == "chiudi") {
224         $('authbox').style.visibility = "hidden";
225         return (false);
226     }
227
228     if (form.elements['name'].value == '' || j_check_email(form.elements['email'].value) == false)
229         no = new notify(gst, "<br>I campi user e/o e-mail non sono validi;</br> correggeteli per favore.", 1, "chiudi", 280, 100); 
230     else {
231         // submit the request
232         token = server_request('mesg', 'warranty', 
233                                'cli_name', encodeURIComponent(form.elements['name'].value),
234                                'cli_email', encodeURIComponent(form.elements['email'].value) );
235         if (token == "1") {
236             $('authbox').style.visibility = "hidden";
237             form.elements['name'].value = "";
238             form.elements['email'].value = "";
239             return (false);
240         }
241     }
242
243     return (false);
244 }
245
246 function authbox(w, h)
247 {
248     var box;
249
250     box = $('authbox');
251
252     box.style.zIndex = 200;
253     box.style.width  = w+"px";
254     box.style.marginLeft  = -parseInt(w/2)+"px";
255     box.style.height = h+"px";
256     box.style.top = parseInt((document.body.clientHeight - h) / 2) + document.body.scrollTop;
257
258     warrant_formtext_hilite();
259
260     box.style.visibility = "visible";
261     $("nameid").focus();
262 }