(function() {
	AjaxTool = {
			XRequest:function(url, data, async, type, dataType, successfn, errorfn){
		        async = (async==null || async=="" || typeof(async)=="undefined")? "true" : async;
		        type = (type==null || type=="" || typeof(type)=="undefined")? "post" : type;
		        dataType = (dataType==null || dataType=="" || typeof(dataType)=="undefined")? "json" : dataType;
		        data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
		        $.ajax({
		            type: type,
		            async: async,
		            data: data,
		            timeout : 10000, //超时时间设置，单位毫秒
		            url: url,
		            //contentType: "application/json; charset=utf-8",
		            dataType: dataType,
		            beforeSend: function() {
						startloading();
					},
		            success: function(d){
		                successfn(d);
		            },
		            error: function(e){
		                errorfn(e);
		            },
					complete: function(xhr, status) {
						setTimeout(function() {
							try{
                                stoploading();
							}catch(e){

							}
						}, 500);
					}
		        });
		    
			},
			XGet:function(url, data, successfn,errorfn){
		        data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
		        $.ajax({
		            type: "get",
		            data: data,
		            timeout : 10000, //超时时间设置，单位毫秒
		            url: url,
		            dataType: "json",
		            beforeSend: function() {
						startloading();
					},
		            success: function(d){
		                successfn(d);
		            },
		            error: function(e){
		                errorfn(e);
		            },
					complete: function(xhr, status) {
						setTimeout(function() {
							try{
								layer.closeAll();
							}catch(e){

							}
						}, 500);
					}
		        });
		    
			},
			XPost:function(url, data, successfn, errorfn){
		        data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
		        $.ajax({
		            type: "post",
		            data: data,
		            url: url,
		            timeout : 100000, //超时时间设置，单位毫秒
		            dataType: "json",
		            beforeSend: function() {
						startloading();
					},
		            success: function(d){
		                successfn(d);
		            },
		            error: function(e){
		                errorfn(e);
		            },
					complete: function(xhr, status) {
						setTimeout(function() {
							try{
                                stoploading();
							}catch(e){

							}
						}, 500);
					}
		        });
		    
			},
			/**
			 * 支持json数组对象传递
			 */
			XPostx:function(url, data, successfn, errorfn){
		        data = (data==null || data=="" || typeof(data)=="undefined")? {"date": new Date().getTime()} : data;
		        $.ajax({
		            type: "post",
		            data: data,
		            timeout : 10000, //超时时间设置，单位毫秒
		            url: url,
		            contentType: 'application/json', // 这句不加出现415错误:Unsupported Media Type
		            dataType: "json",
		            beforeSend: function() {
						startloading();
					},
		            success: function(d){
		                successfn(d);
		            },
		            error: function(e){
		                errorfn(e);
		            },
					complete: function(xhr, status) {
						setTimeout(function() {
							try{
                                stoploading();
							}catch(e){

							}
						}, 500);
					}
		        });
		    
			}
	};
	
})();
(function() {
	CommTool = {
			selectUserDialog:function(callback,sType,ctx,org,orgTree){
				layer
				.open({
					type : 2
					,
					area : [ '900px', '600px' ],
					title : '选择员工',
					shade : 0.6 //遮罩透明度 
					,
					btn : [ '确定', '取消' ],
					maxmin : true //允许全屏最小化 
					,
					anim : 1 //0-6的动画形式，-1不开启 
					,
					content :ctx+ '/common/selectUserDialogUi?orgId='+(org?org:'')+'&orgTree='+(orgTree?orgTree:''),
					yes : function(index, layero) {
						var backJsonData = $(".layui-layer-content iframe")[0].contentWindow.callBackData();
						if(typeof(backJsonData)=='undefined'){
							return;
						}
						if(!sType && backJsonData.length>1){
							layer.msg("只能选择一条数据",{icon:7});
							return ;
						}
						callback(backJsonData);
						layer.close(index);
					},
					cancel : function() {
						
					}
				});
			},
           selectOrgDialog:function(callback,ctx){
            layer
                .open({
                    type : 2
                    ,

                    title : '选择组织',
                    shade : 0.6 //遮罩透明度
                    ,
                    area : [ "600px", "70%" ],
                    content : ctx+'/common/selectOrgUi',
                    btn : [  '取消' ],
                    maxmin : true //允许全屏最小化
                    ,
                    anim : 1 //0-6的动画形式，-1不开启
                    ,
                    cancel : function() {

                    }
                });
            }
	}
	
})();
//表单json格式化方法,不使用&拼接
(function($) {
	$.fn.serializeJson = function() {
		var serializeObj = {};
		var array = this.serializeArray();
		$(array).each(
				function() {
					if (serializeObj[this.name]) {
						if ($.isArray(serializeObj[this.name])) {
							serializeObj[this.name].push(this.value);
						} else {
							serializeObj[this.name] = [
								serializeObj[this.name], this.value ];
						}
					} else {
						serializeObj[this.name] = this.value;
					}
				});
		return serializeObj;
	};
	Date.prototype.format = function(format) {
		var o = {
				"M+" : this.getMonth() + 1, // month
				"d+" : this.getDate(), // day
				"h+" : this.getHours(), // hour
				"m+" : this.getMinutes(), // minute
				"s+" : this.getSeconds(), // second
				"q+" : Math.floor((this.getMonth() + 3) / 3), // quarter
				"S" : this.getMilliseconds()// millisecond
		}
		if (/(y+)/.test(format)) {
			format = format.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
		}
		for ( var k in o) {
			if (new RegExp("(" + k + ")").test(format)) {
				format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
				: ("00" + o[k]).substr(("" + o[k]).length));
			}
		}
		return format;
	}
})(jQuery);

//启动加载
var loadingobject = null;
function startloading() {
	try{
	loadingobject = layer.load(4, {
		shade: [0.1,'#fff'] //0.1透明度的白色背景
	});
	}catch(e){
		
	}
}
//停止加载
function stoploading() {
	try{
		layer.close(loadingobject);
	}catch(e){

	}
}
/**
 * 格式化日期
 * @param now
 * @returns
 */
function formatDate(now) { 
	var year=now.getFullYear(); 
	//alert(year);
	var month=now.getMonth()+1; 
	var date=now.getDate(); 
	var hour=now.getHours(); 
	var minute=now.getMinutes(); 
	var second=now.getSeconds(); 
	return year+"-"+p(month)+"-"+p(date)+" "+p(hour)+":"+p(minute)+":"+p(second); 
} 
function p(s) {
	return s < 10 ? '0' + s: s;
}
/**
 * 清除定时器
 * @returns
 */
function clearAllTimer(){
	try{
		clearInterval(taskinterval);
	}catch(error){
		
	}
}

function jxinfo(){
    var url = '/basejx/jxinfo';

 showBox = layer.open({
     title: "绩效评分标准",
     type: 2,
     area: ["80%", "400px"],
     content: url
 });
   
 }


