var helper = {};

helper.http = {
	newXMLHttp: function() {
		var XMLHttp = null;
		if(window.XMLHttpRequest) {
			XMLHttp = new XMLHttpRequest();
		}
		if(XMLHttp == null && window.ActiveXObject) {
			var clsids = ["MSXML2.XMLHttp.7.0", "MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp.2.0", "MSXML2.XMLHttp.1.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];
			for(var i = 0; i < clsids.length && XMLHttp == null; i++) {
				try {
					XMLHttp = new ActiveXObject(clsids[i]);
				} catch(e) {}
			}
		}
		return XMLHttp;
	},
	get: function(URL, func) {
		try {
			var XMLHttp = this.newXMLHttp();
			if(typeof(func) != "function") {
				XMLHttp.open("GET", URL, false);
				XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
				XMLHttp.send(null);

				var result = XMLHttp.status;
				var responseText = XMLHttp.responseText;

				if(result == 200) {
					return responseText;
				} else {
					return result;
				}
			} else {
				XMLHttp.onreadystatechange = function() {
					if(XMLHttp.readyState == 4) {
						if(XMLHttp.status == 200) {
							var responseText = XMLHttp.responseText;
							func(responseText);
						} else {
							func(false);
						}
					}
				};
				XMLHttp.open("GET", URL, true);
				XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
				XMLHttp.send(null);
			}
		} catch(e) {}
	},
	post: function(URL, data, func) {
		try {
			var XMLHttp = this.newXMLHttp();
			if(typeof(func) != "function") {
				XMLHttp.open("POST", URL, false);
				XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
				XMLHttp.send(data);

				var result = XMLHttp.status;
				var responseText = XMLHttp.responseText;

				if(result == 200) {
					return responseText;
				} else {
					return false;
				}
			} else {
				XMLHttp.onreadystatechange = function() {
					if(XMLHttp.readyState == 4) {
						if(XMLHttp.status == 200) {
							var responseText = XMLHttp.responseText;
							func(responseText);
						} else {
							func(false);
						}
					}
				};

				XMLHttp.open("POST", URL, true);
				XMLHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
				XMLHttp.send(data);
			}
		} catch(e) {}
	}
};

helper.cookies = {
	del: function(name) {
		var exp = new Date();
		exp.setTime(exp.getTime() - 1);
		var cval = helper.cookies.get(name);
		if(cval != null)
			document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
	},
	set: function(name, value, remember) {
		if(remember == true) {
			var Days = 30;
			var exp = new Date();
			exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
			document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();
		} else {
			document.cookie = name + "=" + escape(value) + ";path=/";
		}
	},
	setday: function(name, value, remember) {
		var Days = remember;
		var exp = new Date();
		exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
		document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString();

	},
	setdomain: function(name, value, remember) {
		var domain = window.location.host.split(".");
		if(remember == true) {
			var Days = 30;
			var exp = new Date();
			exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
			document.cookie = name + "=" + escape(value) + ";path=/;expires=" + exp.toGMTString() + ";domain=." + domain[domain.length - 2] + "." + domain[domain.length - 1];
		} else {
			document.cookie = name + "=" + escape(value) + ";path=/" + ";domain=." + domain[1] + "." + domain[2];
		}
	},
	get: function(name) {
		var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

		if(arr = document.cookie.match(reg)) {
			return unescape(arr[2]);
		} else {
			return '';
		}
	}
};

/*
获取URL中指定的参数
例如：
URL:test.com/test.aspx?test=t
var t=help.request.queryString("test");
得到t
*/
helper.request = {
	queryString: function(item) {
		locationSearch = "";
		var tmpLocationArr = location.href.split("?");
		if(tmpLocationArr.length > 1) locationSearch = "?" + tmpLocationArr[1];
		var svalue = locationSearch.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
		var Qvalue = svalue ? svalue[1] : svalue;
		if(Qvalue == null) {
			return "";
		} else {
			return Qvalue.trim();
		}
	},
	queryurl: function(url, item) {
		locationSearch = "";
		var tmpLocationArr = url.split("?");
		if(tmpLocationArr.length > 1) locationSearch = "?" + tmpLocationArr[1];
		var svalue = locationSearch.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
		var Qvalue = svalue ? svalue[1] : svalue;
		if(Qvalue == null) {
			return "";
		} else {
			return Qvalue.trim();
		}
	}
};

helper.pager = {

	//分页
	PageList1: function(strFunName) {
		/***总页数***/
		var intPageCount = parseInt((parseInt(intRecordCount) + parseInt(intPageSize) - 1) / parseInt(intPageSize));
		if(intPageCount <= 1) {
			return "";
		}

		/***页码距***/
		var intPageCurrent = 10;

		/***起始页码***/
		var intStartPage = (parseInt((parseInt(intPageIndex) + intPageCurrent - 1) / intPageCurrent) - 1) * intPageCurrent + 1;

		/***结束页码***/
		var intEndPage = intStartPage + intPageCurrent - 1;
		if(intPageIndex % intPageCurrent == 0) {
			intStartPage++;
			intEndPage++;
		}

		if(intPageIndex % intPageCurrent - 1 == 0 && intPageIndex != 1) {
			intStartPage--;
			intEndPage--;
		}

		if(intEndPage >= intPageCount) {
			intEndPage = intPageCount;
		}

		/***上一页，下一页***/
		var intUpPage = parseInt(intPageIndex) - 1;
		var intDownPage = parseInt(intPageIndex) + 1;
		var strUpPage = "<a href=\"#\" onclick=\"" + strFunName + "(" + intUpPage + ")\" >上一页</a>";
		var strDownPage = "<a href=\"#\" onclick=\"" + strFunName + "(" + intDownPage + ")\">下一页</a>";
		if(intUpPage < 1) {
			//intUpPage = 1;
			strUpPage = "";
		}
		if(intPageIndex >= intPageCount) {
			//intDownPage = intPageCount;
			strDownPage = "";
		}

		/***生成页码列表***/
		var strPageList = strUpPage;

		for(var i = intStartPage; i <= intEndPage; i++) {
			if(intPageIndex == i) {
				/***当前页码***/
				strPageList += "<a style=\"background-image:url(../images/bg/menublue22.jpg); background-position:bottom; background-repeat:repeat-x; padding:1px 6px;border-radius: 4px 4px 4px 4px; margin-right:3px; border:1px solid #aeb2b1;\" >" + i + "</a>";
			} else {
				strPageList += "<a href=\"#\" onclick=\"" + strFunName + "(" + i + ");\">" + i + "</a>";
			}
		}
		strPageList += strDownPage;

		//直接跳转
		strPageList += "总页数：" + intPageCount + "&nbsp;&nbsp;/&nbsp;&nbsp;";
		strPageList += "<input type=\"text\" onkeyup=\"this.value=this.value.replace(/\\D/g,'')\" id=\"tb_index\" />";
		strPageList += "&nbsp;&nbsp;<a style=\"cursor:pointer;\" onclick=\"javascript:helper.pager.checkPageValue()\">跳转</a>";
		return strPageList;

	},
	checkPageValue: function() {
		var intPageIndexNext = document.getElementById('tb_index').value;
		if(parseInt(intPageIndexNext) == 0) {
			document.getElementById('tb_index').value = "1";
			$.jBox.alert('输入页面不能为0', '提示');
			return;
		}
		if(intPageIndexNext == "") {
			document.getElementById('tb_index').value = "1";
			$.jBox.alert('输入页面不能为空', '提示');
			return;
		}
		if(intPageIndexNext.length != 0) {
			var intPageCount = parseInt((parseInt(intRecordCount) + parseInt(intPageSize) - 1) / parseInt(intPageSize));
			if(intPageIndexNext <= intPageCount) {
				intPageIndex = intPageIndexNext;
				loadlist();
			} else {
				document.getElementById('tb_index').value = intPageCount;
				$.jBox.alert('输入页面不能大于总页数', '提示');
			}
		} else {
			document.getElementById('tb_index').value = "1";
		}
	},
	loadJS: function(url) {
		var domScript = document.createElement('script');
		domScript.type = "text/javascript";
		domScript.src = url;
		domScript.onload = domScript.onreadystatechange = function() {
			if(!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
				this.onload = this.onreadystatechange = null;
				this.parentNode.removeChild(this);
			}
		};
		document.getElementsByTagName('head')[0].appendChild(domScript);
	}
};

helper.masklayer = {
	layer: null,
	showcount: 0,
	show: function() {
		this.layer = document.getElementById("masklayer");
		if(!this.layer) {
			this.layer = document.createElement("div");
			this.layer.id = "masklayer";
			this.layer.className = "masklayer";
			/*this.layer.style.position = "absolute";
			this.layer.style.top = "0";
			this.layer.style.left = "0";
			this.layer.style.zIndex = 1000;
			var width = Math.max(
			Math.max(document.body.clientWidth, document.documentElement.clientWidth),
			Math.max(document.body.scrollWidth, document.documentElement.scrollWidth)
			);
			var height = Math.max(
			Math.max(document.body.clientHeight, document.documentElement.clientHeight),
			Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
			);
			this.layer.style.width = width + "px";
			this.layer.style.height = height + "px";*/
			this.layer.innerHTML = "<iframe src='/blank.html' style='width:100%;height:100%;background-color:#fff;" +
				"filter:alpha(opacity=0);-moz-opacity:0;-khtml-opacity: 0;opacity: 0;" +
				"position:absolute;z-index:999;top:0;left:0;' frameborder='0'></iframe>" +
				"<div style='width:100%;height:100%;position:absolute;top:0;left:0;z-index:1000;background:#000;" +
				"filter:alpha(opacity=20);-moz-opacity:0.2;-khtml-opacity: 0.2;opacity: 0.2;'></div>";
			document.body.appendChild(this.layer);
		}
		this.showcount++;
	},
	hide: function() {
		if(--this.showcount == 0) {
			if(this.layer && this.layer.parentNode) {
				this.layer.parentNode.removeChild(this.layer);
			}
		}
	},
	moveToCenter: function(e, x, y) {
		if(e.style.display == "none") e.style.display = "";
		var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
		var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);
		if(x > 0) {
			x += scrollLeft;
		} else x = parseInt((document.documentElement.clientWidth - e.clientWidth) / 2) + scrollLeft;
		if(y > 0) {
			y += scrollTop;
		} else y = parseInt((document.documentElement.clientHeight - e.clientHeight) / 2) + scrollTop;
		x = x < 0 ? 0 : x;
		y = y < 50 ? 50 : y;
		e.style.left = x + "px";
		e.style.top = y + "px";
	}
};

helper.filter = {
	Transcoding: function(content) {
		content = content.replace(/∞L/g, "<");
		content = content.replace(/∞R/g, ">");
		content = content.replace(/∞∴/g, "'");
		content = content.replace(/∞≡/g, "#");
		content = content.replace(/∞※/g, "\"");
		return content;
	}
};


helper.methods = {
	/**
	 * 文件上传删除
	 * @param  string smallimgUrl 小图 当该值为 null时是非图片类型
	 * @param  string bigimgUrl   大图
	 */
	delImgs: function(smallimgUrl, bigimgUrl) {
		//console.log("文件删除01========" + smallimgUrl);
		//console.log("文件删除02========" + bigimgUrl);
		if(smallimgUrl === null) {
			$.get(bigimgUrl, {
				isdel: 1,
			});
		} else {
			$.get(smallimgUrl, {
				isdel: 1,
			});
			$.get(bigimgUrl, {
				isdel: 1,
			});
		}
	},
	//点击操作图标
	taskTools: function(taskobj) {
		$(taskobj).find('.tool_down').toggle();
		$(taskobj).parent().parent().siblings().find('.tool_down').hide();
	},
	//数组去重
	unique: function(arr) {　　
		var res = [];　　
		var json = {};　　
		for(var i = 0; i < arr.length; i++) {
			if(!json[arr[i]]) {　　　　　　
				res.push(arr[i]);　　　　　　
				json[arr[i]] = 1;　　　　
			}　　
		}　　
		return res;
	},
	/**
	 * 对象数组去重(用于自定义字段保存时)
	 * @oldArr 数组
	 * @name 要比较的属性 String
	 */
	uniqueObjArray: function(oldArr, name) {
		var allArr = [];
		for(var i = 0; i < oldArr.length; i++) {　　
			var flag = true;　　
			for(var j = 0; j < allArr.length; j++) {
				if(oldArr[i][name] == allArr[j][name]) {　　　　　　
					flag = false;　　　　
				};　　
			};
			if(flag) {　　　　
				allArr.push(oldArr[i]);　　
			};
		};
		return allArr;
	},
	//比较器（可以根据对象的属性进行比较）  用法 arr.sort(compare('age'))
	//sequence 正序 (有小到大)1     还是倒序 -1
	compare: function(prop, sequence) {
		return function(obj1, obj2) {
			var val1 = obj1[prop];
			var val2 = obj2[prop];
			//将数字 字符串 转为数字
			if(!isNaN(Number(val1)) && !isNaN(Number(val2))) {
				val1 = Number(val1);
				val2 = Number(val2);
			}
			//值是 时间字符串 转为 时间戳
			if(isNaN(val1) && !isNaN(Date.parse(val1)) && isNaN(val2) && !isNaN(Date.parse(val2))) {
				val1 = Number(new Date(val1));
				val2 = Number(new Date(val2));
			}
			if(val1 < val2) {
				return(-1) * (sequence);
			} else if(val1 > val2) {
				return 1 * (sequence);
			} else {
				return 0;
			}
		}
	},
	/**
	 * 将一维的扁平数组转换为多层级对象
	 * @param  {[type]} list 一维数组，数组中每一个元素需包含id和ParentId两个属性 
	 * @return {[type]} tree 多层级树状结构
	 */
	buildTree: function(list) {
		var temp = {};
		var tree = {};
		var arr = [];
		for(var j in list) {
			temp[list[j].id] = list[j];
		}
		for(var i in temp) {
			if(temp[i].ParentId) {
				if(!temp[temp[i].ParentId].children) {
					temp[temp[i].ParentId].children = new Object();
				}
				temp[temp[i].ParentId].children[temp[i].id] = temp[i];
			} else {
				tree[temp[i].id] = temp[i];
			}
		}
		for(var k in tree) {
			arr.push(tree[k]);
		}
		return arr;
	},
	objToArray: function(mobj) {
		var arr = [];
		for(var k in mobj) {
			arr.push(mobj[k]);
		}
		return arr;
	},
	arrayToObj: function(marr) {
		var tobj = {};
		for(var k in marr) {
			tobj[k] = marr[k];
		}
		return tobj;
	},
	// 判断浏览器是否支持placeholder属性
	isSupportPlaceholder: function() {
		var input = document.createElement('input');
		return 'placeholder' in input;
	},
	/**
	 * 判断是否是IE浏览器 版本，包括Edge浏览器(下面是返回值)
	 * -1	Number	 不是ie浏览器
	 * 6	Number	ie版本<=6
	 * 7	Number	ie7
	 * 8	Number	ie8
	 * 9	Number	ie9
	 * 10	Number	ie10
	 * 11	Number	ie11
	 * 'edge'	String	ie的edge浏览器
	 */
	IEVersion: function() {
		var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串  
		var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1; //判断是否IE<11浏览器  
		var isEdge = userAgent.indexOf("Edge") > -1 && !isIE; //判断是否IE的Edge浏览器  
		var isIE11 = userAgent.indexOf('Trident') > -1 && userAgent.indexOf("rv:11.0") > -1;
		if(isIE) {
			var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
			reIE.test(userAgent);
			var fIEVersion = parseFloat(RegExp["$1"]);
			if(fIEVersion == 7) {
				return 7;
			} else if(fIEVersion == 8) {
				return 8;
			} else if(fIEVersion == 9) {
				return 9;
			} else if(fIEVersion == 10) {
				return 10;
			} else {
				return 6; //IE版本<=7
			}
		} else if(isEdge) {
			return 'edge'; //edge
		} else if(isIE11) {
			return 11; //IE11  
		} else {
			return -1; //不是ie浏览器
		}

	},
	/**
	 * 鼠标滚轮放大缩小
	 * o img元素
	 * d 滚轮的方向
	 * */
	zoomImg: function(o, d) {
		console.log(o);
		console.log(d);
		//d 1 上 -1 下
		var width = $(o).width();
		var height = $(o).height();
		if(d === 1) {
			$(o).css({
				"left": "50%",
				"marginLeft": -(width * 1.2) / 2,
				"top": "50%",
				"marginTop": -(height * 1.2) / 2,
				"width": width * 1.2,
				"height": height * 1.2
			});
		}
		if(d === -1) {
			$(o).css({
				"left": "50",
				"marginLeft": -(width * 1.2) / 2,
				"top": "50%",
				"marginTop": -(height * 1.2) / 2,
				"width": width / 1.2,
				"height": height / 1.2
			});
		}
	},
	/**
	 * 初始化layer-photo 图片的大小
	 * @el 图片元素
	 * @pic layer-photo 回调的参数 当前图片的一些信息
	 * @layero layer-photo 回调的参数 当前弹框的一些信息
	 */
	initLayerPhotos: function(el, pic, layero) {
		console.log($(el).find('img[alt="' + pic.alt + '"]'));
		console.log(el);
		console.log(pic);
		console.log(layero);
		var layerHeight = $(layero[0]).height();
		var picHeight = $(el).find('img[alt="' + pic.alt + '"]').height() / 2;
		var picWidth = $(el).find('img[alt="' + pic.alt + '"]').width() / 2;
		var rate = picWidth / picHeight;
		if(picHeight > layerHeight){
			picHeight = layerHeight - 110;
			picWidth  = rate * picHeight;
		}
		$(el).find('img[alt="' + pic.alt + '"]').css({
			width: picWidth,
			height: picHeight,
			overflow: 'auto', 
			margin: 'auto', 
			position: 'absolute', 
			top: 0, left: 0, bottom: 0, right: 0, 
		});
	}
}
function str2asc(strstr) {
	return("0" + strstr.charCodeAt(0).toString(16)).slice(-2);
}
helper.url = {
	getpara: function(name, url) {
		var val;
		paras = url ? url : window.location.search;
		paras = paras.substr(1);
		paraarray = paras.split("&");
		for(i = 0; i < paraarray.length; i++) {
			temp = paraarray[i].split("=");
			if(temp[0] == name) {
				val = temp[1];
				break;
			}
		}
		if(val == null || val == "") {
			return "";
		} else {
			return val;
		}
	}
};

helper.sys = {
	getElementsByClassName: function(pnode, className) {
		var nodes = pnode.getElementsByTagName('*');
		var elements = new Array();
		for(var i = 0; i < nodes.length; i++) {
			if(nodes[i].className == className) {
				elements[elements.length] = nodes[i];
			}
		}
		return elements;
	},
	removeElement: function(element) {
		if(element && element.parentNode) {

			element.parentNode.removeChild(element);
			return true;
		} else {
			return false;
		}
	},
	Return: function(url) {
		top.location.href = url;
	}
};

helper.getDropList = {
    //根据id 获取 区县，主干道、乡镇，路社区村
    getAreas: function (obj, aid) {
        var dtd = $.Deferred(); //在函数内部，新建一个Deferred对象
        obj.empty();
        $.getJSON(huayi.config.callcenter_url + "Area/GetAreaListById", {
            id: aid,
            token: $.cookie("token"),
        }, function (data) {
            if (data.state.toLowerCase() == "success") {
                var content = data.data;
                if (content && content.length > 0) {
                    obj.append('<option value="0">请选择</option>');
                    $(content).each(function (i, n) {
                        if (n.F_AreaName == "安阳市") {
                            $("<option selected='selected' value='" + n.F_AreaId + "'>" + n.F_AreaName + "</option>").appendTo(obj);
                        } else {
                            $("<option value='" + n.F_AreaId + "'>" + n.F_AreaName + "</option>").appendTo(obj);
                        }
                    });
                } else {
                    obj.append('<option selected="selected" value="0">没有数据</option>');
                }
                dtd.resolve(); // 改变Deferred对象的执行状态
            }
        });
        return dtd.promise(); // 返回promise对象
    },

    //区县，主干道、乡镇，路社区村三级联动（目前在来电弹屏中使用）
    getLocations: function (obj) {
        var dtd = $.Deferred(); //在函数内部，新建一个Deferred对象
        helper.getDropList.getAreas(obj, 0).then(function () {
            //主干道、乡镇
//          obj.change(function () {
//              if (obj.find("option:selected").val() != 0) {
//                  helper.getDropList.getAreas(obj1, obj.find("option:selected").val());
//              } else {
//                  obj1.empty();
//                  obj1.append('<option selected="selected" value="0">请选择</option>');
//                  $('#sourceaddress').val('');
//              }
//              obj1.trigger('change');
//          });
//
//          //路社区村
//          obj1.change(function () {
//              if (obj1.find("option:selected").val() != 0) {
//                  helper.getDropList.getAreas(obj2, obj1.find("option:selected").val());
//                  $('#sourceaddress').val(obj1.find("option:selected").text());
//              } else if (obj.find("option:selected").val() != 0) {
//                  obj2.empty();
//                  obj2.append('<option selected="selected" value="0">请选择</option>');
//                  $('#sourceaddress').val('');
//              }
//              obj2.trigger('change');
//          });
//
//          obj2.change(function () {
//              if (obj2.find("option:selected").val() != 0) {
//                  $('#sourceaddress').val(obj1.find("option:selected").text() + obj2.find("option:selected").text());
//              } else if (obj1.find("option:selected").val() != 0) {
//                  $('#sourceaddress').val(obj1.find("option:selected").text());
//              }
//              dtd.resolve(); // 改变Deferred对象的执行状态
//          });

        });

        return dtd.promise(); // 返回promise对象
    },
      //根据id 获取 区县，主干道、乡镇，路社区村
    getOrderAreas: function (obj) {
        var dtd = $.Deferred(); //在函数内部，新建一个Deferred对象
        obj.empty();
        $.getJSON(huayi.config.callcenter_url + "Area/GetAreaListById", {
            id: 0,
            token: $.cookie("token"),
        }, function (data) {
            if (data.state.toLowerCase() == "success") {
                var content = data.data;
                if (content && content.length > 0) {
                    obj.append('<option selected="selected" value="0">请选择区域</option>');
                    $(content).each(function (i, n) {
                        $("<option value='" + n.F_AreaId + "'>" + n.F_AreaName + "</option>").appendTo(obj);
                    });
                } else {
                    obj.append('<option selected="selected" value="0">没有数据</option>');
                }
                dtd.resolve(); // 改变Deferred对象的执行状态
            }
        });
        return dtd.promise(); // 返回promise对象
    }

}

helper.DateFormat = {
	d2s: function(postdate) {
		var second = 1000;
		var minutes = second * 60;
		var hours = minutes * 60;
		var days = hours * 24;
		var months = days * 30;
		var twomonths = days * 365;
		var myDate = new Date(Date.parse(postdate));
		if(isNaN(myDate)) {
			myDate = new Date(postdate.replace(/-/g, "/"));
		}
		var nowtime = new Date();
		var longtime = nowtime.getTime() - myDate.getTime();
		var showtime = 0;
		if(longtime > months * 2) {
			return postdate;
		} else if(longtime > months) {
			return "1个月前";
		} else if(longtime > days * 7) {
			return("1周前");
		} else if(longtime > days) {
			return(Math.floor(longtime / days) + "天前");
		} else if(longtime > hours) {
			return(Math.floor(longtime / hours) + "小时前");
		} else if(longtime > minutes) {
			return(Math.floor(longtime / minutes) + "分钟前");
		} else if(longtime > second) {
			return(Math.floor(longtime / second) + "秒前");
		} else {
			return("刚刚");
		}
	},
	getPreMonth:
		/**
		 * 获取上一个月
		 *
		 * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
		 */
		function(date) {
			var arr = date.split('-');
			var year = arr[0]; //获取当前日期的年份
			var month = arr[1]; //获取当前日期的月份
			var day = arr[2]; //获取当前日期的日
			var days = new Date(year, month, 0);
			days = days.getDate(); //获取当前日期中月的天数
			var year2 = year;
			var month2 = parseInt(month) - 1;
			if(month2 == 0) {
				year2 = parseInt(year2) - 1;
				month2 = 12;
			}
			var day2 = day;
			var days2 = new Date(year2, month2, 0);
			days2 = days2.getDate();
			if(day2 > days2) {
				day2 = days2;
			}
			if(month2 < 10) {
				month2 = '0' + month2;
			}
			var t2 = year2 + '-' + month2 + '-' + day2;
			return t2;
		},
	getNextMonth:
		/**
		 * 获取下一个月
		 *
		 * @date 格式为yyyy-mm-dd的日期，如：2014-01-25
		 */
		function(date) {
			var arr = date.split('-');
			var year = arr[0]; //获取当前日期的年份
			var month = arr[1]; //获取当前日期的月份
			var day = arr[2]; //获取当前日期的日
			var days = new Date(year, month, 0);
			days = days.getDate(); //获取当前日期中的月的天数
			var year2 = year;
			var month2 = parseInt(month) + 1;
			if(month2 == 13) {
				year2 = parseInt(year2) + 1;
				month2 = 1;
			}
			var day2 = day;
			var days2 = new Date(year2, month2, 0);
			days2 = days2.getDate();
			if(day2 > days2) {
				day2 = days2;
			}
			if(month2 < 10) {
				month2 = '0' + month2;
			}

			var t2 = year2 + '-' + month2 + '-' + day2;
			return t2;
		},
	getNowDate: function() {
		var NowDate;
		var myDate = new Date();
		myDate.getYear(); //获取当前年份(2位)    
		var YY = myDate.getFullYear(); //获取完整的年份(4位,1970-????)    
		var MM = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)    
		var DD = myDate.getDate(); //获取当前日(1-31)    
		myDate.getDay(); //获取当前星期X(0-6,0代表星期天)    
		myDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)    
		myDate.getHours(); //获取当前小时数(0-23)    
		myDate.getMinutes(); //获取当前分钟数(0-59)    
		myDate.getSeconds(); //获取当前秒数(0-59)    
		myDate.getMilliseconds(); //获取当前毫秒数(0-999)    
		myDate.toLocaleDateString(); //获取当前日期    
		var mytime = myDate.toLocaleTimeString(); //获取当前时间    
		myDate.toLocaleString(); //获取日期与时间    
		NowDate = YY + "-" + MM + "-" + DD;

		return NowDate;
	},
	getFirstDayInCurrentMonth: function() {
		var NowDate;
		var myDate = new Date();
		myDate.getYear(); //获取当前年份(2位)    
		var YY = myDate.getFullYear(); //获取完整的年份(4位,1970-????)    
		var MM = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)    
		var DD = myDate.getDate(); //获取当前日(1-31)    
		NowDate = YY + "-" + MM + "-1";

		return NowDate;
	},
	getFormatTime: function(longTime) {
		var time = parseFloat(longTime);
		if(time != null && time != "") {
			if(time < 60) {
				var s = time;
				time = s + '秒';
			} else if(time >= 60 && time < 3600) {
				var m = parseInt(time / 60);
				var s = parseInt(time % 60);
				time = m + "分钟" + s + "秒";
			} else if(time >= 3600 && time < 86400) {
				var h = parseInt(time / 3600);
				var m = parseInt(time % 3600 / 60);
				var s = parseInt(time % 3600 % 60 % 60);
				time = h + "小时" + m + "分钟" + s + "秒";
			} else if(time >= 86400) {
				var d = parseInt(time / 86400);
				var h = parseInt(time % 86400 / 3600);
				var m = parseInt(time % 86400 % 3600 / 60);
				var s = parseInt(time % 86400 % 3600 % 60 % 60);
				time = d + '天' + h + "小时" + m + "分钟" + s + "秒";
			}
		}
		return time;
	}

};
helper.string = {
	stringbuilder: function() {
		this.arr = new Array();
		this.append = function(str) {
			this.arr.push(str);
		};
		this.tostring = function() {
			return this.arr.join('');
		};
	}
};
helper.luyin = {
	view: function(ele) {
		var path = $(ele).attr("item");
        layer.open({
            type: 2,
            content: "../CommonHtml/recording.html?path=" + path, //iframe的url，no代表不显示滚动条
            title: '录音',
            area: ['30%', '20%'], //宽高
            maxmin: true,
            shade: 0
        });
	},
	isexist: function() {
	}
};
function turnIframe(str){
	$(".J_mainContent").empty();
    var n = '<iframe class="J_iframe" name="iframe25" width="100%" height="100%" src="' + str + '" frameborder="0" data-id="' + str + '" seamless></iframe>';
    $(".J_mainContent").append(n);
}
function download(url) {
    layer.load(2);
    var xmlResquest = new XMLHttpRequest();
    xmlResquest.open("GET", url, true);
    xmlResquest.setRequestHeader("Content-type", "application/json");
    //xmlResquest.timeout = timeout || (1000 * 60);// 超时时间，单位是毫秒
    xmlResquest.responseType = "blob";//该属性必须设置
    xmlResquest.onload = function (oEvent) {
        layer.closeAll('loading');
        var content = xmlResquest.response;
        var blob = new Blob([content]);

        //判断有没有请求头content-disposition，该请求头在后台文件流导出成功时添加
        if (xmlResquest.getAllResponseHeaders().indexOf('content-disposition')!=-1) {
            var elink = document.createElement('a');
            //获取文件名
            var fileName = xmlResquest.getResponseHeader("content-disposition").split(";")[1].split("=")[1];
            //响应头中的内容如果包含中文会出现乱码，需要解码才能正常显示
            var explorer = navigator.userAgent;
            if (explorer.indexOf("MSIE") >= 0 || explorer.indexOf("Chrome") >= 0) {  //IE和google浏览器
                fileName = decodeURIComponent(fileName);
            } else {
                fileName = decodeURI(escape(fileName));
            }
            elink.download = fileName;
            elink.style.display = 'none';
            elink.href = window.URL.createObjectURL(blob);
            document.body.appendChild(elink);
            elink.click();
            document.body.removeChild(elink);
            window.URL.revokeObjectURL(url);

        } else {//后台出现异常时的处理
            var r = new FileReader();
            r.readAsText(blob, 'utf-8');
            r.onload = function (e) {
                var data = JSON.parse(r.result);
                if (data.state.toLowerCase() == "error") {
                    layer.confirm(data.message, {
                        btn: ['确定']
                    });
                }
            }
        }
    };
    //xmlResquest.ontimeout = function (e) {
    //    layer.closeAll('loading');
    //    layer.confirm("导出超时，请重新导出！", {
    //        btn: ['确定'] //按钮
    //    });
    //};
    xmlResquest.onerror = function (e) {
        layer.closeAll('loading');
        layer.confirm("导出失败", {
            btn: ['确定'] //按钮
        });
    };
    xmlResquest.send();//发送请求
}
helper.init = {
	isload: 1,
	setajax: function() { /// 配置AJAX
		$(document).on("ajaxStart", function() {
			if(helper.init.isload) {
				//加载框显示
				layer.load(2);
			}
		}).on("ajaxSuccess", function(e, jqXHR, s, data) {
			try {
				if(s.type == "POST") {
					if(typeof(data) != 'object') {
						data = $.parseJSON(data);
					}
				}
				if(s.type == "GET") {
					data = data
				}
				if(data.state.toLowerCase() == "notoken") {
					top.window.location.href = "/login.html";
					return;
				}
				if(data.state.toLowerCase() == "unauthorized") {
					layer.confirm(data.message, {
						btn: ['确定'] //按钮
					});
				}
				if(data.state.toLowerCase() == "error") {
					layer.confirm(data.message, {
						btn: ['确定'] //按钮
					});
				}
			} catch(e) {
				if(helper.init.isload) {
					//加载框消失
					layer.closeAll('loading');
				}
			}
		}).on("ajaxStop", function() {
			if(helper.init.isload) {
				//加载框消失
				layer.closeAll('loading');
			}
		})
	},
	setdh: function() {
		$(document).ready(function() {
			$("#ReIndex").click(function() {
				top.$("iframe:visible")[0].src = "widgets.html";
			})
		})
	}
}

helper.init.setajax();
helper.init.setdh();