yiistrap-1 /helpers/TbHtml.php

Language PHP Lines 4046
MD5 Hash 7a768193a813c7bfa641c9e22a52ab50
Repository https://github.com/jacmoe/yiistrap-1.git View Raw File
   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
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
<?php
/**
 * TbHtml class file.
 * @author Antonio Ramirez <ramirez.cobos@gmail.com>
 * @author Christoffer Niska <christoffer.niska@gmail.com>
 * @copyright Copyright &copy; Christoffer Niska 2013-
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
 * @package bootstrap.helpers
 */

/**
 * Bootstrap HTML helper.
 */
class TbHtml extends CHtml // required in order to access protected methods
{
    // Floats.
    const PULL_LEFT = 'left';
    const PULL_RIGHT = 'right';

    // Text alignments.
    const ALIGN_LEFT = 'left';
    const ALIGN_CENTER = 'center';
    const ALIGN_RIGHT = 'right';

    // Element colors.
    const COLOR_DEFAULT = '';
    const COLOR_PRIMARY = 'primary';
    const COLOR_INFO = 'info';
    const COLOR_SUCCESS = 'success';
    const COLOR_WARNING = 'warning';
    const COLOR_ERROR = 'error';
    const COLOR_DANGER = 'danger';
    const COLOR_IMPORTANT = 'important';
    const COLOR_INVERSE = 'inverse';
    const COLOR_LINK = 'link';

    // Element sizes.
    const SIZE_MINI = 'mini';
    const SIZE_SMALL = 'small';
    const SIZE_DEFAULT = '';
    const SIZE_MEDIUM = 'medium';
    const SIZE_LARGE = 'large';
    const SIZE_XLARGE = 'xlarge';
    const SIZE_XXLARGE = 'xxlarge';

    const BUTTON_LINK = 'link';
    const BUTTON_HTML = 'htmlButton';
    const BUTTON_SUBMIT = 'submitButton';
    const BUTTON_RESET = 'resetButton';
    const BUTTON_IMAGE = 'imageButton';
    const BUTTON_LINKBUTTON = 'linkButton';
    const BUTTON_AJAXLINK = 'ajaxLink';
    const BUTTON_AJAXBUTTON = 'ajaxButton';
    const BUTTON_INPUTBUTTON = 'inputButton';
    const BUTTON_INPUTSUBMIT = 'inputSubmit';

    // Menu types.
    const NAV_TABS = 'tabs';
    const NAV_PILLS = 'pills';
    const NAV_LIST = 'list';

    // Navbar positions.
    const NAVBAR_INLINE = '';
    const NAVBAR_FIXED_TOP = 'fixed-top';
    const NAVBAR_FIXED_BOTTOM = 'fixed-bottom';
    const NAVBAR_STATIC_TOP = 'static-top';

    // Image types.
    const IMAGE_ROUNDED = 'rounded';
    const IMAGE_CIRCLE = 'circle';
    const IMAGE_POLAROID = 'polaroid';

    // Progress bar types.
    const PROGRESS_LEFT = 'left';
    const PROGRESS_CENTER = 'centered';
    const PROGRESS_RIGHT = 'right';
    const PROGRESS_STRIPED = 'striped';
    const PROGRESS_ACTIVE = 'active';

    // Tooltip placements.
    const TOOLTIP_TOP = 'top';
    const TOOLTIP_BOTTOM = 'bottom';
    const TOOLTIP_LEFT = 'left';
    const TOOLTIP_RIGHT = 'right';

    // Tab placements.
    const TABS_ABOVE = '';
    const TABS_BELOW = 'below';
    const TABS_LEFT = 'left';
    const TABS_RIGHT = 'right';

    // Affix offset types.
    const AFFIX_TOP = 'top';
    const AFFIX_BOTTOM = 'bottom';

    // Tooltip triggers.
    const TRIGGER_CLICK = 'click';
    const TRIGGER_HOVER = 'hover';
    const TRIGGER_FOCUS = 'focus';
    const TRIGGER_MANUAL = 'manual';

    // Addon types.
    const ADDON_PREPEND = 'prepend';
    const ADDON_APPEND = 'append';

    // Help types.
    const HELP_INLINE = 'inline';
    const HELP_BLOCK = 'block';

    // Form layouts.
    const FORM_VERTICAL = 'vertical';
    const FORM_HORIZONTAL = 'horizontal';
    const FORM_INLINE = 'inline';
    const FORM_SEARCH = 'search';

    // Input types.
    const INPUT_URL = 'urlField';
    const INPUT_EMAIL = 'emailField';
    const INPUT_NUMBER = 'numberField';
    const INPUT_RANGE = 'rangeField';
    const INPUT_DATE = 'dateField';
    const INPUT_TEXT = 'textField';
    const INPUT_PASSWORD = 'passwordField';
    const INPUT_TEXTAREA = 'textArea';
    const INPUT_FILE = 'fileField';
    const INPUT_RADIOBUTTON = 'radioButton';
    const INPUT_CHECKBOX = 'checkBox';
    const INPUT_DROPDOWN = 'dropDownList';
    const INPUT_LISTBOX = 'listBox';
    const INPUT_CHECKBOXLIST = 'checkBoxList';
    const INPUT_INLINECHECKBOXLIST = 'inlineCheckBoxList';
    const INPUT_RADIOBUTTONLIST = 'radioButtonList';
    const INPUT_INLINERADIOBUTTONLIST = 'inlineRadioButtonList';
    const INPUT_UNEDITABLE = 'uneditableField';
    const INPUT_SEARCH = 'searchQuery';

    // grid types.
    const GRID_STRIPED = 'striped';
    const GRID_BORDERED = 'bordered';
    const GRID_CONDENSED = 'condensed';
    const GRID_HOVER = 'hover';

    // Icon types.
    const ICON_GLASS = 'icon-glass';
    const ICON_MUSIC = 'icon-music';
    const ICON_SEARCH = 'icon-search';
    const ICON_ENVELOPE = 'icon-envelope';
    const ICON_HEART = 'icon-heart';
    const ICON_STAR = 'icon-star';
    const ICON_STAR_EMPTY = 'icon-star-empty';
    const ICON_USER = 'icon-user';
    const ICON_FILM = 'icon-film';
    const ICON_TH_LARGE = 'icon-th-large';
    const ICON_TH = 'icon-th';
    const ICON_TH_LIST = 'icon-th-list';
    const ICON_OK = 'icon-ok';
    const ICON_REMOVE = 'icon-remove';
    const ICON_ZOOM_IN = 'icon-zoom-in';
    const ICON_ZOOM_OUT = 'icon-zoom-out';
    const ICON_OFF = 'icon-off';
    const ICON_SIGNAL =  'icon-signal';
    const ICON_COG = 'icon-cog';
    const ICON_TRASH = 'icon-trash';
    const ICON_HOME = 'icon-home';
    const ICON_FILE = 'icon-file';
    const ICON_TIME = 'icon-time';
    const ICON_ROAD = 'icon-road';
    const ICON_DOWNLOAD_ALT = 'icon-download-alt';
    const ICON_DOWNLOAD = 'icon-download';
    const ICON_UPLOAD = 'icon-upload';
    const ICON_INBOX = 'icon-inbox';
    const ICON_PLAY_CIRCLE = 'icon-play-circle';
    const ICON_REPEAT = 'icon-repeat';
    const ICON_REFRESH = 'icon-refresh';
    const ICON_LIST_ALT = 'icon-list-alt';
    const ICON_LOCK = 'icon-lock';
    const ICON_FLAG = 'icon-flag';
    const ICON_HEADPHONES = 'icon-headphones';
    const ICON_VOLUME_OFF = 'icon-volume-off';
    const ICON_VOLUME_DOWN = 'icon-volume-down';
    const ICON_VOLUME_UP = 'icon-volume-up';
    const ICON_QRCODE = 'icon-qrcode';
    const ICON_BARCODE = 'icon-barcode';
    const ICON_TAG = 'icon-tag';
    const ICON_TAGS = 'icon-tags';
    const ICON_BOOK = 'icon-book';
    const ICON_BOOKMARK = 'icon-bookmark';
    const ICON_PRINT = 'icon-print';
    const ICON_CAMERA = 'icon-camera';
    const ICON_FONT = 'icon-font';
    const ICON_BOLD = 'icon-bold';
    const ICON_ITALIC = 'icon-italic';
    const ICON_TEXT_HEIGHT = 'icon-text-height';
    const ICON_TEXT_WIDTH = 'icon-text-width';
    const ICON_ALIGN_LEFT = 'icon-align-left';
    const ICON_ALIGN_CENTER = 'icon-align-center';
    const ICON_ALIGN_RIGHT = 'icon-align-right';
    const ICON_ALIGN_JUSTIFY = 'icon-align-justify';
    const ICON_LIST = 'icon-list';
    const ICON_INDENT_LEFT = 'icon-indent-left';
    const ICON_INDENT_RIGHT = 'icon-indent-right';
    const ICON_FACETIME_VIDEO = 'icon-facetime-video';
    const ICON_PICTURE = 'icon-picture';
    const ICON_PENCIL = 'icon-pencil';
    const ICON_MAP_MARKER = 'icon-map-marker';
    const ICON_ADJUST = 'icon-adjust';
    const ICON_TINT = 'icon-tint';
    const ICON_EDIT = 'icon-edit';
    const ICON_SHARE = 'icon-share';
    const ICON_CHECK = 'icon-check';
    const ICON_MOVE = 'icon-move';
    const ICON_STEP_BACKWARD = 'icon-step-backward';
    const ICON_FAST_BACKWARD = 'icon-fast-backward';
    const ICON_BACKWARD = 'icon-backward';
    const ICON_PLAY = 'icon-play';
    const ICON_PAUSE = 'icon-pause';
    const ICON_STOP = 'icon-pause';
    const ICON_FORWARD = 'icon-forward';
    const ICON_FAST_FORWARD = 'icon-fast-forward';
    const ICON_STEP_FORWARD = 'icon-step-forward';
    const ICON_EJECT = 'icon-eject';
    const ICON_CHEVRON_LEFT = 'icon-chevron-left';
    const ICON_CHEVRON_RIGHT = 'icon-chevron-right';
    const ICON_PLUS_SIGN = 'icon-plus-sign';
    const ICON_MINUS_SIGN = 'icon-minus-sign';
    const ICON_REMOVE_SIGN = 'icon-remove-sign';
    const ICON_OK_SIGN = 'icon-ok-sign';
    const ICON_QUESTION_SIGN = 'icon-question-sign';
    const ICON_INFO_SIGN = 'icon-info-sign';
    const ICON_SCREENSHOT = 'icon-screenshot';
    const ICON_REMOVE_CIRCLE = 'icon-remove-circle';
    const ICON_OK_CIRCLE = 'icon-ok-circle';
    const ICON_BAN_CIRCLE = 'icon-ban-circle';
    const ICON_ARROW_LEFT = 'icon-arrow-left';
    const ICON_ARROW_RIGHT = 'icon-arrow-right';
    const ICON_ARROW_UP = 'icon-arrow-up';
    const ICON_ARROW_DOWN = 'icon-arrow-down';
    const ICON_SHARE_ALT = 'icon-share-alt';
    const ICON_RESIZE_FULL = 'icon-resize-full';
    const ICON_RESIZE_SMALL = 'icon-resize-small';
    const ICON_PLUS = 'icon-plus';
    const ICON_MINUS = 'icon-minus';
    const ICON_ASTERISK = 'icon-asterisk';
    const ICON_EXCLAMATION_SIGN = 'icon-exclamation-sign';
    const ICON_GIFT = 'icon-gift';
    const ICON_LEAF = 'icon-leaf';
    const ICON_FIRE = 'icon-fire';
    const ICON_EYE_OPEN = 'icon-eye-open';
    const ICON_EYE_CLOSE = 'icon-eye-close';
    const ICON_WARNING_SIGN = 'icon-warning-sign';
    const ICON_PLANE = 'icon-plane';
    const ICON_CALENDAR = 'icon-calendar';
    const ICON_RANDOM =  'icon-random';
    const ICON_COMMENT = 'icon-comment';
    const ICON_MAGNET = 'icon-magnet';
    const ICON_CHEVRON_UP = 'icon-chevron-up';
    const ICON_CHEVRON_DOWN = 'icon-chevron-down';
    const ICON_RETWEET = 'icon-retweet';
    const ICON_SHOPPING_CART = 'icon-shopping-cart';
    const ICON_FOLDER_CLOSE = 'icon-folder-close';
    const ICON_FOLDER_OPEN = 'icon-folder-open';
    const ICON_RESIZE_VERTICAL = 'icon-resize-vertical';
    const ICON_RESIZE_HORIZONTAL = 'icon-resize-horizontal';
    const ICON_HDD = 'icon-hdd';
    const ICON_BULLHORN = 'icon-bullhorn';
    const ICON_BELL = 'icon-bell';
    const ICON_CERTFICATE = 'icon-certificate';
    const ICON_THUMBS_UP = 'icon-thumbs-up';
    const ICON_THUMBS_DOWN = 'icon-thumbs-down';
    const ICON_HAND_RIGHT = 'icon-hand-right';
    const ICON_HAND_LEFT = 'icon-hand-left';
    const ICON_HAND_UP = 'icon-hand-up';
    const ICON_HAND_DOWN = 'icon-hand-down';
    const ICON_CIRCLE_ARROW_RIGHT = 'icon-circle-arrow-right';
    const ICON_CIRCLE_ARROW_LEFT = 'icon-circle-arrow-left';
    const ICON_CIRCLE_ARROW_UP   = 'icon-circle-arrow-up';
    const ICON_CIRCLE_ARROW_DOWN = 'icon-circle-arrow-down';
    const ICON_GLOBE = 'icon-globe';
    const ICON_WRENCH = 'icon-wrench';
    const ICON_TASKS = 'icon-tasks';
    const ICON_FILTER = 'icon-filter';
    const ICON_BRIEFCASE = 'icon-briefcase';
    const ICON_FULLSCREEN = 'icon-fullscreen';

    // Default close text.
    const CLOSE_TEXT = '&times;';

    //
    // BASE CSS
    // --------------------------------------------------

    // Typography
    // http://twitter.github.com/bootstrap/base-css.html#typography
    // --------------------------------------------------

    /**
     * Generates a paragraph that stands out.
     * @param string $text the lead text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated paragraph.
     */
    public static function lead($text, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('lead', $htmlOptions);
        return self::tag('p', $htmlOptions, $text);
    }

    /**
     * Generates small text.
     * @param string $text the text to style.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text.
     */
    public static function small($text, $htmlOptions = array())
    {
        return self::tag('small', $htmlOptions, $text);
    }

    /**
     * Generates bold text.
     * @param string $text the text to style.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text.
     */
    public static function b($text, $htmlOptions = array())
    {
        return self::tag('strong', $htmlOptions, $text);
    }

    /**
     * Generates italic text.
     * @param string $text the text to style.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text.
     */
    public static function i($text, $htmlOptions = array())
    {
        return self::tag('em', $htmlOptions, $text);
    }

    /**
     * Generates an emphasized text.
     * @param string $style the text style.
     * @param string $text the text to emphasize.
     * @param array $htmlOptions additional HTML attributes.
     * @param string $tag the HTML tag.
     * @return string the generated text.
     */
    public static function em($style, $text, $htmlOptions = array(), $tag = 'p')
    {
        $htmlOptions = self::addClassName('text-' . $style, $htmlOptions);
        return self::tag($tag, $htmlOptions, $text);
    }

    /**
     * Generates a muted text block.
     * @param string $text the text.
     * @param array $htmlOptions additional HTML attributes.
     * @param string $tag the HTML tag.
     * @return string the generated text block.
     */
    public static function muted($text, $htmlOptions = array(), $tag = 'p')
    {
        if (self::popOption('muted', $htmlOptions, false))
            $htmlOptions = self::addClassName('muted', $htmlOptions);
        return self::tag($tag, $htmlOptions, $text);
    }

    /**
     * Generates a muted span.
     * @param string $text the text.
     * @param array $htmlOptions additional HTML attributes.
     * @param string $tag the HTML tag.
     * @return string the generated span.
     */
    public static function mutedSpan($text, $htmlOptions = array())
    {
        return self::muted($text, $htmlOptions, 'span');
    }

    /**
     * Generates an abbreviation with a help text.
     * @param string $text the abbreviation.
     * @param string $word the word the abbreviation is for.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated abbreviation.
     */
    public static function abbr($text, $word, $htmlOptions = array())
    {
        if (self::popOption('small', $htmlOptions, false))
            $htmlOptions = self::addClassName('initialism', $htmlOptions);
        $htmlOptions['title'] = $word;
        return self::tag('abbr', $htmlOptions, $text);
    }

    /**
     * Generates a small abbreviation with a help text.
     * @param string $text the abbreviation.
     * @param string $word the word the abbreviation is for.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated abbreviation.
     */
    public static function smallAbbr($text, $word, $htmlOptions = array())
    {
        $htmlOptions['small'] = true;
        return self::abbr($text, $word, $htmlOptions);
    }

    /**
     * Generates an address block.
     * @param string $quote the address text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated block.
     */
    public static function address($text, $htmlOptions = array())
    {
        return self::tag('address', $htmlOptions, $text);
    }

    /**
     * Generates a quote.
     * @param string $text the quoted text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated quote.
     */
    public static function quote($text, $htmlOptions = array())
    {
        $paragraphOptions = self::popOption('paragraphOptions', $htmlOptions, array());
        $source = self::popOption('source', $htmlOptions);
        $sourceOptions = self::popOption('sourceOptions', $htmlOptions, array());
        $cite = self::popOption('cite', $htmlOptions);
        $citeOptions = self::popOption('citeOptions', $htmlOptions, array());
        $cite = isset($cite) ? self::tag('cite', $citeOptions, $cite) : '';
        $source = isset($source) ? self::tag('small', $sourceOptions, $source . ' ' . $cite) : '';
        $text = self::tag('p', $paragraphOptions, $text) . $source;
        return self::tag('blockquote', $htmlOptions, $text);
    }

    /**
     * Generates a help text.
     * @param string $text the help text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text.
     */
    public static function help($text, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('help-inline', $htmlOptions);
        return self::tag('span', $htmlOptions, $text);
    }

    /**
     * Generates a help block.
     * @param string $text the help text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated block.
     */
    public static function helpBlock($text, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('help-block', $htmlOptions);
        return self::tag('p', $htmlOptions, $text);
    }

    // Code
    // http://twitter.github.com/bootstrap/base-css.html#code
    // --------------------------------------------------

    /**
     * Generates inline code.
     * @param string $code the code.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated code.
     */
    public static function code($code, $htmlOptions = array())
    {
        return self::tag('code', $htmlOptions, $code);
    }

    /**
     * Generates a code block.
     * @param string $code the code.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated block.
     */
    public static function codeBlock($code, $htmlOptions = array())
    {
        return self::tag('pre', $htmlOptions, $code);
    }

    /**
     * Generates an HTML element.
     * @param string $tag the tag name.
     * @param array $htmlOptions the element attributes.
     * @param mixed $content the content to be enclosed between open and close element tags.
     * @param boolean $closeTag whether to generate the close tag.
     * @return string the generated HTML element tag.
     */
    public static function tag($tag, $htmlOptions = array(), $content = false, $closeTag = true)
    {
        self::addSpanClass($htmlOptions);
        $align = self::popOption('align', $htmlOptions);
        if (isset($align))
            $htmlOptions = self::addClassName('text-' . $align, $htmlOptions);
        $pull = self::popOption('pull', $htmlOptions);
        if (isset($pull))
            $htmlOptions = self::addClassName('pull-' . $pull, $htmlOptions);
        return CHtml::tag($tag, $htmlOptions, $content, $closeTag);
    }

    /**
     * Generates an open HTML element.
     * @param string $tag the tag name.
     * @param array $htmlOptions the element attributes.
     * @return string the generated HTML element tag.
     */
    public static function openTag($tag, $htmlOptions = array())
    {
        return self::tag($tag, $htmlOptions);
    }

    // Tables
    // http://twitter.github.com/bootstrap/base-css.html#forms
    // --------------------------------------------------

    // todo: create table methods here.

    // Forms
    // http://twitter.github.com/bootstrap/base-css.html#tables
    // --------------------------------------------------

    /**
     * Generates a form tag.
     * @param string $layout the form layout.
     * @param string $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated tag.
     */
    public static function formTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
    {
        return self::beginFormTb($layout, $action, $method, $htmlOptions);
    }

    /**
     * Generates an open form tag.
     * @param string $layout the form layout.
     * @param string $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated tag.
     */
    public static function beginFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('form-' . $layout, $htmlOptions);
        return CHtml::beginForm($action, $method, $htmlOptions);
    }

    /**
     * Generates a stateful form tag.
     * @param mixed $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated form tag.
     */
    public static function statefulFormTb($layout = self::FORM_VERTICAL, $action = '', $method = 'post', $htmlOptions = array())
    {
        return self::formTb($layout, $action, $method, $htmlOptions)
            . CHtml::tag('div', array('style' => 'display:none'), CHtml::pageStateField(''));
    }

    /**
     * Generates a text field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function textField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('text', $name, $value, $htmlOptions);
    }

    /**
     * Generates a password field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function passwordField($name, $value = '', $htmlOptions = array())
    {
        CHtml::clientChange('change', $htmlOptions);
        return self::textInputField('password', $name, $value, $htmlOptions);
    }

    /**
     * Generates an url field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function urlField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('url', $name, $value, $htmlOptions);
    }

    /**
     * Generates an email field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function emailField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('email', $name, $value, $htmlOptions);
    }

    /**
     * Generates a number field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function numberField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('number', $name, $value, $htmlOptions);
    }

    /**
     * Generates a range field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function rangeField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('range', $name, $value, $htmlOptions);
    }

    /**
     * Generates a date field input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::textInputField
     */
    public static function dateField($name, $value = '', $htmlOptions = array())
    {
        return self::textInputField('date', $name, $value, $htmlOptions);
    }

    /**
     * Generates a text area input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text area.
     */
    public static function textArea($name, $value = '', $htmlOptions = array())
    {
        $htmlOptions = self::normalizeInputOptions($htmlOptions);
        return CHtml::textArea($name, $value, $htmlOptions);
    }

    /**
     * Generates a radio button.
     * @param string $name the input name.
     * @param boolean $checked whether the radio button is checked.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated radio button.
     */
    public static function radioButton($name, $checked = false, $htmlOptions = array())
    {
        $label = self::popOption('label', $htmlOptions, false);
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $radioButton = CHtml::radioButton($name, $checked, $htmlOptions);
        if ($label !== false)
        {
            $labelOptions = self::addClassName('radio', $labelOptions);
            ob_start();
            echo self::tag('label', $labelOptions, $radioButton . $label);
            return ob_get_clean();
        }
        else
            return $radioButton;
    }

    /**
     * Generates a check box.
     * @param string $name the input name.
     * @param boolean $checked whether the check box is checked.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated check box.
     */
    public static function checkBox($name, $checked = false, $htmlOptions = array())
    {
        $label = self::popOption('label', $htmlOptions, false);
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $checkBox = CHtml::checkBox($name, $checked, $htmlOptions);
        if ($label !== false)
        {
            $labelOptions = self::addClassName('checkbox', $labelOptions);
            ob_start();
            echo self::tag('label', $labelOptions, $checkBox . $label);
            return ob_get_clean();
        }
        else
            return $checkBox;
    }

    /**
     * Generates a drop down list.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @return string the generated drop down list.
     */
    public static function dropDownList($name, $select, $data, $htmlOptions = array())
    {
        $htmlOptions = self::normalizeInputOptions($htmlOptions);
        return CHtml::dropDownList($name, $select, $data, $htmlOptions);
    }

    /**
     * Generates a list box.
     * @param string $name the input name.
     * @param mixed $select the selected value(s).
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list box
     */
    public static function listBox($name, $select, $data, $htmlOptions = array())
    {
        $htmlOptions = self::defaultOption('size', 4, $htmlOptions);
        if (isset($htmlOptions['multiple']))
        {
            if (substr($name, -2) !== '[]')
                $name .= '[]';
        }
        return self::dropDownList($name, $select, $data, $htmlOptions);
    }

    /**
     * Generates a radio button list.
     * @param string $name name of the radio button list.
     * @param mixed $select selection of the radio buttons.
     * @param array $data $data value-label pairs used to generate the radio button list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function radioButtonList($name, $select, $data, $htmlOptions = array())
    {
        $inline = self::popOption('inline', $htmlOptions, false);
        $separator = self::popOption('separator', $htmlOptions, ' ');
        $container = self::popOption('container', $htmlOptions);
        $containerOptions = self::popOption('containerOptions', $htmlOptions, array());

        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        if ($inline)
            $labelOptions = self::addClassName('inline', $labelOptions);

        $items  = array();
        $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));

        $id = 0;
        foreach ($data as $value => $label)
        {
            $checked  = !strcmp($value, $select);
            $htmlOptions['value'] = $value;
            $htmlOptions['id'] = $baseID . '_' . $id++;
            if ($inline)
            {
                $htmlOptions['label'] = $label;
                $htmlOptions['labelOptions'] = $labelOptions;
                $items[] = self::radioButton($name, $checked, $htmlOptions);
            }
            else
            {
                $option = self::radioButton($name, $checked, $htmlOptions);
                $items[] = self::label($option . ' ' . $label, false, $labelOptions);
            }
        }

        $inputs = implode($separator, $items);
        return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
    }

    /**
     * Generates an inline radio button list.
     * @param string $name name of the radio button list.
     * @param mixed $select selection of the radio buttons.
     * @param array $data $data value-label pairs used to generate the radio button list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function inlineRadioButtonList($name, $select, $data, $htmlOptions = array())
    {
        $htmlOptions['inline'] = true;
        return self::radioButtonList($name, $select, $data, $htmlOptions);
    }

    /**
     * Generates a check box list.
     * @param string $name name of the check box list.
     * @param mixed $select selection of the check boxes.
     * @param array $data $data value-label pairs used to generate the check box list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function checkBoxList($name, $select, $data, $htmlOptions = array())
    {
        $inline = self::popOption('inline', $htmlOptions, false);
        $separator = self::popOption('separator', $htmlOptions, ' ');
        $container = self::popOption('container', $htmlOptions);
        $containerOptions = self::popOption('containerOptions', $htmlOptions, array());

        if (substr($name, -2) !== '[]')
            $name .= '[]';

        $checkAllLabel = self::popOption('checkAll', $htmlOptions);
        $checkAllLast = self::popOption('checkAllLast', $htmlOptions);

        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        if ($inline)
            $labelOptions = self::addClassName('inline', $labelOptions);

        $items  = array();
        $baseID = $containerOptions['id'] = self::popOption('baseID', $htmlOptions, CHtml::getIdByName($name));
        $id = 0;
        $checkAll = true;

        foreach ($data as $value => $label)
        {
            $checked = !is_array($select) && !strcmp($value, $select) || is_array($select) && in_array($value, $select);
            $checkAll = $checkAll && $checked;
            $htmlOptions['value'] = $value;
            $htmlOptions['id'] = $baseID . '_' . $id++;
            if ($inline)
            {
                $htmlOptions['label'] = $label;
                $htmlOptions['labelOptions'] = $labelOptions;
                $items[] = self::checkBox($name, $checked, $htmlOptions);
            }
            else
            {
                $option = self::checkBox($name, $checked, $htmlOptions);
                $items[] = self::label($option . ' ' . $label, false, $labelOptions);
            }
        }

        if (isset($checkAllLabel))
        {
            $htmlOptions['value'] = 1;
            $htmlOptions['id'] = $id = $baseID . '_all';
            $option = self::checkBox($id, $checkAll, $htmlOptions);
            $label = self::label($checkAllLabel, '', $labelOptions);
            $item = self::label($option . ' ' . $label, '', $labelOptions);
            if ($checkAllLast)
                $items[] = $item;
            else
                array_unshift($items, $item);
            $name = strtr($name, array('[' => '\\[', ']' => '\\]'));
            $js = <<<EOD
jQuery('#$id').click(function() {
	jQuery("input[name='$name']").prop('checked', this.checked);
});
jQuery("input[name='$name']").click(function() {
	jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
});
jQuery('#$id').prop('checked', !jQuery("input[name='$name']:not(:checked)").length);
EOD;
            $cs = Yii::app()->getClientScript();
            $cs->registerCoreScript('jquery');
            $cs->registerScript($id, $js);
        }

        $inputs = implode($separator, $items);
        return !empty($container) ? self::tag($container, $containerOptions, $inputs) : $inputs;
    }

    /**
     * Generates an inline check box list.
     * @param string $name name of the check box list.
     * @param mixed $select selection of the check boxes.
     * @param array $data $data value-label pairs used to generate the check box list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function inlineCheckBoxList($name, $select, $data, $htmlOptions = array())
    {
        $htmlOptions['inline'] = true;
        return self::checkBoxList($name, $select, $data, $htmlOptions);
    }

    /**
     * Generates an uneditable input.
     * @param string $value the value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input.
     */
    public static function uneditableField($value = '', $htmlOptions = array())
    {
        $size = self::popOption('size', $htmlOptions);
        if (!self::addSpanClass($htmlOptions))
        {
            if (isset($size))
                $htmlOptions = self::addClassName('input-' . $size, $htmlOptions);
            else if (isset($htmlOptions['block']))
                $htmlOptions = self::addClassName('input-block-level', $htmlOptions);
        }
        $htmlOptions = self::addClassName('uneditable-input', $htmlOptions);
        return self::tag('span', $htmlOptions, $value);
    }

    /**
     * Generates a search query input.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input.
     */
    public static function searchQuery($name, $value = '', $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('search-query', $htmlOptions);
        return self::textField($name, $value, $htmlOptions);
    }

    /**
     * Generates a text field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function textFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_TEXT, $name, $value, $htmlOptions);
    }

    /**
     * Generates a password field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::textInputField
     */
    public static function passwordFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_PASSWORD, $name, $value, $htmlOptions);
    }

    /**
     * Generates an url field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function urlFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_URL, $name, $value, $htmlOptions);
    }

    /**
     * Generates an email field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function emailFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_EMAIL, $name, $value, $htmlOptions);
    }

    /**
     * Generates a number field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::textInputField
     */
    public static function numberFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_NUMBER, $name, $value, $htmlOptions);
    }

    /**
     * Generates a range field input row.
     * @param string $name the input name
     * @param string $value the input value
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function rangeFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_RANGE, $name, $value, $htmlOptions);
    }

    /**
     * Generates a date field input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function dateFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_DATE, $name, $value, $htmlOptions);
    }

    /**
     * Generates a text area input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function textAreaRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_TEXTAREA, $name, $value, $htmlOptions);
    }

    /**
     * Generates a file input row.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function fileFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_FILE, $name, $value, $htmlOptions);
    }

    /**
     * Generates a radio button row.
     * @param string $name the input name.
     * @param string $checked whether the radio button is checked.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function radioButtonRow($name, $checked = false, $htmlOptions = array())
    {
        return self::row(self::INPUT_RADIOBUTTON, $name, $checked, $htmlOptions);
    }

    /**
     * Generates a check box row.
     * @param string $name the input name.
     * @param string $checked whether the check box is checked.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function checkBoxRow($name, $checked = false, $htmlOptions = array())
    {
        return self::row(self::INPUT_CHECKBOX, $name, $checked, $htmlOptions);
    }

    /**
     * Generates a drop down list row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function dropDownListRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_DROPDOWN, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates a list box row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function listBoxRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_LISTBOX, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates a radio button list row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function radioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_RADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates an inline radio button list row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function inlineRadioButtonListRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_INLINERADIOBUTTONLIST, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates a check box list row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function checkBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_CHECKBOXLIST, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates an inline check box list row.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function inlineCheckBoxListRow($name, $select = '', $data = array(), $htmlOptions = array())
    {
        return self::row(self::INPUT_INLINECHECKBOXLIST, $name, $select, $htmlOptions, $data);
    }

    /**
     * Generates a uneditable field row.
     * @param string $select the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function unediableFieldRow($value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_UNEDITABLE, '', $value, $htmlOptions);
    }

    /**
     * Generates search query row.
     * @param string $name the input name.
     * @param string $select the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function searchQueryRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_SEARCH, $name, $value, $htmlOptions);
    }

    /**
     * Generates a form row.
     * @param string $type the input type.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the generated row.
     */
    public static function row($type, $name, $value, $htmlOptions = array(), $data = array())
    {
        $wrap = self::popOption('wrap', $htmlOptions, false);
        $label = self::popOption('label', $htmlOptions, false);
        $color = self::popOption('color', $htmlOptions);
        $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $controlOptions = self::popOption('controlOptions', $htmlOptions, array());

        if (in_array($type, array(self::INPUT_CHECKBOX, self::INPUT_RADIOBUTTON)))
        {
            $htmlOptions['label'] = $label;
            $htmlOptions['labelOptions'] = $labelOptions;
            $label = false;
        }

        $help = self::popOption('help', $htmlOptions, '');
        $helpOptions = self::popOption('helpOptions', $htmlOptions, array());
        if (!empty($help))
            $help = self::inputHelp($help, $helpOptions);
        $input = self::createInput($type, $name, $value, $htmlOptions, $data);

        if ($wrap)
        {
            $groupOptions = self::addClassName('control-group', $groupOptions);
            if (isset($color))
                $groupOptions = self::addClassName($color, $groupOptions);
            $labelOptions = self::addClassName('control-label', $labelOptions);
            ob_start();
            echo self::openTag('div', $groupOptions);
            if ($label !== false)
                echo CHtml::label($label, $name, $labelOptions);
            echo self::formControls($input . $help, $controlOptions);
            echo '</div>';
            return ob_get_clean();
        }
        else
        {
            ob_start();
            if ($label !== false)
                echo CHtml::label($label, $name, $labelOptions);
            echo $input . $help;
            return ob_get_clean();
        }
    }

    /**
     * Generates a wrapped form row.
     * @param string $type the input type.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the generated row.
     */
    public static function wrappedRow($type, $name, $value, $htmlOptions = array(), $data = array())
    {
        $htmlOptions['wrap'] = true;
        return self::row($type, $name, $value, $htmlOptions, $data);
    }

    /**
     * Creates a form input of the given type.
     * @param string $type the input type.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the input.
     * @throws CException if the input type is invalid.
     */
    protected static function createInput($type, $name, $value, $htmlOptions = array(), $data = array())
    {
        switch ($type)
        {
            case self::INPUT_URL: return self::urlField($name, $value, $htmlOptions);
            case self::INPUT_EMAIL: return self::emailField($name, $value, $htmlOptions);
            case self::INPUT_NUMBER: return self::numberField($name, $value, $htmlOptions);
            case self::INPUT_RANGE: return self::rangeField($name, $value, $htmlOptions);
            case self::INPUT_DATE: return self::dateField($name, $value, $htmlOptions);
            case self::INPUT_TEXT: return self::textField($name, $value, $htmlOptions);
            case self::INPUT_PASSWORD: return self::passwordField($name, $value, $htmlOptions);
            case self::INPUT_TEXTAREA: return self::textArea($name, $value, $htmlOptions);
            case self::INPUT_FILE: return self::fileField($name, $value, $htmlOptions);
            case self::INPUT_RADIOBUTTON: return self::radioButton($name, $value, $htmlOptions);
            case self::INPUT_CHECKBOX: return self::checkBox($name, $value, $htmlOptions);
            case self::INPUT_DROPDOWN: return self::dropDownList($name, $value, $data, $htmlOptions);
            case self::INPUT_LISTBOX: return self::listBox($name, $value, $data, $htmlOptions);
            case self::INPUT_CHECKBOXLIST: return self::checkBoxList($name, $value, $data, $htmlOptions);
            case self::INPUT_INLINECHECKBOXLIST: return self::inlineCheckBoxList($name, $value, $data, $htmlOptions);
            case self::INPUT_RADIOBUTTONLIST: return self::radioButtonList($name, $value, $data, $htmlOptions);
            case self::INPUT_INLINERADIOBUTTONLIST: return self::inlineRadioButtonList($name, $value, $data, $htmlOptions);
            case self::INPUT_UNEDITABLE: return self::uneditableField($value, $htmlOptions);
            case self::INPUT_SEARCH: return self::searchQuery($name, $value, $htmlOptions);
            default: throw new CException('Invalid input type "' . $type . '".');
        }
    }

    /**
     * Generates an input HTML tag.
     * This method generates an input HTML tag based on the given input name and value.
     * @param string $type the input type.
     * @param string $name the input name.
     * @param string $value the input value.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input tag.
     */
    protected static function textInputField($type, $name, $value, $htmlOptions)
    {
        CHtml::clientChange('change', $htmlOptions);

        $htmlOptions = self::normalizeInputOptions($htmlOptions);

        $addOnClasses = self::getAddOnClasses($htmlOptions);
        $addOnOptions = self::popOption('addOnOptions', $htmlOptions, array());
        $addOnOptions = self::addClassName($addOnClasses, $addOnOptions);

        $prepend = self::popOption('prepend', $htmlOptions, '');
        $prependOptions = self::popOption('prependOptions', $htmlOptions, array());
        if (!empty($prepend))
            $prepend = self::inputAddOn($prepend, $prependOptions);

        $append = self::popOption('append', $htmlOptions, '');
        $appendOptions = self::popOption('appendOptions', $htmlOptions, array());
        if (!empty($append))
            $append = self::inputAddOn($append, $appendOptions);

        ob_start();
        if (!empty($addOnClasses))
            echo self::openTag('div', $addOnOptions);
        echo $prepend . CHtml::inputField($type, $name, $value, $htmlOptions) . $append;
        if (!empty($addOnClasses))
            echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a label tag for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated label tag.
     */
    public static function activeLabel($model, $attribute, $htmlOptions = array())
    {
        $for = self::popOption('for', $htmlOptions, CHtml::getIdByName(self::resolveName($model, $attribute)));
        $label = self::popOption('label', $htmlOptions, $model->getAttributeLabel($attribute));
        if ($label === false)
            return '';
        return CHtml::label($label, $for, $htmlOptions);
    }

    /**
     * Generates a text field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeTextField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('text', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a password field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activePasswordField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('password', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates an url field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeUrlField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('url', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates an email field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeEmailField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('email', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a number field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeNumberField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('number', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a range field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeRangeField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('range', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a date field input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input field.
     * @see TbHtml::activeTextInputField
     */
    public static function activeDateField($model, $attribute, $htmlOptions = array())
    {
        return self::activeTextInputField('date', $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a text area input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated text area.
     */
    public static function activeTextArea($model, $attribute, $htmlOptions = array())
    {
        $htmlOptions = self::normalizeInputOptions($htmlOptions);
        return CHtml::activeTextArea($model, $attribute, $htmlOptions);
    }

    /**
     * Generates a radio button for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated radio button.
     */
    public static function activeRadioButton($model, $attribute, $htmlOptions = array())
    {
        $label = self::popOption('label', $htmlOptions, false);
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $radioButton = CHtml::activeRadioButton($model, $attribute, $htmlOptions);
        if ($label !== false)
        {
            $labelOptions = self::addClassName('radio', $labelOptions);
            ob_start();
            echo self::tag('label', $labelOptions, $radioButton . $label);
            return ob_get_clean();
        }
        else
            return $radioButton;
    }

    /**
     * Generates a check box for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated check box.
     */
    public static function activeCheckBox($model, $attribute, $htmlOptions = array())
    {
        $label = self::popOption('label', $htmlOptions);
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $radioButton = CHtml::activeCheckBox($model, $attribute, $htmlOptions);
        if ($label !== false)
        {
            $labelOptions = self::addClassName('checkbox', $labelOptions);
            ob_start();
            echo self::tag('label', $labelOptions, $radioButton . $label);
            return ob_get_clean();
        }
        else
            return $radioButton;
    }

    /**
     * Generates a drop down list for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @return string the generated drop down list.
     */
    public static function activeDropDownList($model, $attribute, $data, $htmlOptions = array())
    {
        $htmlOptions = self::normalizeInputOptions($htmlOptions);
        return CHtml::activeDropDownList($model, $attribute, $data, $htmlOptions);
    }

    /**
     * Generates a list box for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list box
     */
    public static function activeListBox($model, $attribute, $data, $htmlOptions = array())
    {
        $htmlOptions = self::defaultOption('size', 4, $htmlOptions);
        return self::activeDropDownList($model, $attribute, $data, $htmlOptions);
    }

    /**
     * Generates a radio button list for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data $data value-label pairs used to generate the radio button list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function activeRadioButtonList($model, $attribute, $data, $htmlOptions = array())
    {
        CHtml::resolveNameID($model, $attribute, $htmlOptions);
        $selection = CHtml::resolveValue($model, $attribute);
        if ($model->hasErrors($attribute))
            CHtml::addErrorCss($htmlOptions);
        $name = self::popOption('name', $htmlOptions);
        $unCheck = self::popOption('uncheckValue', $htmlOptions, '');
        $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
        $hidden = $unCheck !== null ? CHtml::hiddenField($name, $unCheck, $hiddenOptions) : '';
        return $hidden . self::radioButtonList($name, $selection, $data, $htmlOptions);
    }

    /**
     * Generates an inline radio button list for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data $data value-label pairs used to generate the radio button list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function activeInlineRadioButtonList($model, $attribute, $data, $htmlOptions = array())
    {
        $htmlOptions['inline'] = true;
        return self::activeRadioButtonList($model, $attribute, $data, $htmlOptions);
    }

    /**
     * Generates a check box list for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data $data value-label pairs used to generate the check box list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function activeCheckBoxList($model,$attribute,$data,$htmlOptions=array())
    {
        CHtml::resolveNameID($model, $attribute, $htmlOptions);
        $selection = CHtml::resolveValue($model, $attribute);
        if ($model->hasErrors($attribute))
            CHtml::addErrorCss($htmlOptions);
        $name = self::popOption('name', $htmlOptions);
        $unCheck = self::popOption('uncheckValue', $htmlOptions, '');
        $hiddenOptions = isset($htmlOptions['id']) ? array('id' => CHtml::ID_PREFIX . $htmlOptions['id']) : array('id' => false);
        $hidden = $unCheck !== null ? CHtml::hiddenField($name, $unCheck, $hiddenOptions) : '';
        return $hidden . self::checkBoxList($name, $selection, $data, $htmlOptions);
    }

    /**
     * Generates an inline check box list for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data $data value-label pairs used to generate the check box list.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated list.
     */
    public static function activeInlineCheckBoxList($model, $attribute, $data, $htmlOptions = array())
    {
        $htmlOptions['inline'] = true;
        return self::activeCheckBoxList($model, $attribute, $data, $htmlOptions);
    }

    /**
     * Generates an uneditable input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input.
     */
    public static function activeUneditableField($model, $attribute, $htmlOptions = array())
    {
        CHtml::resolveNameID($model, $attribute, $htmlOptions);
        $value = CHtml::resolveValue($model, $attribute);
        return self::uneditableField($value, $htmlOptions);
    }

    /**
     * Generates a search query input for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input.
     */
    public static function activeSearchQuery($model, $attribute, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('search-query', $htmlOptions);
        return self::activeTextField($model, $attribute, $htmlOptions);
    }

    /**
     * Generates a text field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeTextFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_TEXT, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a password field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::textInputField
     */
    public static function activePasswordFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_PASSWORD, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates an url field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeUrlFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_URL, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates an email field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeEmailFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_EMAIL, $name, $value, $htmlOptions);
    }

    /**
     * Generates a number field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::textInputField
     */
    public static function activeNumberFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_NUMBER, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a range field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeRangeFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::row(self::INPUT_RANGE, $name, $value, $htmlOptions);
    }

    /**
     * Generates a date field input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeDateFieldRow($name, $value = '', $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_DATE, $name, $value, $htmlOptions);
    }

    /**
     * Generates a text area input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeTextAreaRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_TEXTAREA, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a file input row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeFileFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_FILE, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a radio button row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeRadioButtonRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_RADIOBUTTON, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a check box row for a model attribute.
     * @param string $name the input name.
     * @param string $checked whether the check box is checked.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeCheckBoxRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_CHECKBOX, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates a drop down list row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeDropDownListRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_DROPDOWN, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates a list box row for a model attribute.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeListBoxRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_LISTBOX, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates a radio button list row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeRadioButtonListRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_RADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates an inline radio button list row for a model attribute.
     * @param string $name the input name.
     * @param string $select the selected value.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeInlineRadioButtonListRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_INLINERADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates a check box list row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeCheckBoxListRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_CHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates an inline check box list row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $data data for generating the list options (value=>display).
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeInlineCheckBoxListRow($model, $attribute, $data = array(), $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_INLINECHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Generates a uneditable field row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeUnediableFieldRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_UNEDITABLE, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates search query row for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated row.
     * @see TbHtml::row
     */
    public static function activeSearchQueryRow($model, $attribute, $htmlOptions = array())
    {
        return self::activeRow(self::INPUT_SEARCH, $model, $attribute, $htmlOptions);
    }

    /**
     * Generates an active form row.
     * @param string $type the input type.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the generated row.
     */
    public static function activeRow($type, $model, $attribute, $htmlOptions = array(), $data = array())
    {
        $wrap = self::popOption('wrap', $htmlOptions, false);
        $label = self::popOption('label', $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $controlOptions = self::popOption('controlOptions', $htmlOptions, array());

        if (in_array($type, array(self::INPUT_CHECKBOX, self::INPUT_RADIOBUTTON)))
        {
            $htmlOptions = self::defaultOption('label', $model->getAttributeLabel($attribute), $htmlOptions);
            $htmlOptions['labelOptions'] = $labelOptions;
            $label = false;
        }

        $help = self::popOption('help', $htmlOptions, '');
        $helpOptions = self::popOption('helpOptions', $htmlOptions, array());
        if (!empty($help))
            $help = self::inputHelp($help, $helpOptions);
        $error = self::popOption('error', $htmlOptions, '');
        $input = self::createActiveInput($type, $model, $attribute, $htmlOptions, $data);

        if ($wrap)
        {
            $groupOptions = self::addClassName('control-group', $groupOptions);
            if (isset($color))
                $groupOptions = self::addClassName($color, $groupOptions);
            $labelOptions = self::addClassName('control-label', $labelOptions);
            ob_start();
            echo self::openTag('div', $groupOptions);
            if ($label !== false)
                echo self::activeLabel($model, $attribute, $labelOptions);
            echo self::formControls($input . $error . $help, $controlOptions);
            echo '</div>';
            return ob_get_clean();
        }
        else
        {
            ob_start();
            if ($label !== false)
                echo self::activeLabel($model, $attribute, $labelOptions);
            echo $input . $error . $help;
            return ob_get_clean();
        }
    }

    /**
     * Generates a wrapped active form row.
     * @param string $type the input type.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the generated row.
     */
    public static function wrappedActiveRow($type, $model, $attribute, $htmlOptions = array(), $data = array())
    {
        $htmlOptions['wrap'] = true;
        return self::activeRow($type, $model, $attribute, $htmlOptions, $data);
    }

    /**
     * Creates an active form input of the given type.
     * @param string $type the input type.
     * @param CModel $model the model instance.
     * @param string $attribute the attribute name.
     * @param array $htmlOptions additional HTML attributes.
     * @param array $data data for multiple select inputs.
     * @return string the input.
     * @throws CException if the input type is invalid.
     */
    protected static function createActiveInput($type, $model, $attribute, $htmlOptions = array(), $data = array())
    {
        switch ($type)
        {
            case self::INPUT_URL: return self::activeUrlField($model, $attribute, $htmlOptions);
            case self::INPUT_EMAIL: return self::activeEmailField($model, $attribute, $htmlOptions);
            case self::INPUT_NUMBER: return self::activeNumberField($model, $attribute, $htmlOptions);
            case self::INPUT_RANGE: return self::activeRangeField($model, $attribute, $htmlOptions);
            case self::INPUT_DATE: return self::activeDateField($model, $attribute, $htmlOptions);
            case self::INPUT_TEXT: return self::activeTextField($model, $attribute, $htmlOptions);
            case self::INPUT_PASSWORD: return self::activePasswordField($model, $attribute, $htmlOptions);
            case self::INPUT_TEXTAREA: return self::activeTextArea($model, $attribute, $htmlOptions);
            case self::INPUT_FILE: return self::activeFileField($model, $attribute, $htmlOptions);
            case self::INPUT_RADIOBUTTON: return self::activeRadioButton($model, $attribute, $htmlOptions);
            case self::INPUT_CHECKBOX: return self::activeCheckBox($model, $attribute, $htmlOptions);
            case self::INPUT_DROPDOWN: return self::activeDropDownList($model, $attribute, $data, $htmlOptions);
            case self::INPUT_LISTBOX: return self::activeListBox($model, $attribute, $data, $htmlOptions);
            case self::INPUT_CHECKBOXLIST: return self::activeCheckBoxList($model, $attribute, $data, $htmlOptions);
            case self::INPUT_INLINECHECKBOXLIST: return self::activeInlineCheckBoxList($model, $attribute, $data, $htmlOptions);
            case self::INPUT_RADIOBUTTONLIST: return self::activeRadioButtonList($model, $attribute, $data, $htmlOptions);
            case self::INPUT_INLINERADIOBUTTONLIST: return self::activeInlineRadioButtonList($model, $attribute, $data, $htmlOptions);
            case self::INPUT_UNEDITABLE: return self::activeUneditableField($model, $attribute, $htmlOptions);
            case self::INPUT_SEARCH: return self::activeSearchQuery($model, $attribute, $htmlOptions);
            default: throw new CException('Invalid input type "' . $type . '".');
        }
    }

    /**
     * Displays a summary of validation errors for one or several models.
     * @param mixed $model the models whose input errors are to be displayed.
     * @param string $header a piece of HTML code that appears in front of the errors.
     * @param string $footer a piece of HTML code that appears at the end of the errors.
     * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
     * @return string the error summary. Empty if no errors are found.
     */
    public static function errorSummary($model, $header = null, $footer = null, $htmlOptions = array())
    {
        // kind of a quick fix but it will do for now.
        $htmlOptions = self::addClassName('alert alert-block alert-error', $htmlOptions);
        return CHtml::errorSummary($model, $header, $footer, $htmlOptions);
    }

    /**
     * Displays the first validation error for a model attribute.
     * @param CModel $model the data model.
     * @param string $attribute the attribute name.
     * @param array $htmlOptions additional HTML attributes to be rendered in the container tag.
     * @return string the error display. Empty if no errors are found.
     */
    public static function error($model, $attribute, $htmlOptions = array())
    {
        CHtml::resolveName($model, $attribute); // turn [a][b]attr into attr
        $error = $model->getError($attribute);
        return !empty($error) ? self::help($error, $htmlOptions) : '';
    }

    /**
     * Generates an input HTML tag  for a model attribute.
     * This method generates an input HTML tag based on the given input name and value.
     * @param string $type the input type.
     * @param CModel $model the data model.
     * @param string $attribute the attribute.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated input tag.
     */
    protected static function activeTextInputField($type, $model, $attribute, $htmlOptions)
    {
        CHtml::resolveNameID($model, $attribute, $htmlOptions);
        CHtml::clientChange('change', $htmlOptions);

        $htmlOptions = self::normalizeInputOptions($htmlOptions);

        $addOnClasses = self::getAddOnClasses($htmlOptions);
        $addOnOptions = self::popOption('addOnOptions', $htmlOptions, array());
        $addOnOptions = self::addClassName($addOnClasses, $addOnOptions);

        $prepend = self::popOption('prepend', $htmlOptions, '');
        $prependOptions = self::popOption('prependOptions', $htmlOptions, array());
        if (!empty($prepend))
            $prepend = self::inputAddOn($prepend, $prependOptions);

        $append = self::popOption('append', $htmlOptions, '');
        $appendOptions = self::popOption('appendOptions', $htmlOptions, array());
        if (!empty($append))
            $append = self::inputAddOn($append, $appendOptions);

        ob_start();
        if (!empty($addOnClasses))
            echo self::openTag('div', $addOnOptions);
        echo $prepend . CHtml::activeInputField($type, $model, $attribute, $htmlOptions) . $append;
        if (!empty($addOnClasses))
            echo '</div>';
        return ob_get_clean();
    }

    /**
     * Returns the add-on classes based on the given options.
     * @param array $htmlOptions the options.
     * @return string the classes.
     */
    protected static function getAddOnClasses($htmlOptions)
    {
        $classes = array();
        if (self::getOption('append', $htmlOptions))
            $classes[] = 'input-append';
        if (self::getOption('prepend', $htmlOptions))
            $classes[] = 'input-prepend';
        return !empty($classes) ? implode(' ', $classes) : $classes;
    }

    /**
     * Generates an add-on for an input field.
     * @param string $addOn the add-on.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated add-on.
     */
    protected static function inputAddOn($addOn, $htmlOptions)
    {
        $addOnOptions = self::popOption('addOnOptions', $htmlOptions, array());
        $addOnOptions = self::addClassName('add-on', $addOnOptions);
        return strpos($addOn, 'btn') === false // buttons should not be wrapped in a span
            ? self::tag('span', $addOnOptions, $addOn)
            : $addOn;
    }

    /**
     * Normalizes input options.
     * @param array $options the options.
     * @return array the normalized options.
     */
    protected static function normalizeInputOptions($options)
    {
        $size = self::popOption('size', $options);
        if (!self::addSpanClass($options))
        {
            if (isset($size))
                $options = self::addClassName('input-' . $size, $options);
            else if (isset($options['block']))
                $options = self::addClassName('input-block-level', $options);
        }
        return $options;
    }

    /**
     * Generates a help text for an input field.
     * @param string $help the help text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated help text.
     */
    protected static function inputHelp($help, $htmlOptions)
    {
        $type = self::popOption('type', $htmlOptions, self::HELP_INLINE);
        return $type === self::HELP_INLINE
            ? self::help($help, $htmlOptions)
            : self::helpBlock($help, $htmlOptions);
    }

    /**
     * Generates form controls.
     * @param mixed $controls the controls.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated controls.
     */
    public static function formControls($controls, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('controls', $htmlOptions);
        if (isset($htmlOptions['row']) && $htmlOptions['row'] === true)
            $htmlOptions = self::addClassName('controls-row', $htmlOptions);
        $before = self::popOption('before', $htmlOptions, '');
        $after = self::popOption('after', $htmlOptions, '');
        if (is_array($controls))
            $controls = implode(' ', $controls);
        ob_start();
        echo self::openTag('div', $htmlOptions);
        echo $before . $controls . $after;
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates form controls row.
     * @param mixed $controls the controls.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated controls.
     */
    public static function formControlsRow($controls, $htmlOptions = array())
    {
        $htmlOptions['row'] = true;
        return self::formControls($controls, $htmlOptions);
    }

    /**
     * Generates form actions.
     * @param mixed $actions the actions.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated actions.
     */
    public static function formActions($actions, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('form-actions', $htmlOptions);
        if (is_array($actions))
            $actions = implode(' ', $actions);
        ob_start();
        echo self::openTag('div', $htmlOptions);
        echo $actions;
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a search form.
     * @param mixed $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML options.
     * @return string the generated form.
     */
    public static function searchForm($action, $method = 'post', $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('form-search', $htmlOptions);
        $inputOptions = self::popOption('inputOptions', $htmlOptions, array());
        $inputOptions = self::mergeOptions(array('type' => 'text', 'placeholder' => 'Search'), $inputOptions);
        $buttonOptions = self::popOption('buttonOptions', $htmlOptions, array());
        $buttonLabel = self::popOption('label', $buttonOptions, self::icon('search'));
        $name = self::popOption('name', $inputOptions, 'search');
        $value = self::popOption('value', $inputOptions, '');
        $addon = self::popOption('addon', $htmlOptions);
        if (isset($addon))
            $inputOptions[$addon] = self::htmlButton($buttonLabel, $buttonOptions);
        ob_start();
        echo CHtml::beginForm($action, $method, $htmlOptions);
        echo self::searchQuery($name, $value, $inputOptions);
        echo CHtml::endForm();
        return ob_get_clean();
    }

    /**
     * Generates a navbar form.
     * @param mixed $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML attributes
     * @return string the generated form.
     */
    public static function navbarForm($action, $method = 'post', $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('navbar-form', $htmlOptions);
        return CHtml::form($action, $method, $htmlOptions);
    }

    /**
     * Generates a navbar search form.
     * @param mixed $action the form action URL.
     * @param string $method form method (e.g. post, get).
     * @param array $htmlOptions additional HTML attributes
     * @return string the generated form.
     */
    public static function navbarSearchForm($action, $method = 'post', $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('navbar-search', $htmlOptions);
        return self::searchForm($action, $method, $htmlOptions);
    }

    // Buttons
    // http://twitter.github.com/bootstrap/base-css.html#buttons
    // --------------------------------------------------

    /**
     * Generates an input button.
     * @param string $label the button label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function button($label = 'button', $htmlOptions = array())
    {
        return self::btn(self::BUTTON_INPUTBUTTON, $label, $htmlOptions);
    }

    /**
     * Generates an image submit button.
     * @param string $src the image URL
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function htmlButton($label = 'Button', $htmlOptions = array())
    {
        return self::btn(self::BUTTON_HTML, $label, $htmlOptions);
    }

    /**
     * Generates a submit button.
     * @param string $label the button label
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function submitButton($label = 'Submit', $htmlOptions = array())
    {
        return self::btn(self::BUTTON_SUBMIT, $label, $htmlOptions);
    }

    /**
     * Generates a reset button.
     * @param string $label the button label
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function resetButton($label = 'Reset', $htmlOptions = array())
    {
        return self::btn(self::BUTTON_RESET, $label, $htmlOptions);
    }

    /**
     * Generates an image submit button.
     * @param string $src the image URL
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function imageButton($src, $htmlOptions = array())
    {
        $htmlOptions['src'] = $src;
        return self::btn(self::BUTTON_IMAGE, 'Submit', $htmlOptions);
    }

    /**
     * Generates a link submit button.
     * @param string $label the button label.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button tag.
     */
    public static function linkButton($label = 'Submit', $htmlOptions = array())
    {
        return self::btn(self::BUTTON_LINKBUTTON, $label, $htmlOptions);
    }

    /**
     * Generates a link that can initiate AJAX requests.
     * @param string $text the link body (it will NOT be HTML-encoded.)
     * @param mixed $url the URL for the AJAX request.
     * @param array $ajaxOptions AJAX options.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function ajaxLink($text, $url, $ajaxOptions = array(), $htmlOptions = array())
    {
        $htmlOptions['url'] = $url;
        $htmlOptions['ajaxOptions'] = $ajaxOptions;
        return self::btn(self::BUTTON_AJAXLINK, $text, $htmlOptions);
    }

    /**
     * Generates a push button that can initiate AJAX requests.
     * @param string $label the button label.
     * @param mixed $url the URL for the AJAX request.
     * @param array $ajaxOptions AJAX options.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function ajaxButton($label, $url, $ajaxOptions = array(), $htmlOptions = array())
    {
        $ajaxOptions['url']  = $url;
        $htmlOptions['ajax'] = $ajaxOptions;
        return self::btn(self::BUTTON_AJAXBUTTON, $label, $htmlOptions);
    }

    /**
     * Generates a push button that can submit the current form in POST method.
     * @param string $label the button label
     * @param mixed $url the URL for the AJAX request.
     * @param array $ajaxOptions AJAX options.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function ajaxSubmitButton($label, $url, $ajaxOptions = array(), $htmlOptions = array())
    {
        $ajaxOptions['type'] = 'POST';
        $htmlOptions['type'] = 'submit';
        return self::ajaxButton($label, $url, $ajaxOptions, $htmlOptions);
    }

    /**
     * Generates a button.
     * @param string $type the button type.
     * @param string $label the button label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function btn($type, $label, $htmlOptions = array())
    {
        self::addSpanClass($htmlOptions);
        $htmlOptions = self::addClassName('btn', $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName('btn-' . $color, $htmlOptions);
        $size = self::popOption('size', $htmlOptions);
        if (isset($size))
            $htmlOptions = self::addClassName('btn-' . $size, $htmlOptions);
        if (self::popOption('block', $htmlOptions, false))
            $htmlOptions = self::addClassName('btn-block', $htmlOptions);
        if (self::popOption('disabled', $htmlOptions, false))
            $htmlOptions = self::addClassName('disabled', $htmlOptions);
        $items = strpos($type, 'input') === false ? self::popOption('items', $htmlOptions, array()) : array();
        if (strpos($type, 'input') === false) // inputs cannot have icons
        {
            $icon = self::popOption('icon', $htmlOptions);
            if (isset($icon))
                $label = self::icon($icon) . '&nbsp;' . $label;
        }
        $dropdownOptions = $htmlOptions;
        self::removeOptions($htmlOptions, array('groupOptions', 'menuOptions', 'dropup'));
        return count($items) > 0
            ? self::btnDropdown($type, $label, $items, $dropdownOptions)
            : self::createButton($type, $label, $htmlOptions);
    }

    /**
     * Generates a button dropdown.
     * $type the button type.
     * @param string $label the button label text.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    protected static function btnDropdown($type, $label, $items, $htmlOptions)
    {
        $menuOptions = self::popOption('menuOptions', $htmlOptions, array());
        $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
        $groupOptions = self::addClassName('btn-group', $groupOptions);
        if (self::popOption('dropup', $htmlOptions, false))
            $groupOptions = self::addClassName('dropup', $groupOptions);
        ob_start();
        echo CHtml::openTag('div', $groupOptions);
        if (self::popOption('split', $htmlOptions, false))
        {
            echo self::createButton($type, $label, $htmlOptions);
            echo self::dropdownToggleButton('', $htmlOptions);
        }
        else
            echo self::dropdownToggleLink($label, $htmlOptions);
        echo self::dropdown($items, $menuOptions);
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Creates a button the of given type.
     * @param string $type the button type.
     * @param string $label the button label.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the button.
     */
    protected static function createButton($type, $label, $htmlOptions)
    {
        $url = self::popOption('url', $htmlOptions, '#');
        $ajaxOptions = self::popOption('ajaxOptions', $htmlOptions, array());
        switch ($type)
        {
            case self::BUTTON_HTML:
                return CHtml::htmlButton($label, $htmlOptions);

            case self::BUTTON_SUBMIT:
                $htmlOptions['type'] = 'submit';
                return CHtml::htmlButton($label, $htmlOptions);

            case self::BUTTON_RESET:
                $htmlOptions['type'] = 'reset';
                return CHtml::htmlButton($label, $htmlOptions);

            case self::BUTTON_IMAGE:
                $htmlOptions['type'] = 'image';
                return CHtml::htmlButton($label, $htmlOptions);

            case self::BUTTON_LINKBUTTON:
                return CHtml::linkButton($label, $htmlOptions);

            case self::BUTTON_AJAXLINK:
                return CHtml::ajaxLink($label, $url, $ajaxOptions, $htmlOptions);

            case self::BUTTON_AJAXBUTTON:
                $ajaxOptions['url'] = $url;
                $htmlOptions['ajax'] = $ajaxOptions;
                return CHtml::htmlButton($label, $htmlOptions);

            case self::BUTTON_INPUTBUTTON:
                return CHtml::button($label, $htmlOptions);

            case self::BUTTON_INPUTSUBMIT:
                $htmlOptions['type'] = 'submit';
                return CHtml::button($label, $htmlOptions);

            default:
            case self::BUTTON_LINK:
                return CHtml::link($label, $url, $htmlOptions);
        }
    }

    // Images
    // http://twitter.github.com/bootstrap/base-css.html#images
    // --------------------------------------------------

    /**
     * Generates an image tag with rounded corners.
     * @param string $src the image URL.
     * @param string $alt the alternative text display.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated image tag.
     */
    public static function imageRounded($src, $alt = '', $htmlOptions = array())
    {
        $htmlOptions['type'] = self::IMAGE_ROUNDED;
        return self::image($src, $alt, $htmlOptions);
    }

    /**
     * Generates an image tag with circle.
     * @param string $src the image URL.
     * @param string $alt the alternative text display.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated image tag.
     */
    public static function imageCircle($src, $alt = '', $htmlOptions = array())
    {
        $htmlOptions['type'] = self::IMAGE_CIRCLE;
        return self::image($src, $alt, $htmlOptions);
    }

    /**
     * Generates an image tag within polaroid frame.
     * @param string $src the image URL.
     * @param string $alt the alternative text display.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated image tag.
     */
    public static function imagePolaroid($src, $alt = '', $htmlOptions = array())
    {
        $htmlOptions['type'] = self::IMAGE_POLAROID;
        return self::image($src, $alt, $htmlOptions);
    }

    /**
     * Generates an image tag.
     * @param string $src the image URL.
     * @param string $alt the alternative text display.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated image tag.
     */
    public static function image($src, $alt = '', $htmlOptions = array())
    {
        $type = self::popOption('type', $htmlOptions);
        if (isset($type))
            $htmlOptions = self::addClassName('img-' . $type, $htmlOptions);
        return CHtml::image($src, $alt, $htmlOptions);
    }

    // Icons by Glyphicons
    // http://twitter.github.com/bootstrap/base-css.html#icons
    // --------------------------------------------------

    /**
     * Generates an icon.
     * @param string $icon the icon type.
     * @param array $htmlOptions additional HTML attributes.
     * @param string $tagName the icon HTML tag.
     * @return string the generated icon.
     */
    public static function icon($icon, $htmlOptions = array(), $tagName = 'i')
    {
        if (is_string($icon))
        {
            if (strpos($icon, 'icon') === false)
                $icon = 'icon-' . implode(' icon-', explode(' ', $icon));
            $htmlOptions = self::addClassName($icon, $htmlOptions);
            return CHtml::openTag($tagName, $htmlOptions) . CHtml::closeTag($tagName); // tag won't work in this case
        }
        return '';
    }

    //
    // COMPONENTS
    // --------------------------------------------------

    // Dropdowns
    // http://twitter.github.com/bootstrap/components.html#dropdowns
    // --------------------------------------------------

    /**
     * Generates a dropdown menu.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function dropdown($items, $htmlOptions = array())
    {
        // todo: think about how to apply this, now it applies to all depths while it should only apply for the first.
        //$htmlOptions = self::setDefaultValue('role', 'menu', $htmlOptions);
        $htmlOptions = self::addClassName('dropdown-menu', $htmlOptions);
        $align = self::popOption('align', $htmlOptions);
        if (isset($align) && $align === self::ALIGN_RIGHT)
            $htmlOptions = self::addClassName('pull-right', $htmlOptions);
        ob_start();
        echo self::menu($items, $htmlOptions);
        return ob_get_clean();
    }

    /**
     * Generates a dropdown toggle link.
     * @param string $label the link label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function dropdownToggleLink($label, $htmlOptions = array())
    {
        return self::dropdownToggle(self::BUTTON_LINK, $label, $htmlOptions);
    }

    /**
     * Generates a dropdown toggle button.
     * @param string $label the button label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function dropdownToggleButton($label = '', $htmlOptions = array())
    {
        return self::dropdownToggle(self::BUTTON_HTML, $label, $htmlOptions);
    }

    /**
     * Generates a dropdown toggle element.
     * @param string $tag the HTML tag.
     * @param string $label the element text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated element.
     */
    public static function dropdownToggle($type, $label, $htmlOptions)
    {
        $htmlOptions = self::addClassName('dropdown-toggle', $htmlOptions);
        $htmlOptions = self::defaultOption('data-toggle', 'dropdown', $htmlOptions);
        $label .= ' <b class="caret"></b>';
        return self::btn($type, $label, $htmlOptions);
    }

    /**
     * Generates a dropdown toggle menu item.
     * @param string $label the menu item text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu item.
     */
    public static function dropdownToggleMenuLink($label, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('dropdown-toggle', $htmlOptions);
        $htmlOptions = self::defaultOption('data-toggle', 'dropdown', $htmlOptions);
        $label .= ' <b class="caret"></b>';
        return CHtml::link($label, '#', $htmlOptions);
    }

    // Button groups
    // http://twitter.github.com/bootstrap/components.html#buttonGroups
    // --------------------------------------------------

    /**
     * Generates a button group.
     * @param array $buttons the button configurations.
     * @param array $htmlOptions additional HTML options.
     * @return string the generated button group.
     */
    public static function buttonGroup($buttons, $htmlOptions = array())
    {
        if (is_array($buttons) && !empty($buttons))
        {
            $htmlOptions = self::addClassName('btn-group', $htmlOptions);
            if (self::popOption('vertical', $htmlOptions, false))
                $htmlOptions = self::addClassName('btn-group-vertical', $htmlOptions);
            $parentOptions = array(
                'style' => self::popOption('style', $htmlOptions),
                'size' => self::popOption('size', $htmlOptions),
                'disabled' => self::popOption('disabled', $htmlOptions)
            );
            ob_start();
            echo CHtml::openTag('div', $htmlOptions);
            foreach ($buttons as $buttonOptions)
            {
                $options = self::popOption('htmlOptions', $buttonOptions, array());
                if (!empty($options))
                    $buttonOptions = self::mergeOptions($options, $buttonOptions);
                $buttonLabel = self::popOption('label', $buttonOptions, '');
                $buttonOptions = self::copyOptions(array('style', 'size', 'disabled'), $parentOptions, $buttonOptions);
                if (isset($buttonOptions['items']))
                {
                    $items = self::popOption('items', $buttonOptions);
                    echo self::buttonDropdown($buttonLabel, $items, $buttonOptions);
                }
                else
                    echo self::linkButton($buttonLabel, $buttonOptions);
            }
            echo '</div>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a button toolbar.
     * @param array $groups the button group configurations.
     * @param array $htmlOptions additional HTML options.
     * @return string the generated button toolbar.
     */
    public static function buttonToolbar($groups, $htmlOptions = array())
    {
        if (is_array($groups) && !empty($groups))
        {
            $htmlOptions = self::addClassName('btn-toolbar', $htmlOptions);
            $parentOptions = array(
                'style' => self::popOption('style', $htmlOptions),
                'size' => self::popOption('size', $htmlOptions),
                'disabled' => self::popOption('disabled', $htmlOptions)
            );
            ob_start();
            echo CHtml::openTag('div', $htmlOptions);
            foreach ($groups as $groupOptions)
            {
                $items = self::popOption('items', $groupOptions, array());
                if (empty($items))
                    continue;
                $options = self::popOption('htmlOptions', $groupOptions, array());
                if (!empty($options))
                    $groupOptions = self::mergeOptions($options, $groupOptions);
                $groupOptions = self::copyOptions(array('style', 'size', 'disabled'), $parentOptions, $groupOptions);
                echo self::buttonGroup($items, $groupOptions);
            }
            echo '</div>';
            return ob_get_clean();
        }
        return '';
    }

    // Button dropdowns
    // http://twitter.github.com/bootstrap/components.html#buttonDropdowns
    // --------------------------------------------------

    /**
     * Generates a button with a dropdown menu.
     * @param string $label the button label text.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function buttonDropdown($label, $items, $htmlOptions = array())
    {
        $htmlOptions['items'] = $items;
        return self::btn(self::BUTTON_LINKBUTTON, $label, $htmlOptions);

        $menuOptions = self::popOption('menuOptions', $htmlOptions, array());
        $groupOptions = self::popOption('groupOptions', $htmlOptions, array());
        $groupOptions = self::addClassName('btn-group', $groupOptions);
        if (self::popOption('dropup', $htmlOptions, false))
            $groupOptions = self::addClassName('dropup', $groupOptions);
        ob_start();
        echo CHtml::openTag('div', $groupOptions);
        if (self::popOption('split', $htmlOptions, false))
        {
            echo self::linkButton($label, $htmlOptions);
            echo self::dropdownToggleButton('', $htmlOptions);
        }
        else
            echo self::dropdownToggleLink($label, $htmlOptions);
        echo self::dropdown($items, $menuOptions);
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a button with a split dropdown menu.
     * @param string $label the button label text.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated button.
     */
    public static function splitButtonDropdown($label, $items, $htmlOptions = array())
    {
        $htmlOptions['split'] = true;
        return self::buttonDropdown($label, $items, $htmlOptions);
    }

    // Navs
    // http://twitter.github.com/bootstrap/components.html#navs
    // --------------------------------------------------

    /**
     * Generates a tab navigation.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function tabs($items, $htmlOptions = array())
    {
        return self::nav(self::NAV_TABS, $items, $htmlOptions);
    }

    /**
     * Generates a stacked tab navigation.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function stackedTabs($items, $htmlOptions = array())
    {
        $htmlOptions['stacked'] = true;
        return self::tabs($items, $htmlOptions);
    }

    /**
     * Generates a pills navigation.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function pills($items, $htmlOptions = array())
    {
        return self::nav(self::NAV_PILLS, $items, $htmlOptions);
    }

    /**
     * Generates a stacked pills navigation.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function stackedPills($items, $htmlOptions = array())
    {
        $htmlOptions['stacked'] = true;
        return self::tabs($items, $htmlOptions);
    }

    /**
     * Generates a list navigation.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function navList($items, $htmlOptions = array())
    {
        return self::nav(self::NAV_LIST, $items, $htmlOptions);
    }

    /**
     * Generates a navigation menu.
     * @param string $type the menu type.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function nav($type, $items, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('nav', $htmlOptions);
        $htmlOptions = self::addClassName('nav-' . $type, $htmlOptions);
        if ($type !== self::NAV_LIST && self::popOption('stacked', $htmlOptions, false))
            $htmlOptions = self::addClassName('nav-stacked', $htmlOptions);
        ob_start();
        echo self::menu($items, $htmlOptions);
        return ob_get_clean();
    }

    /**
     * Generates a menu.
     * @param array $items the menu items.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu.
     */
    public static function menu($items, $htmlOptions = array())
    {
        ob_start();
        echo CHtml::openTag('ul', $htmlOptions);
        foreach ($items as $itemOptions)
        {
            if (is_string($itemOptions))
                echo $itemOptions;
            else
            {
                $options = self::popOption('itemOptions', $itemOptions, array());
                if (!empty($options))
                    $itemOptions = self::mergeOptions($options, $itemOptions);
                // todo: I'm not quite happy with the logic below but it will have to do for now.
                $label = self::popOption('label', $itemOptions, '');
                if (self::popOption('active', $itemOptions, false))
                    $itemOptions = self::addClassName('active', $itemOptions);
                if (self::popOption('disabled', $itemOptions, false))
                    $itemOptions = self::addClassName('disabled', $itemOptions);
                if (self::popOption('header', $itemOptions, false))
                    echo self::menuHeader($label, $itemOptions);
                else
                {
                    $itemOptions['linkOptions'] = self::getOption('linkOptions', $itemOptions, array());
                    $icon = self::popOption('icon', $itemOptions);
                    if (isset($icon))
                        $label = self::icon($icon) . ' ' . $label;
                    $items = self::popOption('items', $itemOptions, array());
                    if (empty($items))
                    {
                        $url = self::popOption('url', $itemOptions, false);
                        echo self::menuLink($label, $url, $itemOptions);
                    } else
                        echo self::menuDropdown($label, $items, $itemOptions);
                }
            }
        }
        echo '</ul>';
        return ob_get_clean();
    }

    /**
     * Generates a menu link.
     * @param string $label the link label.
     * @param array $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu item.
     */
    public static function menuLink($label, $url, $htmlOptions = array())
    {
        $linkOptions = self::popOption('linkOptions', $htmlOptions, array());
        ob_start();
        echo CHtml::openTag('li', $htmlOptions);
        echo CHtml::link($label, $url, $linkOptions);
        echo '</li>';
        return ob_get_clean();
    }

    /**
     * Generates a menu dropdown.
     * @param string $label the link label.
     * @param array $items the menu configuration.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated dropdown.
     */
    public static function menuDropdown($label, $items, $htmlOptions)
    {
        $htmlOptions = self::addClassName('dropdown', $htmlOptions);
        $linkOptions = self::popOption('linkOptions', $htmlOptions, array());
        $menuOptions = self::popOption('menuOptions', $htmlOptions, array());
        $menuOptions = self::addClassName('dropdown-menu', $menuOptions);
        if (self::popOption('active', $htmlOptions, false))
            $htmlOptions = self::addClassName('active', $htmlOptions);
        ob_start();
        echo CHtml::openTag('li', $htmlOptions);
        echo self::dropdownToggleMenuLink($label, $linkOptions);
        echo self::menu($items, $menuOptions);
        echo '</li>';
        return ob_get_clean();
    }

    /**
     * Generates a menu header.
     * @param string $label the header text.
     * @param array $htmlOptions additional HTML options.
     * @return string the generated header.
     */
    public static function menuHeader($label, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('nav-header', $htmlOptions);
        return self::tag('li', $htmlOptions, $label);
    }

    /**
     * Generates a menu divider.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated menu item.
     */
    public static function menuDivider($htmlOptions = array())
    {
        $htmlOptions = self::addClassName('divider', $htmlOptions);
        return self::tag('li', $htmlOptions);
    }

    // Navbar
    // http://twitter.github.com/bootstrap/components.html#navbar
    // --------------------------------------------------

    /**
     * Generates a navbar.
     * @param string $content the navbar content.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated navbar.
     */
    public static function navbar($content, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('navbar', $htmlOptions);
        $display = self::popOption('display', $htmlOptions);
        if (isset($display) )
            $htmlOptions = self::addClassName('navbar-' . $display, $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName('navbar-' . $color, $htmlOptions);
        $innerOptions = self::popOption('innerOptions', $htmlOptions, array());
        $innerOptions = self::addClassName('navbar-inner', $innerOptions);
        ob_start();
        echo CHtml::openTag('div', $htmlOptions);
        echo self::tag('div', $innerOptions, $content);
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a brand link for the navbar.
     * @param string $label the link label text.
     * @param string $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function navbarBrandLink($label, $url, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('brand', $htmlOptions);
        return CHtml::link($label, $url, $htmlOptions);
    }

    /**
     * Generates a text for the navbar.
     * @param string $text the text.
     * @param array $htmlOptions additional HTML attributes.
     * @param string $tag the HTML tag.
     * @return string the generated text block.
     */
    public static function navbarText($text, $htmlOptions = array(), $tag = 'p')
    {
        $htmlOptions = self::addClassName('navbar-text', $htmlOptions);
        return self::tag($tag, $htmlOptions, $text);
    }

    /**
     * Generates a menu divider for the navbar.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated divider.
     */
    public static function navbarMenuDivider($htmlOptions = array())
    {
        $htmlOptions = self::addClassName('divider-vertical', $htmlOptions);
        return self::tag('li', $htmlOptions);
    }

    // Breadcrumbs
    // http://twitter.github.com/bootstrap/components.html#breadcrumbs
    // --------------------------------------------------

    /**
     * Generates a breadcrumb menu.
     * @param array $links the breadcrumb links.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated breadcrumb.
     */
    public static function breadcrumbs($links, $htmlOptions = array())
    {
        $divider = self::popOption('divider', $htmlOptions, '/');
        $htmlOptions = self::addClassName('breadcrumb', $htmlOptions);
        ob_start();
        echo CHtml::openTag('ul', $htmlOptions);
        foreach ($links as $label => $url)
        {
            if (is_string($label))
            {
                echo CHtml::openTag('li');
                echo CHtml::link($label, CHtml::normalizeUrl($url));
                echo self::tag('span', array('class' => 'divider'), $divider);
                echo '</li>';
            }
            else
                echo self::tag('li', array('class' => 'active'), $url);
        }
        echo '</ul>';
        return ob_get_clean();
    }

    // Pagination
    // http://twitter.github.com/bootstrap/components.html#pagination
    // --------------------------------------------------

    /**
     * Generates a pagination.
     * @param array $links the pagination buttons.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated pagination.
     */
    public static function pagination($links, $htmlOptions = array())
    {
        if (is_array($links) && !empty($links))
        {
            $htmlOptions = self::addClassName('pagination', $htmlOptions);
            $size = self::popOption('size', $htmlOptions);
            if (isset($size))
                $htmlOptions = self::addClassName('pagination-' . $size, $htmlOptions);
            $align = self::popOption('align', $htmlOptions);
            if (isset($align))
                $htmlOptions = self::addClassName('pagination-' . $align, $htmlOptions);
            $listOptions = self::popOption('listOptions', $htmlOptions, array());
            ob_start();
            echo CHtml::openTag('div', $htmlOptions);
            echo CHtml::openTag('ul', $listOptions);
            foreach ($links as $itemOptions)
            {
                $options = self::popOption('htmlOptions', $itemOptions, array());
                if (!empty($options))
                    $itemOptions = self::mergeOptions($options, $itemOptions);
                $label = self::popOption('label', $itemOptions, '');
                $url = self::popOption('url', $itemOptions, false);
                echo self::paginationLink($label, $url, $itemOptions);
            }
            echo '</ul>' . '</div>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a pagination link.
     * @param string $label the link label text.
     * @param mixed $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function paginationLink($label, $url, $htmlOptions = array())
    {
        $active = self::popOption('active', $htmlOptions);
        $disabled = self::popOption('disabled', $htmlOptions);
        if ($active)
            $htmlOptions = self::addClassName('active', $htmlOptions);
        else if ($disabled)
            $htmlOptions = self::addClassName('disabled', $htmlOptions);
        $linkOptions = self::popOption('linkOptions', $itemOptions, array());
        ob_start();
        echo CHtml::openTag('li', $htmlOptions);
        echo CHtml::link($label, $url, $linkOptions);
        echo '</li>';
        return ob_get_clean();
    }

    /**
     * Generates a pager.
     * @param array $links the pager buttons.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated pager.
     */
    public static function pager($links, $htmlOptions = array())
    {
        if (is_array($links) && !empty($links))
        {
            $htmlOptions = self::addClassName('pager', $htmlOptions);
            ob_start();
            echo CHtml::openTag('ul', $htmlOptions);
            foreach ($links as $itemOptions)
            {
                $options = self::popOption('htmlOptions', $itemOptions, array());
                if (!empty($options))
                    $itemOptions = self::mergeOptions($options, $itemOptions);
                $label = self::popOption('label', $itemOptions, '');
                $url = self::popOption('url', $itemOptions, false);
                echo self::pagerLink($label, $url, $itemOptions);
            }
            echo '</ul>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a pager link.
     * @param string $label the link label text.
     * @param mixed $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function pagerLink($label, $url, $htmlOptions = array())
    {
        $previous = self::popOption('previous', $htmlOptions);
        $next = self::popOption('next', $htmlOptions);
        if ($previous)
            $htmlOptions = self::addClassName('previous', $htmlOptions);
        else if ($next)
            $htmlOptions = self::addClassName('next', $htmlOptions);
        if (self::popOption('disabled', $htmlOptions, false))
            $htmlOptions = self::addClassName('disabled', $htmlOptions);
        $linkOptions = self::popOption('linkOptions', $itemOptions, array());
        ob_start();
        echo CHtml::openTag('li', $htmlOptions);
        echo CHtml::link($label, $url, $linkOptions);
        echo '</li>';
        return ob_get_clean();
    }

    // Labels and badges
    // http://twitter.github.com/bootstrap/components.html#labels-badges
    // --------------------------------------------------

    /**
     * Generates a label span.
     * @param string $label the label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated span.
     */
    public static function labelTb($label, $htmlOptions = array())
    {
        return self::labelBadge('label', $label, $htmlOptions);
    }

    /**
     * Generates a badge span.
     * @param string $label the badge text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated span.
     *
     */
    public static function badge($label, $htmlOptions = array())
    {
        return self::labelBadge('badge', $label, $htmlOptions);
    }

    /**
     * Generates a label or badge span.
     * @param string $type the span type.
     * @param string $label the label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated span.
     */
    public static function labelBadge($type, $label, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName($type, $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName($type . '-' . $color, $htmlOptions);
        return self::tag('span', $htmlOptions, $label);
    }

    // Typography
    // http://twitter.github.com/bootstrap/components.html#typography
    // --------------------------------------------------

    /**
     * Generates a hero unit.
     * @param string $heading the heading text.
     * @param string $content the content text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated hero unit.
     */
    public static function heroUnit($heading, $content, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('hero-unit', $htmlOptions);
        $headingOptions = self::popOption('headingOptions', $htmlOptions, array());
        ob_start();
        echo self::tag('div', $htmlOptions);
        echo self::tag('h1', $headingOptions, $heading);
        echo $content;
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a pager header.
     * @param string $heading the heading text.
     * @param string $subtext the subtext.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated pager header.
     */
    public static function pageHeader($heading, $subtext, $htmlOptions = array())
    {
        // todo: we may have to set an empty array() as default value
        $htmlOptions = self::addClassName('page-header', $htmlOptions);
        $headerOptions = self::popOption('headerOptions', $htmlOptions, array());
        $subtextOptions = self::popOption('subtextOptions', $htmlOptions, array());
        ob_start();
        echo CHtml::openTag('div', $htmlOptions);
        echo CHtml::openTag('h1', $headerOptions);
        echo CHtml::encode($heading) . ' ' . self::tag('small', $subtextOptions, $subtext);
        echo '</h1>';
        echo '</div>';
        return ob_get_clean();
    }

    // Thumbnails
    // http://twitter.github.com/bootstrap/components.html#thumbnails
    // --------------------------------------------------

    /**
     * Generates a list of thumbnails.
     * @param array $thumbnails the list configuration.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated thumbnails.
     */
    public static function thumbnails($thumbnails, $htmlOptions = array())
    {
        if (is_array($thumbnails) && !empty($thumbnails))
        {
            /* todo: we may have to set an empty array() as default value */
            $htmlOptions = self::addClassName('thumbnails', $htmlOptions);
            $defaultSpan = self::popOption('span', $htmlOptions, 3);
            ob_start();
            echo CHtml::openTag('ul', $htmlOptions);
            foreach ($thumbnails as $thumbnailOptions)
            {
                $options = self::popOption('htmlOptions', $thumbnailOptions, array());
                if (!empty($options))
                    $thumbnailOptions = self::mergeOptions($options, $thumbnailOptions);
                $span = self::popOption('span', $thumbnailOptions, $defaultSpan);
                $caption = self::popOption('caption', $thumbnailOptions, '');
                $captionOptions = self::popOption('captionOptions', $thumbnailOptions, array());
                $captionOptions = self::addClassName('caption', $captionOptions);
                if (isset($thumbnailOptions['label']))
                {
                    $label = self::popOption('label', $thumbnailOptions);
                    $labelOptions = self::popOption('labelOptions', $thumbnailOptions, array());
                    $caption = self::tag('h3', $labelOptions, $label) . $caption;
                }
                $content = !empty($caption) ? self::tag('div', $captionOptions, $caption) : '';
                if (isset($thumbnailOptions['image']))
                {
                    $image = self::popOption('image', $thumbnailOptions);
                    $imageOptions = self::popOption('imageOptions', $thumbnailOptions, array());
                    $alt = self::popOption('alt', $imageOptions, '');
                    $content = CHtml::image($image, $alt, $imageOptions) . $content;
                }
                $url = self::popOption('url', $thumbnailOptions, false);
                echo $url !== false
                    ? self::thumbnailLink($span, $content, $url, $thumbnailOptions)
                    : self::thumbnail($span, $content, $thumbnailOptions);
            }
            echo '</ul>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a thumbnail.
     * @param integer $span the number of grid columns that the thumbnail spans over.
     * @param string $content the thumbnail content.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated thumbnail.
     */
    public static function thumbnail($span, $content, $htmlOptions = array())
    {
        $itemOptions = self::popOption('itemOptions', $htmlOptions, array());
        $itemOptions = self::addClassName('span' . $span, $itemOptions);
        $htmlOptions = self::addClassName('thumbnail', $htmlOptions);
        ob_start();
        echo CHtml::openTag('li', $itemOptions);
        echo CHtml::openTag('div', $htmlOptions);
        echo $content;
        echo '</div>';
        echo '</li>';
        return ob_get_clean();
    }

    /**
     * Generates a link thumbnail.
     * @param integer $span the number of grid columns that the thumbnail spans over.
     * @param string $content the thumbnail content.
     * @param mixed $url the url that the thumbnail links to.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated thumbnail.
     */
    public static function thumbnailLink($span, $content, $url, $htmlOptions = array())
    {
        $itemOptions = self::popOption('itemOptions', $htmlOptions, array());
        $itemOptions = self::addClassName('span' . $span, $itemOptions);
        $htmlOptions = self::addClassName('thumbnail', $htmlOptions);
        ob_start();
        echo CHtml::openTag('li', $itemOptions);
        echo CHtml::link($content, $url, $htmlOptions);
        echo '</li>';
        return ob_get_clean();
    }

    // Alerts
    // http://twitter.github.com/bootstrap/components.html#alerts
    // --------------------------------------------------

    /**
     * Generates an alert.
     * @param string $color the style of the alert.
     * @param string $message the message to display.
     * @param array $htmlOptions additional HTML options.
     * @param string the generated alert.
     */
    public static function alert($color, $message, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('alert', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName('alert-' . $color, $htmlOptions);
        if (self::popOption('in', $htmlOptions, true))
            $htmlOptions = self::addClassName('in', $htmlOptions);
        if (self::popOption('block', $htmlOptions, false))
            $htmlOptions = self::addClassName('alert-block', $htmlOptions);
        if (self::popOption('fade', $htmlOptions, true))
            $htmlOptions = self::addClassName('fade', $htmlOptions);
        $closeText = self::popOption('closeText', $htmlOptions, self::CLOSE_TEXT);
        $closeOptions = self::popOption('closeOptions', $htmlOptions, array());
        ob_start();
        echo CHtml::openTag('div', $htmlOptions);
        echo $closeText !== false ? self::closeLink($closeText, $closeOptions) : '';
        echo $message;
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates an alert block.
     * @param string $style the style of the alert.
     * @param string $message the message to display.
     * @param array $htmlOptions additional HTML options.
     * @return string the generated alert.
     */
    public static function blockAlert($style, $message, $htmlOptions = array())
    {
        $htmlOptions['block'] = true;
        return self::alert($style, $message, $htmlOptions);
    }

    // Progress bars
    // http://twitter.github.com/bootstrap/components.html#progress
    // --------------------------------------------------

    /**
     * Generates a progress bar.
     * @param integer $width the progress in percent.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated progress bar.
     */
    public static function progressBar($width = 0, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('progress', $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName('progress-' . $color, $htmlOptions);
        if (self::popOption('striped', $htmlOptions, false))
        {
            $htmlOptions = self::addClassName('progress-striped', $htmlOptions);
            if (self::popOption('animated', $htmlOptions, false))
                $htmlOptions = self::addClassName('active', $htmlOptions);
        }
        $barOptions = self::popOption('barOptions', $htmlOptions, array());
        $content = self::popOption('content', $htmlOptions, '');
        $barOptions = self::defaultOption('content', $content, $barOptions);
        ob_start();
        echo CHtml::openTag('div', $htmlOptions);
        echo self::bar($width, $barOptions);
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a striped progress bar.
     * @param integer $width the progress in percent.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated progress bar.
     */
    public static function stripedProgressBar($width = 0, $htmlOptions = array())
    {
        $htmlOptions['striped'] = true;
        return self::progressBar($width, $htmlOptions);
    }

    /**
     * Generates an animated progress bar.
     * @param integer $width the progress in percent.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated progress bar.
     */
    public static function animatedProgressBar($width = 0, $htmlOptions = array())
    {
        $htmlOptions['animated'] = true;
        return self::stripedProgressBar($width, $htmlOptions);
    }

    /**
     * Generates a stacked progress bar.
     * @param array $bars the bar configurations.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated progress bar.
     */
    public static function stackedProgressBar($bars, $htmlOptions = array())
    {
        if (is_array($bars) && !empty($bars))
        {
            $htmlOptions = self::addClassName('progress', $htmlOptions);
            ob_start();
            echo CHtml::openTag('div', $htmlOptions);
            foreach ($bars as $barOptions)
            {
                $options = self::popOption('htmlOptions', $barOptions, array());
                if (!empty($options))
                    $barOptions = self::mergeOptions($options, $barOptions);
                $width = self::popOption('width', $barOptions, 0);
                echo self::bar($width, $barOptions);
            }
            echo '</div>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a progress bar.
     * @param integer $width the progress in percent.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated bar.
     */
    public static function bar($width = 0, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('bar', $htmlOptions);
        $color = self::popOption('color', $htmlOptions);
        if (isset($color))
            $htmlOptions = self::addClassName('bar-' . $color, $htmlOptions);
        if ($width < 0)
            $width = 0;
        if ($width > 100)
            $width = 100;
        $htmlOptions = self::addStyles("width: {$width}%;", $htmlOptions);
        $content = self::popOption('content', $htmlOptions, '');
        return self::tag('div', $htmlOptions, $content);
    }

    // Media objects
    // http://twitter.github.com/bootstrap/components.html#media
    // --------------------------------------------------

    /**
     * Generates a list of media objects.
     * @param array $mediaObjects, media objects with the following configuration options:
     * <ul>
     *  <li> image: string, url of the image. </li>
     *  <li> heading: string, the heading of the content. </li>
     *  <li> content: string, content of the image. </li>
     *  <li> htmlOptions: array, additional HTML attributes. Factorial attributes see {@link mediaObject}.
     * </ul>
     * @return string generated list.
     */
    public static function mediaObjects($mediaObjects)
    {
        if ($mediaObjects !== null && is_array($mediaObjects))
        {
            ob_start();
            foreach ($mediaObjects as $mediaObjectOptions)
            {
                $image = self::getOption('image', $mediaObjectOptions, '#');
                $heading = self::getOption('heading', $mediaObjectOptions, '');
                $content = self::getOption('content', $mediaObjectOptions, '');
                $itemOptions = self::getOption('htmlOptions', $mediaObjectOptions, array());
                $itemOptions['items'] = self::popOption('items', $mediaObjectOptions, array());
                echo self::mediaObject($image, $heading, $content, $itemOptions);
            }
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a single media object. Factorial.
     * @param $image string the header of the media object
     * @param $title
     * @param $content
     * @param array $htmlOptions additional HTML attributes. The following special attributes are supported:
     * <ul>
     * 	<li> urlOptions: array(), additional HTML attributes for the url of the media-object header image. The following
     *       special attributes are supported:
     *      <ul>
     * 			<li> href: the url of the link </li>
     * 		</ul>
     *  </li>
     *  <li> imageOptions: array(), additional HTML attributes for the image of the media-object header. The following
     *  	 special attributes are supported:
     *       <ul>
     * 			<li> alt: the alt of the image </li>
     * 		 </ul>
     *  </li>
     *  <li> contentOptions: array(), additional HTML attributes for the media-body content. </li>
     *  <li> headingOptions: array(), additional HTML attributes for the heading content. </li>
     *  <li> items: array(), nested media object (childrens) with the following configuration options:
     *       <ul>
     *         <li> image: string, url of the image. </li>
     *         <li> heading: string, the heading of the content. </li>
     *         <li> content: string, content of the image. </li>
     *         <li> htmlOptions: array, additional HTML attributes. Factorial attributes see above.
     *      </ul>
     * </li>
     * </ul>
     * @return string
     */
    public static function mediaObject($imageUrl, $heading, $content, $htmlOptions = array())
    {
        // extract supported options - brainstorm for better approach --
        $urlOptions = self::popOption('urlOptions', $htmlOptions, array());
        $imageOptions = self::popOption('imageOptions', $htmlOptions, array());
        $contentOptions = self::popOption('contentOptions', $htmlOptions, array());
        $headingOptions = self::popOption('headingOptions', $htmlOptions, array());

        // add required classes
        $urlOptions = self::defaultOption('class', 'pull-left', $urlOptions);
        $imageOptions = self::addClassName('media-object', $imageOptions);
        $contentOptions = self::addClassName('media-body', $contentOptions);
        $headingOptions = self::addClassName('media-heading', $headingOptions);

        // do we have any children?
        $children= self::popOption('items', $htmlOptions);

        ob_start();

        echo CHtml::openTag('div', self::addClassName('media', $htmlOptions)); // media

        echo CHtml::link(
            CHtml::image($imageUrl, self::popOption('alt', $imageOptions, ''), $imageOptions),
            self::popOption('href', $urlOptions, '#'),
            $urlOptions);

        echo CHtml::openTag('div', $contentOptions); // media-body

        // render heading
        echo self::tag('h4', $headingOptions, $heading);

        // render content
        echo $content;

        // render children
        echo self::mediaObjects($children);

        echo '</div>'; // media-body
        echo '</div>'; // media

        return ob_get_clean();
    }

    // Misc
    // http://twitter.github.com/bootstrap/components.html#misc
    // --------------------------------------------------

    /**
     * Generates a well element.
     * @param string $content the well content.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated well.
     */
    public static function well($content, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('well', $htmlOptions);
        $size = self::popOption('size', $htmlOptions);
        if (isset($size))
            $htmlOptions = self::addClassName('well-' . $size, $htmlOptions);
        ob_start();
        echo self::tag('div', $htmlOptions, $content);
        return ob_get_clean();
    }

    /**
     * Generates a close link.
     * @param string $label the link label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function closeLink($label = self::CLOSE_TEXT, $htmlOptions = array())
    {
        $htmlOptions = self::defaultOption('href', '#', $htmlOptions);
        return self::closeIcon('a', $label, $htmlOptions);
    }

    /**
     * Generates a close button.
     * @param string $label the button label text.
     * @param array $htmlOptions the HTML options for the button.
     * @return string the generated button.
     */
    public static function closeButton($label = self::CLOSE_TEXT, $htmlOptions = array())
    {
        return self::closeIcon('button', $label, $htmlOptions);
    }

    /**
     * Generates a close element.
     * @param string $label the element label text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated element.
     */
    public static function closeIcon($tag, $label, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('close', $htmlOptions);
        $htmlOptions = self::defaultOption('data-dismiss', 'alert', $htmlOptions);
        return self::tag($tag, $htmlOptions, $label);
    }

    /**
     * Generates a collapse link.
     * @param string $label the link label.
     * @param string $target the CSS selector.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function collapseLink($label, $target, $htmlOptions = array())
    {
        $htmlOptions['data-toggle'] = 'collapse';
        return CHtml::link($label, $target, $htmlOptions);
    }

    /**
     * Generates a collapse icon.
     * @param string $target the CSS selector for the target element.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated icon.
     */
    public static function collapseIcon($target, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('btn btn-navbar', $htmlOptions);
        $htmlOptions = self::defaultOptions($htmlOptions, array(
                'data-toggle' => 'collapse',
                'data-target' => $target,
            ));
        ob_start();
        echo CHtml::openTag('a', $htmlOptions);
        echo '<span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span>';
        echo '</a>';
        return ob_get_clean();
    }

    //
    // JAVASCRIPT
    // --------------------------------------------------

    // Tooltips and Popovers
    // http://twitter.github.com/bootstrap/javascript.html#tooltips
    // http://twitter.github.com/bootstrap/javascript.html#popovers
    // --------------------------------------------------

    /**
     * Generates a tooltip.
     * @param string $label the tooltip link label text.
     * @param mixed $url the link url.
     * @param string $content the tooltip content text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated tooltip.
     */
    public static function tooltip($label, $url, $content, $htmlOptions = array())
    {
        $htmlOptions['rel'] = 'tooltip';
        return self::tooltipPopover($label, $url, $content, $htmlOptions);
    }

    /**
     * Generates a popover.
     * @param string $label the popover link label text.
     * @param string $title the popover title text.
     * @param string $content the popover content text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated popover.
     */
    public static function popover($label, $title, $content, $htmlOptions = array())
    {
        $htmlOptions['rel'] = 'popover';
        $htmlOptions['data-content'] = $content;
        $htmlOptions['data-toggle'] = 'popover';
        return self::tooltipPopover($label, '#', $title, $htmlOptions);
    }

    /**
     * Generates a base tooltip.
     * @param string $label the tooltip link label text.
     * @param mixed $url the link url.
     * @param string $title the tooltip title text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated tooltip.
     */
    protected static function tooltipPopover($label, $url, $title, $htmlOptions)
    {
        $htmlOptions = self::defaultOption('title', $title, $htmlOptions);
        if (self::popOption('animation', $htmlOptions))
            $htmlOptions = self::defaultOption('data-animation', true, $htmlOptions);
        if (self::popOption('html', $htmlOptions))
            $htmlOptions = self::defaultOption('data-html', true, $htmlOptions);
        $placement = self::popOption('placement', $htmlOptions);
        if (isset($placement))
            $htmlOptions = self::defaultOption('data-placement', $placement, $htmlOptions);
        if (self::popOption('selector', $htmlOptions))
            $htmlOptions = self::defaultOption('data-selector', true, $htmlOptions);
        $trigger = self::popOption('trigger', $htmlOptions);
        if (isset($trigger))
            $htmlOptions = self::defaultOption('data-trigger', $trigger, $htmlOptions);
        if (($delay = self::popOption('delay', $htmlOptions)) !== null)
            $htmlOptions = self::defaultOption('data-delay', $delay, $htmlOptions);
        return CHtml::link($label, $url, $htmlOptions);
    }

    // Carousel
    // http://twitter.github.com/bootstrap/javascript.html#carousel
    // --------------------------------------------------

    /**
     * Generates an image carousel.
     * @param array $items the item configurations.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated carousel.
     */
    public static function carousel($items, $htmlOptions = array())
    {
        if (is_array($items) && !empty($items))
        {
            $id = self::getOption('id', $htmlOptions, CHtml::ID_PREFIX . CHtml::$count++);
            $htmlOptions = self::defaultOption('id', $id, $htmlOptions);
            $selector = '#' . $id;
            $htmlOptions = self::addClassName('carousel', $htmlOptions);
            if (self::popOption('slide', $htmlOptions, true))
                $htmlOptions = self::addClassName('slide', $htmlOptions);
            $interval = self::popOption('data-interval', $htmlOptions);
            if ($interval)
                $htmlOptions = self::defaultOption('data-interval', $interval, $htmlOptions);
            $pause = self::popOption('data-interval', $htmlOptions);
            if ($pause) // todo: add attribute validation if seen necessary.
                $htmlOptions = self::defaultOption('data-pause', $pause, $htmlOptions);
            $indicatorOptions = self::popOption('indicatorOptions', $htmlOptions, array());
            $innerOptions = self::popOption('innerOptions', $htmlOptions, array());
            $innerOptions = self::addClassName('carousel-inner', $innerOptions);
            $prevOptions = self::popOption('prevOptions', $htmlOptions, array());
            $prevLabel = self::popOption('label', $prevOptions, '&lsaquo;');
            $nextOptions = self::popOption('nextOptions', $htmlOptions, array());
            $nextLabel = self::popOption('label', $nextOptions, '&rsaquo;');
            ob_start();
            echo CHtml::openTag('div', $htmlOptions);
            echo self::carouselIndicators($selector, count($items), $indicatorOptions);
            echo CHtml::openTag('div', $innerOptions);
            foreach ($items as $i => $itemOptions)
            {
                $itemOptions = self::addClassName('item', $itemOptions);
                if ($i === 0) // first item should be active
                    $itemOptions = self::addClassName('active', $itemOptions);
                $image = self::popOption('image', $itemOptions, '');
                $label = self::popOption('label', $itemOptions);
                $caption = self::popOption('caption', $itemOptions);
                echo self::carouselItem($image, $label, $caption, $itemOptions);
            }
            echo '</div>';
            echo self::carouselPrevLink($prevLabel, $selector, $prevOptions);
            echo self::carouselNextLink($nextLabel, $selector, $nextOptions);
            echo '</div>';
            return ob_get_clean();
        }
        return '';
    }

    /**
     * Generates a carousel item.
     * @param string $image the image url.
     * @param string $label the item label text.
     * @param string $caption the item caption text.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated item.
     */
    public static function carouselItem($image, $label, $caption, $htmlOptions = array())
    {
        $alt = self::popOption('alt', $htmlOptions, '');
        $imageOptions = self::popOption('imageOptions', $htmlOptions, array());
        $overlayOptions = self::popOption('overlayOptions', $htmlOptions, array());
        $overlayOptions = self::addClassName('carousel-caption', $overlayOptions);
        $labelOptions = self::popOption('labelOptions', $htmlOptions, array());
        $captionOptions = self::popOption('captionOptions', $htmlOptions, array());
        ob_start();
        echo CHtml::openTag('div', $htmlOptions);
        echo CHtml::image($image, $alt, $imageOptions);
        if (isset($label) || isset($caption))
        {
            echo CHtml::openTag('div', $overlayOptions);
            if ($label)
                echo self::tag('h4', $labelOptions, $label);
            if ($caption)
                echo self::tag('p', $captionOptions, $caption);
            echo '</div>';
        }
        echo '</div>';
        return ob_get_clean();
    }

    /**
     * Generates a previous link for the carousel.
     * @param string $label the link label text.
     * @param mixed $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function carouselPrevLink($label, $url, $htmlOptions = array())
    {
        $htmlOptions['data-slide'] = 'prev';
        $htmlOptions = self::addClassName('carousel-control left', $htmlOptions);
        return CHtml::link($label, $url, $htmlOptions);
    }

    /**
     * Generates a next link for the carousel.
     * @param string $label the link label text.
     * @param mixed $url the link url.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated link.
     */
    public static function carouselNextLink($label, $url, $htmlOptions = array())
    {
        $htmlOptions['data-slide'] = 'next';
        $htmlOptions = self::addClassName('carousel-control right', $htmlOptions);
        return CHtml::link($label, $url, $htmlOptions);
    }

    /**
     * Generates an indicator for the carousel.
     * @param string $target the CSS selector for the target element.
     * @param integer $numSlides the number of slides.
     * @param array $htmlOptions additional HTML attributes.
     * @return string the generated indicators.
     */
    public static function carouselIndicators($target, $numSlides, $htmlOptions = array())
    {
        $htmlOptions = self::addClassName('carousel-indicators', $htmlOptions);
        ob_start();
        echo CHtml::openTag('ol', $htmlOptions);
        for ($i = 0; $i < $numSlides; $i++)
        {
            $itemOptions = array('data-target' => $target, 'data-slide-to' => $i);
            if ($i === 0)
                $itemOptions['class'] = 'active';
            echo CHtml::tag('li', $itemOptions);
        }
        echo '</ol>';
        return ob_get_clean();
    }

    // UTILITIES
    // --------------------------------------------------

    /**
     * Appends new class names to the named index "class" at the `$htmlOptions` parameter.
     * @param mixed $className the class(es) to append to `$htmlOptions`
     * @param array $htmlOptions the HTML tag attributes to modify
     * @return array the options.
     */
    public static function addClassName($className, $htmlOptions)
    {
        if (is_array($className))
            $className = implode(' ', $className);
        $htmlOptions['class'] = isset($htmlOptions['class']) ? $htmlOptions['class'] . ' ' . $className : $className;
        return $htmlOptions;
    }

    /**
     * Appends a CSS style string to the given options.
     * @param string $styles the CSS style string.
     * @param array $htmlOptions the options.
     * @return array the options.
     */
    public static function addStyles($styles, $htmlOptions)
    {
        $htmlOptions['style'] = isset($htmlOptions['style']) ? $htmlOptions['style'] . ' ' . $styles : $styles;
        return $htmlOptions;
    }

    /**
     * Copies the option values from one option array to another.
     * @param array $names the option names to copy.
     * @param array $fromOptions the options to copy from.
     * @param array $options the options to copy to.
     * @return array the options.
     */
    public static function copyOptions($names, $fromOptions, $options)
    {
        if (is_array($fromOptions) && is_array($options))
        {
            foreach ($names as $key)
            {
                if (isset($fromOptions[$key]) && !isset($options[$key]))
                    $options[$key] = self::getOption($key, $fromOptions);
            }
        }
        return $options;
    }

    /**
     * Moves the option values from one option array to another.
     * @param array $names the option names to move.
     * @param array $fromOptions the options to move from.
     * @param array $options the options to move to.
     * @return array the options.
     */
    public static function moveOptions($names, $fromOptions, $options)
    {
        if (is_array($fromOptions) && is_array($options))
        {
            foreach ($names as $key)
            {
                if (isset($fromOptions[$key]) && !isset($options[$key]))
                    $options[$key] = self::popOption($key, $fromOptions);
            }
        }
        return $options;
    }

    /**
     * Sets multiple default options for the given options array.
     * @param array $options the options to set defaults for.
     * @param array $defaults the default options.
     * @return array the options with default values.
     */
    public static function defaultOptions($options, $defaults)
    {
        if (is_array($defaults) && is_array($options))
        {
            foreach ($defaults as $name => $value)
                $options = self::defaultOption($name, $value, $options);
        }
        return $options;
    }

    /**
     * Merges two options arrays.
     * @param array $a options to be merged to
     * @param array $b options to be merged from
     * @return array the merged options.
     */
    public static function mergeOptions($a, $b)
    {
        return CMap::mergeArray($a, $b); // yeah I know but we might want to change this to be something else later
    }

    /**
     * Returns an item from the given options or the default value if it's not set.
     * @param string $name the name of the item.
     * @param array $options the options to get from.
     * @param mixed $defaultValue the default value.
     * @return mixed the value.
     */
    public static function getOption($name, $options, $defaultValue = null)
    {
        return (is_array($options) && isset($options[$name])) ? $options[$name] : $defaultValue;
    }

    /**
     * Removes an item from the given options and returns the value.
     * @param string $name the name of the item.
     * @param array $options the options to remove the item from.
     * @param mixed $defaultValue the default value.
     * @return mixed the value.
     */
    public static function popOption($name, &$options, $defaultValue = null)
    {
        if (is_array($options))
        {
            $value = self::getOption($name, $options, $defaultValue);
            unset($options[$name]);
            return $value;
        }
        else
            return $defaultValue;
    }

    /**
     * Sets the default value for an item in the given options.
     * @param string $name the name of the item.
     * @param mixed $value the default value.
     * @param array $options the options.
     * @return mixed
     */
    public static function defaultOption($name, $value, $options)
    {
        if (is_array($options) && !isset($options[$name]))
            $options[$name] = $value;
        return $options;
    }

    /**
     * Removes the option values from the given options.
     * @param array $options the options to remove from.
     * @param array $names names to remove from the options.
     * @return array the options.
     */
    public static function removeOptions($options, $names)
    {
        return array_diff_key($options, array_flip($names));
    }

    /**
     * Adds the grid span class to the given options is applicable.
     * @param array $htmlOptions the HTML attributes.
     * @return boolean whether the span class was added.
     */
    protected static function addSpanClass(&$htmlOptions)
    {
        $span = self::popOption('span', $htmlOptions);
        if (isset($span))
        {
            $htmlOptions = self::addClassName('span' . $span, $htmlOptions);
            return true;
        }
        else
            return false;
    }
}
Back to Top