
var settings={"callback":function(){}};
/**
 * 上传组件
 */
jQuery.extend({          
    seocooUpload:function(options,callback) { 
		//创建form表单
	 	if(typeof(options.formName)=='undefined'||options.formName==''){
	 		//删除已有元素
	 		$('#uploadSImage').remove();
   	   	 	var form='<form action="" method="post" id="uploadSelfImage" name="uploadSelfImage" enctype="multipart/form-data" encoding="multipart/form-data">';
   	   	 		form+='<input type="file"  id="imageFile" name="imageFile" style="display:none;"  onchange="uploadSelfImg();"/>';
   	   	 		form+='<input type="hidden"  id="isPress"  name="isPress" value="0"/>';
   	   	 		form+='</form>';
   	   	 	$("body").append(form);
	   	 }
	 	var res=jQuery.isFunction(options);
	 	if(res){
			callback=options;
		}
    	var defaults={"fileName":"imageFile",
    				  "formName":"uploadSelfImage",
    				  "formAction":ctx+'/upload!uploadImage.do',
    				  "callback":callback};
   	 	 settings= $.extend(defaults,options);  
   	 	 //设置压缩属性
   	 	 if(typeof(options.isPress)!='undefined'&&options.isPress!=''){
   	 		 $('#isPress').val(settings.isPress);
   	 	 }
   	 	
   	 	//触发上传按钮
   	 	$('#'+settings.fileName).click();
     }
}); 

function showFailError(){
	alert("上传失败");
}

//上传
function uploadSelfImg(){
	
		var advertImgName =$('#'+settings.fileName).val();
		if (advertImgName == "" || advertImgName == null) {
			alert("请选择文件！");
			return;
		}
		var file_name = advertImgName
				.substring(advertImgName.lastIndexOf("\\") + 1);
		var filename_atr = advertImgName.substring(
				advertImgName.lastIndexOf(".") + 1, advertImgName.length);
		var reg1 = "gif,jpg,jpeg,png,bmp,GIF,JPG,JPEG,PNG,BMP";
		if ((reg1.indexOf(filename_atr) < 0)) {
			alert("请选择gif,jpg,jpeg,png,bmp格式的图片文件！");
			//$('#file').val('');
			$('#'+settings.fileName).val('');
			return;
		}
		//获取上传图片的大小(B)
		var imge=document.getElementById(settings.fileName);
		//超过1M的图片时
		if(imge.files.item(0).size>1048576){
			//$('#'+settings.fileName).val('');
			alert("图片太大，请上传小于1M的图片！");
			return;
		}
		var options = {
		      dataType : "json",
		      async: false,
		      data :{
		    	  'filename_atr': filename_atr
		    	  //'isPress':$('#isPress').val()
		      },
		      success :settings.callback,
		      error:showFailError,
		      timeout: 30000      //限制请求的时间，当请求大于3秒后，跳出请求
		  };
		$('#'+settings.formName).attr('action',settings.formAction);
		jQuery('#'+settings.formName).ajaxSubmit(options);
		$('#'+settings.formName).attr('action','');
}


/**
 * 上传组件
 */
/*jQuery.extend({          
    seocooUpload:function(options,callback) { 
    	var res=jQuery.isFunction(options);
		if(res){
			callback=options;
		}
    	var defaults={"fileName":"imageFile",
    				  "formName":"uploadImage",
    				  "formAction":ctx+'/upload!uploadImage.do'};
   	 	var settings= $.extend(options,defaults);  
   	 	//上传
   		var advertImgName =$('#'+settings.fileName).val();
   		if (advertImgName == "" || advertImgName == null) {
   			alert("请选择文件！");
   			return;
   		}
   		var file_name = advertImgName
   				.substring(advertImgName.lastIndexOf("\\") + 1);
   		var filename_atr = advertImgName.substring(
   				advertImgName.lastIndexOf(".") + 1, advertImgName.length);
   		var reg1 = "gif,jpg,jpeg,png,bmp,GIF,JPG,JPEG,PNG,BMP";
   		if ((reg1.indexOf(filename_atr) < 0)) {
   			alert("请选择gif,jpg,jpeg,png,bmp格式的图片文件！");
   			$('#file').val('');
   			return;
   		}
   		var options = {
   		      dataType : "json",
   		      async: false,
   		      data :{
   		    	  'filename_atr': filename_atr
   		      },
   		      success :callback,
   		      error:showFailError,
   		      timeout: 30000      //限制请求的时间，当请求大于3秒后，跳出请求
   		  };
   		$('#'+settings.formName).attr('action',settings.formAction);
   		jQuery('#'+settings.formName).ajaxSubmit(options);
   		$('#'+settings.formName).attr('action','');
     }
}); 

function showFailError(){
	alert("上传失败");
}*/

