index-debug.js 220 KB
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 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735
define("index", ["jquery","handlebars","source-map","index","lazyload","dot","jquery.placeholder"], function(require, exports, module){
var webYohobuy;

require("js/common");
require("js/header");
require("js/simple-header");
require("js/product/entry");
require("js/index/index");
require("js/brand/index");
require("js/passport/entry");

//订单确认
require("js/order/ensure");

module.exports = webYohobuy;

});
define("js/common", ["jquery"], function(require, exports, module){
/**
 * 页面公共逻辑和接口
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */
var $ = require("jquery");


var $body = $('body');

require("js/footer");

function cookie(name) {
    var re = new RegExp(name + '=([^;$]*)', 'i'),
        matchPattern = '$1';

    return re.test(decodeURIComponent(document.cookie)) ? RegExp[matchPattern] : '';
}

function setCookie(name, value, options) {
    var expires = '',
        path,
        domain,
        secure,
        date;

    if (typeof value !== 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }

        if (options.expires &&
            (typeof options.expires === 'number' || options.expires.toUTCString)) {
            if (typeof options.expires === 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        path = options.path ? '; path=' + options.path : '';
        domain = options.domain ? '; domain=' + options.domain : '';
        secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    }
}

function getUser() {
    var c = cookie('_UID'),
        user;

    if (typeof c === 'undefined') {
        return 0;
    }

    user = c.split('::');

    if (typeof user === 'undefined' || user.length < 4) {
        return 0;
    }

    return user;
}

function getUid() {
    var user = getUser();

    if (user === 0) {
        return 0;
    }

    return user[1];
}

function getShoppingKey() {
    var c = cookie('_g');

    if (typeof c === 'undefined') {
        return '';
    }

    return JSON.parse(c).k;
}

//YAS统计代码
(function(w, d, s, j, f) {
    var a = d.createElement(s);
    var m = d.getElementsByTagName(s)[0];

    w.YohoAcquisitionObject = f;

    w[f] = function() {
        w[f].p = arguments;
    };

    a.async = 1;
    a.src = j;
    m.parentNode.insertBefore(a, m);
})(window, document, 'script', 'http://cdn.yoho.cn/yas-jssdk/1.0.14/yas.js', '_yas');

(function() {
    var uid = getUid();

    uid = uid === 0 ? '' : uid;

    window._ozuid = uid; //暴露ozuid

    if (window._yas) {
        window._yas(1 * new Date(), '1.0.14', 'yohobuy_web', uid, '', '');
    }
}());

//window.resize在width<1180时适配成990
$(window).on('resize', function() {
    var w = $(this).width();

    //return top
    if (w < 1360) {
        $('.return-top').addClass('min');
    } else {
        $('.return-top').removeClass('min');
    }

    //body
    if (w < 1180) {
        $body.addClass('min-screen');
    } else {
        $body.removeClass('min-screen');
    }
}).trigger('resize');

function queryString() {
    var vars = {},
        hash,
        i,
        search = window.location.search,
        hashes = search ? decodeURIComponent(search).slice(1).split('&') : [];

    for (i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars[hash[0]] = hash[1];
    }
    return vars;
}

window.cookie = cookie;

window.setCookie = setCookie;

window.getUser = getUser;

window.getUid = getUid;

window.getShoppingKey = getShoppingKey;

window.queryString = queryString;

});
define("js/footer", ["jquery"], function(require, exports, module){
/**
 * 尾部
 * @author: wangqing<robin.wang@yoho.cn>
 * @date: 2015/12/01
 */

var $ = require("jquery");

var $returnTop = $('.return-top');

/**
 * 订阅
 * @return {[type]} [description]
 */
function actionSubscription() {
    var $subscriberBox = $('#subscriber-box'),
        $subscriberBtn = $('#subscriber-btn'),
        emailReg = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;

    var iconCode = {
        mail: '&#xe61b;',
        tick: '&#xe61a'
    };

    $subscriberBox.focus(function() {
        $(this).val('').css('color', '');
        $subscriberBtn.removeClass('done').html(iconCode.mail);
    });

    $subscriberBtn.click(function() {
        var email = $.trim($subscriberBox.val());

        if (email !== '' && emailReg.test(email)) {
            try {
                $.ajax({
                    url: 'http://new.yohobuy.com/common/emailsubscriber',
                    dataType: 'jsonp',
                    data: {
                        email: email,
                        tmp: Math.random(),
                        uid: window.getUid()
                    },
                    success: function(data) {
                        if (data.data.result === 1) {
                            $subscriberBox.val('已订阅到:' + email);
                            $subscriberBtn.addClass('done').html(iconCode.tick);
                        } else {
                            $subscriberBox.css('color', 'red');
                        }
                    }
                });
            } catch (e) {
                console.log(e.message);
            }
        } else {
            $subscriberBox.css('color', 'red');
        }
    });
}

function actionhomeFootChange() {
    var $vote = $('.vote'),
        $feedBackPage = $('#feed-back-page'),
        count = $vote.children('li').length;

    //意见反馈
    $feedBackPage.on('click', 'span', function() {
        var $this = $(this);

        if ($this.hasClass('cur')) {
            return;
        }

        $this.siblings('.cur').removeClass('cur');
        $this.addClass('cur');

        $vote.children().not('.hide').addClass('hide')
            .end()
            .eq($this.index()).removeClass('hide');
    });

    $vote.on('click', '.feed-back-btn', function() {
        var $this = $(this),
            $li = $this.closest('li'),
            index = $li.index(),
            _solution = [];

        var _answer = $li.find('.feedback-answer').val(),
            _feedback = $li.find('.feedback-id').val(),
            _question = $li.find('.question-id').val();

        $li.find(':checked').each(function() {
            _solution.push($(this).val());
        });

        $.ajax({
            url: 'http://new.yohobuy.com/common/suggestfeedback',
            dataType: 'jsonp',
            data: {
                feedback_id: _feedback || 0,
                question_id: _question || 0,
                answer: _answer || '',
                solution: _solution.join(',')
            },
            success: function(data) {
                var next = index + 1;

                if (~~data.data.result === 1) {
                    if (index === count - 1) {
                        alert('感谢您的参与!');
                        return;
                    }

                    $li.addClass('hide');

                    $vote.children(':eq(' + (index + 1) + ')').removeClass('hide');
                    $feedBackPage.children('.cur').removeClass('cur');
                    $feedBackPage.children(':eq(' + next + ')').addClass('cur');
                }
            }
        });
    });
}

function rePosReturn() {
    if ($(window).height() > $(document).height()) {
        $returnTop.addClass('hide');
    }

    // 只在窗口高度大于文档高度的时候,隐藏返回顶部
    // else {
    //     $returnTop.removeClass('hide');
    // }
}

//返回顶部
$returnTop.click(function() {
    $('html,body').animate({
        scrollTop: 0
    }, 500);
});

$(window).scroll(function() {
    if ($(window).scrollTop() === 0) {
        $returnTop.addClass('hide');
    } else {
        $returnTop.removeClass('hide');
    }
});

//如果初始是隐藏的,监听图片加载,重新确定return-top的高度
if ($returnTop.hasClass('hide')) {
    $('img').load(rePosReturn);
}

//初始化
actionSubscription();
actionhomeFootChange();

//暴露给有可能通AJAX改变内容的页面去用
window.rePosReturnTop = rePosReturn;

});
define("js/header", ["jquery","handlebars","source-map","index"], function(require, exports, module){
/**
 * 头部
 * @author: wangqing<robin.wang@yoho.cn>
 * @date: 2015/12/01
 */
var $ = require("jquery");
var handlebars = require("handlebars");
var json2 = require("index");
var vipInfoCombine = null; //用户信息编译模板
var loginInfoCombine = null; //登录信息编译模板
var apiDomain = $('#api-domain').val(); //获取数据的地址
var cartTpl = ''; //购物车模板
/**
 * 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
 * @type {RegExp}
 */
var reg = /^[\^\!\+\-\(\)\:\[\]\\\{\}\~\*\?\|\&\;\/]{0,}$/g;
var keyword = '';
var link = '';
var dataLayer = [];
var requestFrame = null;
var logoanimationstart = 0;
var $logotrans = $('.icon-logo');
var isen = true;
var loopdurationtime = 500;
var globaltimeout;
var onetimeoout;
/**
 * banner和地址的映射
 * @type {Object}
 */
var bannerMap = {
    listboys: '4f78b0f418fc42314d8b6e791cfb7fa8',
    listgirls: '00c1f025a51b6b597dc37925951ea27d',
    listkids: 'b02df11184727701ade1b6de9737d08c',
    listlifestyle: 'fd35c52dced0c880976ba858346d1fc5',
    searchboys: '9fb8986ea700cc27a8057361c3924394',
    searchgirls: 'e3e207a1443ca60c8037fe52a5560c18',
    searchkids: '620fc77f479da8feaeb06f2324e5d0bb',
    searchlifestyle: 'a3c93301c6ffaf3ed0f36a4a451be36d',
    uniquebrandboys: '2ebb0810c0d1a67e5229149c9c3aba7d',
    uniquebrandgirls: '99e23385f4ba4b65f406b7e2968ac821',
    uniquebrandkids: 'a74ebc9b17840c91b9ea46568111fe6b',
    uniquebrandlifestyle: '0e8c81ead53f56302baa4d0ad967f527',
    brandsboys: '77b352db07129c76a9d532acad149f9f',
    brandsgirls: 'bf047f16e52ebc38be5ce9c7623831e6',
    brandskids: 'e3ae1ce9b5e13c6d271ef3eccb831652',
    brandslifestyle: 'e4ac8029c30f65d7f1af030980d140fe',
    newboys: '869d3c5f3b450fb52101d00a61ce87cb',
    newgirls: 'd953b6dfdac02483d1dcce8d96055954',
    newkids: '0874cb6d75df8e0e78f2d475e53ecc08',
    newlifestyle: '43e8fc8e178115c262bbce2bd0012db7',
    saleboys: 'c846e3165c994769b4201d8c32f3ae9b',
    salegirls: '52b1d389edcbc62d65de71b80c4d6ad0',
    salekids: 'ad8b1703c761ba00973868ab5199cc27',
    salelifestyle: '7acc64905c70ac91846f43fb2cec4bbd',
    homeboys: 'b0856a771ef1b59ab1234c74688fa42d',
    homegirls: '2bd61fa12e4933211518f70fe5ce3c48',
    homekids: '895c59e8c64b40399c9533509507320c',
    homelifestyle: '2e037d4e25d2767352ca3e0a4627f7bd',
    indexboys: '0c911d3000f52e8ca7cffb74f5864c29',
    indexgirls: 'b645b8980c423ab30485e0a9d08c2ef7',
    indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
    indexlifestyle: '735cd393e841762af8793c346abbbc36'
};
var cookieMap = {};

var bannerApi = 'http://new.yohobuy.com/common/getbanner?content_code=';

$('#api-domain').remove(); //删除信息表单

function getSource(column, postition, event) {
    try {
        dataLayer.push({
            louceng: column,
            weizhi: postition,
            event: event
        });
    } catch (e) {}
}


window.submitSearch = function() {
    var $keywordinput = $('#query_key').val();
    var $defaultsearch = $('#defaultsearch').val();
    var column = 'Search';
    var postition = 'Head Search';
    var event = 'Search';
    var $formatkeyword,
        $formatkeywordinput;

    $formatkeyword = $.trim(keyword.toLowerCase());
    $formatkeywordinput = $.trim($keywordinput.toLowerCase());
    getSource(column, postition, event);
    if (link !== '' && keyword !== '' && $formatkeyword === $formatkeywordinput) {
        location.href = link.replace('\'', '');
    } else {
        if (reg.test($keywordinput) && $keywordinput !== '') {
            location.href = 'http://search.yohobuy.com/error?query=' + $keywordinput + '&result=error';
        } else {
            if ($keywordinput === '') {
                $('#query_key').val($defaultsearch);
            }
            $('#searchForm').submit();
            return false;
        }
    }
};
/**
 * 增加关键字
 * @return {[type]} [description]
 */
function actionAddKeyWords() {
    var $keywords = $('#nav_keyword').text();
    var defaultsearch = 'vans';
    var $querykey = $('#query_key');

    if ($keywords !== '') {
        $querykey.css({
            color: '#000'
        });
        $querykey.val($keywords);
    } else {
        $querykey.css({
            color: '#e0e0e0'
        });
        $querykey.val(defaultsearch);
        $querykey.on('focus', function(e) {
            $querykey.css({
                color: '#000'
            });
            $querykey.val('');
        });
    }
}
/**
 * 定义购物车扩展
 */

function actionGoodsCart() {
    var defaults = {
        cookie: '_g',
        cartNum: ''
    };
    var params = '';
    var cartInfo = '';
    var queryNum = 0;
    var listIndex = 0;
    var tmpList = 0;
    var totalNum = 0;
    var text = '';

    $.fn.miniCart = function(options) {
        params = $.extend(defaults, options);
        if (typeof window.cookie(params.cookie) === 'undefined') {
            cartInfo = null;
        } else {
            if (params.cookie) {
                try {
                    cartInfo = json2.parse(window.cookie(params.cookie));
                } catch (e) {

                }

            }

        }
        if (cartInfo !== null && cartInfo !== '') {
            totalNum = parseInt(cartInfo._nac) + parseInt(cartInfo._ac);
            if (totalNum === 0) {
                $('#icart-num').attr('class', 'icart-num icart-none');
            } else {
                $('#icart-num').attr('class', 'icart-num');
            }
            $(params.cartNum).html(totalNum);
        }
    };
    $.fn.search = function(searchDomain) {

        function getKeywords(obj) {
            var key = $.trim($(obj).val());

            key = key.replace(new RegExp('\'', 'gm'), ''); //去掉特殊字符
            if (key === '') {
                $('.search-list').hide();
                return false;
            }
            key = encodeURI(key);
            $.get(searchDomain + '?query=' + key, function(htmlData) {
                $('.search-list').html(htmlData.data);
                queryNum = $('.search-list').children('li').length;
                listIndex = -1;
                if (queryNum > 0) {
                    $('.search-list').show();
                } else {
                    $('.search-list').hide();
                }
                $('.search-list').find('a').hover(function() {
                    $(this).css('background-color', '#eee');
                }, function() {
                    $(this).css('background-color', '#fff');
                });
            }, 'jsonp');
        }

        function getText(obj) {
            $('.search-list li:eq(' + tmpList + ')').children('a').css('background-color', '#fff');
            $('.search-list li:eq(' + listIndex + ')').children('a').css('background-color', '#eee');
            text = $('.search-list li:eq(' + listIndex + ')').children('a').attr('title');
            $('#query_key').val(text);
        }
        return this.each(function() {
            $(this).keyup(function(event) {
                if (event.which === 38) {
                    if (queryNum === 0) {
                        return false;
                    }
                    if (listIndex === -1) {
                        listIndex = 0;
                    }
                    tmpList = listIndex;
                    listIndex = (listIndex - 1 + queryNum) % queryNum;
                    getText(this);
                } else if (event.which === 40) {
                    if (queryNum === 0) {
                        return false;
                    }
                    tmpList = listIndex;
                    listIndex = (listIndex + 1) % queryNum;
                    getText(this);
                } else if (event.which === 13) {
                    window.submitSearch();
                } else {
                    getKeywords(this);
                }
            });
        });
    };
    $.extend({
        getData: function(domain, options, onSuccess) {
            var defaults = {
                page: 1,
                method: '',
                v: 1,
                return_type: 'jsonp',
                open_key: '12345',
                tmp: Math.random()
            };
            var params = '';

            if (typeof (domain) === undefined || domain === '') {
                return false;
            }
            params = $.extend(defaults, options);
            params.page = params.page || 1;
            if (params.method === '') {
                return false;
            }
            try {
                $.getJSON(domain + '/?callback=?', params, function(_data) {
                    if (onSuccess !== '') {
                        if (typeof onSuccess(_data.data) !== 'undefined') {
                            json2.parse(onSuccess(_data.data));
                        }
                        return false;
                    }
                });
            } catch (e) {
                console.log(e.message);
            }
        },
        getShoppingKey: function() {
            var shoppingInfo = window.cookie('_g');
            var shoppingData = json2.parse(shoppingInfo);

            if (typeof shoppingInfo === 'undefined' || shoppingInfo === null) {
                return '';
            }
            return shoppingData._k;
        }
    });
}

/**
 * 时间戳
 * @param  {[type]} v1       [description]
 * @param  {[type]} options) {               if (v1 [description]
 * @return {[type]}          [description]
 */
handlebars.registerHelper('timestamp', function() {
    return new Date().getTime();
});
/**
 * 头像
 * @param  {[type]} v1       [description]
 * @param  {[type]} options) {               if (v1 [description]
 * @return {[type]}          [description]
 */
handlebars.registerHelper('headerimg', function(headerimg) {

    if (headerimg === '') {
        return 'http://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif' +
            '?imageView/2/w/100/h/100';
    } else {
        return headerimg;
    }

});
/**
 * 判断等级为3的helper
 * @param  {[type]} v1       [description]
 * @param  {[type]} options) {               if (v1 [description]
 * @return {[type]}          [description]
 */

handlebars.registerHelper('equallevelthree', function(v1, options) {

    if (v1 === '3') {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

/**
 * 判断为0的helper
 * @param  {[type]} v1       [description]
 * @param  {[type]} options) {               if (v1 [description]
 * @return {[type]}          [description]
 */

handlebars.registerHelper('equalzero', function(v1, options) {

    if (v1 === '0') {
        return options.fn(this);
    } else {
        return options.inverse(this);
    }
});

/**
 * 获取头部banner的回调函数
 * @param {[type]} data [description]
 */
function JsonPCallBack(data) {
    var topbanner;

    if (+data.code === 200) {
        if (typeof data.data === 'object') {
            if (data.data.url !== '') {
                topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
                    'style="height:36px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
                    'background-position: center;display:block;">&nbsp;</a>';
            } else {
                topbanner = '<div class="noticewrapper">' +
                    '<div class="noticecontainer">' +
                    '<h1 class="noticetitle">关于系统升级的公告</h1>' +
                    '<div class="noticecontent">' +
                    '<p class="tips">尊敬的顾客:</p>' +
                    '<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
                    '<p class="detail">' +
                    '系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
                    '</p>' +
                    '<p class="detail">使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
                    '</div>' +
                    '</div>' +
                    '</div>';
            }
            $('body').prepend(topbanner);
        }
    }
}

window.JsonPCallBack = JsonPCallBack;


/**
 * 获得banner数据
 * @param  {[string]} code [banner对应的编码]
 * @return {[type]}      [description]
 */
function getBannerData(code) {
    var script = document.createElement('script');

    script.src = bannerApi + code + '&client_type=web&callback=JsonPCallBack';
    document.getElementsByTagName('head')[0].appendChild(script);
}

/**
 * 显示和隐藏
 * @param  {[type]} sourceClass [description]
 * @param  {[type]} targetClass [description]
 * @return {[type]}             [description]
 */
function toggleDisplay(sourceClass, targetClass) {
    var $that,
        targetobj;

    $(sourceClass).hover(function(e) {
        e.preventDefault();
        $that = $(this);
        targetobj = $(targetClass)[0];
        if (targetobj.style.display === '') {
            $that.addClass('acttags');
            targetobj.style.display = 'block';
        } else {
            $that.removeClass('acttags');
            targetobj.style.display = '';
        }
    });
}

/**
 * 执行顶部显示和隐藏
 * @return {[type]} [description]
 */
function actionTopTagToggle() {
    var tags = [{
            sourceClass: '.myyoho',
            targetClass: '.myyoho-info'
        }, {
            sourceClass: '.phone',
            targetClass: '.qr'
        }],
        obj,
        i;

    for (i = 0; i < tags.length; i++) {
        obj = tags[i];
        toggleDisplay(obj.sourceClass, obj.targetClass);
    }
}
/**
 * 执行顶部群组鼠标交互
 * @return {[type]} [description]
 */
function actionYoHoGroup() {
    var $this;

    $('.yohogroup').mouseenter(function() {
        $this = $(this);
        $this.text($this.attr('cn'));
    });
    $('.yohogroup').mouseleave(function() {
        $this = $(this);
        $this.text($this.attr('en'));
    });
}

/**
 * 检测是否支持css3的动画
 * @return {Boolean} [description]
 */
function isSupportCss3Animation() {
    var thisFunc,
        prefixList = ['webkit', 'moz', 'ms'],
        i;

    for (i = 0; i < prefixList.length; i++) {
        thisFunc = prefixList[i] + 'RequestAnimationFrame';
        if (window[thisFunc]) {
            return true;
        } else {
            return false;
        }
    }

}
/**
 * css3动画
 * @param  {Array}  ) {               var thisFunc, prefixList [description]
 * @return {[type]}   [description]
 */
function requestFrameAct() {
    var prefixList = ['webkit', 'moz', 'ms'];
    var func1 = prefixList[0] + 'RequestAnimationFrame';
    var func2 = prefixList[1] + 'RequestAnimationFrame';
    var func3 = prefixList[2] + 'RequestAnimationFrame';

    if (window[func1]) {
        return function(callback) {
            requestAnimationFrame(callback);
        };
    }
    if (window[func2]) {
        return function(callback) {
            window[func2](callback);
        };
    }
    if (window[func3]) {
        return function(callback) {
            window[func3](callback);
        };
    }
    return function(callback) {
        window.setTimeout(callback, 67);
    };
}


/**
 * css3动画
 * @return {[type]} [description]
 */

function tsAnimate() {
    logoanimationstart += 10;
    $logotrans.css({
        transform: 'rotateX(' + logoanimationstart + 'deg)',
        '-webkit-transform': 'rotateX(' + logoanimationstart + 'deg)',
        '-moz-transform': 'rotateX(' + logoanimationstart + 'deg)'
    });
    if (logoanimationstart / 90 % 2 === 1) {
        if (isen) {
            $logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo1.png)');
            isen = false;
        } else {
            $logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo_e.png)');
            isen = true;
        }
    }
    if (logoanimationstart / 90 % 2 === 0 && logoanimationstart % 360 !== 0) {
        window.setTimeout(tsAnimate, 3000);
    } else {
        if (logoanimationstart % 360 === 0) {
            window.setTimeout(tsAnimate, 1 * 60 * 1000);
        } else {
            requestFrame(function() {
                tsAnimate();
            });
        }
    }
}

/**
 * 淡出
 * @return {[type]} [description]
 */
function fadeAnimate() {
    if (globaltimeout) {
        window.clearTimeout(globaltimeout);
    }
    $logotrans.fadeOut(loopdurationtime, function() {
        isen = false;

        $logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo.png)');
        $logotrans.fadeIn(loopdurationtime, function() {
            onetimeoout = window.setTimeout(function() {
                $logotrans.fadeOut(loopdurationtime, function() {
                    window.clearTimeout(onetimeoout);
                    isen = true;
                    $logotrans.css('background-image',
                        'url(http://static.yohobuy.com/newheader/img/logo_e.png)');
                    $logotrans.fadeIn(loopdurationtime, function() {
                        globaltimeout = window.setTimeout(fadeAnimate, 1 * 60 * 1000);
                    });
                });
            }, 3000);
        });
    });
}
/**
 * 执行头部logo动画
 * @return {[type]} [description]
 */
function actionTopLogoAnimate() {
    if (isSupportCss3Animation()) {
        requestFrame = requestFrameAct();
        window.setTimeout(tsAnimate, 3000);
    } else {
        window.setTimeout(fadeAnimate, 3000);
    }
}
window.newArr = [];
window.wrapperindex = 0;
window.gindex = 0;
window.targetArr1 = [];
window.targetArr2 = [];
window.targetArr3 = [];
window.oh1 = 0;
window.oh2 = 0;
window.oh3 = 0;
window.valueIndex = 0;
window.nowIndex = 0;
window.inner1 = '';
window.inner2 = '';
window.inner3 = '';
window.finalresult = '';

function createNewArray(obj) {
    var $thirdnavpanel = $(obj);

    $thirdnavpanel.find('.thirdnavbar').each(function() {
        var $that = $(this);
        var $alink = $that.find('a');
        var _href = $alink.attr('href');
        var hottag = $alink.attr('hot') === 'hot' ? true : false;
        var objt = {};

        if ($that.hasClass('category-title')) {
            objt = {
                type: 'title',
                height: 49,
                content: $that.text(),
                index: window.valueIndex,
                href: _href,
                hot: false
            };
        } else {
            objt = {
                type: 'catlist',
                height: 36,
                content: $alink.text(),
                index: window.valueIndex,
                href: _href,
                hot: hottag
            };
        }
        window.valueIndex++;
        window.newArr.push(objt);
    });
}

function createWrapper() {
    var arrlength = window.newArr.length;
    var i = 0;
    var objnew = [];
    var aobj = [];
    var bobj = [];
    var cobj = [];
    var final1 = '',
        final2 = '',
        final3 = '';
    var a = 0;
    var b = 0;
    var c = 0;

    for (i; i < arrlength; i++) {
        objnew = window.newArr[i];
        if (window.gindex === 0) {
            window.oh1 = (window.oh1 + objnew.height);
            if (window.oh1 >= 340 && i !== (arrlength - 1)) {
                window.targetArr1 = window.newArr.slice(0, objnew.index + 1);
                window.nowIndex = objnew.index + 1;
                window.gindex++;
            }
            if (i === (arrlength - 1)) {
                window.targetArr1 = window.newArr.slice(0, arrlength + 1);
                break;
            }
        }
        if (window.gindex === 1) {
            window.oh2 = (window.oh2 + objnew.height);
            if (window.oh2 >= 340 && i !== (arrlength - 1)) {
                window.targetArr2 = window.newArr.slice(window.nowIndex, objnew.index + 1);
                window.nowIndex = objnew.index + 1;
                window.gindex++;
            }
            if (i === (arrlength - 1)) {
                window.targetArr2 = window.newArr.slice(window.nowIndex, arrlength + 1);
                break;
            }
        }
        if (window.gindex === 2) {
            window.oh3 = (window.oh3 + objnew.height);
            if (window.oh3 >= 340 && i !== (arrlength - 1)) {
                window.targetArr3 = window.newArr.slice(window.nowIndex, objnew.index + 1);
                window.nowIndex = objnew.index + 1;
                window.gindex++;
                break;
            }
            if (i === (arrlength - 1)) {
                window.targetArr3 = window.newArr.slice(window.nowIndex, arrlength + 1);
                break;
            }
        }
    }
    for (a; a < window.targetArr1.length; a++) {
        aobj = window.targetArr1[a] || {};
        if (aobj.type === 'title') {
            window.inner1 = window.inner1 +
                '<li class="cattitle"><h3><a  href="' +
                aobj.href +
                '">' +
                aobj.content +
                '</a></h3></li>';
        } else {
            if (aobj.hot === true) {
                window.inner1 = window.inner1 +
                    '<li class="catdetail"><a  class="thirdcatelink hot" href="' +
                    aobj.href +
                    '">' +
                    aobj.content +
                    '</a></li>';
            } else {
                window.inner1 = window.inner1 +
                    '<li class="catdetail"><a  class="thirdcatelink" href="' +
                    aobj.href + '">' +
                    aobj.content +
                    '</a></li>';
            }

        }
    }
    for (b; b < window.targetArr2.length; b++) {
        bobj = window.targetArr2[b] || {};
        if (bobj.type === 'title') {
            window.inner2 = (window.inner2 +
                '<li class="cattitle"><h3><a  href="' +
                bobj.href + '">' +
                bobj.content +
                '</a></h3></li>');
        } else {
            if (bobj.hot === true) {
                window.inner2 = (window.inner2 +
                    '<li class="catdetail"><a  class="thirdcatelink hot" href="' +
                    bobj.href + '">' + bobj.content + '</a></li>');
            } else {
                window.inner2 = (window.inner2 +
                    '<li class="catdetail"><a  class="thirdcatelink" href="' +
                    bobj.href + '">' + bobj.content + '</a></li>');
            }

        }
    }
    for (c; c < window.targetArr3.length; c++) {
        cobj = window.targetArr3[c] || {};
        if (cobj.type === 'title') {
            window.inner3 = (window.inner3 +
                '<li class="cattitle"><h3><a  href="' +
                cobj.href +
                '">' +
                cobj.content +
                '</a></h3></li>');
        } else {
            if (cobj.hot === true) {
                window.inner3 = (window.inner3 +
                    '<li class="catdetail"><a  class="thirdcatelink hot" href="' +
                    cobj.href + '">' +
                    cobj.content +
                    '</a></li>');
            } else {
                window.inner3 = (window.inner3 +
                    '<li class="catdetail"><a  class="thirdcatelink" href="' +
                    cobj.href + '">' +
                    cobj.content +
                    '</a></li>');
            }

        }
    }
    if (window.inner1 !== '') {
        final1 = '<ul class="cate_row1 cate_row">' +
            window.inner1 +
            '</ul>';
    }
    if (window.inner2 !== '') {
        final2 = '<ul class="cate_row2 cate_row">' +
            window.inner2 +
            '</ul>';
    }
    if (window.inner3 !== '') {
        final3 = '<ul class="cate_row3 cate_row">' +
            window.inner3 +
            '</ul>';
    }
    window.finalresult = final1 + final2 + final3;
    $('#' + window.wrapperindex).empty().append(window.finalresult);
}

function actionNav() {
    $('.categorywrapper').each(function(index) {
        window.wrapperindex = $(this).attr('id');
        window.newArr = [];
        window.gindex = 0;
        window.targetArr1 = [];
        window.targetArr2 = [];
        window.targetArr3 = [];
        window.oh1 = 0;
        window.oh2 = 0;
        window.oh3 = 0;
        window.valueIndex = 0;
        window.nowIndex = 0;
        window.inner1 = '';
        window.inner2 = '';
        window.inner3 = '';
        createNewArray($(this).find('.category'));
        createWrapper();
    });
}

/**
 * 获取三级导航的tip图标
 * @return {[type]} [description]
 */
function actionTipPic() {
    var tipscode = {};
    var $contentcode = '';
    var $img = '';
    var $title = '';
    var $link = '';
    var logolink = '';

    $(document).on('mouseenter', '.sub-nav-item', function() {
        $contentcode = $(this).find('.showdetail').attr('data-code');
        if ($contentcode) {
            if (!tipscode[$contentcode]) {
                tipscode[$contentcode] = $contentcode;
                $img = $(this).find('.showdetail').find('img');
                $title = $(this).find('.showdetail').find('.title');
                $link = $(this).find('.showdetail').find('a');
                $.get(bannerApi + $contentcode + '&width=337&height=250&client_type=web', function(rsdata) {
                    $img.attr('src', rsdata.data.src);
                    $link.attr('href', rsdata.data.url);
                    $title.text(rsdata.data.title);
                }, 'jsonp');
            }
        }
    });
    logolink = $('.cure').find('.name-cn').find('a').attr('href');
    $('.main-link').attr('href', logolink);
}



function closeCover() {
    var $cover = $('#cover');

    $cover.remove();
}
/**
 * 首次进入有弹窗
 * @return {[type]} [description]
 */
function actionCover() {
    var gender = window.cookie('_Gender');
    var newMask = '';
    var windowheight = '';
    var selfheight = '';
    var containertop;
    var length = '';

    if (window.location.href === 'http://www.yohobuy.com/' &&
        (typeof gender === 'undefined' || gender === '' || gender === null)) {
        $.get('http://www.yohobuy.com/index/guide', function(data) {
            newMask = document.createElement('div');
            newMask.id = 'cover';
            newMask.innerHTML = data;
            document.body.appendChild(newMask);
            windowheight = $(window).height();
            selfheight = $('.guide-box').height();
            containertop = windowheight / 2 - selfheight / 2;
            length = $('.guide-box .clear').find('li').length;
            $('.guide-box').css({
                width: (200 * length) + 'px',
                top: containertop + 'px'
            });
            $('#cover').bind('click', function(event) {
                window.setCookie('_Gender', '1,3', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 90
                });
                window.setCookie('_Channel', 'boys', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 7
                });
                closeCover();
            });
            $('#cover .guide-box .close').bind('click', function(event) {
                getSource('弹窗', 'CLOSE', 'homepage_man');
                window.setCookie('_Gender', '1,3', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 90
                });
                window.setCookie('_Channel', 'boys', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 7
                });
                closeCover();
            });
            $('.boys img , .boys .go').bind('click', function(event) {
                getSource('弹窗', 'BOYS', 'homepage_man');
                window.setCookie('_Gender', '1,3', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 90
                });
                window.setCookie('_Channel', 'boys', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 7
                });
                closeCover();
            });
            $('.girls img, .girls .go').bind('click', function(event) {
                getSource('弹窗', 'GIRLS', 'homepage_woman');
                window.setCookie('_Gender', '2,3', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 90
                });
                window.setCookie('_Channel', 'girls', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 7
                });
            });
            $('.lifestyle img, .lifestyle .go').bind('click', function(event) {
                window.setCookie('_Channel', 'lifestyle', {
                    path: '/',
                    domain: '.yohobuy.com',
                    expires: 7
                });
                getSource('弹窗', 'LIEFSTYLE', 'homepage_lifestyle');
            });
            $('#cover .guide-box').bind('click', function(event) {
                event.stopPropagation();
            });
        });
    }
}
/**
 * 查询跳转后保留关键字
 * @return {[type]} [description]
 */
function actionAddKeyWords() {
    var $keywords = $('#nav_keyword').text();
    var defaultsearch = $('#defaultsearch').val();
    var $querykey = $('#query_key');

    if ($keywords !== '') {
        $querykey.css({
            color: '#000'
        });
        $querykey.val($keywords);
    } else {
        $querykey.css({
            color: '#e0e0e0'
        });
        $querykey.val(defaultsearch);
        $querykey.on('focus', function(e) {
            $querykey.css({
                color: '#000'
            });
            $querykey.val('');
        });
    }
}


/**
 * cookie 初始化
 * @return {[type]} [description]
 */
function actionInitCookie() {
    var $cookieGender = window.cookie('_Gender');
    var $target = $('.cure');

    if (typeof $cookieGender !== 'undefined' && $cookieGender !== '') {
        window.setCookie('_Gender', 1, {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });
    }
    if ($target.find('.name-cn a').text() === '男生') {
        window.setCookie('_Gender', '1,3', {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });
        window.setCookie('_Channel', 'boys', {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });
    }
    if ($target.find('.name-cn a').text() === '女生') {
        window.setCookie('_Gender', '2,3', {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });

        // window.setCookie('_Channel', 'girls', {
        //     path: '/',
        //     domain: '.yohobuy.com',
        //     expires: 7
        // });
    }
    if ($target.find('.name-cn a').text() === '创意生活') {
        window.setCookie('_Channel', 'lifestyle', {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });
    }
    if ($target.find('.name-cn a').text() === '潮童') {
        window.setCookie('_Channel', 'kids', {
            path: '/',
            domain: '.yohobuy.com',
            expires: 7
        });
    }
}
/**
 * 提前设置好频道的cookie
 */
function setChannelCookie() {
    $('.first-nav-item').click(function() {
        var _cookieGender = window.cookie('_Gender');

        if (typeof _cookieGender !== 'undefined' && _cookieGender !== '') {
            window.setCookie('_Gender', 1, {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
        }
        if ($(this).find('.name-cn a').text() === '男生') {
            window.setCookie('_Gender', '1,3', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
            window.setCookie('_Channel', 'boys', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
        }
        if ($(this).find('.name-cn a').text() === '女生') {
            window.setCookie('_Gender', '2,3', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
            window.setCookie('_Channel', 'girls', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
        }
        if ($(this).find('.name-cn a').text() === '创意生活') {
            window.setCookie('_Channel', 'lifestyle', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
        }
        if ($(this).find('.name-cn a').text() === '潮童') {
            window.setCookie('_Channel', 'kids', {
                path: '/',
                domain: '.yohobuy.com',
                expires: 7
            });
        }
    });

}
/**
 * cookie集合
 * @type {Object}
 */
function actionExeCookieMap() {
    var cookies = document.cookie;
    var cookiearr = cookies.split(';');
    var i;
    var temparr;
    var key;

    for (i = 0; i < cookiearr.length; i++) {
        temparr = cookiearr[i].split('=');
        if (typeof temparr[0] !== 'undefined') {
            key = temparr[0].replace(/\s/g, '');
            cookieMap[key] = temparr[1];
        }
    }
}


/**
 * 购物车商品数量
 * @return {[type]} [description]
 */
function actionUpdateCartNum() {
    $('#miniCartBox').miniCart({
        cartNum: '.ic-infomation'
    });
}
/**
 * 加载购物车数据
 * @return {[type]} [description]
 */
function loadCartData() {
    var shoppingInfo,
        shoppingData,
        strK;

    $.getData(apiDomain, {
        method: 'open.Shoppingcart.getCartData',
        shopping_key: $.getShoppingKey()
    }, function(jsonData) {
        if (cartTpl === '') {
            cartTpl = handlebars.compile($('#mini-cart-tpl').html());
        }
        $('#miniCartBox').children('.gobuy-wrapper').html(cartTpl({
            carData: jsonData
        }));
        if (parseInt($('.ic-infomation').html()) === 0) {
            $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
                '<h3 class="information">您的购物车暂无商品</h3></div>');
        }
        if ($('#miniCartBox .goods-list li').length < 1) {
            shoppingInfo = window.cookie('_g');
            shoppingData = json2.parse(shoppingInfo);
            if (shoppingData !== null) {
                strK = '{"_k":"' + shoppingData._k + '","_nac":0' + ',"_ac":0,"_r":0}';
                window.setCookie('_g', strK, {
                    path: '/',
                    domain: '.yohobuy.com'
                });
            }
            $('.ic-infomation').html(0);
            $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
                '<h3 class="information">您的购物车暂无商品</h3></div>');
        }
    });
}
/**
 * 删除购物车数据
 * @param  {[type]}  id        [description]
 * @param  {Boolean} isreduce [description]
 * @return {[type]}            [description]
 */
function delCartGoods(id, isreduce) {
    $.getData(apiDomain, {
        method: 'open.Shoppingcart.delone',
        shopping_key: $.getShoppingKey(),
        id: id,
        isreduce: isreduce
    }, function(jsonData) {
        var shoppingInfo = window.cookie('_g');
        var shoppingData = json2.parse(shoppingInfo);
        var strK = '{"_k":"' + shoppingData._k + '","_nac":' + jsonData.total_goods_num + ',"_ac":0,"_r":0}';

        window.setCookie('_g', strK, {
            path: '/',
            domain: '.yohobuy.com'
        });
        loadCartData();
        actionUpdateCartNum();
    });
}


/**
 * 监听购物车删除
 * @return {[type]} [description]
 */
function actionListenDelCarGoods() {
    var $delcargoods;
    var goodsid,
        cheapest;

    $(document).on('click', '.goodscardelete', function(e) {
        $delcargoods = $(this);
        goodsid = $delcargoods.attr('goodsid');
        cheapest = $delcargoods.attr('cheapest');
        delCartGoods(goodsid, cheapest);
    });
}
/**
 * 监听点击更多打折商品
 * @return {[type]} [description]
 */
function actionListenCartMore() {
    var $morecart;

    $(document).on('click', '.mycart_i_down', function(e) {
        $morecart = $(this);
        $morecart.toggleClass('mycart_i_up');
        $('#mycartmore').slideToggle(300);
    });
}
/**
 * 点击购物车
 * @return {[type]} [description]
 */
function actionClickMiniCartBox() {
    var $target;
    var shopcarurl = 'http://www.yohobuy.com/shopping/cart';

    $('#miniCartBox').on('click', function(e) {
        $target = $(e.target);
        if ($target.hasClass('gobuy')) {
            window.location.href = shopcarurl;
        }
    });
}

/**
 * 显示购物车效果
 * @param  {Boolean} isShow [description]
 * @return {[type]}         [description]
 */
function showMiniCart(isShow) {
    if (isShow === 1) {
        $('#miniCartBox').addClass('list-cur');
        $('.gobuy-wrapper').show();
        if (parseInt($('.ic-infomation').html()) !== 0) {
            $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-loading">' +
                '<h3 class="information">加载中,请稍后</h3></div>');
            loadCartData();
        } else {
            $('#miniCartBox .gobuy-wrapper').html('<div class="gobuy-empty">' +
                '<h3 class="information">您的购物车暂无商品</h3></div>');
        }
    } else {
        $('#miniCartBox').removeClass('list-cur');
        $('.gobuy-wrapper').hide();
    }
}


/**
 * 鼠标购物车的滑入滑出效果
 * @return {[type]} [description]
 */
function actionGoodsCarMouseEffect() {
    var $target;

    $('#miniCartBox').mouseenter(function(e) {
        $target = $(e.target);
        if ($target.attr('id') === 'miniCartBox' || $target.attr('class') === 'ic-infomation') {
            showMiniCart(1);
        }
    });
    $('#miniCartBox').mouseleave(function(e) {
        showMiniCart(0);
    });
}
/**
 * 获得banner & 异常通知
 * @return {[type]} [description]
 */
function actionGetBannerAndNotice() {
    var INDEXKIDS = 'indexkids',
        INDEXLIFESTYLE = 'indexlifestyle',
        INDEXBOYS = 'indexboys',
        INDEXWOMAN = 'indexgirls',
        UNIQUEBRAND = 'uniquebrand';
    var url = window.location.href;
    var host = window.location.host;
    var code = '';
    var firstarea;

    if (url.indexOf('search') !== -1) {
        code = bannerMap['search' + cookieMap._Channel];
    }
    if (url.indexOf('list') !== -1) {
        code = bannerMap['list' + cookieMap._Channel];
    }
    if (url.indexOf('brands') !== -1) {
        code = bannerMap['brands' + cookieMap._Channel];
    }
    if (url.indexOf('new') !== -1) {
        code = bannerMap['new' + cookieMap._Channel];
    }
    if (url.indexOf('sale') !== -1) {
        code = bannerMap['sale' + cookieMap._Channel];
    }
    if (url.indexOf('home') !== -1) {
        code = bannerMap['home' + cookieMap._Channel];
    }
    if (url.indexOf('kids') !== -1) {
        code = bannerMap[INDEXKIDS];
    }
    if (url.indexOf('woman') !== -1 || url.indexOf('girls') !== -1) {
        code = bannerMap[INDEXWOMAN];
    }
    if (url.indexOf('lifestyle') !== -1) {
        code = bannerMap[INDEXLIFESTYLE];
    }
    if (url.indexOf('www.yohobuy.com') !== -1 && window.location.pathname === '/') {
        code = bannerMap[INDEXBOYS];
    }
    firstarea = host.split('.')[0];
    if (firstarea !== 'list' && firstarea !== 'search' && firstarea !== 'www' &&
        firstarea !== 'new' && firstarea !== 'item' && firstarea !== 'guang') {
        code = bannerMap[UNIQUEBRAND + cookieMap._Channel];
    }

    getBannerData(code); //获得banner信息

}

function brandSwitch(index) {
    $('.hot-brands').find('ul').stop().animate({
        opacity: 0,
        'z-index': 1
    }, 200).eq(index).animate({
        opacity: 1,
        'z-index': 2
    }, 200);
}
/**
 * 品牌左右切换
 * @return {[type]} [description]
 */
function actionBrandChange() {
    var activeIndex = 0,
        swiperLen;

    if ($('.hot-brands').size() > 0) {
        swiperLen = $('.hot-brands').find('ul').size();
        $('.hot-brands').find('ul').eq(0).css({
            opacity: 1,
            'z-index': 2
        });
        $('.brands-control').on('click', '.next', function() {
            if (activeIndex === swiperLen - 1) {
                activeIndex = 0;
            } else {
                activeIndex++;
            }
            brandSwitch(activeIndex);
        });
        $('.brands-control').on('click', '.prev', function() {
            if (activeIndex === 0) {
                activeIndex = swiperLen - 1;
            } else {
                activeIndex--;
            }
            brandSwitch(activeIndex);
        });


    }
}
/**
 * 循环检测购物车数量
 * @return {[type]} [description]
 */
function actionLoopUpdCartNum() {
    setInterval(actionUpdateCartNum, 2000);
}
/**
 * 处理模板
 * @return {[type]} [description]
 */
function actionExeTemplate() {
    var $goodcartempwarpper = $('#goodcartempwarpper');
    var resulthtml = '';

    if ($goodcartempwarpper) {
        if ($goodcartempwarpper.html()) {
            resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, '');
            $('#goodcartempwarpper').html(resulthtml);
            vipInfoCombine = handlebars.compile($('#tmpl-my-login-new').html());
        }
    }
}
/**
 * 执行搜索
 * @return {[type]} [description]
 */
function actionSearch() {
    var searchDomain = 'http://search.yohobuy.com/api/suggest';

    $('#query_key').search(searchDomain);
}
/**
 * 获取登录状态
 * @return {[type]} [description]
 */
function actionLoginState(_data) {
    var timestamp = new Date().getTime();
    var noLoginHtml = '<span>Hi~</span>[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out ">' +
        '请登录</a>]&nbsp;' +
        '[<a href="http://www.yohobuy.com/reg.html" class="list-a login-out" onclick="">免费注册</a>]';
    var loginHtml = '<span>Hi~<a href="http://www.yohobuy.com/home?t=' + timestamp +
        '">{{user_name}}</a></span>&nbsp;' +
        '{{#if islogin}}' +
        '[<a href="{{logout}}" class="list-a login-out">退出</a>]' +
        '{{/if}}{{#unless islogin}}' +
        '[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out">请登录</a>]&nbsp;' +
        '[<a href="http://www.yohobuy.com/reg.html" onclick="" class="list-a login-out">免费注册</a>]' +
        '{{/unless}}';
    var $boxObj = $('#loginBox');
    var info = window.cookie('_UID');
    var name = _data.data.profile_name;
    var _length = 0;
    var t = 0;
    var char = '';
    var user = info.split('::');
    var userName = user[0] || ' ';
    var _logout = 'http://www.yohobuy.com/logout_';
    var islogin = '1';
    var _num = 0;
    var data = {
        user_name: name,
        logout: _logout + _data.data.token + '.html',
        random: Math.random()
    };


    loginInfoCombine = handlebars.compile(loginHtml);
    if (typeof info === 'undefined' || info === null) {
        $boxObj.html(noLoginHtml);
        return false;
    }
    if (typeof user === 'undefined' || user.length < 4) {
        $boxObj.html(noLoginHtml);
        return false;
    }

    for (t; t < userName.length; t++) {
        char = userName.substr(t, 1);
        if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
            _length += 2;
        } else {
            _length += 1;
        }
    }
    if (_length <= 10) {
        name = userName;
    } else {
        _num = 0;
        for (t; t < userName.length; t++) {
            if (_num < 10) {
                char = userName.substr(t, 1);
                if (char !== '*') {
                    if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
                        _num += 2;
                    } else {
                        _num += 1;
                    }
                }
                name += char;
            }
        }
        if (name.length < userName.length) {
            name += '...';
        }
    }


    if (/http:\/\//.test(user[3])) {
        _logout = user[3].replace('www.yohobuy.com', 'www.yohobuy.com');
    } else {
        _logout = 'http://www.yohobuy.com/logout_' + user[3] + '.html';
    }
    if (_data.result === -1) {
        islogin = '-1';
    }
    data.islogin = islogin;
    $boxObj.html(loginInfoCombine(data));
}
/**
 * 获得vip用户信息
 * @return {[type]} [description]
 */
function actionVipInfo(_data) {
    var vipInfo = _data.data;
    var headUrl = '';

    if (_data.result === 1) {
        if (typeof vipInfo === undefined || vipInfo.length < 1) {
            return false;
        }
        if (vipInfo.vip.curVipInfo.curLevel === '3') {
            vipInfo.vip3 = true;
        }

        $('#myYohoBox').mouseenter(function() {
            $(this).addClass('acttags');
            $('#myYohoBox .myyoho-info').show().html(vipInfoCombine(vipInfo));
            headUrl = $('.myyoho-photo img').attr('data-url');
            if ($._checkUrlState === 1) {
                $('.myyoho-photo').show().find('img').attr('src', headUrl);
                return;
            }
            if (headUrl === '' || $._checkUrl !== '') {
                return;
            }
            $.ajax({
                url: headUrl,
                type: 'GET',
                complete: function(response) {
                    if (response.status === 200 || response.status === 0) {
                        $('.myyoho-photo').show().find('img').attr('src', headUrl);
                        $._checkUrlState = 1;
                    }
                    $._checkUrl = headUrl;
                }
            });
        });
        $('#myYohoBox').mouseleave(function() {
            $(this).removeClass('acttags');
            $('#myYohoBox .myyoho-info').hide();
        });
    }
}
/**
 * 获取登录信息
 * @return {[type]} [description]
 */
function actionLoginInfo() {
    var param = {
        method: 'open.passport.get'
    };

    $.getData(apiDomain, param, function(_data) {
        if (_data.result !== -1) {
            actionLoginState(_data); // 更改登录状态
            actionVipInfo(_data); //获得vip;
        }
    });
}
/**
 * 初始化函数
 * @return {[type]} [description]
 */
function init() {
    actionNav(); //处理导航
    actionTipPic(); //鼠标移入后查询
    actionExeTemplate(); //处理模板
    actionCover(); //初次登录弹框
    actionInitCookie(); //初始化cookie
    setChannelCookie(); //设置频道缓存
    actionExeCookieMap(); //格式化cookie
    actionGoodsCart(); //初始化购物车插件
    actionYoHoGroup(); // yoho集团鼠标效果
    actionTopTagToggle(); // yoho上部分开关
    actionTopLogoAnimate(); //yoho logo动画
    actionGetBannerAndNotice(); // 获取banner和服务器维护提示
    actionBrandChange(); //切换品牌
    actionAddKeyWords(); //跳转后增加关键字
    actionGoodsCarMouseEffect(); //鼠标滑入滑出效果
    actionUpdateCartNum(); //更新购物车数量
    actionLoopUpdCartNum(); //循环检测购物车数量
    actionSearch(); //搜索执行
    actionClickMiniCartBox(); //点击购物车跳转
    actionListenDelCarGoods(); //监听购物车删除
    actionListenCartMore(); //
    actionLoginInfo(); //获取登录信息
    actionAddKeyWords(); //增加关键字
}
init();
});
define("js/simple-header", ["jquery"], function(require, exports, module){
var $ = require("jquery");

if ($('.simple-header').size() > 0) {
    $('.tool-options').on('mouseenter', function() {
        $(this).find('.tool-select').fadeIn();
    }).on('mouseleave', function() {
        $(this).find('.tool-select').fadeOut();
    });
}

/**
 * 格式化用户名
 * @return {[type]} [description]
 */
function formatUsernName(userName) {
    var name,
        char,
        _num = 0,
        _length = 0,
        t;

    for (t = 0; t < userName.length; t++) {
        char = userName.substr(t, 1);
        if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
            _length += 2;
        } else {
            _length += 1;
        }
    }
    if (_length <= 10) {
        name = userName;
    } else {
        _num = 0;
        name = '';
        for (t = 0; t < userName.length; t++) {
            if (_num < 10) {
                char = userName.substr(t, 1);
                if (char !== '*') {
                    if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
                        _num += 2;
                    } else {
                        _num += 1;
                    }
                }
                name += char;
            }
        }
        if (name.length < userName.length) {
            name += '...';
        }
    }
    return name;
}

/**
 * 设置简单头部登陆状态
 * @return {[type]} [description]
 */
function setLoginStatus(_data) {
    var loginHtml,
        name;

    if (_data && _data.href && _data.href.user) {
        name = formatUsernName(_data.href.user);
        loginHtml = '<span>Hi~</span><a href="">' +
                    name + '</a>&nbsp;<a href="' + _data.href.logout + '">[退出]</a>';
    } else {
        name = formatUsernName(_data.user);
        loginHtml = '<span>Hi~</span><a href="">' +
                    name + '</a>&nbsp;<a href="http://www.yohobuy.com/signin.html">[请登录]</a>' +
                    '<a href="http://www.yohobuy.com/reg.html">[免费注册]</a>';
    }
    $('.header-tool li').eq(0).html(loginHtml);
}

/**
 * 获取登录信息
 * @return {[type]} [description]
 */
function actionLoginInfo() {
    $.ajax({
        type: 'GET',
        url: '/common/getSimpleHeader',
        data: {},
        success: function(data) {
            if (data.code === 200) {
                setLoginStatus(data.data);
            }
        }
    });
}

/**
 * 初始化函数
 * @return {[type]} [description]
 */
function init() {
    actionLoginInfo(); //获取登录信息
}
init();


});
define("js/product/entry", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
 * 商品页面打包入口文件
 * @auhtor: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/28
 */

require("js/product/list");

require("js/product/brand");

require("js/product/hotrank");

});
define("js/product/list", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
 * 商品列表页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */

require("js/product/filter");

require("js/product/sort-pager");

require("js/product/latest-walk");

require("js/product/product");
});
define("js/product/filter", ["jquery","handlebars","source-map"], function(require, exports, module){
/**
 * 商品筛选逻辑
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/4
 */

var $ = require("jquery"),
    Handlebars = require("handlebars");

var checkUnicode = {
    unchecked: '&#xe613;',
    checked: '&#xe633;'
},
moreUnicode = {
    up: '&#xe610;',
    down: '&#xe600;'
};

//品牌相关变量
var $brandDefault = $('.brand .default'),
    $brandPanel = $('.brand .brand-panel'),
    $brandAttrs = $brandPanel.find('.attr'),
    $brandMore = $('#brand-more'),
    $brandMulti = $('#brand-multi');

var $brandMoreTxt, $brandMoreIcon;

//价格相关变量
var $udPrice = $('.ud-price-range'),
    interReg = /^\d+$/,
    $limit, $min, $max, $btn;

//分类相关变量
var $sortSub = $('.sort-sub-wrap');

//高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
    $seniorAttrWrap = $('.senior-attr-wrap');

var seniorHoverTime, hoveredIndex;

// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
    sizeCache = {}, // 缓存一下尺寸信息
    $sizeWrap = $('.filter-box .size');

sizeTmpl = Handlebars.compile(sizeTmpl);

//清除checkbox选中状态
function clearChecked($checkbox) {
    $checkbox.removeClass('checked').html(checkUnicode.unchecked);
}

//显示更多品牌面板
function brandShowMore() {
    $brandDefault.addClass('hide');
    $brandPanel.removeClass('hide');
}

//隐藏更多品牌面板
function brandHideMore() {
    $brandPanel.addClass('hide');
    $brandDefault.removeClass('hide');
}

//url构造&跳转
function uriLoc(attr, val) {
    var qs = window.queryString(),
        newHref;

    qs[attr] = val;
    newHref = '?' + decodeURIComponent($.param(qs));
    window.location.href = newHref;
}

//隐藏高级选项面板
function hideSeniorPanel(index) {
    $seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
    $seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
    hoveredIndex = -1;
}

//屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
    return false;
});

//【分类】
$('.sort-pre').on('click', 'li', function() {
    var $this = $(this),
        index = $this.index(),
        id = $this.data('id');

    if ($this.hasClass('active')) {

        // 选中时,再次点击取消选中
        $this.removeClass('active');
        $sortSub.children(':eq(' + index + ')').addClass('hide');
        $sizeWrap.addClass('hide');
        return;
    }

    $this.siblings('.active').removeClass('active');
    $this.addClass('active');

    $sortSub.children(':not(.hide)').addClass('hide');
    $sortSub.children(':eq(' + index + ')').removeClass('hide');

    if (!$sizeWrap.data('load')) {
        if (sizeCache[id]) {
            $sizeWrap.find('.attr-content').html(sizeCache[id]);
            $sizeWrap.removeClass('hide');
        } else {
            $.ajax({
                url: '/product/search/sortSize',
                data: {
                    msort: id
                }
            }).then(function(res) {
                if ($.type(res) === 'array' && res.length) {
                    sizeCache[id] = sizeTmpl({
                        size: res
                    });
                    $sizeWrap.find('.attr-content').html(sizeCache[id]);
                    $sizeWrap.removeClass('hide');
                } else {
                    $sizeWrap.addClass('hide');
                }
            });
        }
    }
});

//【品牌】
if ($brandMore.length > 0) {
    $brandMoreTxt = $brandMore.children('em');
    $brandMoreIcon = $brandMore.children('.iconfont');
}

//【品牌】多选
$brandMulti.click(function() {
    if ($brandPanel.css('display') === 'none') {

        //显示品牌面板
        $brandMore.trigger('click');
    }

    brandShowMore();
    $brandPanel.removeClass('hide').addClass('multi'); //显示出checkbox
    $(this).addClass('hide');

    //隐藏更多按钮
    $brandMore.addClass('hide');
});

//【品牌】更多
$brandMore.click(function() {
    var $this = $(this);

    if ($this.hasClass('more')) {
        brandHideMore();

        $brandMoreTxt.text('更多');
        $brandMoreIcon.html(moreUnicode.down);
    } else {
        brandShowMore();

        $brandMoreTxt.text('收起');
        $brandMoreIcon.html(moreUnicode.up);
    }

    $(this).toggleClass('more');
});

//【品牌】索引
$('.brands-index').on('mouseenter', 'span', function() {
    var $this = $(this),
        index = $this.data('index');

    if ($this.hasClass('hover')) {
        return;
    }

    $this.siblings('span.hover').removeClass('hover');
    $this.addClass('hover');

    if ($this.index() === 0) {

        //全部
        $brandAttrs.removeClass('hide');
    } else {
        $brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
    }
});

//【品牌】搜索
$('#brand-search-input').keyup(function() {
    var val = $(this).val().toLowerCase();

    if (val === '') {
        $brandAttrs.removeClass('hide');
    } else {
        $brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
    }
});

//【品牌】多选确定
$('#brand-multi-ok').click(function() {
    var val = [];

    if ($(this).hasClass('dis')) {
        return;
    }

    $brandPanel.find('.checked').each(function() {
        val.push($(this).data('id'));
    });

    uriLoc('brand', val.join(','));
});

//【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
    var $panel = $(this).closest('.multi');

    if ($panel.hasClass('brand-panel')) {

        $brandMulti.removeClass('hide'); //显示多选按钮
        $brandMore.trigger('click');

        //显示出更多按钮
        $brandMore.removeClass('hide');
    }

    $panel.addClass('hide').removeClass('multi');
    brandHideMore();
    clearChecked($panel.find('.checkbox.checked')); //清除选中状态
});

//【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
    var $this = $(this),
        $check = $this.find('.checkbox'),
        $btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');

    $check.toggleClass('checked');

    if ($check.hasClass('checked')) {
        $check.html(checkUnicode.checked);
    } else {
        $check.html(checkUnicode.unchecked);
    }

    //更新按钮状态
    if ($check.hasClass('checked') ||
        $this.siblings('.attr').find('.checked').length > 0) {
        $btnOk.removeClass('dis');
    } else {
        $btnOk.addClass('dis');
    }
});

//【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
    if ($(this).closest('.multi').length > 0) {
        e.preventDefault();
    }
});

// 已选中的条件,点击不刷新
$('.filter-box').on('click', 'li.checked, a.checked', function(e) {
    e.preventDefault();
});

//【价格】用户定义价格处理
if ($udPrice.length > 0) {
    $limit = $udPrice.find('.limit');
    $min = $limit.filter('.min');
    $max = $limit.filter('.max');
    $btn = $udPrice.find('.price-sure');

    //【价格】输入
    $limit.keyup(function() {
        var thisPrice = $.trim($(this).val()),
            isPriInt = interReg.test(thisPrice),
            intPrice,
            min,
            max;

        if (!isPriInt) {
            intPrice = parseInt(thisPrice, 10);
            $(this).val(isNaN(intPrice) ? '' : intPrice);
        }

        min = $.trim($min.val());
        max = $.trim($max.val());

        if (min !== '' || max !== '') {
            $btn.removeClass('hide');
        } else {
            $btn.addClass('hide');
        }
    });

    //【价格】多项查询
    $btn.click(function() {
        var min = $.trim($min.val()),
            max = $.trim($max.val()),
            tmp;

        //对于min大于max的情况,交换位置
        if (min !== '' && max !== '' && +min > +max) {
            tmp = max;
            max = min;
            min = tmp;
        }

        uriLoc('price', min + ',' + max);
    });
}

//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
    var $this = $(this);
    var index = $this.index();

    if ($this.hasClass('no-sub')) {
        return;
    }
    $this.addClass('hover').siblings().removeClass('hover');

    $seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
    var $this = $(this),
        index = $this.index();

    if ($this.hasClass('no-sub')) {
        return;
    }

    hoveredIndex = index;

    seniorHoverTime = setTimeout(function() {
        hideSeniorPanel();
    }, 100);
});

//【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
    $(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
    var $btn = $(this),
        $sub = $btn.closest('.senior-sub'),
        val = [];

    if ($btn.hasClass('dis')) {
        return;
    }

    $sub.find('span.checked').each(function() {
        val.push($(this).data('id'));
    });

    uriLoc($sub.data('attr'), val.join(','));
}).on('mouseenter', function() {
    clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
    hideSeniorPanel();
});

});
define("js/product/sort-pager", ["jquery"], function(require, exports, module){
/**
 * 筛选页和列表页操作banner中的每页N个商品选择逻辑
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/4
 */

var $ = require("jquery");

var $countPerPage = $('#count-per-page'),
    $countChose = $countPerPage.next('ul');

var SLIDETIME = 200;

$(document).click(function(e) {
    if ($(e.target).closest('.page-count').length > 0) {
        return;
    }

    $countChose && $countChose.slideUp(SLIDETIME);
});

$countPerPage.click(function() {
    if ($countChose.css('display') === 'none') {
        $countChose.slideDown(SLIDETIME);
    } else {
        $countChose.slideUp(SLIDETIME);
    }
});
});
define("js/product/latest-walk", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
 * 最近浏览取接口渲染模板
 * @author: xuqi<qi.xu@yoho.cn>
 8 @date: 2016/1/20
 */

var $ = require("jquery");
var Handlebars = require("handlebars");
var lazyLoad = require("lazyload");

var $latestWalkCount = $('#latest-walk-count');

(function() {
    var tpl;

    if ($latestWalkCount.length === 0) {
        return;
    }

    tpl = Handlebars.compile($('#latest-walk-tpl').html());

    $.ajax({
        url: 'http://itemapi.yohobuy.com/item/item/recentreview',
        dataType: 'jsonp',
        data: {
            limit: $latestWalkCount.val()
        },
        success: function(data) {
            var latestWalk = [],
                res, i, cur;

            if (data.code === 200) {
                res = data.data;

                //若无最近浏览,请隐藏容器
                if (res.length === 0) {
                    $('.latest-walk').addClass('hide');
                    return;
                }
                for (i = 0; i < res.length; i++) {
                    cur = res[i];

                    latestWalk.push({
                        href: cur.url,
                        img: cur.pic_url,
                        name: cur.product_name,
                        salePrice: cur.price,
                        marketPrice: cur.market_price
                    });
                }

                if (latestWalk.length > 0) {
                    $('#latest-walk-goods').html(tpl({
                        latestWalk: latestWalk
                    }));

                    lazyLoad($('#latest-walk-goods .lazy'));
                }
            }
        }
    });
}());
});
define("js/product/product", ["jquery","lazyload"], function(require, exports, module){
/**
 *Description: 商品列表页
 *Author: chenglong.wang@yoho.cn
 *Date: 2015/12/2
 */

var $ = require("jquery"),
    lazyLoad = require("lazyload"),
    productEvent = require("js/common/product-event");

var $goodsContainer = $('.goods-container'),
    $goodItem = $goodsContainer.find('.good-info'),
    $goodItemWrapper = $goodsContainer.find('.good-item-wrapper'),
    $goodInfoMain = $goodsContainer.find('.good-info-main'),
    $goodSelectColor = $goodsContainer.find('.good-select-color'),
    $productListNav = $('.product-list-nav'),
    productList;

lazyLoad($('img.lazy'));

/**
 * @description 初始化鼠标移入商品列表弹层效果
 * @num 每列存放商品的个数
 */
exports.init = function(num) {

    productList = null;

    $goodItem.unbind();

    productList = productEvent($goodItem, num);

    /**
     * @description 构造商品颜色列表的html结构
     * @param data 商品颜色的数组,[url: '',src: '']
     * @return json {'colorListStr': '', 'ulNum': ''}
     * */
    function createColorList(data, _from) {
        var colorListStr = '',
            len = data.length,
            row = 4, //每列ul放4个li
            col = Math.ceil(len / row), //需要几**列**ul
            i,
            j,
            index,
            ulNum = 0;

        for (i = 0; i < col; i++) {
            colorListStr += '<ul>';
            for (j = 0; j < row; j++) {
                index = i * row + j;
                if (index === len) {
                    break;
                }
                colorListStr +=
                    '<li>' +
                    '<a target="_blank" href="' + data[i * row + j].url + _from + '">' +
                    '<img src="' + data[i * row + j].src + '" data-cover="' + data[i * row + j].coverImg + '" />' +
                    '</a>' +
                    '</li>';

                if (j === row - 1) {
                    colorListStr += '</ul>';
                    ulNum++;
                }
            }
        }
        if (ulNum < col) {
            colorListStr += '</ul>';
        }
        return {
            colorListStr: colorListStr,
            ulNum: col
        };
    }

    function removeHtmlFn() {
        $goodInfoMain.html('');
        $goodSelectColor.html('');
        $goodItemWrapper.css({
            display: 'none'
        });
    }

    productList.addHandler('MouseEnter', function(event) {
        var itemMr = 10, //list的右边距
            itemMb = 35, //list的下边距
            ulStr = '',
            ulNum,
            wrapperWidth,
            diffWidth,
            wrapperX,
            wrapperY,
            wrapperPl, //鼠标移入时弹层的左内边距
            wrapperPt, //鼠标移入时弹层的上内边距
            containerPt, //商品列表容器的上内边距
            _from = event.target.attr('data-from') || '';

        $.ajax({
            type: 'POST',
            url: '/product/list/getProductPic',
            dataType: 'jsonp',
            jsonp: 'callback',
            data: {
                skn: event.target.attr('data-skn')
            }
        }).then(function(res) {
            var data = res.data,
                colorList = createColorList(data.pics, _from);

            removeHtmlFn();

            ulStr = colorList.colorListStr; //ajax请求的颜色列表
            ulNum = colorList.ulNum;//ajax请求的颜色的数量

            $goodInfoMain.append(event.targetDuplicate);
            $goodSelectColor.append($(ulStr));

            if (data.isFavorite) {
                $goodInfoMain.find('.col-btn').addClass('coled');
            } else {
                $goodInfoMain.find('.col-btn').removeClass('coled');
            }

            wrapperPl = $goodItemWrapper.css('paddingLeft');
            wrapperPt = $goodItemWrapper.css('paddingTop');
            containerPt = $goodsContainer.css('paddingTop');

            wrapperWidth = 10 + (15 + 50) * ulNum + event.targetWidth;

            //wrapperWidth = $goodItemWrapper.width();

            wrapperX = (event.targetX - 1) * (event.targetWidth + itemMr) - (parseInt(wrapperPl) + 1);
            wrapperY = (event.targetY - 1) *
            (event.targetHeight + itemMb) + parseInt(containerPt) - (parseInt(wrapperPt) + 1);

            //todo
            //event.offsetR表示当前列表距离浏览器右侧边缘的距离
            diffWidth = event.offsetR - ((15 + 50) * ulNum + 25);

            if (diffWidth <= 0) {
                wrapperX = wrapperX + diffWidth - 25;
            }
            $goodItemWrapper.css({
                width: wrapperWidth,
                left: wrapperX,
                top: wrapperY,
                display: 'inline-block'
            });

            // 鼠标悬浮获取到商品信息后显示第一张图片
            if (data.pics[0] && data.pics[0].src) {
                $goodInfoMain.find('.good-thumb img').attr('src', data.pics[0].src);
            }
        });
    });

    $goodItemWrapper.mouseleave(function() {

        removeHtmlFn();
    });

};

//鼠标放在颜色列表上效果
$(document).on('hover', '.good-select-color li', function() {
    var coverImg = $(this).find('img').attr('data-cover'),
        $coverImg = $(this).closest('.good-item-wrapper').find('.good-detail-img').find('img');

    $coverImg.attr('src', coverImg);
});

$goodInfoMain.on('click', '.col-btn', function() {
    var $this = $(this);

    $.ajax({
        type: 'POST',
        url: '/product/list/changeFavorite',
        dataType: 'jsonp',
        data: {
            skn: $this.closest('.good-info').data('skn'),
            isFavorite: $this.hasClass('coled')
        }
    }).then(function(res) {
        if (res.code === 200) {
            $this.toggleClass('coled');
        } else if (res.code === 403) {
            location.href = 'http://www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
        }
    });
});

// 左侧导航
$productListNav.find('h3').click(function(event) {
    var $this = $(this).closest('.product-list-nav');

    if ($this.hasClass('active')) {

        $this.find('.sort-child-list').stop(true, true).slideUp();

    } else {

        $this.find('.sort-child-list').stop(true, true).slideDown();
    }

    $this.toggleClass('active');
});

});
define("js/common/product-event", ["jquery"], function(require, exports, module){
/**
 *Description: 商品自定义事件
 *Author: chenglong.wang@yoho.cn
 *Date: 2015/12/3
 */

var $ = require("jquery");

function ProductEvent() {

    this.handlers = {};

}

ProductEvent.prototype = {

    constructor: ProductEvent,

    addHandler: function(type, handler) {
        if (typeof this.handlers[type] === 'undefined') {
            this.handlers[type] = [];
        }
        this.handlers[type].push(handler);
    },

    fire: function(event) {
        var handlers,
            i;

        if (!event.target) {

            event.target = this;
        }
        if (this.handlers[event.type] instanceof Array) {
            handlers = this.handlers[event.type];
            for (i = 0; i < handlers.length; i++) {
                handlers[i](event);
            }
        }
    },

    removeHandler: function(type, handler) {
        var handlers,
            i;

        if (this.handlers[type] instanceof Array) {
            handlers = this.handlers[type];
            for (i = 0; i < handlers.length; i++) {
                if (handlers[i] === handler) {
                    break;
                }
            }
            handlers.splice(i, 1);
        }
    }
};

module.exports = function($o, rowWidth) {

    var pMouseHover = new ProductEvent();

    var targetWidth = $o.eq(0).width(),
        targetHeight = $o.eq(0).height(),
        winW = $(window).width();

    function handleEvent(event) {
        var $target,
            targetX = 0,
            targetY = 0,
            rowW = rowWidth,
            activeIndex = 0,
            $targetDuplicate = '',
            offsetL = 0,
            offsetR = 0;


        switch (event.type) {
            case 'mouseenter':

                $target = $(this);
                $targetDuplicate = $target.clone();
                activeIndex = $target.index() + 1;
                targetX = (activeIndex % rowW) === 0 ? rowW : activeIndex % rowW;
                targetY = Math.ceil(activeIndex / rowW);
                offsetL = $target.offset().left;
                offsetR = winW - (offsetL + targetWidth);

                pMouseHover.fire({
                    type: 'MouseEnter',
                    target: $target,
                    targetWidth: targetWidth,
                    targetHeight: targetHeight,
                    targetX: targetX,
                    targetY: targetY,
                    rowWidth: rowW,
                    activeIndex: activeIndex,
                    targetDuplicate: $targetDuplicate,
                    offsetL: offsetL,
                    offsetR: offsetR
                });
                break;
            case 'mouseleave':
                pMouseHover.fire({
                    type: 'MouseLeave'
                });
                break;
        }
    }

    $o.bind('mouseenter', handleEvent);

    return pMouseHover;
};
});
define("js/product/brand", ["jquery"], function(require, exports, module){
/**
 * 品牌页面
 * @auhtor: bikai<kai.bi@yoho.cn>
 * @date: 2016/1/21
 */

var $ = require("jquery");

$('#brand-favor').on('click', function() {
    var $this = $(this),
        uid = window.getUid();

    $.ajax({
        type: 'post',
        url: '/product/index/favoriteBrand',
        data: {
            uid: uid,
            brandId: $this.data('id')
        }
    }).then(function(res) {
        if (res.code === 200) {
            if (res.message === 'add') {
                $this.find('i').addClass('coled');
            } else {
                $this.find('i').removeClass('coled');
            }
        } else if (res.code === 403) {
            location.href = 'http://www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
        }
    });
});

});
define("js/product/hotrank", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
 * 首页
 * @author: liuyue<yue.liu@yoho.cn>
 * @date: 2015/12/17
 */

var $ = require("jquery"),
    Handlebars = require("handlebars"),
    lazyLoad = require("lazyload");

require("js/common/slider");
require("js/common/logo-brand");

lazyLoad($('img.lazy'));
$('.slide-container').slider();
$('.logo-brand').logoBrand({
    showNum: 10,
    url: $('.logo-brand').data('url')
});

/*
 * 一周热卖
 */
(function($) {
    var floatlayer = $('.hot-week').find('.floatlayer'),
        sid = $('.hot-cate').find('li').eq(0).data('sid'),
        weekOffsetTop,
        source,
        template,
        page = 1,
        hotCateW = 0,
        weekEnd = false;

    source = '\{{# list}}' +
        '<div class="good-info">' +
            '<div class="item-img">' +
                '<a class="good-thumb" target="_blank" href="\{{url}}">' +
                    '<img class="lazy" data-original="\{{thumb}}">' +
                '</a>' +
            '</div>' +
            '<div class="good-detail-text">' +
                '<a target="_blank" href="{{url}}">{{name}}</a>' +
                '<p class="price">' +
                    '{{# marketPrice}}<span class="market-price">¥{{.}}</span>{{/ marketPrice}} ' +
                    '<span class="sale-price{{#unless marketPrice}}prime-cost{{/unless}}">' +
                    '¥{{salePrice}}</span>' +
                '</p>' +
            '</div>' +
        '</div>' +
        '{{/ list}}';

    //监听滚动事件,控制浮层样式及下拉加载更多
    $(window).on('scroll', function() {
        var maxH = weekOffsetTop + $('.hot-week').outerHeight(),
            sid;

        //热卖右侧浮动导航位置
        weekOffsetTop = $('.hot-week').offset().top;
        if ($(this).scrollTop() >= weekOffsetTop - $(window).height() / 2) {
            if (floatlayer.offset().top + floatlayer.outerHeight() >= maxH) {
                floatlayer.css({
                    position: 'absolute',
                    marginTop: 0,
                    top: $('.hot-week').outerHeight() - floatlayer.outerHeight()
                });
            } else {
                floatlayer.css({
                    marginTop: -floatlayer.height() / 2
                }).stop().animate({
                    opacity: 1
                }, 200, function() {
                    floatlayer.show();
                });
            }

        } else {
            floatlayer.stop().animate({
                opacity: 0
            }, 200, function() {
                floatlayer.hide();
            });
        }

        if (floatlayer.offset().top >= $(this).scrollTop() + ($(window).height() - floatlayer.outerHeight()) / 2) {
            floatlayer.css({
                position: 'fixed',
                marginTop: -floatlayer.height() / 2,
                top: '50%'
            });
        }

        //下拉加载
        if ($(this).scrollTop() >= weekOffsetTop + $('.hot-week').height() - $(window).height()) {
            if (!weekEnd) {
                sid = $('.hot-cate').find('li.current').data('sid');
                page++;
                weekEnd = true; //防止多次请求
                weekAjax(sid, page);
            }
        }

    });

    //热卖横导航及竖导航的超出显示控制
    $('.hot-cate').find('li').each(function(i) {
        var maxW = $('.hot-cate').width();

        if (hotCateW <= maxW) {
            hotCateW = hotCateW + $(this).width();
            if (hotCateW >= maxW) {
                $('.floatlayer').find('li').eq(i).hide().nextAll().hide();
            }
        }

    });

    //热卖横导航点击事件处理
    $('.hot-cate').on('click', 'li', function() {
        var nowIndex = $(this).index(),
            sid = $(this).data('sid');

        if ($(this).hasClass('current')) {
            return;
        }

        //处理current样式
        $(this).addClass('current').siblings().removeClass('current');
        $('.floatlayer').find('li').removeClass('current').eq(nowIndex).addClass('current');

        //返回热卖顶部,110为floor-header所占高度
        $('body,html').stop().animate({
            scrollTop: weekOffsetTop - 110
        }, 500);

        //调用ajax请求函数,重置page,weekEnd
        weekAjax(sid);
        page = 1;
    });

    //热卖右侧悬浮导航点击事件处理
    $('.floatlayer').on('click', 'li', function() {
        var nowIndex = $(this).index();

        if ($(this).hasClass('current')) {
            return;
        }

        $('.hot-cate').find('li').eq(nowIndex).trigger('click');

        //处理current样式
        $(this).addClass('current').siblings().removeClass('current');
        $('.hot-cate').find('li').removeClass('current').eq(nowIndex).addClass('current');
    });

    /*
     * 热卖内容ajax请求
     * param: sid(ajax请求的id), page(ajax请求的页码)
     */
    function weekAjax(sid, page) {
        var param = {};

        if (page) {
            param = {
                sid: sid,
                page: page
            };
        } else {
            param = {
                sid: sid
            };
        }
        $.ajax({
            type: 'GET',
            dataType: 'json',
            url: '/product/index/getdata',
            data: param,
            success: function(res) {
                var data;

                if (res.code === 200) {
                    data = {
                        list: res.data
                    };

                    //mustache渲染数据,并替换原内容
                    template = Handlebars.compile(source);
                    if (page) {
                        $('.hot-week-list').append(template(data));
                        floatlayer.css({
                            position: 'fixed',
                            marginTop: -floatlayer.height() / 2,
                            top: '50%'
                        });
                    } else {
                        $('.hot-week-list').html(template(data));
                    }

                    lazyLoad($('img.lazy'));
                    weekEnd = false;
                }
            }
        });
    }

    //热卖中导航current类处理
    $('.hot-cate').find('li').eq(0).addClass('current');
    $('.floatlayer').find('li').eq(0).addClass('current');
})($);

});
define("js/common/slider", ["jquery","lazyload"], function(require, exports, module){
/**
 * 首页banner轮播
 * @author: liuyue(yue.liu@yoho.cn)
 * @date: 2015/12/04
 */

var $ = require("jquery"),
    lazyLoad = require("lazyload");

(function($) {
    var Slider = function(element, options) {
        this.$element = $(element);
        this.options = $.extend({}, $.fn.slider.defaults, options);
        this.bigItem = this.$element.find('.slide-wrapper').find('li');
        this.smallItem = null;
        this.len = this.bigItem.size();
        this.index = 0;
        this.timer = null;
        this.init();
    };

    Slider.prototype = {
        init: function() {
            if (!this.$element) {
                return;
            }

            if (this.len <= 1) {
                lazyLoad(this.$element.find('img.lazy'));
                return;
            }
            if (!!this.options.pagination) {
                this.smallItem = $(this.options.pagination).find('li');
            } else {
                this._createPage();
            }

            if (this.options.orient) {
                this._createOrient();
            }
            this._slideShow();
            this._bindEvent();
            this._autoplay();
        },
        _createOrient: function() {

            var orientHtml = '<div class="slide-switch">' +
                    '<a class="prev" href="javascript:;"><span class="iconfont">&#xe60c;</span></a>' +
                    '<a class="next" href="javascript:;"><span class="iconfont">&#xe60b;</span></a>' +
                '</div>';

            if (this.$element.find('.slide-switch').length > 0) {
                return;
            }

            this.$element.append(orientHtml);
        },
        _createPage: function() {
            var pageHtml = '<div class="slide-pagination"><div class="slide-pagination-inner">' +
                            '<div class="slide-shade"></div><div class="slide-pagination-last">',
                i = 0;

            if (this.len <= 1) {
                return;
            }
            for (i = 0; i < this.len; i++) {
                pageHtml += '<span></span>';
            }
            pageHtml += '</div></div></div>';
            this.$element.append($(pageHtml));
            this.smallItem = this.$element.find('.slide-pagination-inner span');
        },
        _bindEvent: function() {
            var that = this;

            this.$element.find('.slide-switch').on('click', '.next', function() {
                that._nextSlide();
                clearInterval(that.timer);
                that.timer = setInterval(function() {
                    that._nextSlide();
                }, that.options.time);
            }).on('click', '.prev', function() {
                that._prevSlide();
                clearInterval(that.timer);
                that.timer = setInterval(function() {
                    that._nextSlide();
                }, that.options.time);
            });

            this.smallItem.on('mouseenter', function() {
                that.index = $(this).index();
                clearInterval(that.timer);
                that._slideShow();
            }).on('mouseleave', function() {
                that._autoplay();
            });

            this.$element.on('mouseenter', function() {
                $(this).find('.slide-switch').addClass('show');
            }).on('mouseleave', function() {
                $(this).find('.slide-switch').removeClass('show');
            });
        },
        _nextSlide: function() {
            if (this.index === this.len - 1) {
                this.index = 0;
            } else {
                this.index++;
            }
            this._slideShow();
        },
        _prevSlide: function() {
            if (this.index === 0) {
                this.index = this.len - 1;
            } else {
                this.index--;
            }
            this._slideShow();
        },
        _slideShow: function() {
            var $img = this.bigItem.eq(this.index).find('img.lazy');

            //未加载图片的及时显示
            if ($img.attr('src') !== $img.data('original')) {
                lazyLoad($img, {
                    event: 'sporty'
                });
                $img.trigger('sporty');
            }

            this.smallItem.eq(this.index).addClass('focus').siblings().removeClass('focus');
            this.bigItem.eq(this.index).show().stop().animate({
                opacity: 1
            }, function() {

                //修正IE下切换时文字会重叠的问题
                $(this).find('.slide-tips > p').removeClass('hide');
            }).siblings().stop().animate({
                opacity: 0
            }, function() {
                $(this).hide().find('.slide-tips > p').addClass('hide');
            });
        },
        _autoplay: function() {
            var that = this;

            clearInterval(this.timer);
            this.timer = setInterval(function() {
                that._nextSlide();
            }, this.options.time);
        }
    };
    $.fn.slider = function(option) {
        return this.each(function() {
            var $this = $(this),
                data = $this.data('Slider'),
                options = typeof option === 'object' && option;

            if (!data) {
                $this.data('Slider', (data = new Slider(this, options)));
            }
            if (typeof option === 'string') {
                data[option]();
            }
        });
    };
    $.fn.slider.Constructor = Slider;
    $.fn.slider.defaults = {
        time: 5000,
        orient: true, //左右切换箭头的显示
        pagination: null
    };
})($);
});
define("js/common/logo-brand", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
/**
 * 首页优选品牌js
 * @author: liuyue(yue.liu@yoho.cn)
 * @date: 2015/12/08
 */

var $ = require("jquery"),
    Handlebars = require("handlebars"),
    lazyLoad = require("lazyload");

(function($) {
    var LogoBrand = function(element, options) {
        this.$element = $(element);
        this.options = $.extend({}, $.fn.logoBrand.defaults, options);

        this.init();
    };

    LogoBrand.prototype = {
        init: function() {
            this.$element.addClass('logos-' + this.options.showNum);
            this._sendRequest();
        },
        _createHelper: function() {
            var showNum = this.options.showNum;

            Handlebars.registerHelper('brandList', function(items, options) {
                var out = '<ul>',
                    i = 0,
                    item = null,
                    fillNum = 0;

                //不是每页显示个数的倍数,填充数据
                if (items.length % showNum !== 0) {
                    fillNum = showNum - (items.length % showNum);
                    for (i = 0; i < fillNum; i++) {
                        items.push({
                            href: 'javascript:;',
                            img: ''
                        });
                    }
                }

                for (i = 0; i < items.length; i++) {
                    item = options.fn(items[i]);

                    if (i % showNum === 5 || i === 5) {

                        //插入切换按钮的位置
                        out = out + '<li class="logo-brand-switch" data-page="' + Math.floor(i / showNum) + '">' +
                                    '<a class="prev iconfont" href="javascript:;">&#xe60f;</a>' +
                                    '<a class="next iconfont" href="javascript:;">&#xe60e;</a></li>' +
                                    '<li data-page="' + Math.floor(i / showNum) + '">' + item + '</li>';
                    } else if (i !== 0 && i % showNum === 0) {

                        //插入more的位置,more占的是下一页第一个brand的位置,所以page是i/17
                        out = out + '<li class="brand-more" data-page="' + Math.floor(i / (showNum + 1)) + '">' +
                                    '<a href="javascript:;" target="_blank">MORE ></a></li>' +
                                    '<li data-page="' + Math.floor(i / showNum) + '">' + item + '</li>';
                    } else {
                        out = out + '<li data-page="' + Math.floor(i / showNum) + '">' + item + '</li>';
                    }
                }

                //加上最后一个more, more占的是下一页第一个brand的位置,这里已经循环不到brand,所以加在末尾
                return out + '<li class="brand-more" data-page="' + Math.floor(i / (showNum + 1)) + '">' +
                            '<a href="javascript:;" target="_blank">MORE ></a></li></ul>';

            });
        },
        _sendRequest: function() {
            var that = this;

            $.ajax({
                type: 'GET',
                url: that.options.url,
                dataType: 'json',
                success: function(data) {
                    var brandTpl,
                        brandHtml;

                    if (!data || data.length === 0) {
                        return;
                    }

                    that._createHelper();
                    brandHtml = '\{{#brandList logoBrand}}' +
                        '<a href="\{{href}}" target="_blank"><img class="lazy" data-original="\{{img}}" alt=""></a>' +
                        '\{{/brandList}}';
                    brandTpl = Handlebars.compile(brandHtml);
                    that.$element.html(brandTpl(data));
                    that.$element.find('.brand-more a').attr('href', data.moreBrand);
                    lazyLoad(that.$element.find('img.lazy'));
                    that._bindEvent();
                }
            });
        },
        _brandShow: function(hidePage, showPage) {
            var that = this;

            lazyLoad($('li[data-page=' + showPage + ']').find('img.lazy').trigger('appear'));
            that.$element.find('li[data-page=' + hidePage + ']').find('img').fadeOut('normal', function() {
                that.$element.find('li').hide();
                that.$element.find('li[data-page=' + showPage + ']').show().find('img').fadeIn();
            });
        },
        _bindEvent: function() {
            var that = this;

            that.$element.on('click', '.next', function() {
                var page = $(this).parent().data('page'),
                    nextPage = 0,
                    totalPage = Math.ceil(that.$element.find('li').size() / (that.options.showNum + 2)) - 1;

                if (page === totalPage) {
                    nextPage = 0;
                } else {
                    nextPage = page + 1;
                }
                that._brandShow(page, nextPage);
            });

            that.$element.on('click', '.prev', function() {
                var page = $(this).parent().data('page'),
                    prevPage = 0,
                    totalPage = Math.ceil(that.$element.find('li').size() / (that.options.showNum + 2)) - 1;

                if (page === 0) {
                    prevPage = totalPage;
                } else {
                    prevPage = page - 1;
                }
                that._brandShow(page, prevPage);
            });
        }
    };
    $.fn.logoBrand = function(option) {
        return this.each(function() {
            var $this = $(this),
                data = $this.data('LogoBrand'),
                options = typeof option === 'object' && option;

            if (!data) {
                $this.data('LogoBrand', (data = new LogoBrand(this, options)));
            }
            if (typeof option === 'string') {
                data[option]();
            }
        });
    };
    $.fn.logoBrand.Constructor = LogoBrand;
    $.fn.logoBrand.defaults = {
        showNum: 16,
        url: '/boys/getBrand'
    };
})($);
});
define("js/index/index", ["jquery","lazyload","handlebars","source-map"], function(require, exports, module){
/**
 * 首页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */

var $ = require("jquery"),
    lazyLoad = require("lazyload"),
    homePage = $('.home-page').data('page'),
    brandUrl = $('.logo-brand').data('url');


require("js/common/slider");
require("js/common/slider2");
require("js/common/logo-brand");

require("js/common/accordion");

$(document).on('mouseenter', '.imgopacity a img', function() {
    $(this).css('opacity', 0.8);
});
$(document).on('mouseout', '.imgopacity a img', function() {
    $(this).css('opacity', 1);
});



if ($.inArray(homePage, ['boys','girls','kids','lifestyle']) > -1) {
    require("js/common/new-arrivls")({
        type: homePage,
        url: '/common/getNewArrival',
        count: (homePage === 'boys') || (homePage === 'lifestyle') ? 5 : 4,
        rows: [5,3]
    });
    window.setCookie('_Channel', homePage, {
        domain: '.yohobuy.com',
        path: '/',
        expires: 365
    });
}



lazyLoad($('img.lazy'));
if (homePage === 'boys') {
    $('.slide-container').slider({
        pagination: '.thumb-pagination'
    });
} else {
    $('.center-col').slider();
    $('.slide-container').slider();
}

if (homePage === 'boys') {
    $('.logo-brand').logoBrand({
        url: brandUrl
    });
    $('.img-brand').slider2();
} else {
    $('.logo-brand').logoBrand({
        showNum: 10,
        url: brandUrl
    });
    $('.img-slider-wrapper').slider2();
}



});
define("js/common/slider2", ["jquery"], function(require, exports, module){
/**
 * (品牌优选)图片幻灯片插件
 * @author: wangqing(robin.wang@yoho.cn)
 * @date: 205/7/2
 */
var $ = require("jquery");

(function($) {
    $.fn.slider2 = function(options) {
        function autoplay(index, limit, toright) {
            if (toright === true) {
                $('.next').trigger('click');
                if (index === (limit - 3)) {
                    autoplayrecycle(--index, limit, false);
                } else {
                    autoplayrecycle(++index, limit, true);
                }
            } else {
                $('.prev').trigger('click');
                if (index === 0) {
                    autoplayrecycle(++index, limit, true);
                } else {
                    autoplayrecycle(--index, limit, false);
                }
            }
        }

        function autoplayrecycle(index, limit, toright) {
            window.setTimeout(autoplay, $.fn.slider2.defaults.delaytime, index, limit, toright);
        }

        function changePic(index, width, callback) {
            var offersetleft = -(index * width);

            $('.img-list')
                .animate({
                    'margin-left': offersetleft + 'px'
                }, 'slow', callback);

        }
        $.fn.slider2.defaults = {
            index: 0,
            shownum: 3,
            autoplay: false,
            delaytime: 3000
        };
        return this.each(function() {
            var opts = $.extend({}, $.fn.slider2.defaults, options);
            var mr = parseInt($('.img-item').css('margin-right'));
            var $banneritems = $('.img-item');
            var bannerarr = [];
            var _width = $banneritems.outerWidth() + mr,
                _size = $banneritems.length,
                j = 0;

            if (_size <= 3) {
                $(this).find('.img-brand-switch').hide();
                return;
            }
            for (j = 0; j < $banneritems.length; j++) {
                bannerarr.push($banneritems[j]);
            }
            _size = bannerarr.length;
            $(this).find('.img-list').css({
                width: (_width * _size)
            });
            $(this).find('.next').on('click', function(e) {
                var i = 0,
                    _obj = null;

                e.preventDefault();

                changePic(3, _width, function() {
                    for (i = 0; i < 3; i++) {
                        _obj = bannerarr.shift();

                        $('.img-item').parent().append(_obj.outerHTML);
                        bannerarr.push(_obj);
                    }
                    $('.img-item').first().remove();
                    $('.img-item').first().remove();
                    $('.img-item').first().remove();
                    $('.img-list').css({
                        'margin-left': '0'
                    });
                });
            });
            $(this).find('.prev').on('click', function(e) {
                var i = 0,
                    _obj = null,
                    offersetleft = '';

                e.preventDefault();
                for (i = 0; i < 3; i++) {
                    _obj = bannerarr.pop();

                    $('.img-item').parent().prepend(_obj.outerHTML);
                    bannerarr.unshift(_obj);
                }
                offersetleft = 3 * _width;
                $('.img-item').last().remove();
                $('.img-item').last().remove();
                $('.img-item').last().remove();
                $('.img-list').css({
                    'margin-left': -offersetleft + 'px'
                });
                changePic(0, _width);
            });
            if (opts.autoplay === true) {
                autoplayrecycle(opts.index, _size, true);
            }
        });

    };

}($));
});
define("js/common/accordion", ["jquery"], function(require, exports, module){
var Slide = require("js/common/yohoui/YH.slide");
var $ = require("jquery");

var $contain = $('.slide-accordion');
var $item = $contain.find('li');

var $width = $item.width();
var $spn = parseInt($('.home-page').width()) === 1150 ? (120 + 5) : (102 + 5);
var slide;

function switchfun(to) {
    $item.each(function(index) {
        $(this).css('zIndex', index);
        if (index <= to) {
            $(this).stop().animate({
                left: index * $spn
            }, 400);
        } else {
            $(this).stop().animate({
                left: (to) * $spn + $width + $spn * (index - to - 1)
            }, 400);
        }
    });
}

switchfun(0);

slide = new Slide({
    length: 5,
    loop: false,
    auto: false,
    timeout: 2,
    index: 0
});

slide.on('change', function(data) {
    switchfun(data.to);
});

$item.mouseover(function() {
    slide.go($(this).index());
});

slide.init();
});
define("js/common/yohoui/YH.slide", [], function(require, exports, module){
var me = require("js/common/yohoui/YH.base");

var slide = function(options) {
    this.__lastTime = null;
    this.__isStop = false;
    options = me.extend(this.defaults, options);
    slide.superclass.constructor.call(this, options);
};

me.inherit(slide, me.assembly);

slide.prototype.oninit = function() {
    var __self = this,
        _o = __self.options;

    if (_o.auto) {
        __self.play();
    }
    __self.go(_o.index);
    return this;
};

slide.prototype.go = function(_to, _from) {
    var __self = this,
        _o = __self.options;
    var _direction,_loop,_current,_index,_originalto,o,key,_e;

    if (__self.__lastTime) {
        clearTimeout(__self.__lastTime);
        __self.__lastTime = null;
    }
    _from = 'undefined' === typeof _from ? _o.index : _from;
    _direction = _to === _from ? 0 : _to > _from ? 1 : -1;
    _loop = _o.loop, _index = _o.length - 1, _originalto = _to;
    if (_loop) {
        if (_to > _index) {
            _to = _to - _index - 1;
        } else {
            if (0 > _to) {
                _to = _to + _index + 1;
            } else {
                _to = _to;
            }
        }
    } else {
        if (_to > _index) {
            _to = _index;
        } else {
            if (0 > _to) {
                _to = 0;
            } else {
                _to = _to;
            }
        }
    }
    _current = _o.index = _to;

    o = {
        from: _from,
        to: _to,
        originalto: _originalto,
        direction: _direction
    };

    for (key in __self.registerEvent) {
        if (__self.registerEvent[key].length > 0) {
            for (_e in __self.registerEvent[key]) {
                if (__self.registerEvent[key].hasOwnProperty(_e)) {
                    __self.registerEvent[key][_e](o);
                }
            }
        }
    }

    if (_current !== _index || _to) {
        if (!__self.__isStop && _o.auto) {
            __self.play();
        }
    } else {
        if (__self.__lastTime) {
            clearTimeout(__self.__lastTime);
        }
    }
};

slide.prototype.play = function() {
    var __self = this,
        _o = __self.options;

    __self.__lastTime = setTimeout(function() {
        __self.next();
    }, 1000 * _o.timeout);
    return this;
};

slide.prototype.next = function() {
    var __self = this,
    _o = __self.options;
    var _from = _o.index;
    var _to = _from + _o.step;

    __self.go(_to, _from);
};

slide.prototype.prev = function() {
    var __self = this,
        _o = __self.options;
    var _from = _o.index;
    var _to = _from - _o.step;

    __self.go(_to, _from);
};

slide.prototype.pause = function() {
    var __self = this;

    if (__self.__lastTime) {
        clearTimeout(__self.__lastTime);
    }
    __self.__isStop = true;
};

slide.prototype.resume = function() {
    var __self = this;

    __self.__isStop = false;
    __self.play();
};

slide.prototype.defaults = {
    index: 0,
    timeout: 5,
    step: 1,
    per: 1,
    auto: false,
    loop: false
};

module.exports = slide;
});
define("js/common/yohoui/YH.base", [], function(require, exports, module){
var assembly;
var classtype = {
        '[object Array]': 'array',
        '[object Boolean]': 'boolean',
        '[object Date]': 'date',
        '[object Function]': 'function',
        '[object Number]': 'number',
        '[object Object]': 'object',
        '[object RegExp]': 'regexp',
        '[object String]': 'string'
    };
var me = {
    __Index: 0,
    list: [],
    get: function(id) {
        return id === undefined ? this.list : this.list[id];
    },
    fn: function() { },
    inherit: function(childClass, parentClass) {
        var Constructor = me.fn;

        Constructor.prototype = parentClass.prototype;
        childClass.prototype = new Constructor();

        childClass.prototype.constructor = childClass;
        childClass.superclass = parentClass.prototype;

        if (childClass.prototype.constructor === Object.prototype.constructor) {
            childClass.prototype.constructor = parentClass;
        }
    },
    extend: function(obj, newProperties) {
        var key;

        for (key in newProperties) {
            if (newProperties.hasOwnProperty(key)) {
                obj[key] = newProperties[key];
            }
        }
        return obj;
    },
    copy: function(TargetClass, obj, newProperties) {
        var value,o,key;

        if (typeof obj !== 'object') {
            return obj;
        }
        value = obj.valueOf();
        if (obj !== value) {
            return new obj.constructor(value);
        }
        if (obj instanceof obj.constructor && obj.constructor !== Object) {
            if (TargetClass) {
                o = new TargetClass();
            } else {
                o = me.clone(obj.constructor.prototype);
            }

            for (key in obj) {
                if (TargetClass || obj.hasOwnProperty(key)) {
                    o[key] = obj[key];
                }
            }
        } else {
            o = {};
            for (key in obj) {
                if (o.hasOwnProperty(key)) {
                    o[key] = obj[key];
                }
            }
        }
        if (newProperties) {
            for (key in newProperties) {
                if (o.hasOwnProperty(key)) {
                    o[key] = newProperties[key];
                }
            }
        }

        return o;
    },
    clone: function(obj) {
        me.__cloneFunc.prototype = obj;
        return new me.__cloneFunc();
    },
    __cloneFunc: function() {
    },
    delegate: function(func, scope) {
        var args;

        scope = scope || window;

        if (arguments.length > 2) {
            args = Array.prototype.slice.call(arguments, 2);

            return function() {
                return func.apply(scope, args);
            };
        } else {
            return function() {
                return func.call(scope);
            };
        }
    },
    dom: function($select, classCss) {
        var wrap = $select;
        var name, DOM = {
            wrap: wrap
        },
            els = wrap[0].getElementsByTagName('*'),
            elsLen = els.length;
        var i;

        for (i = 0; i < elsLen; i++) {
            name = els[i].className;
            if (name.indexOf(classCss) > -1) {
                name = name.split(classCss)[1];
            }
            if (name) {
                DOM[name] = wrap.find(els[i]);
            }
        }
        return DOM;
    },

    //模板引擎
    template: function() {
        var result, key, reg,i;
        var args = arguments;

        if (args.length > 0) {
            if (me.isString(args[0])) {
                result = args[0];
                if (args.length === 2 && me.isObject(args[1])) {
                    for (key in args[1]) {
                        if (args[1][key] !== undefined) {
                            reg = new RegExp('({' + key + '})', 'g');

                            result = result.replace(reg, args[1][key]);
                        }
                    }
                } else {
                    for (i = 1; i < args.length; i++) {
                        if (args[i] !== undefined) {
                            reg = new RegExp('({[' + (i - 1) + ']})', 'g');

                            result = result.replace(reg, args[i]);
                        }
                    }
                }
            }
        }
        return result;
    },
    __type: function(obj) {
        return obj == null ? String(obj) : classtype[Object.prototype.toString.call(obj)] || 'object';
    },
    isObject: function(obj) {
        return this.isFunction(obj) || !!(obj && 'object' === typeof obj);
    },
    isFunction: function(obj) {
        return this.__type(obj) === 'function';
    },
    isArray: Array.isArray || function(obj) {
        return this.__type(obj) === 'array';
    },
    isNum: function(obj) {
        return !isNaN(parseFloat(obj)) && isFinite(obj);
    },
    isString: function(obj) {
        return this.__type(obj) === 'string';
    },
    each: function(data, callback, args) {
        var i, len;

        if (me.isArray(data)) {
            for (i = 0, len = data.length; i < len; i++) {
                if (callback.call(data[i], i, data[i], args) === false) {
                    break;
                }
            }
        } else {

            for (i in data) {
                if (callback.call(data[i], i, data[i], args) === false) {
                    break;
                }
            }
        }
    },
    funManager: {
        __loadList: {},
        __loadFun: function(item, callback, win) {

            if (item.methord && me.isFunction(item.methord())) {
                win = win || window;
                item.methord()(item, function() {
                    callback();
                }, win);
            }
        },
        load: function(fns, statechange, win, __index) {
            __index = __index || 0;

            if (fns[__index]) {
                me.funManager.__loadFun(fns[__index], function() {
                    me.funManager.load(fns, statechange, win, __index + 1);
                }, win);
            }
            statechange(__index, win);
        },
        get: function(id) {
            return this.__loadList[id];
        }
    },
    log: function(msg) {
        var console = window.console || {
            log: function() { }
        };

        console.log(msg);
    },
    Event: {
        mousewheel: function(e) {
            var _eoe = e.originalEvent;
            var _de = _eoe.detail ? _eoe.detail * -1 : _eoe.wheelDelta / 40;
            var _direction = _de < 0 ? -1 : 1;

            return {
                direction: _direction,
                unit: _de
            };
        },
        __: function(_e, el, event, handle) {
            var key;

            for (key in _e) {
                if (window[_e[key].validator]) {
                    el[_e[key].validator](_e[key].prefix + event, handle, false);
                    break;
                }
            }
        },
        add: function(el, event, handle) {
            var _e = [
                {
                    validator: 'addEventListener',
                    prefix: ''
                },
                {
                    validator: 'attachEvent',
                    prefix: 'on'
                }
                            ];

            this.__(_e, el, event, handle);
        },
        remove: function(el, event, handle) {
            var _e = [
                {
                    validator: 'removeEventListener',
                    prefix: ''
                },
                {
                    validator: 'detachEvent',
                    prefix: 'on'
                }
                            ];

            this.__(_e, el, event, handle);
        }
    },
    getUid: function(_name) {
        return me.template('me-{0}{1}-{2}', _name, new Date().getTime(), me.__Index++);
    },
    Browser: {
        isTouch: function() {
            var msGesture = window.navigator && window.navigator.msPointerEnabled && window.MSGesture;

            return (('ontouchstart' in window) || msGesture || window.DocumentTouch) ? true : false;
        },
        Prefix: function() {
            var i;

            var props = ['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective'];
            var obj = document.createElement('div');

            for (i in props) {
                if (obj.style[props[i]] !== undefined) {
                    return me.template('-{0}-', props[i].replace('Perspective', '').toLowerCase());
                }
            }
        },
        parseURL: function(url) {
            var a = document.createElement('a');
            var ret,seg,len,i,s;

            a.href = url;
            return {
                source: url,
                protocol: a.protocol.replace(':', ''),
                host: a.hostname,
                port: a.port,
                query: a.search,
                params: (function() {
                    ret = {},
                    seg = a.search.replace(/^\?/, '').split('&'),
                    len = seg.length, i = 0, s;

                    for (; i < len; i++) {
                        if (!seg[i]) {
                            continue;
                        }
                        s = seg[i].split('=');
                        ret[s[0]] = s[1];
                    }
                    return ret;
                })(),
                file: (a.pathname.match(/\/([^\/?#]+)$/i) || [null, ''])[1],
                hash: a.hash.replace('#', ''),
                path: a.pathname.replace(/^([^\/])/, '/$1'),
                relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [null, ''])[1],
                segments: a.pathname.replace(/^\//, '').split('/')
            };
        }
    },
    Array: {
        indexOf: function(array, val) {
            var i;

            for (i = 0; i < array.length; i++) {
                if (this[i] === val) {
                    return i;
                }
            }
            return -1;
        },
        remove: function(array, val) {
            var index = this.indexOf(array, val);

            if (index > -1) {
                array.splice(index, 1);
            }
            return array;
        }
    }
};

assembly = function(options) {
    this.initialized = false;
    this.registerEvent = {
        before: [],
        change: [],
        after: []
    };
    this.options = options;

    this.init(options);
};

assembly.output = function() {
    me.log(me.list);
};
assembly.prototype.oninit = me.fn;

assembly.prototype.init = function(cfg) {
    this.initialized = true;

    // function _getClassName(_constructor, _constr) {
    //     var _constr = _constr || "";
    //     if (_constructor.superclass) {
    //         var args = /(\w+)\.superclass/.exec(_constructor.arguments.callee);
    //         if (args != null) {
    //             _constr += args[1] + "-";
    //             // return _getClassName(_constructor.superclass.constructor, _constr);
    //         }
    //     }
    //     return _constr;
    // }
    this.__Uid = me.getUid('me');
    this.oninit(cfg);
    me.list[this.__Uid] = this;
};
assembly.prototype.destory = function() {
    this.initialized = false;
    delete me.list[this.__Uid];
};
assembly.prototype.getUid = function() {
    return this.__Uid;
};
assembly.prototype.getOptions = function() {
    return this.options;
};
assembly.prototype.config = function() {
    if (arguments.length > 0) {
        if (typeof (arguments[0]) === 'string') {
            if (arguments.length > 1) {
                this.options[arguments[0]] = arguments[1];
            } else {
                return this.options[name];
            }
        }
    } else {
        return this.options;
    }
};
assembly.prototype.on = function(name, callback) {
    var __self = this;
    var _e = __self.registerEvent[name];

    if (_e) {
        _e.push(callback);
    }
    return _e;
};
assembly.prototype.off = function(name, callback) {
    var __self = this;
    var _e = __self.registerEvent[name];
    var e = [];

    me.each(_e, function(name, _callback) {

        if (_callback === callback) {
            e.push(name);
        }
    });

    me.each(e.reverse(), function(name, _callback) {
        _e.splice(_callback, 1);
    });
};
me.assembly = assembly;

module.exports = me;
});
define("js/common/new-arrivls", ["jquery","lazyload","handlebars","source-map"], function(require, exports, module){
var $ = require("jquery"),
        lazyload = require("lazyload");
var Handlebars = require("handlebars");

function InfiniteLoad(options) {
    var defaults = {
        index: 0,
        isload: true,//是否正在加载
        isrun: true,//判断是否执行
        offset: {
            height: null,
            width: null
        }
    };

    this.registerEvent = {
        before: [],
        change: [],
        after: []
    };

    this.options = $.extend(true, {}, defaults, options);

    return this;
}

InfiniteLoad.prototype.on = function(name, callback) {
    var g = this;
    var _e = g.registerEvent[name];

    if (_e) {
        _e.push(callback);
    }
    return _e;
};

InfiniteLoad.prototype.exect = function(key, params) {
    var g = this;
    var e;

    if (g.registerEvent[key] && g.registerEvent[key].length > 0) {
        for (e in g.registerEvent[key]) {
            if (g.registerEvent[key].hasOwnProperty(e)) {
                g.registerEvent[key][e](params);
            }
        }
    }
};

InfiniteLoad.prototype.init = function() {
    var g = this;
    var p = this.options;

    function __loadMore() {

        if (p.isrun && p.isload && g.__directionCalculation()) {
            p.isload = false;
            p.index++;
            g.exect('after', p);
        }

        g.exect('change', p);
    }

    g.exect('before', p);

    $(window).scroll(__loadMore);
};

InfiniteLoad.prototype.emit = function() {
    var p = this.options;

    p.isload = true;
};

InfiniteLoad.prototype.stop = function() {
    var p = this.options;

    p.isrun = false;
    p.isload = false;
};

InfiniteLoad.prototype.__directionCalculation = function() {
    var p = this.options;

    if (p.offset.height && p.offset.height() > 0 && $(window).scrollTop() + $(window).height() >= p.offset.height()) {
        return true;
    }
    return false;
};

module.exports = function(data) {
    var $container = $('#newarrivals .goods-container');
    var $load = $('.loading a');
    var load = new InfiniteLoad({
        index: 1,
        isload: false,
        offset: {
            height: function() {
                return parseFloat($container.offset().top) + parseFloat($container.height()) - 200;
            }
        }
    });
    var loadAjax;
    var url = data.url,
        count = data.count,
        rows = data.rows;

    data.pageIndex = 0;

    delete data.url;
    delete data.count;
    delete data.rows;

    loadAjax = function(url, data, count) {

        var options = {
            type: 'POST',
            url: url,
            success: function(result) {
                var code = result.code;
                var myTemplate,len,pos;

                if (code === 200) {
                    len = result.goods.length % count;
                    pos = result.goods.length - len - 1;

                    result.goods.splice(pos, len);

                    myTemplate = Handlebars.compile(load.tpl);

                    $container.append(myTemplate(result.goods));
                    data.pageIndex = data.pageIndex + result.goods.length;

                    //懒加载插件貌似有点问题,图片先直接展示
                    lazyload($container.find('img.lazy'));

                    load.emit();
                } else {

                    load.stop();
                    $load.html('查看更多');
                }
            },
            error: function() {

                load.stop();
                $load.html('网络断开连接了~');
            }
        };

        options.data = data;
        $.ajax(options);
    };


    load.on('after', function(p) {

        data.pageCount = count * rows[1];

        loadAjax(url, data);
    });

    load.on('before', function(p) {


        load.tpl = '{{#each this}}';
        load.tpl += '<div class="good-info imgopacity" data-skn="{{skn}}">';
        load.tpl += '    <div class="tag-container clearfix">';
        load.tpl += '        {{# tags}}';
        load.tpl += '            {{# isNew}}';
        load.tpl += '                <span class="good-tag new-tag">NEW</span>';
        load.tpl += '            {{/ isNew}}';
        load.tpl += '            {{# isReNew}}';
        load.tpl += '                <span class="good-tag renew-tag">再到着</span>';
        load.tpl += '            {{/ isReNew}}';
        load.tpl += '            {{# isSale}}';
        load.tpl += '                <span class="good-tag sale-tag">SALE</span>';
        load.tpl += '            {{/ isSale}}';
        load.tpl += '            {{# isNewFestival}}';
        load.tpl += '                <span class="good-tag new-festival-tag">新品节</span>';
        load.tpl += '            {{/ isNewFestival}}';
        load.tpl += '            {{# isLimit}}';
        load.tpl += '                <span class="good-tag limit-tag">限量商品</span>';
        load.tpl += '            {{/ isLimit}}';
        load.tpl += '            {{# isYearEndPromotion}}';
        load.tpl += '                <span class="good-tag yep-tag">年终大促</span>';
        load.tpl += '            {{/ isYearEndPromotion}}';
        load.tpl += '            {{# isYearMidPromotion}}';
        load.tpl += '                <span class="good-tag ymp-tag">年中热促</span>';
        load.tpl += '            {{/ isYearMidPromotion}}';
        load.tpl += '        {{/ tags}}';
        load.tpl += '    </div>';
        load.tpl += '    <div class="good-detail-img">';
        load.tpl += '        <a class="good-thumb" href="{{url}}" target= "_blank">';
        load.tpl += '            <img class="lazy" data-original="{{thumb}}">';
        load.tpl += '        </a>';
        load.tpl += '        {{# isFew}}';
        load.tpl += '            <p class="few-tag">即将售罄</p>';
        load.tpl += '        {{/ isFew}}';

        load.tpl += '        {{#if showColBtn}}';
        load.tpl += '            <span class="col-btn iconfont{{#if coled}} coled{{/if}}">&#xe616;</span>';
        load.tpl += '        {{/if}}';
        load.tpl += '    </div>';
        load.tpl += '    <div class="good-detail-text">';
        load.tpl += '        <a href="{{url}}" target= "_blank">{{name}}</a>';
        load.tpl += '        <p class="price">';
        load.tpl += '            <span class="sale-price{{#unless marketPrice}}prime-cost{{/unless}}">';
        load.tpl += '                ¥{{salePrice}}';
        load.tpl += '            </span>';
        load.tpl += '            {{# marketPrice}}';
        load.tpl += '                <span class="market-price">¥{{.}}</span>';
        load.tpl += '            {{/ marketPrice}}';
        load.tpl += '        </p>';
        load.tpl += '    </div>';
        load.tpl += '</div>';
        load.tpl += '{{/each}}';


        data.pageCount = count * rows[0];

        loadAjax(url, data, data.count);

        //load.emit();
    });

    load.init();

};
});
define("js/brand/index", ["jquery","lazyload","handlebars","source-map","dot"], function(require, exports, module){
/**
 * 首页
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/11/23
 */

var $ = require("jquery"),
    lazyLoad = require("lazyload");


require("js/common/slider");
require("js/brand/brands");

lazyLoad($('img.lazy'));
$('.slide-container').slider({
    orient: true
});
});
define("js/brand/brands", ["jquery","handlebars","source-map","dot"], function(require, exports, module){
var $ = require("jquery"),
    Handlebars = require("handlebars"),
    dot = require("dot");

var $tabs = $('.brands-tabs');
var $list = $('.brands-list');
var $gory = $('.brands-category');
var $news = $('.news-txt ul');
var $clearfix = $list.find('dl.clearfix');
var $brand = $list.find('li>a');
var $category = $gory.find('a');
var $tab = $tabs.find('li>a');
var $arr = $tabs.find('.hoverarr');
var $thisTab;

var categoryHeight = $category.height();
var categoryTop = $category.offset() ? $category.offset().top : 0;
var newsHeight = $news.height();
var newsTop = $news.offset() ? $news.offset().top : 0;
var timeout, _id;


//用于临时存储数据
var tempdata = {};

var templete = '<div class="brands-dialog">';

templete += '    <div class="brands-layer">';
templete += '        <div class="layer-content">';
templete += '            <div class="title">{{title}}</div>';
templete += '            <div class="clearfix desc">';
templete += '                <img src="{{icon}}">';
templete += '                <p class="right">{{content}}</p>';
templete += '            </div> ';
templete += '            <div class="featured">';
templete += '                <p>{{subtitle}}</p> ';
templete += '                <div class="clearfix"> ';
templete += '                    {{#each imgs}}';
templete += '                    <img src="{{src}}">';
templete += '                    {{/each}}';
templete += '                </div>';
templete += '            </div>';
templete += '        </div>';
templete += '    </div>';
templete += '</div>';

dot($('.brand-desc'));

$.easing.easeOutQuint = function(x, t, b, c, d) {
    return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
};

function getQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
    var r = window.location.search.substr(1).match(reg);

    if (r != null) {
        return window.unescape(r[2]);
    }
    return null;
}

// 格式化资讯NEWS标题数量
if ($news.length) {
    $news.find('li').each(function() {
        var $dom = $(this);
        var domHeight = $dom.offset().top - newsTop + $dom.height();

        if (domHeight > newsHeight) {
            $dom.hide();
        }
    });
}

//头部图片TAB切换展示
$tab.eq(0).parent('li').find('.brands-content').css('z-index', '1');

_id = getQueryString('id') ? getQueryString('id') : 0;

// 设置对应TAB选中
$thisTab = $tab.eq(_id);
$thisTab.find('.g-mask').addClass('g-mask-on');

if (_id && $thisTab.length) {
    $arr.css({
        left: parseFloat($thisTab.offset().left) - parseFloat($tabs.offset().left)
    });
}
$tab.hover(function() {
    var $this = $(this);

    clearTimeout(timeout);
    timeout = setTimeout(function() {
        var targetLeft = parseFloat($this.offset().left) - parseFloat($tabs.offset().left);

        $arr.animate({
            left: targetLeft
        }, 200, 'easeOutQuint');
    }, 50);
    $tabs.find('.brands-content').removeAttr('style');
    $this.parent('li').find('.brands-content').css('z-index', '1');

}, function() {
    clearTimeout(timeout);
});

//品牌类别滚动事件
$(window).scroll(function() {
    if ($(this).scrollTop() >= categoryTop) {
        $gory.addClass('category-fix');
    } else {
        $gory.removeClass('category-fix');
    }
});

//点击字母,页面滚动到相关区域
$category.click(function() {
    var name = $(this).attr('href').split('#')[1];
    var targetTop = $list.find('[name=' + name + ']').offset().top - categoryHeight;

    if (!$gory.hasClass('category-fix')) {
        targetTop -= categoryHeight;
    }

    $('html,body').animate({
        scrollTop: targetTop
    }, 200);
    return false;
});


//浮层代码
function bindTemplete($select, data, templete) {
    var $this = $select;
    var offset = {
        width: $this.width(),
        left: $this.offset().left,
        right: parseFloat($(window).width()) - parseFloat($this.offset().left) - parseFloat($this.width())
    };

    var $parent = $this.parent('li');
    var myTemplate;

    $list.find('.brands-dialog').remove();
    myTemplate = Handlebars.compile(templete);
    $parent.append(myTemplate(data));
    dot($parent.find('.right'));

    if (offset.right - 350 < 0) {
        $parent.find('.brands-layer')
                .addClass('brands-layer-right').css('left', -330 - offset.width);
    }
}

//鼠标悬浮品牌,请求数据,并且展示
function bindHoverEvent() {
    $brand.unbind('mouseenter').unbind('mouseleave').hover(function() {
        var $this = $(this);
        var key = $this.attr('data-key');

        var options = {
            url: '/brands/brandinfo',
            type: 'get',
            data: {
                brandId: key
            },
            success: function(_data) {

                if (_data.code === 200 && _data.brand) {
                    if (!tempdata.hasOwnProperty(_data.brand.key)) {
                        tempdata[_data.brand.key] = _data.brand;
                    }
                    bindTemplete($this, tempdata[_data.brand.key], templete);
                }
            }
        };

        clearTimeout(timeout);
        timeout = setTimeout(function() {
            if (!tempdata.hasOwnProperty(key)) {
                $.ajax(options);
            } else {
                bindTemplete($this, tempdata[key], templete);
            }
        }, 200);
    }, function() {
        clearTimeout(timeout);
        $list.find('.brands-dialog').remove();
    });
}

if ($clearfix.length < 26) {
    $.ajax({
        url: '/brands/brandList',
        type: 'POST',
        data: {
            start: $clearfix.length ? ($clearfix.length + 1) : 1
        },
        success: function(_data) {
            if (_data) {
                $list.append(_data);
                $brand = $list.find('li>a');
                bindHoverEvent();
            }
        }
    });
}

bindHoverEvent();
});
define("js/passport/entry", ["jquery","jquery.placeholder"], function(require, exports, module){
/*
 * 密码中心打包入口文件
 */

require("js/passport/reg");
require("js/passport/back");
require("js/passport/login");
require("js/passport/reset");
require("js/passport/vertification");
require("js/passport/thirdlogin");
require("js/passport/third-pwd");
});
define("js/passport/reg", ["jquery","jquery.placeholder"], function(require, exports, module){
/*
 * @description 注册页js
 * @time 2015/12/14
 */

var $ = require("jquery"),
    regValidate = require("js/passport/mail-phone-regx"),
    computeComplex = require("js/passport/pwd-strength");

var $registerPage = $('.register-page'),
    $pwdTips = $('#pwd-tips'),
    $pwdTip1 = $pwdTips.find('#pwd-tip1'),
    $errTip = $('#err-tip'),
    $registerBtn = $('#register-btn');

var $sendCaptcha = $('#send-captcha'),
    caCount = 4,
    validateResult = [];

var $pn = $('#phone-num'),
    $mc = $('#msg-captcha'),
    $pwd = $('#pwd'),
    $repwd = $('#repwd'),
    $ca = $('#captcha');

// 密码强度验证
var $pwdIntensity = $('.pwd-intensity'),
    $pwdParent = $pwdIntensity.closest('.pwd-intensity-container');

//signup验证
var $region = $('#country-code'),
    $regionSelect = $('#region'),
    isPwd = false,
    pwdVal;

var pwdReg = regValidate.pwdValidateRegx;

var $curErrContainer;

require("jquery.placeholder");

setTimeout(function() {
    $pn.val('');
    $mc.val('');
    $pwd.val('');
    $repwd.val('');
    $ca.val('');
}, 0);

//验证码位数
$ca.attr('maxlength', caCount);

//密码规则提示
$pwd.focus(function(event) {
    $pwdTips.removeClass('hide');
    isPwd = true;
    pwdVal = $(this).val();
}).blur(function() {
    $pwdTips.addClass('hide');
    isPwd = false;
});


//IE8 placeholder
$('[placeholder]').placeholder();

// 存储校验信息
validateResult = [
    {
        id: 'phone-num',
        message: '', //错误信息
        status: false //当前的状态
    },
    {
        id: 'captcha',
        message: '',
        status: false
    },
    {
        id: 'msg-captcha',
        message: '',
        status: false
    },
    {
        id: 'pwd',
        message: '',
        status: false
    },
    {
        id: 'repwd',
        message: '',
        status: false
    }
];

//手机号ajax校验
function phoneAjaxFn(page, callback) {
    var url,
        data;

    if (page === 'reg') {
        url = '/passport/register/checkmobile';
        data = {
            mobile: $pn.val(),
            area: $region.text().split('+')[1]
        };
    } else if (page === 'third') {
        url = '/passport/autouserinfo/bindCheck';
        data = {
            mobile: $pn.val(),
            area: $region.text().split('+')[1],
            openId: $('#open-id').val(),
            sourceType: $('#source-type').val()
        };
    }

    $.ajax({
        url: url,
        type: 'POST',
        data: data
    }).then(function(data) {
        if (!data) {
            return;
        }

        switch (data.code) {
            case 200:
                validateResult[0].message = '';
                validateResult[0].status = true;
                break;
            case 400:
                validateResult[0].message = data.message;
                validateResult[0].status = false;
                break;
        }

        callback();
    });
}

//图形验证码ajax校验
function picCaptchaAjaxFn(page, callback) {
    var url;

    if (page === 'reg') {
        url = '/passport/register/piccaptcha';
    } else if (page === 'third') {
        url = '/passport/autouserinfo/checkPicCode';
    }
    $.ajax({
        type: 'POST',
        url: url,
        data: {
            verifyCode: $ca.val()

            //mobile: $pn.val(),
            //area: $region.text().split('+')[1]
        }
    }).then(function(data) {
        if (!data) {
            return;
        }

        switch (data.code) {
            case 200:
                validateResult[1].message = '';
                validateResult[1].status = true;
                break;
            case 400:
                validateResult[1].message = '图形验证码错误';
                validateResult[1].status = false;
                break;
        }
        callback();
    });
}

//短信验证码ajax校验
function msgCaptchaAjaxFn(page, callback) {
    var url;

    if (page === 'reg') {
        url = '/passport/register/msgcaptcha';
    } else if (page === 'third') {
        url = '/passport/autouserinfo/checkBindMsg';
    }
    $.ajax({
        type: 'POST',
        url: url,
        data: {
            code: $mc.val(),
            mobile: $pn.val(),
            area: $region.text().split('+')[1]
        }
    }).then(function(data) {
        if (!data) {
            return;
        }

        switch (data.code) {
            case 200:
                validateResult[2].message = '';
                validateResult[2].status = true;
                break;
            case 400:
                validateResult[2].message = '短信验证码错误';
                validateResult[2].status = false;
                break;
        }

        callback();
    });
}

// 验证
function validateRule(page, $element, callback) {

    var val = $.trim($element.val()),
        regionCode;

    // 根据需求http://redmine.yoho.cn/issues/3117改成上边的正则
    // 对应的错误提示语也改了,感觉要不了多久就会改回来
    // pwdReg = /^([a-zA-Z0-9\-\+_!@\#$%\^&\*\(\)\:\;\.=\[\]\\\',\?]){6,20}$/gi;

    //手机号校验
    if ($element.hasClass('phone-num')) {

        regionCode = $region.text();

        if (val === '') {
            validateResult[0].message = '请输入手机号码';
            validateResult[0].status = false;
            callback();

        } else if (!regValidate.phoneRegx[regionCode].test(val)) {
            validateResult[0].message = '手机号码格式不正确,请重新输入';
            validateResult[0].status = false;
            callback();

        } else {
            phoneAjaxFn(page, callback);
        }

    //图形验证码校验
    } else if ($element.hasClass('captcha')) {
        if (val === '') {
            validateResult[1].message = '请输入图形验证码';
            validateResult[1].status = false;
            callback();

        } else if (val.length <= 3) {
            validateResult[1].message = '图形验证码为4位';
            validateResult[1].status = false;
            callback();

        } else {

            // 并且手机号正确
            if (validateResult[0].status) {
                picCaptchaAjaxFn(page, callback);
            } else {
                validateResult[1].message = '图形验证码错误';
                validateResult[1].status = false;
                callback();
            }

        }

    //短信验证码校验
    } else if ($element.hasClass('msg-captcha')) {

        if (val === '') {
            validateResult[2].message = '请输入短信验证码';
            validateResult[2].status = false;
            callback();

        } else if (val.length <= 3) {
            validateResult[2].message = '短信验证码错误';
            validateResult[2].status = false;
            callback();

        } else {

            // 并且图形验证码正确
            if (validateResult[1].status) {
                msgCaptchaAjaxFn(page, callback);
            } else {
                validateResult[2].message = '短信验证码错误';
                validateResult[2].status = false;
                callback();
            }
        }

    //密码校验
    } else if ($element.hasClass('pwd')) {
        if (val === '') {
            validateResult[3].message = '请输入密码';
            validateResult[3].status = false;

        } else if (val.length < 6 || val.length > 20) {
            validateResult[3].message = '密码只支持6-20位字符';
            validateResult[3].status = false;

        } else if (!pwdReg.test($element.val())) {
            validateResult[3].message = '密码须字母和数字组合';
            validateResult[3].status = false;

        } else {
            validateResult[3].message = '';
            validateResult[3].status = true;
        }
        callback();

    //二次密码校验
    } else if ($element.hasClass('repwd')) {
        if (val === '') {
            validateResult[4].message = '请输入密码确认';
            validateResult[4].status = false;

        } else if ($pwd.val() !== val) {
            validateResult[4].message = '与密码不一致,请重新输入';
            validateResult[4].status = false;

        } else {
            validateResult[4].message = '';
            validateResult[4].status = true;

        }

        callback();
    }
}

function posErrTip() {
    var tipPos = $curErrContainer.offset();

    return $errTip.css({
        top: tipPos.top - 40,
        left: tipPos.left
    });
}

//显示提示信息
function showErrTip() {

    var show = false,
        i,
        validateResultLen = validateResult.length;

    for (i = 0; i < validateResultLen; i++) {
        if (!show) {

            //不可以通过status判断
            if (!!validateResult[i].message) {

                //显示错误提示
                $errTip.find('span').text(validateResult[i].message);
                $curErrContainer = $('#' + validateResult[i].id);
                posErrTip().removeClass('hide');

                show = true; //停止判断
            } else {
                $errTip.addClass('hide');
            }
        }
    }
}

//显示红色边框
function showBorder() {

    var $errInput,
        i,
        validateResultLen = validateResult.length;

    for (i = 0; i < validateResultLen; i++) {
        if (!!validateResult[i].message) {

            //显示红色边框
            $errInput = $('#' + validateResult[i].id);
            $errInput.addClass('error');

        } else {

            //去掉红色边框
            $errInput = $('#' + validateResult[i].id);
            $errInput.removeClass('error');
        }
    }
}

// 密码强度验证
function pwdFn($obj) {
    var pwd = $obj.val(),
        pwdStrength = computeComplex(pwd),
        level = 0;

    if (pwdStrength === 0) {
        level = 0;
    } else if (pwdStrength <= 10) {
        level = 1;
    } else if (pwdStrength <= 20) {
        level = 2;
    } else {
        level = 3;
    }

    switch (level) {
        case 0:
            $pwdParent.removeClass('red yellow green');
            $pwdIntensity.removeClass('color');
            break;
        case 1:
            $pwdParent.addClass('red').removeClass('yellow green');
            $pwdIntensity.filter('.low').addClass('color');
            $pwdIntensity.filter('.mid,.high').removeClass('color');
            break;
        case 2:
            $pwdParent.addClass('yellow').removeClass('red green');
            $pwdIntensity.filter('.low,.mid').addClass('color');
            $pwdIntensity.filter('.high').removeClass('color');
            break;
        case 3:
            $pwdParent.addClass('green').removeClass('yellow red');
            $pwdIntensity.addClass('color');
            break;
    }

    //提示框
    if (pwd === '') {
        $pwdTip1.removeClass('red yes no').addClass('default');
    } else if (pwd.length < 6 || pwd.length > 20) {
        $pwdTip1.removeClass('default yes').addClass('no red');
    } else {
        $pwdTip1.removeClass('default no red').addClass('yes');
    }
}

//重新定位错误提示
$(window).resize(function() {
    if ($errTip.hasClass('hide')) {
        return;
    }

    posErrTip();
});

// 失去焦点时开始校验
// Tips: 不可以在获得焦点的时候验证,获得焦点和失去焦点的间隔太小,如果中间存在ajax校验的话会出现问题
// ( ▼-▼ )注册页和信息完善页面接口不同
exports.init = function(page) {

    $('#agree-terms').click(function() {
        if ($(this).attr('notchecked')) {
            $(this).removeAttr('notchecked');
            $registerBtn.addClass('disable').attr('disabled', 'true');
        }
    });

    // 按回车键提交
    $registerPage.on('keydown', function(e) {
        var key = e.which;

        if (key === 13) {
            $registerBtn.click();
        }
    });

    $registerPage.find('.va').keyup(function() {

        var j,
            statusLen = 0,
            vLen = validateResult.length,
            $that = $(this);

        validateRule(page, $(this), function() {
            showErrTip(); // 显示错误提示
            showBorder(); // 显示红色边框

            // 如果validateResult中有4个status为true表示验证通过
            for (j = 0; j < vLen; j++) {

                if (validateResult[j].status) {

                    statusLen++;
                }

            }

            if (statusLen === 4 && !$('#agree-terms').attr('notchecked')) {
                $registerBtn.removeClass('disable').removeAttr('disabled');
            } else {
                $registerBtn.addClass('disable').attr('disabled', 'true');
            }

            // 图形验证通过时,发送短信按钮可点击
            if (validateResult[1].status) {
                $sendCaptcha.removeClass('disable');
            } else {
                $sendCaptcha.addClass('disable');
            }

            //图形验证通过时,发送短信按钮可点击 end

        });

        // 如果是密码则校验强度
        if (($that).hasClass('pwd')) {
            pwdFn($that);
        }

    }).blur(function() {

        /*validateRule($(this), function() {
            showErrTip();
            showBorder(); // 显示红色边框
        });*/
    });

    $regionSelect.change(function() {

        $region.text($('#region').val());

        validateRule(page, $pn, showErrTip); //验证
    });

    // 点击发送验证码
    $sendCaptcha.click(function() {
        var timeResidue = 60,
            t,
            url;

        if ($(this).hasClass('disable')) {
            return;
        }

        $sendCaptcha.addClass('disable');

        t = setInterval(function() {
            if (timeResidue <= 0) {
                $sendCaptcha.removeClass('disable').val('获取短信验证码');
                clearInterval(t);
                return;
            }
            $sendCaptcha.val(timeResidue-- + '秒可重新发送');
        }, 1000);

        if (page === 'reg') {
            url = '/passport/register/sendBindMsg';
        } else if (page === 'third') {
            url = '/passport/autouserinfo/sendBindMsg';
        }

        //todo ajax 发送验证码
        $.ajax({
            type: 'POST',
            url: url,
            data: {
                area: $region.text().split('+')[1],
                mobile: $pn.val(),
                verifyCode: $ca.val()
            }
        });
    });

    // 防止粘贴密码
    $pwd[0].onpaste = function() {
        return false;
    };

    //ajax表单提交
    $registerBtn.click(function() {
        var url;

        if (page === 'reg') {
            url = '/passport/register/mobileregister';
        } else if (page === 'third') {
            url = '/passport/autouserinfo/bindMobile';
        }

        if ($(this).hasClass('disable')) {
            return;
        } else {

            //ajax提交
            $.ajax({
                type: 'POST',
                url: url,
                data: {
                    area: $region.text().split('+')[1],
                    mobile: $pn.val(),
                    verifyCode: $ca.val(),
                    code: $mc.val(),
                    password: $pwd.val()
                }
            }).then(function(data) {

                var time = 0,
                    t,
                    refer;

                if (data.code === 200) {

                    refer = data.data.href;

                    t = setTimeout(function() {
                        time++;
                    }, 1000);

                    $.ajax({
                        type: 'GET',
                        url: data.data.session
                    }).then(function(data) {

                        if (data.code === 200 && t < 3) {
                            clearInterval(t);
                            location.href = refer;
                        }
                    });

                    if (t >= 3) {
                        clearInterval(t);
                        location.href = refer;
                    }
                } else {

                    //todo
                    console.log('网络超时~');
                }

            });
        }
    });

    $('.change-captcha').click(function() {
        var time = new Date(),
            $captchaImg = $('.captcha-img'),
            captchaImgSrc = $captchaImg.attr('src').split('?')[0];

        $captchaImg.attr('src', captchaImgSrc + '?t=' + time.getTime());
    });
};

});
define("js/passport/mail-phone-regx", [], function(require, exports, module){
/**
 * 国家区号Map手机号码以及邮箱验证正则
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/11
 */

var countryPhoneRegx = {
    '+86': /^1[35847]{1}[0-9]{9}$/,
    '+852': /^[965]{1}[0-9]{7}$/,
    '+853': /^[0-9]{8}$/,
    '+886': /^[0-9]{10}$/,
    '+65': /^[98]{1}[0-9]{7}$/,
    '+60': /^1[1234679]{1}[0-9]{8}$/,
    '+1': /^[0-9]{10}$/,
    '+82': /^01[0-9]{9}$/,
    '+44': /^7[789]{1}[0-9]{8}$/,
    '+81': /^0[9|8|7][0-9]{9}$/,
    '+61': /^[0-9]{11}$/
};

var emailRegx = /^[.\-_a-zA-Z0-9]+@[\-_a-zA-Z0-9]+\.[a-zA-Z0-9]/;

var pwdValidateRegx = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$/;

exports.phoneRegx = countryPhoneRegx;

exports.emailRegx = emailRegx;

exports.pwdValidateRegx = pwdValidateRegx;
});
define("js/passport/pwd-strength", [], function(require, exports, module){
/*
 * 计算密码复杂度
 */

function gettype(str, i) {
    if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
        return 1;
    } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
        return 2;
    } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
        return 3;
    }

    return 4;
}

function isregular(cur, pre, type) {
    var curCode = cur.charCodeAt(0);
    var preCode = pre.charCodeAt(0);

    if (curCode - preCode === 0) {
        return true;
    }

    if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
        return true;
    }

    return false;
}

function getcomplex(curType, preType) {
    if (preType === 0 || curType === preType) {
        return 0;
    } else if (curType === 4 || preType === 4) {
        return 2;
    } else {
        return 1;
    }
}

function computeComplex(password) {
    var complex = 0,
        length = password.length,
        pre = '',
        preType = 0,
        i = 0,
        cur,
        curType;


    for (i = 0; i < length; i++) {
        cur = password.charAt(i);
        curType = gettype(password, i);

        if (preType !== curType || !isregular(cur, pre, curType)) {
            complex += curType + getcomplex(curType, preType);
        }

        pre = cur;
        preType = curType;
    }

    return complex;
}

module.exports = computeComplex;
});
define("js/passport/back", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
 * 找回密码
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/14
 */

var $ = require("jquery"),
    regx = require("js/passport/mail-phone-regx"),
    emailReg = regx.emailRegx,
    phoneRegx = regx.phoneRegx;

var emailAc = require("js/passport/ac-email"); //邮箱自动完成

var $cr = $('#country-code-hide'),
    $phoneNum = $('#phone-num'),
    $ca = $('#captcha'),
    $ccList = $('#country-code-list'),
    $cc = $('#country-code'),
    $btn = $('#find-btn'),
    $accErr = $('#account-err'),
    $caErr = $('#captcha-err'),
    caCount = 4, //验证码位数
    hasPh = false,
    hasCa = false;


require("jquery.placeholder");

function imgcode() {
    var time = new Date(),
        $captchaImg = $('#captcha-img'),
        captchaImgSrc = $captchaImg.attr('src').split('?')[0];

    $('#captcha-img').attr('src', captchaImgSrc + '?t=' + time.getTime());
}

function enableBtn() {
    if (hasPh && hasCa) {
        $btn.removeClass('disable').prop('disabled', false);
    } else {
        $btn.addClass('disable').prop('disabled', true);
    }
}

function vaPn(v) {
    var pass = true,
        errTxt = '';

    v = $.trim(v);
    if (v !== '') {
        if (/^[0-9]+$/.test(v)) {
            if (phoneRegx[$cr.val()].test(v)) {
                pass = true;
            } else {
                errTxt = '手机号码格式不正确, 请重新输入';
                pass = false;
            }
        } else {
            if (emailReg.test(v)) {
                pass = true;
            } else {
                errTxt = '邮箱格式不正确, 请重新输入';
                pass = false;
            }
        }
    } else {
        errTxt = '账户名不能为空';
        pass = false;
    }
    hasPh = pass;
    return {
        pass: pass,
        errTxt: errTxt
    };
}

function vaCa() {
    var v = $.trim($ca.val());

    if (v === '' || v.length < caCount) {
        hasCa = false;
        enableBtn();
        return;
    } else {
        $.ajax({
            type: 'POST',
            url: '/passport/back/authcode',
            data: {
                verifyCode: v,
                phoneNum: $('#phone-num').val(),
                area: $('#country-code-hide').val()
            }

        }).then(function(data) {
            if (data.code === 200) {
                hasCa = true;
            } else if (data.code === 402) {
                hasPh = false;
                hasCa = true;
                $accErr.removeClass('hide').find('em').text('该账号不存在');
                $phoneNum.addClass('error');
            } else if (data.code === 400) {
                hasCa = false;
                imgcode();
            }
            enableBtn();
        });
    }
}

emailAc($phoneNum, function() {
        var pnVa = vaPn($phoneNum.val());

        if (pnVa.pass) {
            $accErr.addClass('hide');
            $phoneNum.removeClass('error');
        } else {
            $accErr.removeClass('hide').find('em').text(pnVa.errTxt);
            $phoneNum.addClass('error');
        }

        enableBtn();
    }
);

$ca.attr('maxlength', caCount);

//IE8 placeholder
$('input').placeholder();

$('#change-captcha, #captcha-img').on('click', function() {
    imgcode();
});

$cc.on('click', function(e) {
    e.stopPropagation();
    if ($ccList.css('style') === 'block') {
        $ccList.slideUp('fast');
    } else {
        $ccList.slideDown('fast');
    }
});

$ccList.delegate('li', 'click', function(e) {
    var $cur = $(this),
        code = $cur.data('cc'),
        pnVa;

    e.stopPropagation();
    $cr.val(code);
    $cc.find('em').html($cur.text());

    //切换后验证手机号码
    if ($.trim($phoneNum.val()) !== '') {
        pnVa = vaPn($phoneNum.val());
        enableBtn();
        if (hasPh) {
            $accErr.addClass('hide');
            $phoneNum.removeClass('error');
        } else {
            $accErr.removeClass('hide').text(pnVa.errTxt);
            $phoneNum.addClass('error');
        }
    }
    $ccList.slideUp('fast');
});

$(document).click(function() {
    if ($ccList.css('display') === 'block') {
        $ccList.slideUp();
    }
});

$phoneNum.keyup(function() {
    vaPn($.trim($(this).val()));
    enableBtn();
}).focus(function() {
    $(this).removeClass('error');

    //focus隐藏错误提示
    $accErr.addClass('hide');
});

//验证码在鼠标移开后验证, keyup时不再验证
$ca.blur(function() {
    var errTxt = $.trim($ca.val()) === '' ? '验证码不能为空' : '验证码不正确';

    if (hasCa) {
        $caErr.addClass('hide');
        $ca.removeClass('error');
    } else {
        $caErr.removeClass('hide').find('em').text(errTxt);
        $ca.addClass('error');

        //验证码错误则刷新验证码
        imgcode();
    }
}).focus(function() {
    $(this).removeClass('error');

    //focus隐藏错误提示
    $caErr.addClass('hide');
}).keyup(function() {
    vaCa();
});

$('#find-btn').click(function(e) {

    if (/^[0-9]+$/.test($.trim($phoneNum.val()))) {
        $('#find-form').attr('action', '/passport/back/mobile');
    }
    if ($(this).hasClass('disable')) {
        return;
    }
    if (!hasCa || !hasPh) {
        e.preventDefault();
        return true;
    }
});
});
define("js/passport/ac-email", ["jquery"], function(require, exports, module){
/**
 * 邮箱自动补全
 * @author:xuqi<qi.xu@yoho.cn>
 * @date: 2016/2/22
 */
var $ = require("jquery");

var mailPostfix = {
    num: ['qq.com', '163.com', '126.com', 'sina.com', 'gmail.com', 'sohu.com', 'hotmail.com', '139.com', '189.com'],
    other: ['gmail.com', 'qq.com', '163.com', '126.com', 'sina.com', 'sohu.com', 'hotmail.com', '139.com', '189.com']
};

var emailAcTime;

/**
 * @param $input 需要自动完成的$对象
 * @param cb 鼠标移开/点击自动完成项后需要执行的操作(验证等)
 */
module.exports = function($input, cb) {
    var ulHtml = '<ul id="email-autocomplete" class="email-autocomplete hide"></ul>';

    var $emailAutoComplete;

    $input.parent().append(ulHtml);

    $emailAutoComplete = $('#email-autocomplete');

    $input.on('keyup', function() {
        var account = $.trim($(this).val()),
            html = '',
            accountMatch,
            matchStr,
            postfix,
            i;

        //输入@时自动补全邮箱后缀
        //此处>0非错误,用于避免输入的第一个字符为@被识别为邮箱
        if (account.indexOf('@') > 0) {
            accountMatch = account.match(/^[0-9]+@(.*)/);
            if (accountMatch) {

                //数字邮箱补全
                postfix = mailPostfix.num;
                matchStr = accountMatch[1];
            } else {
                postfix = mailPostfix.other;
                matchStr = account.match(/@(.*)/)[1];
            }

            for (i = 0; i < postfix.length; i++) {
                if (postfix[i].indexOf(matchStr) > -1) {
                    html += '<li>' + account.slice(0, account.indexOf('@')) + '@' + postfix[i] + '</li>';
                }
            }

            if (html !== '' && /.com$/.test(account) === false) {
                $emailAutoComplete.html(html).removeClass('hide');
            } else {

                //隐藏autocomplete
                $emailAutoComplete.html('').addClass('hide');
            }
        }
    }).on('blur', function() {
        emailAcTime = setTimeout(function() {

            //未点击自动完成项
            $emailAutoComplete.addClass('hide');

            cb && cb();
        }, 200);
    });

    //邮箱自动完成列表项点击
    $emailAutoComplete.on('click', 'li', function() {
        clearTimeout(emailAcTime); //清空默认关闭

        //点击自动完成项后进行验证
        $input.val($(this).text()).focus();

        $emailAutoComplete.addClass('hide');

        cb && cb();
    });
};
});
define("js/passport/login", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
 * 登录
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/11
 */
var $ = require("jquery");

var $account = $('#account'),
    $password = $('#password'),
    $captcha = $('#captcha');

var $accountTip = $account.siblings('.err-tip'),
    $passwordTip = $password.siblings('.err-tip'),
    $captchaTip = $captcha.siblings('.err-tip'),
    $capsLock = $('#caps-lock');

var $countryCodeHide = $('#country-code-hide'),
    $countryCodeEm = $('#country-code > em'),
    $countryList = $('#country-list');

var $emailAutoComplete = $('#email-autocomplete');

var mailPhoneRegx = require("js/passport/mail-phone-regx");
var mailAc = require("js/passport/ac-email"); //邮箱自动完成

var $remember = $('.remember-me');

var captchaUrl = '/passport/images?t='; // /passport/images?t=1454464125

var $captchaWrap = $('.captcha-wrap'),
    $captcha = $captchaWrap.find('#captcha'),
    $captchaImg = $captchaWrap.find('#captcha-img'),
    $captchaTip = $captchaWrap.find('.err-tip');

//checkbox status unicode
var checkbox = {
    checked: '&#xe612;',
    unchecked: '&#xe613;'
};

var authing = false;

var emailAcTime;

require("jquery.placeholder");

//验证账户名
function validateAccount() {
    var pass = false,
        account = $.trim($account.val()),
        err;

    if (account !== '') {
        if (/^[0-9]+$/.test(account)) {

            //如果是纯数字,则作为手机号码处理
            if (mailPhoneRegx.phoneRegx[$countryCodeHide.val()].test(account)) {
                pass = true;
            } else {
                pass = false;
                err = '手机号码不正确,请重新输入';
            }
        } else {
            if (mailPhoneRegx.emailRegx.test(account)) {
                pass = true;
            } else {
                pass = false;
                err = '邮箱格式不正确,请重新输入';
            }
        }
    } else {
        err = '请输入账户名';
    }

    if (pass) {
        $accountTip.addClass('hide');
        $account.removeClass('error');
    } else {
        $accountTip.removeClass('hide').children('em').text(err);
        $account.addClass('error');
    }
    return pass;
}

//验证密码
function validatePassword() {
    var pass = false,
        password = $.trim($password.val()),
        err;

    if (password !== '') {
        if (password.length < 6) {
            err = '请输入长度为6-20字符的密码';
        } else {
            pass = true;
        }
    } else {
        err = '请输入密码';
    }

    if (pass) {
        $passwordTip.addClass('hide');
        $password.removeClass('error');
    } else {
        $passwordTip.removeClass('hide').children('em').text(err);
        $password.addClass('error');
    }
    return pass;
}

//验证验证码
function validateCaptcha() {
    var pass = false,
        captcha = $.trim($captcha.val()),
        err;

    // 验证码不可见的时候不验证
    if ($captchaWrap.is(':hidden')) {
        return true;
    }

    if (captcha !== '') {
        if (captcha.length !== 4) {
            err = '请输入长度为4字符的验证码';
        } else {
            pass = true;
        }
    } else {
        err = '请输入验证码';
    }

    if (pass) {
        $captchaTip.addClass('hide');
        $captcha.removeClass('error');
    } else {
        $captchaTip.removeClass('hide').children('em').text(err);
        $captcha.addClass('error');
    }
    return pass;
}

//验证
function validate() {
    var pass = true,
        account = $.trim($account.val()),
        password = $.trim($password.val());

    if (account !== '') {
        pass = validateAccount() && validatePassword() && validateCaptcha();
    } else {
        pass = false;
        $account.addClass('error');

        if (password === '') {

            //账户名和密码都为空的情况下点击登陆,只在账户输入框后显示错误提示
            $accountTip.addClass('both-error').removeClass('hide').children('em').text('请输入账户名和密码');
            $passwordTip.addClass('hide');
            $password.addClass('error');
        } else {
            $accountTip.removeClass('hide').children('em').text('请输入账户名');
        }
    }

    return pass;
}

//密码错误次数,超过三次显示验证码
function vaAccountErrTimes() {
    $captchaImg.attr('src', captchaUrl + $.now());
    $captcha.val('');
    $captchaWrap.removeClass('hide');
}

mailAc($account, function() {
        if (validateAccount()) {
            $.ajax({
                url: '/passport/login/account',
                type: 'GET',
                data: {
                    account: $.trim($account.val())
                }
            }).then(function(res) {
                if (res.data && res.data.needCaptcha) {
                    vaAccountErrTimes();
                }
            });
        }
    }
);

$('[placeholder]').placeholder();

//展开地区列表
$('#country-code').on('click', function() {
    if ($countryList.css('display') === 'none') {
        $countryList.slideDown();
    }
});

//选中地区列表项
$countryList.on('click', 'li', function() {
    var $this = $(this),
        cc = $this.data('cc');

    $countryCodeEm.html($this.html());

    $countryCodeHide.val(cc);

    $countryList.slideUp();
});

//点击其他区域,收起区域列表
$(document).on('click', function(e) {
    if ($(e.target).closest('#country-code').length > 0) {
        return;
    }

    if ($countryList.css('display') === 'block') {
        $countryList.slideUp();
    }
});

//密码
$password.on('blur', function() {
    validatePassword();

    if ($capsLock.hasClass('hide')) {
        return;
    }

    $capsLock.addClass('hide');
}).on('keypress', function(e) {
    var code = e.which;

    //CapsLock检测
    if (code >= 65 && code <= 90) {
        $capsLock.removeClass('hide');
        return;
    }
    $capsLock.addClass('hide');
});

// 验证码
$captcha.on('blur', function() {
    validateCaptcha();
});

//邮箱自动完成列表项点击
$emailAutoComplete.on('click', 'li', function() {
    clearTimeout(emailAcTime); //清空默认关闭

    $account.val($(this).text()).focus();

    $emailAutoComplete.addClass('hide');
});

//记住登录状态
$remember.on('click', function() {
    var $this = $(this);

    $this.toggleClass('checked');

    if ($this.hasClass('checked')) {
        $this.children('i').html(checkbox.checked);
    } else {
        $this.children('i').html(checkbox.unchecked);
    }
});

//focus到输入框则隐藏错误提示和样式
$('.va').on('focus', function() {
    var $this = $(this);

    $this.removeClass('error');

    $this.siblings('.err-tip').addClass('hide');
});

// 验证码刷新
$captchaWrap.on('click', '.change-captcha, .captcha-img', function() {
    $captchaImg.attr('src', captchaUrl + $.now());
});

//登录
$('#login-btn').on('click', function() {
    var pass = validate();

    if (pass && authing === false) {
        authing = true;

        $.ajax({
            url: '/passport/login/auth',
            type: 'POST',
            data: {
                areaCode: $countryCodeHide.val().replace('+', ''),
                account: $.trim($account.val()),
                password: $.trim($password.val()),
                captcha: $.trim($captcha.val()),
                isRemember: $remember.hasClass('checked') ? true : false
            },
            success: function(res) {
                if (res.code === 200) {
                    if (res.data) {

                        //防止data.data为undefined时下行语句执行出错而导致脚本不能走到complete去处理authing
                        location.href = res.data.session;
                    }
                } else {
                    if (res.data.errorType === 'captcha') {
                        $captchaTip.removeClass('hide').children('em').html(res.message);
                        $captcha.addClass('error').val('');
                    } else {
                        $passwordTip.removeClass('hide').children('em').html(res.message);
                        $password.addClass('error').val('');
                    }

                    //验证错误次数
                    if (res.data && res.data.needCaptcha) {
                        vaAccountErrTimes();
                    }
                }
            },
            complete: function() {
                authing = false;
            }
        });
    }
});

});
define("js/passport/reset", ["jquery","jquery.placeholder"], function(require, exports, module){
/**
 * 找回密码
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/14
 */

var $ = require("jquery");

var $pwd = $('#pwd'),
    $repwd = $('#re-input'),
    $next = $('#reset-pwd-btn'),
    $pwdErr = $('#pwd-err'),
    $repwdErr = $('#repwd-err'),
    $pwdTips = $('#pwd-tips');

var hasNoErrPw = false;

var $pwdIntensity = $('.pwd-intensity'),
    $pwdParent = $pwdIntensity.closest('.pwd-intensity-container'),
    $pwdTip1 = $('#pwd-tip1');

var pwdRegx = require("js/passport/mail-phone-regx").pwdValidateRegx;

require("jquery.placeholder");


/*
 * 计算密码复杂度
 */

function gettype(str, i) {
    if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
        return 1;
    } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
        return 2;
    } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
        return 3;
    }

    return 4;
}

function isregular(cur, pre, type) {
    var curCode = cur.charCodeAt(0);
    var preCode = pre.charCodeAt(0);

    if (curCode - preCode === 0) {
        return true;
    }

    if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
        return true;
    }

    return false;
}

function getcomplex(curType, preType) {
    if (preType === 0 || curType === preType) {
        return 0;
    } else if (curType === 4 || preType === 4) {
        return 2;
    } else {
        return 1;
    }
}

function computeComplex(password) {
    var complex = 0,
        length = password.length,
        pre = '',
        preType = 0,
        i = 0,
        cur,
        curType;


    for (i = 0; i < length; i++) {
        cur = password.charAt(i);
        curType = gettype(password, i);

        if (preType !== curType || !isregular(cur, pre, curType)) {
            complex += curType + getcomplex(curType, preType);
        }

        pre = cur;
        preType = curType;
    }

    return complex;
}

function pwdKeyupEvt() {
    var pwd = $pwd.val(),
        pwdStrength = computeComplex(pwd),
        level = 0;

    //TODO:自定义密码强度规则,需要修正
    if (pwdStrength === 0) {
        level = 0;
    } else if (pwdStrength <= 10) {
        level = 1;
    } else if (pwdStrength <= 20) {
        level = 2;
    } else {
        level = 3;
    }
    switch (level) {
        case 0:
            $pwdParent.removeClass('red yellow green');
            $pwdIntensity.removeClass('color');
            break;
        case 1:
            $pwdParent.addClass('red').removeClass('yellow green');
            $pwdIntensity.filter('.low').addClass('color');
            $pwdIntensity.filter('.mid,.high').removeClass('color');
            break;
        case 2:
            $pwdParent.addClass('yellow').removeClass('red green');
            $pwdIntensity.filter('.low,.mid').addClass('color');
            $pwdIntensity.filter('.high').removeClass('color');
            break;
        case 3:
            $pwdParent.addClass('green').removeClass('yellow red');
            $pwdIntensity.addClass('color');
            break;
    }

    //提示框
    if (pwd === '') {
        $pwdTip1.removeClass('red yes no').addClass('default');
    } else if (pwd.length < 6 || pwd.length > 20) {
        $pwdTip1.removeClass('default yes').addClass('no red');
    } else {
        $pwdTip1.removeClass('default no red').addClass('yes');
    }

    if (pwdRegx.test(pwd)) {
        hasNoErrPw = true;
    } else {
        hasNoErrPw = false;
    }
}

//IE8 placeholder
$('input').placeholder();

$('.va').keyup(function() {
    var pass = true;

    if ($(this).hasClass('pwd')) {
        pwdKeyupEvt();
    } else {
        if ($(this).val() === '') {
            pass = false;
        }
    }
    if (pass && hasNoErrPw && $pwd.val() === $repwd.val()) {
        pass = true;
    } else {
        pass = false;
    }
    if (pass) {
        $next.removeClass('disable').prop('disabled', false);
    } else {
        $next.addClass('disable').prop('disabled', true);
    }
}).blur(function() {
    var $this = $(this),
        v = $this.val();

    if ($this.hasClass('pwd')) {
        if (v === '') {
            $this.addClass('error');
            $pwdErr.removeClass('hide').find('em').text('请输入密码');
        } else if (v.length < 6 || v.length > 20) {
            $this.addClass('error');
            $pwdErr.removeClass('hide').find('em').text('密码只支持6-20位');
        } else if (!pwdRegx.test(v)) {
            $this.addClass('error');
            $pwdErr.removeClass('hide').find('em').text('密码须字母和数字组合');
        } else {
            $pwdErr.addClass('hide');
            if ($repwd.val() !== '') {
                if (v !== $repwd.val()) {
                    $repwd.addClass('error');
                    $repwdErr.removeClass('hide').find('em').text('两次密码输入不一致,请重新输入');
                } else {
                    $repwd.removeClass('error');
                    $repwdErr.addClass('hide');
                }
            }
        }
    } else {
        if (v === '') {
            $this.addClass('error');
            $repwdErr.removeClass('hide').find('em').text('请输入密码确认');
        } else {
            if ($pwd.val() !== '' && v !== $pwd.val()) {
                $this.addClass('error');
                $repwdErr.removeClass('hide').find('em').text('两次密码输入不一致,请重新输入');
            } else {
                $this.removeClass('error');
                $repwdErr.addClass('hide');
            }
        }
    }
}).focus(function() {
    $(this).removeClass('error');

    //focus后错误提示隐藏
    if ($(this).hasClass('pwd')) {
        $pwdErr.addClass('hide');
    } else {
        $repwdErr.addClass('hide');
    }
});

$pwd.focus(function() {
    $pwdErr.addClass('hide');
    $pwdTips.removeClass('hide');
}).blur(function() {
    $pwdTips.addClass('hide');
});

$('#pwd, #repwd').keydown(function(e) {
    var code = e.keyCode || e.which;

    //空格输入过滤
    if (code === 32) {
        e.preventDefault();
        return;
    }
});

});
define("js/passport/vertification", ["jquery"], function(require, exports, module){
/**
 * 验证手机
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/12/14
 */

var $ = require("jquery");

var $sc = $('#send-captcha'),
    $msgTip = $('#captcha-tip'),
    $errTip = $('#err-tip'),
    $next = $('#next-step'),
    seconds,
    itime;

$sc.click(function() {
    $.post('/passport/back/sendbackmobile', {
        mobile: $('#mobile').val(),
        area: $('#area').val(),
        verifyCode: $('#captchaPic').val()
    }, function(jsonData) {
        if (jsonData.code === 200) {
            $errTip.hide();
            if ($(this).hasClass('disable')) {
                return;
            }
            seconds = 60;

            //$sc.addClass('disable').prop('disabled', true);
            $sc.addClass('disable').attr('disabled', true);
            $msgTip.removeClass('hide');

            $sc.val(seconds-- + '秒后可重新操作');
            itime = setInterval(function() {
                if (seconds === 0) {
                    clearInterval(itime);

                    //$sc.val('发送验证码').removeClass('disable').prop('disabled', false);
                    $sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
                } else {
                    $sc.val(seconds-- + '秒后可重新操作');
                }
            }, 1000);
        } else {
            $(this).addClass('error');
            $errTip.removeClass('hide').text('发送失败');
        }
    });
});

if ($(this).hasClass('disable')) {
    return;
}
seconds = 60;

//$sc.addClass('disable').prop('disabled', true);
$sc.addClass('disable').attr('disabled', true);
$msgTip.removeClass('hide');

$sc.val(seconds-- + '秒后可重新操作');
itime = setInterval(function() {
    if (seconds === 0) {
        clearInterval(itime);

        //$sc.val('发送验证码').removeClass('disable').prop('disabled', false);
        $sc.val('发送验证码').removeClass('disable').removeAttr('disabled');
    } else {
        $sc.val(seconds-- + '秒后可重新操作');
    }
}, 1000);


$('#captcha').keyup(function() {
    var v = $.trim($(this).val()),
        that = this;

    if (v.length === 4) {
        $.ajax({
            type: 'POST',
            url: '/passport/back/backmobile',
            dataType: 'json',
            data: {
                code: $('#captcha').val(),
                verifyCode: $("#captchaPic").val(),
                area: $('#area').val(),
                mobile: $('#mobile').val()
            },
            success: function(res) {
                if (res.code === 200) {

                    //添加验证码正确验证
                    $next.removeClass('disable').attr('href', res.data);
                    $errTip.addClass('hide');
                    $(that).removeClass('error');
                } else {
                    $next.addClass('disable');
                    $errTip.removeClass('hide').find('em').text('验证码输入错误');
                    $(that).addClass('error');
                }
            }
        });
    }
}).blur(function() {
    var v = $.trim($(this).val());

    if (v === '') {

        //添加验证码正确验证
        $(this).addClass('error');
        $errTip.removeClass('hide').text('请输入验证码');
    }
}).focus(function() {
    $(this).removeClass('error');
});
});
define("js/passport/thirdlogin", ["jquery"], function(require, exports, module){
/**
 * 第三方登录首页
 * @author: wq
 * @date: 2016/1/21
 */
var $ = require("jquery");
var nopermissionoption = $('#nopermissionmessage').html(); //倒计时dom
var sendmessagehtml = $('.validatewrapper').html(); //发送短信dom
var second = +$('.second').text(); //倒计时秒数
var dovalidate = false; //校验验证码标识
var validatecode = false; //验证码是否通过
var choosedpic = 'http://cdn.yoho.cn/yohobuy/assets/img/passport/choosed.png';//已选择图片

var $wrapper = $('.bindwrapper'),
    $phoneTip = $wrapper.find('.phone-err-tip'),
    $nextBtn = $wrapper.find('.yohobindbtn');

/**
 * 选择协议
 * @return {[type]} [description]
 */
function chooseProtocol() {
    $('.choosetag').on('change', function() {
        var btnColor = '#f02200';

        if ($(this).attr('checked') === 'checked') {
            $('.choosewrapper').css({
                'background-image': 'url("' + choosedpic + '")'
            });
        } else {
            $('.choosewrapper').css({
                'background-image': 'none'
            });
            btnColor = '#CCCCCC';
        }
        $nextBtn.css({
            'background-color': btnColor
        });
    });
}
/**
 * 判断是否同意协议
 * @return {[type]} [description]
 */
function isagree() {
    return $('.choosetag').attr('checked') === 'checked';
}
/**
 * 选择区域的开关
 * @return {[type]} [description]
 */
function chooseAreaToogle() {
    $('.optionshow').on('click', function() {
        $('.optionslist').toggleClass('hide');
    });
}

/**
 * 验证码校验
 * @return {[type]} [description]
 */
function codeValidate() {
    var validatenum = '';

    $(document).on('keyup', '#validatenum', function() {
        validatenum = $(this).val();
        if (validatenum.length === 4) {
            if (!dovalidate) {
                dovalidate = true;
                $.ajax({
                    type: 'POST',
                    url: '/passport/autouserinfo/checkBindMsg',
                    data: {
                        code: validatenum,
                        mobile: $('#mobile').val(),
                        area: $('#area').val()
                    }
                }).then(function(data) {
                    dovalidate = false;
                    if (data.code === 200) {
                        validatecode = true;
                    } else {
                        alert(data.message);
                    }
                });
            }
        }
    });
}

/**
 * 选择区域
 * @return {[type]} [description]
 */
function chooseArea() {
    $('.optionitem').on('click', function() {
        var $option = $(this);
        var areanum = $option.attr('areanum');
        var areaname = $option.text();

        $('#areaname').text(areaname);
        $('#areanum').text(areanum);
        $('#areacode').val(areanum);
        $('.optionslist').addClass('hide');
    });
}
/**
 * 取消选择区域
 * @return {[type]} [description]
 */
function cancelChooseArea() {
    $(document).on('click', 'body', function(e) {
        var $target = $(e.target);

        if ($target.hasClass('yohoselectarea') ||
            $target.hasClass('areaname') ||
            $target.hasClass('righttag') ||
            $target.hasClass('optionslist') ||
            $target.hasClass('optionitem')) {
            return;
        } else {
            $('.optionslist').addClass('hide');
        }
    });
}
/**
 * 去掉区域号的加号
 * @return {[type]} [description]
 */
function fixAreaNum() {
    var $opitem = '';
    var itemarecode = '';

    $('.optionitem').each(function() {
        $opitem = $(this);
        itemarecode = $opitem.attr('areanum').replace(/\+/g, '');
        $opitem.attr('areanum', itemarecode);
    });
}

/**
 * 关闭蒙层
 * @return {[type]} [description]
 */
function closeMask() {
    var $target;

    $(document).on('click', '#alreayregist', function(e) {
        $target = $(e.target);
        if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
            $('#alreayregist').hide();
            $('.backdrop').hide();
        }
    });
    $(document).on('click', '#bindconfirm', function(e) {
        $target = $(e.target);
        if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
            $('#bindconfirm').hide();
            $('.backdrop').hide();
        }
    });
}
/**
 * 绑定其他手机号
 * @return {[type]} [description]
 */
function yohoBindBtn() {
    $(document).on('click', '#yohobindbtn', function(e) {
        $('.phonenum').val('');
        $('#bindconfirm').hide();
        $('.backdrop').hide();
    });
    $(document).on('click', '#yohobindbtn2', function(e) {
        $('.phonenum').val('');
        $('#alreayregist').hide();
        $('.backdrop').hide();
    });
}
/**
 * 发送短信的时间变换动画
 * @return {[type]} [description]
 */
function changeSecond() {
    second -= 1;
    if (second < 0) {
        second = 60;
        $('.validatewrapper').html(sendmessagehtml);
        return;
    } else {
        $('.second').text(second);
        window.setTimeout(changeSecond, 1000);
    }

}
/**
 * 时间循环
 * @param  {[type]} phonenum [description]
 * @return {[type]}          [description]
 */
function circleTime(phonenum) {
    $('.validatewrapper').html(nopermissionoption);
    window.setTimeout(changeSecond, 1000);
}
/**
 * 发送短信
 * @return {[type]} [description]
 */
function sendMessageValidate() {
    $(document).on('click', '#sendmessage', function() {
        if ($('#sendmessage').attr('disabled') === 'disabled') {
            return;
        }
        circleTime($('#mobile').val());
        $.ajax({
            type: 'POST',
            url: '/passport/autouserinfo/sendBindMsg',
            data: {
                mobile: $('#mobile').val(),
                area: $('#area').val()
            }
        }).then(function(data) {
            if (data.code !== 200) {
                alert(data.message);
            }
        });

    });
}

/**
 * 最终提交表单
 */
function actionSubmit() {
    var mobile = '';
    var area = '';

    area = $('#area').val();
    mobile = $('#mobile').val();
    $.ajax({
        type: 'POST',
        url: '/passport/autouserinfo/bindMobile',
        data: {
            area: area,
            openId: $('#openId').val(),
            sourceType: $('#sourceType').val(),
            mobile: mobile
        }
    }).then(function(data) {
        if (data.code === 201) {
            window.location.href = '/passport/thirdlogin/bindsuccess';
        } else {
            alert(data.message);
        }
    });
}

/**
 * 确认去绑定
 * @return {[type]} [description]
 */
function goToBindPhone() {
    $(document).on('click', '#gotobindphone', function() {
        if (validatecode === true) {
            $('#inarea').val($('#areanum').val());
            $('#inmobile').val($('#mobile').val());
            actionSubmit();
        } else {
            alert('请输入正确验证码');
        }
    });
}
/**
 * 无交互的发送短信
 * @return {[type]} [description]
 */
function sendMessage() {
    var mobile = '';
    var area = '';

    mobile = $('#mobile').val();
    area = $('#areanum').text();
    $.ajax({
        type: 'POST',
        url: '/passport/autouserinfo/sendBindMsg',
        data: {
            mobile: mobile,
            area: area
        }
    }).then(function(data) {
        if (data.code !== 200) {
            console.log(data.message);
        }
    });
}
/**
 * 点击下一步
 * @return {[type]} [description]
 */
function nextStep() {
    var openId = '';
    var sourceType = '';
    var mobile = '';
    var areaCode = '';
    var username = '';
    var headImg = '';

    $('#bindfirststep').on('click', function(e) {
        e.preventDefault();
        mobile = $('.phonenum').val();
        areaCode = $('#areanum').text();
        if (!isagree()) {
            return;
        }
        if (mobile === '') {
            $phoneTip.find('em').text('手机格式错误');
            $phoneTip.removeClass('hide');
            return;
        }
        openId = $('#openId').val() || '29803EC6D4AAC3AAB8ABDB6AE829D579';
        sourceType = $('#sourceType').val() || 'qq';
        $.ajax({
            type: 'post',
            url: '/passport/autouserinfo/bindCheck',
            data: {
                mobile: mobile,
                area: areaCode,
                openId: openId,
                sourceType: sourceType
            },
            dataType: 'json',
            success: function(data) {
                if (data.code === 200) {
                    $('#bindmobileform').attr('action', '/passport/thirdlogin/noregist');
                    sendMessage();
                    $('#bindmobileform').submit();
                }
                if (data.code === 400 || data.code === 402) {
                    $phoneTip.find('em').text('手机格式错误');
                    $phoneTip.removeClass('hide');
                }
                if (data.code === 506) {
                    username = data.data.user.username;
                    headImg = data.data.user.headImg;
                    $('#registphone').text(mobile);
                    $('#username').text(username);
                    if (headImg === '') {
                        $('#userphoto').attr('src', 'http://img10.static.yhbimg.com/headimg/2013/11/28/09/' +
                            '01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100');
                    } else {
                        $('#userphoto').attr('src', headImg);
                    }
                    $('#logindirectly2').attr('href', data.data.user.bindLogin);
                    $('.backdrop').show();
                    $('#alreayregist').show();
                }
                if (data.code === 505) {
                    username = data.data.user.username;
                    headImg = data.data.user.headImg;
                    $('#registphonetwo').text(mobile);
                    $('#username1').text(username);
                    if (headImg === '') {
                        $('#userphoto1').attr('src', 'http://img10.static.yhbimg.com/headimg/2013/11/28/09/' +
                            '01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100');
                    } else {
                        $('#userphoto').attr('src', headImg);
                    }
                    $('#logindirectly').attr('href', data.data.user.bindLogin);
                    $('.backdrop').show();
                    $('#bindconfirm').show();
                }
            }
        });
    });
}

function init() {
    fixAreaNum(); //去掉所有区域的+
    sendMessageValidate(); //有交互的发送短信
    chooseProtocol(); //选择协议
    chooseArea(); //选择区域
    chooseAreaToogle(); //选择区域展示或关闭
    cancelChooseArea(); //取消选择区域
    nextStep();  //下一步
    closeMask(); //关闭蒙层
    yohoBindBtn(); //绑定其他手机号点击
    goToBindPhone(); //绑定手机
    codeValidate(); //验证码校验
}
init();
});
define("js/passport/third-pwd", ["jquery"], function(require, exports, module){
/**
 * 第三方绑定完善个人信息
 * @author: wq
 * @date: 2016/1/27
 */
var $ = require("jquery");
var dovalidate = false; //校验验证码的标识
var isvalidatecode = false; //是否验证成功的标识
var isvalidatepwd = false; //密码验证是否通过的标识
var second = ''; //倒计时时间
var nopermissionoption = ''; //倒计时的dom
var sendmessagehtml = ''; //发送短信的dom

var $wrapper = $('.bindwrapper'),
    $codeTip = $wrapper.find('.code-err-tip'),
    $pwdTip = $wrapper.find('.pwd-err-tip');
var $pwd,
    $pwdParent,
    $pwdTip1,
    $pwdIntensity;

var pwdRegx = require("js/passport/mail-phone-regx").pwdValidateRegx;

nopermissionoption = $('#nopermissionmessage').html();
sendmessagehtml = $('.validatewrapper').html();
second = +$('.second').text();


function gettype(str, i) {
    if (str.charCodeAt(i) >= 48 && str.charCodeAt(i) <= 57) {
        return 1;
    } else if (str.charCodeAt(i) >= 97 && str.charCodeAt(i) <= 122) {
        return 2;
    } else if (str.charCodeAt(i) >= 65 && str.charCodeAt(i) <= 90) {
        return 3;
    }

    return 4;
}

function isregular(cur, pre, type) {
    var curCode = cur.charCodeAt(0);
    var preCode = pre.charCodeAt(0);

    if (curCode - preCode === 0) {
        return true;
    }

    if (type !== 4 && (curCode - preCode === 1 || curCode - preCode === -1)) {
        return true;
    }

    return false;
}


function getcomplex(curType, preType) {
    if (preType === 0 || curType === preType) {
        return 0;
    } else if (curType === 4 || preType === 4) {
        return 2;
    } else {
        return 1;
    }
}


/**
 * @desc: 计算密码复杂度(from:http://www.oschina.net/code/snippet_127301_17269)
 * @author: xuqi(qi.xu@yoho.cn)
 * @date: 2015/5/6
 */
function computeComplex(password) {
    var complex = 0;
    var length = password.length;
    var pre = '';
    var preType = 0;
    var i = 0;
    var cur = '';
    var curType = '';

    for (i; i < length; i++) {
        cur = password.charAt(i);
        curType = gettype(password, i);
        if (preType !== curType || !isregular(cur, pre, curType)) {
            complex += curType + getcomplex(curType, preType);
        }
        pre = cur;
        preType = curType;
    }

    return complex;
}

function showErrTip($dom, info) {
    $dom.find('em').text(info);
    $dom.removeClass('hide');
}

function changeSecond() {
    second -= 1;
    if (second < 0) {
        second = 60;
        $('.validatewrapper').html(sendmessagehtml);
        return;
    } else {
        $('.second').text(second);
        window.setTimeout(changeSecond, 1000);
    }

}
/**
 * 启动倒计时
 * @return {[type]} [description]
 */
function circleTime() {
    $('.validatewrapper').html(nopermissionoption);
    window.setTimeout(changeSecond, 1000);
}

function sendMessageValidate() {
    var mobile = '';
    var area = '';

    $(document).on('click', '#sendmessage', function() {
        circleTime();
        mobile = $('#mobile').val();
        area = $('#area').val();
        $.ajax({
            type: 'POST',
            url: '/passport/autouserinfo/sendBindMsg',
            data: {
                mobile: mobile,
                area: area
            }
        }).then(function(data) {
            if (data.code !== 200) {
                alert(data.message);
            }
        });

    });
}



function codeValidate() {
    var validatenum = '';

    $(document).on('keyup', '#validatenum', function() {
        $('#err-info').hide();
        validatenum = $(this).val();
        if (validatenum.length === 4) {
            if (!dovalidate) {
                dovalidate = true;
                $.ajax({
                    type: 'POST',
                    url: '/passport/autouserinfo/checkBindMsg',
                    data: {
                        code: validatenum,
                        mobile: $('#mobile').val(),
                        area: $('#area').val()
                    }
                }).then(function(data) {
                    dovalidate = false;
                    if (data.code !== 200) {
                        $('#err-info').show();
                    } else {
                        isvalidatecode = true;
                    }
                });
            }
        }
    });
}

function pwdKeyupEvt() {
    var pwd = $pwd.val(),
        pwdStrength = computeComplex(pwd),
        level = 0;

    if (pwdStrength === 0) {
        level = 0;
    } else if (pwdStrength <= 10) {
        level = 1;
    } else if (pwdStrength <= 20) {
        level = 2;
    } else {
        level = 3;
    }
    switch (level) {
        case 0:
            $pwdParent.removeClass('red yellow green');
            $pwdIntensity.removeClass('color');
            break;
        case 1:
            $pwdParent.addClass('red').removeClass('yellow green');
            $pwdIntensity.filter('.low').addClass('color');
            $pwdIntensity.filter('.mid,.high').removeClass('color');
            break;
        case 2:
            $pwdParent.addClass('yellow').removeClass('red green');
            $pwdIntensity.filter('.low,.mid').addClass('color');
            $pwdIntensity.filter('.high').removeClass('color');
            break;
        case 3:
            $pwdParent.addClass('green').removeClass('yellow red');
            $pwdIntensity.addClass('color');
            break;
    }
    if (pwd === '') {
        isvalidatepwd = false;
        $pwdTip1.removeClass('red yes no').addClass('default');
    } else {
        if (pwd.length < 6 || pwd.length > 20) {
            isvalidatepwd = false;
            $pwdTip1.removeClass('default yes').addClass('no red');
        } else {
            isvalidatepwd = true;
            $pwdTip1.removeClass('default no red').addClass('yes');
        }
    }
}

function validatePwd() {
    $(document).on('keyup', '.pwdcontent', function() {
        pwdKeyupEvt($(this));
    });
    $(document).on('focus', '.pwdcontent', function() {
        $('#pwd-tips').removeClass('hide');
    });
    $(document).on('blur', '.pwdcontent', function() {
        $('#pwd-tips').addClass('hide');
    });
}

/**
 * 最终提交表单
 */
function actionSubmit() {
    var mobile = '';
    var area = '';
    var pwd = '';
    var code = '';

    area = $('#area').val();
    pwd = $('#pwd').val();
    mobile = $('#mobile').val();
    code = $('#validatenum').val();
    $.ajax({
        type: 'POST',
        url: '/passport/autouserinfo/bindMobile',
        data: {
            area: area,
            openId: $('#openId').val(),
            sourceType: $('#sourceType').val(),
            mobile: mobile,
            password: pwd,
            code: code
        }
    }).then(function(data) {
        if (data.code === 200) {
            window.location.href = '/passport/thirdlogin/bindsuccess';
        } else {
            alert(data.message);
        }
    });
}
/**
 * 确定完善信息
 * @return {[type]} [description]
 */
function actionConfirm() {
    var validatenum = '';
    var pwd = '';

    $('#confirmsubmit').on('click', function() {
        var isAssess = true;

        validatenum = $('#validatenum').val();
        pwd = $('#pwd').val();

        if (validatenum === '') {
            showErrTip($codeTip, '短信验证码不能为空');
            isAssess = false;
        } else if (isvalidatecode === false) {
            showErrTip($codeTip, '请输入正确的验证码');
            isAssess = false;
        }

        if (pwd === '') {
            showErrTip($pwdTip, '密码不能为空');
            isAssess = false;
        } else if (pwd.length < 6 || pwd.length > 20) {
            showErrTip($pwdTip, '密码只支持6-20位字符');
            isAssess = false;
        } else if (!pwdRegx.test(pwd)) {
            showErrTip($pwdTip, '密码须由字母和数字组合');
            isAssess = false;
        } else if (isvalidatepwd === false) {
            showErrTip($pwdTip, '请输入符合强度的密码');
            isAssess = false;
        }

        if (!isAssess) {
            return;
        }

        actionSubmit();
    });
}



function init() {
    circleTime(); //倒计时
    $pwd = $('#pwd');
    $pwdParent = $('.safelevel');
    $pwdIntensity = $('.pwd-intensity');
    $pwdTip1 = $('#pwd-tip1');
    sendMessageValidate();
    codeValidate();
    validatePwd();
    actionConfirm();
}

init();

});
define("js/order/ensure", ["jquery"], function(require, exports, module){
/**
 * @description: 订单保存
 * @time: 2015/12/21
 */

var $ = require("jquery");

var address = require("js/order/address");

var Order = {
    /*业务数据(人民币)*/
    Data: {
        product: 0,//商品价格
        activity: 0,//活动
        carriage: 0,//邮费
        juan: 0,//优惠卷
        yohocoin: 0//有货币
    },
    /*view 交互*/
    UI: {
        e: {
            $pan: $('.pan'),
            $jc: $('#juancode'),
            $bp: $('#biprice'),
            $statistics: $('li', '.play-total'),
            $tobi: $('p em', '.play-bi-pan .play-pan'),
            $cancel: $('.cancel', '.btn-group'),
            $total: $('em', '.to-play'),
            $tbody: $('table tbody', '.pay-wapper'),

            //请填写并核对一下信息
            $orderSelectionSave: $('.address-list h2 span'),
            $addAddress: $('.add-address'),
            $addressManage: $('.address-manage'),
            $spanPayTypeLegend: $('span.pay-type-legend'),
            $supportType: $('.support-type'),
            $existAddressList: $('.exist-address-list').find('li'),
            $existAddress: $('.exist-address-list').find('input[name="exist-address"]'),
            $payTimeModify: $('.pay-time-modify'),
            $switchPayModify: $('.switch-pay-modify')
        },
        init: function() {
            var e = this.e,
            d = Order.Data,
            c = Order.Common;

            /*初始化产品价格*/
            e.$tbody.find('tr').each(function(index) {
                var td = $(this).find('td');
                var len = e.$tbody.find('tr').length;
                var subtotal = parseFloat(td.eq(1).html()) * parseInt(td.eq(3).html());

                td.eq(4).html(c.strFixed(subtotal));
                d.product += subtotal;
                if (!index) {
                    td.last().attr('rowspan', len);
                } else {
                    td.last().remove();
                }
                if (index === len - 1) {
                    e.$tbody.find('tr').eq(0).find('td').last().html('<strong>' + c.strFixed(d.product) + '</strong>');
                }
            });



            /*初始化价格*/
            this.render();

            /*点击pan dt 打开dd*/
            e.$pan.find('dt').click(function() {
                var pan = $(this).parent('dl.pan');

                if (pan.find('dd').is(':hidden')) {
                    c.winShow(pan);
                } else {
                    c.winHide(pan);
                }

            });

            /*使用优惠卷支付 下面的文本框*/
            e.$jc.on('focus change', function(event) {
                var radio = $(this).prev('label').prev(':radio');

                if (event.type === 'focus') {
                    radio.attr('checked', true);
                } else {
                    radio.val($(this).val());
                }

            });

            /*使用有货币支付*/
            e.$bp.data('tobi', e.$tobi.html());
            e.$bp.on('keyup change', function() {
                var bi = c.enterNUM($(this).val(), $(this).data('tobi'));

                $(this).val(bi);
            });

            /*取消关闭小窗口*/
            e.$cancel.click(function() {
                var pan = $(this).parents('.pan');

                c.winHide(pan);
            });

            e.$statistics.slice(3, 5).find('a').click(function() {
                var pan = $('.' + $(this).attr('to'));

                c.winShow(pan);
            });


            //请填写并核对一下信息
            e.$orderSelectionSave.click(function() {

                if (!$(this).data('expand')) {
                    $('.address-list-inner').addClass('hide');

                    $(this).data('expand', 'expand').text('[不保存并关闭]');

                } else {
                    $('.address-list-inner').removeClass('hide');

                    $(this).removeData('expand').text('[修改]');
                }

            });


            //支付及送货时间
            e.$switchPayModify.click(function() {

                if (e.$payTimeModify.hasClass('hide')) {
                    e.$payTimeModify.removeClass('hide');
                    $(this).text('[不保存并关闭]');
                } else {
                    e.$payTimeModify.addClass('hide');
                    $(this).text('[修改]');
                }
            });

            e.$spanPayTypeLegend.click(function() {
                $(this).toggleClass('active');

                e.$supportType.toggleClass('hide');
            });

            $(document).on('click', '.exist-address-list li', function() {

                e.$existAddressList.removeClass('active');
                $(this).addClass('active');

                e.$existAddress.removeAttr('checked');
                $(this).find('input[name="exist-address"]').attr('checked', 'checked');

                if ($(this).hasClass('use-new-address')) {
                    e.$addressManage.removeClass('hide');
                }
            });
        },

        //渲染价格明细
        render: function() {
            var e = this.e,
            d = Order.Data,
            c = Order.Common;
            var i = 0;

            e.$total.html('0.00');
            e.$statistics.find('em').html('0.00');
            e.$statistics.slice(3, 5).hide();

            $.each(d, function(key) {
                if (d.hasOwnProperty(key)) {
                    if (d[key]) {
                        e.$statistics.eq(i).show().find('em').html(c.strFixed(d[key]));
                    }
                }
                i++;
            });
            e.$total.html(c.strFixed(c.calucate()));

        }
    },
    /*公共方法*/
    Common: {
        enterNUM: function(str1, str2) {
            str1 = str1.replace(/[^\d]/g, '');
            if (str1 && str2) {
                str1 = parseInt(str1);
                str2 = parseInt(str2);
                if (str1 > str2) {
                    str1 = str2;
                }
            }
            return str1;
        },
        calucate: function() {
            var p = Order.Data;

            $.each(Order.Data, function(key, index) {
                p[key] = parseFloat(Order.Data[key]);
            });
            return p.product - p.activity + p.carriage - p.juan - p.yohocoin;
        },
        winShow: function(pan) {
            pan.find('dt').show();
            pan.find('dd').show();
            if (pan.attr('class').match(/(-bi-)|(-juan-)/g)) {
                pan.find('dt').hide();
            }
        },
        winHide: function(pan) {
            pan.find('dt').show();
            pan.find('dd').hide();
        },
        strFixed: function(str) {
            return parseFloat(str).toFixed(2);
        }
    },
    /*业务逻辑*/
    Bll: {
        e: {
            $juanok: $('#juansubmit'),
            $juantip: $('.errtip', '.play-juan-pan'),
            $biok: $('#bisubmit'),
            $carriageGroup: $('input[name="carriagegroup"]')
        },
        init: function() {
            var e = this.e,
                d = Order.Data,
                c = Order.Common,
                u = Order.UI;
            var options;

            e.$carriageGroup.change(function() {
                d.carriage = parseFloat($(this).val());
                u.render();
            });
            /*点击 优惠卷支付 确认按钮*/
            e.$juanok.click(function() {
                var code = $('input[name="juangroup"]:checked').val();
                var pan = $(this).parents('.pan');

                if (code) {
                    options = {
                        url: '/Order/save/priceByCode',
                        type: 'post',
                        data: {
                            code: code
                        },
                        success: function(data) {
                            if (data.code === 200) {
                                if (data.price) {
                                    d.juan = data.price;
                                    Order.UI.render();
                                    c.winHide(pan);
                                    return;
                                }
                                u.render();
                            }
                            e.$juantip.html(data.msg);
                        },
                        error: function() {
                            e.$juantip.html('网络出现错误~');
                        }
                    };

                    $.ajax(options);
                }
            });
            /*点击 有货币支付 确认按钮*/
            e.$biok.click(function() {
                var pan = $(this).parents('.pan');

                d.yohocoin = parseFloat(u.e.$bp.val()) / 100;
                u.render();
                c.winHide(pan);
                return;
            });
        }
    }
};

Order.Data.activity = 0;
Order.Data.carriage = 0;

Order.UI.init();
Order.Bll.init();


address.newAddress();
address.modifyAddress();
address.saveAddress();

});
define("js/order/address", ["jquery"], function(require, exports, module){
/**
 * @description: 地址管理
 * @author: chenglong.wang@yoho.cn
 */

var $ = require("jquery");

var isProvinceChecked = false;

var $addressManage = $('.address-manage'),
    $province = $addressManage.find('.text-input[name="province"]'),
    $city = $addressManage.find('.text-input[name="city"]'),
    $county = $addressManage.find('.text-input[name="county"]'),
    $selectList = $addressManage.find('.text-input[name="province"], .text-input[name="city"]'),
    $addressList = $('.address-list'),
    $name = $addressManage.find('.text-input[name="name"]'),
    $phone = $addressManage.find('.text-input[name="phone"]'),
    $telCode = $addressManage.find('.text-input[name="code-tel"]'),
    $tel = $addressManage.find('.text-input[name="tel"]'),
    $mail = $addressManage.find('.text-input[name="mail"]'),
    $address = $addressManage.find('.text-input[name="address"]'),
    $code = $addressManage.find('.text-input[name="code"]'),
    $saveBtn = $('.save-btn');

function structureOption($obj, data) {

    var key,
        optionHtml,
        defaultOption;

    for (key in data) {

        if (data[key].checked) {
            optionHtml += '<option selected value="' + data[key].value + '">' + data[key].name + '</option>';
        } else {
            optionHtml += '<option value="' + data[key].value + '">' + data[key].name + '</option>';
        }


    }

    $obj.html(optionHtml);

    if ($obj.attr('name') === 'province') {
        defaultOption = '<option value="0">请选择省份</option>';
    } else if ($obj.attr('name') === 'city') {
        defaultOption = '<option value="0">请选择城市</option>';
    } else if ($obj.attr('name') === 'county') {
        defaultOption = '<option value="0">请选择区县</option>';
    }
    $obj.prepend($(defaultOption));

}
/**
 * @description: 改函数会返回地址信息
 * d {Object} type: 'getProvince'获取省 type: 'getCity'获取城市 type: 'getCounty'获取县
 * id: 0 && type: 'getProvince' 获取所有省,默认没有选中项
 * id !== 0 && type: 'getProvince' 获取所有省,默认选中用户所在的省
 */
function getAddress(d, callback) {

    var $obj,
        url;

    if (d.type === 'getProvince') {
        url = 'getProvince';

        $obj = $province;
    } else if (d.type === 'getCity') {
        url = 'getCity';

        $obj = $city;
    } else if (d.type === 'getCounty') {
        url = 'getCounty';

        $obj = $county;
    }
    $.ajax({
        type: 'post',
        url: '/order/save/' + url,
        dataType: 'json',
        data: {
            id: d.id
        }
    }).then(function(data) {

        structureOption($obj, data);

        if (typeof callback === 'function') {
            callback();
        }

    }).fail(function() {

        //todo
    });
}

function getUserInfo(id) {
    $.ajax({
        type: 'post',
        url: 'getUserInfo',
        data: {
            id: id
        }
    }).then(function(data) {
        var key;

        for (key in data) {

            if (data.hasOwnProperty(key)) {
                if (!!data[key]) {
                    eval('$' + key).val(data[key]);
                }
            }
        }

    }).fail(function() {

    });
}

//添加地址
exports.newAddress = function(id) {

    var pId = id !== 'undefined' ? id : 0;

    if (!!pId) {
        getUserInfo();
    }

    //获取省
    getAddress({
        id: pId,
        type: 'getProvince'
    }, function() {

        var provinceId = $province.val();

        if (provinceId !== '0') {

            //如果获取的省有默认选中项则获取市
            getAddress({
                id: provinceId,
                type: 'getCity'
            }, function() {

                var cityId = $city.val();

                //如果获取的市有默认选中项则获取县
                if (cityId !== '0') {
                    getAddress({
                        id: cityId,
                        type: 'getCounty'
                    });
                }
            });
        }
    });

    $selectList.change(function() {
        var $this = $(this);

        if ($this.attr('name') === 'province') {
            getAddress({
                id: $this.val(),
                type: 'getCity'
            }, function() {
                isProvinceChecked = true;
            });
        }

        if ($this.attr('name') === 'city' && isProvinceChecked) {
            getAddress({
                id: $this.val(),
                type: 'getCounty'
            });
        }
    });
};

//修改地址
exports.modifyAddress = function() {

    $addressList.click(function(event) {
        var $this = $(event.target),
            id = $this.closest('li').find('.radio').attr('id');

        if ($this.hasClass('address-modify')) {
            $addressManage.removeClass('hide');
            exports.newAddress(id);
        } else if ($this.hasClass('address-del')) {

            $.ajax({
                type: 'post',
                url: '/order/save/addressDel',
                data: {
                    id: id
                }
            }).then(function(data) {

                if (!!data.status) {
                    $this.closest('li').remove();
                }
            }).fail(function() {

                //todo
            });
        } else if ($this.hasClass('default-address')) {

            // 设为默认地址
            $.ajax({
                type: 'post',
                url: '/order/save/defaultAddress',
                data: {
                    id: id
                }
            }).then(function(data) {

                if (!!data.status) {
                    $this.remove();
                }
            }).fail(function() {

                //todo
            });
        }
    });
};

exports.saveAddress = function() {
    $saveBtn.click(function() {

        var name = $name.val(),
            province = $province.val(),
            city = $city.val(),
            county = $county.val(),
            address = $address.val(),
            phone = $phone.val(),
            telCode = $telCode.val(),
            tel = $tel.val(),
            mail = $mail.val(),
            code = $code.val(),
            id = new Date();

        $.ajax({
            type: 'post',
            url: '/order/save/addressSave',
            data: {
                name: name,
                province: province,
                city: city,
                county: county,
                address: address,
                phone: phone,
                tel: tel,
                telCode: telCode,
                mail: mail,
                code: code,
                id: id * 1
            }
        }).then(function(data) {

            var addressStr;

            if (!!data.status) {
                addressStr = '<li>' +
                    '<input class="radio" type="radio" name="address" id="' + id * 1 + '" />' +
                    '<label for="' + id * 1 + '">' +
                        '<strong>' + name + '</strong>' +
                        '<span>' + address + '</span>' +
                        '<a href="javascript:void(0);">设为默认地址</a>' +
                        '<div class="order-modify-btn">' +
                            '<span class="address-modify">[修改]</span>' +
                            '<span class="address-del">[删除]</span>' +
                        '</div>' +
                    '</label>' +
                '</li>';

                $('.use-new-address').before($(addressStr));
            }
        }).fail(function() {

            //todo
        });
    });
};
});