attachmentoperation.js 61.3 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
/**
 * 附件操作
 */
// var iphost="http://116.10.196.223:8080/doc-service/";
// var iphost=$("#fileservice").val();
// var rootPath="";// 当前公文附件根目录
var copyPath="";
var currentPath="";
var electronState = "";
var serviceState = "";
var originflag=false;
var attachflag=false;
var gwstate = true;
var username = getUserName();
var attachmentSrc = [];
var operation = false;
var parentid= "-1";
var folderid="-1";
var user_=null;
var pagetype;
var showFlag = "up";
var projectType="";
var openPath = "";


var originaldocFolderId = "";



contentpath=global.contextPath;

//function update_material(doctype){
//	createDirInService(doctype,"general");
//	createDirInService(doctype,"originaldoc");	
//	$("#divNoAttachment,#update_material").css("display","none");
//}
/**
 * 根据目录创建文件夹 发文是默认多创建一级目录:一般附件根目录为:/FW/xxx(uuid)/general
 * 原始来文为:/FW/xxx(uuid)/原始来文
 * 
 * @param doctype
 *            公文类型
 * @returns 目录
 */
function createDirInService(doctype,flodername){
	var type=doctype;
	var iphost=$("#fileservice").val();
	var url=iphost +"ftpfile/createDirectory.do";
	var remotePath="";
	var foldid;
	if($.cookie('uuid')=="null"||$.cookie('uuid')==undefined||$.cookie('uuid')==""){
		foldid=uuid();
		$.cookie('uuid',foldid);
		currentuuid = foldid;
	}else{
		foldid=$.cookie('uuid');
	}
		
	if(doctype=="FW"&&flodername=="general"){
		rootPath=doctype+"/"+foldid+"/general";
	}else if(doctype!="FW"){
		rootPath = doctype+"/"+foldid;
	}

	if(serviceState=="serviceno"){
		if(ftpPathHtml.val()=="")
			ftpPathHtml.val(rootPath);
		else
			rootPath = ftpPathHtml.val();
	}
	if(serviceState=="serviceyes"){
		if(servicepath!="null")
			rootPath = servicepath
	}
	//若当前路径已经包含general文件夹等则不自动创建
	if(doctype=="FW"){
		//这两个文件夹只可以自动创建一次,且是在根目录
		if(currentPath.indexOf("general")!=-1||currentPath.indexOf("originaldoc")!=-1){
		//	flodername=="general"||flodername=="originaldoc"||
			return;
		}
	}

	if(flodername.length==0){
			remotePath=rootPath;
	}else{
		if(currentPath.length==0){
			if(doctype=="FW"&&flodername=="originaldoc"){
				remotePath=doctype+"/"+foldid+"/originaldoc";
				rootPath = doctype+"/"+foldid;
				parentid = getParentId(rootPath);
			}else if(doctype=="FW"&&flodername=="general"){
				remotePath=rootPath;
			}else{
				remotePath=rootPath+"/"+flodername;
			}
		}else{
			remotePath=rootPath+"/"+currentPath+"/"+flodername;
		}		
	}
	
	//档案模块
	if(doctype == "AM"){
		var amFilePath = $("#AMfilePath").val();
		rootPath = amFilePath;
		if(rootPath == ""){
			rootPath = doctype+"/"+uuid();
			remotePath=rootPath+"/"+flodername;
		}else{
			remotePath=rootPath+"/"+flodername;
		}
	}
	
	// 父文件夹ID
	//var parentid = $("#parentid").val();
	
	// 用户ID
	var uid_ = getUserId();
	// 用户名称
	
	$.ajaxSetup({
		async : false //取消异步
	});	
	// params = {remotePath:remotePath,flodername:flodername,parentId:parentid,userId:userId}
    $.post(url,{remotePath:remotePath,
		    	flodername:flodername,
		    	parentId:parentid,
		    	username:username,
		    	userId:uid_}, function (result) {
		  if(result)
		  {
			  if(result.message!="目录已存在!"){
				  if(currentPath.length!=0){
					  listFiles(rootPath+"/"+currentPath);
				  }else{
					  if(type == "FW"){
						  rootPath = doctype+"/"+foldid+"/general"
					  }
					  listFiles(rootPath);
				  }
				  // 更新主表根目录和时间
				  if(doctype =="HY"){
					  updateHytime();
				  }else if(doctype == "ZD"){
					  updateZDRootPath();
				  }else{
					  updaterootortime()
				  }
			  }
/*			  else{
				  layer.msg("目录已存在!",{icon:2}); 
			  }*/
		  return;
		  $("#divNoAttachment").css("display","none");
		  }
	});
   
    return remotePath;
}

function updateZDRootPath(){
	var status=$("#status").val();
	var importid=$("#importid").val();	
	if(importid!=undefined){
		$.post(global.contextPath + "/mvc/major/updateRootPath.do", {importid:importid,rootPath:rootPath},
				 function (result) {
				 
		       });
	}
}

function copyfile(doctype){
	var type=doctype;
	var iphost=$("#fileservice").val();
	var url=iphost +"ftpfile/copyfile.do";
//	var url = "http://127.0.0.1:8081/DocService/ftpfile/copyfile.do";
	var foldid;
	if($.cookie('uuid')=="null"||$.cookie('uuid')==undefined||$.cookie('uuid')==""){
		foldid=uuid();
		$.cookie('uuid',foldid);
	}else{
		foldid=$.cookie('uuid');
	}
	var CopyrootPath = doctype+"/"+foldid;
	$.ajaxSetup({
		async : false //取消异步
	});
//	rootPath = "HY/copy";
	$.post(url,{source:rootPath,target:CopyrootPath}, function (result) {
		  if(result)
		  {
			  if(result.message=="复制成功")
				  copyPath = CopyrootPath;	
		  }
	});
}



//加密算法
function Encrypt(str, pwd) {    
    if(str=="")return "";    
    str = escape(str);    
    if(!pwd || pwd==""){ var pwd="1234"; }    
    pwd = escape(pwd);    
      if(pwd == null || pwd.length <= 0) {    
        alert("Please enter a password with which to encrypt the message.");    
          return null;    
      }    
      var prand = "";    
      for(var I=0; I<pwd.length; I++) {    
        prand += pwd.charCodeAt(I).toString();    
      }    
      var sPos = Math.floor(prand.length / 5);    
      var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));    
      var incr = Math.ceil(pwd.length / 2);    
      var modu = Math.pow(2, 31) - 1;    
      if(mult < 2) {    
        alert("Algorithm cannot find a suitable hash. Please choose a different password. /nPossible considerations are to choose a more complex or longer password.");    
        return null;    
      }    
      var salt = Math.round(Math.random() * 1000000000) % 100000000;    
      prand += salt;    
      while(prand.length > 10) {    
        prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();    
      }    
      prand = (mult * prand + incr) % modu;    
    var enc_chr = "";    
    var enc_str = "";    
    for(var I=0; I<str.length; I++) {    
        enc_chr = parseInt(str.charCodeAt(I) ^ Math.floor((prand / modu) * 255));    
        if(enc_chr < 16) {    
            enc_str += "0" + enc_chr.toString(16);    
        }else    
            enc_str += enc_chr.toString(16);    
        prand = (mult * prand + incr) % modu;    
    }    
      salt = salt.toString(16);    
      while(salt.length < 8)salt = "0" + salt;    
    enc_str += salt;    
    return enc_str;    
} 
//解密算法
function Decrypt(str, pwd) {    
    if(str=="")return "";    
    if(!pwd || pwd==""){ var pwd="1234"; }    
    pwd = escape(pwd);    
      if(str == null || str.length < 8) {    
        alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");    
        return;    
      }    
      if(pwd == null || pwd.length <= 0) {    
        alert("Please enter a password with which to decrypt the message.");    
        return;    
      }    
      var prand = "";    
      for(var I=0; I<pwd.length; I++) {    
        prand += pwd.charCodeAt(I).toString();    
      }    
      var sPos = Math.floor(prand.length / 5);    
      var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));    
      var incr = Math.round(pwd.length / 2);    
      var modu = Math.pow(2, 31) - 1;    
      var salt = parseInt(str.substring(str.length - 8, str.length), 16);    
      str = str.substring(0, str.length - 8);    
      prand += salt;    
      while(prand.length > 10) {    
        prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();    
      }    
      prand = (mult * prand + incr) % modu;    
      var enc_chr = "";    
      var enc_str = "";    
    for(var I=0; I<str.length; I+=2) {    
        enc_chr = parseInt(parseInt(str.substring(I, I+2), 16) ^ Math.floor((prand / modu) * 255));    
        enc_str += String.fromCharCode(enc_chr);    
        prand = (mult * prand + incr) % modu;    
    }    
    return unescape(enc_str);    
} 

/**
 * 添加文件夹按钮事件
 * 
 * @param type
 *            类型
 */
var childfilename;
function adddir(type){	
	layer.open({
		  type: 2,
		  title:'输入文件夹名称',
		  shadeClose: true,
		  area: ['350px', '200px'], //宽高
		  btn: ['确认', '取消'],
		  content: global.contextPath+"/meeting/folder.jsp?type="+type,
		  yes:function(index,layero){
			  var name = childfilename;
			  folerFile(type,name);
		  },
		});
}
//获取创建文件页面文件名
function getfilename(name){
	childfilename = name;
}
//创建文件夹
function folerFile(type,foldname){
	var re =/^[^`~*#%|\\\][\]\{\}:;'\,.<>/?]{1,}$/;
	if(!re.test(foldname)){
		layer.msg("创建失败,目录存在特殊字符!",{icon:0});
		return;
	}
	var isOK = true;
	// 当前文件夹全路径
	var cPath = rootPath;
	if(currentPath && currentPath != ""){
		cPath = rootPath + "/" + currentPath;
	}

	var url =$("#fileservice").val() + "ftpfile/list.do";
	$.post(url,{target:cPath}, function (result) {
		var files = result;
		if(files && files.length>0){
			for(var i=0;i<files.length;i++){
				var f = files[i];
				if(f.name == foldname){
					isOK = false;
					break;
				}
			}
		}
		if(isOK){
			userid_ = $("#userid_").val();
			if(type=="FW"&&rootPath.length==0){
				createDirInService(type,"general");
				createDirInService(type,"originaldoc");
			}
			createDirInService(type,foldname);
			layer.closeAll();
		}else {
			layer.closeAll();
			layer.msg("创建失败,目录已存在!",{icon:0});
		}
	});
}


/**
 *js截取字符串,中英文都能用
 *@param str:需要截取的字符串 
 *@param len: 需要截取的长度
 */
function cutstr(str,len)  
{  
   var str_length = 0;  
   var str_len = 0;  
      str_cut = new String();  
      str_len = str.length;  
      for(var i = 0;i<str_len;i++)  
     {  
        a = str.charAt(i);  
        str_length++;  
        if(escape(a).length > 4)  
        {  
         //中文字符的长度经编码之后大于4  
         str_length++;  
         }  
         str_cut = str_cut.concat(a);  
         if(str_length>=len)  
         {  
         str_cut = str_cut.concat("...");  
         return str_cut;  
         }  
    }  
    //如果给定字符串小于指定长度,则返回源字符串;  
    if(str_length<len){  
     return  str;  
    }  
}


/**
 * 文件列表
 * 
 * @param node
 *            列表的节点 div-attachment
 * @param path
 *            当前路径
 * @returns
 */
function listFiles(cupath,morere,auxiliariesNumber,listname){
		
	var iphost=$("#fileservice").val();
	var foldid=$.cookie('uuid');
	var path;
	var node;
	var head;
	var isGG="";
	var rootbool = false;
	//判断传入的是否为根目录
	if(rootPath==cupath)
		rootbool = true;
	if(serviceState =="serviceyes"){
		rootbool = true;	
	}
	if(cupath==undefined||cupath.length==0){
		path=rootPath;
	}else{
		path=cupath;
	}
	if(cupath==null||cupath==undefined){
		return;
	}else{			
	/*公告附件  20160629  hepo*/
		if(cupath.indexOf("GG")!=-1){
			node = $(".div-notice-attachment");
			isGG="true";
			rootPath=cupath;
		}else{
			if(serviceState =="serviceno")
				node = attachmentHtml;
			else if(serviceState=="serviceyes")
				node = $('.div-attachment'+attHtml);
			else
				node = $(".div-attachment");
		}
	}	
	node.children().filter('div').remove();
	var paths = currentPath.split("/");
	var pathdir="";
	var clickpath="";
	if(paths[0].length!=0){
	if(paths.length>3){
		var patgsArr = paths.slice(-3);
		var index = paths.length-3;
		for(var i=0;i<patgsArr.length;i++){
			rootbool = false;
			var pathArrStr = ""
			if(clickpath.length==0){
				for(var m=0;m<index;m++){
					if(pathArrStr.length==0)
						pathArrStr = paths[m];
					else{
						pathArrStr = pathArrStr + "/"+ paths[m];
					}				
				}
				clickpath=pathArrStr+"/"+patgsArr[i];
			}else{
				clickpath=clickpath+"/"+patgsArr[i];
			}
			patgsArr[i] = cutstr(patgsArr[i],6);
			if(pathdir.length==0){
				pathdir ="<a class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+patgsArr[i]+"</a>";
			}else{
				pathdir=pathdir+"<span style=\"padding:0 5px;\">></span>"+"<a class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+patgsArr[i]+"</a>";
			}
		}
	}else{
		for(var j=0;j<paths.length;j++){
			rootbool = false;
			if(clickpath.length==0){
				clickpath=paths[j];
			}else{
				clickpath=clickpath+"/"+paths[j];
			}
				//字符串大于12个长度截取
				paths[j] = cutstr(paths[j],6);
				if(pathdir.length==0){
//					pathdir="<label class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+paths[j]+"</label>";
					pathdir ="<a class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+paths[j]+"</a>";
				}else{
//					pathdir=pathdir+">"+"<label class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+paths[j]+"</label>";
					pathdir=pathdir+"<span style=\"padding:0 5px;\">></span>"+"<a class=\"link\" onclick=\" backroot(\'"+clickpath+"\')\" >"+paths[j]+"</a>";
				}
		    }
	  }		
    }
	/*公告附件  20160629  hepo*/
	if(cupath.indexOf("GG")!=-1){		
	}else if(cupath.indexOf("_ZD_")!=-1){
		head = "";
	}else{
		if(cupath.indexOf("repair")!=-1){
			head = "";
		}else{
			if(rootbool){
				 head = "<div class=\"div-attachment-divpath\" style=\"background-color:gray;\">" +
						"<div class=\"div-attachment-path\">" +
						"<label class=\"link\" onclick=\" backroot(\'根目录\')\"><span class=\"glyphicon glyphicon-home\">" +
						"</span>根目录</label>" +pathdir +
						"</div></div>";

			}else{

			 if(paths.length>3)
				 headRoot = "<a>...</a><span style=\"padding:0 5px;\">></span>";	
			 else
				 headRoot = "<a onclick=\" backroot(\'根目录\')\"><span class=\"glyphicon glyphicon-home\"></span>根目录</a><span style=\"padding:0 5px;\">></span>";	 
			 head = "<div class=\"div-attachment-divpath\" style=\"background-color:gray;\">" +
					"<div class=\"div-attachment-path-history\">" +
					"<ul class=\"ul_none\"><li onclick=\"backDir()\"><a class=\"glyphicon\">返回上一级 </a><span style=\"padding:0 5px;\">|</span></li>" +headRoot
					+pathdir+
					"</li></ul></div></div>";
			}
		}

	}
	node.append(head);
	var content="";
	var url=iphost +"ftpfile/list.do";
	openPath = path;
//	try{
      $.post(url,{target:path}, function (result) {
    	var  re_size=0;
    	if(result.length==0){
    	var currentPathIdUrl = iphost +"ftpfile/getPathId.do";
   		if(rootbool){
    			// 查询当前路径的ID
    			var path_ = rootPath;
    			$.post(currentPathIdUrl,{target:path_}, function (json) {
    				var data = json;
    				if(json && json != ""){
    					//$("#folderid").val(json.id);
    					//$("#parentid").val(json.id);
    					parentid = json.id;
    					folderid = json.id;
    				}
    			});
    		}else{
    			$.post(currentPathIdUrl,{target:path}, function (json) {
    				if(json && json != ""){
    					//$("#folderid").val(json.id);
    					//$("#parentid").val(json.id);
    					parentid = json.id;
    					folderid = json.id;
    				}
    			});
    		}
    		
    		$("#morebtn").css("display","none");
    		
    		re_size=result.length;
    		 var gg_attachNumberStr="";
    		//通知公告附件数
    		 if(morere=="首页详情"){
  				auxiliariesObj=$(".div-notice-attachment");
  				 $(auxiliariesObj).html("<div><img src='../assets/images/index/icon-attachment.png' />附件("+re_size+")</div>");
  		    	
  			 }
  			 if(listname=="公告列表"){
  				
  				 if(re_size!="0"){
  					gg_attachNumberStr="<img src='../assets/images/index/icon-attachment.png' />附件("+re_size+")";
  		  		 }else{
  		  			gg_attachNumberStr="";
  				 }
  				 
  				 $("#"+auxiliariesNumber).html(gg_attachNumberStr);
   				
  			 }
     		 if(morere=="首页"){
     			 auxiliariesObj=$("#"+auxiliariesNumber + "  .div-documentlist-other")[2];
     			 $(auxiliariesObj).html("<img src='assets/images/index/icon-attachment.png' />附件("+re_size+")");
     		 }
    		if(electronState=="elect"){
    			if(rootbool)
    				node.children().filter('div').remove();
    			$("#divNoAttachment").css("display","block");
    		}
    		if(electronState=="retrieves"){
    			if(rootbool)
    				node.children().filter('div').remove();
    			$("#divNoMeeting").css("display","block");
    			$("#divNoAttachment").css("display","none");
    		}else if(electronState=="repair"){
    			$("#repairflie").css("display","none");
    			$("#uploadbtn").css("display","none");
    			$("#origin").css("display","block");
    		}else if(electronState=="zdProject"){
    			if(rootbool)
    				node.children().filter('div').remove();
    			$("#divNoMeeting").css("display","block");
    			$("#divNoAttachment").css("display","none");
    		}else{
    			var files=path.split("/");
    			var file_length=files.length;
    			// 文字显示按钮不显示
        		if(path.indexOf("FW")!=-1){  
        			
        			//长度大于3,表示含有文件夹,若为文件夹则不隐藏
        			if(file_length>=4){
        				
            			 $("#attachmentname").css("display","block");
            			 $("#originhead").css("margin-top","60px");
        			}else{	
        			  if(pagetype==undefined||pagetype==null){
  					  if(pagetype!="5"){
  						 $("#divNoAttachment").css("display","block");	
  						 }
					 }
        				 $("#attachmentname").css("display","none");
        			}
        			
        			if(path.indexOf("origindoc")!=-1){
    			    	$("#originhead").find("button").css("display","none");
    			    	//没有附件的时候显示上传文件
        	    		$("#origin").css("display","block");
        			}else{
        				$("#atthead").find("button").css("display","none");
        				$("#divNoAttachment").css("display","block");

        				
        			}
        			
        		}else{
        			/**
        			 * 若没有附件,则全部隐藏附件div
        			 * @param docattachmentpath
        			 *除发文外其他公文附件div
        			 *	长度大于3,表示含有文件夹,若为文件夹则不隐藏
        			 */
        			if(file_length>=3){
        				
           			 $(".div-attachment").css("display","block");
        			}else{
        				if(pagetype==undefined||pagetype==null){
        					if(pagetype!="5"){
        					  $("#divNoAttachment").css("display","block");	
        					}
						}
      						  $(".div-attachment").css("display","none");  
        			}
        			$(".div-document-content-right").find("button").css("display","none");
        			if(serviceState =="serviceno")
        				NoAttachmentHtml.css("display","block");
        			else if(serviceState == "serviceyes"){
        				$("#divNoAttachment"+attHtml).css("display","block");
        				$(".div-document-content-right").find("button").css("display","block");
        			}
        			else{
        				//审批已办项目无附件显示
        				if(projectType=="dealedproject"){
        					$("#divNoAttachment").css("display","none");
        					$("#noAttachment").css("display","block");
        				}else
        				$("#divNoAttachment").css("display","block");
        			}
        				
        		
        		}  
        		
    		}
    		
//    		if(retrievestate!=null||retrievestate!=undefined){
//    			$("#divNoAttachment").css("display","none");
//    		}
    	}else{
    		
    		
    			if(attachmentSrc.length>0)
    				attachmentSrc = [];
        		for(var i=0;i<result.length;i++){
        				if(result[i].isDir!="true")
            				attachmentSrc.push(result[i]);
        		}        		
    		if(path.indexOf("FW")!=-1){
    			
				
    		
        		/**
    			 * 若有附件,则全部隐藏附件div
    			 * @param docattachmentpath
    			 *发文的附件
    			 */
    			 $("#attachmentname").css("display","block");
    	
    			if(path.indexOf("origindoc")!=-1){
    				
			    	$("#originhead").find("button").css("display","block");
			    	$("#origin").css("display","none");
    			}else{   
    			
    				$("#atthead").find("button").css("display","block");
    				   				
    				$("#divNoAttachment").css("display","none");
    				
    			}
    		}else{
    			/**
    			 * 若有附件,显示
    			 * @param docattachmentpath
    			 *除发文外其他公文附件div
    			 */
    			$(".div-attachment").css("display","block");
    			if(serviceState =="serviceno"){
    				NoAttachmentHtml.css("display","none");
    			}
    			else if(serviceState == "serviceyes")
    				$("#divNoAttachment"+attHtml).css("display","none");
    			else{
    				$("#divNoAttachment").css("display","none");
    			}
    			if(electronState=="zdProject")
    				$(".div-document-content-right").find("button").css("display","block");
    			else
    				$(".div-document-content-right").find("button").css("display","block");
    			$("#divNoMeeting").css("display","none");
    			$("#repairflie").css("display","block");
    			$("#uploadbtn").css("display","block");
    			$("#origin").css("display","none");
    			
    		} 
    	
    		
    		if(result.length>2){
    			
    			if(electronState=="elects" || electronState=="elect" || 
    			   electronState=="retrieves" || electronState=="zdm" || electronState =="zdProject"){
    				 re_size=result.length;
        			 $("#morebtn").css("display","none");
    			}else{
    				 if(morere!=undefined){
            			 //re_size=result.length;
    					 var showMsg = "";
    					 if(showFlag == "up"){
    						 re_size=2;
    						 showFlag = "down"
    						 showMsg = "向下展开<span class=\"glyphicon glyphicon-arrow-down silverColor\"></span>";
    					 }else{
    						 re_size=result.length;
    						 showFlag = "up"
    						 showMsg = "向上收起<span class=\"glyphicon glyphicon-arrow-up silverColor\"></span>";
    					 }
    					 
            			 if(serviceState == "serviceyes"){
            				 $("#morebtn"+attHtml).css("display","block");
             			 	$("#morebtn"+attHtml).html(showMsg);
            			 }else if(serviceState=="serviceno"){
            				 morebtnHtml.css("display","block");
             			     morebtnHtml.html(showMsg);
            			 }else{
            				 $("#morebtn").css("display","block");
            			     $("#morebtn").html(showMsg);
            			 }
             				 
            		 }else{
            			//re_size=2;
            			re_size=result.length;
            			if(serviceState == "serviceyes")
            				$("#morebtn"+attHtml).css("display","block");
            			else if(serviceState=="serviceno")
            				morebtnHtml.css("display","block");
            			else
            				$("#morebtn").css("display","block");
            		 }
    			}
    			
    		}else{
    			re_size=result.length;
    			if(serviceState == "serviceyes")
    				$("#morebtn"+attHtml).css("display","none");
    			else if(serviceState=="serviceno")
    				morebtnHtml.css("display","none");
    			else
    				$("#morebtn").css("display","none");
    		}
    		if(cupath.indexOf("GG")!=-1){
    			re_size=result.length;
    		}
    		
    		var action="";
 			if(morere!=undefined){
 				
 				action="1";
 				if(morere=="首页详情"){
 	 				action="2"; 
 	 	        }else if(morere=="列表编辑"){
 	 	    			action="3";
 	 	    		 }
 				 /*若为查看状态,给action赋值标识*/
   			 if(morere=="lookover"){action="lookover";}
 			}
 			var auxiliariesObj=null;
 			
 			 if(morere=="首页详情"){
 				auxiliariesObj=$(".div-notice-attachment");
 				 $(auxiliariesObj).html("<div><img src='../assets/images/index/icon-attachment.png' />附件("+re_size+")</div>");
 		    	
 			 }
 			 if(listname=="公告列表"){
 				 $("#"+auxiliariesNumber).html("<img src='../assets/images/index/icon-attachment.png' />附件("+re_size+")");
  		    	
 			 }
    		 if(morere=="首页"){
    			 auxiliariesObj=$("#"+auxiliariesNumber).find("  .div-documentlist-other")[2];
    			 
    			 $(auxiliariesObj).html("<img src='assets/images/index/icon-attachment.png' />附件("+re_size+")");
    		 }else{
    			 if(path.indexOf("HY")!=-1 || path.indexOf("repair")!=-1 || path.indexOf("AM")!=-1 || path.indexOf("ZD")!=-1)
    				 gwstate = false;
    			 if(electronState =="elect")
    				 gwstate = false;
    			 for(var k=0;k<re_size;k++){
        			 var item = result[k];
        			
        			 
        			 
        			 if(serviceState=="serviceyes")
        				 content = createServiceDiv(item,cupath);
        			 else
        				 content = createFileDiv(item,isGG,action,cupath);
        			if(isGG=="true"&&action=="2"){
        				 node=$("#gg-attach");
        				 node.append(content);
        				 
        			 }else if(isGG=="true"&&action=="3"){
//        				 var attachItem=$("#gg_create .div-notice-attachment-item");
//        				 if(attachItem.length>0){
//        					 $(attachItem)[0].before(content);
//        				 }else{
        					 node.append(content);
//        				 }
        				
        			 }else{//不是公告的时候按照以前的方法
        				 node.append(content);
        			 }
        			// node.append(content);
        			 if(serviceState =="serviceyes"){
        				 if(operation==true)
        					 addAttachmentEvent();
        				 else
        					 removerMouseover();
        			 }else{
        				 addAttachmentEvent();
        			 }
        		
        		 }
    			 addAttachmentEvent();
    			//在非待办的列表打开公文时,附件的样式以及事件(只可下载)
    			 if(pagetype!=undefined || pagetype!=null){
    				 if(pagetype!="5"){
//    					    $(".div-attachment-item,.div-attachment-control").unbind("mouseover");
//    						$(".div-attachment-item,.div-attachment-control").unbind("mouseleave");
//    						$(".glyphicon-eye-open,.glyphicon-trash").css("display","none"); 
//    						removerMouseover();
//    						$(".div-attachment-control,#downloadbtn").css("display","block");
    					 $(".glyphicon-pencil").css("display","none");
    					 $(".glyphicon-trash").css("display","none"); 
    				 }	}
    		   //审批项目已办项目,附件样式以及事件(只可预览)
    			 if(projectType=="dealedproject"){
    				 $(".div-right-content-item button").css("display","none");
    				 $(".glyphicon-trash").css("display","none"); 
    			 }
    		 }
    		 
    		 var currentPathIdUrl = iphost +"ftpfile/getPathId.do";
    		 if(rootbool){
     			// 查询当前路径的ID
     			var path_ = rootPath;
     			$.post(currentPathIdUrl,{target:path_}, function (json) {
     				if(json && json != ""){
     					var data = json;
     					//$("#folderid").val(json.id);
     					//$("#parentid").val(json.id);
     					parentid = json.id;
     					folderid = json.id;
     				}
     			});
     		}else{
     			$.post(currentPathIdUrl,{target:path}, function (json) {
     				if(json && json != ""){
     					//$("#folderid").val(json.id);
     					//$("#parentid").val(json.id);
     					parentid = json.id;
     					folderid = json.id;
     				}
     			});
     		}
    		 
    		 if(cupath.indexOf("GG")!=-1){fujianEvent();}
    	}
    	
	});
   
//    	
//    }catch(e){
//    	var aa=e.message;
//    	alert(e.message);
//    }
    //档案模块:记录根路径
    var amfilepath = $("#AMfilePath");
    if(rootPath != ""){
    	amfilepath.val(rootPath);
    }
    allowPreviewOrNot();
}


function morelist(){
	if(serviceState == "projectAsk"){
		var currcheckbox = event.currentTarget;
		rootPath = $(currcheckbox).parent().find("#divpath").val();
		attHtml = $(currcheckbox).parent().find("#divlistId").val();
		listAttachment(rootPath+"/"+currentPath, "more");
	}else
		if(currentPath.length!=0){
			listFiles(rootPath+"/"+currentPath, "more");
		}else{
			listFiles(rootPath, "more");
		}
}

function listOriginFiles(){
	var iphost=$("#fileservice").val();
	var repath = "FW/"+$.cookie('uuid')+"/originaldoc"
	var url=iphost +"ftpfile/list.do";
	var node = $("#originattachment");
	node.children().filter('div').remove();
    $.post(url,{target:repath}, function (result) {
    	if(result.length==0){
    		$("#origin").css("display","block");
    		$("#originhead").find("button").css("display","none");
    	}else{
    		$("#origin").css("display","none");
    		$("#uploadbtn").css("display","block");
    		if(!originflag){
				loadOriginButton();
				originflag=true;
				}
    		//$("#originhead").find("button").css("display","block");
    		for(var k=0;k<result.length;k++){
   			 var item = result[k];
   			var uploadname = item["uploadUser"]==null?"":item["uploadUser"];
   			 var filename=item["name"];
   			 var path =item["path"];
   			 var username = item["username"] || "";
   			 
   			if(filename.indexOf(".doc")!=-1 || filename.indexOf(".docx")!=-1){
   				downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>"+
					"<span title=\"预览\" class=\"glyphicon glyphicon-eye-open\"  onclick=\"preview({filename:\'"+path+"\'})\"  ></span>"+
					" <span id=\"btnedit\" title=\"编辑\" class=\"glyphicon glyphicon-pencil\" onclick=\"openWindow({filename:\'"+path+"\'})\"  >" +
	   				"</span>";;
   			}else{
   				downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>"+
   			 					"<span title=\"预览\" class=\"glyphicon glyphicon-eye-open\"  onclick=\"preview({filename:\'"+path+"\'})\"  ></span>";
   			} 
   			 
   			var typecontent = contentpath+"/assets/images/fileicon/default.png";
   			var filetype=filename.substring(filename.lastIndexOf("."),filename.length);
   			if(filetype==".doc"||filetype==".docx"){
   				typecontent=contentpath+"/assets/images/fileicon/doc.png";
   			}else if(filetype==".pdf"){
   				typecontent=contentpath+"/assets/images/fileicon/pdf.png";
   			}else if(filetype==".ppt"){
   				typecontent=contentpath+"/assets/images/fileicon/ppt.png";
   			}else if(filetype==".jpg"){
   				typecontent=contentpath+"/assets/images/fileicon/jpg.png";	
   			}else if(filetype==".xls"){
   				typecontent=contentpath+"/assets/images/fileicon/xls.png";
   			}else if(filetype==".zip"){
   				typecontent=contentpath+"/assets/images/fileicon/zip.png";
   			}else if(filetype==".txt"){
   				typecontent=contentpath+"/assets/images/fileicon/txt.png";
   			}else {
   				typecontent=contentpath+"/assets/images/fileicon/default.png";
   			}
//   			 var content="<div class=\"div-attachment-item\"><a class=\"a-file-name\" href=\"javascript:void(0)\" style=\" height: 40px !important; line-height: 40px !important;\" ><img style=\"width:32px\" src=\""+contentpath+"/assets/images/fileicon/doc.png\">"+item["name"]+"</a>"+" <div class=\"div-attachment-control\" style=\"line-height: 40px;\" >"+downloadcontent+ "<span id=\"delebtn\" title=\"删除\" class=\"glyphicon glyphicon-trash\" onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\','origin',event)\"></span></div>"+"</div>"
   			content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
			+typecontent+"\" /> <div class=\"div-attachment-file\"><div class=\""
			+"div-attachment-name\" onclick=\"openlayerdoc({filename:\'"+path+"\'})\">"+item["name"]+"</div><label class=\"div-attachment-size\">"+username+ " " +uploadname+"上传于"+
							item["time"]+"</label><label class=\"div-attachment-size\">" +
							"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+ "<span id=\"delebtn\" title=\"删除\" class=\"glyphicon glyphicon-trash\" onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\','origin',event,'"+item["id"]+"')\"></span></div></div>";  
   			
   			node.append(content);
   			if(pagetype=="3"){
   				$(".div-attachment-control #btnedit").css("display","none"); 
   				$(".div-attachment-control #delebtn").css("display","none"); 
   			 }
   			 addAttachmentEvent();
    		}
    	}
    });
}

var  index_attach;

/**
 * 上传文件或创建文件夹
 * 
 * 
 * 
 * 
 * type:file或folder
 * 
 * @returns
 */
var hydoctype = "";

function upload_click(type,doctype,folderorigin){
	hydoctype = doctype;
	
//	if(doctype=="FW"){
//		createDirInService(doctype,"general");
//		createDirInService(doctype,"originaldoc");
//	}
	
	createDirInService(doctype,"");// 新建当前附件文件夹
	
	if(folderorigin!=undefined){
		$("#origintext").val(folderorigin);
	}else{
		$("#origintext").val("false");
	}
   // url=encodeURI(encodeURI(contentpath+"/fileupload/upload.jsp?type="+type+"&currentPath="+rootPath+"/"+currentPath));
	var height="150px";
	if(type=="file"){
		height="178px";
	}
	$("#_upfile").trigger("click");
	//$("#fileBrower").trigger("click");
}

//进度条方法
function getProgress(){
	var iphost=$("#fileservice").val();
	var now = new Date();
    $.ajax({
        type: "post",
        dataType: "json",
        url: iphost+"ftpfile/getuploadprocess.do?md5str="+md5str,
        data: now.getTime(),
        success: function(data) {
			
			if(data.message!="0%"){
				console.log("get progress data is:"+data.message);
				$(".progress-bar").width(data.message); 
			}
        },
        error: function(err) {
        	console.log("get progress data fail:"+err); 
        }
    });
}

// 判断文件是否以js..等结尾
function safe(suffix){
	// 获取可上传文件类型
	
	if("zip" == suffix || "war" == suffix ||
		"jar" == suffix || "jpg" == suffix ||
		"pdf" == suffix || "mp3" == suffix ||
		"dwg" == suffix || "doc" == suffix ||
		"docx" == suffix || "xls" == suffix ||
		"xlsx" == suffix || "ppt" == suffix ||
		"pptx" == suffix || "bmp" == suffix ||
		"gif" == suffix || "png" == suffix ||
		"svg" == suffix || "txt" == suffix ||
		"3gp" == suffix || "mp4" == suffix ||
		"avi" == suffix || "rmvb" == suffix ||
		"rm" == suffix || "mkv" == suffix
	){
		return true;
	}else {
		return false;
	}
}

var oTimer = null;
var md5str = "";
var filename="";
function onchangeFileName(obj){
	var fileadress = $("#fileadress").val();
	var docviewservice = $("#docviewservice").val();
	var pid = $("#pid").val();
	var state = $("#status").val();
//	var detailurl = window.location.href;//详细页面url
	
	var iphost=$("#fileservice").val();
//	var iphost = "http://127.0.0.1:8080/DocService/";
	var origindoc=$("#origintext").val();
	var meetingNoticeAll = $("#meetingNoticeAll").val();	//会议通知默认展开标记
	filename = document.getElementById("_upfile").value;
	filename = filename.substring(filename.lastIndexOf("\\")+1, filename.length);
	
	var endwidth = filename.substring(filename.lastIndexOf(".")+1);
	
	// 判断文件是否小于0
	var fileSize = obj.files[0].size;   
	if(fileSize<=0){
		layer.msg("不允许上传空文件",{icon:2});
		return;
	}
	
	// 判断文件是否不安全
	if(safe(endwidth)){
		md5str = hex_md5(filename+new Date().getTime());
//		if(rootPath!=null&&rootPath.indexOf("FW")!=-1){
		url=iphost+"ftpfile/ncUploadfiles.do?md5str="+md5str;
//		}else{
//			 url=iphost+"ftpfile/uploadfiles.do?md5str="+md5str;
//		}
	    var uploadpath=null;
	    if(origindoc!="false"&&origindoc!=undefined){
	    	uploadpath="/FW/"+$.cookie('uuid')+"/originaldoc";
	    	folderid = getParentId("FW/"+$.cookie('uuid')+"/originaldoc");
	    }else{
	    	if(currentPath.length==0){
	    		uploadpath= "/"+rootPath;
	    		folderid = getParentId(rootPath);
	    	}else{
	    		uploadpath= "/"+rootPath+"/"+currentPath;
	    		folderid = getParentId(rootPath+"/"+currentPath);
	    	}
	    	
	    }
	    
	    userid_ = getUserId();
	    var folerid_ = folderid;
	    
	    var viewurl =uploadpath+"/"+filename;//预览url
	    $("#filepath").val(rootPath);
	    $("#_fileForm").ajaxSubmit({
	        type: "post",
	        data: {
	            'dirPath': uploadpath,
	            'viewurl':viewurl,
	            'detailurl':pid,
	            'state':state,
	            'username':username,
	            "folderid":folerid_,
	            'userid':userid_,
	            'filename':filename,
	        },
	        url:url ,
	        async:true,
	        beforeSend: function() 
			{ 
	        	if(origindoc!="false"&&origindoc!=undefined){
	        		$("#lw").show();    			
	        	}else{
        			if(serviceState=="serviceyes")
            			$("#fj"+attHtml).show();
            		else if(serviceState=="serviceno")
            			fjHtml.show();
            		else
            			$("#fj").show(); 
	        	}
	        	$(".progress-bar").width('0%'); 
	        	
	        	$("#attachmentfile").hide();	
	        	$("#attachmenting").show();
        		oTimer = setInterval("getProgress()", 100);
			}, 
	        success: function (data) {
	        	//档案模块
	            $("#AMfilePath").val(rootPath);
	            
	            
	          
	        	layer.msg("上传成功!",{icon:1});
	        	if(origindoc!="false"&&origindoc!=undefined){
	        		listOriginFiles();
	        	}else{       		
	        		if(currentPath.length!=0){
	        			listFiles(rootPath+"/"+currentPath);
	        		}else{
	        			if(meetingNoticeAll!=null&&meetingNoticeAll=="all")
	        				listFiles(rootPath,"more");
	        			else
	        				listFiles(rootPath);
	        		}
	        		
	        		
	        	}
	        	
	        	$('#_fileForm').clearForm();
	        	clearInterval(oTimer);
	        	$(".progress-bar").width('100%'); 
	        	$("#attachmentfile").show();	
	        	$("#attachmenting").hide();
	        	if(origindoc!="false"&&origindoc!=undefined){
	            	$("#lw").hide();
	          
	        	}else{
	        		if(serviceState=="serviceyes")
	        			$("#fj"+attHtml).hide();
	        		else if(serviceState=="serviceno")
	        			fjHtml.hide();
	        		else	
	        			$("#fj").hide();       		
	        	}
	        	$(".progress-bar").width('0%'); 
	        	
	        	//更新时间和root
	        	if(hydoctype == "HY"){
	        		updateHytime();
	        	}else if(hydoctype == "ZD"){
	        		updateZDRootPath();
	        	}else{
	        		updaterootortime();
	        	}
	           	 	
	        },
	        error: function (msg) {
	        	if(origindoc!="false"&&origindoc!=undefined){
	        		$(".progress[id='lw']").hide();
	            	$(".progress-bar[id='lw']").width('0%'); 
	        	}else{
	        		$(".progress[id='fj']").hide();
	            	$(".progress-bar[id='fj']").width('0%'); 
	        	}
	        	
	        	layer.msg("文件上传失败!",{icon:0});  
	        	clearInterval(oTimer);
	        	$('#_fileForm').clearForm();
	        }
	    });
	}else{
		layer.msg("存在不安全因素,禁止上传",{icon:2});
		document.getElementById("_upfile").value="";
		
		/*layer.confirm('您上传的文件包含存在安全因素,确定继续上传吗?', {
		  btn: ['确定','取消'] //按钮
		}, function(){
		});*/
	}
}


function updatefjlog(pid,path){
	if(path!=undefined){
		if(path.indexOf("GG")!=-1){rootPath=path;}
	}
	var iphost=CONF_DOC_SERVERURL;
	var url=iphost+"ftpfile/updatefj.do";
	$.post(url,{rootpath:rootPath,pid:pid}, function (result) {
		console.log(result);
	});
}


/**
 * 返回上一级目录
 * 
 * @returns
 */
function backDir()
{
var pArray = currentPath.split('/');
if(pArray.length>=2){
	var path = currentPath.substring(0,currentPath.lastIndexOf("/"));
	currentPath=path;
	listFiles(rootPath+"/"+currentPath);
	}else if(pArray.length==1){
		currentPath="";
		listFiles(rootPath);
	}
}

function backroot(node){
	if(node=="根目录"){
		currentPath="";
		listFiles(rootPath);
		
	}else{
		currentPath=node
		listFiles(rootPath+"/"+node);
	}
	
}

/**
 * 拼接文件列表
 * 
 * @param item
 * @returns
 */
function createFileDiv(item,isGG,action,cupath){
	
	// 图片类型
	var typecontent="";
	var path;
	var downloadcontent="";
	var uploadname = item["uploadUser"]==null?"":item["uploadUser"];
	 var username = item["username"] || "";
	if(item["isDir"]=="true"){// 是不是文件夹
		var filename = item["name"];
		if(currentPath.length==0){
			path = "/"+rootPath+"/"+filename;
		}else{
			path = "/"+rootPath+"/"+currentPath+"/"+filename;
		}
		typecontent=contentpath+"/assets/images/projecttask/folder.png";// 文件图标路径
		downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>";
	}else{// 文件则用后缀判断文件类型
		
		var filename=item["name"];
		var filetype=filename.substring(filename.lastIndexOf("."),filename.length);
		if(filetype==".doc"||filetype==".docx"){
			typecontent=contentpath+"/assets/images/fileicon/doc.png";
		}else if(filetype==".pdf"){
			typecontent=contentpath+"/assets/images/fileicon/pdf.png";
		}else if(filetype==".ppt"){
			typecontent=contentpath+"/assets/images/fileicon/ppt.png";
		}else if(filetype==".jpg"){
			typecontent=contentpath+"/assets/images/fileicon/jpg.png";	
		}else if(filetype==".xls"){
			typecontent=contentpath+"/assets/images/fileicon/xls.png";
		}else if(filetype==".zip"){
			typecontent=contentpath+"/assets/images/fileicon/zip.png";
		}else if(filetype==".txt"){
			typecontent=contentpath+"/assets/images/fileicon/txt.png";
		}else {
			typecontent=contentpath+"/assets/images/fileicon/default.png";
		}
		if(currentPath.length==0){
			path = "/"+rootPath+"/"+filename;
		}else{
			path = "/"+rootPath+"/"+currentPath+"/"+filename;
		}
		if(filetype.indexOf(".doc")!=-1 || filetype.indexOf(".docx")!=-1){
			downloadcontent = downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>"+
			" <span title=\"预览\" class=\"glyphicon glyphicon-eye-open\"  onclick=\"preview({filename:\'"+path+"\'})\"  ></span>"+
			" <span title=\"编辑\" class=\"glyphicon glyphicon-pencil\" onclick=\"openWindow({filename:\'"+path+"\'})\"  >" +
//			"<a href=PageOffice://|"+global.contextPath+"/editfile.jsp?filename="+path.filename+"|width=1300px;height=730px|DlELURlHBUwPQnMwCzR6MHhDdzR5QQk/fEF/N3swZD93N38wezZ7NAtAdzk=|></a>"
			"</span>";
		}else{
			downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>"+
			" <span title=\"预览\" class=\"glyphicon glyphicon-eye-open\"  onclick=\"preview({filename:\'"+path+"\'})\"  ></span>";
		}

	}
	var content = "";
	if(electronState=="retrieves" || electronState=="zdProject"){
		var fieldStr = "";
		if(item["isDir"]!="true"){
			fieldStr = "onclick=openlayerdoc({filename:\'"+path+"\'})";
			
		}
		content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
		+typecontent+"\" /> <div class=\"div-attachment-file\"><div class=\""
		+"div-attachment-name\" "+fieldStr+">"+item["name"]+"</div><label class=\"div-attachment-size\">"+username+ " " +uploadname+"上传于"+
				item["time"]+"</label><label class=\"div-attachment-size\">" +
						"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+ "</div></div>";                   
	}else if(electronState=="elect"){
		var strclick = "";
		if(path==undefined)
			strclick= "onclick=\"openlayerdoc({filename:\'"+path+"\'})\"";
		else
			strclick = "onclick=\"preview({filename:\'"+path+"\'})\"";
		
		content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
		+typecontent+"\" /> <div class=\"div-attachment-file\"><div class=\"div-attachment-name\""+strclick+">"
		+item["name"]+"</div><label class=\"div-attachment-size\">"+username+" " +uploadname+"上传于"+
				item["time"]+"</label><label class=\"div-attachment-size\">" +
						"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+ "</div></div>";

	}else{
		var fieldStr = "";
		if(item["isDir"]!="true"){
			fieldStr = "onclick=\"openlayerdoc({filename:\'"+path+"\'})\"";
			
		}
		content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
			+typecontent+"\" /> <div class=\"div-attachment-file\"><div class=\""
			+"div-attachment-name\" "+ fieldStr +">"+item["name"]+"</div><label class=\"div-attachment-size\">"+username+" " +uploadname+"上传于"+
							item["time"]+"</label><label class=\"div-attachment-size\">" +
							"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+ "<span id=\"delebtn\" title=\"删除\" class=\"glyphicon glyphicon-trash\" onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\',event,event,'"+item["id"]+"')\"></span></div></div>";                           
	}
	if(!gwstate)
		attachflag=true;
	if(isGG=="true"){
		var divString="";
		if(action=="1")return;
//		alert("path:"+path);
//		alert("rootPath:"+rootPath);
//		alert("filename:"+filename);
		//弹窗详情(notice-window.jsp)
		if(action=="2"){
			path=cupath;
//		content=" <div onclick=scan({filename:'"+path+"/"+item["name"]+"'})>" 
//			+"<img src=\""+typecontent+"\" /> "+item["name"]+"</div>";
		
		content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
		+typecontent+"\" /> <div class=\"div-attachment-file\">" +
				"<div class=\"div-attachment-name\" onclick=\"preview({filename:\'/"+item["name"]+"\'})\">"+item["name"]+"</div>" +
						"<label class=\"div-attachment-size\">"+username+" " +uploadname+"上传于"+
						item["time"]+"</label><label class=\"div-attachment-size\">" +
						"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+
		 "<span id=\"delebtn\" title=\"删除\" class=\"glyphicon glyphicon-trash\" onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\',event,event,'"+item["id"]+"')\"></span></div></div>";                           

		}else{				
		 //新建或者编辑action=="3"时可以进行删除,若为查看状态则不能删除
			if(action==="lookover"){
				divString="";
				
			}else{
				divString=" <div class='div-notice-add-fileremove' onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\',event,event,'"+item["id"]+"')\">" 
//            	+"<label class=\"div-attachment-size\">" +item["size"]+"</label>"
            	+"<span class='glyphicon glyphicon-trash' style='display:none;'></span>" 
            	+"</div>";
			}
		 content="<div class='div-notice-attachment-item' onclick=\"preview({filename:\'"+path+"\'})\" >"
            	+"<img src=\""+typecontent+"\" /> "
            	+" <div class='div-notice-add-filename'>"+item["name"]+"</div>"
            	+divString
            	+"</div>";
		}
	}else{
		//不是公告附件的情况下执行按钮加载(如发文、收文等表单界面的附件按钮)
		 if(!attachflag){
				loadAttachButton(cupath);
				attachflag=true;
				}
	}
	return content;
}

function openWindow(item){
	
	var filename = item.filename
	var encodename = encodeURI(encodeURI(filename));
	var url = $("#linkUrl").attr('href');
	url = url.replace("***",encodename);
//	var basepath = $("#basepath").val();
//	var url = "PageOffice://|"+basepath+"/editfile.jsp?name="+encodename+"|width=1300px;height=730px;|DlELURlHBUwPQnNEZzN4MgkyZkB6P2QwZC4JNAlBZjF7Q3wwe0J2RGQvfTk=|";
	window.location.href = url;

	
}


/**
 * 点击文件夹刷新列表
 * 
 * @param filename
 *            文件夹名称
 * @param isDir
 *            是否为文件夹
 * @returns
 */
function clickreshlist(filename,isDir,e){
	e = window.event || e;
    if (e.stopPropagation) {
        e.stopPropagation();
        if(isDir=="true"){
    		if(currentPath.length==0){
    			currentPath=filename;
    		}else{
    			currentPath=currentPath+"/"+filename;
    		}
    	listFiles(rootPath+"/"+currentPath);
    	}
    } else {
        e.cancelBubble = true;
    }
}

/**
 * 删除文件
 * 
 * @returns
 */
function deletefile(filename,isDir,origin,e,id){
	var iphost=$("#fileservice").val();	
	e = window.event || e;
    if (e.stopPropagation) {
        e.stopPropagation();
        var url=iphost +'ftpfile/delete.do';
        var dirpath=null;
        if(origin!="origin"){
        	if(currentPath=="")
        		dirpath="/"+rootPath+"/"+currentPath;
        	else
        		dirpath="/"+rootPath+"/"+currentPath+"/"
        }else{
        	dirpath="/FW/"+$.cookie('uuid')+"/originaldoc/";
        }
        var viewurl =docviewservice+ encodeURI(fileadress+dirpath+"/"+filename);//预览url
        var userid = getUserId();
        layer.open({
    		content: '是否删除文件?',
    		btn: ['确认', '取消'],
    		shadeClose: true,
    		icon: 3,
    		yes: function(){
    			$.post(url,{filename:filename,
    						dirPath:dirpath,
    						username:username,
    						userid:userid,
    						id:id,
    						isDir:isDir}, function (result) {
    	    		  if(result.message=="删除成功!")
    	    		  {
    	    			  if(origin!="origin"){
    	    				  if(currentPath.length!=0){
    	        				  listFiles(rootPath+"/"+currentPath);
    	        			  }else{
    	        				  //若是公告 而且是公告详情 删除后重新加载
    	        				  if(rootPath.indexOf("GG")!=-1){
    	        				  listFiles(rootPath);
    	        				  }else{
    	        				  listFiles(rootPath);
    	        				  }
    	        			  }	 
    	    			  }else{
    	    				  listOriginFiles();
    	    			  }
    	    			  layer.msg(result.message,{icon:6}); 
    	    		  return;
    	    		  }else{
    	    			  layer.msg(result.message,{icon:0}); 
    	    		  }
    	    	});
    		}
    	});
        
    } else {
        e.cancelBubble = true;
    }
}

/**
 * 下载文件
 * 
 * @returns
 */
function downloadfile(params,e){
	e = window.event || e;
	if (e.stopPropagation) {
		e.stopPropagation();
		var iphost=$("#fileservice").val();
		var url = iphost+"ftpfile/downloadfile.do";	
		var temp = document.createElement("form");
		temp.action = url;
		temp.method = "post";
		temp.style.display = "none";
		for (var x in params) {
			var opt = document.createElement("textarea");
			opt.name = x;
			opt.value = params[x];
			temp.appendChild(opt);
		}
		document.body.appendChild(temp);
		temp.submit();
		return temp;
	}else {
		e.cancelBubble = true;
	}
}


function preview(params){
	
	var fileadress = $("#fileadress").val();
	var docviewservice = $("#docviewservice").val();
	var url = fileadress+params["filename"];
//	$("#fileUrlfrom").val(url);
	var path = params["filename"];
	var name = path.substring(path.lastIndexOf("/")+1,path.length);
//	var a = encodeURIComponent(encodeURIComponent("#"))
	var encodeurl = encodeURIComponent(encodeURIComponent(url));
	var encodename = encodeURIComponent(encodeURIComponent(name));
//	$("#filenamefrom").val(name);
//	$("#openPath").val(openPath);
//	$("#attmentfrom").submit();
//	url=encodeURI(encodeURI(docviewservice+url));
//	window.open(url);
	window.open(global.contextPath+"/meeting/previewAttachment.jsp?fileUrl="+encodeurl+"&filename="+encodename+"&openPath="+openPath);
	
}
/**
 * 公告预览文档
 * 
 * @param params
 */
function scan(params){
	var fileadress = $("#fileadress").val();
	var docviewservice = $("#docviewservice").val();
	var url = fileadress+params["filename"];
	var path = params["filename"];
	var name = path.substring(path.lastIndexOf("/")+1,path.length);
	if(path!="undefined"){
		parent.layer.open({
			  type: 2,
			  title: name,
			  shadeClose: true,
			  shade: 0.6,
			  area: ['80%', '90%'],
			  content: docviewservice+encodeURI(url)
			}); 
	}
	
}
/**
 * 弹出层形式预览文档
 * 
 * @param params
 */
var layerindex = 0;
function getlayer() {
	return layerindex;
}

function openlayerdoc(params){
	var fileadress = $("#fileadress").val();
	var docviewservice = $("#docviewservice").val();
	var url =fileadress+params["filename"];
	var path = params["filename"];
	var name = path.substring(path.lastIndexOf("/")+1,path.length);
	$('#fileUrl').val(url);
	$('#filename').val(name);
//	var fileadress = $("#fileadress").val();
//	var docviewservice = $("#docviewservice").val();
//	var url = fileadress+params["filename"];
//	url=encodeURI(encodeURI(docviewservice+url));
//	window.open(url);
//	
	if(path!="undefined"){
		layerindex = layer.open({
			  type: 2,
			  title: name,
			  shadeClose: true,
			  shade: 0.6,
			  area: ['80%', '90%'],
//			  content: docviewservice+encodeURI(url)
			  content: global.contextPath+"/meeting/attachment.jsp"
			});
		
//		var json = {
//				  "title": name, //相册标题
//				  "id": 123, //相册id
//				  "start": 0, //初始显示的图片序号,默认0
//				  "data": [   //相册包含的图片,数组格式
//				    {
//				      "alt": name,
//				      "pid": "img", //图片id
//				      "src": "http://116.10.196.223:8088/data/test/2016/0906/11/112549_114397_imahuki/index.png", //原图地址
//				      "thumb": "" //缩略图地址
//				    },
//				    {
//					      "alt": name,
//					      "pid": "img", //图片id
//					      "src": "http://116.10.196.223:8088/data/test/2016/0906/11/113125_9828_iiKnpFi/index.png", //原图地址
//					      "thumb": "" //缩略图地址
//					    }
//				  ]
//				}
//
//		layer.photos({
//			photos: json
//		});
		
	}
	
}

/**
 * 更新主表的根路径和更新时间
 */
function updaterootortime(){
	var status=$("#status").val();	
	var pid=$("#pid").val();	
	 if(pid==""||pid==undefined||pid==null){pid=$("gid").val();}
	if(status!=0){
		if(pid!=undefined){
		$.post(global.contextPath + global.modelctls.document.updateroot,{pid:pid,rootpath:rootPath},
				 function (result) {
				 
		       });
		}
	}
}


function updateHytime(){
	var projectId=$("#projectId").val();	
	if(projectId!=""){
		$.post(global.contextPath+"/mvc/meetingProject/updateroot.do",{projectId:projectId,rootpath:rootPath},
				 function (result) {
		       });
	}
}

//更新附件操作信息表
//参数pid ,rootpath 根路径
//
function fujianEvent(){
	//显示删除图标
    $(".div-notice-attachment-item").mouseover(function (evt) {
        $(evt.currentTarget).css("background-color", selectedbg);
        $(".div-notice-add-fileremove").show("fast");
//        $(evt.currentTarget).find(".glyphicon-trash").show("fast");
//        $(evt.currentTarget).find(".glyphicon-eye-open").show("fast");
//        $(evt.currentTarget).find(".div-notice-add-fileremove span").slideDown("fast", function () {
//            if ($(this).parent().parent().css("background-color") == selectedbg) {
//                $(this).hide("fast");
//            }
//        });
        $(evt.currentTarget).find(".div-notice-add-fileremove span").css("display","inline");
    });
    $(".div-notice-attachment-item").mouseleave(function (evt) {
        $(evt.currentTarget).css("background-color", "white");
//        $(evt.currentTarget).find(".glyphicon-trash").hide("fast");
//        $(evt.currentTarget).find(".glyphicon-eye-open").hide("fast");
        $(evt.currentTarget).find(".glyphicon-trash").css("display","none");
        $(evt.currentTarget).find(".glyphicon-eye-open").css("display","none");
    });
    //删除事件
//    $(".div-notice-add-fileremove").click(removeNotice);
}

/**
 * 生成UUID
 * 
 * @returns uuid
 */
function uuid(){
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
	s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the
														// clock_seq_hi_and_reserved
														// to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
	}


/*
 * 获取登录用户id
 */
function getUserName(){
	var name = null;
	$.ajaxSetup({
		async : false // 取消异步
	});	
	
//	$.post(global.contextPath + global.modelctls.document.getListUser, function (result) {
//		if(result==null||result==undefined){return;}
//		user_ = result.data.user;
//		name = result.data.user.loginname;
//     })
//    return name; 
}

/*
 * 获取登录用户id
 */
function getParentId(rootPath){
	var id = "-1";
	$.ajaxSetup({
		async : false // 取消异步
	});	
	var currentPathIdUrl = CONF_DOC_SERVERURL +"ftpfile/getPathId.do";
	var path_ = rootPath;
	$.post(currentPathIdUrl,{target:path_}, function (json) {
		var data = json;
		if(json && json != ""){
			id = json.id;
		}
	});
    return id; 
}

/**
 * 获取用户ID
 * @returns
 */
function getUserId(){
	var id = null;
	$.ajaxSetup({
		async : false // 取消异步
	});	
	$.post(global.contextPath + global.modelctls.user.loginInfo, function (result) {
		//$.post(CONF_OURP_SERVERURL + global.modelctls.user.loginInfo, function (result) {//hyh  修改  2017、9、15
		if(result==null||result==undefined){return;}
		id = result.data.user.id;
     })
    return id; 
}

/**
 * 是否含有附件,是否上传
 * @returns
 */
function attachYn(){
	var iphost=$("#fileservice").val();
	var foldid;
	var path;
	var bool;
	if($.cookie('uuid')=="null"||$.cookie('uuid')==undefined||$.cookie('uuid')=="")
		bool = "false";	
	else{
		foldid=$.cookie('uuid');
		path = "SP/"+foldid;
		var url=iphost +"ftpfile/list.do";
		$.post(url,{target:path}, function (result) {
		    	if(result.length==0)
		    		bool = "false"	
		    	else
		    		bool = "true";
		    });
	}
	return bool;
}



//重点项目服务记录附件
function createServiceDiv(item,cupath){	
		// 图片类型
		var typecontent="";
		var path;
		var downloadcontent="";
		var uploadname = item["uploadUser"]==null?"":item["uploadUser"];
		 var username = item["username"] || "";
		if(item["isDir"]=="true"){// 是不是文件夹
			typecontent=contentpath+"/assets/images/projecttask/folder.png";// 文件图标路径
			downloadcontent="<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},event)\" ></span>";
		}else{// 文件则用后缀判断文件类型
			
			var filename=item["name"];
			var filetype=filename.substring(filename.lastIndexOf("."),filename.length);
			if(filetype==".doc"||filetype==".docx"){
				typecontent=contentpath+"/assets/images/fileicon/doc.png";
			}else if(filetype==".pdf"){
				typecontent=contentpath+"/assets/images/fileicon/pdf.png";
			}else if(filetype==".ppt"){
				typecontent=contentpath+"/assets/images/fileicon/ppt.png";
			}else if(filetype==".jpg"){
				typecontent=contentpath+"/assets/images/fileicon/jpg.png";	
			}else if(filetype==".xls"){
				typecontent=contentpath+"/assets/images/fileicon/xls.png";
			}else if(filetype==".zip"){
				typecontent=contentpath+"/assets/images/fileicon/zip.png";
			}else if(filetype==".txt"){
				typecontent=contentpath+"/assets/images/fileicon/txt.png";
			}else {
				typecontent=contentpath+"/assets/images/fileicon/default.png";
			}
			path = "/"+cupath+"/"+filename;
			downloadcontent=" <span title=\"预览\" class=\"glyphicon glyphicon-eye-open\"  onclick=\"preview({filename:\'"+path+"\'})\"  ></span>"+"<span id=\"downloadbtn\" title=\"下载\" class=\"glyphicon glyphicon-save\"  onclick=\"downloadfile({filename:\'"+path+"\'},e)\" ></span>";
			
		}
		var fieldStr = "";
		if(item["isDir"]!="true"){
			fieldStr = "onclick=openlayerdoc({filename:\'"+path+"\'})";
			
		}
		var	content ="<div class=\"div-attachment-item\"  onclick=\"clickreshlist(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\" ><img src=\""
			+typecontent+"\" /> <div class=\"div-attachment-file\"><div class=\""
			+"div-attachment-name\" "+ fieldStr +">"+item["name"]+"</div><label class=\"div-attachment-size\">"+username+" " +uploadname+"上传于"+
							item["lastUpdateTime"]+"</label><label class=\"div-attachment-size\">" +
							"</label></div> <div class=\"div-attachment-control\" >"+downloadcontent+ "<span id=\"delebtn\" title=\"删除\" class=\"glyphicon glyphicon-trash\" onclick=\"deletefile(\'"+item["name"]+"\','"+item["isDir"]+"\',event)\",event,'"+item["id"]+"')\"></span></div></div>";                         
		return content;
}

/**
 * 档案模块:清除附件栏残留的操作
 * 
 */
function clear_operation(){
	$(".div-attachment-divpath").css("display","none");
	$(".div-attachment-path").css("display","none");
	$(".div-attachment-item").css("display","none");
	$(".div-no-attachment").css("display","block");
	rootPath = "AM/"+uuid();
}

/**
 * 附件大于20M时,不使用预览
 */
function moreThan20M(fileSize){
	if(fileSize){
		if(fileSize.indexOf('G')!=-1){
			return true;
		}else if(fileSize.indexOf('M')!=-1){
			var size=parseFloat(fileSize.replace('M',''));
			if(size>20)return true;
		}
	}
	return false;
}
function allowPreviewOrNot(){
	$('.div-attachment .div-attachment-item').each(function(i){
		var fileSize=$(this).find('.div-attachment-file .div-attachment-size:last').text()
		if(moreThan20M(fileSize)){
			$(this).find('.div-attachment-control span.glyphicon-eye-open').remove();
			$(this).find('.div-attachment-file .div-attachment-name').removeAttr('onclick').css("cursor","default");;
		}
	})
}

function loadAttachButton(attachpath) {
	var doctype = "";
	if (attachpath.indexOf("FW") != -1) {
		doctype = "FW";
	} else if (attachpath.indexOf("HY") != -1) {
		doctype = "HY";
	} else if (attachpath.indexOf("SW") != -1) {
		doctype = "SW";
	} else if (attachpath.indexOf("XJ") != -1) {
		doctype = "XJ";
	} else if (attachpath.indexOf("officehelper") != -1) {
		doctype = "officehelper";
	} else if (attachpath.indexOf("SP") != -1) {
		doctype = "SP";
	} else if (attachpath.indexOf("CY") != -1) {
		doctype = "CY";
	}else if (attachpath.indexOf("DA") != -1) {
		doctype = "DA";
	}else if (attachpath.indexOf("YS") != -1) {
		doctype = "YS";
	} else {
		doctype = "other";
	}
	if(pagetype==null||pagetype==undefined||pagetype=="5"){			
	// 附件按钮
	$("#_fileForm ")
			.before(
					"<button class=\"btn btn-info\" onclick=\"adddir('"
							+ doctype
							+ "')\">"
							+ "<span class=\"glyphicon glyphicon-folder-close\"></span>创建文件夹"
							+ "</button>"
							+ "<button class=\"btn btn-info progress-button\" id=\"uploadbtn\""
							+ "onclick=\"upload_click('file','"
							+ doctype
							+ "')\" data-style=\"fill\""
							+ "data-horizontal>"
							+ "<span class=\"glyphicon glyphicon-file\"></span>上传文件"
							+ "</button>");
	
	}

}