-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathjs.js
297 lines (259 loc) · 7.53 KB
/
js.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/***Prints The Days on the Registration Form***/
function printDays()
{
for(i=0;i<31;i++){
var dateVar = 1 + i;
document.write('<option value=\"' + dateVar + '\">' + dateVar + '</option>');
}
}
/***Prints The Years on the Registration Form***/
function printYears()
{
for(i=0;i<83;i++)
{
var dateVar = 1930 + i;
document.write('<option value=\"' + dateVar + '\">' + dateVar + '</option>');
}
}
/***Validates The Inputted Registration Form***/
function validateregform()
{
var fname=document.forms["register"]["fname"].value;
var lname=document.forms["register"]["lname"].value;
var email=document.forms["register"]["email"].value;
var pwd1=document.forms["register"]["pwd"].value;
var pwd2=document.forms["register"]["pwd2"].value;
var birthyear = parseInt(document.forms["register"]["year"].value);
var birthmonth = parseInt(document.forms["register"]["month"].value) - 1;
var birthday = parseInt(document.forms["register"]["day"].value);
if (fname==null || fname=="")
{
var div = document.getElementById("error");
div.textContent = "First name must be filled in";
var text = div.textContent;
return false;
}
if (lname==null || lname=="")
{
var div = document.getElementById("error");
div.textContent = "Last name must be filled in";
var text = div.textContent;
return false;
}
if (email==null || email=="")
{
var div = document.getElementById("error");
div.textContent = "E-mail must be filled in";
var text = div.textContent;
return false;
}
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length) //Checks if @ is first character, if email is @. or if the . is not in the string
{
var div = document.getElementById("error");
div.textContent = "Not a valid e-mail address";
var text = div.textContent;
return false;
}
if (pwd1 != pwd2)
{
var div = document.getElementById("error");
div.textContent = "Passwords don't match";
var text = div.textContent;
return false;
}
if (pwd1 == "" || pwd1 == null)
{
var div = document.getElementById("error");
div.textContent = "Passwords must be filled in";
var text = div.textContent;
return false;
}
//Minimum Age to Allow on the Site. Due to Children's Online Privacy Protection, this is 13
var min_age = 13;
var submitteddate = new Date((birthyear + min_age), birthmonth, birthday); //get date in JS format
var today = new Date;
if ( (today.getTime() - submitteddate.getTime()) < 0) { //If thier age is less than 13, this will return false
alert("Sorry! Due to the Children's Online Privacy Protection Act, you must be 13 years old to join the Brotherhood.");
return false;
}
}
/***Validates The Login Box***/
function validatelogin()
{
var pwd=document.forms["loginbox"]["password"].value;
var email=document.forms["loginbox"]["email"].value;
if (pwd==null || pwd=="")
{
alert("Please fill in your password.");
return false;
}
if (email==null || email=="")
{
alert("Email must be filled in.");
return false;
}
}
function validateDispatches()
{
var text=document.forms["dispatches"]["dispatch"].value;
if (text==null || text=="")
{
alert("Please type something to post!");
return false;
}
}
function handleUserInfoChangers()
{
var changerequest = new XMLHttpRequest();
xmlhttp.open("GET", "get_data.php", true);
xmlhttp.send();
}
function goHome()
{
window.location = "home.php";
}
function logout()
{
window.location = "logout.php";
}
function goToMyFriends()
{
window.location = "friends.php";
}
function goToMyRequests()
{
window.location = "requests.php";
}
function validatemissinginfomname()
{
var mname=document.forms["missinginfo"]["mname"].value;
if (fname==null || "mname"=="")
{
alert("Middle name must be filled in");
return false;
}
}
function validatemissinginfonickname()
{
var nickname=document.forms["missinginfo"]["nickname"].value;
if (nickname==null || nickname=="")
{
alert("Nickname name must be filled in");
return false;
}
}
function validatemissinginfophonenum()
{
var nickname=document.forms["missinginfo"]["phonenum"].value;
if (phonenum==null || phonenum=="")
{
alert("Phone number must be filled in");
return false;
}
}
function searchValidate()
{
var searchterms=document.forms["navsearch"]["query"].value;
if (searchterms==null || searchterms=="")
{
alert("You must type in a search term to search!");
return false;
}
else
{
var numOfWords = (searchterms.split(" ")).length
if (numOfWords>2)
{
alert("Please type in only up to two search terms!");
return false;
}
}
}
function printFriendsListold(userid)
{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
xmlDoc = xmlhttp.responseXML;
var root = xmlDoc.documentElement;
var friends = root.getElementsByTagName("friend");
document.write("<table border=\"1\"><tbody><tr><th>Userid</th><th>First Name</th><th>Last Name</th>");
for(var i = 0; i < friends.length; i += 1)
{
var fuserid = friends[i].getElementsByTagName("userid");
var fname = friends[i].getElementsByTagName("fname");
var lname = friends[i].getElementsByTagName("lname");
document.write("<tr><td>");
document.write(fuserid[0].textContent);
document.write("</td><td>");
document.write(fname[0].textContent);
document.write("</td><td>");
document.write(lname[0].textContent);
document.write("</td></tr>");
}
document.write("</tbody></table>");
}
}
var fListURL="getfriends.php?id=" + userid;
xmlhttp.open("GET", fListURL, true)
xmlhttp.send()
}
function checkProfilePicUpload()
{
var fileUploadDoc = document.getElementById('upload_filename');
var fileName = fileUploadDoc.value;
var extension = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "gif" || ext == "GIF" || ext == "JPEG" || ext == "jpeg" || ext == "jpg" || ext == "JPG" || ext == "png" || ext == "PNG" )
{
return true;
}
else
{
alert("Upload Gif or Jpg images only");
fileUploadDoc.focus();
return false;
}
}
/******Profile Navigation*******/
function showFriendsTab()
{
//Show Selected Tab
document.getElementById('friendsTab').style.display = '';
//Hide deselected Tabs
document.getElementById('userinfoTab').style.display = 'none';
document.getElementById('dispatchesTab').style.display = 'none';
}
function showUserinfoTab()
{
//Show Selected Tab
document.getElementById('userinfoTab').style.display = '';
//Hide deselected Tabs
document.getElementById('friendsTab').style.display = 'none';
document.getElementById('dispatchesTab').style.display = 'none';
}
function showDispatchesTab()
{
//Show Selected Tab
document.getElementById('dispatchesTab').style.display = '';
//Hide deselected Tabs
document.getElementById('friendsTab').style.display = 'none';
document.getElementById('userinfoTab').style.display = 'none';
}
/**
* I required this snipp.it due to the new format of dates from the v2 API and found
* a great example so thought I'd share.
* Credit to:
* - fest (http://snippets.dzone.com/user/fest)
* - post: http://snippets.dzone.com/posts/show/4132
**/
function mysqlTimeStampToDate(timestamp) {
//function parses mysql datetime string and returns javascript Date object
//input has to be in this format: 2007-06-05 15:26:02
var regex=/^([0-9]{2,4})-([0-1][0-9])-([0-3][0-9]) (?:([0-2][0-9]):([0-5][0-9]):([0-5][0-9]))?$/;
var parts=timestamp.replace(regex,"$1 $2 $3 $4 $5 $6").split(' ');
return new Date(parts[0],parts[1]-1,parts[2],parts[3],parts[4],parts[5]);
}