File size: 2,411 Bytes
1e40c2a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
function $_GET(q) { 
    var s = window.location.search; 
    var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i'); 
    return (s=s.replace(/^\?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined; 
}

function getXmlHttp() {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
	return new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
	return new ActiveXObject("Microsoft.XMLHTTP");
    }
}

function scoreScreenOnLoad() {
    var sessionRef = $_GET('tempRef');
    
    var xmlhttp = getXmlHttp();
    xmlhttp.onreadystatechange=function()
    {
	if (xmlhttp.readyState==4 && xmlhttp.status==200)
	{
	    var response = jsonParse(xmlhttp.responseText),
	    ranked = false;
	    output = '<br/><br/><div class="resTitle">GOOD GAME!</div><br/><br/>';

	    output += '<table class="resultsTable">';

	    output += '<tr><td class="resultsLeft">Score:</td><td class="resultsRight">' + response.userScore + '</td></tr>';
	    if (response.dailyRank > 0) {
		output += '<tr><td class="resultsLeft">Daily Rank:</td><td class="resultsRight">'
		    + response.dailyRank + '</td></tr>';
		ranked = true;
		
	    }
	    if (response.totalRank > 0) {
		output += '<tr><td class="resultsLeft">Total Rank:</td><td class="resultsRight">'
		    + response.totalRank + '</td></tr>';
		ranked = true;
	    }
	    output += '</table><br/><br/><br/>';

	    document.getElementById("scoreDiv").innerHTML = output;

	    // if ranked, prompt for a name
	    if (ranked) {
		document.getElementById("applyNameDiv").setAttribute('class', 'applyNameVisible');
	    }
	}
    }

    xmlhttp.open("POST", "/score/postGame?tempRef="+sessionRef, true);
    xmlhttp.send();
}

function nameKeyDown(e) {
    var keycode;
    if (window.event) { //IE
	keycode = e.keyCode;
    } else {
	keycode = e.which;
    }
    if (keycode === 13) { // if the enter key
	applyName();
    }
}

function applyName() {
    var sessionRef = $_GET('tempRef');
    var name = document.getElementById("nameInput").value;

    if (name.length < 1 || sessionRef.length < 1) return;

    document.getElementById("applyNameDiv").setAttribute('class', 'applyNameHidden');

    var xmlhttp = getXmlHttp();
    xmlhttp.open("POST", "/score/apply?tempRef="+sessionRef+"&name="+name, true);
    xmlhttp.send();

    return false;
}

function trySubmitName() {
    applyName();
}