Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/content/js/global.js
blob: 489f6ab21d0204890784d1304262e66e85a3b5d0 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
 * Functions that are common in all lessons 
 * 
 */

var flag_start = 0,i,j,flag;

function linkHome(){
        pth = 'http://localhost:8008/content/index.html';
        window.location = pth;
};
function editreturn(){
        $('<div id="temp"/>')
            .load('http://localhost:8008/cgi-bin/return.py',
            function(responseTxt,status,xhr){
                window.location = responseTxt
        });
}
function linkEnglish(){
        url = window.location+"";
        grade = url.charAt(url.length-1);
        last = url.charAt(url.length-3)+url.charAt(url.length-2)+grade;
        pth = 'http://localhost:8008/content/English';
        pos = url.indexOf('?F');
        if (pos<0){
            window.location = pth + '/index.html';
        }else{
            tpth = pth + '/p'+grade+'.html'+last;
            window.location = tpth;
        }
};
function linkMathematics(){
        url = window.location+"";
        grade = url.charAt(url.length-1);
        last = url.charAt(url.length-3)+url.charAt(url.length-2)+grade;
        pth = 'http://localhost:8008/content/Mathematics';
        pos = url.indexOf('?F');
        if (pos<0){
            window.location = 'content/Mathematics/index.html'         
        }else{
            tpth = pth + '/p'+grade+'.html'+last;
            window.location = tpth;
        }
};
function goback(){
        url = window.location+"";
        levels = url.split('/');
        last = levels.pop();
        levels.pop()
        levels.push(last);
        newurl = levels.join('/');
	window.location = newurl
}
function apply(){
        items = (window.location+"").split('/');
        score = '70';
        subject = items[4];
        milestone = items[5];
        activity = items[6];
        $('#content').load('http://localhost:8008/cgi-bin/results.py',{
              'score':score, 
              'subject':subject,
              'milestone':milestone,
              'activity':activity 
          },function(responseText, status, xhr){
            if (responseText==1){ goback();
            } else if (responseText==2){ gobackOne();
            } else if (responseText==3){ gobackTwo();
            };
        });
}
function quit(){
        window.close();
}
function edit(){
        openfile = window.location
        $().load('http://localhost:8008/cgi-bin/setOpenFile.py',
           {'filename':'openfile'},
        function(responseText, status, xhr){});
        window.location = 'http://localhost:8008/contentedit.html';
}
//enable or disable the control buttons
function controlButtonDisplay(button,status){ 
	var opacity;
	if(status === 'enabled'){
		opacity = 1;
		cursor = 'pointer';
	}else{
		opacity = .3;
		cursor = 'default';
	}
	var buttonCss = {
			'opacity':opacity,
			'cursor':cursor
	};
	$('#'+button).css(buttonCss);		
}
//generate a random numbers between two limits
function genRand( lower, upper ){
	  return Math.floor(Math.random() * (upper - lower + 1) + lower);  
};

/*
	Function to generate a set of random numbers and assign it to a variable supplied
	@params: randVar - > The variable in which the random numbers to be stored
			 lower -> lower number
			 upper -> upper number
	include lower and upper limit
	Currently it generates numbers betweem 0-upper (exclude upper)
*/
function shuffleNumbers(randVar,lower,upper)  {
	var total_nums = upper-lower;
	randVar[0] = genRand(0,total_nums-1); 
	for(i= 1; i < total_nums; i++){
			do{
				flag = 0;
				randVar[i] = genRand(0,total_nums-1); 
				for(j=0; j<i; j++){
					if(randVar[i] === randVar[j]){
						flag++;
					}
				}
			}while(flag != 0 );  //end of do while loop	
		}
}