summaryrefslogtreecommitdiffstats
path: root/modules-available/locationinfo/frontend/doorsign.html
blob: 2ad347682888063afcae7a099f66d3a4be40c06c (plain) (blame)
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
<!--

parameter

required:
    id: [integer] room id, see in admin panel
optional:

    lang:[en,de] set the language
    mode:[1,2,3,4] sets the displaying
        1: Calendar & Room
        2: only Calendar
        3: only Room
        4: Calendar & Room alternately
    daystoshow:[1,2,3,4,5,6,7] sets how many days the calendar shows
    scale:[10-90] scales the calendar and Roomplan in mode 1
    switchtime:[1-120] sets the time between switchen in mode 4  (in seconds)
    calupdate: Time the calender querys for updates,in minutes.
    roomupdate: Time the PCs in the room gets updated,in seconds.
    rotation:[0-3] rotation of the roomplan
    vertical:[true] only mode 1, sets the calendar above the roomplan
    configupdate: Time interval the config gets updated (in minutes)
    scaledaysauto: [true] if true it finds automaticly the daystoshow parameter depending on display size
-->
<!DOCTYPE html>
<html lang="de">
<meta name="viewport" content="width=device-width, initial-scale=1.0" charset="utf-8">
<head>
	<title>DoorSign</title>
	<script type='text/javascript' src='../../../script/jquery.js'></script>
	<script type='text/javascript' src='../../js_jqueryui/clientscript.js'></script>
	<link rel='stylesheet' type='text/css' href='../../js_jqueryui/style.css'/>
	<link rel='stylesheet' type='text/css' href='jquery-week-calendar/jquery.weekcalendar.css'/>

	<script type='text/javascript' src="jquery-week-calendar/jquery.weekcalendar.js"></script>
	<style type='text/css'>

		body {
			font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
			margin: 0;

		}

		.row {
			background-color: #404040;
			box-shadow: 0 2px 4px 0 black;
			margin-bottom: 4px;

			width: 100%;

		}
		.header {
			display: table;
			color: white;
			padding: 0;
			height: 80px;

		}

		.font {
			display: table-cell;
			vertical-align: middle;
			font-size: 40px;
			font-weight: bold
		}

		.courseText {
			text-align: center;
		}

		.row::after {
			content: "";
			clear: both;
			display: block;
		}

		[class*="col-"] {
			float: left;;
			padding: 0;
			box-sizing: border-box;
		}

		.col-1 {
			width: 33%;
		}

		.col-2 {
			width: 33%;
		}


		.roomLayoutDesign {
			position: relative;
			background: linear-gradient(#cccccc, white);
			float: left;
			boxSizing: border-box;
		}

		.calendar {
			float: left;
			padding: 0;
			dboxSizing: border-box;
			background: linear-gradient(#cccccc, white);
		}

		.free-busy-busy {
			background: grey;
		}

		.ui-widget-content {
			color: white;
		}

		.wc-header {
			background-color: #404040;
			font-weight: bold;
		}

		.ui-state-default {
			text-shadow: none;
		}

		.square {
			display: table;
			float: right;
			padding: 0;
			width: 80px;
			height: 80px;
		}

		.FreeSeatsFont {
			display: table-cell;
			vertical-align: middle;
			font-size: 65px;
			color: white;
			top: 0;
			margin: 0 auto;
			position: relative;
			text-align: center;
			font-weight: bold;
			overflow: visible;
		}


		.pcImg {
			position: absolute;
			left: 0;
			bottom: 0;
		}

		.wc-scrollable-grid {

		}

		.ui-widget-content .ui-state-active {
			font-weight: bold;
			color: black;
		}

		.wc-container {
			font-weight: bold;
		}

		.wc-today {
			background-color: white;
		}

		.wc-time-header-cell {
			background-color: #eeeeee;
			border: none;
		}

		.ui-corner-all {
			moz-border-radius-bottomright: 0;
			webkit-border-bottom-right-radius: 0;
			-khtml-border-bottom-right-radius: 0;
			border-bottom-right-radius: 0;

			moz-border-radius-topright: 0;
			webkit-border-top-right-radius: 0;
			-khtml-border-top-right-radius: 0;
			border-top-right-radius: 0;

			moz-border-radius-bottomleft: 0;
			webkit-border-bottom-left-radius: 0;
			-khtml-border-bottom-left-radius: 0;
			border-bottom-left-radius: 0;

			moz-border-radius-topleft: 0;
			webkit-border-left-right-radius: 0;
			-khtml-border-left-right-radius: 0;
			border-top-left-radius: 0;
		}
		.wc-scrollable-grid .wc-day-column-first {
			border-style:solid;

		}
		[class*="wc-day-"] {
			border-color: grey;
		}

		@media (max-width: 1200px){
			.square {
				height: 60px;
				width: 60px;
			}
			.FreeSeatsFont {
				font-size: 45px;
			}
			.font {
				font-size: 26px;
			}
			.header {
				height: 60px;

			}
		}
		@media (max-width: 800px){
			.square {
				height: 50px;
				width: 50px;
			}
			.FreeSeatsFont {
				font-size: 35px;
			}
			.font {
				font-size: 20px;
			}
			.header {
				height: 50px;

			}
		}
		@media (max-width: 600px){
			.square {
				height: 40px;
				width: 40px;
			}
			.FreeSeatsFont {
				font-size: 30px;
			}
			.font {
				font-size: 18px;
			}
			.header {
				height: 40px;

			}
		}

	</style>
	<script type='text/javascript'>
		var date;

		var room;
		var freeSeats;
		var queryTimeCalendar;
		var queryTimeRoom;
		var openingTimes;
		var state;
		var openTimes;
		var openingTimesCalendar = [];
		var mode;
		var data;
		var roomId;
		var verticalmode = false;
		var scaleLayout;
		var switchTime;
		var rotation;
		var daysToShow;
		var configJson;
		var configupdate;
		var scaleDaysAuto = false;
		var eInkMode = false;
		var supportSvg = !!(document.createElementNS && document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect);
		var translation = {
			"en": {
				"room": "Room",
				"closed": "Closed",
				"free": "Free",
				"shortDays": ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
				"longDays": ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
				"to": "to"

			},
			"de": {
				"room": "Raum",
				"closed": "Geschlossen",
				"free": "Frei",
				"shortDays": ["Son", "Mon", "Die", "Mit", "Don", "Frei", "Sam"],
				"longDays": ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitrag", "Samstag"],
				"to": "bis"
			},
			"pt": {
				"room": "Quarto",
				"closed": "Fechado",
				"free": "Livre",
				"shortDays": ['Dom', 'Seg', 'Ter', 'Qua', 'Qui', 'Se', 'Sáb'],
				"longDays": ['Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado'],
				"to": "para"

			}
		};


		$(document).ready(function () {
			if (!getId()) {
				return;
			}
			getConfig();

		});

		function getConfig() {
			$.ajax({
				url: "../../../api.php?do=locationinfo&action=config&id=" + roomId,
				dataType: 'json',
				cache: false,
				timeout: 30000,
				success: function (result) {
					if (configJson == null) {
						if(result.room == null) {
							var heading = $("#courseHeading");
							heading.text("Error: wrong id");
							heading.css({'font-size': "30px"});
							return;
						}
						getParamerter(result);
						startMode();
						delete result.time;
					} else{
						// Todo resync time?
						delete result.time;
						if (JSON.stringify(configJson) != JSON.stringify(result)) {
							location.reload(true);
						}
					}
					configJson = result;
					setTimeout(function () {
						getConfig();
					}, configupdate);
				}, error: function () {
					var heading = $("#courseHeading");
					heading.text("Error: couldn't get the config");
					heading.css({'font-size': "30px"});
				}
			})
		}

		function getId() {
			roomId = getUrlParameter("id");
			if (roomId == null) {
				$("#courseHeading").text("Error: id required");
				return false;
			}

			return true;
		}
		function getParamerter(json) {
			var lang;
			if (json != null) {
				mode = parseInt(json.mode);
				lang = json.lang;
				daysToShow = parseInt(json.daystoshow);
				scaleLayout = parseInt(json.scale);
				switchTime = parseInt(json.switchtime) * 1000;
				queryTimeCalendar = parseInt(json.calupdate) * 60 * 1000;
				queryTimeRoom = parseInt(json.roomupdate) * 1000;
				rotation = parseInt(json.rotation);

				if(json.scaledaysauto!=null) {
					scaleDaysAuto = JSON.parse(json.scaledaysauto)
				}

				if(json.vertical!=null) {
					verticalmode = JSON.parse(json.vertical);
				}
				if(json.einkmode!=null) {
					eInkMode = JSON.parse(json.einkmode);
				}
				configupdate = parseInt(json.configupdate)* 60 * 1000;
				room = json.room;
			}
			var time = new Date(json.time);
			if (isNaN(time.getTime())) {
				time = new Date();
			}
			SetUpDate(time);

			if (room != null) {
				$("#roomHeader").text(room);
			}
			if (getUrlParameter("mode") != null) {
				mode = parseInt(getUrlParameter("mode"));
			}
			if (getUrlParameter("calupdate") != null) {
				queryTimeCalendar = (parseInt(getUrlParameter("calupdate")) * 60 * 1000);
			}
			if (getUrlParameter("roomupdate") != null) {
				queryTimeRoom = (parseInt(getUrlParameter("roomupdate")) * 1000);
			}
			if (getUrlParameter("daystoshow") != null) {
				daysToShow = parseInt(getUrlParameter("daystoshow"));
			}
			if (getUrlParameter("scaledaysauto") == "true") {
				scaleDaysAuto = true;
			}
			if (getUrlParameter("vertical") == "true") {
				verticalmode = true;
			}
			if (getUrlParameter("einkmode") == "true") {
				eInkMode = true;
			}

			if (getUrlParameter("scale") != null) {
				scaleLayout = parseInt(getUrlParameter("scale"));
			}
			if (getUrlParameter("rotation") != null) {
				rotation = parseInt(getUrlParameter("rotation"));
			}
			if (getUrlParameter("switchtime") != null) {
				switchTime = (parseInt(getUrlParameter("switchtime")) * 1000);
			}
			if (getUrlParameter("configupdate") != null) {
				configupdate = (parseInt(getUrlParameter("configupdate")) * 60 * 1000);
			}

			// parameter validation
			if (switchTime == null || isNaN(switchTime) || switchTime > 120 || switchTime < 1) {
				switchTime = 5;
			}
			if (scaleLayout == null || isNaN(scaleLayout) || scaleLayout > 90 || scaleLayout < 10) {
				scaleLayout = 50;
			}
			if (verticalmode == null) {
				verticalmode = false;
			}
			if (daysToShow == null || isNaN(daysToShow) || daysToShow > 7 || daysToShow < 1) {
				daysToShow = 7;
			}

			if (queryTimeRoom == null || isNaN(queryTimeRoom) || queryTimeRoom < 1000) {
				queryTimeRoom = 20 * 1000;
			}
			if (configupdate == null || isNaN(configupdate) || (configupdate < 1)) {
				configupdate = 30 * 60 * 1000;
			}

			if (queryTimeCalendar == null || isNaN(queryTimeCalendar) || queryTimeCalendar < 60 * 1000) {
				queryTimeCalendar = 30 * 60 * 1000;
			}
			if (mode == null || isNaN(mode) || mode > 4 || mode < 1) {
				mode = 1;
			}
			if(rotation ==null||isNaN(rotation)||rotation < 0 || rotation > 4){
				rotation = 0;
			}

			if (getUrlParameter("lang") != null && getUrlParameter("lang") in translation) {
				lang = getUrlParameter("lang");
			}
			$('html').attr('lang', lang);
		}

		function startMode() {
			var updateRate = 1000;
			if(eInkMode){
				updateRate =updateRate* 60;
			}
			// mixed mode
			if (mode == 1) {
				setUpCalendar(scaleLayout + "%", daysToShow);
				preInitRoom();
				Update();
				setInterval(function () {
					Update();
				}, updateRate);
			}
			// clendar only
			if (mode == 2) {
				setUpCalendar("100%", daysToShow);
				Update();
				setInterval(function () {
					Update();
				}, updateRate);
				queryRoom();
			}
			// room only
			if (mode == 3) {
				preInitRoom();
				$.getJSON("../../../api.php?do=locationinfo&action=openingtime&id=" + roomId, function (result) {
					SetOpeningTimes(result);
					queryCalendar();
					Update();
					setInterval(function () {
						Update();
					}, updateRate);
				});

			}
			//swichting mode
			if (mode == 4) {
				setUpCalendar("100%", daysToShow);
				preInitRoom();
				generateProgressBar();
				Update();
				setInterval(function () {
					Update();
				}, 1000);
				MoveProgressBar(switchTime);
				setInterval(function () {
					switchLayout();
					MoveProgressBar(switchTime);
				}, switchTime * 1000);
			}
		}


		function setUpCalendar(percent, daysToShow) {
			generateCalendarDiv(percent);
			var $calendar = $("#calendar").weekCalendar({
				timeslotsPerHour: 1,
				timeslotHeight: 20,
				daysToShow: daysToShow,
				height: function ($calendar) {
					var height = $(window).height() - document.getElementById('header').clientHeight - 5;
					if (mode == 1 && verticalmode) {
						height = height * (scaleLayout / 100)
					}
					return height;
				},
				eventRender: function (calEvent, $event) {
					if (calEvent.end.getTime() < new myDate().getTime()) {
						$event.css("backgroundColor", "#aaa");
						$event.find(".time").css({"backgroundColor": "#999", "border": "1px solid #888"});
					} else if (calEvent.end.getTime() > new myDate().getTime() && calEvent.start.getTime() < new myDate().getTime()) {
						$event.css("backgroundColor", "#25B002");
						$event.find(".time").css({"backgroundColor": "#25B002", "border": "1px solid #888"});
					}
				},
				date:myDate(),
				dateFormat: "j.n",
				timeFormat: "G:i",
				use24Hour: true,
				readonly: true,
				showHeader: false,
				hourLine: true,
				shortDays: t("shortDays"),
				longDays: t("longDays"),
				buttons: false,
				timeSeparator: " " + t("to") + " ",
				startOnFirstDayOfWeek: false,
				displayFreeBusys: true,
				defaultFreeBusy: {free: false}
			});
			$.getJSON("../../../api.php?do=locationinfo&action=openingtime&id=" + roomId, function (result) {
				SetOpeningTimes(result)
			})
				.success(function() {
					scaleCalendar();
					queryCalendar();
				})
				.error(function() {
					scaleCalendar();
					queryCalendar();})
		}

		function generateCalendarDiv(width) {
			var div = document.createElement("div");
			div.id = "calendar";
			div.className = "calendar";
			if (verticalmode && mode == 1) {
				width = 100 + "%";
				div.float = "Top";
			}
			div.style.width = width;
			document.body.appendChild(div);
		}

		function SetOpeningTimes(parsedOpenings) {
			var opening = 24;
			var close = 0;
			openingTimesCalendar = [];
			openingTimes = [parsedOpenings['Sunday'], parsedOpenings['Monday'], parsedOpenings['Tuesday'],
				parsedOpenings['Wednesday'], parsedOpenings['Thursday'],
				parsedOpenings['Friday'], parsedOpenings['Saturday']];
			if(mode == 3) {
				return;
			}
			for (var i = 0; i < 7; i++) {
				var tmp = openingTimes[i];
				if (tmp != null) {
					for (var d = 0; d < tmp.length; d++) {
						var day = getNextDayOfWeek(new myDate(), i);
						openingTimesCalendar.push({
							"start": new Date(day.getFullYear(), day.getMonth(), day.getDate(),
								tmp[d]['HourOpen'], tmp[d]['MinutesOpen']),
							"end": new Date(day.getFullYear(), day.getMonth(),
								day.getDate(), tmp[d]['HourClose'], tmp[d]['MinutesClose']),
							"free": true
						});
						if (parseInt(tmp[d]['HourOpen']) < opening) {
							opening = tmp[d]['HourOpen'];
						}
						if (parseInt(tmp[d]['HourClose']) > close) {
							close = tmp[d]['HourClose'];
							if (parseInt(tmp[d]['MinutesClose']) != 0) {
								close++;
							}
						}
					}
				}
			}
			if (parsedOpenings.length == 0) {
				opening = 0;
				close = 24;
			}
			openTimes = close - opening;
			$('#calendar').weekCalendar("option", "businessHours", {
				start: parseInt(opening),
				end: parseInt(close),
				limitDisplay: true
			});
		}
		function queryCalendar() {
			$.ajax({
				url: "../../../api.php?do=locationinfo&action=calendar&id="+roomId,
				dataType: 'json',
				cache: false,
				timeout: 30000,
				success: function (result) {
					data = result;
					updateCalendar(result);
					setTimeout(queryCalendar, queryTimeCalendar);
				}, error: function () {
					setTimeout(queryCalendar, queryTimeCalendar);
				}
			});
		}

		function updateCalendar(json) {
			if (mode != 3) {
				var cal = $('#calendar');
				cal.weekCalendar("option", "data", json);
				cal.weekCalendar("refresh");
				cal.weekCalendar("option", "defaultFreeBusy", {free: false});
				cal.weekCalendar("updateFreeBusy", openingTimesCalendar);
			}
			ComputeCurrentState();
		}

		function scaleCalendar() {

			if (openTimes == null) {
				openTimes = 24;
			}
			var cal = $('#calendar');
			var columnWidth = document.getElementsByClassName("wc-day-1")[0].clientWidth;

			if(scaleDaysAuto) {
				var result = (44 + cal.weekCalendar("option","daysToShow")*columnWidth)/100;
				result = parseInt(Math.min(Math.max(Math.abs(result),1),7));
				if(result != parseInt(cal.weekCalendar("option","daysToShow"))){
					cal.weekCalendar("option", "daysToShow", Math.abs(result));
				}
			}
			if(((!scaleDaysAuto)||cal.weekCalendar("option","daysToShow")==1)	&& columnWidth < 85){
				cal.weekCalendar("option", "useShortDayNames", true);
			} else {
				cal.weekCalendar("option", "useShortDayNames", false);
			}
			var clientHeight = $(window).height() - document.getElementById('header').clientHeight - document.getElementsByClassName("wc-time-column-header")[0].clientHeight-10 ;
			if (mode == 1 && verticalmode) {

				clientHeight = clientHeight * (scaleLayout / 100);
				clientHeight -= 22;

			}


			var height = clientHeight / (openTimes * cal.weekCalendar("option", "timeslotsPerHour"));
			cal.weekCalendar("option", "timeslotHeight", height);
			cal.weekCalendar("updateFreeBusy", openingTimesCalendar);
		}
		/**
		 * @return {string}
		 * @return {string}
		 */
		function GetTimeDiferenceAsString(a, b) {
			if (a == null || b == null) {
				return "";
			}
			var milliseconds = a.getTime() - b.getTime();
			var seconds = Math.floor((milliseconds / 1000) % 60);
			milliseconds -= seconds * 1000;
			var minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
			milliseconds -= minutes * 1000 * 60;
			var hours = Math.floor((milliseconds / (1000 * 60 * 60)) % 24);

			var days = Math.floor((milliseconds / (1000 * 60 * 60 * 24)) % 31);
			if (seconds < 10) {
				seconds = "0" + seconds;
			}
			if (minutes < 10) {
				minutes = "0" + minutes;
			}
			if (days != 0) {
				// dont show?
				return "";
			}
			if(eInkMode){
				return hours + ":" + minutes ;
			}
			return hours + ":" + minutes + ":" + seconds;
		}
		function GetNextClosing() {
			var now = new myDate();
			var day = now.getDay();
			var offset = 0;
			var bestdate;
			for (var a = 0; a < 7; a++) {
				var tmp = openingTimes[day];
				if (tmp != null) {
					for (var i = 0; i < tmp.length; i++) {
						var closeDate = new myDate();
						closeDate.setDate(now.getDate() + offset);
						closeDate.setHours(tmp[i].HourClose);
						closeDate.setMinutes(tmp[i].MinutesClose);
						if (closeDate > now) {
							if (!IsOpen(new Date(closeDate.getTime() + 60000))) {
								if (bestdate == null || bestdate > closeDate) {
									bestdate = closeDate;
								}
							}
						}
					}
				}
				offset++;
				day++;
				if (day > 6) {
					day = 0;
				}
			}
			return bestdate;
		}
		/**
		 * @return {boolean}
		 */
		function IsOpenNow() {
			var now = new myDate();
			if(openingTimes == null) {
				return false;
			}
			var tmp = openingTimes[now.getDay()];
			if (tmp == null) {
				return false;
			}
			for (var i = 0; i < tmp.length; i++) {
				var openDate = new myDate();
				openDate.setHours(tmp[i].HourOpen);
				openDate.setMinutes(tmp[i].MinutesOpen);
				var closeDate = new myDate();
				closeDate.setHours(tmp[i].HourClose);
				closeDate.setMinutes(tmp[i].MinutesClose);
				if (openDate < now && closeDate > now) {
					return true;
				}
			}
			return false;
		}
		/**
		 * @return {boolean}
		 */
		function IsOpen(date) {
			if(openingTimes == null) {
				return false;
			}
			var tmp = openingTimes[date.getDay()];
			if (tmp == null) {
				return false;
			}
			for (var i = 0; i < tmp.length; i++) {
				var openDate = new myDate();
				openDate.setHours(tmp[i].HourOpen);
				openDate.setMinutes(tmp[i].MinutesOpen);
				var closeDate = new myDate();
				closeDate.setHours(tmp[i].HourClose);
				closeDate.setMinutes(tmp[i].MinutesClose);
				if (openDate < date && closeDate > date) {
					return true;
				}
			}
			return false;
		}


		function GetNextOpening() {
			var now = new myDate();
			var day = now.getDay();
			var offset = 0;
			var bestdate;
			for (var a = 0; a < 7; a++) {
				if(openingTimes == null) {
					return null;
				}
				var tmp = openingTimes[day];
				if (tmp != null) {
					for (var i = 0; i < tmp.length; i++) {
						var openDate = new myDate();
						openDate.setDate(now.getDate() + offset);
						openDate.setHours(tmp[i].HourOpen);
						openDate.setMinutes(tmp[i].MinutesOpen);
						if (openDate > now) {
							if (!IsOpen(new Date(openDate.getTime() - 60000))) {
								if (bestdate == null || bestdate > openDate) {
									bestdate = openDate;
								}
							}
						}
					}
				}
				offset++;
				day++;
				if (day > 6) {
					day = 0;
				}
			}
			return bestdate;
		}

		function SetFreeSeats(_freeSeats) {
			if (_freeSeats > 0) {
				$("#freeSeatsHeader").text(_freeSeats);
				$(".square").css('background-color', '#00dd10');
			} else if (_freeSeats == -1) {
				$("#freeSeatsHeader").text("");
				$(".square").css('background-color', 'red');
			} else {
				$("#freeSeatsHeader").text("0");
				$(".square").css('background-color', 'red');
			}
			freeSeats = _freeSeats;
		}

		function Update() {
			var tmp = GetState();
			if (tmp == null) {
				ComputeCurrentState();
				return;
			}
			if (tmp.state == "closed") {
				$("#courseHeading").text(t("closed") + " " + GetTimeDiferenceAsString(tmp.end, new myDate()));
				SetFreeSeats(-1);
			} else if (tmp.state == "ClaendarEvent") {
				$("#courseHeading").text(state.titel);
				SetFreeSeats(-1);
			} else if (tmp.state == "Free") {
				$("#courseHeading").text(t("free") + " " + GetTimeDiferenceAsString(tmp.end, new myDate()));
			} else if (tmp.state == "FreeNoEnd") {
				$("#courseHeading").text(t("free"));
			}
			var now = new myDate();
			//console.log(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds());
			// reload if date Changes
			if (date != null) {
				if (date.getDate() != now.getDate()) {
					location.reload(true);
				}
			}
			date = now;
		}

		function GetState() {
			if (state == null) {
				ComputeCurrentState();
				return state;
			}
			if (state.end != "") {
				if (state.end < new myDate()) {
					ComputeCurrentState();
				}
			}
			return state;
		}

		function ComputeCurrentState() {
			if (!IsOpenNow()) {
				state = {state: "closed", end: GetNextOpening(), titel: "", next: ""};
				return;
			}
			var closing = GetNextClosing();
			var event = getNextEvent(data);
			// no event and no closing
			if (closing == null && event == null) {
				state = {state: "FreeNoEnd", end: "", titel: "", next: ""};
				return;
			}

			// no event so closing is next
			if (event == null) {
				state = {state: "Free", end: closing, titel: "", next: "closing"};
				return;
			}

			// event is at the moment
			if (event.start.getTime() < closing.getTime() && event.start.getTime() < new myDate()) {
				state = {state: "ClaendarEvent", end: event.end, titel: event.title, next: ""};
				return;
			}

			// no closing so event is next
			if (closing == null) {
				state = {state: "Free", end: event.start, titel: "", next: "event"};
				return;
			}

			// event sooner then closing
			if (event.start.getTime() < closing) {
				state = {state: "Free", end: event.start, titel: "", next: "event"};
			} else if (event.start.getTime() > closing) {
				state = {state: "Free", end: closing, titel: "", next: "closing"};
			}
		}

		function getNextEvent(json) {
			var event;
			var now = new myDate();
			for (var i = 0; i < json.length; i++) {
				//event is now active
				if (json[i].start.getTime() < now.getTime() && json[i].end.getTime() > now.getTime()) {
					return json[i];
				}
				//first element to consider
				if (event == null) {
					if (json[i].start.getTime() > now.getTime()) {
						event = json[i];
					}
				}
				if (json[i].start.getTime() > now.getTime() && event.start.getTime() > json[i].start.getTime()) {
					event = json[i];
				}
			}
			return event;
		}

		function getNextDayOfWeek(date, dayOfWeek) {
			// Code to check that date and dayOfWeek are valid left as an exercise ;)

			var resultDate = new Date(date.getTime());

			resultDate.setDate(date.getDate() + (7 + dayOfWeek - date.getDay()) % 7);

			return resultDate;
		}
		/*
		 /========================================== Room Layout =============================================
		 */
		var scale;
		var xOffset;
		var yOffset;
		var picSizeX = 3.8;
		var picSizeY = 3;
		var Layout;
		var LayoutJson;
		var maxX;
		var maxY;
		var minY;
		var minX;
		var xDifference;
		var yDifference;

		function generateRoomLayoutDiv(width) {
			var div = document.createElement("div");
			div.id = "roomLayout";
			div.className = "roomLayoutDesign";
			if ((verticalmode && mode == 1) || (mode == 3)|| (mode == 4)) {
				width = 100 + "%";
				div.float = "Top";
			}

			div.style.width = width;
			document.body.appendChild(div);

		}
		function preInitRoom() {
			$.getJSON("../../../api.php?do=locationinfo&action=roominfo&id=" + roomId + "&coords=1", function (result) {
				initRoom(result, (100 - scaleLayout) + "%")
			}).error(function() {
				generateRoomLayoutDiv((100 - scaleLayout) + "%");
			})
		}


			function initRoom(Json, scale) {

				Layout = Json;
				if(Layout == null||Layout.length == 0) {
					return;
				}
				generateRoomLayoutDiv(scale);
				if (rotation != 0) {
					rotateRoom(rotation);
				}

				for (var i = 0; i < Layout.length; i++) {
					if(!isNaN(parseInt(Layout[i].x)) && ! isNaN(parseInt(Layout[i].y))) {
						if(minX === undefined){
							minX = parseInt(Layout[i].x);
						}
						if(minY === undefined){
							minY = parseInt(Layout[i].y);
						}
						if(maxX === undefined){
							maxX = parseInt(Layout[i].x);
						}
						if(maxY === undefined){
							maxY = parseInt(Layout[i].y);
						}
						if (parseInt(Layout[i].x) < parseInt(minX)) {
							minX = parseInt(Layout[i].x);
						}
						if (parseInt(Layout[i].y) < parseInt(minY)) {
							minY = parseInt(Layout[i].y);
						}
						if (parseInt(Layout[i].x) > parseInt(maxX)) {
							maxX = parseInt(Layout[i].x);
						}
						if (parseInt(Layout[i].y) > parseInt(maxY)) {
							maxY = parseInt(Layout[i].y);
						}
					}
				}

				xDifference = maxX - minX;
				yDifference = maxY - minY;
				generateOffsetAndScale();
				setUpRoom();
			}

		function generateOffsetAndScale() {
			var clientHeight = ($(window).height() - document.getElementById('header').clientHeight - 5);
			if (verticalmode && mode == 1) {
				clientHeight = clientHeight * (1 - (scaleLayout / 100));
			}
			($("#roomLayout")).height(clientHeight);
			var clientWidth = document.getElementById('roomLayout').clientWidth;
			var scaleX;
			if (xDifference != 0) {
				scaleX = clientWidth / xDifference;
			} else {
				scaleX = clientWidth;
			}
			var scaleY;
			if (yDifference != 0) {
				scaleY = clientHeight / yDifference;
			} else {
				scaleY = clientHeight;
			}
			var scaleYs = (clientHeight - (picSizeY * scaleY)) / yDifference;
			var scaleXs = (clientWidth - (picSizeX * scaleX)) / xDifference;
			if (scaleYs <= 0) {
				scaleYs = 9999;
			}
			if (scaleXs <= 0) {
				scaleXs = 9999;
			}
			var tmp = [scaleYs, scaleY, scaleXs, scaleX];
			scale = Math.min.apply(Math, tmp);
			xOffset = 0 - minX;
			yOffset = 0 - minY;
			xOffset += ((1 / 2 * (clientWidth - (((maxX + xOffset) * scale) + picSizeX * scale))) / scale);
			yOffset += ((1 / 2 * (clientHeight - (((maxY + yOffset) * scale) + picSizeY * scale))) / scale);
		}

		function setUpRoom() {
			for (var i = 0; i < Layout.length; i++) {


				var img = $('<img />',
					{
						id: Layout[i].id,
						class: "pcImg",
					})
					.appendTo($('#roomLayout'));
			}
			scaleRoom();
			UpdatePc(Layout);
			queryRoom();
		}

		// possible fix for long delay of updates after long runtime
		function queryRoom() {
			$.ajax({
				url: "../../../api.php?do=locationinfo&action=roominfo&id=" + roomId + "&coords=1",
				dataType: 'json',
				cache: false,
				timeout: 30000,
				success: function (result) {
					if (LayoutJson != JSON.stringify(result)) {
						LayoutJson = JSON.stringify(result);
						UpdatePc(result);

					}
					setTimeout(queryRoom, queryTimeRoom);
				}, error: function () {
					setTimeout(queryRoom, queryTimeRoom);
				}
			})
		}

		function rotateRoom(r) {
			for (var z = 0; z < r; z++) {
				for (var i = 0; i < Layout.length; i++) {
					var x = parseInt(Layout[i].x);
					var y = parseInt(Layout[i].y);
					Layout[i].x = y;
					Layout[i].y = -x;
				}
			}
		}

		function scaleRoom() {
			if(Layout== null) {
				return;
			}
			for (var i = 0; i < Layout.length; i++) {
				if(Layout[i].y!= null & Layout[i].x!=null) {
					document.getElementById(Layout[i].id).width = (picSizeX * scale);
					document.getElementById(Layout[i].id).height = (picSizeY * scale);
					document.getElementById(Layout[i].id).style.left = ((parseInt(Layout[i].x) + xOffset) * scale) + "px";
					document.getElementById(Layout[i].id).style.top = ((parseInt(Layout[i].y) + yOffset) * scale ) + "px";
				}
			}
		}


		function UpdatePc(update) {
			var freePcs = 0;
			for (var i = 0; i < update.length; i++) {
				var imgobj =document.getElementById(update[i].id);

				var img;
				if (update[i].pcState == "0") {
					//add time to prevent caching
					if(supportSvg) {
						img = "img/pc_free";
					} else {
						imgobj.style.backgroundColor="green";
					}
					freePcs++;
				} else if (update[i].pcState == "1") {
					if(supportSvg) {
						img = "img/pc_used";
					}else {
						imgobj.style.backgroundColor="red";
					}
				} else {
					if(supportSvg) {
						img = "img/pc_defect?";
					}else {
						imgobj.style.backgroundColor="black";
					}
				}
				if(imgobj !=null && supportSvg) {
					if(eInkMode){
						img = img + "_eink";
					}
					imgobj.src = img+ ".svg";
				}
			}
			if (state == null || state.state == "FreeNoEnd" || state.state == "Free") {
				SetFreeSeats(freePcs);
			}

		}

		/*
		 /========================================== Misc =============================================
		 */
		var resized = false;
		$(window).resize(function () {
			resized = true;
			setTimeout(function () {
				if (mode != null) {
					if (mode != 3) {
						scaleCalendar();

					}
					if (mode != 2) {
						generateOffsetAndScale();
						scaleRoom();
					}
				}
			}, 50);
		});

		var getUrlParameter = function getUrlParameter(sParam) {
			var sPageURL = decodeURIComponent(window.location.search.substring(1)),
				sURLVariables = sPageURL.split('&'),
				sParameterName,
				i;

			for (var i = 0; i < sURLVariables.length; i++) {
				sParameterName = sURLVariables[i].split('=');

				if (sParameterName[0] === sParam) {
					return sParameterName[1] === undefined ? true : sParameterName[1];
				}
			}
		};

		function t(toTranslate) {
			var r = translation[$('html')[0].lang][toTranslate];
			if (r === undefined) {
				r = translation['en'][toTranslate]
			}
			return r;
		}

		function switchLayout() {
			var car = document.getElementById("calendar");
			var room = document.getElementById("roomLayout");

			if (car.style.display == "none") {
				room.style.display = "none";
				car.style.display = "block";
				if(resized){
					scaleCalendar();
					resized = false;
				}
			} else {
				car.style.display = "none";
				room.style.display = "block";
				if(resized){
					generateOffsetAndScale();
					scaleRoom();
					resized = false;
				}
			}
		}
		function generateProgressBar() {
			var div = document.createElement("div");
			div.style.width = "0px";
			div.style.height = "2px";
			div.style.position = "absolute";
			div.id = "progressBar";
			div.style.backgroundColor = "red";
			div.style.bottom = "0px";
			div.style.zIndex = "1";
			document.body.appendChild(div);
		}
		function MoveProgressBar(time) {
			var elem = document.getElementById("progressBar");
			var width = 1;
			var id = setInterval(frame, time * 10);

			function frame() {
				if (width >= 100) {
					clearInterval(id);
				} else {
					width++;
					elem.style.width = width + '%';
				}
			}
		}



	</script>
</head>
<body>
<div id="header" class="row">
	<div class="header col-2">
		<div class ="font" id="roomHeader"></div>
	</div>
	<div class="col-1 courseText header">
		<div class ="font"  id="courseHeading"></div>
	</div>
	<div class="square .col-2">
		<div class="FreeSeatsFont" id="freeSeatsHeader"></div>
	</div>
</div>

</body>
</html>