User-friendly vchess presentation on index + some code cleaning
[vchess.git] / public / javascripts / utils / misc.js
1 // Source: https://www.quirksmode.org/js/cookies.html
2
3 function setCookie(name,value)
4 {
5 var date = new Date();
6 date.setTime(date.getTime()+(183*24*60*60*1000)); //6 months
7 var expires = "; expires="+date.toGMTString();
8 document.cookie = name+"="+value+expires+"; path=/";
9 }
10
11 function getCookie(name) {
12 var nameEQ = name + "=";
13 var ca = document.cookie.split(';');
14 for (var i=0;i < ca.length;i++)
15 {
16 var c = ca[i];
17 while (c.charAt(0)==' ')
18 c = c.substring(1,c.length);
19 if (c.indexOf(nameEQ) == 0)
20 return c.substring(nameEQ.length,c.length);
21 }
22 return null;
23 }
24
25 function getRandString()
26 {
27 // Random enough (for socket and game IDs)
28 return (Date.now().toString(36) + Math.random().toString(36).substr(2, 7))
29 .toUpperCase();
30 }