document.onkeydown = function (e) {//键盘按键控制
        e = e || window.event;
        if ((e.ctrlKey && e.keyCode == 82) || //ctrl+R
            e.keyCode == 116) {//F5刷新，禁止
            setTimeout(function () { window.location.reload(); }, 100);//延时提醒，要不alert会导致return false被alert挂起从而浏览器执行了刷新
            return false;
        }
    }
/*提示信息*/
//return toastr['error']('添加失败', '提示'); //success  成功绿色  info 信息，蓝色   warning，警告，橙色  error，错误，深红色
 //权限认证
 $(function(){
	   	if(localStorage.getItem("userType")==0){
	   		$("#index_ach").show();
	   		$("#index_dev").show();
	   		$("#index_des").show();
	   		$("#index_dek").show();
	   	}else if(localStorage.getItem("userType")==1){
	   		
	   	}
   })
 
 
  /**
   * 全选
   */
  
  $(function() {
    $('.table-sort').on('click', '.btn-checkall', function() {
      $('.btn-checkall').prop('checked', this.checked);
      $('[type="checkbox"][name="sublist"]').prop("checked", this.checked);
    });
    $('.table-sort').on('click', '[type="checkbox"][name="sublist"]', function() {
      $('.btn-checkall').prop("checked", $('[type="checkbox"][name="sublist"]').length == $('[type="checkbox"][name="sublist"]:checked').length ? true : false);
    });
    /**
     * 提示
     */
    $('.tips-icon,.tips-obj').hover(function() {
      $(this).find('.dialog-warp').show();
      $(this).find('.dialog-warp').stop();
      $(this).find('.dialog-warp').animate({
        "opacity": 1
      }, 300);
    }, function() {
      $(this).find('.dialog-warp').stop();
      $(this).find('.dialog-warp').animate({
        "opacity": 0
      }, 300);
      $(this).find('.dialog-warp').hide();
    })
    $('.dialog-warp').each(function() {
      var H = $(this).height();
      $(this).css('margin-top', -H / 2);
    });
    /**
     * 速度动画
     * @param {Object} obj
     */
    var $obj = $('.fly-numberAdd');
    $obj.each(function() {
      var $this = $(this);
      var max_number = $this.data("value"); //最大值
      var plus_number = Math.ceil(max_number / 99); //增加值,因为时间变化一样的
      var start_number = 0;
      var Interval = setInterval(function() {
        start_number += plus_number;
        if(start_number > max_number) {
          $this.html(max_number);
          clearInterval(Interval);
        } else { 
          $this.text(start_number);
        }
      }, 10);
    });
    /**
     * 数字过万则处理
     */
    $('.fly-number').each(function(i, obj) {
      var n = +$(obj).data('number');
      if(n > 10000) {
        $(obj).text((n / 10000).toFixed(2) + '万');
      }
    });
    
  });


//table配置项汉化
var lang = {
  "sProcessing": "<div class='loader'>加载中...</div>",
  "sLengthMenu": "每页 _MENU_ 项",
  "sZeroRecords": "换个搜索词试试呢？暂无数据",
  "sInfo": "当前显示第 _START_ 至 _END_ 项，全部 _TOTAL_ 项。",
  "sInfoEmpty": "当前显示第 0 至 0 项，全部 0 项",
  "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
  "sInfoPostFix": "",
  "sSearch": "本地搜索：",
  "sUrl": "",
  "sEmptyTable": "暂无数据",
  "sLoadingRecords": "载入中...",
  "sInfoThousands": ",",
  "oPaginate": {
    "sFirst": "首页",
    "sPrevious": "上一页",
    "sNext": "下一页",
    "sLast": "最后页",
    "sJump": "跳转至"
  },
  "oAria": {
    "sSortAscending": ": 以升序排列此列",
    "sSortDescending": ": 以降序排列此列"
  }
};

/**
 * 关闭弹出框口
 */
function layer_close() {
  var index = parent.layer.getFrameIndex(window.name);
  parent.layer.close(index);
}
/**
 *********************************扩展原生函数**********************************
 */
/**
 * addclass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function addClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  if(!inArray(array, classStr)) {
    array.push(classStr);
  }
  obj.className = array.join(' ');
  return obj;
}
/**
 * removeclass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function removeClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  var index = indexOf(array, classStr);
  if(index != -1) {
    classStr.splice(index, 1);
    obj.className = classStr.join(' ');
  }
  return obj;
}
/**
 * toggleClass函数封装
 * @param {Object} obj
 * @param {Object} classStr
 */
function toggleClass(obj, classStr) {
  var array = noRepeat(trim(obj.className).split('\s+'));
  if(inArray(array, classStr)) {
    removeClass(obj, classStr);
  } else {
    addClass(obj, classStr);
  }
}

/**
 * 格式化时间戳
 */
function replaceTime(nS) {
//return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
  var dt = new Date(nS * 1000);
		var date = [
			[dt.getFullYear(), dt.getMonth() + 1, dt.getDate()].join('-'), [dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(' : ')
		].join(' ').replace(/(?=\b\d\b)/g, '0');
		return date;
}

/**
 * 月日时间
 */
function replaceMonth(nS) {
//return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
  var dt = new Date(nS * 1000);
		var date = [
			[ dt.getMonth() + 1, dt.getDate()].join('-'), [dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(' : ')
		].join(' ').replace(/(?=\b\d\b)/g, '0');
		return date;
}
/**
 * 格式化时间戳
 */
function replaceTimeWithoutYear(nS) {
    var dt = new Date(nS * 1000);
    var date = [
        [dt.getMonth() + 1, dt.getDate()].join('-'), [dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(' : ')
    ].join(' ').replace(/(?=\b\d\b)/g, '0');
    return date;
}

/**
 * 格式化日期
 */
function replaceDate(nS) {
//return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
    var dt = new Date(nS * 1000);
    var date = [
        [dt.getFullYear(), dt.getMonth() + 1, dt.getDate()].join('-')
    ].join(' ').replace(/(?=\b\d\b)/g, '0');
    return date;
}




/**
 * 格式化时间点
 */
function replaceHourTime(nS) {
//return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/, ' ');
    var dt = new Date(nS * 1000);
    var date = [[dt.getHours(), dt.getMinutes(), dt.getSeconds()].join(' : ')
    ].join(' ').replace(/(?=\b\d\b)/g, '0');
    return date;
}
function getYMD(time){
    var dt = new Date(time * 1000);
    var date = [[dt.getFullYear(),(dt.getMonth()+1) , dt.getDate()].join('-')
    ].join(' ').replace(/(?=\b\d\b)/g, '0');
    return date;
}
//分秒
function formatSeconds(value) {
    var theTime = parseInt(value);// 秒
    var theTime1 = 0;// 分
    var theTime2 = 0;// 小时
    if(theTime > 60) {
        theTime1 = parseInt(theTime/60);
        theTime = parseInt(theTime%60);
            if(theTime1 > 60) {
            theTime2 = parseInt(theTime1/60);
            theTime1 = parseInt(theTime1%60);
            }
    }
        var result = ""+parseInt(theTime)+"秒";
        if(theTime1 > 0) {
        result = ""+parseInt(theTime1)+"分"+result;
        }
        if(theTime2 > 0) {
        result = ""+parseInt(theTime2)+"小时"+result;
        }
    return result;
}


/**
 * 求数组最大值
 */
Array.prototype.max = function() {
  return Math.max.apply(null, this);
};
/**
 * 求数组最小值
 */
Array.prototype.min = function() {
  return Math.min.apply(null, this);
};
/**
 * 数组排序
 * @param {name} name
 * arr.sort(sortBy('name'))
 */
function sortBy(name) {
  return function(o, p) {
    var a, b;
    if(typeof o === "object" && typeof p === "object" && o && p) {
      a = o[name];
      b = p[name];
      if(a === b) {
        return 0;
      }
      if(typeof a === typeof b) {
        return a < b ? -1 : 1;
      }
      return typeof a < typeof b ? -1 : 1;
    } else {
      throw("error");
    }
  }
};
/**
 * 时间差
 * @param {Object} olddate
 */
function timeDiff(olddate) {
  var old = new Date(olddate);
  var dateNum = (new Date()) - old;
  var days = dateNum / 1000 / 60 / 60 / 24;
  return Math.floor(days);
}
/**
 * 获取当前时间
 */
function getNowDate() {
  var now = new Date();
  return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
}

/**
 * 获取昨天的日期
 * @returns {string}
 */
function getYestoday() {
  var myDate=new Date();
  myDate.setDate(myDate.getDate()-1);
  return myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate();
}

/**
 * 获取一周前的日期
 * @returns {string}
 */
function getWeekBefor() {
  var myDate=new Date();
  myDate.setDate(myDate.getDate()-7);
  return myDate.getFullYear() + "-" + (myDate.getMonth() + 1) + "-" + myDate.getDate();
}

function getNowFormatDate() {
  var date = new Date();
  var seperator1 = "-";
  var seperator2 = ":";
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
      + " " + date.getHours() + seperator2 + date.getMinutes()
      + seperator2 + date.getSeconds();
  return currentdate;
}
/**
 * 获取星期几
 */
function getWeek() {
  return(new Date()).getDay();
}
getWeek();
/**
 * 数组的indexOf方法封装
 * @param {Object} arr
 * @param {Object} value
 * @param {Object} start
 */
function indexOf(arr, value, start) {
  //如果不设置start,则默认start为0
  if(arguments.length == 2) {
    start = 0;
  }
  //如果数组中存在indexOf方法，则用原生的indexOf方法
  if(arr.indexOf) {
    return arr.indexOf(value, start);
  }
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] === value) {
      return i;
    }
  }
  return -1;
}
/**
 * 数组去重方法封装
 * @param {Object} arr
 */
function noRepeat(arr) {
  var result = [];
  for(var i = 0; i < arr.length; i++) {
    if(indexOf(result, arr[i]) == -1) {
      result.push(arr[i]);
    }
  }
  return result;
}
/**
 * inArray方法封装
 * @param {Object} arr
 * @param {Object} value
 */
function inArray(arr, value) {
  for(var i = 0; i < arr.length; i++) {
    if(arr[i] === value) {
      return true;
    }
  }
  return false;
}
/**
 * 去除首尾空格函数封装
 * @param {Object} arr
 */
function trim(arr) {
  var result = arr.replace(/^\s+|\s+$/g, '');
  return result;
}

 //表单数据站环卫
function formToJson(formObj){
	   var o={};
	   var a=formObj.serializeArray();
	   $.each(a, function() {
	       if(this.value){
	           if (o[this.name]) {
	               if (!o[this.name].push) {
	                   o[this.name]=[ o[this.name] ];
	               }
	                   o[this.name].push(this.value || null);
	           }else {
	               if($("[name='"+this.name+"']:checkbox",formObj).length){
	                   o[this.name]=[this.value];
	               }else{
	                   o[this.name]=this.value || null;
	               }
	           }
	       }
	   });
	   return JSON.stringify(o);
};

//存储 登录ID 跟accessToken
var storage=window.localStorage;
adminId = storage.getItem("parallelId");
var accessToken = storage.getItem("parallelToken");

// var userName = localStorage.getItem("userName");



//url传参方式
userId = getQueryString("userId",window.location.href); //用户传ID
deviceInspectionId = getQueryString("deviceInspectionId",window.location.href);
deviceId = getQueryString("deviceId",window.location.href); //设备传ID
teamId = getQueryString("teamId",window.location.href); //
scenesId = getQueryString("scenesId",window.location.href); //
stadiumId = getQueryString("stadiumId",window.location.href); //
scenesResultId = getQueryString("scenesResultId",window.location.href); //
function getQueryString(name, url) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    if (!url || url == ""){
	    url = window.location.search;
    }else{
    	url = url.substring(url.indexOf("?"));
    }
    r = url.substr(1).match(reg)
    if (r != null) return unescape(r[2]); return null;
}
//ajax的url
//var url='http://192.168.3.117:8085/mark';
var url = 'http://60.205.229.131:8085/mark';
// var url = 'http://localhost:8085/mark';

//AJAX 的请求成功判断条件
function ifajax(data){
	window.parent.location.href = 'login.html';
}

// 验证手机号，input--onchange="checkMobile()"
function checkMobile(){ 
    var sMobile = document.getElementById('teamName').value;
    if(!(/^1[3|5][0-9]\d{4,8}$/.test(sMobile))){ 
        layer.msg('请输入正确的手机号');
        return false; 
    } 
} 