ctucx.git: tinyDAV

[php] Cal-/ CardDAV server with a simple web-GUI based on SabreDAV

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 
2936 
2937 
2938 
2939 
2940 
2941 
2942 
2943 
2944 
2945 
2946 
2947 
2948 
2949 
2950 
2951 
2952 
2953 
2954 
2955 
2956 
2957 
2958 
2959 
2960 
2961 
2962 
2963 
2964 
2965 
2966 
2967 
2968 
2969 
2970 
2971 
2972 
2973 
2974 
2975 
2976 
2977 
2978 
2979 
2980 
2981 
2982 
2983 
2984 
2985 
2986 
2987 
2988 
2989 
2990 
2991 
2992 
2993 
2994 
2995 
2996 
2997 
2998 
2999 
3000 
3001 
3002 
3003 
3004 
3005 
3006 
3007 
3008 
3009 
3010 
3011 
3012 
3013 
3014 
3015 
3016 
3017 
3018 
3019 
3020 
3021 
3022 
3023 
3024 
3025 
3026 
3027 
3028 
3029 
3030 
3031 
3032 
3033 
3034 
3035 
3036 
3037 
3038 
3039 
3040 
3041 
3042 
3043 
3044 
3045 
3046 
3047 
3048 
3049 
3050 
3051 
3052 
3053 
3054 
3055 
3056 
3057 
3058 
3059 
3060 
3061 
3062 
3063 
3064 
3065 
3066 
3067 
3068 
3069 
3070 
3071 
3072 
3073 
3074 
3075 
3076 
3077 
3078 
3079 
3080 
3081 
3082 
3083 
3084 
3085 
3086 
3087 
3088 
3089 
3090 
3091 
3092 
3093 
3094 
3095 
3096 
3097 
3098 
3099 
3100 
3101 
3102 
3103 
3104 
3105 
3106 
3107 
3108 
3109 
3110 
3111 
3112 
3113 
3114 
3115 
3116 
3117 
3118 
3119 
3120 
3121 
3122 
3123 
3124 
3125 
3126 
3127 
3128 
3129 
3130 
3131 
3132 
3133 
3134 
3135 
3136 
3137 
3138 
3139 
3140 
3141 
3142 
3143 
3144 
3145 
3146 
3147 
3148 
3149 
3150 
3151 
3152 
3153 
3154 
3155 
3156 
3157 
3158 
3159 
3160 
3161 
3162 
3163 
3164 
3165 
3166 
3167 
3168 
3169 
3170 
3171 
3172 
3173 
3174 
3175 
3176 
3177 
3178 
3179 
3180 
3181 
3182 
3183 
3184 
3185 
3186 
3187 
3188 
3189 
3190 
3191 
3192 
3193 
3194 
3195 
3196 
3197 
3198 
3199 
3200 
3201 
3202 
3203 
3204 
3205 
3206 
3207 
3208 
3209 
3210 
3211 
3212 
3213 
3214 
3215 
3216 
3217 
3218 
3219 
3220 
3221 
3222 
3223 
3224 
3225 
3226 
3227 
3228 
3229 
3230 
3231 
3232 
3233 
3234 
3235 
3236 
3237 
3238 
3239 
3240 
3241 
3242 
3243 
3244 
3245 
3246 
3247 
3248 
3249 
3250 
3251 
3252 
3253 
3254 
3255 
3256 
3257 
3258 
3259 
3260 
3261 
3262 
3263 
3264 
3265 
3266 
3267 
3268 
3269 
3270 
3271 
3272 
3273 
3274 
3275 
3276 
3277 
3278 
3279 
3280 
3281 
3282 
3283 
3284 
3285 
3286 
3287 
3288 
3289 
3290 
3291 
3292 
3293 
3294 
3295 
3296 
3297 
3298 
3299 
3300 
3301 
3302 
3303 
3304 
3305 
3306 
3307 
/*
InfCloud - the open source CalDAV/CardDAV Web Client
Copyright (C) 2011-2015
    Jan Mate <jan.mate@inf-it.com>
    Andrej Lezo <andrej.lezo@inf-it.com>
    Matej Mihalik <matej.mihalik@inf-it.com>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

function updateTodoFormDimensions(setHeight)
{
	$('#CATodo').css('width','');
	$('#CATodo').css('width',$('#todo_details_template').css('width'));

	if(setHeight)
	{
		$('#CATodo').css('height','');
		$('#CATodo').css('height',$('#todo_details_template').css('height'));
	}
}

function updateEventFormDimensions(setHeight)
{
	$('#CAEvent').css('width','');
	$('#CAEvent').css('width',$('#event_details_template').css('width'));

	if(setHeight)
	{
		$('#CAEvent').css('height','');
		$('#CAEvent').css('height',$('#event_details_template').css('height'));
	}
}

function setFormPosition(jsEvent, confirmRepeat)
{
	var position_x,
	position_y,
	dist_x,
	dist_y;

	$('#event_details_template').css('max-height','');

	if(jsEvent)
	{
		if(jsEvent.pageX<=($('#main').width()/2))
		{
			position_v='left';
			dist_x=jsEvent.pageX;
		}
		else
		{
			position_v='right';
			dist_x=$('body').width()-jsEvent.pageX;
		}

		/*if(jsEvent.pageY<=($('#main').height()/2))
		{
			position_h='top';
			dist_y=jsEvent.pageY;
		}
		else
		{
			position_h='top';
			dist_y=jsEvent.pageY-$('#event_details_template').height();
		}*/
		position_h='top';
		dist_y=Math.max(29, jsEvent.pageY-(confirmRepeat ? $('#CAEvent').height() : $('#event_details_template').height()));
	}
	else
	{
		position_v='right';
		position_h='top';
		dist_x=25;
		dist_y=29;
	}

	$('#CAEvent').css('left','');
	$('#CAEvent').css('right','');
	$('#CAEvent').css('top','');
	$('#CAEvent').css('bottom','');
	$('#CAEvent').css(position_v, dist_x);
	$('#CAEvent').css(position_h, dist_y);
	$('#event_details_template').css('max-height', $('#main').height()-dist_y+20+'px');
	$('#CAEvent').css('max-height', $('#main').height()-dist_y+20+'px');
}

function setTodoPosition(jsEvent)
{
	var dist,
	pointY=0;
	$('#todo_details_template').css('max-height','');
	$('#CATodo').css('max-height','');

	if(jsEvent!=undefined)
	{
		if(jsEvent.pageY!=undefined)
			pointY=jsEvent.pageY;
		else
			pointY=jsEvent.clientY;
	}

	if(jsEvent)
	{
		/*if((pointY)+$('#todo_details_template').height()<$(window).height())
			dist=jsEvent.pageY;
		else
			dist=pointY-$('#todo_details_template').height();*/
		dist=Math.max(25, jsEvent.pageY-$('#todo_details_template').height());
	}
	else
		dist=25;

	$('#CATodo').css('left','');
	$('#CATodo').css('right','');
	$('#CATodo').css('top','');
	$('#CATodo').css('bottom','');
	$('#CATodo').css('top', dist);
	$('#todo_details_template').css('right', 0);
	$('#CATodo').css('right', 25);
	$('#todo_details_template').css('max-height', $('#main').height()-dist+20+'px');
	$('#CATodo').css('max-height', $('#main').height()-dist+20+'px');
}

function showTimezones(selTimezone, todoSelector)
{
	if(!globalSettings.timezonesupport.value)
		return false;

	var select=$('#timezone'+todoSelector);
	select.empty();
	var isFirst=false;
	for(var izone in timezoneKeys)
	{
		if(timeZonesEnabled.indexOf(timezoneKeys[izone])==-1)
			continue;
		if(!isNaN(izone))
		{
			var tmp=null;
			if(!isFirst)
			{
				tmp=$('<option>');
				tmp.attr('data-type','local');
				isFirst=true;
				if(!(selTimezone in timezones) && selTimezone!= '' && selTimezone!= 'local' && (globalSettings.removeunknowntimezone.value == null || !globalSettings.removeunknowntimezone.value))
				{
					tmp.text(localization[globalInterfaceLanguage].customTimezone);
					tmp.attr('value','custom');
					if((todoSelector=='PickerTODO' || todoSelector=='Picker') && globalSettings.timezone.value != null)
						tmp.attr('value',globalSettings.timezone.value);
					select.append(tmp);
				}
			}
			tmp=$('<option>');
			tmp.attr('data-type',timezoneKeys[izone]);
			if(izone==0)
			{
				tmp.text(localization[globalInterfaceLanguage].localTime);
				tmp.attr('value','local');
				select.append(tmp);
			}
			else
			{
				tmp.text(timezoneKeys[izone]);
				tmp.attr('value',timezoneKeys[izone]);
				select.append(tmp);
			}
		}
	}

	if(!selTimezone && typeof globalSessionTimeZone!='undefined' && globalSessionTimeZone)
		selTimezone=globalSessionTimeZone;

	if(selTimezone in timezones)
		select.val(selTimezone);
	else
	{
		if((globalSettings.removeunknowntimezone.value != null && globalSettings.removeunknowntimezone.value) || selTimezone == 'local')
			select.val('local');
		else
			select.val('custom');
	}
}

function showTodoForm(todo, mod, repeatOne, confirmRepeat)
{
	$('#CATodo').css('display','none');
	$('#todo_details_template').remove();
	$('#CATodo').html(cleanVtodoTemplate);
	setFirstDayTodo();
	bindTodoForm();

	$('#noteTODO').autosize({defaultStyles: {height: '64', overflow: '', 'overflow-y': '', 'word-wrap': '', resize: 'none'}, callback: function(){checkTodoFormScrollBar();}});
	$("#showTODO").val('');
	$("#uidTODO").val('');
	$("#etagTODO").val('');
	$("#vcalendarUIDTODO").val('');
	globalPrevDate='';
	globalObjectLoading=true;

	var color='';
	if(todo==null)
	{
		var activeCollection = $('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item.resourceCalDAV_item_selected');
		if(activeCollection.length>0 && !globalResourceCalDAVList.getTodoCollectionByUID(activeCollection.attr('data-id')).permissions.read_only)
			color=rgbToHex(activeCollection.children('.resourceCalDAVColor').css('background-color'));
	}
	else
		color=globalResourceCalDAVList.getTodoCollectionByUID(todo.res_id).ecolor;

	if(confirmRepeat)
	{
		$('#showTODO').val(todo.id);
		$('#repeatTodo').val(true);
		$('#CATodo').show();
		$('#repeatConfirmBoxTODO').css('visibility', 'visible');
		if(todo.repeatCount!='' && todo.repeatCount == 1 || globalSettings.appleremindersmode.value)
		{
			$('#editFutureTODO').css('display','none');
			if($('#editFutureTODO').next('br').length>0)
				$('#editFutureTODO').next().remove();
		}
		else if($('#editFutureTODO').css('display')=='none')
		{
			$('#editFutureTODO').css('display','block');
			if($('#editFutureTODO').next('br').length==0)
				$('#editFutureTODO').after('<br/>')
		}

		$('#editAllTODO, #editOnlyOneTODO, #editFutureTODO').click(function(){
			if(globalCalTodo)
			{
				if($(this).attr('id')=='editOnlyOneTODO')
					showTodoForm(globalCalTodo, 'show', 'editOnly');
				else if($(this).attr('id')=='editAllTODO')
						showTodoForm(globalCalTodo, 'show', '');
				else if($(this).attr('id')=='editFutureTODO')
					showTodoForm(globalCalTodo, 'show', 'futureOnly');

				$('#repeatConfirmBoxContentTODO').html('');
				$('#repeatConfirmBoxTODO').css('visibility', 'hidden');
				$('#todo_details_template').css('visibility', 'visible');
				$('#AlertDisabler').fadeOut(globalEditorFadeAnimation);
			}
		});

		$('#repeatConfirmBoxContentTODO').html('<b>'+todo.title+"</b> "+localization[globalInterfaceLanguage].repeatBoxContentTODO);
		$('#repeatConfirmBoxQuestionTODO').html(localization[globalInterfaceLanguage].repeatBoxQuestionTODO);
		$('#todo_details_template').css('visibility', 'hidden');
		globalObjectLoading=false;
		$('#CATodo').show(200, function(){
			$('#todoColor').css('background-color',color);
			checkTodoFormScrollBar();
			$('#todoForm').scrollTop(0);
		});
		return true;
	}

	if(mod=='show' && repeatOne=='futureOnly')
	{
		if(todo.start!=null)
			$('#futureStartTODO').val(todo.realRepeatCount+';'+todo.start);
		else if(todo.end!=null)
			$('#futureStartTODO').val(todo.realRepeatCount+';'+todo.end);
	}

	if(mod=='show')
	{
		var checkDataStart='';
		if(todo.start)
			checkDataStart=$.fullCalendar.formatDate(todo.start, "yyyyMMdd'T'HHmmss'Z'");
		if($('.fc-event-selected').length>0 && $('.fc-event-selected').attr("data-start")!=checkDataStart)
			$('.fc-view-todo').addClass('fc-view-trans');
		else
			$('.fc-view-todo').removeClass('fc-view-trans');
	}

	if(repeatOne=='editOnly')
		if(todo!=null && (todo.type || todo.rec_id))
		{
			var eventsSorted=jQuery.grep(globalEventList.displayTodosArray[todo.res_id],function(e){if(e.id==todo.id)return true}).sort(repeatStartCompare);
			if(eventsSorted.indexOf(todo)!=-1)
			{
				if(eventsSorted.indexOf(todo)<(eventsSorted.length-1))
					showTodoNextNav();
				if(eventsSorted.indexOf(todo)!=0)
					showTodoPrevNav();

				var uncomplete=0;
				for(var ij=(eventsSorted.indexOf(todo)+1); ij<eventsSorted.length; ij++)
					if(eventsSorted[ij].status!='COMPLETED')
						uncomplete++;
				if(uncomplete>0 && eventsSorted.indexOf(todo)<(eventsSorted.length-1))
					showTodoNextNav(true);

				var uncomplete=0;
				for(var ij=(eventsSorted.indexOf(todo)-1); ij>=0; ij--)
					if(eventsSorted[ij].status!='COMPLETED')
						uncomplete++;
				if(uncomplete>0 && eventsSorted.indexOf(todo)!=0)
					showTodoPrevNav(true);
			}
		}

	if(todo!=null)
	{
		var prior=parseInt(todo.priority,10);
		if(prior==5)
			$('#priority_TODO').val(5);
		else if(prior>5 && prior<10)
		{
			$('#priority_TODO [data-type="priority_TODO_low"]').attr('value',prior)
			$('#priority_TODO').val(prior);
		}
		else if(prior<5 && prior>0)
		{
			$('#priority_TODO [data-type="priority_TODO_high"]').attr('value',prior)
			$('#priority_TODO').val(prior);
		}
		else
			$('#priority_TODO').val(0);
	}

	if(todo!=null)
		var sliderValue=todo.percent;
	else
		sliderValue=0;

	var cals=globalResourceCalDAVList.sortedTodoCollections;
	var todoCalendarObj = $('#todo_calendar');
	var calSelected = $('.resourceCalDAVTODO_item.resourceCalDAV_item_selected').attr('data-id');
	for(var i=0;i<cals.length;i++)
	{
		if( cals[i].uid!=undefined && ((todo!=null && todo.res_id==cals[i].uid) || (cals[i].makeLoaded && !cals[i].permissions_read_only)))
		{
			todoCalendarObj.append(new Option(cals[i].displayValue,cals[i].uid));
		}
	}

	if(mod!='new')
		fullVcalendarToTodoData(todo,true);
	else
		CalDAVeditor_cleanup('form');

	if(mod=='new')
	{
		$('#todoInEdit').val('true');
		$('#deleteTODO').hide();
		$('#resetTODO').hide();
		$('#editTODO').hide();
		$('#duplicateTODO').hide();
		$('#editOptionsButtonTODO').hide();
		$('#showTODO').val('');

		if($('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item.resourceCalDAV_item_selected').length>0 && $('#todo_calendar').find('option[value="'+$('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item.resourceCalDAV_item_selected').attr("data-id")+'"]').length>0)
			$('#todo_calendar').val($('#ResourceCalDAVTODOList').find('.resourceCalDAVTODO_item.resourceCalDAV_item_selected').attr("data-id"));
		else
			$('#todo_calendar').val('choose');
		//$('[data-type="name_TODO"]').attr('placeholder', localization[globalInterfaceLanguage].pholderNewTODO);

		showTimezones('', 'TODO');
		$('.timezone_rowTODO').css('display','none')
	}
	$('#CATodo').show();
	$('#todo_details_template').show();
	if(globalSettings.appleremindersmode.value)
	{
		$('[data-type="todo_type_start"], [data-type="todo_type_both"]').remove();
		if(typeof globalSettings.appleremindersmode.value == 'string' && globalSettings.appleremindersmode.value.toLowerCase()=='ios6')
		{
			$('#url_trTODO').hide();
			$('#location_row_TODO').hide();
		}
		$('[data-type="STATUS_CANCELLED_TODO"],[data-type="STATUS_IN-PROCESS_TODO"]').remove();
	}
	if(mod=='show')
	{
		$('#showTODO').val(todo.id);
		$('#todoDetailsTable :input[type!="button"]').prop('disabled', true);

			if(todo.timeZone)
				showTimezones(todo.timeZone,'TODO');
			else
				showTimezones('local','TODO');

		if(todo.etag!='')
			$('#todo_calendar').val(todo.res_id);

		$('#nameTODO').val(todo.title);
		if(todo.status=='CANCELLED')
			$('#nameTODO').addClass('title_cancelled');

		if(todo.start!=null || todo.end!=null)
		{
			if((!globalSettings.appleremindersmode.value) && ((todo.start!=null && todo.end!=null && repeatOne!='') || (!todo.type && todo.realStart!='' && todo.realEnd!='' && repeatOne=='') || (todo.type && todo.repeatStart!='' && todo.repeatEnd!='' && repeatOne=='')))
				$('#todo_type').val('both');
			else if((!globalSettings.appleremindersmode.value) && ((todo.start!=null && todo.end==null && repeatOne!='') || (!todo.type && todo.realStart!='' && todo.realEnd=='' && repeatOne=='') || (todo.type && todo.repeatStart!='' && todo.repeatEnd=='' && repeatOne=='')))
				$('#todo_type').val('start');
			else
				$('#todo_type').val('due');
			if(globalSettings.timezonesupport.value)
			$('.timezone_rowTODO').show();
		}
		else
		{
			$('#todo_type').val('none');
			$('.timezone_rowTODO').css('display','none');
		}
		if(todo.start!='' && todo.start!=null)
		{
			var date,
			year,
			month,
			day,
			hour,
			minute;

			if(todo.realStart)
				date=$.fullCalendar.parseDate(todo.realStart);
			else
				date=$.fullCalendar.parseDate(todo.start);

			if($('#showTODO').val()!='' && todo.repeatStart!='' && repeatOne=='')
				date=todo.repeatStart;
			else if($('#showTODO').val()!='' && todo.repeatStart=='' && repeatOne=='' && todo.type)
				date='';

			if(date)
			{
				(date.getHours())<10 ? (hour='0'+(date.getHours())) : (hour=date.getHours());
				(date.getMinutes())<10 ? (minute='0'+(date.getMinutes())) : (minute=date.getMinutes());

				var formattedDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
				$('#date_fromTODO').val(formattedDate);
				if($('#todo_type').val=='both')
					globalPrevDate = new Date(date.getTime());
				$('#time_fromTODO').val($.fullCalendar.formatDate(date, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			}
		}
		if(todo.end!='' && todo.end!=null)
		{
			if(todo.realEnd)
				date=$.fullCalendar.parseDate(todo.realEnd);
			else
				date=$.fullCalendar.parseDate(todo.end);

			if($('#showTODO').val()!='' && todo.repeatEnd!='' && repeatOne=='')
				date=todo.repeatEnd;
			else if($('#showTODO').val()!='' && todo.repeatEnd=='' && repeatOne=='' && todo.type)
				date='';

			if(date)
			{
				(date.getHours())<10 ? (hour='0'+(date.getHours())) : (hour=date.getHours());
				(date.getMinutes())<10 ? (minute='0'+(date.getMinutes())) : (minute=date.getMinutes());

				var formattedDate_to=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
				$('#date_toTODO').val(formattedDate_to);
				$('#time_toTODO').val($.fullCalendar.formatDate(date, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			}
		}
		if(repeatOne=='editOnly' && todo.rec_id=='')
		{
			if(todo.repeatStart!='' && todo.start)
			{
				if(typeof todo.realStart=='object')
					$('#recurrenceIDTODO').val($.fullCalendar.formatDate(todo.realStart, "yyyyMMdd'T'HHmmss"));
				else if(typeof todo.realStart =='string')
					$('#recurrenceIDTODO').val($.fullCalendar.formatDate($.fullCalendar.parseDate(todo.realStart), "yyyyMMdd'T'HHmmss"));
			}
			else if(todo.repeatEnd!='' && todo.end)
			{
				if(typeof todo.realEnd =='object')
					$('#recurrenceIDTODO').val($.fullCalendar.formatDate(todo.realEnd, "yyyyMMdd'T'HHmmss"));
				else if(typeof todo.realEnd =='string')
					$('#recurrenceIDTODO').val($.fullCalendar.formatDate($.fullCalendar.parseDate(todo.realEnd), "yyyyMMdd'T'HHmmss"));
			}
		}
		else
			$('#recurrenceIDTODO').val(todo.rec_id);

		if(todo.rec_id || repeatOne=='editOnly' || repeatOne=='futureOnly')
		{
			var savedEvs=jQuery.grep(globalEventList.displayTodosArray[todo.res_id],function(e){if(e.id==todo.id && (e.repeatCount<2 || !e.repeatCount))return true});
			if(savedEvs.length>1 || (repeatOne=='futureOnly' && todo.repeatCount>1) || (repeatOne=='editOnly' && todo.type!=''))
			{
				$('#deleteTODO').attr('onclick',"$('#todoInEdit').val('false');updateEventFormDimensions(true);$('#todoLoader').show();saveTodo(true);");
			}
		}

		if(todo.completedOn!='' && todo.completedOn!=null)
		{
			var date,
			year,
			month,
			day,
			hour,
			minute;


		//	(todo.completedOn.getHours())<10 ? (hour='0'+(todo.completedOn.getHours())) : (hour=todo.completedOn.getHours());
		//	(todo.completedOn.getMinutes())<10 ? (minute='0'+(todo.completedOn.getMinutes())) : (minute=todo.completedOn.getMinutes());
			if(typeof todo.completedOn=='string')
				date = $.fullCalendar.parseDate(todo.completedOn);
			else if(typeof todo.completedOn=='object')
				date=new Date(todo.completedOn.getTime());

			var formattedDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
			$('#completedOnDate').val(formattedDate);
			$('#completedOnTime').val($.fullCalendar.formatDate(date, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('.completedOnTr').show();
		}

		var alarmDate='';
		var alarmIterator=0;

		for(alarmIterator=0;alarmIterator<todo.alertTime.length;alarmIterator++)
		{
			if(alarmIterator>0)
				todo_alert_add(alarmIterator);

			$(".alertTODO[data-id="+(alarmIterator+1)+"]").val("message");

			if(todo.alertTime[alarmIterator].charAt(0)=='-' || todo.alertTime[alarmIterator].charAt(0)=='+')
			{
				var alVal=parseInt(todo.alertTime[alarmIterator].substring(1, todo.alertTime[alarmIterator].length-1));
				var alString='';

				if(todo.alertTime[alarmIterator].charAt(todo.alertTime[alarmIterator].length-1)=="W")
				{
					alVal=alVal/1000/60/60/24/7;
					alString='weeks';
				}
				else if(todo.alertTime[alarmIterator].charAt(todo.alertTime[alarmIterator].length-1)=="D")
				{
					alVal=alVal/1000/60/60/24;
					alString='days';
				}
				else if(todo.alertTime[alarmIterator].charAt(todo.alertTime[alarmIterator].length-1)=="H")
				{
					alVal=alVal/1000/60/60;
					alString='hours';
				}
				else if(todo.alertTime[alarmIterator].charAt(todo.alertTime[alarmIterator].length-1)=="M")
				{
					alVal=alVal/1000/60;
					alString='minutes';
				}
				else if(todo.alertTime[alarmIterator].charAt(todo.alertTime[alarmIterator].length-1)=="S")
				{
					alVal=alVal/1000;
					alString='seconds';
				}

				if(todo.alertTime[alarmIterator].charAt(0)=='-')
					alString+="_before";
				else
					alString+="_after"

				$(".alert_message_detailsTODO[data-id="+(alarmIterator+1)+"]").val(alString);
				$(".before_after_inputTODO[data-id="+(alarmIterator+1)+"]").val(alVal);
				$('.alert_detailsTODO[data-id="'+(alarmIterator+1)+'"]').show();
				$('.alert_message_dateTODO[data-id="'+(alarmIterator+1)+'"]').show();
				$('.before_after_inputTODO[data-id="'+(alarmIterator+1)+'"]').show();
				$(".message_date_inputTODO[data-id="+(alarmIterator+1)+"]").hide();
				$(".message_time_inputTODO[data-id="+(alarmIterator+1)+"]").hide();
			}
			else
			{
				alarmDate=$.fullCalendar.parseDate(todo.alertTime[alarmIterator]);
				(alarmDate.getHours())<10 ? (hour='0'+(alarmDate.getHours())) : (hour=alarmDate.getHours());
				(alarmDate.getMinutes())<10 ? (minute='0'+(alarmDate.getMinutes())) : (minute=alarmDate.getMinutes());

				$(".alert_message_detailsTODO[data-id="+(alarmIterator+1)+"]").val('on_date');
				var formattedAlarmDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, alarmDate);

				$(".message_date_inputTODO[data-id="+(alarmIterator+1)+"]").val(formattedAlarmDate);
				$(".message_time_inputTODO[data-id="+(alarmIterator+1)+"]").val($.fullCalendar.formatDate(alarmDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));

				$('.alert_detailsTODO[data-id="'+(alarmIterator+1)+'"]').show();
				$('.alert_message_dateTODO[data-id="'+(alarmIterator+1)+'"]').show();
			}
		}

		if(alarmIterator>0)
			todo_alert_add(alarmIterator);
		if(todo.type!='' && repeatOne!='editOnly' && todo.ruleString.match(vCalendar.re['recurCaldav'])!=null)
		{
			var ruleString=todo.vcalendar.match(vCalendar.pre['contentline_RRULE2'])[0].match(vCalendar.pre['contentline_parse'])[4];
			if(ruleString.indexOf('BYMONTH=')!=-1 || ruleString.indexOf('BYMONTHDAY=')!=-1 || ruleString.indexOf('BYDAY=')!=-1)
			{
				var pars=ruleString.split(';');

				if(pars.indexElementOf('BYMONTH=')!=-1 && pars.indexElementOf('BYMONTHDAY=')==-1 && pars.indexElementOf('BYDAY=')==-1)
					pars[pars.length] = "BYMONTHDAY="+todo.start.getDate();
				if(todo.type=="DAILY")
				{
					$("#repeat_TODO option[value='DAILY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);
				}
				else if(todo.type=="WEEKLY")
				{
					$("#repeat_TODO option[value='CUSTOM_WEEKLY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);

					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.replace(/\d*MO/,1).replace(/\d*TU/,2).replace(/\d*WE/,3).replace(/\d*TH/,4).replace(/\d*FR/,5).replace(/\d*SA/,6).replace(/\d*SU/,0).split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								if(!isNaN(parseInt(byDay[rj],10)))
									$('#week_custom_TODO .customTable td[data-type="'+byDay[rj]+'"]').addClass('selected');
							}
						}
					}
					$('#week_custom_TODO').show();
				}
				else if(todo.type=="MONTHLY")
				{
					$("#repeat_TODO option[value='CUSTOM_MONTHLY']").prop('selected', true).change();
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);


					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								var checkString = byDay[rj].match(vCalendar.pre['+/-number']);
								byDay[rj] = byDay[rj].replace(checkString[0],'');
								if(!isNaN(parseInt(checkString[0],10)))
								{
									switch(parseInt(checkString[0],10))
									{
										case 1:
											$('#repeat_month_custom_select_TODO').val('first');
											break;
										case 2:
											$('#repeat_month_custom_select_TODO').val('second');
											break;
										case 3:
											$('#repeat_month_custom_select_TODO').val('third');
											break;
										case 4:
											$('#repeat_month_custom_select_TODO').val('fourth');
											break;
										case 5:
											$('#repeat_month_custom_select_TODO').val('fifth');
											break;
										case -1:
											$('#repeat_month_custom_select_TODO').val('last');
											break;
										default:
											$('#repeat_month_custom_select_TODO').val('every');
											break;
									}
									$('#repeat_month_custom_select2_TODO').val(byDay[rj]);
								}
							}
						}
						else if(pars[ri].indexOf("BYMONTHDAY=")!=-1)
						{
							$('#repeat_month_custom_select_TODO').val('custom').change();
							var byMonthDay=pars[ri].split('=')[1];
							byMonthDay=byMonthDay.split(',');
							for(var rj=0; rj<byMonthDay.length;rj++)
							{
								if(parseInt(byMonthDay[rj],10)==-1)
								{
									$('#repeat_month_custom_select_TODO').val('last').change();
									$('#repeat_month_custom_select2_TODO').val("DAY");

								}
								else
									$('#month_custom2_TODO .customTable td[data-type="'+(parseInt(byMonthDay[rj],10))+'"]').addClass('selected');
							}
						}
					}
				}
				else if(todo.type=="YEARLY")
				{
					$("#repeat_TODO option[value='CUSTOM_YEARLY']").prop('selected', true).change();
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
					var isMonthDay=false;
					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								var checkString = byDay[rj].match(vCalendar.pre['+/-number']);
								byDay[rj] = byDay[rj].replace(checkString[0],'');
								if(!isNaN(parseInt(checkString[0],10)))
								{
									switch(parseInt(checkString[0],10))
									{
										case 1:
											$('#repeat_year_custom_select1_TODO').val('first');
											break;
										case 2:
											$('#repeat_year_custom_select1_TODO').val('second');
											break;
										case 3:
											$('#repeat_year_custom_select1_TODO').val('third');
											break;
										case 4:
											$('#repeat_year_custom_select1_TODO').val('fourth');
											break;
										case 5:
											$('#repeat_year_custom_select1_TODO').val('fifth');
											break;
										case -1:
											$('#repeat_year_custom_select1_TODO').val('last');
											break;
										default:
											$('#repeat_year_custom_select1_TODO').val('every');
											break;
									}
									$('#repeat_year_custom_select2_TODO').val(byDay[rj]);
								}
							}
						}
						else if(pars[ri].indexOf("BYMONTHDAY=")!=-1)
						{
							$('#repeat_year_custom_select1_TODO').val('custom').change()
							var byMonthDay=pars[ri].split('=')[1];
							byMonthDay=byMonthDay.split(',');
							for(var rj=0; rj<byMonthDay.length;rj++)
							{
								if(parseInt(byMonthDay[rj],10)==-1)
								{
									$('#repeat_year_custom_select1_TODO').val('last').change();
									$('#repeat_year_custom_select2_TODO').val("DAY");

								}
								else
									$('#year_custom1_TODO .customTable td[data-type="'+(parseInt(byMonthDay[rj],10))+'"]').addClass('selected');
							}
							isMonthDay=true;
						}
						else if(pars[ri].indexOf("BYMONTH=")!=-1)
						{
							var byMonth=pars[ri].split('=')[1];
							byMonth=byMonth.split(',');
							for(var rj=0; rj<byMonth.length;rj++)
								$('#year_custom3_TODO .customTable td[data-type="'+(parseInt(byMonth[rj],10)-1)+'"]').addClass('selected');
						}
					}
				}

				if(todo.after=='' && todo.untilDate=='')
					$("#repeat_end_details_TODO option[value='never']").prop('selected', true);
				else if(todo.after!='')
				{
					$("#repeat_end_details_TODO option[value='after']").prop('selected', true);
					$('#repeat_end_after_TODO').val(todo.after);
				}
				else if(todo.untilDate!='')
				{
					date=$.fullCalendar.parseDate(todo.untilDate);
					$("#repeat_end_details_TODO option[value='on_date']").prop('selected', true);
					var formattedRepeatDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
					$('#repeat_end_date_TODO').val(formattedRepeatDate);
				}

				$('#repeat_interval_detail_TODO').val(todo.interval);
				$('#repeat_interval_TODO').show();

				if(todo.byDay.length>0)
				{
					var businessArray=new Array();
					if(globalSettings.weekenddays.value.length>0)
						for(var i=0;i<7;i++)
							if(globalSettings.weekenddays.value.indexOf(i)==-1)
								businessArray[businessArray.length]=i+'';
					var businessCount=0;
					var weekendCount=0;
					for(var i=0;i<byDay.length;i++)
					{
						if(businessArray.indexOf(byDay[i])!=-1)
							businessCount++;
						if(globalSettings.weekenddays.value.indexOf(parseInt(byDay[i],10))!=-1)
							weekendCount++;
					}

					if(businessArray.length>0 && businessArray.length==businessCount)
					{
						$("#repeat_TODO option[value='BUSINESS']").prop('selected', true);
						$('#repeat_interval_TODO').hide();
						$('#week_custom_TODO').hide();
					}
					else if(globalSettings.weekenddays.value.length>0 && globalSettings.weekenddays.value.length==weekendCount)
					{
						$("#repeat_TODO option[value='WEEKEND']").prop('selected', true);
						$('#repeat_interval_TODO').hide();
						$('#week_custom_TODO').hide();
					}
				}
			}
			else
			{
				if(todo.type=="DAILY")
				{
					$("#repeat_TODO option[value='DAILY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);
				}
				else if(todo.type=="WEEKLY")
				{
					$("#repeat_TODO option[value='WEEKLY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);
				}
				else if(todo.type=="MONTHLY")
				{
					$("#repeat_TODO option[value='MONTHLY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);
				}
				else if(todo.type=="YEARLY")
				{
					$("#repeat_TODO option[value='YEARLY']").prop('selected', true);
					$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
				}

				if(todo.after=='' && todo.untilDate=='')
					$("#repeat_end_details_TODO option[value='never']").prop('selected', true);
				else if(todo.after!='')
				{
					$("#repeat_end_details_TODO option[value='after']").prop('selected', true);
					$('#repeat_end_after_TODO').val(todo.after);
				}
				else if(todo.untilDate!='')
				{
					date=$.fullCalendar.parseDate(todo.untilDate);
					$("#repeat_end_details_TODO option[value='on_date']").prop('selected', true);
					var formattedRepeatDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
					$('#repeat_end_date_TODO').val(formattedRepeatDate);
				}

				$('#repeat_interval_detail_TODO').val(todo.interval);
				$('#repeat_interval_TODO').show();
				$('#repeatTodo').val(true);
			}
		}
		else if(todo.type!='' && repeatOne!='editOnly')
		{
			var cu_opt = new Option(localization[globalInterfaceLanguage].customRepeat, todo.ruleString, false, true);
			cu_opt.attr('data-type','custom_repeat');
			$('#repeat_TODO').append(cu_opt);
		}
		else
			$('#repeatTodo').val(false);

		if(todo.start!=null || todo.end!=null)
		{
			if(globalSettings.timezonesupport.value)
				$('.timezone_rowTODO').show()
		}
		else
			$('.timezone_rowTODO').css('display', 'none');


		if(todo.status!='')
			$('#statusTODO').find('option[value='+todo.status+']').prop('selected', true);

		$('#noteTODO').val(todo.note).trigger('autosize.resize');

		if(todo.classType!='')
			$('#typeTODO').val(todo.classType.toLowerCase());
		else
			$('#typeTODO').val('public');

		if(todo!=null && mod!='new')
		{
			var uidArray = todo.id.match(vCalendar.pre['uidParts']);

			if(decodeURIComponent(uidArray[4]).indexOf(uidArray[2])==-1)
				$('.row_typeTODO').css('display','none');
		}

		$('#uidTODO').val(todo.id);
		$('#url_TODO').val(todo.url);
		$('#location_TODO').val(todo.location);
		$('#etagTODO').val(todo.etag);
		$('#vcalendarHashTODO').val(hex_sha256(todo.vcalendar));
		var stringUIDcurrent=todo.vcalendar.match(vCalendar.pre['contentline_UID']);

		if(stringUIDcurrent!=null)
			stringUIDcurrent=stringUIDcurrent[0].match(vCalendar.pre['contentline_parse'])[4];

		if(stringUIDcurrent)
			$('#vcalendarUIDTODO').val(stringUIDcurrent);
	}


	if($('#todo_type').val()=='start')
	{
		$('.dateTrFromTODO').show();
		$('.dateTrToTODO').hide();
	}
	else if($('#todo_type').val()=='due')
	{
		$('.dateTrToTODO').show();
		$('.dateTrFromTODO').hide();
	}
	else if($('#todo_type').val()=='both')
	{
		$('.dateTrToTODO').show();
		$('.dateTrFromTODO').show();
	}
	else
	{
		$('.dateTrToTODO').hide();
		$('.dateTrFromTODO').hide();
		$('#repeat_row_TODO').hide();
	}

	if($('#repeat_TODO option:selected').attr('data-type')!="repeat_no-repeat" && $('#repeat_TODO option:selected').attr('data-type')!="custom_repeat")
		$('#repeat_details_TODO').show();

	if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_on_date")
	{
		$('#repeat_end_after_TODO').hide();
		$('#repeat_end_date_TODO').show();
	}

	if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_after")
	{
		$('#repeat_end_after_TODO').show();
		$('#repeat_end_date_TODO').hide();
	}

	if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_never")
	{
		$('#repeat_end_after_TODO').hide();
		$('#repeat_end_date_TODO').hide();
	}


	if(mod=='show')
	{
		if($('#ResourceCalDAVTODOList').find('[data-id="'+todo.res_id+'"]').hasClass("resourceCalDAV_item_ro"))
		{
			$('#editTODO').hide();
			$('#duplicateTODO').hide();
			$('#editOptionsButtonTODO').hide();
		}

		$('#saveTODO').hide();
		$('#resetTODO').hide();
		$('#deleteTODO').hide();
		$('#todoDetailsTable :input[type!="button"]').prop('disabled', true);
		$('#todoDetailsTable :input[type="text"]').prop('readonly', true);
		$('#todoDetailsTable textarea').prop('readonly', true);

		$('#percentageSlider').slider({disabled: true});

		/*************************** BAD HACKS SECTION ***************************/
		// here we fix the cross OS/cross broser problems (unfixable in pure CSS)
		if($.browser.webkit && !!window.chrome)	/* Chrome */
		{
			if(navigator.platform.toLowerCase().indexOf('win')==0)	/* Windows version */
			{
				$('#todo_details_template').find('input').css('text-indent', '2px');
				$('#todo_details_template').find('select').css({'padding-left': '0px', 'padding-right': '13px'});
			}
			else	/* non-Windows version */
				$('#todo_details_template').find('input').css('text-indent', '1px');
		}
		else if($.browser.safari)
		{
			$('#todo_details_template').find('textarea').addClass('safari_hack');
			$('#todo_details_template').find('input').addClass('safari_hack');
		}
		else if($.browser.msie)	/* IE */
		{
			if(parseInt($.browser.version, 10)==10)	/* IE 10 (because there are no more conditional comments) */
			{
				$('#todo_details_template').find('select').css({'padding-top': '1px', 'padding-left': '0px', 'padding-right': '0px'});
				$('#todo_details_template').find('textarea').css('padding-top', '3px');
				$('#todo_details_template').find('input[type=button]').css('padding-top', '2px');
			}
		}

		if($.browser.msie || $.browser.mozilla)
		{
			var newSVG=$(SVG_select_dis).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-22px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
			$('#todo_details_template').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
		}
		/*************************** END OF BAD HACKS SECTION ***************************/
	}
	if(repeatOne=='editOnly' || $('#recurrenceIDTODO').val()!='')
	{
		$('#repeat_TODO').parent().parent().css('display', 'none');
		$('#week_custom_TODO').css('display', 'none');
		$('#month_custom1_TODO').css('display', 'none');
		$('#month_custom2_TODO').css('display', 'none');
		$('#year_custom1_TODO').css('display', 'none');
		$('#year_custom2_TODO').css('display', 'none');
		$('#year_custom3_TODO').css('display', 'none');
		$('#repeat_details_TODO').css('display', 'none');
	}
	if(todo==null || todo.type=='' || (globalSettings.appleremindersmode.value && (todo.status=='COMPLETED' || todo.status== 'CANCELLED')) ||
		(globalSettings.appleremindersmode.value && typeof globalAppleSupport.nextDates[todo.id] == 'undefined'))
		$('#editOptionsButtonTODO').hide();
	else
		$('#editOptionsButtonTODO').click(function(){
			showTodoForm(globalCalTodo, 'show', '', true);
		});

	if(repeatOne=='editOnly' || repeatOne=='futureOnly' || $('#recurrenceIDTODO').val())
		$('#calendarLineTODO').hide();

	if(todo && todo.after && repeatOne=='futureOnly')
			$('#repeat_end_after_TODO').val(todo.after - todo.realRepeatCount + 1);

	$('#percenteCompleteValue').val(sliderValue);

	$('#percentageSlider').slider({
		animate: true,
		range: "min",
		value: sliderValue,
		min: 0,
		max: 100,
		step: 1,

		//this gets a live reading of the value and prints it on the page
		slide: function(event, ui)
		{
			$("#percenteCompleteValue").val(ui.value);
			$(this).parent().parent().find('img').css('display', 'none');
		},

		//this updates the hidden form field so we can submit the data using a form
		change: function(event, ui) {
			var status;

			if (ui.value>99 && $('#statusTODO').val()==='CANCELLED')
				status='CANCELLED';
			else if(ui.value>99)
				status='COMPLETED';
			else if(ui.value>0 && !globalSettings.appleremindersmode.value)
				status='IN-PROCESS';
			else
				status='NEEDS-ACTION';

			$('#statusTODO').val(status);
			todoStatusChanged(status);
		}
	});

	if(!globalSettings.timezonesupport.value)
		$('.timezone_rowTODO').css('display', 'none');

	//updateTodoFormDimensions();

	//if(window.event!=undefined)
	//	setTodoPosition(window.event);
	//else
	//	setTodoPosition(event);

	if($('#todo_type').val()=='none')
		stripTodoAlerts();
	if(mod!='new')
		$('#closeTODO').hide();
	globalObjectLoading=false;
	$('#CATodo').show(200, function(){
		$('#todoColor').css('background-color',color);
		checkTodoFormScrollBar();
		$('#todoForm').scrollTop(0);
	});
}

function bindTodoForm()
{
	initCalDavDatepicker($('#todo_details_template'));
	initCalDavTimepicker($('#todo_details_template'));

	$('#todo_details_template .alert_message_detailsTODO').change(function(){
		var data_id=$(this).attr("data-id");
		$('.before_after_inputTODO[data-id="'+data_id+'"]').parent().parent().find('img').css('display','none');
		if($('.alert_message_detailsTODO[data-id="'+data_id+'"] option:selected').attr('data-type')=="on_dateTODO")
		{
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('.dateTrToTODO').is(':visible') && $('.dateTrToTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_toTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_toTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('.dateTrFromTODO').is(':visible') && $('.dateTrFromTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_fromTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_fromTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}

			$('.message_date_inputTODO[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_date_inputTODO[data-id="'+data_id+'"]').show();
			$('.message_time_inputTODO[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('.message_time_inputTODO[data-id="'+data_id+'"]').show();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').hide();
		}
		else
		{
			$('.message_date_inputTODO[data-id="'+data_id+'"]').hide();
			$('.message_time_inputTODO[data-id="'+data_id+'"]').hide();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').show();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').val('15');
		}
	});

	$('#todo_details_template .before_after_inputTODO').bind('keyup change', function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^[0-9]+$")==null)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});

	$('#todo_details_template .alertTODO').change(function(){
		var data_id=$(this).attr("data-id");
		if($(this).val()!='none')
		{
			$('.alert_detailsTODO[data-id="'+data_id+'"]').show();
			$('.alert_message_dateTODO[data-id="'+data_id+'"]').show();
			if($('#todo_type').val()!='none')
				expandTodoAlerts();
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('.dateTrToTODO').is(':visible') && $('.dateTrToTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_toTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_toTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('.dateTrFromTODO').is(':visible') && $('.dateTrFromTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_fromTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_fromTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}

			$('.message_date_inputTODO[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_time_inputTODO[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			todo_alert_add(data_id);
		}
		else
		{
			$('.alert_detailsTODO[data-id="'+data_id+'"]').hide();
			$('.alert_message_dateTODO[data-id="'+data_id+'"]').hide();
			checkForTodo(data_id);
			var data_id=$(this).attr("data-id");
			$('#todo_details_template tr[data-id="'+data_id+'"]').remove();
		}
		checkTodoFormScrollBar();
	});

	$('#repeat_end_after_TODO, #repeat_interval_detail_TODO').bind('keyup change',function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^[0-9]+$")==null || parseInt($(this).val(),10)<1)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});

	$('#repeat_month_custom_select_TODO').change(function(){
		if($(this).val()=="custom")
		{
			$('#month_custom2_TODO').show();
			$('#repeat_month_custom_select2_TODO').parent().hide();
		}
		else
		{
			$('#month_custom2_TODO').hide();
			$('#repeat_month_custom_select2_TODO').parent().show();
		}
		checkTodoFormScrollBar();
	});

	$('#repeat_year_custom_select1_TODO').change(function(){
		if($(this).val()=="custom")
		{
			$('#year_custom1_TODO').show();
			$('#repeat_year_custom_select2_TODO').parent().hide();
		}
		else
		{
			$('#year_custom1_TODO').hide();
			$('#repeat_year_custom_select2_TODO').parent().show();
		}
		checkTodoFormScrollBar();
	});

	$('#repeat_end_details_TODO').change(function(){
		$('#repeat_end_date_TODO').parent().find('img').css('display', 'none');

		if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_on_date")
		{
			$('#repeat_end_after_TODO').hide();
			$('#repeat_end_date_TODO').show();

			var today;
			if($('#date_fromTODO').val()!='')
			{
				today=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_fromTODO').val());
				if(today==null)
					today=new Date();
			}
			else
				today=new Date();

			var date=new Date(today.getFullYear(), today.getMonth(), today.getDate()+2);
			$('#repeat_end_date_TODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date));
		}

		if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_after")
		{
			$('#repeat_end_after_TODO').show();
			$('#repeat_end_after_TODO').val('2');
			$('#repeat_end_date_TODO').hide();
		}

		if($('#repeat_end_details_TODO option:selected').attr('data-type')=="repeat_details_never")
		{
			$('#repeat_end_after_TODO').hide();
			$('#repeat_end_date_TODO').hide();
		}

		checkTodoFormScrollBar();
	});

	$('#todo_details_template .customTable td').click(function(){
		if($(this).hasClass('disabled'))
			return true;
		else if($(this).hasClass('selected'))
			$(this).removeClass('selected');
		else
			$(this).addClass('selected');
	});

	$('#closeTODO').click(function()
	{
		$('#todoInEdit').val('false');
		if($('#uidTODO').val()!='')
		{
			var uid=$('#uidTODO').val();
			var calUID=uid.substring(0, uid.lastIndexOf('/')+1);
			var color=$('#ResourceCalDAVTODOList').find("[data-id='"+calUID+"']").find('.resourceCalDAVColor').css('background-color');

			$('.event_item[data-id="'+uid+'"]').children('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
		}

		$('#TodoDisabler').fadeOut(globalEditorFadeAnimation, function(){
			$('#timezonePickerTODO').prop('disabled', false);
		});

		if(typeof globalCalTodo!= 'undefined' && globalCalTodo!=null && globalVisibleCalDAVTODOCollections.indexOf(globalCalTodo.res_id)!=-1)
		{
			$('#todoList').fullCalendar('selectEvent');
		}
		else
			$('#CATodo').attr('style','display:none');
	});

	$('#resetTODO').click(function(){
		$('#todo_details_template').find('img[data-type=invalidSlider],img[data-type=invalidSmall]').css('display','none');
		if($('#uidTODO').val()!='')
		{
			var uid=$('#uidTODO').val();
			var calUID=uid.substring(0, uid.lastIndexOf('/')+1);
			var color=$('#ResourceCalDAVTODOList').find("[data-id='"+calUID+"']").find('.resourceCalDAVColor').css('background-color');

			$('.event_item[data-id="'+uid+'"]').children('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color});

			if($('#recurrenceIDTODO').val()!='')
				showTodoForm(globalCalTodo, 'show','editOnly');
			else
				showTodoForm(globalCalTodo, 'show');
			startEditModeTodo();
		}
	});

	$('#todo_calendar').change(function(){
		var color = '';
		if($(this).val()=='choose')
			color = 'rgb(240,240,240)';
		else
			color=$('#ResourceCalDAVTODOList').find("[data-id='"+$(this).val()+"']").find('.resourceCalDAVColor').css('background-color');

		var uid='fooUID';
		if($('#uidTODO').val()!='')
			uid=$('#uidTODO').val();

		$('#todoColor').css('background-color',color);
		$('.event_item[data-id="'+uid+'"]').find('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
	});

	$('#repeat_TODO').change(function(){
		if($('#repeat_TODO option:selected').attr('data-type')=='repeat_no-repeat' || $('#repeat_TODO option:selected').attr('data-type')=="custom_repeat")
		{
			$('#repeat_details_TODO').hide();
			$('#repeat_interval_TODO').hide();
			$('#week_custom_TODO').hide();
			$('#month_custom1_TODO').hide();
			$('#month_custom2_TODO').hide();
			$('#year_custom1_TODO').hide();
			$('#year_custom2_TODO').hide();
			$('#year_custom3_TODO').hide();
		}
		else
		{
			$('#repeat_details_TODO').show();

			if($(this).val()!='BUSINESS' && $(this).val()!='TWO_WEEKLY' && $(this).val()!='WEEKEND')
			{
				$('#repeat_interval_TODO').show();
				$("#repeat_interval_detail_TODO").val('1');
				$('#repeat_interval_TODO').find('img').css('display','none');
			}
			else
				$('#repeat_interval_TODO').hide();

			if($(this).val()=='DAILY')
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);

			if($(this).val()=='WEEKLY')
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);

			if($(this).val()=='MONTHLY')
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);

			if($(this).val()=='YEARLY')
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);

			if($(this).val()=='CUSTOM_WEEKLY')
			{
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);
				$('#week_custom_TODO').show();
			}
			else
				$('#week_custom_TODO').hide();

			if($(this).val()=='CUSTOM_MONTHLY')
			{
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);
				$('#month_custom1_TODO').show();
				if($('#repeat_month_custom_select_TODO').val() == "custom")
					$('#repeat_month_custom_select_TODO').trigger('change');
			}
			else
			{
				$('#month_custom1_TODO').hide();
				$('#month_custom2_TODO').hide();
			}

			if($(this).val()=='CUSTOM_YEARLY')
			{
				$('#repeat_interval_TODO [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
				$('#year_custom2_TODO').show();
				$('#year_custom3_TODO').show();
				if($('#repeat_year_custom_select1_TODO').val() == "custom")
					$('#repeat_year_custom_select1_TODO').trigger('change');
			}
			else
			{
				$('#year_custom1_TODO').hide();
				$('#year_custom2_TODO').hide();
				$('#year_custom3_TODO').hide();
			}

			var today;
			if($('#date_fromTODO').val()!='')
			{
				today=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_fromTODO').val());
				if(today==null)
					today=new Date();
			}
			else
				today=new Date();

			var date=new Date(today.getFullYear(),today.getMonth(),today.getDate()+2);
			$('#repeat_end_date_TODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date));
		}
		checkTodoFormScrollBar();
	});

	$('#statusTODO').change(function(){
		var status = $(this).val();

		switch(status) {
			case 'NEEDS-ACTION':
				$('#percenteCompleteValue').val(0);
				$('#percentageSlider').slider({value: 0});
				$('#nameTODO').removeClass('title_cancelled');
				break;
			case 'IN-PROCESS':
				var value = 50;
				var id = $('.fc-event-selected').attr('data-repeat-hash');
				if(typeof globalTodolistStatusArray[id]!='undefined' && typeof globalTodolistStatusArray[id].percent!='undefined')
					value=globalTodolistStatusArray[id].percent;
				$('#percenteCompleteValue').val(value);
				$('#percentageSlider').slider({value: value});
				$('#nameTODO').removeClass('title_cancelled');
				break;
			case 'CANCELLED':
				$('#percenteCompleteValue').val(100);
				$('#percentageSlider').slider({value: 100});
				$('#nameTODO').addClass('title_cancelled');
				break;
			case 'COMPLETED':
				$('#percenteCompleteValue').val(100);
				$('#percentageSlider').slider({value: 100});
				$('#nameTODO').removeClass('title_cancelled');
				break;
			default:
				break;
		}

		todoStatusChanged(status);
	});

	$('#todo_type').change(function(){
		if($(this).val()=='none')
		{
			$('#timezoneTODO').val('local');
			$('#repeat_row_TODO').hide();
			$('#date_fromTODO, #time_fromTODO, #date_toTODO, #time_toTODO').parent().find('img').css('display','none');
			$('.dateTrFromTODO, .dateTrToTODO, .timezone_rowTODO').hide();
			stripTodoAlerts();
		}
		else if($(this).val()=='start')
		{
			var myDate=new Date();
			$('#date_fromTODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('#time_fromTODO').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('#repeat_row_TODO').show();
			$('#date_toTODO, #time_toTODO').parent().find('img').css('display','none');
			$('.dateTrToTODO').hide();

			$('.dateTrFromTODO').show();
			if(globalSettings.timezonesupport.value)
			{
				$('.timezone_rowTODO').show();
				$('#timezoneTODO').val(globalSessionTimeZone);
			}
			$('#date_fromTODO, #time_fromTODO').trigger('change');
		}
		else if($(this).val()=='due')
		{
			var myDate=new Date($('#todoList').fullCalendar('getView').start.getTime());
			myDate.setHours(globalSettings.calendarendofbusiness.value);
			myDate.setMinutes((globalSettings.calendarendofbusiness.value%1)*60);
			$('#date_toTODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('#time_toTODO').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('#repeat_row_TODO').show();
			$('#date_fromTODO, #time_fromTODO').parent().find('img').css('display','none');
			$('.dateTrFromTODO').hide();

			$('.dateTrToTODO').show();
			if(globalSettings.timezonesupport.value)
			{
				$('.timezone_rowTODO').show();
				$('#timezoneTODO').val(globalSessionTimeZone);
			}
			$('#date_toTODO, #time_toTODO').trigger('change');
		}
		else if($(this).val()=='both')
		{
			var myDate='';
			var myDateStart= new Date();
			if($('#date_toTODO').val()!='')
			{
				var dateFrom=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_toTODO').val());
				var datetime_to=$.fullCalendar.formatDate(dateFrom, 'yyyy-MM-dd');
				var aDate=new Date(Date.parse("01/02/1990, "+$('#time_toTODO').val()));
				var time_from=$.fullCalendar.formatDate(aDate, 'HH:mm:ss');
				var myDate=$.fullCalendar.parseDate(datetime_to+'T'+time_from);
			}
			else
			{
				myDate=new Date($('#todoList').fullCalendar('getView').start.getTime());
				$('#repeat_row_TODO').show();
				myDate.setHours(globalSettings.calendarendofbusiness.value);
				myDate.setMinutes((globalSettings.calendarendofbusiness.value%1)*60);
				if($('#date_toTODO').val()=='')
					$('#date_toTODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
				if($('#time_toTODO').val()=='')
					$('#time_toTODO').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			}

			if(myDateStart>myDate)
				myDateStart= new Date(myDate.getTime());
			globalPrevDate = new Date(myDateStart.getTime());
			if($('#date_fromTODO').val()=='')
				$('#date_fromTODO').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDateStart));

			if($('#time_fromTODO').val()=='')
				$('#time_fromTODO').val($.fullCalendar.formatDate(myDateStart, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));

			$('.dateTrFromTODO, .dateTrToTODO').show();
			if(globalSettings.timezonesupport.value)
			{
				$('.timezone_rowTODO').show();
				$('#timezoneTODO').val(globalSessionTimeZone);
			}
			$('#date_fromTODO, #time_fromTODO, #date_toTODO, #time_toTODO').trigger('change');
		}
		if($('#todo_type').val()!='none')
			expandTodoAlerts();
		checkTodoFormScrollBar();
	});

	$('#percenteCompleteValue').bind('keyup change',function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
		}
		else
		{
			if($(this).val().match('^(([0-9])|([1-9][0-9])|(100))$')==null)
				$(this).parent().find('img').css('display', 'inline');
			else
			{
				$(this).parent().find('img').css('display', 'none');
				$( "#percentageSlider" ).slider({value: $(this).val()});
			}
		}
	});
}

function showEventForm(date, allDay, calEvent, jsEvent, mod, repeatOne, confirmRepeat)
{
	$('#event_details_template').remove();
	$('#CAEvent').html(cleanVcalendarTemplate);
	setFirstDayEvent();
	bindEventForm();

	$('#note').autosize({defaultStyles: {height: '64', overflow: '', 'overflow-y': '', 'word-wrap': '', resize: 'none'}, callback: function(){checkEventFormScrollBar();}});
	$("#show").val('');
	$("#uid").val('');
	$("#etag").val('');
	$("#repeatCount").val('');
	$("#repeatEvent").val('');
	$("#recurrenceID").val('');
	$("#futureStart").val('');
	$("#vcalendarHash").val('');
	$("#vcalendarUID").val('');
	globalPrevDate='';
	var color='';
	if(mod=='new')
	{
		var activeCollection = $('#ResourceCalDAVList').find('.resourceCalDAV_item.resourceCalDAV_item_selected');
		if(activeCollection.length>0 && !globalResourceCalDAVList.getEventCollectionByUID(activeCollection.attr('data-id')).permissions.read_only)
			color=rgbToHex(activeCollection.children('.resourceCalDAVColor').css('background-color'));
	}
	else
		color=globalResourceCalDAVList.getEventCollectionByUID(calEvent.res_id).ecolor;

	if(confirmRepeat)
	{
		$('#show').val(calEvent.id);
		$('#repeatEvent').val(true);
		$('#CAEvent').show();
		$('#repeatConfirmBox').css('visibility', 'visible');
		if(calEvent.repeatCount!='' && calEvent.repeatCount == 1)
		{
			$('#editFuture').css('display','none');
			if($('#editFuture').next('br').length>0)
				$('#editFuture').next().remove();
		}
		else if($('#editFuture').css('display')=='none')
		{
			$('#editFuture').css('display','block');
			if($('#editFuture').next('br').length==0)
				$('#editFuture').after('<br/>')
		}
		$('#repeatConfirmBoxContent').html('<b>'+calEvent.title+"</b> "+localization[globalInterfaceLanguage].repeatBoxContent);
		$('#repeatConfirmBoxQuestion').html(localization[globalInterfaceLanguage].repeatBoxQuestion);

		$('#editAll, #editOnlyOne, #editFuture').click(function(){
			if(globalCalEvent)
			{
				if($(this).attr('id')=='editOnlyOne')
					showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', 'editOnly');
				else if($(this).attr('id')=='editAll')
						showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', '');
				else if($(this).attr('id')=='editFuture')
					showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', 'futureOnly');

				$('#repeatConfirmBoxContent').html('');
				$('#repeatConfirmBox').css('visibility', 'hidden');
				$('#AlertDisabler').fadeOut(globalEditorFadeAnimation);
			}
		});

		$('#CAEvent').height($('#repeatConfirmBox').height());
		$('#eventColor').css('background-color',color);
		updateEventFormDimensions();
		setFormPosition(jsEvent, true);
		$('#event_details_template').scrollTop(0);
		return true;
	}

	if(mod=='show' && repeatOne=='futureOnly')
	{
		$('#futureStart').val(calEvent.realRepeatCount+';'+calEvent.start);
	}
	if(mod!='new')
		fullVcalendarToData(calEvent);
	else
		CalDAVeditor_cleanup();

		if(calEvent!=null && ((repeatOne=='editOnly'&&calEvent.type) || calEvent.rec_id))
		{
			var eventsSorted=jQuery.grep(globalEventList.displayEventsArray[calEvent.res_id],function(e){if(e.id==calEvent.id)return true}).sort(repeatStartCompare);
			if(eventsSorted.indexOf(calEvent)!=-1)
			{
				if(eventsSorted.indexOf(calEvent)<(eventsSorted.length-1))
					showEventNextNav();
				if(eventsSorted.indexOf(calEvent)!=0)
					showEventPrevNav();
			}
		}

	var cals=globalResourceCalDAVList.sortedCollections;
	var calendarObj = $('#event_calendar');
	var calSelected = $('.resourceCalDAV_item.resourceCalDAV_item_selected').attr('data-id');
		for(var i=0;i<cals.length;i++)
		{
			if(cals[i].uid!=undefined && ((calEvent!=null && calEvent.res_id==cals[i].uid) || (cals[i].makeLoaded && !cals[i].permissions_read_only )))
			{
				calendarObj.append(new Option(cals[i].displayValue,cals[i].uid));
			}
		}

	if(mod=='new')
	{
		$('#show').val('');
		$('#editButton').hide();
		$('#duplicateButton').hide();
		$('#editOptionsButton').hide();
		$('#resetButton').hide();
		$('#deleteButton').hide();

		if($('#ResourceCalDAVList').find('.resourceCalDAV_item.resourceCalDAV_item_selected').length>0 && $('#event_calendar').find('option[value="'+$('#ResourceCalDAVList').find('.resourceCalDAV_item.resourceCalDAV_item_selected').attr("data-id")+'"]').length>0)
			$('.R_calendar').val($('#ResourceCalDAVList').find('.resourceCalDAV_item.resourceCalDAV_item_selected').attr("data-id"));
		else
			$('#event_calendar').val('choose');
	}

	if(mod=='drop')
	{
		if(calEvent.etag!='')
			$('#event_calendar').val(calEvent.res_id);
	}

	if(mod=='new')
	{
		//$('[data-type="name"]').attr('placeholder', localization[globalInterfaceLanguage].pholderNewEvent);
		var date_to = null;

		if(calEvent!==null)
		{
			if(calEvent.realStart)
				date=calEvent.realStart;
			else
				date=calEvent.start;

			if(calEvent.realEnd)
				date_to=new Date(calEvent.realEnd.getTime());
			else
				date_to=new Date(calEvent.end.getTime());
		}

		if(!allDay && ((date_to==null) || ((date_to-date)==0))) {
			date_to = new Date(date.getTime());

			if(globalSettings.defaulteventduration.value!==null)
				date_to.setMinutes(date_to.getMinutes()+globalSettings.defaulteventduration.value);
			else {
				date_to.setHours(globalSettings.calendarendofbusiness.value);
				date_to.setMinutes((globalSettings.calendarendofbusiness.value%1)*60);
			}

			if(date_to.getTime()<date.getTime())
				date_to.setDate(date_to.getDate()+1);
		}

		var beforeScroll = $('#main').width()-$('#calendar').width();
		$('#calendar').fullCalendar('renderEvent', $.extend(new items('',date,date_to,localization[globalInterfaceLanguage].pholderNewEvent, allDay, 'fooUID', '', '', '', '', '', '', '', '', '', '', '', '', '','', '', '', '', '', '', '', '', '','', '', '', '', '', '', '', ''),{backgroundColor:hexToRgba(color,0.9),borderColor:color,textColor:checkFontColor(color)}));
		var afterScroll = $('#main').width()-$('#calendar').width();
		rerenderCalendar(beforeScroll!=afterScroll);

		if(allDay)
		{
			$('#allday').prop('checked', true);
			$('#time_from_cell').css('visibility', 'hidden');
			$('#time_to_cell').css('visibility', 'hidden');
			$('.timezone_row').css('display', 'none');
		}
		showTimezones('', '');
	}

	if(mod=='show' || mod=='drop')
	{
		if(calEvent.status=='CANCELLED')
			$('#name').addClass('title_cancelled');

		$('#name').val(calEvent.title);
		$('#location').val(calEvent.location);

		if(calEvent.allDay==true)
		{
			$('#allday').prop('checked', true);
			$('#time_from_cell').css('visibility', 'hidden');
			$('#time_to_cell').css('visibility', 'hidden');
			$('.timezone_row').css('display', 'none');
		}

		if(calEvent.end)
			if(calEvent.realEnd && (mod!='drop'  || repeatOne!='editOnly'))
				date_to=new Date(calEvent.realEnd.getTime());
			else
				date_to=new Date(calEvent.end.getTime());

		$('#note').val(calEvent.note).trigger('autosize.resize');
		if(typeof calEvent.classType!='undefined' && calEvent.classType!=null && calEvent.classType!='')
			$('#type').val(calEvent.classType.toLowerCase());
		else
			$('#type').val('public');

		if(calEvent.status!='')
			$('#status').val(calEvent.status);
		else
			$('#status').val('NONE');

		if(calEvent!=null && mod!='new')
		{
			var uidArray = calEvent.id.match(vCalendar.pre['uidParts']);
			if(decodeURIComponent(uidArray[4]).indexOf(uidArray[2])==-1)
				$('.row_type').css('display','none');
		}

		if(calEvent.avail == 'OPAQUE')
			$('#avail').val('busy');
		else
			$('#avail').val('free');

		if(calEvent!=null)
		{
			var prior=parseInt(calEvent.priority,10);
			if(prior==5)
				$('#priority').val(5);
			else if(prior>5 && prior<10)
			{
				$('#priority [data-type="priority_low"]').attr('value',prior)
				$('#priority').val(prior);
			}
			else if(prior<5 && prior>0)
			{
				$('#priority [data-type="priority_high"]').attr('value',prior)
				$('#priority').val(prior);
			}
			else
				$('#priority').val(0);
		}

		$('#uid').val(calEvent.id);
		$('#url_EVENT').val(calEvent.hrefUrl+'');
		$('#vcalendarHash').val(hex_sha256(calEvent.vcalendar));
		$('#etag').val(calEvent.etag);
		var stringUIDcurrent=calEvent.vcalendar.match(vCalendar.pre['contentline_UID']);

		if(stringUIDcurrent!=null)
			stringUIDcurrent=stringUIDcurrent[0].match(vCalendar.pre['contentline_parse'])[4];

		if(stringUIDcurrent)
			$('#vcalendarUID').val(stringUIDcurrent);

		var alarmDate='';
		for(var alarmIterator=0;alarmIterator<calEvent.alertTime.length;alarmIterator++)
		{
			if(alarmIterator>0)
				event_alert_add(alarmIterator);

			$(".alert[data-id="+(alarmIterator+1)+"]").val("message");
			if(calEvent.alertTime[alarmIterator].charAt(0)=='-' || calEvent.alertTime[alarmIterator].charAt(0)=='+')
			{
				var alVal=parseInt(calEvent.alertTime[alarmIterator].substring(1, calEvent.alertTime[alarmIterator].length-1));
				var alString='';

				if(calEvent.alertTime[alarmIterator].charAt(calEvent.alertTime[alarmIterator].length-1)=="W")
				{
					alVal=alVal/1000/60/60/24/7;
					alString='weeks';
				}
				else if(calEvent.alertTime[alarmIterator].charAt(calEvent.alertTime[alarmIterator].length-1)=="D")
				{
					alVal=alVal/1000/60/60/24;
					alString='days';
				}
				else if(calEvent.alertTime[alarmIterator].charAt(calEvent.alertTime[alarmIterator].length-1)=="H")
				{
					alVal=alVal/1000/60/60;
					alString='hours';
				}
				else if(calEvent.alertTime[alarmIterator].charAt(calEvent.alertTime[alarmIterator].length-1)=="M")
				{
					alVal=alVal/1000/60;
					alString='minutes';
				}
				else if(calEvent.alertTime[alarmIterator].charAt(calEvent.alertTime[alarmIterator].length-1)=="S")
				{
					alVal=alVal/1000;
					alString='seconds';
				}

				if(calEvent.alertTime[alarmIterator].charAt(0)=='-')
					alString+="_before";
				else
					alString+="_after"

				$(".alert_message_details[data-id="+(alarmIterator+1)+"]").val(alString);
				$(".before_after_input[data-id="+(alarmIterator+1)+"]").val(alVal);
				$('.alert_details[data-id="'+(alarmIterator+1)+'"]').show();
				$('.alert_message_date[data-id="'+(alarmIterator+1)+'"]').show();
				$('.before_after_input[data-id="'+(alarmIterator+1)+'"]').show();
				$(".message_date_input[data-id="+(alarmIterator+1)+"]").hide();
				$(".message_time_input[data-id="+(alarmIterator+1)+"]").hide();
			}
			else
			{
				alarmDate=$.fullCalendar.parseDate(calEvent.alertTime[alarmIterator]);
				(alarmDate.getHours())<10 ? (hour='0'+(alarmDate.getHours())) : (hour=alarmDate.getHours());
				(alarmDate.getMinutes())<10 ? (minute='0'+(alarmDate.getMinutes())) : (minute=alarmDate.getMinutes());

				$(".alert_message_details[data-id="+(alarmIterator+1)+"]").val('on_date');
				var formattedAlarmDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, alarmDate);

				$(".message_date_input[data-id="+(alarmIterator+1)+"]").val(formattedAlarmDate);
				$(".message_time_input[data-id="+(alarmIterator+1)+"]").val($.fullCalendar.formatDate(alarmDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));

				$('.alert_details[data-id="'+(alarmIterator+1)+'"]').show();
				$('.alert_message_date[data-id="'+(alarmIterator+1)+'"]').show();
			}
		}

		if(alarmIterator>0)
			event_alert_add(alarmIterator+2);

		if(calEvent.type!='' && repeatOne!='editOnly' && calEvent.ruleString.match(vCalendar.re['recurCaldav'])!=null)
		{
			var ruleString=calEvent.vcalendar.match(vCalendar.pre['contentline_RRULE2'])[0].match(vCalendar.pre['contentline_parse'])[4];
			if(ruleString.indexOf('BYMONTH=')!=-1 || ruleString.indexOf('BYMONTHDAY=')!=-1 || ruleString.indexOf('BYDAY=')!=-1)
			{
				var pars=ruleString.split(';');

				if(pars.indexElementOf('BYMONTH=')!=-1 && pars.indexElementOf('BYMONTHDAY=')==-1 && pars.indexElementOf('BYDAY=')==-1)
					pars[pars.length] = "BYMONTHDAY="+calEvent.start.getDate();
				if(calEvent.type=="DAILY")
				{
					$("#repeat option[value='DAILY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);
				}
				else if(calEvent.type=="WEEKLY")
				{
					$("#repeat option[value='CUSTOM_WEEKLY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);

					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.replace(/\d*MO/,1).replace(/\d*TU/,2).replace(/\d*WE/,3).replace(/\d*TH/,4).replace(/\d*FR/,5).replace(/\d*SA/,6).replace(/\d*SU/,0).split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								if(!isNaN(parseInt(byDay[rj],10)))
									$('#week_custom .customTable td[data-type="'+byDay[rj]+'"]').addClass('selected');
							}
						}
					}
					$('#week_custom').show();
				}
				else if(calEvent.type=="MONTHLY")
				{
					$("#repeat option[value='CUSTOM_MONTHLY']").prop('selected', true).change();
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);


					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								var checkString = byDay[rj].match(vCalendar.pre['+/-number']);
								byDay[rj] = byDay[rj].replace(checkString[0],'');
								if(!isNaN(parseInt(checkString[0],10)))
								{
									switch(parseInt(checkString[0],10))
									{
										case 1:
											$('#repeat_month_custom_select').val('first');
											break;
										case 2:
											$('#repeat_month_custom_select').val('second');
											break;
										case 3:
											$('#repeat_month_custom_select').val('third');
											break;
										case 4:
											$('#repeat_month_custom_select').val('fourth');
											break;
										case 5:
											$('#repeat_month_custom_select').val('fifth');
											break;
										case -1:
											$('#repeat_month_custom_select').val('last');
											break;
										default:
											$('#repeat_month_custom_select').val('every');
											break;
									}
									$('#repeat_month_custom_select2').val(byDay[rj]);
								}
							}
						}
						else if(pars[ri].indexOf("BYMONTHDAY=")!=-1)
						{
							$('#repeat_month_custom_select').val('custom').change();
							var byMonthDay=pars[ri].split('=')[1];
							byMonthDay=byMonthDay.split(',');
							for(var rj=0; rj<byMonthDay.length;rj++)
							{
								if(parseInt(byMonthDay[rj],10)==-1)
								{
									$('#repeat_month_custom_select').val('last').change();
									$('#repeat_month_custom_select2').val("DAY");

								}
								else
									$('#month_custom2 .customTable td[data-type="'+(parseInt(byMonthDay[rj],10))+'"]').addClass('selected');
							}
						}
					}
				}
				else if(calEvent.type=="YEARLY")
				{
					$("#repeat option[value='CUSTOM_YEARLY']").prop('selected', true).change();
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
					var isMonthDay=false;
					for(var ri=0;ri<pars.length;ri++)
					{
						if(pars[ri].indexOf("BYDAY=")!=-1)
						{
							var byDay=pars[ri].split('=')[1];
							byDay=byDay.split(',');
							for(var rj=0;rj<byDay.length;rj++)
							{
								var checkString = byDay[rj].match(vCalendar.pre['+/-number']);
								byDay[rj] = byDay[rj].replace(checkString[0],'');
								if(!isNaN(parseInt(checkString[0],10)))
								{
									switch(parseInt(checkString[0],10))
									{
										case 1:
											$('#repeat_year_custom_select1').val('first');
											break;
										case 2:
											$('#repeat_year_custom_select1').val('second');
											break;
										case 3:
											$('#repeat_year_custom_select1').val('third');
											break;
										case 4:
											$('#repeat_year_custom_select1').val('fourth');
											break;
										case 5:
											$('#repeat_year_custom_select1').val('fifth');
											break;
										case -1:
											$('#repeat_year_custom_select1').val('last');
											break;
										default:
											$('#repeat_year_custom_select1').val('every');
											break;
									}
									$('#repeat_year_custom_select2').val(byDay[rj]);
								}
							}
						}
						else if(pars[ri].indexOf("BYMONTHDAY=")!=-1)
						{
							$('#repeat_year_custom_select1').val('custom').change()
							var byMonthDay=pars[ri].split('=')[1];
							byMonthDay=byMonthDay.split(',');
							for(var rj=0; rj<byMonthDay.length;rj++)
							{
								if(parseInt(byMonthDay[rj],10)==-1)
								{
									$('#repeat_year_custom_select1').val('last').change();
									$('#repeat_year_custom_select2').val("DAY");

								}
								else
									$('#year_custom1 .customTable td[data-type="'+(parseInt(byMonthDay[rj],10))+'"]').addClass('selected');
							}
							isMonthDay=true;
						}
						else if(pars[ri].indexOf("BYMONTH=")!=-1)
						{
							var byMonth=pars[ri].split('=')[1];
							byMonth=byMonth.split(',');
							for(var rj=0; rj<byMonth.length;rj++)
								$('#year_custom3 .customTable td[data-type="'+(parseInt(byMonth[rj],10)-1)+'"]').addClass('selected');
						}
					}
				}

				if(calEvent.after=='' && calEvent.untilDate=='')
					$("#repeat_end_details option[value='never']").prop('selected', true);
				else if(calEvent.after!='')
				{
					$("#repeat_end_details option[value='after']").prop('selected', true);
					$('#repeat_end_after').val(calEvent.after);
				}
				else if(calEvent.untilDate!='')
				{
					date=$.fullCalendar.parseDate(calEvent.untilDate);
					$("#repeat_end_details option[value='on_date']").prop('selected', true);
					var formattedRepeatDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
					$('#repeat_end_date').val(formattedRepeatDate);
				}

				$('#repeat_interval_detail').val(calEvent.interval);
				$('#repeat_interval').show();

				if(calEvent.byDay.length>0)
				{
					var businessArray=new Array();
					if(globalSettings.weekenddays.value.length>0)
						for(var i=0;i<7;i++)
							if(globalSettings.weekenddays.value.indexOf(i)==-1)
								businessArray[businessArray.length]=i+'';
					var businessCount=0;
					var weekendCount=0;
					for(var i=0;i<byDay.length;i++)
					{
						if(businessArray.indexOf(byDay[i])!=-1)
							businessCount++;
						if(globalSettings.weekenddays.value.indexOf(parseInt(byDay[i],10))!=-1)
							weekendCount++;

					}

					if(businessArray.length>0 && businessArray.length==businessCount)
					{
						$("#repeat option[value='BUSINESS']").prop('selected', true);
						$('#repeat_interval').hide();
						$('#week_custom').hide();
					}
					else if(globalSettings.weekenddays.value.length>0 && globalSettings.weekenddays.value.length==weekendCount)
					{
						$("#repeat option[value='WEEKEND']").prop('selected', true);
						$('#repeat_interval').hide();
						$('#week_custom').hide();
					}
				}

			}
			else
			{
				if(calEvent.type=="DAILY")
				{
					$("#repeat option[value='DAILY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);
				}
				else if(calEvent.type=="WEEKLY")
				{
					$("#repeat option[value='WEEKLY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);
				}
				else if(calEvent.type=="MONTHLY")
				{
					$("#repeat option[value='MONTHLY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);
				}
				else if(calEvent.type=="YEARLY")
				{
					$("#repeat option[value='YEARLY']").prop('selected', true);
					$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
				}

				if(calEvent.after=='' && calEvent.untilDate=='')
					$("#repeat_end_details option[value='never']").prop('selected', true);
				else if(calEvent.after!='')
				{
					$("#repeat_end_details option[value='after']").prop('selected', true);
					$('#repeat_end_after').val(calEvent.after);
				}
				else if(calEvent.untilDate!='')
				{
					date=$.fullCalendar.parseDate(calEvent.untilDate);
					$("#repeat_end_details option[value='on_date']").prop('selected', true);
					var formattedRepeatDate=$.datepicker.formatDate(globalSettings.datepickerformat.value, date);
					$('#repeat_end_date').val(formattedRepeatDate);
				}

				$('#repeat_interval_detail').val(calEvent.interval);
				$('#repeat_interval').show();

				if(calEvent.byDay.length>0)
				{
					if(calEvent.byDay.indexOf('1')!=-1 && calEvent.byDay.indexOf('2')!=-1 && calEvent.byDay.indexOf('3')!=-1 && calEvent.byDay.indexOf('4')!=-1 && calEvent.byDay.indexOf('5')!=-1 && calEvent.byDay.indexOf('6')==-1 && calEvent.byDay.indexOf('0')==-1)
					{
						$("#repeat option[value='BUSINESS']").prop('selected', true);
						$('#repeat_interval').hide();
					}
					else if(calEvent.byDay.indexOf('1')==-1 && calEvent.byDay.indexOf('2')==-1 && calEvent.byDay.indexOf('3')==-1 && calEvent.byDay.indexOf('4')==-1 && calEvent.byDay.indexOf('5')==-1 && calEvent.byDay.indexOf('6')!=-1 && calEvent.byDay.indexOf('0')!=-1)
					{
						$("#repeat option[value='WEEKEND']").prop('selected', true);
						$('#repeat_interval').hide();
					}
				}
			$('#repeatEvent').val(true);
			}
		}
		else if(calEvent.type!='' && repeatOne!='editOnly')
		{
			var cu_opt = new Option(localization[globalInterfaceLanguage].customRepeat, calEvent.ruleString, false, true);
			$(cu_opt).attr('data-type','custom_repeat');
			$('#repeat').append(cu_opt);
		}
		else
			$('#repeatEvent').val(false);

		if(calEvent.timeZone)
			showTimezones(calEvent.timeZone,'');
		else
			showTimezones('local','');
	}

	var year,
	month,
	day,
	hour,
	minute;
	if(mod=='show')
		$('#show').val(calEvent.id);
	if(mod=='show' || mod=='drop')
	{
		$('#repeatCount').val(calEvent.repeatCount);
		if(calEvent.realStart && (mod!='drop' || repeatOne!='editOnly'))
			date=calEvent.realStart;
		else
			date=calEvent.start;

		if($('#show').val())
		{
			if(calEvent.repeatStart && repeatOne=='')
				date=new Date(calEvent.repeatStart.getTime());
			if(calEvent.repeatEnd && repeatOne=='')
				date_to=new Date(calEvent.repeatEnd.getTime());

		}
		if(repeatOne=='editOnly')
		{
			if((mod=='drop' && globalPrevDragEventAllDay) || (mod!='drop' && calEvent.allDay))
			{
				if(calEvent.realStart)
					$('#recurrenceID').val($.fullCalendar.formatDate($.fullCalendar.parseDate(calEvent.realStart), "yyyyMMdd"));
				else
					$('#recurrenceID').val($.fullCalendar.formatDate(date, "yyyyMMdd"));
			}
			else
			{
				if(calEvent.realStart)
					$('#recurrenceID').val($.fullCalendar.formatDate(calEvent.realStart, "yyyyMMdd'T'HHmmss"));
				else
					$('#recurrenceID').val($.fullCalendar.formatDate(date, "yyyyMMdd'T'HHmmss"));
			}
		}
		else
			$('#recurrenceID').val(calEvent.rec_id);

		if(calEvent.rec_id || repeatOne=='editOnly' || repeatOne=='futureOnly')
		{
			var savedEvs=jQuery.grep(globalEventList.displayEventsArray[calEvent.res_id],function(e){if(e.id==calEvent.id && (e.repeatCount<2 || !e.repeatCount))return true});
			if(savedEvs.length>1 || (repeatOne=='futureOnly' && calEvent.repeatCount>1) || (repeatOne=='editOnly' && calEvent.type!=''))
				$('#deleteButton').attr('onclick',"updateEventFormDimensions(true);$('#CAEvent .saveLoader').show();save(false, true);");
		}
	}


	var today = new Date();
	var todayClear = new Date(today.getTime());
	todayClear.setHours(0);
	todayClear.setMinutes(0);
	todayClear.setSeconds(0);
	todayClear.setMilliseconds(0);
	var dateClear = new Date(date.getTime());
	dateClear.setHours(0);
	dateClear.setMinutes(0);
	dateClear.setSeconds(0);
	dateClear.setMilliseconds(0);

	if(allDay)
	{
		if(globalSettings.defaulteventduration.value!==null && todayClear.getTime()===dateClear.getTime())
		{
			if(today.getMinutes()>0) {
				date.setHours(today.getHours()+1);
				date.setMinutes(0);
			}
			else {
				date.setHours(today.getHours());
				date.setMinutes(today.setMinutes());
			}
		}
		else {
			date.setHours(globalSettings.calendarstartofbusiness.value);
			date.setMinutes((globalSettings.calendarstartofbusiness.value%1)*60);
		}
	}

	$('#date_from').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date));
	$('#time_from').val($.fullCalendar.formatDate(date, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
	globalPrevDate=new Date(date.getTime());

	if(typeof date_to==='undefined' || date_to===null)
		date_to = new Date(date.getTime());

	if(allDay) {
		if(globalSettings.defaulteventduration.value!==null)
		{
			date_to.setHours(date.getHours());
			date_to.setMinutes(date.getMinutes()+globalSettings.defaulteventduration.value);
		}
		else {
			date_to.setHours(globalSettings.calendarendofbusiness.value);
			date_to.setMinutes((globalSettings.calendarendofbusiness.value%1)*60);
		}
	}

	if(date_to.getTime()<date.getTime())
		date_to.setDate(date_to.getDate()+1);

	$('#date_to').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date_to));
	$('#time_to').val($.fullCalendar.formatDate(date_to, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));

	if($('#repeat option:selected').attr('data-type')!="repeat_no-repeat" && $('#repeat option:selected').attr('data-type')!="custom_repeat")
		$('#repeat_details').show();

	if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_on_date")
	{
		$('#repeat_end_after').hide();
		$('#repeat_end_date').show();
	}

	if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_after")
	{
		$('#repeat_end_after').show();
		$('#repeat_end_date').hide();
	}

	if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_never")
	{
		$('#repeat_end_after').hide();
		$('#repeat_end_date').hide();
	}

	if(mod=='show')
	{
		$('#saveButton').hide();
		$('#resetButton').hide();
		$('#deleteButton').hide();
		if($('#ResourceCalDAVList').find('[data-id="'+calEvent.res_id+'"]').hasClass("resourceCalDAV_item_ro"))
		{
			$('#editButton').hide();
			$('#duplicateButton').hide();
			$('#editOptionsButton').hide();
		}
		$('#eventDetailsTable :input[type!="button"]').prop('disabled', true);
		$('#eventDetailsTable :input[type="text"]').prop('readonly', true);
		$('#eventDetailsTable .customTable td').addClass('disabled');
		$('#eventDetailsTable textarea').prop('readonly', true);

		/*************************** BAD HACKS SECTION ***************************/
		// here we fix the cross OS/cross broser problems (unfixable in pure CSS)
		if($.browser.webkit && !!window.chrome)	/* Chrome */
		{
			if(navigator.platform.toLowerCase().indexOf('win')==0)	/* Windows version */
			{
				$('#event_details_template').find('input').css('text-indent', '2px');
				$('#event_details_template').find('select').css({'padding-left': '0px', 'padding-right': '13px'});
			}
			else	/* non-Windows version */
				$('#event_details_template').find('input').css('text-indent', '1px');
		}
		else if($.browser.safari)
		{
			$('#event_details_template').find('textarea').addClass('safari_hack');
			$('#event_details_template').find('input').addClass('safari_hack');
		}
		else if($.browser.msie)	/* IE */
		{
			if(parseInt($.browser.version, 10)==10)	/* IE 10 (because there are no more conditional comments) */
			{
				$('#event_details_template').find('select').css({'padding-top': '1px', 'padding-left': '0px', 'padding-right': '0px'});
				$('#event_details_template').find('textarea').css('padding-top', '3px');
				$('#event_details_template').find('input[type=button]').css('padding-top', '2px');
			}
		}

		if($.browser.msie || $.browser.mozilla)
		{
			var newSVG=$(SVG_select_dis).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-22px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
			$('#event_details_template').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
		}
		/*************************** END OF BAD HACKS SECTION ***************************/
		if(calEvent.etag!='')
			$('#event_calendar').val(calEvent.res_id);
	}

	if(repeatOne=='editOnly' || $('#recurrenceID').val()!='')
	{
		$('#repeat').parent().parent().css('display', 'none');
		$('#week_custom').css('display', 'none');
		$('#month_custom1').css('display', 'none');
		$('#month_custom2').css('display', 'none');
		$('#year_custom1').css('display', 'none');
		$('#year_custom2').css('display', 'none');
		$('#year_custom3').css('display', 'none');
		$('#repeat_details').css('display', 'none');
	}

	if(repeatOne=='editOnly' || repeatOne=='futureOnly' || $('#recurrenceID').val())
		$('#calendarLine').hide();
	if(calEvent==null || calEvent.type=='')
		$('#editOptionsButton').hide();
	else
		$('#editOptionsButton').click(function(){
		showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', '', true);
	});
	if(calEvent && calEvent.after && repeatOne=='futureOnly')
			$('#repeat_end_after').val(calEvent.after - calEvent.realRepeatCount + 1);

	if(!globalSettings.timezonesupport.value)
		$('.timezone_row').css('display', 'none');

	if($('#allday').prop('checked'))
		stripEventAlerts();

	if(mod!='drop')
	{
		$('#CAEvent').show();
		$('#event_details_template').show();
		$('#eventColor').css('background-color',color);
		updateEventFormDimensions();
		setFormPosition(jsEvent);
	}

	checkEventFormScrollBar();
	$('#event_details_template').scrollTop(0);
}

function bindEventForm()
{
	initCalDavDatepicker($('#event_details_template'));
	initCalDavTimepicker($('#event_details_template'));

	$('#event_details_template .alert_message_details').change(function(){
		var data_id=$(this).attr("data-id");
		$('.before_after_input[data-id="'+data_id+'"]').parent().parent().find('img').css('display','none');
		if($('.alert_message_details[data-id="'+data_id+'"] option:selected').attr('data-type')=="on_date")
		{
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('#date_from').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_from").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_from").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('#date_to').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_to").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_to").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			$('.message_date_input[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_date_input[data-id="'+data_id+'"]').show();
			$('.message_time_input[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('.message_time_input[data-id="'+data_id+'"]').show();
			$('.before_after_input[data-id="'+data_id+'"]').hide();
		}
		else
		{
			$('.message_date_input[data-id="'+data_id+'"]').hide();
			$('.message_time_input[data-id="'+data_id+'"]').hide();
			$('.before_after_input[data-id="'+data_id+'"]').show();
			$('.before_after_input[data-id="'+data_id+'"]').val('15');
		}
	});

	$('#event_details_template .before_after_input').bind('keyup change', function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^(\d*[0-9])*$")==null)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});

	$('#event_details_template .alert').change(function(){
		var data_id=$(this).attr("data-id");
		if($(this).val()!='none')
		{
			$('.alert_details[data-id="'+data_id+'"]').show();
			$('.alert_message_date[data-id="'+data_id+'"]').show();
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('#date_from').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_from").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_from").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('#date_to').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_to").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_to").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			$('.message_date_input[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_time_input[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			event_alert_add(data_id);
		}
		else
		{
			$('.alert_details[data-id="'+data_id+'"]').hide();
			$('.alert_message_date[data-id="'+data_id+'"]').hide();
			checkFor(data_id);
			var data_id=$(this).attr("data-id");
			$('#event_details_template tr[data-id="'+data_id+'"]').remove();
		}
		checkEventFormScrollBar();
	});

	$('#repeat_end_after, #repeat_interval_detail').bind('keyup change',function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^[0-9]+$")==null || parseInt($(this).val(),10)<1)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});

	$('#repeat_month_custom_select').change(function(){
		if($(this).val()=="custom")
		{
			$('#month_custom2').show();
			$('#repeat_month_custom_select2').parent().hide();
		}
		else
		{
			$('#month_custom2').hide();
			$('#repeat_month_custom_select2').parent().show();
		}
		checkEventFormScrollBar();
	});

	$('#repeat_year_custom_select1').change(function(){
		if($(this).val()=="custom")
		{
			$('#year_custom1').show();
			$('#repeat_year_custom_select2').parent().hide();
		}
		else
		{
			$('#year_custom1').hide();
			$('#repeat_year_custom_select2').parent().show();
		}
		checkEventFormScrollBar();
	});

	$('#repeat_end_details').change(function(){
		$('#repeat_end_date').parent().find('img').css('display', 'none');

		if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_on_date")
		{
			$('#repeat_end_after').hide();
			$('#repeat_end_date').show();

			var today;
			if($('#date_from').val()!='')
			{
				today=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_from').val());
				if(today==null)
					today=new Date();
			}
			else
				today=new Date();

			var date=new Date(today.getFullYear(), today.getMonth(), today.getDate()+2);
			$('#repeat_end_date').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date));
		}

		if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_after")
		{
			$('#repeat_end_after').show();
			$('#repeat_end_after').val('2');
			$('#repeat_end_date').hide();
		}

		if($('#repeat_end_details option:selected').attr('data-type')=="repeat_details_never")
		{
			$('#repeat_end_after').hide();
			$('#repeat_end_date').hide();
		}

		checkEventFormScrollBar();
	});

	$('#closeButton').click(function(){
		if($('#uid').val()!='')
		{
			var uid=$('#uid').val();
			var calUID=uid.substring(0, uid.lastIndexOf('/')+1);
			var events=$('.event_item[data-id="'+uid+'"]');
			var color=$('#ResourceCalDAVList').find("[data-id='"+calUID+"']").find('.resourceCalDAVColor').css('background-color');

			$.each(events, function(index, event){
				if(event.nodeName.toLowerCase()!='tr')
				{
					$(event).find('.fc-event-inner, .fc-event-head').addBack().css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
					$(event).find('.fc-event-title, .fc-event-title-strict, .fc-event-time').css('color',checkFontColor(rgbToHex(color)));
				}
				else
				{
					$(event).children('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
				}
			});
		}
		else
		{
			var beforeScroll = $('#main').width()-$('#calendar').width();
			$('#calendar').fullCalendar('unselect');
			$('#calendar').fullCalendar('removeEvents', 'fooUID');
			var afterScroll = $('#main').width()-$('#calendar').width();
			rerenderCalendar(beforeScroll!=afterScroll);
		}

		$('#show').val('');
		$('#CAEvent').hide();
		$('#EventDisabler').fadeOut(globalEditorFadeAnimation, function(){
			$('#timezonePicker').prop('disabled', false);
		});
	});

	$('#resetButton').click(function(){
		$('#event_details_template').find('img[data-type=invalidSmall]').css('display','none');
		var uid=$('#uid').val();

		if(uid!='')
		{
			var calUID=uid.substring(0, uid.lastIndexOf('/')+1);
			var events=$('.event_item[data-id="'+uid+'"]');
			var color=$('#ResourceCalDAVList').find("[data-id='"+calUID+"']").find('.resourceCalDAVColor').css('background-color');

			$.each(events, function(index, event){
				if(event.nodeName.toLowerCase()!='tr')
				{
					$(event).find('.fc-event-inner, .fc-event-head').addBack().css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
					$(event).find('.fc-event-title, .fc-event-title-strict, .fc-event-time').css('color',checkFontColor(rgbToHex(color)));
				}
				else
				{
					$(event).children('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color})
				}
			});
			if($('#recurrenceID').val()!='' && $('#repeatCount').val()!='')
				showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', 'editOnly');
			else if($('#futureStart').val()!='')
				showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', 'futureOnly');
			else
				showEventForm(null, globalCalEvent.allDay, globalCalEvent, globalJsEvent, 'show', '');
			startEditModeEvent();
		}
	});

	$('#allday').click(function(){
		if($('#allday').prop('checked'))
		{
			$('#timezone').val('local');
			$('#time_from_cell').css('visibility','hidden');
			$('#time_to_cell').css('visibility','hidden');
			$('#time_to_cell').find('img').css('display','none');
			$('#time_from_cell').find('img').css('display','none');
			$('.timezone_row').css('display', 'none');
			stripEventAlerts();
		}
		else
		{
			$('#time_from_cell').css('visibility','visible');
			$('#time_to_cell').css('visibility','visible');
			$('#time_from').trigger('change');
			$('#time_to').trigger('change');
			if(globalSettings.timezonesupport.value)
			{
				$('.timezone_row').show();
				$('#timezone').val(globalSessionTimeZone);
			}
			expandEventAlerts();
		}
		checkEventFormScrollBar();
	});

	$('#event_details_template .customTable td').click(function(){
		if($(this).hasClass('disabled'))
			return true;
		else if($(this).hasClass('selected'))
			$(this).removeClass('selected');
		else
			$(this).addClass('selected');
	});

	$('#event_calendar').change(function(){
		var color = '';
		if($(this).val()=='choose')
			color = 'rgb(240,240,240)';
		else
			color=$('#ResourceCalDAVList').find("[data-id='"+$(this).val()+"']").find('.resourceCalDAVColor').css('background-color');

		var uid='fooUID';
		if($('#uid').val()!='')
			uid=$('#uid').val();
		var events=$('.event_item[data-id="'+uid+'"]');

		$('#eventColor').css('background-color',color);
		$.each(events, function(index, event){
			if(event.nodeName.toLowerCase()!='tr')
			{
				$(event).find('.fc-event-inner, .fc-event-head').addBack().css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
				$(event).find('.fc-event-title, .fc-event-title-strict, .fc-event-time').css('color', checkFontColor(rgbToHex(color)));
			}
			else
			{
				$(event).find('.fc-event-handle').css({'background-color': rgbToRgba(color,0.9), 'border-color': color});
			}
		});
	});

	$('#repeat').change(function(){
		if($('#repeat option:selected').attr('data-type')=='repeat_no-repeat' || $('#repeat option:selected').attr('data-type')=="custom_repeat")
		{
			$('#repeat_details').hide();
			$('#repeat_interval').hide();
			$('#week_custom').hide();
			$('#month_custom1').hide();
			$('#month_custom2').hide();
			$('#year_custom1').hide();
			$('#year_custom2').hide();
			$('#year_custom3').hide();
		}
		else
		{
			$('#repeat_details').show();

			if($(this).val()!='BUSINESS' && $(this).val()!='TWO_WEEKLY' && $(this).val()!='WEEKEND')
			{
				$('#repeat_interval').show();
				$("#repeat_interval_detail").val('1');
				$('#repeat_interval').find('img').css('display','none');
			}
			else
				$('#repeat_interval').hide();

			if($(this).val()=='DAILY')
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatDays);

			if($(this).val()=='WEEKLY')
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);

			if($(this).val()=='MONTHLY')
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);

			if($(this).val()=='YEARLY')
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);

			if($(this).val()=='CUSTOM_WEEKLY')
			{
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatWeeks);
				$('#week_custom').show();
			}
			else
				$('#week_custom').hide();

			if($(this).val()=='CUSTOM_MONTHLY')
			{
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatMonths);
				$('#month_custom1').show();
				if($('#repeat_month_custom_select').val() == "custom")
					$('#repeat_month_custom_select').trigger('change');
			}
			else
			{
				$('#month_custom1').hide();
				$('#month_custom2').hide();
			}

			if($(this).val()=='CUSTOM_YEARLY')
			{
				$('#repeat_interval [data-type="txt_interval"]').text(localization[globalInterfaceLanguage].repeatYears);
				$('#year_custom2').show();
				$('#year_custom3').show();
				if($('#repeat_year_custom_select1').val() == "custom")
					$('#repeat_year_custom_select1').trigger('change');
			}
			else
			{
				$('#year_custom1').hide();
				$('#year_custom2').hide();
				$('#year_custom3').hide();
			}

			var today;
			if($('#date_from').val()!='')
			{
				today=$.datepicker.parseDate(globalSettings.datepickerformat.value, $('#date_from').val());
				if(today==null)
					today=new Date();
			}
			else
				today=new Date();

			var date=new Date(today.getFullYear(),today.getMonth(),today.getDate()+2);
			$('#repeat_end_date').val($.datepicker.formatDate(globalSettings.datepickerformat.value, date));
		}
		checkEventFormScrollBar();
	});

	$('#status').change(function(){
		var status = $(this).val();

		if(status=='CANCELLED')
			$('#name').addClass('title_cancelled');
		else
			$('#name').removeClass('title_cancelled');

		todoStatusChanged(status);
	});
}

function startEditModeEvent()
{
	$('#timezonePicker').prop('disabled', true);
	$('#EventDisabler').fadeIn(globalEditorFadeAnimation);
	$('#CAEvent .formNav').css('display', 'none');
	$('#CAEvent textarea.header').removeClass('leftspace rightspace');
	$('#editButton').hide();
	$('#duplicateButton').hide();
	$('#editOptionsButton').hide();
	$('#saveButton').show();
	$('#resetButton').show();
	$('#deleteButton').show();
	$('#show').val('');
	$('#eventDetailsTable :input[disabled]').prop('disabled', false);
	$('#eventDetailsTable :input[type="text"]').prop('readonly', false);
	$('#eventDetailsTable .customTable td').removeClass('disabled');
	$('#eventDetailsTable textarea').prop('readonly', false);
	/*************************** BAD HACKS SECTION ***************************/
	if($.browser.msie || $.browser.mozilla)
	{
		var newSVG=$(SVG_select).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
		$('#event_details_template').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
	}
	/*************************** END OF BAD HACKS SECTION ***************************/

	$('#name').focus();
}

function startEditModeTodo()
{
	$('#todoInEdit').val('true');
	$('#timezonePickerTODO').prop('disabled', true);
	$('#TodoDisabler').fadeIn(globalEditorFadeAnimation);
	$('#CATodo .formNav').css('display', 'none');
	$('#CATodo textarea.header').removeClass('leftspace rightspace');
	$('#editTODO').hide();
	$('#duplicateTODO').hide();
	$('#editOptionsButtonTODO').hide();
	$('#closeTODO').show();
	$('#saveTODO').show();
	$('#resetTODO').show();
	$('#deleteTODO').show();
	$('#showTODO').val('');

	$('#todoDetailsTable :input[disabled]').prop('disabled', false);
	$('#todoDetailsTable :input[type="text"]').prop('readonly', false);
	$('#todoDetailsTable textarea').prop('readonly', false);
	/*************************** BAD HACKS SECTION ***************************/
	if($.browser.msie || $.browser.mozilla)
	{
		var newSVG=$(SVG_select).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
		$('#todo_details_template').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
	}
	/*************************** END OF BAD HACKS SECTION ***************************/

	$('#percentageSlider').slider({
		disabled: false
	});
	$('#nameTODO').focus();
}

function todo_alert_add(data_id)
{
	data_id++;
	var newTr1,
	newTr2,
	newTr3;

	newTr1='<tr data-id="'+data_id+'">'+
		'<td><label data-type="alert_TODO" for="alertTODO">alert: </label></td>'+
		'<td data-size="full" colspan="2">'+
		'<select class="long alertTODO" name="alert_typeTODO" data-id="'+data_id+'">'+
		'<option data-type="alert_none_TODO" value="none">none</option>'+
		'<option data-type="alert_message_TODO" value="message">message</option>'+
		'</select>'+
		'</td>'+
		'</tr>';
	newTr2='<tr class="alert_detailsTODO" style="display:none;" data-id="'+data_id+'">'+
		'<td></td>'+
		'<td data-size="full" colspan="2">'+
		'<select class="long alert_message_detailsTODO" name="alert_detailsTODO" data-id="'+data_id+'">'+
		'<option data-type="on_dateTODO" class="todoTimeOptions" value="on_date">On date</option>'+
		($('#todo_type').val()=='none' ? '' : '<option data-type="weeks_beforeTODO" value="weeks_before">weeks before</option>'+
		'<option data-type="days_beforeTODO" value="days_before">days before</option>'+
		'<option data-type="hours_beforeTODO" value="hours_before">hours before</option>'+
		'<option data-type="minutes_beforeTODO" value="minutes_before">minutes before</option>'+
		'<option data-type="seconds_beforeTODO" value="seconds_before">seconds before</option>'+
		'<option data-type="weeks_afterTODO" value="weeks_after">weeks after</option>'+
		'<option data-type="days_afterTODO" value="days_after">days after</option>'+
		'<option data-type="hours_afterTODO" value="hours_after">hours after</option>'+
		'<option data-type="minutes_afterTODO" value="minutes_after">minutes after</option>'+
		'<option data-type="seconds_afterTODO" value="seconds_after">seconds after</option>')+
		'</select>'+
		'</td>'+
		'</tr>';
	newTr3='<tr data-id="'+data_id+'" class="alert_message_dateTODO" style="display:none;">'+
		'<td></td>'+
		'<td><input data-id="'+data_id+'" data-type="PH_before_after_alert_TODO" class="small before_after_inputTODO" type="text" style="display:none;" />'+
		'<input data-id="'+data_id+'" class="date small message_date_inputTODO" data-type="PH_alarm_date_TODO" type="text" name="message_dateTODO" /><div class="invalidWrapper"><img data-type="invalidSmall" data-id="'+data_id+'" style="display: none;" src="images/error_b.svg" alt="invalid" /></div></td>'+
		'<td><input data-id="'+data_id+'" data-type="PH_alarm_time_TODO" class="time small message_time_inputTODO" type="text" name="message_timeTODO" /><div class="invalidWrapper"><img data-type="invalidSmall" data-id="'+data_id+'" style="display: none;" src="images/error_b.svg" alt="invalid" /></div></td>'+
		'<tr>';

	$('#url_trTODO').before(newTr1);
	$('#url_trTODO').before(newTr2);
	$('#url_trTODO').before(newTr3);
	translateTodoAlerts();
	$('#todo_details_template').find('input[placeholder],textarea[placeholder]').placeholder();

	$('#todo_details_template .alert_message_detailsTODO[data-id="'+data_id+'"]').change(function(){
		var data_id=$(this).attr("data-id");
		$('.before_after_inputTODO[data-id="'+data_id+'"]').parent().parent().find('img').css('display','none');
		if($('.alert_message_detailsTODO[data-id="'+data_id+'"] option:selected').attr('data-type')=="on_dateTODO")
		{
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('.dateTrToTODO').is(':visible') && $('.dateTrToTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_toTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_toTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('.dateTrFromTODO').is(':visible') && $('.dateTrFromTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_fromTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_fromTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}

			$('.message_date_inputTODO[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_date_inputTODO[data-id="'+data_id+'"]').show();
			$('.message_time_inputTODO[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('.message_time_inputTODO[data-id="'+data_id+'"]').show();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').hide();
		}
		else
		{
			$('.message_date_inputTODO[data-id="'+data_id+'"]').hide();
			$('.message_time_inputTODO[data-id="'+data_id+'"]').hide();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').show();
			$('.before_after_inputTODO[data-id="'+data_id+'"]').val('15');
		}
	});
	$('#todo_details_template .before_after_inputTODO[data-id="'+data_id+'"]').bind('keyup change', function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^[0-9]+$")==null)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});
	$('#todo_details_template .alertTODO[data-id="'+data_id+'"]').change(function(){
		var data_id=$(this).attr("data-id");
		if($(this).val()!='none')
		{
			$('.alert_detailsTODO[data-id="'+data_id+'"]').show();
			$('.alert_message_dateTODO[data-id="'+data_id+'"]').show();
			if($('#todo_type').val()!='none')
				expandTodoAlerts();
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('.dateTrToTODO').is(':visible') && $('.dateTrToTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_toTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_toTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('.dateTrFromTODO').is(':visible') && $('.dateTrFromTODO img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_fromTODO").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to +$("#time_fromTODO").val()));
				myDate.setHours(myDate.getHours()-1);
			}

			$('.message_date_inputTODO[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_time_inputTODO[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			todo_alert_add(data_id);
		}
		else
		{
			$('.alert_detailsTODO[data-id="'+data_id+'"]').hide();
			$('.alert_message_dateTODO[data-id="'+data_id+'"]').hide();
			checkForTodo(data_id);
			var data_id=$(this).attr("data-id");
			$('#todo_details_template tr[data-id="'+data_id+'"]').remove();
		}
		checkTodoFormScrollBar();
	});
	initCalDavDatepicker($('#todo_details_template .alert_message_dateTODO[data-id="'+data_id+'"]'));
	initCalDavTimepicker($('#todo_details_template .alert_message_dateTODO[data-id="'+data_id+'"]'));
	/*************************** BAD HACKS SECTION ***************************/
	// here we fix the cross OS/cross broser problems (unfixable in pure CSS)
	if($.browser.webkit && !!window.chrome)	/* Chrome */
	{
		if(navigator.platform.toLowerCase().indexOf('win')==0)	/* Windows version */
		{
			$('#todo_details_template').find('input').css('text-indent', '2px');
			$('#todo_details_template').find('select').css({'padding-left': '0px', 'padding-right': '13px'});
		}
		else	/* non-Windows version */
			$('#todo_details_template').find('input').css('text-indent', '1px');
	}
	else if($.browser.safari)
	{
		$('#todo_details_template').find('textarea').addClass('safari_hack');
		$('#todo_details_template').find('input').addClass('safari_hack');
	}
	else if($.browser.msie)	/* IE */
	{
		if(parseInt($.browser.version, 10)==10)	/* IE 10 (because there are no more conditional comments) */
		{
			$('#todo_details_template').find('select').css({'padding-top': '1px', 'padding-left': '0px', 'padding-right': '0px'});
			$('#todo_details_template').find('textarea').css('padding-top', '3px');
			$('#todo_details_template').find('input[type=button]').css('padding-top', '2px');
		}
	}

	/* IE or FF */
	if($.browser.msie || $.browser.mozilla)
	{
		// ADD empty SVG to interface (we will replace it later)
		$('<svg data-type="select_icon"></svg>').css('display', 'none').insertAfter($('#todo_details_template tr[data-id="'+data_id+'"]').find('select'));
	}

	if($.browser.msie || $.browser.mozilla)
	{
		var newSVG=$(SVG_select).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
		$('#todo_details_template tr[data-id="'+data_id+'"]').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
	}
	/*************************** END OF BAD HACKS SECTION ***************************/
}

function event_alert_add(data_id)
{
	data_id++;

	var newTr1,
	newTr2,
	newTr3;

	newTr1='<tr data-id="'+data_id+'">'+
		'<td><label data-type="alert" for="alert">alert: </label></td>'+
		'<td data-size="full" colspan="2">'+
		'<select class="long alert" name="alert_type" data-id="'+data_id+'">'+
		'<option data-type="alert_none" value="none">none</option>'+
		'<option data-type="alert_message" value="message">message</option>'+
		'</select>'+
		'</td>'+
		'</tr>';
	newTr2='<tr data-id="'+data_id+'" class="alert_details" style="display:none;">'+
		'<td></td>'+
		'<td data-size="full" colspan="2">'+
		'<select class="long alert_message_details" name="alert_details" data-id="'+data_id+'">'+
		'<option data-type="on_date" value="on_date">On date</option>'+
		($('#allday').prop('checked') ? '' : '<option data-type="weeks_before" value="weeks_before">weeks before</option>'+
		'<option data-type="days_before" value="days_before">days before</option>'+
		'<option data-type="hours_before" value="hours_before">hours before</option>'+
		'<option data-type="minutes_before" value="minutes_before">minutes before</option>'+
		'<option data-type="seconds_before" value="seconds_before">seconds before</option>'+
		'<option data-type="weeks_after" value="weeks_after">weeks after</option>'+
		'<option data-type="days_after" value="days_after">days after</option>'+
		'<option data-type="hours_after" value="hours_after">hours after</option>'+
		'<option data-type="minutes_after" value="minutes_after">minutes after</option>'+
		'<option data-type="seconds_after" value="seconds_after">seconds after</option>')
		+
		'</select>'+
		'</td>'+
		'</tr>';
	newTr3='<tr data-id="'+data_id+'" class="alert_message_date" style="display:none;">'+
		'<td></td>'+
		'<td><input class="small before_after_input" data-type="PH_before_after_alert" type="text" data-id="'+data_id+'" style="display:none;" />'+
		'<input class="date small message_date_input" data-type="PH_alarm_date" type="text" data-id="'+data_id+'" /><div class="invalidWrapper"><img data-type="invalidSmall" data-id="'+data_id+'" style="display: none;" src="images/error_b.svg" alt="invalid" /></div></td>'+
		'<td><input class="time small message_time_input" data-type="PH_alarm_time" type="text" data-id="'+data_id+'" /><div class="invalidWrapper"><img data-type="invalidSmall" data-id="'+data_id+'" style="display: none;" src="images/error_b.svg" alt="invalid" /></div></td>'+
		'<tr>';

	$('#url_tr').before(newTr1);
	$('#url_tr').before(newTr2);
	$('#url_tr').before(newTr3);

	translateEventAlerts();
	$('#event_details_template').find('input[placeholder],textarea[placeholder]').placeholder();

	$('#event_details_template .before_after_input[data-id="'+data_id+'"]').bind('keyup change', function(){
		if($(this).val()=='')
		{
			$(this).parent().find('img').css('display', 'inline');
			//$(this).parent().find('img').css('visibility','visible');
		}
		else
		{
			if($(this).val().match("^(\d*[0-9])*$")==null)
			{
				$(this).parent().find('img').css('display', 'inline');
				//$(this).parent().find('img').css('visibility','visible');
			}
			else
				$(this).parent().find('img').css('display', 'none');
		}
	});
	$('#event_details_template .alert[data-id="'+data_id+'"]').change(function(){
		var data_id=$(this).attr("data-id");
		if($(this).val()!='none')
		{
			$('.alert_details[data-id="'+data_id+'"]').show();
			$('.alert_message_date[data-id="'+data_id+'"]').show();
			if(!$('#allday').prop('checked'))
				expandEventAlerts();
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('#date_from').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_from").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_from").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('#date_to').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_to").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_to").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			$('.message_date_input[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_time_input[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			event_alert_add(data_id);
		}
		else
		{
			$('.alert_details[data-id="'+data_id+'"]').hide();
			$('.alert_message_date[data-id="'+data_id+'"]').hide();
			checkFor(data_id);
			var data_id=$(this).attr("data-id");
			$('#event_details_template tr[data-id="'+data_id+'"]').remove();
		}
		checkEventFormScrollBar();
	});
	$('#event_details_template .alert_message_details[data-id="'+data_id+'"]').change(function(){
		var data_id=$(this).attr("data-id");
		$('.before_after_input[data-id="'+data_id+'"]').parent().parent().find('img').css('display','none');
		if($('.alert_message_details[data-id="'+data_id+'"] option:selected').attr('data-type')=="on_date")
		{
			var myDate=new Date();
			myDate.setDate(myDate.getDate()+7);

			if($('#date_from').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_from").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_from").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			else if($('#date_to').parent().parent().find('img:visible').length==0) {
				var dateTo=$.datepicker.parseDate(globalSettings.datepickerformat.value,$("#date_to").val());
				var datetime_to=$.fullCalendar.formatDate(dateTo, 'MM/dd/yyyy, ');
				myDate=new Date(Date.parse(datetime_to + (!$("#allday").prop('checked')?$("#time_to").val():'')));
				myDate.setHours(myDate.getHours()-1);
			}
			$('.message_date_input[data-id="'+data_id+'"]').val($.datepicker.formatDate(globalSettings.datepickerformat.value, myDate));
			$('.message_date_input[data-id="'+data_id+'"]').show();
			$('.message_time_input[data-id="'+data_id+'"]').val($.fullCalendar.formatDate(myDate, (globalSettings.ampmformat.value ? 'hh:mm TT' : 'HH:mm')));
			$('.message_time_input[data-id="'+data_id+'"]').show();
			$('.before_after_input[data-id="'+data_id+'"]').hide();
		}
		else
		{
			$('.message_date_input[data-id="'+data_id+'"]').hide();
			$('.message_time_input[data-id="'+data_id+'"]').hide();
			$('.before_after_input[data-id="'+data_id+'"]').show();
			$('.before_after_input[data-id="'+data_id+'"]').val('15');
		}
	});
	initCalDavDatepicker($('#event_details_template .alert_message_date[data-id="'+data_id+'"]'));
	initCalDavTimepicker($('#event_details_template .alert_message_date[data-id="'+data_id+'"]'));
	/*************************** BAD HACKS SECTION ***************************/
	// here we fix the cross OS/cross broser problems (unfixable in pure CSS)
	if($.browser.webkit && !!window.chrome)	/* Chrome */
	{
		if(navigator.platform.toLowerCase().indexOf('win')==0)	/* Windows version */
		{
			$('#event_details_template').find('input').css('text-indent', '2px');
			$('#event_details_template').find('select').css({'padding-left': '0px', 'padding-right': '13px'});
		}
		else	/* non-Windows version */
			$('#event_details_template').find('input').css('text-indent', '1px');
	}
	else if($.browser.safari)
	{
		$('#event_details_template').find('textarea').addClass('safari_hack');
		$('#event_details_template').find('input').addClass('safari_hack');
	}
	else if($.browser.msie)	/* IE */
	{
		if(parseInt($.browser.version, 10)==10)	/* IE 10 (because there are no more conditional comments) */
		{
			$('#event_details_template').find('select').css({'padding-top': '1px', 'padding-left': '0px', 'padding-right': '0px'});
			$('#event_details_template').find('textarea').css('padding-top', '3px');
			$('#event_details_template').find('input[type=button]').css('padding-top', '2px');
		}
	}

	/* IE or FF */
	if($.browser.msie || $.browser.mozilla)
	{
		// ADD empty SVG to interface (we will replace it later)
		$('<svg data-type="select_icon"></svg>').css('display', 'none').insertAfter($('#event_details_template tr[data-id="'+data_id+'"]').find('select'));
	}

	if($.browser.msie || $.browser.mozilla)
	{
		var newSVG=$(SVG_select).attr('data-type', 'select_icon').css({'pointer-events': 'none', 'z-index': '1', 'display': 'inline', 'margin-left': '-19px', 'vertical-align': 'top', 'background-color': '#ffffff'});	// background-color = stupid IE9 bug
		$('#event_details_template tr[data-id="'+data_id+'"]').find('svg[data-type="select_icon"]').replaceWith($('<div>').append($(newSVG).clone()).html());
	}
	/*************************** END OF BAD HACKS SECTION ***************************/
}

function stripEventAlerts()
{
	$('.alert_message_details').each(function(){
		if($(this).val()=='on_date')
			$(this).find('option').not(':selected').remove();
		else
		{
			var dataID=$(this).parent().parent().attr('data-id');
			$('#event_details_template').find('tr[data-id="'+dataID+'"]').remove();
		}
	});
}

function expandEventAlerts()
{
	$('.alert_message_details').each(function(){
		var value=$(this).val();
		$(this).html('<option data-type="on_date" value="on_date">on date</option>'+
		'<option data-type="weeks_before" value="weeks_before">weeks before</option>'+
		'<option data-type="days_before" value="days_before">days before</option>'+
		'<option data-type="hours_before" value="hours_before">hours before</option>'+
		'<option data-type="minutes_before" value="minutes_before">minutes before</option>'+
		'<option data-type="seconds_before" value="seconds_before">seconds before</option>'+
		'<option data-type="weeks_after" value="weeks_after">weeks after</option>'+
		'<option data-type="days_after" value="days_after">days after</option>'+
		'<option data-type="hours_after" value="hours_after">hours after</option>'+
		'<option data-type="minutes_after" value="minutes_after">minutes after</option>'+
		'<option data-type="seconds_after" value="seconds_after">seconds after</option>');
		$(this).val(value);
	});
	translateEventAlerts();
}

function stripTodoAlerts()
{
	$('.alert_message_detailsTODO').each(function(){
		if($(this).val()=='on_date')
			$(this).find('option').not(':selected').remove();
		else
		{
			var dataID=$(this).parent().parent().attr('data-id');
			$('#todo_details_template').find('tr[data-id="'+dataID+'"]').remove();
		}
	});
}

function expandTodoAlerts()
{
	$('.alert_message_detailsTODO').each(function(){
		var value=$(this).val();
		$(this).html('<option data-type="on_dateTODO" value="on_date">On date</option>'+
		'<option data-type="weeks_beforeTODO" value="weeks_before">weeks before</option>'+
		'<option data-type="days_beforeTODO" value="days_before">days before</option>'+
		'<option data-type="hours_beforeTODO" value="hours_before">hours before</option>'+
		'<option data-type="minutes_beforeTODO" value="minutes_before">minutes before</option>'+
		'<option data-type="seconds_beforeTODO" value="seconds_before">seconds before</option>'+
		'<option data-type="weeks_afterTODO" value="weeks_after">weeks after</option>'+
		'<option data-type="days_afterTODO" value="days_after">days after</option>'+
		'<option data-type="hours_afterTODO" value="hours_after">hours after</option>'+
		'<option data-type="minutes_afterTODO" value="minutes_after">minutes after</option>'+
		'<option data-type="seconds_afterTODO" value="seconds_after">seconds after</option>');
		$(this).val(value);
	});
	translateTodoAlerts();
}