/* @charset "UTF-8" */
$(function () {
	if (IntervalStatData && IntervalStatData.registerDrag) {
		IntervalStatData.registerDrag(function (data) {
			$('#fz周期数').html(data.periodNum);
			$('#begintime').val(data.begin);
			$('#endtime').val(data.end);
		});
	}
	
	// 屏蔽右键
	document.onkeydown	= function () {
		if (event.keyCode == 116) {
			event.keyCode	= 0;
			event.cancelBubble	= true;
			return false;
		}
	}
	
	$(window).unload(function () {
		release();
	});
});

/**
 * 释放变量
 * @returns
 */
var release	 = function ()
{
	if (IntervalStatData) {
		if (IntervalStatData.release) {
			IntervalStatData.release();
		}
		delete(IntervalStatData);
	}
};

/**
 * 日期选择处理
 * @param operateObj 选择框
 * @param beginOrEnd 起始时间还是结束时间 begin|end
 * @param currentPeriod 当前周期
 * @returns
 */
var selectDate = function (operateObj, beginOrEnd, currentPeriod) {
	var WdatePickerParams = {};
	if (currentPeriod < 16384) {
		WdatePickerParams['dateFmt'] = 'yy-MM-dd HH:mm';
		if (beginOrEnd == 'begin') {
			WdatePickerParams['maxDate'] = '#F{$dp.$D(\'endtime\')||\'%y-%M-%d %H:%m\'}';
		} else {
			WdatePickerParams['minDate'] = '#F{$dp.$D(\'begintime\')}';
			WdatePickerParams['maxDate'] = '%y-%M-%d %H:%m';
		}
		WdatePickerParams['onpicked'] = function(dp) {
			var pickedYear		= dp.cal.getP('y', 'yyyy');
			var pickedMonth		= dp.cal.getP('M', 'MM');
			var pickedDay		= dp.cal.getP('d', 'dd');
			var pickedHour		= dp.cal.getP('H', 'HH');
			var pickedMinute	= dp.cal.getP('m', 'mm');
			visionTime			= pickedYear+pickedMonth+pickedDay+pickedHour+pickedMinute;
			formatTime			= minuteToData(visionTime);
			//调用客户端接口，处理选择的日期
			if (beginOrEnd == 'begin') {
				var params = {
						begintime	: formatTime,
						endtime		: IntervalStatData.getOriginalEndTime()
				};
				var setZone = IntervalStatData.setAreaStatTime(params);
			} else {
				var params = {
						begintime	: IntervalStatData.getOriginalBeginTime(),
						endtime		: formatTime
				};
				var setZone = IntervalStatData.setAreaStatTime(params);
			}
			var data = requestData();
			handleData(data);
		};
	} else {
		WdatePickerParams['dateFmt'] = 'yyyy-MM-dd';
		if (beginOrEnd == 'begin') {
			WdatePickerParams['maxDate'] = '#F{$dp.$D(\'endtime\')||\'%y-%M-%d\'}';
		} else {
			WdatePickerParams['minDate'] = '#F{$dp.$D(\'begintime\')}';
			WdatePickerParams['maxDate'] = '%y-%M-%d';
		}
		WdatePickerParams['onpicked'] = function(dp) {
			var pickedYear		= dp.cal.getP('y', 'yyyy');
			var pickedMonth		= dp.cal.getP('M', 'MM');
			var pickedDay		= dp.cal.getP('d', 'dd');
			formatTime			= pickedYear+pickedMonth+pickedDay;
			//调用客户端接口，处理选择的日期
			if (beginOrEnd == 'begin') {
				var params = {
						begintime	: formatTime,
						endtime		: IntervalStatData.getOriginalEndTime()
				};
				var setZone = IntervalStatData.setAreaStatTime(params);
			} else {
				var params = {
						begintime	: IntervalStatData.getOriginalBeginTime(),
						endtime		: formatTime
				};
				var setZone = IntervalStatData.setAreaStatTime(params);
			}
			var data = requestData();
			handleData(data);
		};
	}
	
	operateObj.click(function(){
		WdatePicker(WdatePickerParams);
	});
};
