define(function(require){
	var $ = require('jquery');
	require('dialog')($);
	var flag=$("#dispatcherTimerReminder").val();
	if(flag=="true"){
		timerReminder($("#timerCycle").val());
	}else if(flag==""){
		queryAuth();
	}
	//验证登陆用户是否有权限
	function queryAuth(){
		$.ajax({
			type:"get",
			url:$("#reservationTimerReminder").val(),
			success:function(response){
			var status=response.dispatcherTimerReminder;
			if(status){
				timerReminder(response.cycle);
				$("#timerCycle").val(response.cycle);
			}
			$("#dispatcherTimerReminder").val(status);
			}});
		}
	
	/*
	 * 查询是否存在48H将要过期车辆.
	 * 有权限的访问入口  倒时器
	 */
	function timerReminder(cooldown){
		//生命周期，单位秒
		var count=cooldown;
		var hidden=cooldown-8;
		countdown=setInterval(function(){
			if(count==hidden){
				$("#dispatcherTips").dialog("close");
			}
			if(count==0){
				var status=queryResult();
				if(status){
					count=cooldown;
				}else{
					clearInterval(countdown);
				}
				}
			count--;
			},1000);
	 }
	/*
	 * 查询是否存在48H将要过期车辆.无权限则退出
	 */
	function queryResult(){
		var logIn=false;
		$.ajax({
			type:"post",
			async:false,
			url:$("#reservationTimerReminder").val(),
			success:function(response){
			if(response.auth){
			var resNoList=response.resNoList;
			var total=response.total;
			if(total!=0){
			var messageTips=i18n['System.record.waiting.process'].patchContent(total);
			$("#dispatcherTips").html(messageTips);
			$.msg.alert(i18n['Page.Dialog.title'],$("#dispatcherTips"));
			}
			logIn=true;
			}
			},
			error:function(){
				logIn=false;
			}});
		return logIn;
	}
});