-
Notifications
You must be signed in to change notification settings - Fork 2
/
Javascript.js
363 lines (322 loc) · 11.6 KB
/
Javascript.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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
function ToggleAdvanced() {
var x = document.getElementById('AdvancedSearch');
if (x.style.display === "block") {
x.style.display = 'none';
} else {
x.style.display = 'block';
}
}
function ToggleAdvancedJazz() {
var x = document.getElementById('AdvancedFilter');
if (x.style.display === "block") {
x.style.display = 'none';
} else {
x.style.display = 'block';
}
}
//Hide Jazz Select Days
function Hide(){
document.getElementById('AdvancedFilter').style.display = 'none';
document.getElementById('Friday').style.visibility = 'hidden';
document.getElementById('Saturday').style.visibility = 'hidden';
document.getElementById('Sunday').style.visibility = 'hidden';
document.getElementById('Friday1').style.display = 'none';
document.getElementById('Saturday1').style.display = 'none';
document.getElementById('Sunday1').style.display = 'none';
}
//Show Jazz div $DAY
function ShowDate(day) {
if(day == 1){
document.getElementById('Thursday').style.visibility = 'unset';
document.getElementById('Thursday1').style.display = 'block';
document.getElementById('Friday').style.visibility = 'hidden';
document.getElementById('Friday1').style.display = 'none';
document.getElementById('Saturday').style.visibility = 'hidden';
document.getElementById('Saturday1').style.display = 'none';
document.getElementById('Sunday').style.visibility = 'hidden';
document.getElementById('Sunday1').style.display = 'none';
}
else if(day == 2){
document.getElementById('Friday').style.visibility = 'unset';
document.getElementById('Friday1').style.display = 'block';
document.getElementById('Thursday').style.visibility = 'hidden';
document.getElementById('Thursday1').style.display = 'none';
document.getElementById('Saturday').style.visibility = 'hidden';
document.getElementById('Saturday1').style.display = 'none';
document.getElementById('Sunday').style.visibility = 'hidden';
document.getElementById('Sunday1').style.display = 'none';
}
else if(day == 3){
document.getElementById('Saturday').style.visibility = 'unset';
document.getElementById('Saturday1').style.display = 'block';
document.getElementById('Friday').style.visibility = 'hidden';
document.getElementById('Friday1').style.display = 'none';
document.getElementById('Thursday').style.visibility = 'hidden';
document.getElementById('Thursday1').style.display = 'none';
document.getElementById('Sunday').style.visibility = 'hidden';
document.getElementById('Sunday1').style.display = 'none';
}
else if(day == 4){
document.getElementById('Sunday').style.visibility = 'unset';
document.getElementById('Sunday1').style.display = 'block';
document.getElementById('Friday').style.visibility = 'hidden';
document.getElementById('Friday1').style.display = 'none';
document.getElementById('Saturday').style.visibility = 'hidden';
document.getElementById('Saturday1').style.display = 'none';
document.getElementById('Thursday').style.visibility = 'hidden';
document.getElementById('Thursday1').style.display = 'none';
}
JazzClearItems();
}
//Add to cart for jazz
function JazzAddToCart(){
var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
if(inputs[i].type.toLowerCase() == 'text') {
if(inputs[i].value >0){
id = inputs[i].id;
amount = inputs[i].value;
amount = parseInt(amount);
AddToCart(id, 4, amount)
}
}
}
JazzClearItems();
}
//Clear all form input "text"
function JazzClearItems(){
var inputs = document.getElementsByTagName('input');
for(var i = 0; i < inputs.length; i++) {
if(inputs[i].type.toLowerCase() == 'text') {
if(inputs[i].value >0){
inputs[i].value = 0;
}
}
}
}
function TimeTablePDF(id){
var win = window.open("CreateTimeTablePDF.php?id="+id, '_blank');
win.focus();
}
// js function to add tickets to cart. 'normal' tickets only need eventId, typeEvent and amount. Reservations need more info, thus they're 0 or "" on default so normal tickets adding isn't changed
function AddToCart(eventId, typeEvent, amount, childAmount = 0, adultAmount = 0, startTime = "", date = "", extraInfo = "") {
// check to make sure amount that's being added is not a negative number or 0
amountCheck = amount + childAmount + adultAmount;
if (amountCheck > 0) {
$.ajax({ url: 'AddToCart.php',
data: {eventId: eventId,typeEvent: typeEvent, amount:amount, childAmount: childAmount, adultAmount: adultAmount, startTime: startTime, date: date, extraInfo: extraInfo},
type: 'post',
success: function(output) {
if (output == 1) {
ShowPopup();
ShoppingCartPlus(amountCheck);
}
else {
alert("Sorry there are not enough tickets left for your request.");
}
}
});
}
}
function FoodAddToCartHelper(count) {
// grab variables necessary to put ticket in session
var childAmount = parseInt(document.getElementById('pplBelow12' + count).value);
var adultAmount = parseInt(document.getElementById('pplAbove12' + count).value);
var extraInfo = document.getElementById('extraInfo' + count).value;
var eventId = document.getElementById('pickSession' + count).value;
var date = document.getElementById('date' + count).value;
var startTimeSelect = document.getElementById('pickSession' + count);
var startTime = startTimeSelect.options[startTimeSelect.selectedIndex].text;
// check if selected time is valid, act accordingly
var timeCheck = startTime.search(":");
if (timeCheck == 2 && startTime.length == 5) {
AddToCart(eventId, 1, 0, childAmount, adultAmount, startTime, date, extraInfo);
} else {
alert("Please select a time.");
}
}
// when a user selects a date for a restaurant, the corresponding times AND foodRestaurant Id are picked up, allowing for the correct ticket information to be displayed in the checkout
function SelectedDate(count, id) {
var date = document.getElementById('pickDay' + count).value;
var time = document.getElementById('pickSession' + count);
time.disabled = false;
while (time.firstChild) {
time.removeChild(time.firstChild);
}
$.ajax({ url: 'FoodHelper.php',
data: {date: date, id: id},
type: 'post',
success: function(output) {
// parse output back to array allowing usage
output = JSON.parse(output);
for (var i = 0; i < output.length; i++) {
// for the length of the array, create time 'options' and add them to select time element
var opt = output[i];
var el = document.createElement("option");
el.textContent = String(opt.SessionStartTime);
el.textContent
el.value = opt.Id;
time.appendChild(el);
}
}
});
}
// removes ticket from cart
function RemoveFromCart(self, eventId, typeEvent, price) {
$.ajax({ url: 'RemoveFromCart.php',
data: {eventId: eventId, typeEvent: typeEvent},
type: 'post',
success: function(output) {
var parent = self.parentNode;
var parenttickets = parent.parentNode;
ShoppingCartmin(output);
self.parentNode.remove();
if(parenttickets.children.length == 0){
var eventday = parenttickets.parentNode;
eventday.remove();
}
var totalamount = String(document.getElementById("TotalAmount").innerHTML);
totalamount = totalamount.replace(',', '.');
totalamount = parseFloat(totalamount);
var remove = totalamount - (price * output);
remove = remove.toFixed(2);
remove = String(remove).replace('.', ',');
document.getElementById("TotalAmount").innerHTML = remove;
}
});
}
// removes food reservation from cart
function FoodRemoveFromCart(self, eventId, typeEvent, price, amountType) {
$.ajax({ url: 'RemoveFromCartFood.php',
data: {eventId: eventId, typeEvent: typeEvent, amountType: amountType},
type: 'post',
success: function(output) {
output = parseInt(output);
var parent = self.parentNode;
var parenttickets = parent.parentNode;
ShoppingCartmin(output);
self.parentNode.remove();
if (parenttickets.children.length == 0) {
var eventday = parenttickets.parentNode;
eventday.remove();
}
// get current totalAmounts
var totalAmount = String(document.getElementById("TotalAmount").innerHTML);
var totalFoodAmount = String(document.getElementById("TotalFoodAmount").innerHTML);
// replace comma with period because parseFloat doesn't 'take' comma's ...
totalAmount = totalAmount.replace(',', '.');
totalFoodAmount = totalFoodAmount.replace(',', '.');
// parse it to float
totalAmount = parseFloat(totalAmount);
totalFoodAmount = parseFloat(totalFoodAmount);
// calculate new totalAmounts
var removeTotal = totalAmount - (10 * output);
var removeFoodTotal = totalFoodAmount - (price * output);
// round down to 2 numbers behind comma
removeTotal = removeTotal.toFixed(2);
removeFoodTotal = removeFoodTotal.toFixed(2);
// replace period with comma again
removeTotal = String(removeTotal).replace('.', ',');
removeFoodTotal = String(removeFoodTotal).replace('.', ',');
// replace html element with new totalAmount
document.getElementById("TotalAmount").innerHTML = removeTotal;
document.getElementById("TotalFoodAmount").innerHTML = removeFoodTotal;
}
});
}
function ShowPopup() {
var popup = document.getElementById("myPopup");
setTimeout( popup.style.display = 'block', 10000);
setTimeout(function () {
popup.style.display = 'none';
}, 2000);
}
function ToEvent(src){
if (src == "Historic") {
location.href = "Historic.php";
}
if (src == "Jazz") {
location.href = "Jazz.php";
}
if (src == "Dance") {
location.href = "Dance.php";
}
if (src == "Food") {
location.href = "Food.php";
}
}
function showTickets(){
location.href = ("HistoricOrderTickets.php");
}
function SelectedDay(date){
var elem = document.getElementById(date);
var slides = document.getElementsByClassName("HideTimeTable");
for(var i = 0; i < slides.length; i++)
{
slides[i].style.display = "none";
}
elem.style.display = "block";
}
function ShoppingCartPlus(amount){
var number = parseInt(document.getElementById("shoppingcartCount").innerHTML);
number = number + amount;
document.getElementById("shoppingcartCount").innerHTML = number;
}
function ShoppingCartmin(amount){
var number = parseInt(document.getElementById("shoppingcartCount").innerHTML);
number = number - amount;
document.getElementById("shoppingcartCount").innerHTML = number;
}
function ShoppingCartPlusJazz(id){
var amount = document.getElementById(id).value;
amount++;
document.getElementById(id).value = amount;
}
function ShoppingCartMinJazz(id){
var amount = document.getElementById(id).value;
if (amount >0){
amount--;
document.getElementById(id).value = amount;
}
}
function cartAmountPlus(count){
var indentifier = "amountNumber".concat(count);
var number = parseInt(document.getElementById(indentifier).value);
number = number + 1;
document.getElementById(indentifier).value = number;
}
function cartAmountMinus(count){
var indentifier = "amountNumber".concat(count);
var number = parseInt(document.getElementById(indentifier).value);
if (number > 0) {
number = number - 1;
document.getElementById(indentifier).value = number;
}
}
function GetTicketAmount(count){
var indentifier = "amountNumber".concat(count);
var number = parseInt(document.getElementById(indentifier).value);
return number;
}
function ShowHideJazzFilter(){
var x = document.getElementById('Toggle');
if (x.style.display === "block") {
x.style.display = 'none';
} else {
x.style.display = 'block';
}
}
function CheckMail(){
var Email = document.getElementById("EmailControl").value;
$.ajax({ url: 'CheckMail.php',
data: {Email: Email},
type: 'post',
success: function(output) {
if (output != false) {
if (confirm("We see that there is a purchase with the same email, would you like to combine them?")){
document.getElementById("OrderNumber").value = output;
}
}
}
});
}