-
Notifications
You must be signed in to change notification settings - Fork 0
/
global.js
185 lines (152 loc) · 3.94 KB
/
global.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/";
}
function deleteCookie ( cookie_name )
{
createCookie(cookie_name,"",-1);
}
function getDatetime(){
var startDate = '';
var date = new Date(); // 06/21/2013 03:39:50 PM
var years = date.getFullYear();
var days = date.getDate();
var hours = date.getHours();
var minutes = date.getMinutes();
var month = date.getMonth() + 1;
var suffix = 'AM';
if (hours >= 12)
{
suffix = 'PM';
hours = hours - 12;
}
if (hours == 0)
{
hours = 12;
}
if (minutes < 10)
minutes = '0' + minutes;
if (month < 10)
month = '0' + month;
if (days < 10)
days = '0' + days;
if (hours < 10)
hours = '0' + hours;
startDate = month+'/'+days+'/'+years+' '+hours+':'+minutes+':00'+' '+suffix;
return startDate;
}
function getProjectURL(){
var protocol = window.location.protocol;
var host = window.location.host;
var path = window.location.pathname;
var n=path.split("/");
var newpath = '';
for(var i=0;i < n.length-1;i++) {
newpath = newpath+n[i]+'/';
}
var url = protocol+'//'+host+newpath;
return url;
}
function getParameterByName(name){
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.search);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function logout() {
deleteCookie("loginEmail");
deleteCookie("loginPassword");
deleteCookie("xmlFile");
deleteCookie("canLogin");
location.href = 'login.html';
}
function contentClick() {
alert('contentClick');
}
function loadAccount() {
var email = readCookie("loginEmail");
var pwd = readCookie("loginPassword");
return loadAccountParam(email, pwd);
}
function loadAccountParam(email, pwd) {
var data = '<option value=""></option>';
var projecturl = getProjectURL();
var ret = false;
var json = $.getJSON(projecturl+"login.php?callback=?", {
email: email,
pwd: pwd
})
.success(function(json) {
ret = true;
if( json.success ) {
if (json.mps) {
for( var i = 0 ; i < json.mps.length ; i++ ) {
data += '<option value="'+ json.mps[i][0] +'">'+ json.mps[i][1] +'</option>';
}
}
if (data != "") {
$('#account').html(data);
Sort('account');
}
} else {
alert(json.message);
ret = false;
}
})
.error(function() {
alert("A connection error occured. Please try again.");
});
return ret;
}
function Sort(elementId) {
// Convert the listbox options to a javascript array and sort (ascending)
var sortedList = $.makeArray($("#" + elementId + " option"))
.sort(function(a, b) {
return $(a).text().toLowerCase() < $(b).text().toLowerCase() ? -1 : 1;
});
// Clear the options and add the sorted ones
$("#" + elementId).empty().html(sortedList);
}
function checkEmail(email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
if(reg.test(email) == false) {
//alert('Invalid Email Address');
return false;
} else {
return true;
}
}
function getRemote(remote_url) {
return $.ajax({
type: "GET",
dataType: 'json',
url: remote_url,
async: false,
}).responseText;
}
function serealizeSelects (select)
{
var array = [];
select.each(function(){ array.push($(this).val()) });
return array;
}