//---------------文件上传js--------------------------
//同时一个页面多个上传时，交换输入框的Id
var inputId="";
//文件上传对话框inputStr要赋值的输入框id
function uploadFileDialog(targetId){
inputId = targetId;
  var urlStr = path+"/website/upload.init.xhtml?randomDateStr="+ new Date().getTime();
  nzWindow.win({message:urlStr,width:400,height:180,title:' 文件上传',btn:[['确定','ok'],['取消','cancel']],handler:uploadHandler,maxBtn:true,minBtn:true,iframe:true})
}

function uploadHandler(tp){
	if(tp=='ok'){
		upload();
	}
	if(tp=='cancel'){
		nzWindow.close();
	}
}

dojo.require("dojo.io.iframe");
function upload(){
	var doc = nzWindow.getPage().contentWindow.document;
	
	if(doc.getElementById("upload").value==""||doc.getElementById("upload").value==null){
	   alert('请选择要上传的文件');
	   return false;
	}	
	
	var detailForm = doc.getElementById('detailForm');
	doc.getElementById("uploadFileName").value=doc.getElementById("upload").value;
	var fileName = doc.getElementById("upload").value;
	
	//如果是IE
	if(window.navigator.userAgent.indexOf("MSIE")>=1){
		var temName = fileName.substring(fileName.lastIndexOf("\\")+1,fileName.length);
		if(temName.length > 14){
			alert('文件名称长度不能超过14，请重新选择！');
			return false;
		}
	}
	//如果是火狐
	else if(window.navigator.userAgent.indexOf("Firefox")>=1){
		if(fileName.length > 14){
			alert('文件名称长度不能超过14，请重新选择！');
			return false;
		}
	}else{//以后可能有其他浏览器，再说。。。
		if(fileName.length > 14){
			alert('文件名称长度不能超过14，请重新选择！');
			return false;
		}
	}
	
	var isOk=0;
	if(fileName.lastIndexOf(".") != -1){
		var fileType = (fileName.substring(fileName.lastIndexOf(".")+1,fileName.length)).toLowerCase();
		var suppotFile = new Array();
		suppotFile[0]="pdf";
		suppotFile[1]="jpg";
		suppotFile[2]="gif";
		suppotFile[3]="bmp";
		suppotFile[4]="png";
		for(var i=0;i<suppotFile.length;i++){
			if(suppotFile[i] == fileType){
				isOk++;
			}else{
				continue;
				isOk++;
			}
		}
		if(isOk==1){		
			dojo.io.iframe.send({
				form:doc.getElementById("detailForm"),
				url: "upload.uploadFile.xhtml",
				method:"post",
				handleAs:"text",
				handle:function(response){
					response=decodeURI(response);
					if(response.indexOf('error') != -1){
						alert("文件上传失败！");
					}else{
						alert("文件上传成功！");
						dojo.byId(inputId).value=response.replace(/[+]/g," ");
					}
				},
				error:function(data,ioArgs){
					alert("上传出错！");
				}
			});
		}
		else{
			alert('图片格式只支持pdf、jpg、gif、bmp、png 格式');
		}
	}
	return false;
 }
