-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscripts.js
58 lines (54 loc) · 1.49 KB
/
scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function showMenu()
{
var username = getCookie('username');
if(username)
{
if(username == 'admin')
{
document.getElementById('admin').style.display = '';
document.getElementById('signout').style.display = '';
}
else
{
document.getElementById('myaccount').style.display = '';
document.getElementById('signout').style.display = '';
}
}
else
{
document.getElementById('signin').style.display = '';
document.getElementById('register').style.display = '';
}
}
function signin(username)
{
createCookie("username", username, 0);
redirect("index.php");
}
function signout()
{
deleteCookie("username");
}
function createCookie(name, value, expires) {
var cookie = name + "=" + escape(value) + ";";
if (expires == -1) {
expires = new Date(new Date().getTime() + parseInt(expires) * 1000 * 60 * 60 * 24);
cookie += "expires=" + expires.toGMTString() + ";";
}
cookie += "path=/;";
document.cookie = cookie;
}
function deleteCookie(name) {
// If the cookie exists
if (getCookie(name))
createCookie(name, "", -1);
}
function getCookie(name) {
var regexp = new RegExp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g");
var result = regexp.exec(document.cookie);
return (result === null) ? null : result[1];
}
function redirect(page)
{
window.location = page;
}