
function fileupload(field){

	document.getElementById(field).onchange = function(event){  
													var img = event.target.files[0];   
													if(!img){  
														return false;  
													}  
													
													var reader = new FileReader();  
													reader.readAsDataURL(img);  
											  
													reader.onload = function(e){ 
													var  content="";
											$.post(upload_url, {'type':'html5',img: e.target.result},function(data){  
															if(data){ 
                                                           
															$("input[name='config["+field+"]']").val(data.id);						
						     var html = "<div class='upload-pre-item'><img src='" +data.path +"'> <span class='close' onclick='del(this,"+field+");'></span></div>"; 
							 console.log(field+$(".img"+field).text());
						$("#"+field).parents(".form-item").find('.upload_preview').html(html);
						$('#'+field).replaceWith('<input type="file" class="file" id="'+field+'"  />');
															
															}else{  
																alert('upload fail');  
															}  
														},'json'); 		
													
     
                                                          }
                    return false;
													} 
													
}
function upload(field){
	  iframeFileUpload({
	  url: url, // 后端 url
	  elementId: [field], // input表单的id数组集合
	   data: { // 发送到后端的data
		
	 },
	success: function (data) {
		  	 				  
					 var src=data.path;									   
					if(data.status == 200){  											
						$("input[name='"+field+"']").val(data.id);						
						     var html = "<div class='upload-pre-item'><img src='" +data.path +"'> <span class='close' onclick='del(this,"+field+");'></span></div>";
						$("#"+field).parents(".form-item").find('.upload_preview').html(html);
					 
					  }else{
						  
						alert(data.msg);  
					  }
	},
	error: function (data) {
		
	}
});
	  
  }
 function del(obj,field){ //删除
            $(obj).parents(".upload-pre-item").remove();
		   $("input[name='"+field+"']").val('');	
} 
  
function uploads(field){
	  iframeFileUpload({
	  url: url, // 后端 url
	  elementId: [field], // input表单的id数组集合
	   data: { // 发送到后端的data
		name: 'zym',
		blog: 'zymseo.com'
	 },
	success: function (data) {
		  	 				  
					 var src=data.path;									   
					if(data.status == 200){  											
						$("input[name='"+field+"']").val(data.id);						
						  var html = "<div class='upload-pre-item'><img src='" +src +"' data-id="+data.id+"> <span class='close' onclick='delimage(this,"+field+");'></span></div>";
						  $("#"+field).parents(".form-item").find(".upload_preview").append(html);
						   setinput(field); 
					 
					  }
	},
	error: function (data) {
		
	}
      });
	  
  }
  
 function delimage(obj,field){ //删除
            $(obj).parents(".upload-pre-item").remove();
		    setinput(field);
}
 function setinput(field){ //取值
		    var option =$("#"+field).parents(".form-item").find(".upload_preview img");
		    var result=new Array();
		    option.each(function(i){
		 	     result.push($(this).attr('data-id'));
		    });
           var ids= result.join(',');
            $("input[name='"+field+"']").val(ids);
} 
  
 function uploadvideo(field){
	  iframeFileUpload({
	  url: url, // 后端 url
	  elementId: [field], // input表单的id数组集合
	   data: { // 发送到后端的data
		name: 'zym',
		blog: 'zymseo.com'
	 },
	success: function (data) {
		  	 				  
					 var src=data.path;									   
					if(data.status == 200){  											
						$("input[name='"+field+"']").val(data.id);	
					
						$("#"+field).parents(".form-item").find('video').attr("src",src);					
						
					 
					  }
	},
	error: function (data) {
		
	}
});
	  
  } 