summaryrefslogtreecommitdiffstats
path: root/main/survey/app/Controllers/JsController.php
blob: 308fb41518448d13bd6d1b9c50978b5389c9934d (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
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
<?php
/***************************************
 * Description:
 * Autor: Robert Šmalc
 * Created date: 08.02.2016
 *****************************************/

namespace App\Controllers;

use App\Controllers\CheckController as Check;
use App\Controllers\FindController as Find;
use App\Controllers\HeaderController as Header;
use App\Controllers\HelperController as Helper;
use App\Models\Model;
use Cache;
use enkaParameters;
use SurveyAdvancedParadataLog;
use SurveyInfo;
use SurveySetting;
use SurveySlideshow;
use Common;
use SurveyPanel;
use AppSettings;

class JsController extends Controller
{

    public function __construct($var = null)
    {
        parent::getGlobalVariables();
    }

    /************************************************
     * Get instance
     ************************************************/
    private static $_instance;

    public static function getInstance()
    {
        if (self::$_instance)
            return self::$_instance;

        return new JsController();
    }

    // izpise kodo za JS sledenje, ce je nastavljena
    public static function js_tracking()
    {

        $row = SurveyInfo::getSurveyRow();

        if ($row['js_tracking'] != '') {
            echo '<!-- JS tracking code -->';
            echo $row['js_tracking'];
            echo '<!-- / JS tracking code -->';
        }

    }

    /**
     * @desc generira JavaScript za alert pri vprasanjih z reminderjem
     */
    public function generateSubmitJS()
    {
        global $lang;
        global $site_url;
		global $site_domain;
		global $admin_type;

        // Dodaten text pri alertu ce smo v testnem vnosu
        $test_alert = (isset($_GET['testdata']) && $_GET['testdata'] == 'on') ? '\n\n' . $lang['srv_remind_preview'] : '';

        // Custom texti za opozorila...
        SurveySetting::getInstance()->Init(get('anketa'));
        if (get('lang_id') != null) $_lang = '_' . get('lang_id'); else $_lang = '';
        $srv_remind_sum_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_sum_hard' . $_lang);
        if ($srv_remind_sum_hard == '') $srv_remind_sum_hard = $lang['srv_remind_sum_hard'];
        $srv_remind_sum_hard = strip_tags(addslashes(stripslashes($srv_remind_sum_hard))).$test_alert;
        $srv_remind_sum_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_sum_soft' . $_lang);
        if ($srv_remind_sum_soft == '') $srv_remind_sum_soft = $lang['srv_remind_sum_soft'];
        $srv_remind_sum_soft = strip_tags(addslashes(stripslashes($srv_remind_sum_soft))).$test_alert;
        $srv_remind_num_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_num_hard' . $_lang);
        if ($srv_remind_num_hard == '') $srv_remind_num_hard = $lang['srv_remind_num_hard'];
        $srv_remind_num_hard = strip_tags(addslashes(stripslashes($srv_remind_num_hard))).$test_alert;
        $srv_remind_num_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_num_soft' . $_lang);
        if ($srv_remind_num_soft == '') $srv_remind_num_soft = $lang['srv_remind_num_soft'];
        $srv_remind_num_soft = strip_tags(addslashes(stripslashes($srv_remind_num_soft))).$test_alert;
        
        $srv_remind_text_num_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_text_num_hard' . $_lang);
        if ($srv_remind_text_num_hard == '') $srv_remind_text_num_hard = $lang['srv_remind_text_num_hard'];
        $srv_remind_text_num_hard = strip_tags(addslashes(stripslashes($srv_remind_text_num_hard))).$test_alert;
        $srv_remind_text_num_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_text_num_soft' . $_lang);
        if ($srv_remind_text_num_soft == '') $srv_remind_text_num_soft = $lang['srv_remind_text_num_soft'];
        $srv_remind_text_num_soft = strip_tags(addslashes(stripslashes($srv_remind_text_num_soft))).$test_alert;
		
		//za minimalno stevilo izbranih checkbox-ov
		$srv_remind_checkbox_min_violated_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_checkbox_min_violated_hard' . $_lang);
        if ($srv_remind_checkbox_min_violated_hard == '') $srv_remind_checkbox_min_violated_hard = $lang['srv_remind_checkbox_min_violated_hard'];
        $srv_remind_checkbox_min_violated_hard = strip_tags(addslashes(stripslashes($srv_remind_checkbox_min_violated_hard))).$test_alert;
		
		$srv_remind_checkbox_min_violated_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_checkbox_min_violated_soft' . $_lang);
        if ($srv_remind_checkbox_min_violated_soft == '') $srv_remind_checkbox_min_violated_soft = $lang['srv_remind_checkbox_min_violated_soft'];
        $srv_remind_checkbox_min_violated_soft = strip_tags(addslashes(stripslashes($srv_remind_checkbox_min_violated_soft))).$test_alert;
		//za minimalno stevilo izbranih checkbox-ov - konec

        $srv_remind_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_hard' . $_lang);
        if ($srv_remind_hard == '') $srv_remind_hard = $lang['srv_remind_hard'];
        $srv_remind_hard = strip_tags(addslashes(stripslashes($srv_remind_hard))).$test_alert;
        $srv_remind_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_soft' . $_lang);
        if ($srv_remind_soft == '') $srv_remind_soft = $lang['srv_remind_soft'];
        $srv_remind_soft = strip_tags(addslashes(stripslashes($srv_remind_soft))).$test_alert;

        $srv_remind_hard_99 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_hard_-99' . $_lang);
        if ($srv_remind_hard_99 == '') $srv_remind_hard_99 = $lang['srv_remind_hard_-99'];
        $srv_remind_hard_99 = strip_tags(addslashes(stripslashes($srv_remind_hard_99))).$test_alert;
        $srv_remind_soft_99 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_soft_-99' . $_lang);
        if ($srv_remind_soft_99 == '') $srv_remind_soft_99 = $lang['srv_remind_soft_-99'];
        $srv_remind_soft_99 = strip_tags(addslashes(stripslashes($srv_remind_soft_99))).$test_alert;
        $srv_remind_hard_98 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_hard_-98' . $_lang);
        if ($srv_remind_hard_98 == '') $srv_remind_hard_98 = $lang['srv_remind_hard_-98'];
        $srv_remind_hard_98 = strip_tags(addslashes(stripslashes($srv_remind_hard_98))).$test_alert;
        $srv_remind_soft_98 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_soft_-98' . $_lang);
        if ($srv_remind_soft_98 == '') $srv_remind_soft_98 = $lang['srv_remind_soft_-98'];
        $srv_remind_soft_98 = strip_tags(addslashes(stripslashes($srv_remind_soft_98))).$test_alert;
        $srv_remind_hard_97 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_hard_-97' . $_lang);
        if ($srv_remind_hard_97 == '') $srv_remind_hard_97 = $lang['srv_remind_hard_-97'];
        $srv_remind_hard_97 = strip_tags(addslashes(stripslashes($srv_remind_hard_97))).$test_alert;
        $srv_remind_soft_97 = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_soft_-97' . $_lang);
        if ($srv_remind_soft_97 == '') $srv_remind_soft_97 = $lang['srv_remind_soft_-97'];
        $srv_remind_soft_97 = strip_tags(addslashes(stripslashes($srv_remind_soft_97))).$test_alert;
        $srv_remind_hard_multi = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_hard_multi' . $_lang);
        if ($srv_remind_hard_multi == '') $srv_remind_hard_multi = $lang['srv_remind_hard_multi'];
        $srv_remind_hard_multi = strip_tags(addslashes(stripslashes($srv_remind_hard_multi))).$test_alert;
        $srv_remind_soft_multi = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_soft_multi' . $_lang);
        if ($srv_remind_soft_multi == '') $srv_remind_soft_multi = $lang['srv_remind_soft_multi'];
        $srv_remind_soft_multi = strip_tags(addslashes(stripslashes($srv_remind_soft_multi))).$test_alert;

        $srv_remind_captcha_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_captcha_soft' . $_lang);
        if ($srv_remind_captcha_soft == '') $srv_remind_captcha_soft = $lang['srv_remind_captcha_soft'];
        $srv_remind_captcha_soft = strip_tags(addslashes(stripslashes($srv_remind_captcha_soft))).$test_alert;
        $srv_remind_captcha_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_captcha_hard' . $_lang);
        if ($srv_remind_captcha_hard == '') $srv_remind_captcha_hard = $lang['srv_remind_captcha_hard'];
        $srv_remind_captcha_hard = strip_tags(addslashes(stripslashes($srv_remind_captcha_hard))).$test_alert;

        $srv_remind_email_soft = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_email_soft' . $_lang);
        if ($srv_remind_email_soft == '') $srv_remind_email_soft = $lang['srv_remind_email_soft'];
        $srv_remind_email_soft = strip_tags(addslashes(stripslashes($srv_remind_email_soft))).$test_alert;
        $srv_remind_email_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_remind_email_hard' . $_lang);
        if ($srv_remind_email_hard == '') $srv_remind_email_hard = $lang['srv_remind_email_hard'];
        $srv_remind_email_hard = strip_tags(addslashes(stripslashes($srv_remind_email_hard))).$test_alert;

        $srv_alert_number_toobig = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_alert_number_toobig' . $_lang);
        if ($srv_alert_number_toobig == '') $srv_alert_number_toobig = $lang['srv_alert_number_toobig'];
        $srv_alert_number_toobig = strip_tags(addslashes(stripslashes($srv_alert_number_toobig))).$test_alert;
        $srv_alert_number_exists = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_alert_number_exists' . $_lang);
        if ($srv_alert_number_exists == '') $srv_alert_number_exists = $lang['srv_alert_number_exists'];
        $srv_alert_number_exists = strip_tags(addslashes(stripslashes($srv_alert_number_exists))).$test_alert;

        $mobile_tables = SurveySetting::getInstance()->getSurveyMiscSetting('mobile_tables');
		
		$srv_remind_checkbox_max_violated_hard = SurveySetting::getInstance()->getSurveyMiscSetting('srv_remind_checkbox_max_violated_hard' . $_lang);
		if ($srv_remind_checkbox_max_violated_hard == '') $srv_remind_checkbox_max_violated_hard = $lang['srv_remind_checkbox_max_violated_hard'];
		$srv_remind_checkbox_max_violated_hard = strip_tags(addslashes(stripslashes($srv_remind_checkbox_max_violated_hard))).$test_alert;

	
        echo '        <script> ' . "\n";
		
        ?>
        var lang_srv_alert_number_exists = "<?= $srv_alert_number_exists ?>";
        var lang_srv_alert_number_toobig = "<?= $srv_alert_number_toobig ?>";
        var lang_srv_remind_checkbox_max_violated_hard = "<?= $srv_remind_checkbox_max_violated_hard ?>";
        <?

        $survey_hint = SurveySetting::getInstance()->getSurveyMiscSetting('survey_hint');
        if ($survey_hint == '') $survey_hint = 1;

        echo '          // generateSubmitJS() ' . "\n";
        ?>
        function submitAlert (id, action, type, bol, validation, txt, alert_sum, alert_num, alert_validation) {

			if (validation == true) {

				if (<?= $survey_hint ?> == 1) {

					// pri tabelah izberemo celo spremenljivko
					if ( ! $(id).hasClass('spremenljivka') ) {
						id = '#' + $(id).closest('.spremenljivka')[0].id;
					}
					
					if (type == 'require' || type == 'require2' || type == 'require3' || type == 'require4' || type == 'require5') {						
						if ( $(id)[0].getAttribute('data-vrstni_red') >= max_vrstni_red ) return;
					} else {						
						if ( $(id)[0].getAttribute('data-vrstni_red') > max_vrstni_red ) return;
					}

					var text;
					if (type == 'require')
					text = '<?= str_replace('\n', '<br />', $srv_remind_hard) ?>';
					if (type == 'require2')
					text = '<?= str_replace('\n', '<br />', $srv_remind_hard_99) ?>';
					if (type == 'require3')
					text = '<?= str_replace('\n', '<br />', $srv_remind_hard_98) ?>';
					if (type == 'require4')
					text = '<?= str_replace('\n', '<br />', $srv_remind_hard_97) ?>';
					if (type == 'require5')
					text = '<?= str_replace('\n', '<br />', $srv_remind_hard_multi) ?>';
					if (type == 'limit')
					text = '<?= str_replace('\n', '<br />', $srv_remind_num_hard) ?>';
                    if (type == 'text_limit')
					text = '<?= str_replace('\n', '<br />', $srv_remind_text_num_hard) ?>';
					if (type == 'validation')
					text = txt;
					if (type == 'checkbox_min_limit')
					text = '<?= str_replace('\n', '<br />', $srv_remind_checkbox_min_violated_hard) ?>';

					if (action == 'add') {
						if ($(id+' div.validation_alert.'+type+'').length == 0){

							$(id).append('<div class="validation_alert '+type+'">'+text+'</div>');

							// Ce je opozorilo izven ekrana (ozki ekran, mobitel, tablica...) ga prikazemo na desni
							$('div.validation_alert').each(function(){
								if($(this).offset().left < 0){
									$(this).addClass('alignRight');
								}
							});
						}			
						showMissing(id);
					}
					else {
						$(id+' div.validation_alert.'+type+'').remove();
					}
				}				
			}
			else {
				if (action == 'add') {
					$(id).addClass('required_'+type);

					// Ce imamo vklopljene napredne parapodatke zabelezimo opozorilo
					<?if (SurveyAdvancedParadataLog::getInstance()->paradataEnabled()){?>
						dodaj_opozorilo(alert_sum, alert_num, alert_validation, bol, id);
					<?}?>

					showMissing(id);
				}
				else {
					$(id).removeClass('required_'+type);
				}
			}
        }

        function isEmail(email) {
			var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			return regex.test(email);
        }

        var missing_hidden = false;
        function showMissing(id) {

            // Si zapomnimo, ce so bili missingi skriti - posebej za CDI anketo za posebno vprasanje
            if($(id).find('.missing:visible').length == 0){
                missing_hidden = true;
            }
            else{
                missing_hidden = false;
            }

            // Naknadno prikazemo missing vrednosti
			$(id).find('.missing').slideDown();

            // Prikazemo missinge se v dropdownu
			$(id).find('.active-result').show();
			$(id).find('option').show();
        }
        <?
		
        echo '          function submitForm(parent_if, validation) { ' . "\n";
        echo '            if (is_paused_slideshow == true) return false' . "\n";
        echo '            var hard = true; ' . "\n";
        echo '            var soft = true; ' . "\n";
        echo '            var vsota = true; ' . "\n";
        echo '            var num = true; ' . "\n";
        echo '            var text_num = true; ' . "\n";
		echo '            var checkbox_min_limit_alert = false; ' . "\n";	

        $require = '';

        $sql = sisplet_query("SELECT * FROM srv_spremenljivka WHERE gru_id='" . get('grupa') . "' AND gru_id != '0' AND reminder > 0 ORDER BY vrstni_red ASC");
        while ($row = mysqli_fetch_array($sql)) {

            echo '           try { ' . "\n";

            // katero spremenljivko bomo nastavili
            if ($row['reminder'] == 1) {
                $bol = 'soft';
            } else {
                $bol = 'hard';
            }

            // ce prikazujemo naknadno vec moznosti (recimo nevem in neustrezno)
            if (($row['alert_show_99'] == 1 && $row['alert_show_98'] == 1) || ($row['alert_show_99'] == 1 && $row['alert_show_97'] == 1) || ($row['alert_show_98'] == 1 && $row['alert_show_97'] == 1)) {
                $require = 'require5';
            } // ce prikazujemo naknadno ne vem
            elseif ($row['alert_show_99'] == 1) {
                $require = 'require2';
            } // ce prikazujemo naknadno zavrnil
            elseif ($row['alert_show_98'] == 1) {
                $require = 'require3';
            } // ce prikazujemo naknadno neustrezno
            elseif ($row['alert_show_97'] == 1) {
                $require = 'require4';
            } else {
                $require = 'require';
            }

            // najprej damo pogoj, da se uposteva, samo ce je vprasanje vidno (ker je lahko v ifu)
            //echo '            if ( $(\'#spremenljivka_'.$row['id'].'\').css(\'display\') != \'none\' ) { '."\n";
            echo '            if ( document.getElementById(\'spremenljivka_' . $row['id'] . '\').style.display != \'none\' ) { ' . "\n";
			
            // radio in checkbox
            if ($row['tip'] <= 2 && ($row['orientation'] != 8 || get('mobile') == 1)) {
				
				if ($row['tip'] == 1)
					$ime = 'vrednost_' . $row['id'];
				else
					$ime = 'vrednost_' . $row['id'] . '[]';

				echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
				echo '              var len = obj.length; ' . "\n";

				echo '              var bol = false; ' . "\n";

				// ce je samo 1 (spodnja procedura ne prime, je treba posebej)
				echo '              if (len == undefined) {  ' . "\n";

				echo '                if (obj.checked)  ' . "\n";
				echo '                  bol = true;  ' . "\n";

				// sicer gremo normalno čez vse
				//preureditev za pregled textboxa za drugo
				echo '              } else { ' . "\n";
				
				echo '					var bolTextBox = [] ' . "\n"; //polje, ki shranjuje info o boolean za "drugo"
				
				echo '					for (i=0; i<len; i++){ ' . "\n";						
				echo '                  	if (obj[i].checked){ ' . "\n";	//ce je odgovor izbran
				echo '                    		bol = true; ' . "\n";
				
					//urejanje za textbox za drugo
 				echo '                  		var drugo_temp = obj[i].id.replace("vrednost", "textfield"); ' . "\n";				
 				echo '                  		if($("#"+drugo_temp).length){ ' . "\n";
				echo '              				var drugo_text_empty = true; ' . "\n";				
				echo '                  			if($("#"+drugo_temp).val() != ""){ ' . "\n";
				echo '                  				drugo_text_empty = false; ' . "\n";			
				echo '                  			} ' . "\n";
				echo '              				if (drugo_text_empty){ ' . "\n";
				echo '               					bolTextBox[i] = false; ' . "\n";
				echo '              				}else{ ' . "\n";
				echo '               					bolTextBox[i] = true; ' . "\n";
				echo '                  			} ' . "\n";
				
				echo '                  		} ' . "\n";
					//urejanje za textbox za drugo - konec
				echo '               		} ' . "\n";	//konec if (obj[i].checked)
				echo '              	} ' . "\n";	//konec for
				
					//ce polje za textbox "drugo" ni prazno, ustrezno uredi spremenljivko bol
				echo '                  if(bolTextBox.indexOf(false)>0){ ' . "\n";
				echo '               		bol = false; ' . "\n";
				echo '              	} ' . "\n";
					//ce polje za textbox "drugo" ni prazno, ustrezno uredi spremenljivko bol - konec
				

				echo '              }  ' . "\n";
				//preureditev za pregled textboxa za drugo - konec
					
			
				// Posebna funkcionalnost za ministrstvo za obrambo, ker se mudi (q5,q6,q8,q9,q11,q14)
				if($site_url == 'https://www.1ka.si/' && get('anketa') == '180402' && in_array($row['id'], array('10654896', '10654916', '10668668', '10677046', '10668603', '10657205'))){
					
					// Minimalno št. checkboxov (3 oz. 5)
					if(in_array($row['id'], array('10654896', '10654916', '10668668', '10677046'))){
						$cnt_special = ($row['id'] == '10668668') ? 5 : 3;
						
						echo '              var cnt_special = 0; ' . "\n";

						echo '              for (i=0; i<len; i++){ ' . "\n";
						echo '                if (obj[i].checked) ' . "\n";
						echo '                  cnt_special ++; ' . "\n";
						echo '              } ' . "\n";
						
						echo '              if (cnt_special != '.$cnt_special.') ' . "\n";
						echo '                bol = false; ' . "\n";
					}
					
					// Kliknil drugo brez vnosa v text polje
					if(in_array($row['id'], array('10654896', '10668603', '10657205'))){
						
						echo '              for (i=0; i<len; i++){ ' . "\n";
						echo '                if (obj[i].checked){ ' . "\n";				
						echo '                  var drugo_temp = obj[i].id.replace("vrednost", "textfield"); ' . "\n";						
						echo '                  if($("#"+drugo_temp).length){ ' . "\n";				
						
						echo '              		var drugo_text_empty = true; ' . "\n";
						
						echo '                  	if($("#"+drugo_temp).val() != "") ' . "\n";
						echo '                  		drugo_text_empty = false; ' . "\n";			

						echo '              		if (drugo_text_empty) ' . "\n";
						echo '               			bol = false; ' . "\n";

						echo '                  } ' . "\n";					
						echo '                } ' . "\n";
						echo '              } ' . "\n";
					}
				}

				
				echo '              if (!bol) { ' . "\n";
				echo '                ' . $bol . ' = false; ' . "\n";
				echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";				
				echo '              } else { ' . "\n";
				echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";		
				echo '              }' . "\n";
                
            }
            //drag and drop - kategorije en in vec odgovorov
            if ($row['tip'] <= 2 && ($row['orientation'] == 8 && get('mobile') != 1)) {
                $ime = 'vrednost_' . $row['id'];
                echo '
					var bol = false;
					var prisotno = $("#half2_frame_dropping_' . $row['id'] . '").children("div").attr("value");
					if (prisotno){
						bol = true;
					}
					if (!bol) {
						' . $bol . ' = false;
						submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false);
					}else{
						submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false);
					}
				';
            } 
            // dropdown
            elseif ($row['tip'] == 3) {

                $ime = 'vrednost_' . $row['id'];

                echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                echo '              if (!obj.value > 0) { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";
            } 
            // tabele @ drag and drop
            elseif (($row['tip'] == 6 && $row['enota'] == 9) || ($row['tip'] == 16 && $row['enota'] == 9)) {
                echo '
					var bol = true;
					var prisotno = $("#half_frame_dropping_' . $row['id'] . '").children("div").attr("value");
					if (prisotno){
						bol = false;
					}
					if (!bol) {
						' . $bol . ' = false;
						submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false);
					}else{
						submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false);
					}
				';
            } 
            // tabela - max diff
            elseif ($row['tip'] == 6 && $row['enota'] == 5) {

                echo '                var bol = false; ' . "\n";
                
                // Preverimo, ce sta oznaceni vrednosti 1 in 2 (min max)
                echo '                if ($(\'#spremenljivka_'.$row['id'].'\').find(\'input[value="1"]\').is(\':checked\') && $(\'#spremenljivka_'.$row['id'].'\').find(\'input[value="2"]\').is(\':checked\')) {   ' . "\n";
                echo '                  var bol = true; ' . "\n";
                echo '                } ' . "\n";

                echo '                if (!bol) { ' . "\n";
                echo '                  ' . $bol . ' = false; ' . "\n";
                echo '                  if (!validation) submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '                } else { ' . "\n";
                echo '                  if (!validation) submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '                } ' . "\n";
            }
            // tabele
            elseif (($row['tip'] == 6 && $row['enota'] != 9) || $row['tip'] == 16 || $row['tip'] == 19 || $row['tip'] == 20) {

                echo '                  var totalbol = true; ';

                $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' AND other!='1' ORDER BY vrstni_red");
                while ($row1 = mysqli_fetch_array($sql1)) {

                    // Pri postopnem resevanju multigrida tega nimamo, ker drugace ne dela ok (ker deluje na principu da so vse vrstice razen tekoce display:none;)
                    if ($row['dynamic_mg'] == 0) {
                        echo '              if ( document.getElementById(\'vrednost_if_' . $row1['id'] . '\').style.display != \'none\' ) {  ' . "\n";
                    }

                    // dropdown
                    if ($row['enota'] == 2) { // zakaj je tole? pride do bugov, ce je ostala enota nastavljena na ostalih tipih

                        // todo
                        $ime = 'vrednost_' . $row1['id'];

                        echo '                var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                        echo '                if (!obj.value > 0) { ' . "\n";
                        echo '                  ' . $bol . ' = false; ' . "\n";
                        echo '                  totalbol = false; ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } else { ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } ' . "\n";


                        // multi radio
                        //} elseif ($row['tip'] == 6) {
                    } elseif ($row['tip'] == 6 && $row['enota'] != 9) {
						
						$ime = 'vrednost_' . $row1['id'];
												
						// Pri postopnem resevanju moramo skrite z ifom posebej izlociti iz preverjanja
						if ($row['dynamic_mg'] != 0) {
							echo '       if( !$(\'#vrednost_if_' . $row1['id'] . '\').hasClass(\'if_hide\') ){ ' . "\n";
						}

						//echo 'console.log("Klasična tabela!"); ';
						echo '                var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
						echo '                var len = obj.length; ' . "\n";
						echo '                var bol = false; ' . "\n";
						
						// ce je samo 1 (spodnja procedura ne prime, je treba posebej)
						echo '                if (len == undefined) {  ' . "\n";

						echo '                  if (obj.checked)  ' . "\n";
						echo '                    bol = true;  ' . "\n";

						// sicer gremo normalno čez vse
						echo '                } else { ' . "\n";

						echo '                  for (i=0; i<len; i++) ' . "\n";
						echo '                    if (obj[i].checked) ' . "\n";
						echo '                      bol = true; ' . "\n";

						echo '                }  ' . "\n";
											
						// Pri dvojnih tabelah moramo posebej preverjati se desno stran
						echo '                var bol2 = true; ' . "\n";		
						if ($row['enota'] == 3) {
							$ime2 = 'vrednost_' . $row1['id'].'_part_2';
							
							echo '                var obj2 = document.forms[\'vnos\'].elements[\'' . $ime2 . '\']; ' . "\n";
							echo '                var len2 = obj2.length; ' . "\n";
							echo '                var bol2 = false; ' . "\n";
							
							echo '                for (i=0; i<len2; i++) ' . "\n";
							echo '                  if (obj2[i].checked) ' . "\n";
							echo '                    bol2 = true; ' . "\n";
						}					

						echo '                if (!bol || !bol2) { ' . "\n";
						echo '                  ' . $bol . ' = false; ' . "\n";
						echo '                  totalbol = false; ' . "\n";
						echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
						echo '                } else { ' . "\n";
						echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
						echo '                } ' . "\n";
												
						// Pri postopnem resevanju moramo skrite z ifom posebej izlociti iz preverjanja
						if ($row['dynamic_mg'] != 0) {
							echo '        } ' . "\n";
						}
		
                        // multicheck
                        //} elseif ($row['tip'] == 16) {
                    } elseif ($row['tip'] == 16 && $row['enota'] != 9) {

                        $ime = 'vrednost_' . $row1['id'];

                        echo '                var bol = false; ' . "\n";

                        echo '                for (var i=1; i<=' . $row['grids'] . '; i++) { ' . "\n";
                        echo '                    obj = document.getElementById(\'' . $ime . '_grid_\'+i); ' . "\n";

                        echo '                    if (obj.checked || obj.disabled) ' . "\n";
                        echo '                        bol = true; ' . "\n";

                        echo '                } ' . "\n";

                        echo '                if (!bol) { ' . "\n";
                        echo '                  ' . $bol . ' = false; ' . "\n";
                        echo '                  totalbol = false; ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } else { ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } ' . "\n";

                        // tabela besedilo in tabela number
                    } elseif ($row['tip'] == 19 || $row['tip'] == 20) {

                        $ime = 'vrednost_' . $row1['id'];

                        echo '                var bol = false; ' . "\n";

                        echo '                for (var i=1; i<=' . $row['grids'] . '; i++) { ' . "\n";
                        echo '                    obj = document.getElementById(\'' . $ime . '_grid_\'+i); ' . "\n";

                        echo '                    if (obj.value != "" || obj.disabled) ' . "\n";
                        echo '                        bol = true; ' . "\n";

                        echo '                } ' . "\n";

                        echo '                if (!bol) { ' . "\n";
                        echo '                  ' . $bol . ' = false; ' . "\n";
                        echo '                  totalbol = false; ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } else { ' . "\n";
                        echo '                  if (!validation) submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '                } ' . "\n";

                    }

                    // Pri postopnem resevanju multigrida tega nimamo, ker drugace ne dela ok
                    if ($row['dynamic_mg'] == 0) {
                        echo '              } ' . "\n";;
                    }
                }

                echo '              if (validation) {																								';
                echo '                if (!totalbol)																								';
                echo '					submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '				  else 																											';
                echo '					submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo ' 			    }																												';

                // besedilo *
            } elseif ($row['tip'] == 21) {

                // captcha
                $spremenljivkaParams = new enkaParameters($row['params']);
                $captcha = ($spremenljivkaParams->get('captcha') ? $spremenljivkaParams->get('captcha') : 0);

				if ($captcha == 1) {
                    ?>
                    var response = grecaptcha.getResponse();
					
					if (response.gelgth != 0 || validation==true) {
						// ok
					} 
					else {
						<?
						if ($bol == 'soft') {
							?>
							if (!confirm('<?=$srv_remind_captcha_soft?>'))
								return;
							<?
						} 
						else {
							?>
							alert('<?=$srv_remind_captcha_hard?>');
							return;
							<?
						}
						?>
					}
					<?
				}

                //for ($i=0; $i<$row['text_kosov']; $i++) {
                $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY vrstni_red");
                while ($row1 = mysqli_fetch_array($sql1)) {

                    $ime = 'vrednost_' . $row['id'] . '_kos_' . $row1['id'];

                    echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                    echo '              if (obj.value == "" && obj.disabled == false) { ' . "\n";
                    echo '                ' . $bol . ' = false; ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'validation\', \'' . $bol . '\', validation); ' . "\n";

                    // Email validation
                    $emailVerify = ($spremenljivkaParams->get('emailVerify') ? $spremenljivkaParams->get('emailVerify') : 0);
                    if ($emailVerify == 1) {
                        echo '              } else if(isEmail(obj.value) == false) { ' . "\n";
                        echo '                ' . $bol . ' = false; ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'validation\', \'' . $bol . '\', validation, \'' . ($bol == 'soft' ? $srv_remind_email_soft : $srv_remind_email_hard) . '\'); ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation); ' . "\n";
                        
                        echo '              } else if(isEmail(obj.value) == true) { ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'validation\', \'' . $bol . '\', validation, \'' . ($bol == 'soft' ? $srv_remind_email_soft : $srv_remind_email_hard) . '\'); ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation); ' . "\n";
                    }

                    echo '              } else { ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation); ' . "\n";
                    echo '              } ' . "\n";
                }

                // textbox, compute, quota
            } elseif ($row['tip'] == 4 || $row['tip'] == 22 || $row['tip'] == 25 || $row['tip'] == 8) {

                $ime = 'vrednost_' . $row['id'];

                echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                echo '              if (obj.value == "" && obj.disabled == false) { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";

                // number
            } elseif ($row['tip'] == 7) {

                $ime = 'spremenljivka_' . $row['id'] . '_vrednost';

                echo '              var obj1 = document.getElementById(\'' . $ime . '_1\'); 	' . "\n";
                if ($row['size'] == 2)
                    echo '              var obj2 = document.getElementById(\'' . $ime . '_2\'); 	' . "\n";
                if ($row['size'] == 1)
                    echo '              if (obj1.value == "" && obj1.disabled == false) { ' . "\n";
                elseif ($row['size'] == 2)
                    echo '              if ((obj1.value == "" && obj1.disabled == false) || (obj2.value == "" && obj2.disabled == false)) { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'' . $require . '\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";
            }

            // razvrscanje - ostevilcevanje
            elseif ($row['tip'] == 17 && ($row['design'] == 1 || get('mobile') > 0)) {

                // max stevilo vnesenih vrednosti
                $max = $row['ranking_k'];

                // nimamo omejenega stevila vnosov (morajo biti vnesena vsa stevila)
                if ($max == 0) {
                    $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY vrstni_red");
                    while ($row1 = mysqli_fetch_array($sql1)) {

                        $ime = 'spremenljivka_' . $row['id'] . '_vrednost_' . $row1['id'];

                        echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                        echo '              if (obj.value == "") { ' . "\n";
                        echo '                ' . $bol . ' = false; ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '              } else { ' . "\n";
                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                        echo '              } ' . "\n";
                    }
                } 
                // imamo omejeno stevilo vnosov
                else {
                    echo '              var count = ' . $max . '; ' . "\n";

                    $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY vrstni_red");
                    while ($row1 = mysqli_fetch_array($sql1)) {
                        $ime = 'spremenljivka_' . $row['id'] . '_vrednost_' . $row1['id'];

                        echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                        echo '              if (obj.value != "") ' . "\n";
                        echo '                count --; ' . "\n";
                    }

                    echo '              if (count > 0) { ' . "\n";
                    echo '                ' . $bol . ' = false; ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } else { ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } ' . "\n";
                }
            } 
            // razvrscanje - prestavljanje
            elseif ($row['tip'] == 17 && ($row['design'] == 0)) {

                //max stevilo vnesenih vrednosti
                $max = $row['ranking_k'];

                //nimamo omejenega stevila vnosov (morajo biti vnesena vsa stevila)
                if ($max == 0) {
                    $sql1 = sisplet_query("SELECT COUNT(id) FROM srv_vrednost WHERE spr_id='$row[id]'");
                    $row1 = mysqli_fetch_array($sql1);
                    $max = $row1['COUNT(id)'];
                }

                $ime = 'half2_' . $row['id'];
                echo '              var count = $(\'#' . $ime . '\').children().size(); ' . "\n";

                echo '              if (count < \'' . $max . '\') { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";
            } 
            // razvrscanje - heatmap
            elseif ($row['tip'] == 17 && ($row['design'] == 3)) {

                $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]'");
                while($row1 = mysqli_fetch_array($sql1)){

                    $ime = 'spremenljivka_' . $row['id'] . '_vrednost_' . $row1['id'];

                    echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                    echo '              if (obj.value == "") { ' . "\n";
                    echo '                ' . $bol . ' = false; ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } else { ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } ' . "\n";
                }
            } 
            
            // vsota
            elseif ($row['tip'] == 18) {

                $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY vrstni_red");
                while ($row1 = mysqli_fetch_array($sql1)) {

                    $ime = 'spremenljivka_' . $row['id'] . '_vrednost_' . $row1['id'];

                    echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                    echo '              if (obj.value == "") { ' . "\n";
                    echo '                ' . $bol . ' = false; ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } else { ' . "\n";
                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '              } ' . "\n";
                }

                // sn
            } elseif ($row['tip'] == 9) {

                echo '              var obj = document.getElementById(\'txt1\'); 	' . "\n";
                echo '              if (obj.value == "") { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";


                // kombinirana tabela
            } elseif ($row['tip'] == 24) {

                $first_spr = 0;

                $sqlm = sisplet_query("SELECT s.* FROM srv_spremenljivka s, srv_grid_multiple gm WHERE s.id=gm.spr_id AND gm.parent = '$row[id]' ORDER BY gm.vrstni_red ASC");
                $rowm = mysqli_fetch_array($sqlm);
                $first_spr = $rowm['id'];

                $sql1 = sisplet_query("SELECT id, vrstni_red FROM srv_vrednost WHERE spr_id='$first_spr' ORDER BY vrstni_red");
                				
                while ($row1 = mysqli_fetch_array($sql1)) {
				
					// Preverjamo ce je if na trenutni vrstici
					$vrednost = '';
					$sqlVrednostIf = sisplet_query("SELECT * FROM srv_vrednost WHERE spr_id='$row[id]' AND if_id>0 AND vrstni_red='".$row1['vrstni_red']."'");
					if(mysqli_num_rows($sqlVrednostIf) > 0){
						$rowVrednostIf = mysqli_fetch_array($sqlVrednostIf);
						$vrednost = 'vrednost_if_' . $rowVrednostIf['id'];
					}
					echo '            if ( !$(\'#'.$vrednost.'\').length || document.getElementById(\'' . $vrednost . '\').style.display != \'none\' ) {  ' . "\n";
					
                    echo '                var totalBol = true; ' . "\n";

                    mysqli_data_seek($sqlm, 0);
                    while ($rowm = mysqli_fetch_array($sqlm)) {

                        $sql2 = sisplet_query("SELECT * FROM srv_vrednost WHERE spr_id='$rowm[id]' AND vrstni_red='$row1[vrstni_red]'");
                        $row2 = mysqli_fetch_array($sql2);

                        // dropdown
                        if ($rowm['tip'] == 6 && $rowm['enota'] == 2) {

                            // todo
                            $ime = 'multi_' . $rowm['id'] . '_' . $row2['id'];

                            echo '                var bol = true; ' . "\n";
                            echo '                var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                            echo '                if (!obj.value > 0) { ' . "\n";
                            echo '                  bol = false; ' . "\n";
                            echo '                }' . "\n";
                            echo '                if (bol==false) totalBol = false; ' . "\n";
                            //selectbox
                        } elseif ($rowm['tip'] == 6 && $rowm['enota'] == 6) {

                            // todo
                            $ime = 'multi_' . $rowm['id'] . '_' . $row2['id'];

                            echo '                var bol = true; ' . "\n";
                            echo '                var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                            echo '                if (!obj.value > 0) { ' . "\n";
                            echo '                  bol = false; ' . "\n";
                            echo '                }' . "\n";
                            echo '                if (bol==false) totalBol = false; ' . "\n";

                            // multi radio
                        } elseif ($rowm['tip'] == 6) {

                            $ime = 'multi_' . $rowm['id'] . '_' . $row2['id'];

                            echo '                var bol = false; ' . "\n";
                            echo '                var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                            echo '                var len = obj.length; ' . "\n";


                            // ce je samo 1 (spodnja procedura ne prime, je treba posebej)
                            echo '                if (len == undefined) {  ' . "\n";

                            echo '                  if (obj.checked)  ' . "\n";
                            echo '                    bol = true;  ' . "\n";

                            // sicer gremo normalno čez vse
                            echo '                } else { ' . "\n";

                            echo '                  for (i=0; i<len; i++) ' . "\n";
                            echo '                    if (obj[i].checked) ' . "\n";
                            echo '                      bol = true; ' . "\n";

                            echo '                }  ' . "\n";
                            echo '                if (bol==false) totalBol = false; ' . "\n";

                            // multicheck
                        } elseif ($rowm['tip'] == 16) {

                            $ime = 'multi_' . $rowm['id'] . '_' . $row2['id'];

                            echo '                var bol = false; ' . "\n";
                            echo '                for (var i=1; i<=' . $rowm['grids'] . '; i++) { ' . "\n";
                            echo '                    obj = document.getElementById(\'' . $ime . '_grid_\'+i); ' . "\n";

                            echo '                    if (obj.checked || obj.disabled) ' . "\n";
                            echo '                        bol = true; ' . "\n";

                            echo '                } ' . "\n";
                            echo '                if (bol==false) totalBol = false; ' . "\n";

                            // tabela besedilo in tabela number
                        } elseif ($rowm['tip'] == 19 || $rowm['tip'] == 20) {

                            $ime = 'multi_' . $rowm['id'] . '_' . $row2['id'];

                            echo '                var bol = false; ' . "\n";
                            echo '                for (var i=1; i<=' . $rowm['grids'] . '; i++) { ' . "\n";
                            echo '                    obj = document.getElementById(\'' . $ime . '_grid_\'+i); ' . "\n";

                            echo '                    if (obj.value != "" || obj.disabled) ' . "\n";
                            echo '                        bol = true; ' . "\n";

                            echo '                } ' . "\n";
                            echo '                if (bol==false) totalBol = false; ' . "\n";

                        }
                    }

                    echo '                if (!totalBol) { ' . "\n";
                    echo '                  ' . $bol . ' = false; ' . "\n";
                    echo '                  submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '                } else {' . "\n";
                    echo '                  submitAlert(\'#vrednost_if_' . $row1['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                    echo '                }' . "\n";

                    echo '              } '."\n";;
                }
            // Lokacija - maps
            } elseif ($row['tip'] == 26) {

                $ime = 'vrednost_' . $row['id'] . '[]';

                echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                echo '              if (!obj) { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";

            // Heatmap
            } elseif ($row['tip'] == 27) {

                $ime = 'vrednost_' . $row['id'] . '[]';

                echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                echo '              if (!obj) { ' . "\n";
                echo '                ' . $bol . ' = false; ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } else { ' . "\n";
                echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'require\', \'' . $bol . '\', validation, false, false, false, false); ' . "\n";
                echo '              } ' . "\n";
            }

            // konec pogoja, ce je vprasanje vidno
            echo '            }     //-- if display != none ' . "\n";

            echo '           } catch (e) {} ' . "\n";

        }


        // Alert za EVOLI departmente
        if(SurveyInfo::getInstance()->checkSurveyModule('evoli_teammeter') 
            || SurveyInfo::getInstance()->checkSurveyModule('evoli_quality_climate')
            || SurveyInfo::getInstance()->checkSurveyModule('evoli_teamship_meter')
            || SurveyInfo::getInstance()->checkSurveyModule('evoli_organizational_employeeship_meter')
        )
            $evoli_teammeter = true;
        else
            $evoli_teammeter = false;

        if($evoli_teammeter){
            echo '              var obj = document.forms[\'vnos\'].elements[\'evoli_tm_department\']; ' . "\n";

            echo '              if (typeof(obj) != "undefined" && obj != null) { ' . "\n";

            echo '                  if (obj.value == 0) { ' . "\n";
            echo '                    hard = false; ' . "\n";
            echo '                    submitAlert(\'#spremenljivka_evoli_tm_department\', \'add\', \'require\', \'hard\', validation, false, false, false, false); ' . "\n";
            echo '                  } else { ' . "\n";
            echo '                    submitAlert(\'#spremenljivka_evoli_tm_department\', \'remove\', \'require\', \'hard\', validation, false, false, false, false); ' . "\n";
            echo '                  } ' . "\n";

            echo '              } ' . "\n";
        }


        // posebno testiranje za vsoto in num ce smo presegli limit
        //$sql = sisplet_query("SELECT * FROM srv_spremenljivka WHERE gru_id='".get('grupa')."' AND vsota_reminder > 0 ORDER BY vrstni_red ASC");
        $sql = sisplet_query("SELECT * FROM srv_spremenljivka WHERE gru_id='" . get('grupa') . "'  AND gru_id != '0' AND (tip='18' OR tip='7' OR tip='20' OR tip='21') ORDER BY vrstni_red ASC");
        while ($row = mysqli_fetch_array($sql)) {

            if ($row['vsota_reminder'] > 0) {

                if ($row['vsota_reminder'] == 1) {
                    $bol_vsota = 'soft';
                } else {
                    $bol_vsota = 'hard';
                }

                // najprej damo pogoj, da se uposteva, samo ce je vprasanje vidno (ker je lahko v ifu)
                //echo '            if ( $(\'#spremenljivka_'.$row['id'].'\').css(\'display\') != \'none\' ) { '			."\n";
                echo '            if ( $(\'#spremenljivka_' . $row['id'] . '\').length && document.getElementById(\'spremenljivka_' . $row['id'] . '\').style.display != \'none\' ) { ' . "\n";

                // vsota
                if ($row['tip'] == 18) {
                    $ime = 'spremenljivka_' . $row['id'] . '_vsota';
					
                    echo '              var obj = document.forms[\'vnos\'].elements[\'' . $ime . '\']; ' . "\n";
                    echo '              if ( (obj.value > ' . $row['vsota_limit'] . ' && !$(obj).hasClass("def") && ' . $row['vsota_limit'] . ' != 0) || (obj.value < ' . $row['vsota_min'] . ' && !$(obj).hasClass("def") && ' . $row['vsota_min'] . ' != 0) ){ ' . "\n";
                    echo '               	' . $bol_vsota . ' = false;' . "\n";
                    echo '                	vsota = false; ' . "\n";
                    echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'limit\', \'' . $bol_vsota . '\', validation, false, true, false, false); ' . "\n";
                    echo '              } else { ' . "\n";
                    echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'limit\', \'' . $bol_vsota . '\', validation, false, true, false, false); ' . "\n";
                    echo '              } ' . "\n";

                } // multinumber
                elseif ($row['tip'] == 20) {

                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";

                    $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id='$row[id]' ORDER BY vrstni_red");
                    while ($row1 = mysqli_fetch_array($sql1)) {
                        $ime = 'vrednost_' . $row1['id'];

                        echo '                var bol = false; ' . "\n";

                        echo '                for (var i=1; i<=' . $row['grids'] . '; i++) { ' . "\n";
                        echo '                    obj = document.getElementById(\'' . $ime . '_grid_\'+i); ' . "\n";

                        if ($row['num_useMax'] == 1) {
                            echo '              if (obj.value > ' . $row['vsota_limit'] . ' && obj.value != \'\' && ' . $row['num_useMax'] . ' == 1){ ' . "\n";
                            echo '               	' . $bol_vsota . ' = false; ' . "\n";
                            echo '                	num = false; ' . "\n";
                            echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                            echo '              } ' . "\n";
                        }

                        if ($row['num_useMin'] == 1) {
                            echo '              if (obj.value < ' . $row['vsota_min'] . ' && obj.value != \'\'){ ' . "\n";
                            echo '               	' . $bol_vsota . ' = false; ' . "\n";
                            echo '                	num = false; ' . "\n";
                            echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                            echo '              } ' . "\n";
                        }

                        echo '                } ' . "\n";
                    }
                } 
				// number in text
                else {
                    //za text se ne gleda value amapak value.length
                    $length = $row['tip'] == 21 ? '.length' : '';
                    $num_var = $row['tip'] == 21 ? 'text_' : '';
                    
                    $ime = 'spremenljivka_' . $row['id'] . '_vrednost_1';

                    ///echo '              var obj = document.forms[\'vnos\'].elements[\''.$ime.'\']; '					."\n";
                    echo '                var obj = document.getElementById(\'' . $ime . '\'); ' . "\n";

                    echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";

                    if ($row['num_useMax'] == 1) {
                        echo '              if (obj.value'.$length.' > ' . $row['vsota_limit'] . ' && obj.value != \'\' && ' . $row['num_useMax'] . ' == 1){ ' . "\n";
                        echo '               	' . $bol_vsota . ' = false; ' . "\n";
                        echo '                	'.$num_var.'num = false; ' . "\n";
                        echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                        //echo '              } else { '																		."\n";
                        //echo '                  $(\'#spremenljivka_'.$row['id'].'\').removeClass(\'required\'); '			."\n";
                        echo '              } ' . "\n";
                    }

                    if ($row['num_useMin'] == 1) {
                        echo '              if (obj.value'.$length.' < ' . $row['vsota_min'] . ' && obj.value != \'\'){ ' . "\n";
                        echo '               	' . $bol_vsota . ' = false; ' . "\n";
                        echo '                	'.$num_var.'num = false; ' . "\n";
                        echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                        //echo '              } else { '																		."\n";
                        //echo '                  $(\'#spremenljivka_'.$row['id'].'\').removeClass(\'required\'); '			."\n";
                        echo '              } ' . "\n";
                    }

                    if ($row['size'] > 1) {
                        $ime = 'spremenljivka_' . $row['id'] . '_vrednost_2';

                        //echo '              var obj = document.forms[\'vnos\'].elements[\''.$ime.'\']; '				."\n";
                        echo '              var obj = document.getElementById(\'' . $ime . '\'); ' . "\n";

                        echo '                submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";

                        if ($row['num_useMax2'] == 1) {
                            echo '              if (obj.value'.$length.' > ' . $row['num_max2'] . ' && obj.value != \'\'){ ' . "\n";
                            echo '               	' . $bol_vsota . ' = false; ' . "\n";
                            echo '                	'.$num_var.'num = false; ' . "\n";
                            echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                            //echo '              } else { '																		."\n";
                            //echo '                  $(\'#spremenljivka_'.$row['id'].'\').removeClass(\'required\'); '			."\n";
                            echo '              } ' . "\n";
                        }

                        if ($row['num_useMin2'] == 1) {
                            echo '              if (obj.value'.$length.' < ' . $row['num_min2'] . ' && obj.value != \'\'){ ' . "\n";
                            echo '               	' . $bol_vsota . ' = false; ' . "\n";
                            echo '                	'.$num_var.'num = false; ' . "\n";
                            echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \''.$num_var.'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                            //echo '              } else { '																		."\n";
                            //echo '                  $(\'#spremenljivka_'.$row['id'].'\').removeClass(\'required\'); '			."\n";
                            echo '              } ' . "\n";
                        }
                    }

                    if($row['tip'] == 7){
                        //Alert za mobile slider *************************************
                        echo '
                                                            //console.log(' . $row['ranking_k'] . ');
                                                            //console.log(' . $row['id'] . ');
                                            ';

                        if ($row['ranking_k'] == '1' && get('mobile') != 0) {
                            echo '
                                                            //console.log(' . $row['ranking_k'] . ');
                                                            //console.log(' . $row['id'] . ');
                                            ';

                            $slider_MaxNumLabel = ($spremenljivkaParams->get('slider_MaxNumLabel') ? $spremenljivkaParams->get('slider_MaxNumLabel') : 100);

                            echo '              if (obj.value > ' . $slider_MaxNumLabel . ' && obj.value != \'\'){ ' . "\n";
                            echo '               	' . $bol_vsota . ' = false; ' . "\n";
                            echo '                	num = false; ' . "\n";
                            echo '                  submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'limit\', \'' . $bol_vsota . '\', validation, false, false, true, false); ' . "\n";
                            //echo '              } else { '																		."\n";
                            //echo '                  $(\'#spremenljivka_'.$row['id'].'\').removeClass(\'required\'); '			."\n";
                            echo '              } ' . "\n";
                        }
                    }
                }

                // konec pogoja, ce je vprasanje vidno
                echo '            }     //-- if display != none ' . "\n";

            }

        }
		
		
		// posebno testiranje ce respondent ni izbral minimalnega stevila checkbox-ov
        $sql = sisplet_query("SELECT * FROM srv_spremenljivka WHERE gru_id='" . get('grupa') . "' AND gru_id != '0' AND (tip='2') ORDER BY vrstni_red ASC");
		
        while ($row = mysqli_fetch_array($sql)) {
			$spremenljivkaParams = new enkaParameters($row['params']);
			$checkbox_min_limit = ($spremenljivkaParams->get('checkbox_min_limit') ? $spremenljivkaParams->get('checkbox_min_limit') : 0);
			$checkbox_min_limit_reminder = ($spremenljivkaParams->get('checkbox_min_limit_reminder') ? $spremenljivkaParams->get('checkbox_min_limit_reminder') : 0);
			
			if ($checkbox_min_limit > 0) {	//ce je minimalni limit nastavljen
				
				if ($checkbox_min_limit_reminder == 1) {
                    $bol_min_limit = 'soft';
                } else {
                    $bol_min_limit = 'hard';
                }
				
				// najprej damo pogoj, da se uposteva, samo ce je vprasanje vidno (ker je lahko v ifu)
				echo '            if ( document.getElementById(\'spremenljivka_' . $row['id'] . '\').style.display != \'none\' ) { ' . "\n";
				
					echo '            var checkbox_min_limit = '.$checkbox_min_limit.'; ' . "\n";
					echo '            var checkbox_min_limit_reminder = '.$checkbox_min_limit_reminder.'; ' . "\n";			
                    
                    //ce je checkbox in ni drag drop, preveri, koliko je oznacenih odgovorov
					if($row['tip'] == 2 && ($row['orientation'] != 8 || get('mobile') == 1)){	

						echo '            obj = document.forms[\'vnos\'].elements[\'vrednost_\'+'.$row['id'].'+\'[]\']; ' . "\n";
						echo '            var len = obj.length; ' . "\n";
						echo '            var count = 0; ' . "\n";
						echo '            for (i=0; i<len; i++){ ' . "\n";
						echo '            	if (obj[i].checked){ ' . "\n";
						echo '            		count++; ' . "\n";
						echo '            	} ' . "\n";
						echo '            } ' . "\n";
						echo '			if (count < checkbox_min_limit){ 
											checkbox_min_limit_alert = true;
											submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'checkbox_min_limit\', \'' . $bol_min_limit . '\', validation, false, true, false, false);
										}else{
											submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'checkbox_min_limit\', \'' . $bol_min_limit . '\', validation, false, true, false, false);
										} ' . "\n";
                    }
                    //ce je check box in drag drop, preveri, koliko je oznacenih odgovorov
                    elseif($row['tip'] == 2 && $row['orientation'] == 8){	
	 					echo '
							var prisotno = $("#half2_frame_dropping_' . $row['id'] . '").children("div").attr("value");
							var len = $("#half2_frame_dropping_' . $row['id'] . '").children().length;
							
							if(len < checkbox_min_limit){
								checkbox_min_limit_alert = true;								
								submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'add\', \'checkbox_min_limit\', \'' . $bol_min_limit . '\', validation, false, true, false, false);
							}else{
								submitAlert(\'#spremenljivka_' . $row['id'] . '\', \'remove\', \'checkbox_min_limit\', \'' . $bol_min_limit . '\', validation, false, true, false, false);
							}							
						';		
					}
				// konec pogoja, ce je vprasanje vidno
				echo '}     //-- if display != none ' . "\n";
			}
		}
		
		
        if (isset($_GET['disableif']) && $_GET['disableif'] == 1) {
            echo '           vsota = true; ' . "\n";
            echo '           hard = true;  ' . "\n";
            echo '           soft = true;  ' . "\n";
        }

        echo ' if ( validation ) {    ';

        // validacija
        $sqlv = sisplet_query("SELECT v.* FROM srv_validation v, srv_spremenljivka s WHERE v.spr_id=s.id AND s.gru_id='" . get('grupa') . "' AND s.gru_id != '0' AND v.reminder>'0'");
        while ($rowv = mysqli_fetch_array($sqlv)) {

			if ($rowv['reminder'] == 1) {
                $bol = 'soft';
            } else {
                $bol = 'hard';
            }

			// Ce imamo vklopljene napredne parapodatke zabelezimo opozorilo
	        if(SurveyAdvancedParadataLog::getInstance()->paradataEnabled()){
				echo 'odstrani_opozorilo(\'#spremenljivka_' . $rowv['spr_id'] . '\', false, false, true); ';
			}       
			
			echo 'submitAlert(\'#spremenljivka_' . $rowv['spr_id'] . '\', \'remove\', \'validation\', \'' . $bol . '\', validation, false, false, false, true); '; 
        }
		
        if (mysqli_num_rows($sqlv) > 0) mysqli_data_seek($sqlv, 0);
		
        while ($rowv = mysqli_fetch_array($sqlv)) {
			if ($rowv['reminder'] == 1) {
			    $bol = 'soft';
			} else {
			    $bol = 'hard';
			}

			?>
			if ( <? $this->generateCondition($rowv['if_id']); ?> ) {

			<?
			// Ce imamo vklopljene napredne parapodatke zabelezimo opozorilo
			if (SurveyAdvancedParadataLog::getInstance()->paradataEnabled()){
				?>
					<?= ' dodaj_opozorilo_val(\'' . $bol . '\', \'#spremenljivka_' . $rowv['spr_id'] . '\'); ' ?>
				<?
			}?>

			<?=	' submitAlert(\'#spremenljivka_' . $rowv['spr_id'] . '\', \'add\', \'validation\', \'' . $bol . '\', validation, \'' . $rowv['reminder_text'] . '\', false, false, true); ' ?>

			}
			<?
        }

        echo '        } else {               ';
            
        //alert za preseg limita vsote
        echo '           if (!vsota) { ' . "\n";
        echo '            if (!hard) { ' . "\n";
        echo '              alert(\'' . $srv_remind_sum_hard . '\'); ' . "\n";
        echo '              return; ' . "\n";
        echo '            } else if (!soft) { ' . "\n";
        echo '              if (!confirm(\'' . $srv_remind_sum_soft . '\')) { ' . "\n";
        echo '                return; ' . "\n";
        echo '              } ' . "\n";
        echo '            } ' . "\n";
        echo '           } ' . "\n";

        //alert za preseg limita stevila
        echo '           if (!num) { ' . "\n";
        echo '            if (!hard) { ' . "\n";
        echo '              alert(\'' . $srv_remind_num_hard . '\'); ' . "\n";
        echo '              return; ' . "\n";
        echo '            } else if (!soft) { ' . "\n";
        echo '              if (!confirm(\'' . $srv_remind_num_soft . '\')) { ' . "\n";
        echo '                return; ' . "\n";
        echo '              } ' . "\n";
        echo '            }	' . "\n";
        echo '           } ' . "\n";
        
        //alert za preseg limita besedila
        echo '           if (!text_num) { ' . "\n";
        echo '            if (!hard) { ' . "\n";
        echo '              alert(\'' . $srv_remind_text_num_hard . '\'); ' . "\n";
        echo '              return; ' . "\n";
        echo '            } else if (!soft) { ' . "\n";
        echo '              if (!confirm(\'' . $srv_remind_text_num_soft . '\')) { ' . "\n";
        echo '                return; ' . "\n";
        echo '              } ' . "\n";
        echo '            }	' . "\n";
        echo '           } ' . "\n";
		
		//alert za premalo izbranih checkboxov
        echo '           if (checkbox_min_limit_alert) { ' . "\n";
        echo '            if (checkbox_min_limit_reminder == 2) { ' . "\n";
        echo '              alert(\'' . $srv_remind_checkbox_min_violated_hard . '\'); ' . "\n";
        echo '              return; ' . "\n";
        echo '            } else if (checkbox_min_limit_reminder == 1) { ' . "\n";
        echo '              if (!confirm(\'' . $srv_remind_checkbox_min_violated_soft . '\')) { ' . "\n";
        echo '                return; ' . "\n";
        echo '              } ' . "\n";
        echo '            }	' . "\n";
        echo '           } ' . "\n";

        //alert za ostale tipe
        echo '           if(text_num && num && vsota) {	' . "\n";
        echo '            if (!hard) { ' . "\n";
        echo '              if(\'' . $require . '\' == \'require2\') ' . "\n";
        echo '              	alert(\'' . $srv_remind_hard_99 . '\'); ' . "\n";
        echo '              else if(\'' . $require . '\' == \'require3\') ' . "\n";
        echo '              	alert(\'' . $srv_remind_hard_98 . '\'); ' . "\n";
        echo '              else if(\'' . $require . '\' == \'require4\') ' . "\n";
        echo '              	alert(\'' . $srv_remind_hard_97 . '\'); ' . "\n";
       
        // alert za posebno vprasanje za SURS anketo 113 (1ka.cdi.si)
        echo '              
            else if(\'' . $site_domain . '\' == \'1ka.cdi.si\' && \'' . $require . '\' == \'require5\' && \'' . $require . '\' == \'require5\' && $(\'#spremenljivka_18178\').length){
                
                if(!missing_hidden){
                    alert(\'' . $lang['srv_remind_hard2'] . '\');
                }

            } ' . "\n";
    
        echo '              else if(\'' . $require . '\' == \'require5\') ' . "\n";
        echo '              	alert(\'' . $srv_remind_hard_multi . '\'); ' . "\n";
        echo '              else ' . "\n";
        echo ' 		            alert(\'' . $srv_remind_hard . '\'); ' . "\n";
        echo '              return; ' . "\n";
        echo '            } else if (!soft) { ' . "\n";
        echo '              if(\'' . $require . '\' == \'require2\'){ ' . "\n";
        echo '             		if (!confirm(\'' . $srv_remind_soft_99 . '\')) { ' . "\n";
        echo '                		return; ' . "\n";
        echo '              	} ' . "\n";
        echo '              }else if(\'' . $require . '\' == \'require3\'){ ' . "\n";
        echo '             		if (!confirm(\'' . $srv_remind_soft_98 . '\')) { ' . "\n";
        echo '                		return; ' . "\n";
        echo '              	} ' . "\n";
        echo '              }else if(\'' . $require . '\' == \'require4\'){ ' . "\n";
        echo '             		if (!confirm(\'' . $srv_remind_soft_97 . '\')) { ' . "\n";
        echo '                		return; ' . "\n";
        echo '              	} ' . "\n";
        echo '              }else if(\'' . $require . '\' == \'require5\'){ ' . "\n";
        echo '             		if (!confirm(\'' . $srv_remind_soft_multi . '\')) { ' . "\n";
        echo '                		return; ' . "\n";
        echo '              	} ' . "\n";
        echo '              }else{ ' . "\n";
        echo '             		 if (!confirm(\'' . $srv_remind_soft . '\')) { ' . "\n";
        echo '                		return; ' . "\n";
        echo '              	} ' . "\n";
        echo '              } ' . "\n";
        echo '            }	' . "\n";
        echo '          } ' . "\n";


        // validacija
        $sqlv = sisplet_query("SELECT v.* FROM srv_validation v, srv_spremenljivka s WHERE v.spr_id=s.id AND s.gru_id='" . get('grupa') . "' AND s.gru_id != '0'");
        while ($rowv = mysqli_fetch_array($sqlv)) {

            ?>
            if ( <? $this->generateCondition($rowv['if_id']); ?> ) {

            <? if ($rowv['reminder'] == 1) {

                ?> $('#spremenljivka_<?= $rowv['spr_id'] ?>').addClass('required'); <?
                /*?> if ( ! confirm('<?= $rowv['reminder_text'] ?>') ) return; else $('#spremenljivka_<?= $rowv['spr_id'] ?>').removeClass('required'); <?*/
                /*?> console.log('Soft validacija se je sprozila za spremenljivko: <?= $rowv['spr_id'] ?>'); if ( ! confirm('<?= $rowv['reminder_text'] ?>') ) return; else $('#spremenljivka_<?= $rowv['spr_id'] ?>').removeClass('required'); <?*/
                ?> if ( ! confirm('<?= $rowv['reminder_text'] ?>') ) return; else $('#spremenljivka_<?= $rowv['spr_id'] ?>').removeClass('required'); <?

            } elseif ($rowv['reminder'] == 2) {

                ?> $('#spremenljivka_<?= $rowv['spr_id'] ?>').addClass('required'); <?
                /*?> alert('<?= $rowv['reminder_text'] ?>'); return; <?*/
                /*?> console.log('Hard validacija se je sprozila za spremenljivko: <?= $rowv['spr_id'] ?>'); alert('<?= $rowv['reminder_text'] ?>'); return; <?*/
                ?> alert('<?= $rowv['reminder_text'] ?>'); return; <?

            } ?>

            }
            <?

        }

        // preverjanje, da vnese inicialke
        $question_resp_comment_inicialke = SurveySetting::getInstance()->getSurveyMiscSetting('question_resp_comment_inicialke');
        $question_resp_comment_inicialke_alert = SurveySetting::getInstance()->getSurveyMiscSetting('question_resp_comment_inicialke_alert');
        if ($question_resp_comment_inicialke == 1 && $question_resp_comment_inicialke_alert == 2) {
            ?>
            if ( !check_inicialke() ) {
            alert('<?= $lang['srv_enter_inicialke'] ?>');
            preview_popup_open();
            return;
            }
            <?php
        } elseif ($question_resp_comment_inicialke == 1 && $question_resp_comment_inicialke_alert == 1) {
            ?>
            if ( !check_inicialke() ) {
            if ( !confirm('<?= $lang['srv_enter_inicialke2'] ?>') ) {
            preview_popup_open();
            return;
            }
            }
            <?php
        }

        echo '          if (parent_if == undefined) {  ' . "\n";

        // Ce imamo vklopljene napredne parapodatke zabelezimo cas post-a
        if(SurveyAdvancedParadataLog::getInstance()->paradataEnabled() && SurveyAdvancedParadataLog::getInstance()->collectPostTime()){
            echo 'logEvent(\'page\', \'unload_page\', function(){
                $("form[name=vnos]").submit(); 
            });';
        }
        else{
            echo '            $("form[name=vnos]").submit(); ' . "\n";
        }

        echo '          } else { ' . "\n";
        echo '            $.post($(\'form[name=vnos]\').attr(\'action\'), $(\'form[name=vnos]\').serialize(), function () { ' . "\n";
        echo '              $.post(\'' . $site_url . 'main/survey/ajax.php?a=grupa_for_if\', {anketa:' . get('anketa') . ', parent_if: parent_if}, function (data) { ' . "\n";
        echo '                window.location.href = \'' . SurveyInfo::getSurveyLink(false, false) . '&grupa=\'+data+\'' . Header::getSurveyParams() . get('cookie_url') . '\';       ' . "\n";
        echo '              }) ' . "\n";
        echo '            } ) 	' . "\n";
        echo '          } ' . "\n";

        // if validation else
        echo '          } ';

        echo '          } ' . "\n";
		//echo 'spr_id_indeks = 0; ' . "\n";	//za sledenje opozoril
        echo '        </script>	' . "\n";


        $sqlG = sisplet_query("SELECT spol FROM srv_glasovanje WHERE ank_id='" . get('anketa') . "'");
        $rowG = mysqli_fetch_array($sqlG);

        $sql1 = sisplet_query("SELECT MAX(vrstni_red) AS vrstni_red FROM srv_grupa WHERE ank_id = '" . get('anketa') . "'");
        $row1 = mysqli_fetch_array($sql1);

        $rowa = SurveyInfo::getInstance()->getSurveyRow();

        //namesto naprej in nazaj se pri glasovanju izrise gumb potrdi oz. gumba moski/zenska pri izbiri spola
        if ($rowa['survey_type'] == 0) {
			
            if (!get('printPreview')) {
                if ($rowG['spol'] == 0) {
					
					$srv_potrdi = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_potrdi'.$_lang);
					if ($srv_potrdi == '') $srv_potrdi = $lang['srv_potrdi'];
					
                    echo '  <div class="buttons">
							<input class="next" type="submit" value="' . $srv_potrdi . '" onclick="submitForm(); return false;">
							</div>' . "\n";
                } else {
                    echo '  <div class="buttons">
							<input class="next" type="submit" name="submit" value="' . $lang['glasovanja_spol_moski'] . '" onclick="submitForm(); return false;">
							<input class="next" type="submit" name="submit" value="' . $lang['glasovanja_spol_zenska'] . '" onclick="submitForm(); return false;">
							</div>' . "\n";
                }
            }

            //namesto naprej in nazaj izrise pri formi gumb poslji
        } elseif ($rowa['survey_type'] == 1) {

            SurveySetting::getInstance()->Init(get('anketa'));

            $srv_nextpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_forma_send' . $_lang);
            if ($srv_nextpage == '') $srv_nextpage = $lang['srv_forma_send'];

            if (!get('printPreview')) {
                echo '  <div class="buttons">';
                echo '	<input class="next" type="submit" value="' . $srv_nextpage . '" onclick="submitForm(); return false;">
						</div>' . "\n";
            }

        } else {

            SurveySetting::getInstance()->Init(get('anketa'));

            $row = SurveyInfo::getInstance()->getSurveyRow();
            $sqlg = sisplet_query("SELECT vrstni_red FROM srv_grupa WHERE ID = '" . get('grupa') . "'");
            $rowg = mysqli_fetch_array($sqlg);

			// Smo na zadnji strani
            if ($row1['vrstni_red'] == $rowg['vrstni_red']) {
		
				// Dodatno preverimo ce imamo loop
				if(isset($_GET['loop_id']) && $_GET['loop_id'] > 0){				
					
					// Ce obstaja naslednji loop izpisemo "naslednja stran" in ne "zadnja stran"
					if(Find::getInstance()->findNextLoopId() > 0){
						$srv_nextpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_nextpage' . $_lang);
						if ($srv_nextpage == '') $srv_nextpage = $lang['srv_nextpage'];
					}
					else{
						$srv_nextpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_lastpage' . $_lang);
						if ($srv_nextpage == '') $srv_nextpage = $lang['srv_lastpage'];					
					}
				}
				else{
					$srv_nextpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_lastpage' . $_lang);
					if ($srv_nextpage == '') $srv_nextpage = $lang['srv_lastpage'];
				}
            } 
			else {
                $srv_nextpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_nextpage' . $_lang);
                if ($srv_nextpage == '') $srv_nextpage = $lang['srv_nextpage'];
            }

            $srv_prevpage = SurveySetting::getInstance()->getSurveyMiscSetting('srvlang_srv_prevpage' . $_lang);
            if ($srv_prevpage == '') $srv_prevpage = $lang['srv_prevpage'];

            $display_backlink = SurveySetting::getInstance()->getSurveyMiscSetting('display_backlink');

            if (!get('printPreview')) {
                echo '<div class="buttons" id="buttons_gru_' . get('grupa') . '">';
                //echo '			<input class="prev" type="submit" value="'.$lang['srv_prevpage'].'" onclick="document.location.href=\'index.php?anketa='.get('anketa').''.($this->findPrevGrupa()>0?'&grupa='.$this->findPrevGrupa().'':'').get('cookie_url').'\'; return false;">
                if ($row['show_intro'] == 1 || $rowg['vrstni_red'] > 1) {
                    #echo '<input class="prev" type="button" value="'.$srv_prevpage.'" onclick="history.back()">';

                    if (!SurveyInfo::getInstance()->checkSurveyModule('slideshow')) {

                        // Posebej za WebSM anketo - back naredimo tako, da poiscemo prejsnjo stran
                        if (get('anketa') == get('webSMSurvey') && Common::checkModule('websmsurvey') == '1') {

                            $grupa = Find::findPrevGrupa();
                            $grupa = ($grupa > 0) ? '&grupa=' . $grupa : '';

                            $lang_s = (isset($_GET['language'])) ? '&language=' . $_GET['language'] : '';
                            $language = save('language', $lang_s, 1);

                            $link = SurveyInfo::getSurveyLink(false, false) . $grupa . $language;

                            echo '<input class="prev" type="button" value="' . $srv_prevpage . '" onclick="location.href=\'' . $link . '\';">';
                        } elseif ($display_backlink != '0') {
                            echo '<input class="prev" type="button" value="' . $srv_prevpage . '" onclick="javascript:history.go(-1)">';
                        }
                    } else {

                        # če smo v slideshowu prikazujemo gumb nazaj ali naprej na zahtevo
                        $ss = new SurveySlideshow(get('anketa'));
                        $ss_setings = $ss->getSettings();

                        if ($ss_setings['back_btn'] == 1) {
                            echo '<input class="prev" type="button" value="' . $srv_prevpage . '" onclick="javascript:history.go(-1)">';
                        }
                    }
                }

                if (SurveyInfo::getInstance()->checkSurveyModule('slideshow')) {
                    # če smo v prezentaciji in imamo nastavljen pause button
                    $ss = new SurveySlideshow(get('anketa'));
                    $ss_setings = $ss->getSettings();

                    if ($ss_setings['pause_btn'] == 1) {
                        echo '<input id="btn_pause_on" class="pause" type="button" value="' . $lang['srv_slideshow_btn_pause_on'] . '" onclick="slide_timer_pause_ON();">';
                        echo '<input id="btn_pause_off" class="pause display_none" type="button" value="' . $lang['srv_slideshow_btn_pause_off'] . '" onclick="slide_timer_pause_OFF();">';
                    }
                }
                if (!SurveyInfo::getInstance()->checkSurveyModule('slideshow')) {
                    echo ' <input class="next" type="submit" value="' . $srv_nextpage . '" onclick="submitForm(); return false;">';
                } else {
                    # če smo v slideshowu prikazujemo gumb nazaj ali naprej na zahtevo
                    $ss = new SurveySlideshow(get('anketa'));
                    $ss_setings = $ss->getSettings();
                    if ($ss_setings['next_btn'] == 1) {
                        echo ' <input class="next" type="submit" value="' . $srv_nextpage . '" onclick="submitForm(); return false;">';
                    }
                }

                echo '</div>' . "\n";
            }
        }
    }

    /**
     * @desc poklice generatorje JS kode za branching
     */
    public function generateBranchingJS()
    {
        echo '<script> ' . "\n";

        echo '  function checkBranching () { ' . "\n";

        $this->generateComputeJS();

        // ce je preverjanje pogojev izklopljeno
        if (!isset($_GET['disableif']) || $_GET['disableif'] != 1) {

            $this->generateBranching();

            $this->generateVrednostIf();
        }

        // sprotna validacija v balonckih
        echo '      submitForm(undefined, true);                ';
        
        // Popravek footerja pri temi Bled
        $row = SurveyInfo::getSurveyRow();
        if($row['skin'] == 'Bled'){
            echo '      footerBled(); ' . "\n";
        }

        echo '  }  //-- function checkBranching() ' . "\n";

		
        echo '  checkBranching(); ' . "\n";

        echo '</script> ' . "\n";     
    }

    /**
     * zgenerira koda za compute spremenljivke, ki si vrednost napolnijo samodejno iz calculation izraza
     *
     */
    public function generateComputeJS()
    {

        if (get('generateComputeJS') != '') {

            echo 'try { ' . "\n";
            echo '  ' . get('generateComputeJS') . "\n";
            echo '} catch (e) {} ' . "\n";
        }

    }

    /**
     * za podano spremenljivko zgenerira compute kodo, ki se shrani v začasno spremenljivko, da se na koncu izpiše s funkcijo generateComputeJS()
     *
     * @param mixed $spremenljivka
     */
    public function generateCompute($spremenljivka)
    {

        // vrednost kalkulacije za ife
        add('generateComputeJS', "document.getElementById('vrednost_" . $spremenljivka . "').value = " . $this->generateCalculationJS(-$spremenljivka) . "; \n\r");

        // vrednost se zapise v class .data-piping-SPR_ID za data-piping da se v zivo refresha
        add('generateComputeJS', " var val; if ( ! isNaN(document.getElementById('vrednost_" . $spremenljivka . "').value) ) val = document.getElementById('vrednost_" . $spremenljivka . "').value; else val = ''; \n\r");
        add('generateComputeJS', " $('.data-piping-$spremenljivka').html( val ); \n\r");
    }

    /**
     * @desc zgenerira kodo za IFe na vrednostih (podifi)
     */
    public function generateVrednostIf()
    {

        SurveySetting::getInstance()->Init(get('anketa'));
        $mobile_tables = SurveySetting::getInstance()->getSurveyMiscSetting('mobile_tables');

        $sql = sisplet_query("SELECT v.*, s.tip AS tip, s.id AS spr_id, s.dynamic_mg AS dynamic_mg, s.vsota_limit, s.design, s.params FROM srv_vrednost v, srv_spremenljivka s WHERE v.if_id>'0' AND v.spr_id=s.id AND s.gru_id='" . get('grupa') . "' AND s.gru_id != '0'");
        while ($row = mysqli_fetch_array($sql)) {

            // Ce je odgovor skrit ga nikoli ne prikazemo in preskocimo kar celotno proceduro za to vrednost
            if($row['hidden'] == '1'){
                continue;
            }

            //stavek za pobiranje informacij o tipu in orienataciji spremenljivke, potrebno za nadaljnje notranje pogoje za drag and drop
            $sqldd = sisplet_query("SELECT id, enota, orientation FROM srv_spremenljivka WHERE id = '$row[spr_id]'");
            while ($rowdd = mysqli_fetch_array($sqldd)) {
                $spremenljivka_dd = $rowdd['id'];
                $orientation_dd = $rowdd['orientation'];
                $enota_dd = $rowdd['enota'];
            }

            // vsota - treba je se enkrat pognati racunanje
            if ($row['tip'] == 18) {
                $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE spr_id = '$row[spr_id]' AND vrstni_red>0");
                $max = mysqli_num_rows($sql1);
                $sum = '   calcSum(\'' . $row['spr_id'] . '\', \'' . $max . '\', \'' . $row['vsota_limit'] . '\'); ' . "\n";
            } 
            else
                $sum = '';


            // dinamicni multigrid (za mobilne naprave)
            if ($row['tip'] == 6 && $enota_dd != 9 && $enota_dd != 3 && $row['dynamic_mg'] > 0) {

                echo ' try { 																										' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   dynamicMultigridSwitchIf(1, ' . $row['id'] . ', ' . $row['spr_id'] . '); ' . "\n";

                echo '  } else { ' . "\n";

                echo '   dynamicMultigridSwitchIf(0, ' . $row['id'] . ', ' . $row['spr_id'] . '); ' . "\n";

                echo '  } ' . "\n";

                echo ' } catch (e) {} ' . "\n";
            }
            // Navaden multigrid
            else if ($row['tip'] == 6 && $enota_dd != 9 && $enota_dd != 3)  {
                                
                echo ' try { 																										' . "\n";
                
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                // Element je viden
                echo '  document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                echo '  var el = document.getElementById("branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '")' . "\n";
                echo '  el.parentNode.removeChild( el );' . "\n";

                // Element ni viden
                echo '  } else { ' . "\n";

                // ker je element neviden, dodamo novega hidz vrednostjo -2
                echo '  var el = document.getElementById(\'vrednost_if_' . $row['id'] . '\');' . "\n";
                echo '  var hiddenEl = document.getElementById("branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '")' . "\n";
                echo '  var parent = el.parentNode.parentNode.parentNode;' . "\n";
               
                // V kolikor je hidden polje že postavljeno potem ga ponovno ne ustvarjamo -> se izognemo podvojenim vpisom v bazi
                echo '  if(!hiddenEl){' . "\n"; 
                echo        'var newElement = document.createElement(\'input\');' . "\n";
                echo '      newElement.setAttribute("id", "branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '");' . "\n";
                echo '      newElement.setAttribute("name", "cond_vrednost_' . $row['id'] . '");' . "\n";
                echo '      newElement.setAttribute("value", "-2");' . "\n";
                echo '      newElement.setAttribute("type", "hidden");' . "\n";
                echo '      parent.appendChild(newElement);' . "\n";
                echo '  }' . "\n";

                echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                echo '  } ' . "\n";

                echo ' } catch (e) {} ' . "\n";
            }
            // checkbox in ne drag and drop
            else if ($row['tip'] == 2 && ($row['orientation'] != 8 || get('mobile') == 1)) {

                if ($spremenljivka_dd == $row['spr_id'] && ($orientation_dd == 8 || $enota_dd == 9)) {//ce je drag and drop
                    echo ' try {																									' . "\n";
                    echo '  if ( ';
                    $this->generateCondition($row['if_id']);
                    echo ' ) { ' . "\n";

                    echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                    echo '  } else { ' . "\n";
                    echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                    echo '  } ' . "\n";

                    echo ' } catch (e) {} ' . "\n";
                } 
                else {
                    echo ' try { 																										' . "\n";
                    
                    echo '  if ( ';
                    $this->generateCondition($row['if_id']);
                    echo ' ) { ' . "\n";

                    // Element je viden
                    echo '  document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                    echo '  var el = document.getElementById("branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '")' . "\n";
                    echo '  el.parentNode.removeChild( el );' . "\n";

                    // Element ni viden
                    echo '  } else { ' . "\n";

                    // ker je element neviden, dodamo novega hidz vrednostjo -2
                    echo '  var el = document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\');' . "\n";
                    echo '  var hiddenEl = document.getElementById("branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '")' . "\n";
                    echo '  var parent = el.parentNode.parentNode.parentNode;' . "\n";
                   
                    // V kolikor je hidden polje že postavljeno potem ga ponovno ne ustvarjamo -> se izognemo podvojenim vpisom v bazi
                    echo '  if(!hiddenEl){' . "\n"; 
                    echo        'var newElement = document.createElement(\'input\');' . "\n";
                    echo '      newElement.setAttribute("id", "branch_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '");' . "\n";
                    echo '      newElement.setAttribute("name", "cond_vrednost_' . $row['spr_id'] . '[]");' . "\n";
                    echo '      newElement.setAttribute("value", "' . $row['id'] . '");' . "\n";
                    echo '      newElement.setAttribute("type", "hidden");' . "\n";
                    echo '      parent.appendChild(newElement);' . "\n";
                    echo '  }' . "\n";

                    echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                    echo '  } ' . "\n";

                    echo $sum;

                    echo ' } catch (e) {} ' . "\n";
                }

            } 
            // roleta - desktop
            else if ($row['tip'] == 3 && get('mobile') == 0) {
                echo ' try { 																										' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   document.getElementById(\'vrednost_' . $row['spr_id'] . '_chzn_o_' . $row['vrstni_red'] . '\').style.display = \'\'; ' . "\n";

                echo '  } else { ' . "\n";
                echo '   document.getElementById(\'vrednost_' . $row['spr_id'] . '_chzn_o_' . $row['vrstni_red'] . '\').style.display = \'none\'; ' . "\n";

                echo '  } ' . "\n";

                echo $sum;

                echo ' } catch (e) {} ' . "\n";
            } 
            // roleta - mobile ali tablica
            else if ($row['tip'] == 3 && get('mobile') != 0) {
                echo ' try { 																				' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                echo '  } else { ' . "\n";
                echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                echo '  } ' . "\n";

                echo $sum;

                echo ' } catch (e) {} ' . "\n";
            } 
            // ranking premikanje
            else if ($row['tip'] == 17 && $row['design'] == 2 && get('mobile') == '0') {
                echo ' try { 																										' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                echo '  } else { ' . "\n";
                
                echo '   $(\'#spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').hide(); ' . "\n";                 
                echo '   $(\'#frame_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').hide(); ' . "\n";                 

                echo '  } ' . "\n";

                echo $sum;

                echo ' } catch (e) {} ' . "\n";
            } 
            // ranking prestavljanje
            else if ($row['tip'] == 17 && $row['design'] == 0 && get('mobile') == '0') {
                
                echo ' try { 																										' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'\'; ' . "\n";
                
                echo '  } else { ' . "\n";
                
                echo '   $(\'#spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').hide(); ' . "\n";                 
                echo '   $(\'#frame_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').hide(); ' . "\n";                 

                echo '  } ' . "\n";


                // Pri rankingu prestejemo in skrijemo tudi prazne okvirje na desni
                // Prestejemo skrite
                echo ' var count = $(\'#prestavljanje_'.$row['spr_id'].'\').find(\'.ranking:hidden\').length;   ' . "\n"; 

                // Prikazemo vse
                echo ' $(\'#prestavljanje_'.$row['spr_id'].'\').find(\'.dropholder\').find(\'ul li\').show();   ' . "\n"; 

                // Skrijemo toliko okvirjev kolikor je skritih elementov
                echo ' for(var i=0; i<count; i++){ $(\'#prestavljanje_'.$row['spr_id'].'\').find(\'.dropholder\').find(\'ul li:visible\').last().hide(); }' . "\n"; 


                echo $sum;

                echo ' } catch (e) {} ' . "\n";
            } 
            // ranking ostevilcevanje
            else if ($row['tip'] == 17 && ($row['design'] == 1 || get('mobile') != '0')) {

                echo ' try { 																										' . "\n";
                echo '  if ( ';
                $this->generateCondition($row['if_id']);
                echo ' ) { ' . "\n";

                echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                echo '  } else { ' . "\n";
                echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                echo '  } ' . "\n";


                // Pri rankingu prestejemo in skrijemo tudi odvecne vrednosti v dropdownu
                // Prestejemo vidne
                echo ' var count_visible = $(\'#spremenljivka_'.$row['spr_id'].'\').find(\'.variabla:visible\').length;   ' . "\n"; 

                // Na novo napolnimo select
                echo ' $(\'#spremenljivka_'.$row['spr_id'].'\').find(\'select\').empty()' . "\n"; 
                echo ' $(\'#spremenljivka_'.$row['spr_id'].'\').find(\'select\').append(\'<option></option>\')' . "\n"; 
                echo ' for(var i=1; i<=count_visible; i++){ $(\'#spremenljivka_'.$row['spr_id'].'\').find(\'select\').append(\'<option value="\'+i+\'">\'+i+\'</option>\'); }' . "\n"; 


                echo $sum;

                echo ' } catch (e) {} ' . "\n";
            }
            else {
                if ($spremenljivka_dd == $row['spr_id'] && ($orientation_dd == 8 || $enota_dd == 9)) {//ce je drag and drop
                    echo ' try {																									' . "\n";
                    echo '  if ( ';
                    $this->generateCondition($row['if_id']);
                    echo ' ) { ' . "\n";

                    echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                    echo '  } else { ' . "\n";
                    echo '   document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                    echo '  } ' . "\n";

                    echo $sum;

                    echo ' } catch (e) {} ' . "\n";
                } 
                else {
                    echo ' try { 																										' . "\n";
                    echo '  if ( ';
                    $this->generateCondition($row['if_id']);
                    echo ' ) { ' . "\n";

                    echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'\'; ' . "\n";

                    echo '  } else { ' . "\n";
                    echo '   document.getElementById(\'vrednost_if_' . $row['id'] . '\').style.display = \'none\'; ' . "\n";

                    echo '  } ' . "\n";

                    echo $sum;

                    echo ' } catch (e) {} ' . "\n";
                }
            }

            // Po notranjih pogojih prikazemo ponavljanje naslovne vrstice za tabele ce je to vklopljeno
            if($row['tip'] == 6 || $row['tip'] == 16){

                $spremenljivkaParams = new enkaParameters($row['params']);
                $grid_repeat_header = ($spremenljivkaParams->get('grid_repeat_header') ? $spremenljivkaParams->get('grid_repeat_header') : 0);        
                
                if($grid_repeat_header > 0){
                    echo ' gridRepeatHeader(\''.$grid_repeat_header.'\', \''.$row['spr_id'].'\'); ';
                }
            }
        }
    }

    /**
     * @desc zgenerira kodo za branching
     */
    public function generateBranching($parent = 0)
    {
        Cache::cache_all_srv_branching(get('anketa'));
        Cache::cache_all_srv_if(get('anketa'));

        foreach (Cache::srv_branching_parent(get('anketa'), $parent) AS $k => $row) {

            if ($row['element_if'] > 0) {

                $rowb = Cache::srv_if($row['element_if']);

                // build conditions
                //echo 'console.log("V generateBranching");';
                echo ' try { ' . "\n";
				
                echo '  if (';

                if ($rowb['tip'] == 0) {    // if

                    if ($rowb['enabled'] == 1)
                        echo 'true';
                    elseif ($rowb['enabled'] == 2)
                        echo 'false';
                    else
                        $this->generateCondition($row['element_if']);

                } else {    // blok

                    if ($rowb['enabled'] != 2)
                        echo 'true';
                    else
                        echo 'false';

                }
                echo '  ) { ' . "\n";

                // ko prikazujemo, prikazemo samo trenutni nivo
                foreach (Cache::srv_branching_parent(get('anketa'), $row['element_if']) AS $k1 => $row1) {

                    if ($row1['element_spr'] > 0) {

                        if (Helper::getGrupa($row1['element_spr']) == get('grupa')) {

                            $rowc = Model::select_from_srv_spremenljivka($row1['element_spr']);
                            if ($rowc['tip'] != 22 && $rowc['tip'] != 25) { // spremenljivka tipa compute in quota je izvzeta iz pogojev

                                echo '      try { ' . "\n";
                                echo '        document.getElementById(\'spremenljivka_' . $row1['element_spr'] . '\').style.display = "block"; ' . "\n";
                                echo '        document.getElementById(\'visible_' . $row1['element_spr'] . '\').value = \'1\'; ' . "\n";
                               
                                // Dodamo class da je vprasanje v bloku
                                echo '			$(\'#spremenljivka_' . $row1['element_spr'] . '\').addClass(\'block_child\'); ' . "\n";

                                // Dodamo class ce je vprasanje v bloku in je prikazano horizontalno
                                if (Helper::checkParentHorizontal($row1) == 1) {
                                    echo '			$(\'#spremenljivka_' . $row1['element_spr'] . '\').addClass(\'horizontal_block\'); ' . "\n";
                                }
                                // Dodamo class ce je vprasanje v bloku in je prikazano z razpiranjem
                                if (Helper::checkParentHorizontal($row1) == 2) {
                                    echo '			$(\'#spremenljivka_' . $row1['element_spr'] . '\').addClass(\'expendable_block\'); ' . "\n";
                                }

                                // Dodamo class z id-jem bloka
                                echo '			$(\'#spremenljivka_' . $row1['element_spr'] . '\').addClass(\'block_child_'.$row['element_if'].'\'); ' . "\n";
                                
                                
                                //Uros - samo za tip 26
                                //ker se mapa ne kreira vredu, ce je hidden, jo je ob prikazu treba resizat ter nastavit bounds mape
                                echo '        
                                    if('.$rowc['tip'].' == 26){
                                        //resize map, ker je zaradi display=none postala velika 0
                                        var map = document.getElementById("map_"+' . $row1['element_spr'] . ').gMap;
                                        google.maps.event.trigger(map, \'resize\');
                                        //ce je 0 ali 1 marker, centriraj kot nastavi admin, drugace prilagodi markerjem
                                        if (st_markerjev[' . $row1['element_spr'] . '] == 0){
                                            if(map.centerInMapKoordinate){
                                                map.setCenter({lat:  parseFloat(map.centerInMapKoordinate.center.lat), 
                                                    lng:  parseFloat(map.centerInMapKoordinate.center.lng)});
                                            }
                                            else
                                                centrirajMap(map.centerInMap, map);
                                        }
                                        else
                                            map.fitBounds(bounds[' . $row1['element_spr'] . ']);
                                    }';
                                
                                echo '      } catch (e) {} ' . "\n";

                            }
                        }

                    }
                }

                $this->generateBranching($row['element_if']);
				
				// Ce imamo vklopljen modul panel moramo nastaviti status panelista glede na izpolnjen if
				if(SurveyInfo::checkSurveyModule('panel') == 1){
					
					$sp = new SurveyPanel(get('anketa'));
					$panel_if = $sp->getPanelIf($row['element_if']);
					
					if($panel_if != ''){
						echo '$(\'#panel_status\').val(\''.$panel_if.'\'); ' . "\n";
					}
				}

                echo '  } else { ' . "\n";

                // ko skrivamo, skrijemo vse (tudi podnivoje) (zato klic rekurzivne funkcije)
                foreach (Helper::getElements($row['element_if']) AS $key) {

                    if (Helper::getGrupa($key) == get('grupa')) {

                        $rowc = Model::select_from_srv_spremenljivka($key);
                        if ($rowc['tip'] != 22 && $rowc['tip'] != 25) { // spremenljivka tipa compute in quota je izvzeta iz pogojev

                            echo '      try { ' . "\n";
                            echo '        document.getElementById(\'spremenljivka_' . $key . '\').style.display = "none"; ' . "\n";
                            echo '        document.getElementById(\'visible_' . $key . '\').value = \'0\'; ' . "\n";
                           
                            // Dodamo class da je vprasanje v bloku
                            echo '			$(\'#spremenljivka_' . $row1['element_spr'] . '\').addClass(\'block_child\'); ' . "\n";

                            // Dodamo class ce je vprasanje v bloku in je prikazano horizontalno
                            if (Helper::checkParentHorizontal($row) == 1) {
                                echo '			$(\'#spremenljivka_' . $key . '\').addClass(\'horizontal_block\'); ' . "\n";
                            }
                            // Dodamo class ce je vprasanje v bloku in je prikazano z razpiranjem
                            if (Helper::checkParentHorizontal($row) == 2) {
                                echo '			$(\'#spremenljivka_' . $key . '\').addClass(\'expendable_block\'); ' . "\n";
                            }

                            // Dodamo class z id-jem bloka
                            echo '			$(\'#spremenljivka_' . $key . '\').addClass(\'block_child_' . $row['element_if'] . '\'); 			' . "\n";
                            echo '      } catch (e) {} ' . "\n";

                        }
                    }
                }

                echo '  } ' . "\n";

                echo ' } catch (e) {} ' . "\n";


                // RANDOMIZACIJA VSEBINE BLOKA
                // Randomiziramo vprasanja v bloku (ce imamo to vklopljeno)
                if ($rowb['random'] >= 0) {

                    $questions = [];

                    foreach (Cache::srv_branching_parent(get('anketa'), $rowb['id']) AS $key => $val) {
                        if ($val['element_spr'] > 0) {
                            $questions[] = $val['element_spr'];
                        }
                    }

                    // Ce imamo nastavljen prikaz samo dolocenega stevila vprasanj
                    $spr_count = ($rowb['random'] > 0) ? $rowb['random'] : count($questions);

                    // Napolnimo seed za posameznega respondenta (da dobi vsakic isti vrstni red)
                    mt_srand((int)get('usr_id') + (int)$rowb['id']);

                    // Zgeneriramo random vrstni red
                    $order = array_map(function($val){return mt_rand();}, range(1, count($questions)));
                    array_multisort($order, $questions);

                    $order_in_block = json_encode($questions);

                    echo ' blockRandomizeQuestions(\''.$rowb['id'].'\', \''.$order_in_block.'\', \''.get('usr_id').'\', \''.$spr_count.'\');	' . "\n";
                }
                // Randomiziramo bloke v bloku (ce imamo to vklopljeno)
                elseif ($rowb['random'] == -2) {

                    $blocks = [];

                    foreach (Cache::srv_branching_parent(get('anketa'), $rowb['id']) AS $key => $val) {
                        if ($val['element_if'] > 0) {

                            $if_el = Cache::srv_if($val['element_if']);

                            // blok
                            if ($if_el['tip'] == 1) {
                                $blocks[] = $if_el['id'];
                            }
                        }
                    }

                    // Napolnimo seed za posameznega respondenta (da dobi vsakic isti vrstni red)
                    mt_srand((int)get('usr_id') + (int)$rowb['id']);

                    // Zgeneriramo random vrstni red
                    $order = array_map(function($val){return mt_rand();}, range(1, count($blocks)));
                    array_multisort($order, $blocks);

                    $order_in_block = json_encode($blocks);

                    echo ' blockRandomizeBlocks(\'' . $rowb['id'] . '\', \'' . $order_in_block . '\', \'' . get('usr_id') . '\');	' . "\n";
                }
            }            
        }

        // dodamo crte pri blokih, kjer so vprasanja postavljena horizontalno
        echo ' blockHorizontalLine();	' . "\n";
    }

    /**
     * @desc zgenerira pogoje za JS branching
     */
    public function generateCondition($if)
    {
        $rowa = SurveyInfo::getInstance()->getSurveyRow();

		$echo = '';
        $sql = Cache::srv_condition($if);
        if (!$sql) echo mysqli_error($GLOBALS['connect_db']);

        $i = 0;
        while ($row = mysqli_fetch_array($sql)) {

            if ($i++ != 0)
                if ($row['conjunction'] == 0)
                    $echo .= ' && ';
                else
                    $echo .= ' || ';

            if ($row['negation'] == 1)
                $echo .= ' ! ';

            for ($i = 1; $i <= $row['left_bracket']; $i++)
                $echo .= ' ( ';

            // obicajne spremenljivke
            if ($row['spr_id'] > 0) {

                $row2 = Model::select_from_srv_spremenljivka($row['spr_id']);

                // obicne spremenljivke
                if ($row['vre_id'] == 0) {
                    $row1 = Model::select_from_srv_spremenljivka($row['spr_id']);
                    // multigrid
                } elseif ($row['vre_id'] > 0) {
                    $sql1 = sisplet_query("SELECT id FROM srv_vrednost WHERE id = '$row[vre_id]'");
                    if (!$sql1) echo mysqli_error($GLOBALS['connect_db']);
                    $row1 = mysqli_fetch_array($sql1);
                } else
                    $row1 = null; //�ud not hepen


                // kombinirana tabela
                if (in_array($row2['tip'], array(6, 16, 19, 20)) && $row2['gru_id'] == '-2') {

                    if (in_array($row2['tip'], array(6, 16))) {
                        $sql3 = sisplet_query("SELECT * FROM srv_condition_grid c WHERE cond_id='$row[id]'");
                        if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                        $j = 0;
                        while ($row3 = mysqli_fetch_array($sql3)) {
                            if ($j++ != 0) $echo .= ' || ';

                            if ($rowa['mass_insert'] != 1 || $row2['tip'] != 6 || $_GET['m'] == 'quick_edit') {    // normalno izpolnjevanje

                                // Ce imamo if pogoj za -1 -> neodgovor
                                if ($row3['grd_id'] == '-1') {
                                    $condition = '';

                                    // loop cez vse gride in preverimo ce je kaksen odkljukan
                                    $sqlG = sisplet_query("SELECT id, part, other FROM srv_grid WHERE spr_id='$row2[id]'");
                                    while ($rowG = mysqli_fetch_array($sqlG)) {
                                        if ($row2['enota'] == 0 || $row2['enota'] == 1 || $row2['enota'] == 3) {
                                            if ($rowG['other'] == 0)
                                                $condition .= '!document.getElementById(\'multi_' . $row2['id'] . '_' . $row1['id'] . '_grid_' . $rowG['id'] . ($rowG['part'] > 1 ? '_part_2' : '') . '\').checked ';
                                            else
                                                $condition .= '!document.getElementById(\'grid_missing_value_' . $row1['id'] . '_grid_' . $rowG['id'] . ($rowG['part'] > 1 ? '_part_2' : '') . '\').checked ';

                                        } elseif ($row2['enota'] == 2 || $row2['enota'] == 6) {
                                            $condition .= '!document.getElementsByName(\'multi_' . $row2['id'] . '_' . $row1['id'] . '\')[0].options[document.getElementsByName(\'multi_' . $row2['id'] . '_' . $row1['id'] . '\')[0].selectedIndex].value == \'' . $rowG['id'] . '\' ';
                                        }
                                        $condition .= ' && ';
                                    }
                                    $echo .= '(' . substr($condition, 0, -3) . ')';
                                } else {
                                    if ($row2['enota'] == 0 || $row2['enota'] == 1 || $row2['enota'] == 3) {

                                        $sql4 = sisplet_query("SELECT part, other FROM srv_grid WHERE spr_id='$row2[id]' AND id='$row3[grd_id]'");
                                        $row4 = mysqli_fetch_array($sql4);

                                        if ($row4['other'] == 0)
                                            $echo .= 'document.getElementById(\'multi_' . $row2['id'] . '_' . $row1['id'] . '_grid_' . $row3['grd_id'] . ($row4['part'] > 1 ? '_part_2' : '') . '\').checked ';
                                        else
                                            $echo .= 'document.getElementById(\'grid_missing_value_' . $row1['id'] . '_grid_' . $row3['grd_id'] . ($row4['part'] > 1 ? '_part_2' : '') . '\').checked ';

                                    } elseif ($row2['enota'] == 2 || $row2['enota'] == 6) {
                                        $echo .= 'document.getElementsByName(\'multi_' . $row2['id'] . '_' . $row1['id'] . '\')[0].options[document.getElementsByName(\'multi_' . $row2['id'] . '_' . $row1['id'] . '\')[0].selectedIndex].value == \'' . $row3['grd_id'] . '\' ';
                                    }
                                }

                                // masovni vnos
                            } else {
                                $echo .= 'document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['vre_id'] . '\').value == "' . $row3['grd_id'] . '"';
                            }

                        }
                    } elseif (in_array($row2['tip'], array(19, 20))) {
                        $echo .= ' ( ';

                        $echo .= ' document.getElementById(\'multi_' . $row2['id'] . '_' . $row['vre_id'] . '_grid_' . $row['grd_id'] . '\').value';

                        if ($row['operator'] == 0)
                            $echo .= ' == ';
                        elseif ($row['operator'] == 1)
                            $echo .= ' !== ';
                        elseif ($row['operator'] == 2)
                            $echo .= ' < ';
                        elseif ($row['operator'] == 3)
                            $echo .= ' <= ';
                        elseif ($row['operator'] == 4)
                            $echo .= ' > ';
                        elseif ($row['operator'] == 5)
                            $echo .= ' >= ';


                        //if ($row['text'] == '')
                        $echo .= '"' . $row['text'] . '"';
                        /*else
                            $echo .= $row['text'];*/

                        $echo .= ' ) ';
                    }

                    // radio, checkbox, dropdown in multigrid (brez drag and drop)
                } elseif ((($row2['tip'] <= 3 && ($row2['orientation'] != 8 || get('mobile') == 1)) || ($row2['tip'] == 6 || $row2['tip'] == 16) && ($row2['enota'] != 9)) && ($row['spr_id'] || $row['vre_id'])) {

                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';

                    // obicne spremenljivke
                    if ($row['vre_id'] == 0) {

                        $sql3 = sisplet_query("SELECT c.vre_id, v.id, v.vrstni_red, v.other FROM srv_condition_vre c, srv_vrednost v WHERE cond_id='$row[id]' AND c.vre_id=v.id");
                        if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                        $j = 0;
                        while ($row3 = mysqli_fetch_array($sql3)) {
                            if ($j++ != 0) $echo .= ' || ';

                            if ($rowa['mass_insert'] != 1 || $_GET['m'] == 'quick_edit') {    // normalno izpolnjevanje

                                // Ce imamo if pogoj za -1 -> neodgovor
                                if ($row3['vre_id'] == '-1') {
                                    $condition = '';

                                    // loop cez vse odgovore in preverimo ce je kaksen odkljukan
                                    $sqlV = sisplet_query("SELECT id, other FROM srv_vrednost WHERE spr_id='$row[spr_id]'");
                                    while ($rowV = mysqli_fetch_array($sqlV)) {
                                        if ($row2['tip'] <= 2 && ($row2['orientation'] != 8 || get('mobile') == 1)) {
                                            if ($rowV['other'] >= 0)
                                                $condition .= '!document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $rowV['id'] . '\').checked ';
                                            else
                                                $condition .= '!document.getElementById(\'missing_value_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $rowV['id'] . '\').checked ';
                                        } else {
                                            $condition .= '!document.getElementById(\'vrednost_' . $row['spr_id'] . '\').value == \'' . $rowV['id'] . '\' ';
                                        }
                                        $condition .= ' && ';
                                    }
                                    $echo .= '(' . substr($condition, 0, -3) . ')';
                                } else {
                                    //if ($row2['tip'] <= 2) {
                                    if ($row2['tip'] <= 2 && ($row2['orientation'] != 8 || get('mobile') == 1)) {
                                        if ($row3['other'] >= 0)
                                            $echo .= 'document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row3['id'] . '\').checked ';
                                        else
                                            $echo .= 'document.getElementById(\'missing_value_spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row3['id'] . '\').checked ';
                                    } else {
                                        $echo .= 'document.getElementById(\'vrednost_' . $row['spr_id'] . '\').value == \'' . $row3['id'] . '\' ';
                                    }
                                }

                                // masovni vnos
                            } else {
                                if ($row2['tip'] != 2) {    // radio, dropdown
                                    $echo .= 'document.getElementById(\'vrednost_' . $row['spr_id'] . '\').value == "' . $row3['vrstni_red'] . '"';
                                } else {    // checkbox
                                    $echo .= 'document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row3['id'] . '\').value == "1"';
                                }
                            }
                        }

                        // multigrid
                    } elseif ($row['vre_id'] > 0) {
                        $sql3 = sisplet_query("SELECT grd_id FROM srv_condition_grid WHERE cond_id='$row[id]'");
                        if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                        $j = 0;
                        while ($row3 = mysqli_fetch_array($sql3)) {
                            if ($j++ != 0) $echo .= ' || ';

                            if ($rowa['mass_insert'] != 1 || $row2['tip'] != 6 || $_GET['m'] == 'quick_edit') {    // normalno izpolnjevanje

                                // Ce imamo if pogoj za -1 -> neodgovor
                                if ($row3['grd_id'] == '-1') {
                                    $condition = '';

                                    // loop cez vse gride in preverimo ce je kaksen odkljukan
                                    $sqlG = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row2[id]'");
                                    while ($rowG = mysqli_fetch_array($sqlG)) {
                                        if ($row2['enota'] == 0 || $row2['enota'] == 1 || $row2['enota'] == 3) {
                                            if ($rowG['other'] == 0)
                                                $condition .= '!document.getElementById(\'vrednost_' . $row1['id'] . '_grid_' . $rowG['id'] . ($rowG['part'] > 1 ? '_part_2' : '') . '\').checked ';
                                            else
                                                $condition .= '!document.getElementById(\'grid_missing_value_' . $row1['id'] . '_grid_' . $rowG['id'] . ($rowG['part'] > 1 ? '_part_2' : '') . '\').checked ';

                                            //} elseif ($row2['enota'] == 2) {
                                        } elseif ($row2['enota'] == 2 || $row2['enota'] == 6) {
                                            $condition .= '!document.getElementsByName(\'vrednost_' . $row1['id'] . '\')[0].options[document.getElementsByName(\'vrednost_' . $row1['id'] . '\')[0].selectedIndex].value == \'' . $rowG['id'] . '\' ';
                                        }
                                        $condition .= ' && ';
                                    }
                                    $echo .= '(' . substr($condition, 0, -3) . ')';
                                } else {
                                    if ($row2['enota'] == 0 || $row2['enota'] == 1 || $row2['enota'] == 3 || $row2['enota'] == 4 || $row2['enota'] == 8) {

                                        $sql4 = sisplet_query("SELECT * FROM srv_grid WHERE spr_id='$row2[id]' AND id='$row3[grd_id]'");
                                        $row4 = mysqli_fetch_array($sql4);

                                        if ($row4['other'] == 0)
                                            $echo .= 'document.getElementById(\'vrednost_' . $row1['id'] . '_grid_' . $row3['grd_id'] . ($row4['part'] > 1 ? '_part_2' : '') . '\').checked ';
                                        else
                                            $echo .= 'document.getElementById(\'grid_missing_value_' . $row1['id'] . '_grid_' . $row3['grd_id'] . ($row4['part'] > 1 ? '_part_2' : '') . '\').checked ';

                                        //} elseif ($row2['enota'] == 2) {
                                    } elseif ($row2['enota'] == 2 || $row2['enota'] == 6) {
                                        $echo .= 'document.getElementsByName(\'vrednost_' . $row1['id'] . '\')[0].options[document.getElementsByName(\'vrednost_' . $row1['id'] . '\')[0].selectedIndex].value == \'' . $row3['grd_id'] . '\' ';
                                    }
                                }

                                // masovni vnos
                            } else {
                                $echo .= 'document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['vre_id'] . '\').value == "' . $row3['grd_id'] . '"';
                            }

                        }
                    }

                    $echo .= ' ) ';
                    //drag and drop @ kategorije en odgovor
                } elseif ($row2['tip'] == 1 && ($row2['orientation'] == 8 && get('mobile') != 1)) {

                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';
                    //SELECT * FROM srv_condition_vre c, srv_vrednost v WHERE cond_id='$row[id]' AND c.vre_id=v.id
                    $sql3 = sisplet_query("SELECT c.vre_id FROM srv_condition_vre c, srv_vrednost v WHERE cond_id='$row[id]' AND c.vre_id=v.id");
                    if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                    $j = 0;
                    while ($row3 = mysqli_fetch_array($sql3)) {
                        if ($j++ != 0) $echo .= ' || ';

                        //if ($row2['design'] == 0 && get('mobile') == 0)
                        $echo .= ' $("#half2_frame_dropping_' . $row2['id'] . '").children("div").attr("value") == ' . $row3['vre_id'];

                        //half2_frame_dropping_4271, half2_frame_dropping_1_4276		//spremenljivka_4276_vrednost_22811

                    }

                    $echo .= ' ) ';
                    //drag and drop @ kategorije vec odgovorov
                } elseif ($row2['tip'] == 2 && ($row2['orientation'] == 8 && get('mobile') != 1)) {
                    $z = 0;
                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';
                    //SELECT * FROM srv_condition_vre c, srv_vrednost v WHERE cond_id='$row[id]' AND c.vre_id=v.id
                    $sql3 = sisplet_query("SELECT c.vre_id FROM srv_condition_vre c, srv_vrednost v WHERE cond_id='$row[id]' AND c.vre_id=v.id");
                    if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                    $j = 0;
                    while ($row3 = mysqli_fetch_array($sql3)) {
                        if ($j++ != 0) $echo .= ' || ';

                        //if ($row2['design'] == 0 && get('mobile') == 0)
                        for ($z = 1; $z <= $row2['grids']; $z++) {    //preleti vse mozne odgovore in sestavi pogoj
                            $echo .= ' $("#half2_frame_dropping_' . $row2['id'] . '").children("div :nth-child(' . $z . ')").attr("value") == ' . $row3['vre_id'];
                            if ($z < $row2['grids']) {    //ce ni zadnji mozni odgovor dodaj ali (||)
                                $echo .= '||';
                            }
                        }
                    }

                    $echo .= ' ) ';

                    //drag and drop @ tabela en odgovor
                } elseif (($row2['tip'] == 6) && ($row2['enota'] == 9)) {
                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';

                    $sql3 = sisplet_query("SELECT grd_id FROM srv_condition_grid WHERE cond_id='$row[id]'");

                    if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                    $j = 0;
                    while ($row3 = mysqli_fetch_array($sql3)) {
                        if ($j++ != 0) $echo .= ' || ';

                        //if ($row2['design'] == 0 && get('mobile') == 0)
                        $echo .= ' $("#half2_frame_dropping_' . $row3['grd_id'] . '_' . $row2['id'] . '").children("div").attr("value") == ' . $row['vre_id'];
                    }

                    $echo .= ' ) ';
                    //drag and drop @ tabela vec odgovorov
                } elseif (($row2['tip'] == 16) && ($row2['enota'] == 9)) {
                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';

                    $sql3 = sisplet_query("SELECT grd_id FROM srv_condition_grid WHERE cond_id='$row[id]'");

                    if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                    $j = 0;
                    while ($row3 = mysqli_fetch_array($sql3)) {
                        if ($j++ != 0) $echo .= ' || ';

                        //if ($row2['design'] == 0 && get('mobile') == 0)
                        for ($z = 1; $z <= $row2['grids']; $z++) {    //preleti vse mozne odgovore in sestavi pogoj
                            $echo .= ' $("#half2_frame_dropping_' . $row3['grd_id'] . '_' . $row2['id'] . '").children("div :nth-child(' . $z . ')").attr("value") == ' . $row['vre_id'];
                            if ($z < $row2['grids']) {    //ce ni zadnji mozni odgovor dodaj ali (||)
                                $echo .= '||';
                            }
                        }
                    }

                    $echo .= ' ) ';


                    // razvrscanje
                } elseif ($row2['tip'] == 17) {

                    if ($row['operator'] == 0)
                        $echo .= ' ';
                    else
                        $echo .= ' ! ';

                    $echo .= ' ( ';

                    $sql3 = sisplet_query("SELECT grd_id FROM srv_condition_grid WHERE cond_id='$row[id]'");
                    if (!$sql3) echo mysqli_error($GLOBALS['connect_db']);

                    $j = 0;
                    while ($row3 = mysqli_fetch_array($sql3)) {
                        if ($j++ != 0) $echo .= ' || ';

                        if ($row2['design'] == 0 && get('mobile') == 0)    // prestavljanje
                            $echo .= ' $(\'#half2_' . $row2['id'] . '\').sortable(\'toArray\')[' . ($row3['grd_id'] - 1) . '] == \'spremenljivka_'.$row['spr_id'].'_vrednost_' . $row['vre_id'] . '\' ';
                        elseif ($row2['design'] == 1 || get('mobile') > 0)    // ostevilcevanje
                            $echo .= ' document.getElementsByName(\'spremenljivka_' . $row2['id'] . '_vrednost_' . $row['vre_id'] . '\')[0].value == \'' . ($row3['grd_id']) . '\' ';
                        elseif ($row2['design'] == 2 && get('mobile') == 0)    // premikanje
                            $echo .= ' $(\'#sortzone_' . $row2['id'] . '\').sortable(\'toArray\')[' . ($row3['grd_id'] - 1) . '] == \'spremenljivka_'.$row['spr_id'].'_vrednost_' . $row['vre_id'] . '\' ';

                    }

                    $echo .= ' ) ';


                    // tabela text, tabela stevilo
                } elseif ($row2['tip'] == 19 || $row2['tip'] == 20) {

                    $echo .= ' ( ';

                    $echo .= ' document.getElementById(\'vrednost_' . $row['vre_id'] . '_grid_' . $row['grd_id'] . '\').value';

                    if ($row['operator'] == 0)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 1)
                        $echo .= ' !== ';
                    elseif ($row['operator'] == 2)
                        $echo .= ' < ';
                    elseif ($row['operator'] == 3)
                        $echo .= ' <= ';
                    elseif ($row['operator'] == 4)
                        $echo .= ' > ';
                    elseif ($row['operator'] == 5)
                        $echo .= ' >= ';


                    //if ($row['text'] == '')
                    $echo .= '"' . $row['text'] . '"';
                    /*else
                        $echo .= $row['text'];*/

                    $echo .= ' ) ';

                    // textbox
                } elseif ($row2['tip'] == 21) {

                    $echo .= ' ( ';

                    if ($row['operator'] <= 5)
                        $echo .= 'document.getElementsByName(\'vrednost_' . $row['spr_id'] . '_kos_' . $row['vre_id'] . '\')[0].value';
                    else
                        $echo .= 'document.getElementsByName(\'vrednost_' . $row['spr_id'] . '_kos_' . $row['vre_id'] . '\')[0].value.length';

                    if ($row['operator'] == 0)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 1)
                        $echo .= ' !== ';
                    elseif ($row['operator'] == 6)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 7)
                        $echo .= ' < ';
                    elseif ($row['operator'] == 8)
                        $echo .= ' > ';

                    $echo .= '"' . $row['text'] . '"';

                    $echo .= ' ) ';

                    // number, compute in kvota majo drugacne pogoje in opcije
                } elseif ($row2['tip'] == 4 || $row2['tip'] == 7 || $row2['tip'] == 22 || $row2['tip'] == 25) {

                    $echo .= ' ( ';

                    if ($row2['tip'] == 7)    // number ma drugacen ID, ker ima lahko dva polja
                        $echo .= 'document.getElementById(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . ($row['grd_id'] + 1) . '\').value';
                    else
                        $echo .= 'document.getElementById(\'vrednost_' . $row['spr_id'] . '\').value';

                    if ($row['operator'] == 0)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 1)
                        $echo .= ' !== ';
                    elseif ($row['operator'] == 2)
                        $echo .= ' < ';
                    elseif ($row['operator'] == 3)
                        $echo .= ' <= ';
                    elseif ($row['operator'] == 4)
                        $echo .= ' > ';
                    elseif ($row['operator'] == 5)
                        $echo .= ' >= ';

                    if ($row2['tip'] == 4 || $row['operator'] == 0 || $row['operator'] == 1)
                        $echo .= '"' . $row['text'] . '"';
                    else {
                        if ($row['text'] == '')
                            $echo .= '"' . $row['text'] . '"';
                        else
                            $echo .= $row['text'];
                    }

                    $echo .= ' ) ';

                    // datum
                } elseif ($row2['tip'] == 8) {

                    $echo .= ' ( ';

                    $echo .= 'Date.parse(convertDate(document.getElementById(\'vrednost_' . $row['spr_id'] . '\').value))';

                    if ($row['operator'] == 0)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 1)
                        $echo .= ' !== ';
                    elseif ($row['operator'] == 2)
                        $echo .= ' < ';
                    elseif ($row['operator'] == 3)
                        $echo .= ' <= ';
                    elseif ($row['operator'] == 4)
                        $echo .= ' > ';
                    elseif ($row['operator'] == 5)
                        $echo .= ' >= ';

                    if ($row['text'] == '')
                        $echo .= '"' . $row['text'] . '"';
                    else
                        $echo .= 'Date.parse(convertDate("' . $row['text'] . '"))';

                    $echo .= ' ) ';

                    // vsota
                } elseif ($row2['tip'] == 18) {

                    $echo .= ' ( ';

                    $echo .= 'document.getElementsByName(\'spremenljivka_' . $row['spr_id'] . '_vrednost_' . $row['vre_id'] . '\')[0].value';

                    if ($row['operator'] == 0)
                        $echo .= ' == ';
                    elseif ($row['operator'] == 1)
                        $echo .= ' !== ';
                    elseif ($row['operator'] == 2)
                        $echo .= ' < ';
                    elseif ($row['operator'] == 3)
                        $echo .= ' <= ';
                    elseif ($row['operator'] == 4)
                        $echo .= ' > ';
                    elseif ($row['operator'] == 5)
                        $echo .= ' >= ';

                    if ($row['text'] == '')
                        $echo .= '"' . $row['text'] . '"';
                    else
                        $echo .= $row['text'];

                    $echo .= ' ) ';

                }

                // recnum
            } elseif ($row['spr_id'] == -1) {

                $echo .= ' ( _recnum % ' . $row['modul'] . ' == ' . $row['ostanek'] . ' ) ';

                // calculations
            } elseif ($row['spr_id'] == -2) {

                $echo .= ' ( ';

                $echo .= $this->generateCalculationJS($row['id']);

                if ($row['operator'] == 0)
                    $echo .= ' == ';
                elseif ($row['operator'] == 1)
                    $echo .= ' !== ';
                elseif ($row['operator'] == 2)
                    $echo .= ' < ';
                elseif ($row['operator'] == 3)
                    $echo .= ' <= ';
                elseif ($row['operator'] == 4)
                    $echo .= ' > ';
                elseif ($row['operator'] == 5)
                    $echo .= ' >= ';

                if ($row['text'] == '')
                    $echo .= '"' . $row['text'] . '"';
                else
                    $echo .= $row['text'];

                $echo .= ' ) ';

                // quotas
            } elseif ($row['spr_id'] == -3) {

                $quota = Check::getInstance()->checkQuota($row['id']);

                $echo .= ' ( ';

                $echo .= $quota;

                if ($row['operator'] == 0)
                    $echo .= ' == ';
                elseif ($row['operator'] == 1)
                    $echo .= ' !== ';
                elseif ($row['operator'] == 2)
                    $echo .= ' < ';
                elseif ($row['operator'] == 3)
                    $echo .= ' <= ';
                elseif ($row['operator'] == 4)
                    $echo .= ' > ';
                elseif ($row['operator'] == 5)
                    $echo .= ' >= ';

                if ($row['text'] == '')
                    $echo .= '"' . $row['text'] . '"';
                else
                    $echo .= $row['text'];

                $echo .= ' ) ';
				
            // naprava
            } elseif ($row['spr_id'] == -4) {
				
				if (in_array($row['text'], array('0','1','2','3'))){
				
                    // Star nacin detekcije - vedno vezan na prvi prihod, po novem detektiramo vsakic posebej
					/*$sqlU = sisplet_query("SELECT device FROM srv_user WHERE ank_id='".get('anketa')."' AND id='".get('usr_id')."'");
					$rowU = mysqli_fetch_array($sqlU);

                    $echo .= $row['text'] . ' == ' . $rowU['device'];*/

                    $device = 0;
                    $useragent = $_SERVER['HTTP_USER_AGENT'];

                    if ($useragent != '' && get_cfg_var('browscap')) {

                        $browser_detect = get_browser($useragent, true);

                        $detect = New \Detection\MobileDetect;
                        $detect->setUserAgent($useragent);

                        // Detect naprave (pc, mobi, tablet, robot)
                        if ($detect->isMobile()) {
                            if ($detect->isTablet())
                                $device = 2;
                            else
                                $device = 1;
                        } 
                        elseif ($browser_detect['crawler'] == 1){
                            $device = 3;
                        }
                    }
				
					$echo .= ' ( ';	
					$echo .= $row['text'] . ' == ' . $device;
					$echo .= ' ) ';
				}
            }

            for ($i = 1; $i <= $row['right_bracket']; $i++)
                $echo .= ' ) ';
        }

        // failsafe, ce se poklika if, pa se ne nastavi pogoja
        if ($echo == '')
            $echo .= ' true ';

        echo $echo;
    }

    /**
     * @desc zgenerira kalkulacijo za vstavitev v JS
     */
    public function generateCalculationJS($condition)
    {
		$calculationSpr = Cache::srv_spremenljivka(-$condition);
	
        $sql = sisplet_query("SELECT * FROM srv_calculation WHERE cnd_id = '$condition' ORDER BY vrstni_red ASC");
        if (!$sql) echo mysqli_error($GLOBALS['connect_db']);

        $i = 0;
        $expression = '';
        while ($row = mysqli_fetch_array($sql)) {

            if ($i++ != 0)
                if ($row['operator'] == 0)
                    $expression .= ' + ';
                elseif ($row['operator'] == 1)
                    $expression .= ' - ';
                elseif ($row['operator'] == 2)
                    $expression .= ' * ';
                elseif ($row['operator'] == 3)
                    $expression .= ' / ';

            for ($i = 1; $i <= $row['left_bracket']; $i++)
                $expression .= ' ( ';

            // spremenljivke
            if ($row['spr_id'] > 0) {

                // obicne spremenljivke
                if ($row['vre_id'] == 0) {
                    $row1 = Model::select_from_srv_spremenljivka($row['spr_id']);

                    $spr = $row1['id'];
                    $vre = 0;
                    $grd = $row['grd_id'];
                    $tip = $row1['tip'];
                } // checkbox, multigrid
                elseif ($row['vre_id'] > 0) {
                    $sql1 = sisplet_query("SELECT v.spr_id, v.id, s.tip AS tip FROM srv_vrednost v, srv_spremenljivka s WHERE v.id = '$row[vre_id]' AND v.spr_id=s.id");
                    if (!$sql1) echo mysqli_error($GLOBALS['connect_db']);

                    $row1 = mysqli_fetch_array($sql1);

                    $spr = $row1['spr_id'];
                    $vre = $row1['id'];
                    $tip = $row1['tip'];
                    $grd = $row['grd_id'];
                } else {
                    $spr = 0;
                    $vre = 0;
                    $tip = 0;
                    $grd = 0;
                }

				// Preverimo kako obravnavamo missinge - posamezno kot 0 ali kot -88 za celo kalkulacijo
				$newParams = new enkaParameters($calculationSpr['params']);
				$calcMissing = $newParams->get('calcMissing', '0');
			
                $expression .= " checkCalculation('{$spr}', '{$vre}', '{$grd}', '{$tip}', '{$calcMissing}') ";
            } 
			// konstante
            elseif ($row['spr_id'] == -1) {
                $expression .= $row['number'];
            }
            // recnum
            elseif ($row['spr_id'] == -2) {
                $sqlu = sisplet_query("SELECT recnum FROM srv_user WHERE id='".get('usr_id')."'");
                $rowu = mysqli_fetch_array($sqlu);

                $expression .= $rowu['recnum'];
            }

            for ($i = 1; $i <= $row['right_bracket']; $i++)
                $expression .= ' ) ';
        }

        // Zaokrozimo na doloceno stevilo decimalk
        $decimals = $calculationSpr['decimalna'];
        $expression = 'parseFloat((' . $expression . ').toFixed(' . $decimals . '))';

        return '(' . $expression . ')';
    }
}