﻿$(document).ready(function () {
  $(document).pngFix();

  if ($('.GoPageBtn').length) {
    $('.GoPageBtn').click(function () {
      if ($('.GoPage').val() != "") {
        var count = parseInt($('#_PageCount').html());
        if (!isNaN($('.GoPage').val())) {
          if ((parseInt($('.GoPage').val()) > count) || (parseInt($('.GoPage').val()) < 1)) {
            alert("页码超出索引，请重新输入！");
            return false;
          }
        }
        else {
          alert("页码输入错误！");
          return false;
        }
      }
      else {
        alert("请输入页码！");
        return false;
      }
    });
  }
})

function JHshNumberText() {
  if (!(((window.event.keyCode >= 48) && (window.event.keyCode <= 57)) || (window.event.keyCode == 13) || (window.event.keyCode == 46) || (window.event.keyCode == 45))) {
    window.event.keyCode = 0;
  }
}

function chgTabNews(i) {
  resetTabNews();
  $(".MyStyle .title .item").eq(i).removeClass("myot");
  $(".MyStyle .title .item").eq(i).addClass("mycur");
  $(".MyStyle .cont .div100").eq(i).show();
}
function resetTabNews() {
  $(".MyStyle .title .item").removeClass("mycur");
  $(".MyStyle .title .item").addClass("myot");
  $(".MyStyle .cont .div100").hide();
}

//-------------------------------------=================================JQUERY Documnet=================---------------
var Tools = {
  isUndefined: function (variable) {
    return typeof variable == 'undefined' ? true : false;
  },
  lastFolderName: window.location.href.toLowerCase().replace(/.+\/(\w+)\/[^\/]*$/, '$1'),
  lastFileName: window.location.href.toLowerCase().replace(/.+\//g, ''),
  isArray: function (o) {
    return Object.prototype.toString.call(o) === '[object Array]';
  },
  getExt: function (path) {
    return path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
  },
  $: function (obj) {
    return document.getElementById(obj);
  },
  getParameter: function (param) {
    var query = window.location.search;
    var iLen = param.length;
    var iStart = query.indexOf(param);
    if (iStart == -1) return '';
    iStart += iLen + 1;
    var iEnd = query.indexOf('&', iStart);
    if (iEnd == -1) return query.substring(iStart);
    return query.substring(iStart, iEnd);
  },
  switchDiv: function (li, sltClass, switchObj) {
    $(li).each(function (i) {
      $(this).click(function () {
        $(this).addClass(sltClass).siblings().removeClass(sltClass);
        $(switchObj).eq(i).show().siblings(switchObj).hide();
      });
    });
  },
  checkNull: function (id, str) {
    _temp = $('#' + id).val().trim();
    if (_temp.length == 0) {
      alert('请输入' + str);
      $('#' + id).focus();
      return false;
    }
    return true;
  },
  checkEmail: function (id, str) {
    _temp = $('#' + id).val().trim();
    if (!/^[a-z0-9_]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*@[a-z0-9]{1}[a-z0-9\-_]*(\.[a-z0-9\-_]+)*\.[a-z]{2,4}$/.test(_temp)) {
      alert(str + '格式不正确');
      $('#' + id).focus();
      return false;
    }
    return true;
  },
  comparePwd: function (str1, str2) {
    if ($('#' + str1).val().trim() != $('#' + str2).val().trim()) {
      alert('前后密码不一致');
      $('#' + str2).focus();
      return false;
    }
    return true;
  },
  needChecked: function (id, str) {
    if ($('#' + id).attr('checked') == false) {
      alert(str);
      $('#' + id).focus();
      return false;
    }
    return true;
  },
  checkDigit: function (id, str) {
    _temp = $('#' + id).val().trim();
    if (!/^[0-9]+$/.test(_temp)) {
      alert(str);
      $('#' + id).focus();
      return false;
    }
    return true;
  },
  checkFixedLength: function (id, str, value, mode) {
    _temp = $('#' + id).val().trim();
    if (mode == 'MIN') {
      if (value != null && _temp.length < value) {
        alert(str + ' 长度至少为 ' + value + '位');
        $('#' + id).focus();
        return false;
      }
    }
    else if (mode == 'MAX') {
      if (value != null && _temp.length > value) {
        alert(str + ' 长度应小于 ' + value + '');
        $('#' + id).focus();
        return false;
      }
    }
    else {
      if (value != null && _temp.length != value) {
        alert(str + ' 长度应当为 ' + value + '位');
        $('#' + id).focus();
        return false;
      }
    }
    return true;
  },
  checkTel: function (id, str) {
    _temp = $('#' + id).val().trim();
    if (/^[0-9\-,]+$/.test(_temp)) {
      return true;
    }
    else {
      alert(str + ' 格式不正确 ');
      $('#' + id).focus();
      return false;
    }
  },
  checkMobile: function (id, str) {
    _temp = $('#' + id).val().trim();
    if (/^1[35]\d{9}$/.test(_temp)) {
      return true;
    }
    else {
      alert(str + ' 格式不正确 ');
      $('#' + id).focus();
      return false;
    }
  },
  checkUpLoadFile: function (obj, fileType, bool) {
    var o = Tools.$(obj);
    if (o.value.length > 0) {
      var tempType = o.value.substring(o.value.lastIndexOf('.'), o.value.length);
      if (fileType.toLowerCase().indexOf(tempType.toLowerCase()) == -1) {
        alert('上传格式不对，请重新选择');
        return false;
      }
    }
    else {
      if (!bool) {
        alert('请选择图片后上传');
        o.style.background = 'red';
        return false;
      }
    }
    return true;
  }
};
String.prototype.trim = function () {
  return this.replace(/(^\s*)|(\s*$)/g, '');
}
String.prototype.isDigit = function () {
  return (this.trim().replace(/\d/g, '').length == 0);
}
jQuery.cookie = function (name, value, options) {
  if (typeof value != 'undefined') { // name and value given, set cookie
    options = options || {};
    if (value === null) {
      value = '';
      options.expires = -1;
    }
    var expires = '';
    if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
      var date;
      if (typeof options.expires == 'number') {
        date = new Date();
        date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
      } else {
        date = options.expires;
      }
      expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
    }
    var path = options.path ? '; path=' + options.path : '';
    var domain = options.domain ? '; domain=' + options.domain : '';
    var secure = options.secure ? '; secure' : '';
    document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  } else { // only name given, get cookie
    var cookieValue = null;
    if (document.cookie && document.cookie != '') {
      var cookies = document.cookie.split(';');
      for (var i = 0; i < cookies.length; i++) {
        var cookie = jQuery.trim(cookies[i]);
        // Does this cookie string begin with the name we want?
        if (cookie.substring(0, name.length + 1) == (name + '=')) {
          cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
          break;
        }
      }
    }
    return cookieValue;
  }
};
//-->
